Adjusting tests to the changed KVStore 02/28202/3
authorJan Olszak <j.olszak@samsung.com>
Wed, 24 Sep 2014 14:12:13 +0000 (16:12 +0200)
committerJan Olszak <j.olszak@samsung.com>
Wed, 1 Oct 2014 12:04:32 +0000 (14:04 +0200)
[Bug/Feature]   Added isEmpty() and exists() functions
[Cause]         N/A
[Solution]      N/A
[Verification]  Build, install, run tests

Change-Id: Ied7f469599cfdb31104e4f0bc1b67b8cbc2a2cc0

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

index 1e98d22..b205339 100644 (file)
@@ -48,11 +48,13 @@ struct TestConfig {
         };
 
         int intVal;
+        std::vector<int> intVector;
         SubSubConfig subSubObj;
 
         CONFIG_REGISTER
         (
             intVal,
+            intVector,
             subSubObj
         )
     };
@@ -63,6 +65,7 @@ struct TestConfig {
     double doubleVal;
     bool boolVal;
 
+    std::vector<int> emptyIntVector;
     std::vector<int> intVector;
     std::vector<std::string> stringVector;
     std::vector<double> doubleVector;
@@ -78,6 +81,7 @@ struct TestConfig {
         doubleVal,
         boolVal,
 
+        emptyIntVector,
         intVector,
         stringVector,
         doubleVector,
@@ -98,12 +102,13 @@ const std::string jsonTestString =
     "\"stringVal\": \"blah\", "
     "\"doubleVal\": -1.234000, "
     "\"boolVal\": true, "
+    "\"emptyIntVector\": [ ], "
     "\"intVector\": [ 1, 2, 3 ], "
     "\"stringVector\": [ \"a\", \"b\" ], "
     "\"doubleVector\": [ 0.000000, 1.000000, 2.000000 ], "
-    "\"subObj\": { \"intVal\": 54321, \"subSubObj\": { \"intVal\": 234 } }, "
-    "\"subVector\": [ { \"intVal\": 123, \"subSubObj\": { \"intVal\": 345 } }, "
-                     "{ \"intVal\": 456, \"subSubObj\": { \"intVal\": 567 } } ] }";
+    "\"subObj\": { \"intVal\": 54321, \"intVector\": [ 1, 2 ], \"subSubObj\": { \"intVal\": 234 } }, "
+    "\"subVector\": [ { \"intVal\": 123, \"intVector\": [ 3, 4 ], \"subSubObj\": { \"intVal\": 345 } }, "
+    "{ \"intVal\": 456, \"intVector\": [ 5, 6 ], \"subSubObj\": { \"intVal\": 567 } } ] }";
 
 // Floating point tolerance as a number of rounding errors
 const int TOLERANCE = 1;
@@ -121,6 +126,8 @@ BOOST_AUTO_TEST_CASE(FromStringTest)
     BOOST_CHECK_CLOSE(-1.234, testConfig.doubleVal, TOLERANCE);
     BOOST_CHECK_EQUAL(true, testConfig.boolVal);
 
+    BOOST_REQUIRE_EQUAL(0, testConfig.emptyIntVector.size());
+
     BOOST_REQUIRE_EQUAL(3, testConfig.intVector.size());
     BOOST_CHECK_EQUAL(1, testConfig.intVector[0]);
     BOOST_CHECK_EQUAL(2, testConfig.intVector[1]);
@@ -136,12 +143,21 @@ BOOST_AUTO_TEST_CASE(FromStringTest)
     BOOST_CHECK_CLOSE(2.0, testConfig.doubleVector[2], TOLERANCE);
 
     BOOST_CHECK_EQUAL(54321, testConfig.subObj.intVal);
+    BOOST_CHECK_EQUAL(2,     testConfig.subObj.intVector.size());
+    BOOST_CHECK_EQUAL(1,     testConfig.subObj.intVector[0]);
+    BOOST_CHECK_EQUAL(2,     testConfig.subObj.intVector[1]);
+    BOOST_CHECK_EQUAL(234,   testConfig.subObj.subSubObj.intVal);
 
     BOOST_REQUIRE_EQUAL(2, testConfig.subVector.size());
     BOOST_CHECK_EQUAL(123, testConfig.subVector[0].intVal);
     BOOST_CHECK_EQUAL(456, testConfig.subVector[1].intVal);
     BOOST_CHECK_EQUAL(345, testConfig.subVector[0].subSubObj.intVal);
     BOOST_CHECK_EQUAL(567, testConfig.subVector[1].subSubObj.intVal);
+    BOOST_CHECK_EQUAL(3,   testConfig.subVector[0].intVector[0]);
+    BOOST_CHECK_EQUAL(5,   testConfig.subVector[1].intVector[0]);
+    BOOST_CHECK_EQUAL(4,   testConfig.subVector[0].intVector[1]);
+    BOOST_CHECK_EQUAL(6,   testConfig.subVector[1].intVector[1]);
+
 }
 
 
index 66efc2b..2c9a998 100644 (file)
@@ -114,33 +114,29 @@ BOOST_AUTO_TEST_CASE(EscapedCharactersTest)
     std::string HARD_KEY = "[" + KEY;
     BOOST_CHECK_NO_THROW(c.set(HARD_KEY, "A"));
     BOOST_CHECK_NO_THROW(c.set(KEY, "B"));
-    BOOST_CHECK_EQUAL(c.count(HARD_KEY), 1);
-    BOOST_CHECK_EQUAL(c.count(KEY), 1);
-    BOOST_CHECK_EQUAL(c.size(), 2);
+    BOOST_CHECK(c.exists(HARD_KEY));
+    BOOST_CHECK(c.exists(KEY));
     BOOST_CHECK_NO_THROW(c.clear());
 
     HARD_KEY = "]" + KEY;
     BOOST_CHECK_NO_THROW(c.set(HARD_KEY, "A"));
     BOOST_CHECK_NO_THROW(c.set(KEY, "B"));
-    BOOST_CHECK_EQUAL(c.count(HARD_KEY), 1);
-    BOOST_CHECK_EQUAL(c.count(KEY), 1);
-    BOOST_CHECK_EQUAL(c.size(), 2);
+    BOOST_CHECK(c.exists(HARD_KEY));
+    BOOST_CHECK(c.exists(KEY));
     BOOST_CHECK_NO_THROW(c.clear());
 
     HARD_KEY = "?" + KEY;
     BOOST_CHECK_NO_THROW(c.set(HARD_KEY, "A"));
     BOOST_CHECK_NO_THROW(c.set(KEY, "B"));
-    BOOST_CHECK_EQUAL(c.count(HARD_KEY), 1);
-    BOOST_CHECK_EQUAL(c.count(KEY), 1);
-    BOOST_CHECK_EQUAL(c.size(), 2);
+    BOOST_CHECK(c.exists(HARD_KEY));
+    BOOST_CHECK(c.exists(KEY));
     BOOST_CHECK_NO_THROW(c.clear());
 
     HARD_KEY = "*" + KEY;
     BOOST_CHECK_NO_THROW(c.set(HARD_KEY, "A"));
     BOOST_CHECK_NO_THROW(c.set(KEY, "B"));
-    BOOST_CHECK_EQUAL(c.count(HARD_KEY), 1);
-    BOOST_CHECK_EQUAL(c.count(KEY), 1);
-    BOOST_CHECK_EQUAL(c.size(), 2);
+    BOOST_CHECK(c.exists(HARD_KEY));
+    BOOST_CHECK(c.exists(KEY));
 }
 
 namespace {
@@ -154,11 +150,11 @@ void testSingleValue(Fixture& f, const A& a, const B& b)
     // Update
     BOOST_CHECK_NO_THROW(f.c.set(KEY, b));
     BOOST_CHECK_EQUAL(f.c.get<B>(KEY), b);
-    BOOST_CHECK_EQUAL(f.c.count(KEY), 1);
+    BOOST_CHECK(f.c.exists(KEY));
 
     // Remove
     BOOST_CHECK_NO_THROW(f.c.remove(KEY));
-    BOOST_CHECK_EQUAL(f.c.count(KEY), 0);
+    BOOST_CHECK(!f.c.exists(KEY));
     BOOST_CHECK_THROW(f.c.get<B>(KEY), ConfigException);
 }
 } // namespace
