Enable automatic compilation and unit test verification

refs #2691

Change-Id: I0ab113fc9c4d481a74534fb8105a87dde8f76a12
diff --git a/.jenkins b/.jenkins
new file mode 100755
index 0000000..4daa40f
--- /dev/null
+++ b/.jenkins
@@ -0,0 +1,9 @@
+#!/usr/bin/env bash
+set -e
+
+DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+
+for i in `find "$DIR/.jenkins.d" -type f -perm +111 | sort`; do
+    echo "Run: $i"
+    $i
+done
diff --git a/.jenkins.d/00-deps.sh b/.jenkins.d/00-deps.sh
new file mode 100755
index 0000000..9eac278
--- /dev/null
+++ b/.jenkins.d/00-deps.sh
@@ -0,0 +1,27 @@
+#!/usr/bin/env bash
+set -e
+
+JDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
+source "$JDIR"/util.sh
+
+if has OSX $NODE_LABELS; then
+    set -x
+    brew update
+    brew upgrade
+    brew install boost sqlite3 pkg-config mysql jsoncpp
+    brew cleanup
+fi
+
+if has Ubuntu $NODE_LABELS; then
+    BOOST_PKG=libboost-all-dev
+    if has Ubuntu-12.04 $NODE_LABELS; then
+        BOOST_PKG=libboost1.48-all-dev
+    fi
+
+    set -x
+    sudo apt-get update -qq -y
+    sudo apt-get -qq -y install build-essential pkg-config $BOOST_PKG libssl-dev \
+                                libcrypto++-dev libsqlite3-dev mysql-client \
+                                mysql-server libjsoncpp-dev protobuf-compiler \
+                                libprotobuf-dev
+fi
diff --git a/.jenkins.d/10-ndn-cxx.sh b/.jenkins.d/10-ndn-cxx.sh
new file mode 100755
index 0000000..2af7d6a
--- /dev/null
+++ b/.jenkins.d/10-ndn-cxx.sh
@@ -0,0 +1,31 @@
+#!/usr/bin/env bash
+set -x
+set -e
+
+pushd /tmp >/dev/null
+
+INSTALLED_VERSION=$((cd ndn-cxx && git rev-parse HEAD) 2>/dev/null || echo NONE)
+
+sudo rm -Rf ndn-cxx-latest
+git clone --depth 1 git://github.com/named-data/ndn-cxx ndn-cxx-latest
+LATEST_VERSION=$((cd ndn-cxx-latest && git rev-parse HEAD) 2>/dev/null || echo UNKNOWN)
+
+if [[ $INSTALLED_VERSION != $LATEST_VERSION ]]; then
+    sudo rm -Rf ndn-cxx
+    mv ndn-cxx-latest ndn-cxx
+else
+    sudo rm -Rf ndn-cxx-latest
+fi
+
+sudo rm -Rf /usr/local/include/ndn-cxx
+sudo rm -f /usr/local/lib/libndn-cxx*
+sudo rm -f /usr/local/lib/pkgconfig/libndn-cxx*
+
+pushd ndn-cxx >/dev/null
+
+./waf configure -j1 --color=yes --without-osx-keychain
+./waf -j1 --color=yes
+sudo ./waf install -j1 --color=yes
+
+popd >/dev/null
+popd >/dev/null
diff --git a/.jenkins.d/11-chronoSync.sh b/.jenkins.d/11-chronoSync.sh
new file mode 100755
index 0000000..50318d4
--- /dev/null
+++ b/.jenkins.d/11-chronoSync.sh
@@ -0,0 +1,35 @@
+#!/usr/bin/env bash
+set -x
+set -e
+
+pushd /tmp >/dev/null
+
+INSTALLED_VERSION=$((cd ChronoSync && git rev-parse HEAD) 2>/dev/null || echo NONE)
+
+sudo rm -Rf ChronoSync-latest
+git clone --depth 1 git://github.com/named-data/ChronoSync ChronoSync-latest
+LATEST_VERSION=$((cd ChronoSync-latest && git rev-parse HEAD) 2>/dev/null || echo UNKNOWN)
+
+if [[ $INSTALLED_VERSION != $LATEST_VERSION ]]; then
+    sudo rm -Rf ChronoSync
+    mv ChronoSync-latest ChronoSync
+else
+    sudo rm -Rf ChronoSync-latest
+fi
+
+sudo rm -Rf /usr/local/include/ChronoSync
+sudo rm -f /usr/local/lib/libChronoSync*
+sudo rm -f /usr/local/lib/pkgconfig/ChronoSync*
+
+pushd ChronoSync >/dev/null
+
+export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:\
+/usr/local/lib32/pkgconfig:\
+/usr/local/lib64/pkgconfig
+
+./waf configure -j1 --color=yes
+./waf -j1 --color=yes
+sudo ./waf install -j1 --color=yes
+
+popd >/dev/null
+popd >/dev/null
diff --git a/.jenkins.d/20-build.sh b/.jenkins.d/20-build.sh
new file mode 100755
index 0000000..76f827e
--- /dev/null
+++ b/.jenkins.d/20-build.sh
@@ -0,0 +1,26 @@
+#!/usr/bin/env bash
+set -x
+set -e
+
+# Cleanup
+sudo ./waf -j1 --color=yes distclean
+
+# Configure/build in debug mode
+./waf -j1 --color=yes configure --with-tests --debug
+./waf -j1 --color=yes build
+
+# Cleanup
+sudo ./waf -j1 --color=yes distclean
+
+# Configure/build in optimized mode without tests
+./waf -j1 --color=yes configure
+./waf -j1 --color=yes build
+
+# Cleanup
+sudo ./waf -j1 --color=yes distclean
+
+# Configure/build in optimized mode
+./waf -j1 --color=yes configure --with-tests
+./waf -j1 --color=yes build
+
+# (tests will be run against optimized version)
diff --git a/.jenkins.d/30-unit-tests.sh b/.jenkins.d/30-unit-tests.sh
new file mode 100755
index 0000000..815e3f1
--- /dev/null
+++ b/.jenkins.d/30-unit-tests.sh
@@ -0,0 +1,9 @@
+#!/usr/bin/env bash
+set -x
+set -e
+
+# Prepare environment
+sudo rm -Rf ~/.ndn
+
+# Run unit tests
+./build/catalog/unit-tests -l test_suite
diff --git a/.jenkins.d/util.sh b/.jenkins.d/util.sh
new file mode 100755
index 0000000..81c8931
--- /dev/null
+++ b/.jenkins.d/util.sh
@@ -0,0 +1,9 @@
+has() {
+    local p=$1
+    shift
+    local x
+    for x in "$@"; do
+        [[ "${x}" == "${p}" ]] && return 0
+    done
+    return 1
+}
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..36518df
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,16 @@
+# For Ubuntu only
+sudo: true
+language: cpp
+os:
+  - linux
+compiler:
+  - gcc
+notifications:
+  email:
+    on_success: always
+    on_failure: always
+env:
+  global:
+    - NODE_LABELS="Linux Ubuntu Ubuntu-12.04 Ubuntu-12.04-64bit Boost1.48"
+script:
+  - ./.jenkins
diff --git a/README.md b/README.md
index 528369e..cc53e52 100644
--- a/README.md
+++ b/README.md
@@ -14,4 +14,4 @@
  2. ChronoSync v0.2 (https://github.com/named-data/ChronoSync.git)
  3. boost (Minimum required boost version is 1.48.0)
  4. jsoncpp 1.6.0 (https://github.com/open-source-parsers/jsoncpp.git)
- 5. postgresql 9.4.1 (http://www.postgresql.org)
+ 5. mysql 5.6.23 (http://www.mysql.com/)
diff --git a/catalog/src/main.cpp b/catalog/src/main.cpp
index d5f89ee..6e2fae1 100644
--- a/catalog/src/main.cpp
+++ b/catalog/src/main.cpp
@@ -22,7 +22,7 @@
 #include <ChronoSync/socket.hpp>
 #include <ndn-cxx/face.hpp>
 #include <json/value.h>
-#include <libpq-fe.h>
+#include <mysql.h>
 
 using namespace std;
 using namespace ndn;
@@ -33,12 +33,11 @@
   shared_ptr<chronosync::Socket> socket; // use ChronoSync
 
   Json::Value root; // use jsoncpp
-  PGconn *conn; // use libpq
-  // Make a connection to the database
-  conn = PQconnectdb("dbname=bedrock sslmode=disable");
-  if (PQstatus(conn) != CONNECTION_OK) {
-    cout << "Connection to database failed: "
-         << PQerrorMessage(conn) << endl;
+  MYSQL *con = mysql_init(NULL);
+  if (con == NULL)
+  {
+    fprintf(stderr, "%s\n", mysql_error(con));
+    return 1;
   }
 
   return 0;
diff --git a/catalog/tests/unit-tests/simple.cpp b/catalog/tests/unit-tests/simple.cpp
index 01ae66a..970b835 100644
--- a/catalog/tests/unit-tests/simple.cpp
+++ b/catalog/tests/unit-tests/simple.cpp
@@ -20,10 +20,10 @@
  */
 
 #include <boost/test/unit_test.hpp>
-#include <libpq-fe.h>
 #include <json/value.h>
 #include <json/writer.h>
 #include <json/reader.h>
+#include <mysql.h>
 #include <iostream>
 
 namespace NdnAtmos {
@@ -38,9 +38,8 @@
 
 BOOST_AUTO_TEST_CASE(DBTest)
 {
-  PGconn *conn;
-  conn = PQconnectdb("dbname=test sslmode=disable");
-  BOOST_CHECK_EQUAL(PQstatus(conn) != CONNECTION_OK, true);
+  MYSQL *conn = mysql_init(NULL);
+  BOOST_CHECK_EQUAL(conn == NULL, false);
 }
 
 BOOST_AUTO_TEST_CASE(JsonTest)
diff --git a/wscript b/wscript
index df0b84c..3388a06 100644
--- a/wscript
+++ b/wscript
@@ -49,6 +49,8 @@
     if not os.environ.has_key('PKG_CONFIG_PATH'):
         os.environ['PKG_CONFIG_PATH'] = ':'.join([
             '/usr/local/lib/pkgconfig',
+            '/usr/local/lib32/pkgconfig',
+            '/usr/local/lib64/pkgconfig',
             '/opt/local/lib/pkgconfig'])
 
     conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'],
@@ -60,8 +62,8 @@
     conf.check_cfg(package='jsoncpp', args=['--cflags', '--libs'],
                    uselib_store='JSON', mandatory=True)
 
-    conf.check_cfg(package='libpq', args=['--cflags', '--libs'],
-                   uselib_store='SQL_PQ', mandatory=True)
+    conf.check_cfg(path='mysql_config', args=['--cflags', '--libs'], package='',
+                   uselib_store='MYSQL', mandatory=True)
 
     boost_libs = 'system random thread filesystem'
 
@@ -84,9 +86,9 @@
         target='ndn_atmos_objects',
         name='ndn_atmos_objects',
         features='cxx',
-        source=bld.path.ant_glob(['catalog/src/*.cpp'],
+        source=bld.path.ant_glob(['catalog/src/**/*.cpp'],
                                  excl=['catalog/src/main.cpp']),
-        use='NDN_CXX BOOST SYNC JSON SQL_PQ',
+        use='NDN_CXX BOOST SYNC JSON MYSQL',
         includes='catalog/src .',
         export_includes='catalog/src .'
     )