From: Reinhard Pfau Date: Thu, 4 Sep 2008 14:10:12 +0000 (+0000) Subject: libsimpleio: (reinhard) added unit test for the "var does not vanish" problem. X-Git-Tag: v2.6~150 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=1cbc8602a8b7d2a78da33e4dc9a6384be416c2de;p=libi2ncommon libsimpleio: (reinhard) added unit test for the "var does not vanish" problem. --- diff --git a/test/test_global_config.cpp b/test/test_global_config.cpp index a889f97..55d04ea 100644 --- a/test/test_global_config.cpp +++ b/test/test_global_config.cpp @@ -37,17 +37,18 @@ using namespace CppUnit; class TestGlobalConfig : public TestFixture { CPPUNIT_TEST_SUITE(TestGlobalConfig); - + CPPUNIT_TEST(Basics); CPPUNIT_TEST(MultipleValues); - + CPPUNIT_TEST(MultipleValuesVanish); + CPPUNIT_TEST_SUITE_END(); - + protected: - + std::set used_check_files; - - + + std::string getCheckFilepath(std::string tag) { std::string result; @@ -245,8 +246,71 @@ class TestGlobalConfig : public TestFixture 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);