@@ -182,8 +178,6 @@ void setVector(Fixture& f, std::vector<T> vec)
     BOOST_CHECK_NO_THROW(f.c.set(KEY, vec));
     BOOST_CHECK_NO_THROW(storedVec = f.c.get<std::vector<T> >(KEY))
     BOOST_CHECK_EQUAL_COLLECTIONS(storedVec.begin(), storedVec.end(), vec.begin(), vec.end());
-    BOOST_CHECK_EQUAL(f.c.count(KEY), vec.size());
-    BOOST_CHECK_EQUAL(f.c.size(), vec.size());
 }
 
 template<typename T>
@@ -199,8 +193,8 @@ void testVectorOfValues(Fixture& f,
 
     // Remove
     BOOST_CHECK_NO_THROW(f.c.remove(KEY));
-    BOOST_CHECK_EQUAL(f.c.count(KEY), 0);
-    BOOST_CHECK_EQUAL(f.c.size(), 0);
+    BOOST_CHECK(!f.c.exists(KEY));
+    BOOST_CHECK(f.c.isEmpty());
     BOOST_CHECK_THROW(f.c.get<std::vector<T> >(KEY), ConfigException);
     BOOST_CHECK_THROW(f.c.get(KEY), ConfigException);
 }
@@ -221,7 +215,7 @@ BOOST_AUTO_TEST_CASE(ClearTest)
     std::vector<std::string> vec = {"A", "B"};
     BOOST_CHECK_NO_THROW(c.set(KEY, vec));
     BOOST_CHECK_NO_THROW(c.clear());
-    BOOST_CHECK_EQUAL(c.size(), 0);
+    BOOST_CHECK(c.isEmpty());
 
     BOOST_CHECK_NO_THROW(c.remove(KEY));
     BOOST_CHECK_THROW(c.get<std::vector<std::string>>(KEY), ConfigException);