Support for boost version less then 1.54 -- disbale move in config union 32/31832/4
authorMateusz Malicki <m.malicki2@samsung.com>
Wed, 10 Dec 2014 17:24:32 +0000 (18:24 +0100)
committerJan Olszak <j.olszak@samsung.com>
Fri, 12 Dec 2014 16:13:00 +0000 (08:13 -0800)
[Bug/Feature]   Boost < 1.54 doesn't support rvalues in boost::any, better rvalues tests
[Cause]         ConfigUnionTest doesn't pass if compiled with boost 1.51
[Solution]      Changes in libConfig; Disable moving in union
[Verification]  Build, install, run tests

Change-Id: I3bb6af655fa9393bfab66d535705fa252ecf6174

tests/unit_tests/config/ut-configuration.cpp

index 8aab028..e46bfd8 100644 (file)
@@ -44,11 +44,31 @@ struct TestConfig {
 
         struct SubSubConfig {
             int intVal;
+            bool moved;
 
             CONFIG_REGISTER
             (
                 intVal
             )
+            SubSubConfig() : moved(false) {}
+            SubSubConfig(const SubSubConfig& config) : intVal(config.intVal), moved(false) {}
+            SubSubConfig(SubSubConfig&& config) : intVal(std::move(config.intVal)), moved(false) {
+                config.moved = true;
+            }
+            SubSubConfig& operator=(const SubSubConfig& config) {
+                intVal = config.intVal;
+                moved = false;
+                return *this;
+            }
+            SubSubConfig& operator=(SubSubConfig&& config) {
+                intVal = std::move(config.intVal);
+                moved = false;
+                config.moved = true;
+                return *this;
+            }
+            bool isMoved() const {
+                return moved;
+            }
         };
 
         int intVal;
@@ -368,7 +388,7 @@ BOOST_AUTO_TEST_CASE(FromToFDTest)
     fs::remove(fifoPath);
 }
 
-BOOST_AUTO_TEST_CASE(ConfigUnion)
+BOOST_AUTO_TEST_CASE(ConfigUnionTest)
 {
     TestConfig testConfig;
     BOOST_REQUIRE_NO_THROW(loadFromString(jsonTestString, testConfig));
@@ -385,11 +405,29 @@ BOOST_AUTO_TEST_CASE(ConfigUnion)
     std::string out = saveToString(testConfig);
     BOOST_CHECK_EQUAL(out, jsonTestString);
 
-    //Check move and copy
+    //Check copy
+
     std::vector<TestConfig::SubConfigOption> unions(2);
     unions[0].set<int>(2);
+    //set from const lvalue reference (copy)
+    unions[1].set(testConfig.unions[1].as<const TestConfig::SubConfig>());
+    BOOST_CHECK(!testConfig.unions[1].as<TestConfig::SubConfig>().subSubObj.isMoved());
+    //set from lvalue reference (copy)
+    unions[1].set(testConfig.unions[1].as<TestConfig::SubConfig>());
+    BOOST_CHECK(!testConfig.unions[1].as<TestConfig::SubConfig>().subSubObj.isMoved());
+    //set from const rvalue reference (copy)
+    unions[1].set(std::move(testConfig.unions[1].as<const TestConfig::SubConfig>()));
+    BOOST_CHECK(!testConfig.unions[1].as<TestConfig::SubConfig>().subSubObj.isMoved());
+    //set rvalue reference (copy -- move is disabled)
     unions[1].set(std::move(testConfig.unions[1].as<TestConfig::SubConfig>()));
-    BOOST_CHECK(testConfig.unions[1].as<TestConfig::SubConfig>().intVector.empty());
+    BOOST_CHECK(!testConfig.unions[1].as<TestConfig::SubConfig>().subSubObj.isMoved());
+    //assign lvalue reference (copy)
+    testConfig.unions[1] = unions[1];
+    BOOST_CHECK(!unions[1].as<TestConfig::SubConfig>().subSubObj.isMoved());
+    //assign rvalue reference (copy -- move is disabled)
+    testConfig.unions[1] = std::move(unions[1]);
+    BOOST_CHECK(!unions[1].as<TestConfig::SubConfig>().subSubObj.isMoved());
+
     testConfig.unions.clear();
     testConfig.unions = unions;
     out = saveToString(testConfig);