Tests of the serialization functions from libConfig 66/28366/5
authorJan Olszak <j.olszak@samsung.com>
Fri, 3 Oct 2014 16:20:30 +0000 (18:20 +0200)
committerJan Olszak <j.olszak@samsung.com>
Tue, 7 Oct 2014 14:15:50 +0000 (16:15 +0200)
[Bug/Feature]   N/A
[Cause]         N/A
[Solution]      N/A
[Verification]  Build, install, run tests

Change-Id: Ifa9e3397f4405cf4d9d1bcca2c891eb789cdf2ae

tests/unit_tests/config/ut-configuration.cpp
tests/unit_tests/config/ut-kvstore.cpp

index b205339..1d72bd8 100644 (file)
@@ -27,6 +27,9 @@
 #include "ut.hpp"
 #include "config/fields.hpp"
 #include "config/manager.hpp"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 #include <boost/filesystem.hpp>
 
 namespace fs = boost::filesystem;
@@ -316,6 +319,29 @@ BOOST_AUTO_TEST_CASE(FromToKVStoreTest)
     BOOST_CHECK_EQUAL(out, jsonTestString);
 
     fs::remove(dbPath);
+    fs::remove(dbPath + "-journal");
+}
+
+BOOST_AUTO_TEST_CASE(FromToFDTest)
+{
+    TestConfig config;
+    loadFromString(jsonTestString, config);
+    // Setup fd
+    std::string fifoPath = fs::unique_path("/tmp/fdstore-%%%%").string();
+    BOOST_CHECK(::mkfifo(fifoPath.c_str(), S_IWUSR | S_IRUSR) >= 0);
+    int fd = ::open(fifoPath.c_str(), O_RDWR);
+    BOOST_REQUIRE(fd >= 0);
+
+    // The test
+    saveToFD(fd, config);
+    TestConfig outConfig;
+    loadFromFD(fd, outConfig);
+    std::string out = saveToString(outConfig);
+    BOOST_CHECK_EQUAL(out, jsonTestString);
+
+    // Cleanup
+    BOOST_CHECK(::close(fd) >= 0);
+    fs::remove(fifoPath);
 }
 
 BOOST_AUTO_TEST_SUITE_END()
index 2c9a998..ba95452 100644 (file)
@@ -50,6 +50,7 @@ struct Fixture {
     ~Fixture()
     {
         fs::remove(dbPath);
+        fs::remove(dbPath + "-journal");
     }
 };