19 #ifndef ConfigAdmin_cpp 20 #define ConfigAdmin_cpp 22 #include <cppunit/ui/text/TestRunner.h> 23 #include <cppunit/TextOutputter.h> 24 #include <cppunit/extensions/TestFactoryRegistry.h> 25 #include <cppunit/extensions/HelperMacros.h> 26 #include <cppunit/TestAssert.h> 37 :
public CppUnit::TestFixture
83 std::string name =
"name of parameter";
85 std::string default_value =
"3.14159";
90 CPPUNIT_ASSERT_EQUAL(name, std::string(
config.name));
93 CPPUNIT_ASSERT_EQUAL(default_value, std::string(
config.default_value));
103 std::string name =
"name of parameter";
105 std::string default_value =
"3.14159";
110 CPPUNIT_ASSERT_EQUAL(0.0, value);
113 CPPUNIT_ASSERT_EQUAL(
true,
config.update(
"1.41421356"));
116 CPPUNIT_ASSERT_EQUAL(1.41421356, value);
127 std::string name =
"name of parameter";
129 std::string default_value =
"3.14159";
134 CPPUNIT_ASSERT_EQUAL(0.0, value);
137 CPPUNIT_ASSERT_EQUAL(
false,
config.update(
"Not float value"));
140 CPPUNIT_ASSERT_EQUAL(3.14159, value);
151 std::string name =
"name of parameter";
153 std::string illegal_default_value =
"Not float value";
158 CPPUNIT_ASSERT_EQUAL(0.0, value);
163 CPPUNIT_ASSERT_EQUAL(
false,
config.update(
"Not float value too"));
164 CPPUNIT_ASSERT_EQUAL(0.0, value);
195 void operator()(
const char* config_set,
const char* config_param)
304 :
public CppUnit::TestFixture
320 CPPUNIT_TEST(test_update_with_specified_parameter_name);
325 CPPUNIT_TEST(test_isChanged_on_activateConfigurationSet);
331 CPPUNIT_TEST(test_addConfigurationSet_and_getConfigurationSet);
333 CPPUNIT_TEST(test_setConfigurationSetValues_with_inexist_configuration_set);
336 CPPUNIT_TEST(test_removeConfigurationSet_with_inexist_configuration_id);
343 const std::string& name,
344 const std::vector<coil::Properties*>& propertiesSet)
const 346 for (
int i = 0; i < (int) propertiesSet.size(); ++i)
348 if (std::string(propertiesSet[i]->getName()) == name)
350 return propertiesSet[i];
400 CPPUNIT_ASSERT_EQUAL(std::string(
"value"), activeConfigSet.
getProperty(
"key"));
415 const char* varName =
"name";
417 const char* default_value =
"3.14159";
418 CPPUNIT_ASSERT_EQUAL(
419 true, configAdmin.
bindParameter(varName, var, default_value));
422 CPPUNIT_ASSERT_EQUAL(3.14159, var);
436 const char* varName1 =
"name";
438 const char* default_value1 =
"3.14159";
439 CPPUNIT_ASSERT_EQUAL(
440 true, configAdmin.
bindParameter(varName1, var1, default_value1));
441 CPPUNIT_ASSERT_EQUAL(3.14159, var1);
444 const char* varName2 = varName1;
446 const char* default_value2 =
"1.41421356";
447 CPPUNIT_ASSERT_EQUAL(
448 false, configAdmin.
bindParameter(varName2, var2, default_value2));
451 CPPUNIT_ASSERT_EQUAL(3.14159, var1);
465 const char* varName =
"name";
467 const char* default_value =
"Illegal default value";
468 CPPUNIT_ASSERT_EQUAL(
469 false, configAdmin.
bindParameter(varName, var, default_value));
495 const char* varName =
"name";
497 const char* default_value =
"3.14159";
498 CPPUNIT_ASSERT_EQUAL(
499 true, configAdmin.
bindParameter(varName, var, default_value));
502 CPPUNIT_ASSERT_EQUAL(3.14159, var);
505 configAdmin.
update(
"set 1");
506 CPPUNIT_ASSERT_EQUAL(1.41421356, var);
509 configAdmin.
update(
"set 2");
510 CPPUNIT_ASSERT_EQUAL(1.7320508, var);
530 const char* varName =
"name";
532 const char* default_value =
"3.14159";
533 CPPUNIT_ASSERT_EQUAL(
534 true, configAdmin.
bindParameter(varName, var, default_value));
535 CPPUNIT_ASSERT_EQUAL(3.14159, var);
539 configAdmin.
update(
"inexist set");
540 CPPUNIT_ASSERT_EQUAL(3.14159, var);
560 configSet2.setProperty(
"name 1",
"3.14159");
561 configSet2.setProperty(
"name 2",
"2.71828");
565 const char* varName1 =
"name 1";
567 const char* default_value1 =
"2.23620679";
568 CPPUNIT_ASSERT_EQUAL(
569 true, configAdmin.
bindParameter(varName1, var1, default_value1));
570 CPPUNIT_ASSERT_EQUAL(2.23620679, var1);
572 const char* varName2 =
"name 2";
574 const char* default_value2 =
"2.4494897";
575 CPPUNIT_ASSERT_EQUAL(
576 true, configAdmin.
bindParameter(varName2, var2, default_value2));
577 CPPUNIT_ASSERT_EQUAL(2.4494897, var2);
580 configAdmin.
update(
"set 2",
"name 1");
581 CPPUNIT_ASSERT_EQUAL(3.14159, var1);
582 CPPUNIT_ASSERT_EQUAL(2.4494897, var2);
601 configSet2.setProperty(
"name",
"1.7320508");
605 const char* varName =
"name";
607 const char* default_value =
"3.14159";
608 CPPUNIT_ASSERT_EQUAL(
609 true, configAdmin.
bindParameter(varName, var, default_value));
610 CPPUNIT_ASSERT_EQUAL(3.14159, var);
616 CPPUNIT_ASSERT_EQUAL(3.14159, var);
620 CPPUNIT_ASSERT_EQUAL(1.41421356, var);
626 CPPUNIT_ASSERT_EQUAL(1.41421356, var);
630 CPPUNIT_ASSERT_EQUAL(1.7320508, var);
645 const char* varName =
"name";
647 const char* default_value =
"3.14159";
648 CPPUNIT_ASSERT_EQUAL(
649 true, configAdmin.
bindParameter(varName, var, default_value));
650 CPPUNIT_ASSERT_EQUAL(3.14159, var);
653 CPPUNIT_ASSERT_EQUAL(
true, configAdmin.
isExist(
"name"));
656 CPPUNIT_ASSERT_EQUAL(
false, configAdmin.
isExist(
"inexist name"));
671 CPPUNIT_ASSERT_EQUAL(
false, configAdmin.
isChanged());
675 configSet.setProperty(
"key",
"value");
679 CPPUNIT_ASSERT_EQUAL(
true, configAdmin.
isChanged());
700 CPPUNIT_ASSERT_EQUAL(
false, configAdmin.
isChanged());
729 CPPUNIT_ASSERT_EQUAL(
false, configAdmin.
isChanged());
733 CPPUNIT_ASSERT_EQUAL(
true, configAdmin.
isChanged());
759 CPPUNIT_ASSERT_EQUAL(std::string(
"default"), std::string(configAdmin.
getActiveId()));
763 CPPUNIT_ASSERT_EQUAL(std::string(
"set 1"), std::string(configAdmin.
getActiveId()));
767 CPPUNIT_ASSERT_EQUAL(std::string(
"set 2"), std::string(configAdmin.
getActiveId()));
786 CPPUNIT_ASSERT_EQUAL(
true, configAdmin.
haveConfig(
"id"));
789 CPPUNIT_ASSERT_EQUAL(
false, configAdmin.
haveConfig(
"inexist id"));
806 CPPUNIT_ASSERT_EQUAL(
false, configAdmin.
isActive());
810 CPPUNIT_ASSERT_EQUAL(
true, configAdmin.
isActive());
827 CPPUNIT_ASSERT_EQUAL(
true, configAdmin.
isActive());
867 configSet2.setProperty(
"name 1",
"3.14159");
868 configSet2.setProperty(
"name 2",
"2.71828");
873 std::vector<coil::Properties*> expectedConfigSets;
874 expectedConfigSets.push_back(&configSet1);
875 expectedConfigSets.push_back(&configSet2);
877 const std::vector<coil::Properties*>& configSets
880 CPPUNIT_ASSERT_EQUAL(
881 std::string(
"1.41421356"),
882 getPropertiesBy(
"set 1", configSets)->getProperty(
"name 1"));
883 CPPUNIT_ASSERT_EQUAL(
884 std::string(
"1.7320508"),
885 getPropertiesBy(
"set 1", configSets)->getProperty(
"name 2"));
887 CPPUNIT_ASSERT_EQUAL(
888 std::string(
"3.14159"),
889 getPropertiesBy(
"set 2", configSets)->getProperty(
"name 1"));
890 CPPUNIT_ASSERT_EQUAL(
891 std::string(
"2.71828"),
892 getPropertiesBy(
"set 2", configSets)->getProperty(
"name 2"));
913 CPPUNIT_ASSERT_EQUAL(std::string(
"value"), configSetRet.
getProperty(
"key"));
932 configSet2.setProperty(
"name 2",
"1.7320508");
937 CPPUNIT_ASSERT_EQUAL(std::string(
"1.41421356"), configSetRet.getProperty(
"name 1"));
938 CPPUNIT_ASSERT_EQUAL(std::string(
"1.7320508"), configSetRet.getProperty(
"name 2"));
958 configSet2.setProperty(
"name 2",
"1.7320508");
963 CPPUNIT_ASSERT_EQUAL(std::string(
"1.41421356"), configSetRet.getProperty(
"name 1"));
964 CPPUNIT_ASSERT_EQUAL(std::string(
""), configSetRet.getProperty(
"name 2"));
984 configSet2.setProperty(
"name 1",
"3.14159");
985 configSet2.setProperty(
"name 2",
"2.71828");
991 CPPUNIT_ASSERT_EQUAL(std::string(
"1.41421356"), activeConfigSet1.getProperty(
"name 1"));
992 CPPUNIT_ASSERT_EQUAL(std::string(
"1.7320508"), activeConfigSet1.getProperty(
"name 2"));
997 CPPUNIT_ASSERT_EQUAL(std::string(
"3.14159"), activeConfigSet2.getProperty(
"name 1"));
998 CPPUNIT_ASSERT_EQUAL(std::string(
"2.71828"), activeConfigSet2.getProperty(
"name 2"));
1015 CPPUNIT_ASSERT_EQUAL(
true, configAdmin.
haveConfig(
"id"));
1021 CPPUNIT_ASSERT_EQUAL(
false, configAdmin.
haveConfig(
"id"));
1038 CPPUNIT_ASSERT_EQUAL(
true, configAdmin.
haveConfig(
"id"));
1044 CPPUNIT_ASSERT_EQUAL(
true, configAdmin.
haveConfig(
"id"));
1068 CPPUNIT_ASSERT(!cdm1->
result);
1070 CPPUNIT_ASSERT(cdm1->
result);
1074 CPPUNIT_ASSERT(!cdm2->
result);
1076 CPPUNIT_ASSERT(cdm2->
result);
1098 CPPUNIT_ASSERT(!cdm1->
result);
1100 CPPUNIT_ASSERT(cdm1->
result);
1104 CPPUNIT_ASSERT(!cdm2->
result);
1106 CPPUNIT_ASSERT(cdm2->
result);
1123 configSet2.
setProperty(
"config_id2.key",
"value2");
1130 CPPUNIT_ASSERT(!cdm1->
result);
1132 CPPUNIT_ASSERT(cdm1->
result);
1136 CPPUNIT_ASSERT(!cdm2->
result);
1138 CPPUNIT_ASSERT(cdm2->
result);
1155 configSet2.
setProperty(
"config_id2.key",
"value2");
1162 CPPUNIT_ASSERT(!cdm1->
result);
1164 CPPUNIT_ASSERT(cdm1->
result);
1168 CPPUNIT_ASSERT(!cdm2->
result);
1170 CPPUNIT_ASSERT(cdm2->
result);
1192 CPPUNIT_ASSERT(!cdm1->
result);
1194 CPPUNIT_ASSERT(cdm1->
result);
1198 CPPUNIT_ASSERT(!cdm2->
result);
1200 CPPUNIT_ASSERT(cdm2->
result);
1222 CPPUNIT_ASSERT(!cdm1->
result);
1224 CPPUNIT_ASSERT(cdm1->
result);
1228 CPPUNIT_ASSERT(!cdm2->
result);
1230 CPPUNIT_ASSERT(cdm2->
result);
1248 int main(
int argc,
char* argv[])
1261 std::string arg(argv[i]);
1262 std::string next_arg;
1263 if (i + 1 < argc) next_arg = argv[i + 1];
1266 if (arg ==
"--text") { format =
TEXT_OUT;
break; }
1279 ofs.open(fname.c_str());
1281 if ( arg ==
"--compiler" ) { format =
COMPILER_OUT;
break; }
1282 if ( arg ==
"--cerr" ) { target = 1;
break; }
1283 if ( arg ==
"--xsl" )
1285 if (next_arg ==
"") xsl =
"default.xsl";
1286 else xsl = next_arg;
1288 if ( arg ==
"--namespace" )
1292 std::cerr <<
"no namespace specified" << std::endl;
1302 CppUnit::TextUi::TestRunner runner;
1304 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
1306 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
1307 CppUnit::Outputter* outputter = 0;
1308 std::ostream* stream = target ? &std::cerr : &std::cout;
1312 outputter =
new CppUnit::TextOutputter(&runner.result(),*stream);
1315 std::cout <<
"XML_OUT" << std::endl;
1316 outputter =
new CppUnit::XmlOutputter(&runner.result(),
1318 static_cast<CppUnit::XmlOutputter*
>(outputter)->setStyleSheet(xsl);
1321 outputter =
new CppUnit::CompilerOutputter(&runner.result(),*stream);
1324 runner.setOutputter(outputter);
1329 #endif // ConfigAdmin_cpp ConfigAdminMock(coil::Properties &configsets)
void test_setOnActivateSet()
setOnActivateSet()メソッドのテスト
void test_setOnSetConfigurationSet()
setOnSetConfigurationSet()メソッドのテスト
void test_isActive_on_addConfigurationSet()
isActive()メソッドのテスト
int main(int argc, char **argv)
void onAddConfigurationSetMock(const coil::Properties &config_set)
void test_removeConfigurationSet_with_inexist_configuration_id()
removeConfigurationSet()のテスト
void operator()(const coil::Properties &config_set)
Virtual Callback function.
void onUpdateParam(const char *config_set, const char *config_param)
When the configuration parameter is updated, it is called.
void test_bindParameter_already_exist()
bindParameter()メソッドのテスト
virtual ~OnRemoveConfigurationSetCallbackMock(void)
ConfigTests()
Constructor.
virtual void setUp()
Test initialization.
void onRemoveConfigurationSet(const char *config_id)
Called when the configuration set has been deleted.
~ConfigAdminTests()
Destructor.
void test_constructor()
コンストラクタのテスト
void test_haveConfig()
haveConfig()メソッドのテスト
void test_update_by_active_configuration_set()
update()メソッド(アクティブコンフィグレーションセット)のテスト
bool activateConfigurationSet(const char *config_id)
Activate the configuration set.
CPPUNIT_TEST(test_constructor)
void test_isActive_on_removeConfigurationSet()
isActive()メソッドのテスト
void test_update_with_illegal_value()
update()メソッドのテスト
void operator()(const char *config_set)
Virtual Callback function.
bool isActive(void)
Confirm to activate configuration set.
void test_getActiveId()
getActiveId()メソッドのテスト
void operator()(const char *config_set)
Virtual Callback function.
const std::vector< coil::Properties * > & getConfigurationSets(void)
Get all configuration sets.
void operator()(const char *config_id)
Virtual Callback function.
virtual ~OnActivateSetCallbackMock(void)
void test_update()
update()メソッドのテスト
void test_setConfigurationSetValues()
void test_getConfigurationSets()
getConfigurationSets()メソッドのテスト
void onRemoveConfigurationSetMock(const char *config_id)
void onSetConfigurationSetMock(const coil::Properties &config_set)
virtual ~OnSetConfigurationSetCallbackMock(void)
~ConfigTests()
Destructor.
const coil::Properties * getPropertiesBy(const std::string &name, const std::vector< coil::Properties * > &propertiesSet) const
void setOnRemoveConfigurationSet(OnRemoveConfigurationSetCallback *cb)
ConfigurationSetListener class.
ConfigurationSetNameListener class.
ConfigurationParamListener class.
void test_isExist()
isExist()メソッドのテスト
Configuration Administration classes.
OnUpdateCallbackMock(void)
const coil::Properties & getActiveConfigurationSet(void)
Get the active configuration set.
void onActivateSet(const char *config_id)
Called when the configuration set is made active.
void setOnActivateSet(OnActivateSetCallback *cb)
virtual ~OnUpdateParamCallbackMock(void)
void test_isChanged_on_activateConfigurationSet()
isChanged()メソッドのテスト
const coil::Properties & getConfigurationSet(const char *config_id)
Get a configuration set by specified ID.
bool isExist(const char *name)
Check the existence of configuration parameters.
void test_isChanged_on_setConfigurationSetValues()
virtual ~OnAddConfigurationAddCallbackMock(void)
void test_isActive_on_activateConfigurationSet()
isActive()メソッドのテスト
void test_removeConfigurationSet()
removeConfigurationSet()のテスト
void test_addConfigurationSet_and_getConfigurationSet()
void test_setOnAddConfigurationSet()
setOnAddConfigurationSet()メソッドのテスト
virtual void tearDown()
Test finalization.
virtual void tearDown()
Test finalization.
void onUpdateParamMock(const char *config_set, const char *config_param)
void onUpdateMock(const char *config_set)
void update(void)
Update the values of configuration parameters (Active configuration set)
void setOnUpdate(OnUpdateCallback *cb)
bool isChanged(void)
Confirm to change configuration parameters.
OnAddConfigurationAddCallbackMock(void)
void setOnSetConfigurationSet(OnSetConfigurationSetCallback *cb)
void test_isActive_on_setConfigurationSetValues()
ConfigAdminTests()
Constructor.
bool addConfigurationSet(const coil::Properties &configuration_set)
Add the configuration value to configuration set.
void test_setOnUpdateParam()
setOnUpdateParam()メソッドのテスト
void test_update_with_illegal_default_value()
update()メソッドのテスト
virtual ~OnUpdateCallbackMock(void)
std::string setProperty(const std::string &key, const std::string &value)
Set a value associated with key in the property list.
OnSetConfigurationSetCallbackMock(void)
virtual ~ConfigAdminMock(void)
void test_isChanged_on_removeConfigurationSet()
isChanged()メソッドのテスト
void test_update_with_specified_parameter_name()
update()メソッド(名称指定)のテスト
CPPUNIT_TEST_SUITE_REGISTRATION(Config::ConfigTests)
void test_bindParameter()
bindParameter()メソッドのテスト
void onUpdate(const char *config_set)
When the configuration parameter is updated, it is called.
OnActivateSetCallbackMock(void)
void test_setOnRemoveConfigurationSet()
setOnRemoveConfigurationSet()メソッドのテスト
OnUpdateParamCallbackMock(void)
Class represents a set of properties.
const char * getActiveId(void)
Get ID of active configuration set.
void onSetConfigurationSet(const coil::Properties &config_set)
Called when the property is added to the configuration set.
void operator()(const char *config_set, const char *config_param)
Virtual Callback function.
void test_update()
update()メソッドのテスト
void operator()(const coil::Properties &config_set)
Virtual Callback function.
void test_update_by_inexist_configuration_set()
update()メソッドのテスト
void onAddConfigurationSet(const coil::Properties &config_set)
Called when a set value is added to the configuration set.
void setOnAddConfigurationSet(OnAddConfigurationAddCallback *cb)
bool bindParameter(const char *param_name, VarType &var, const char *def_val, bool(*trans)(VarType &, const char *)=coil::stringTo)
Setup for configuration parameters.
virtual void setUp()
Test initialization.
bool haveConfig(const char *config_id)
Check the existence of configuration set.
bool setConfigurationSetValues(const coil::Properties &configuration_set)
Add to configuration set from specified property.
void test_activateConfigurationSet()
OnRemoveConfigurationSetCallbackMock(void)
void test_isChanged_on_addConfigurationSet()
isChanged()メソッドのテスト
void test_bindParameter_illegal_default_value()
bindParameter()メソッドのテスト
void test_setOnUpdate()
setOnUpdate()メソッドのテスト
void setOnUpdateParam(OnUpdateParamCallback *cb)
bool removeConfigurationSet(const char *config_id)
Remove the configuration set.
void test_getActiveConfigurationSet()
getActiveConfigurationSet()メソッドのテスト
void onActivateSetMock(const char *config_id)
void test_setConfigurationSetValues_with_inexist_configuration_set()
setConfigurationSetValues()メソッドのテスト
CPPUNIT_TEST_SUITE(ConfigTests)
const std::string & getProperty(const std::string &key) const
Search for the property with the specified key in this property.
void test_constructor()
コンストラクタのテスト