Integrating external libraries (libpq and jsoncpp) into waf
refs #2631
Change-Id: I420421fba0f53e78ddd4908792df2ce380117ea3
diff --git a/catalog/src/main.cpp b/catalog/src/main.cpp
index 78e3ccf..d5f89ee 100644
--- a/catalog/src/main.cpp
+++ b/catalog/src/main.cpp
@@ -21,13 +21,25 @@
#include <ChronoSync/socket.hpp>
#include <ndn-cxx/face.hpp>
+#include <json/value.h>
+#include <libpq-fe.h>
using namespace std;
using namespace ndn;
int main()
{
- Face face;
- shared_ptr<chronosync::Socket> socket;
+ Face face; // use ndn-cxx
+ 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;
+ }
+
return 0;
}
diff --git a/catalog/tests/unit-tests/simple.cpp b/catalog/tests/unit-tests/simple.cpp
index c6b4fbb..01ae66a 100644
--- a/catalog/tests/unit-tests/simple.cpp
+++ b/catalog/tests/unit-tests/simple.cpp
@@ -20,6 +20,11 @@
*/
#include <boost/test/unit_test.hpp>
+#include <libpq-fe.h>
+#include <json/value.h>
+#include <json/writer.h>
+#include <json/reader.h>
+#include <iostream>
namespace NdnAtmos {
namespace test {
@@ -31,6 +36,30 @@
BOOST_CHECK(0==0);
}
+BOOST_AUTO_TEST_CASE(DBTest)
+{
+ PGconn *conn;
+ conn = PQconnectdb("dbname=test sslmode=disable");
+ BOOST_CHECK_EQUAL(PQstatus(conn) != CONNECTION_OK, true);
+}
+
+BOOST_AUTO_TEST_CASE(JsonTest)
+{
+ Json::Value original;
+ original["command"] = "test";
+
+ Json::FastWriter fastWriter;
+ std::string jsonMessage = fastWriter.write(original);
+
+ Json::Value parsedFromString;
+ Json::Reader reader;
+ bool result;
+ BOOST_CHECK_EQUAL(result = reader.parse(jsonMessage, parsedFromString), true);
+ if (result) {
+ BOOST_CHECK_EQUAL(original, parsedFromString);
+ }
+}
+
BOOST_AUTO_TEST_SUITE_END()
} //namespace test
diff --git a/catalog/tests/wscript b/catalog/tests/wscript
index 21e0b09..0f29974 100644
--- a/catalog/tests/wscript
+++ b/catalog/tests/wscript
@@ -26,11 +26,11 @@
def build(bld):
# unit test objects
unit_tests_objects = bld(
- target="unit-test-objects",
- name="unit-test-objects",
+ target='unit-test-objects',
+ name='unit-test-objects',
features="cxx",
source=bld.path.ant_glob(['unit-tests/**/*.cpp']),
- use='ndn-cxx BOOST',
+ use='NDN_CXX BOOST ndn_atmos_objects',
includes='.',
install_path=None)
@@ -39,6 +39,6 @@
target='../unit-tests',
name='unit-tests-main-unit',
source="main.cpp",
- use='ndn-cxx unit-test-objects BOOST',
+ use='unit-test-objects',
install_path=None)