class TestGlobalConfig : public TestFixture
{
CPPUNIT_TEST_SUITE(TestGlobalConfig);
-
+
CPPUNIT_TEST(Basics);
CPPUNIT_TEST(MultipleValues);
-
+ CPPUNIT_TEST(MultipleValuesVanish);
+
CPPUNIT_TEST_SUITE_END();
-
+
protected:
-
+
std::set<std::string> used_check_files;
-
-
+
+
std::string getCheckFilepath(std::string tag)
{
std::string result;
CPPUNIT_ASSERT_EQUAL( 22, list2().back() );
} // eo MultipleValues
-
-
+
+
+ void MultipleValuesVanish()
+ {
+ std::string filename= getCheckFilepath("MultipleValuesVanish");
+ std::string cfg(
+ "[sec1]\n"
+ "g1 = 11\n"
+ "g1 = 12\n"
+ "g2 = 21\n"
+ );
+ std::string cfg2(
+ "[sec1]\n"
+ "g1 = 11\n"
+ );
+
+ bool res= write_file(filename,cfg);
+ CPPUNIT_ASSERT_EQUAL( true, res );
+
+ typedef std::list< int > IntList;
+ typedef std::vector< int > IntVector;
+
+ res= Config::set_config_file(filename);
+ CPPUNIT_ASSERT_EQUAL( true, res );
+
+ Config::Var< IntList > list1("sec1","g1", IntList());
+ Config::Var< IntList > list2("sec1","g2", IntList());
+
+ CPPUNIT_ASSERT_EQUAL( 2u, list1().size() );
+ CPPUNIT_ASSERT_EQUAL( 1u, list2().size() );
+
+ CPPUNIT_ASSERT_EQUAL( 11, list1().front() );
+ CPPUNIT_ASSERT_EQUAL( 12, list1().back() );
+ CPPUNIT_ASSERT_EQUAL( 21, list2().front() );
+ CPPUNIT_ASSERT_EQUAL( 21, list2().back() );
+
+ Config::Var< IntVector > vector1("sec1","g1", IntVector());
+ Config::Var< IntVector > vector2("sec1","g2", IntVector());
+
+ CPPUNIT_ASSERT_EQUAL( 2u, vector1().size() );
+ CPPUNIT_ASSERT_EQUAL( 1u, vector2().size() );
+
+ CPPUNIT_ASSERT_EQUAL( 11, vector1().front() );
+ CPPUNIT_ASSERT_EQUAL( 12, vector1().back() );
+ CPPUNIT_ASSERT_EQUAL( 21, vector2().front() );
+ CPPUNIT_ASSERT_EQUAL( 21, vector2().back() );
+
+ // now write a modified config
+ res= write_file(filename,cfg2);
+ CPPUNIT_ASSERT_EQUAL( true, res );
+
+ // .. and reload.
+ res= Config::reload();
+ CPPUNIT_ASSERT_EQUAL( true, res );
+
+ // check if the (right) vars changed..
+
+ CPPUNIT_ASSERT_EQUAL( 1u, list1().size() );
+ CPPUNIT_ASSERT_EQUAL( 0u, list2().size() );
+
+ CPPUNIT_ASSERT_EQUAL( 11, list1().front() );
+
+ } // eo MultipleValuesVanish
+
+
}; // eo class TestGlobalConfig
CPPUNIT_TEST_SUITE_REGISTRATION(TestGlobalConfig);