00001
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef ConfigAdmin_cpp
00020 #define ConfigAdmin_cpp
00021
00022 #include <cppunit/ui/text/TestRunner.h>
00023 #include <cppunit/TextOutputter.h>
00024 #include <cppunit/extensions/TestFactoryRegistry.h>
00025 #include <cppunit/extensions/HelperMacros.h>
00026 #include <cppunit/TestAssert.h>
00027 #include <strstream>
00028 #include <rtm/ConfigAdmin.h>
00029
00034 namespace Config
00035 {
00036 class ConfigTests
00037 : public CppUnit::TestFixture
00038 {
00039 CPPUNIT_TEST_SUITE(ConfigTests);
00040 CPPUNIT_TEST(test_constructor);
00041 CPPUNIT_TEST(test_update);
00042 CPPUNIT_TEST(test_update_with_illegal_value);
00043 CPPUNIT_TEST(test_update_with_illegal_default_value);
00044 CPPUNIT_TEST_SUITE_END();
00045
00046 private:
00047
00048
00049 public:
00053 ConfigTests()
00054 {
00055 }
00056
00060 ~ConfigTests()
00061 {
00062 }
00063
00067 virtual void setUp()
00068 {
00069 }
00070
00074 virtual void tearDown()
00075 {
00076 }
00077
00081 void test_constructor()
00082 {
00083 std::string name = "name of parameter";
00084 double value = 0.0;
00085 std::string default_value = "3.14159";
00086
00087 RTC::Config<double> config(name.c_str(), value, default_value.c_str());
00088
00089
00090 CPPUNIT_ASSERT_EQUAL(name, std::string(config.name));
00091
00092
00093 CPPUNIT_ASSERT_EQUAL(default_value, std::string(config.default_value));
00094 }
00095
00101 void test_update()
00102 {
00103 std::string name = "name of parameter";
00104 double value = 0.0;
00105 std::string default_value = "3.14159";
00106
00107 RTC::Config<double> config(name.c_str(), value, default_value.c_str());
00108
00109
00110 CPPUNIT_ASSERT_EQUAL(0.0, value);
00111
00112
00113 CPPUNIT_ASSERT_EQUAL(true, config.update("1.41421356"));
00114
00115
00116 CPPUNIT_ASSERT_EQUAL(1.41421356, value);
00117 }
00118
00125 void test_update_with_illegal_value()
00126 {
00127 std::string name = "name of parameter";
00128 double value = 0.0;
00129 std::string default_value = "3.14159";
00130
00131 RTC::Config<double> config(name.c_str(), value, default_value.c_str());
00132
00133
00134 CPPUNIT_ASSERT_EQUAL(0.0, value);
00135
00136
00137 CPPUNIT_ASSERT_EQUAL(false, config.update("Not float value"));
00138
00139
00140 CPPUNIT_ASSERT_EQUAL(3.14159, value);
00141 }
00142
00149 void test_update_with_illegal_default_value()
00150 {
00151 std::string name = "name of parameter";
00152 double value = 0.0;
00153 std::string illegal_default_value = "Not float value";
00154
00155 RTC::Config<double> config(name.c_str(), value, illegal_default_value.c_str());
00156
00157
00158 CPPUNIT_ASSERT_EQUAL(0.0, value);
00159
00160
00161
00162
00163 CPPUNIT_ASSERT_EQUAL(false, config.update("Not float value too"));
00164 CPPUNIT_ASSERT_EQUAL(0.0, value);
00165 }
00166
00167 };
00168 };
00169
00174 namespace ConfigAdmin
00175 {
00176 class OnUpdateCallbackMock : public RTC::OnUpdateCallback
00177 {
00178 public:
00179 OnUpdateCallbackMock(void) : result(false) {}
00180 virtual ~OnUpdateCallbackMock(void){}
00181 void operator()(const char* config_set)
00182 {
00183
00184
00185 result = true;
00186 }
00187 bool result;
00188 };
00189
00190 class OnUpdateParamCallbackMock : public RTC::OnUpdateParamCallback
00191 {
00192 public:
00193 OnUpdateParamCallbackMock(void) : result(false) {}
00194 virtual ~OnUpdateParamCallbackMock(void){}
00195 void operator()(const char* config_set, const char* config_param)
00196 {
00197
00198
00199 result = true;
00200 }
00201 bool result;
00202 };
00203
00204 class OnSetConfigurationSetCallbackMock : public RTC::OnSetConfigurationSetCallback
00205 {
00206 public:
00207 OnSetConfigurationSetCallbackMock(void) : result(false) {}
00208 virtual ~OnSetConfigurationSetCallbackMock(void){}
00209 void operator()(const coil::Properties& config_set)
00210 {
00211
00212 result = true;
00213 }
00214 bool result;
00215 };
00216
00217 class OnAddConfigurationAddCallbackMock : public RTC::OnAddConfigurationAddCallback
00218 {
00219 public:
00220 OnAddConfigurationAddCallbackMock(void) : result(false) {}
00221 virtual ~OnAddConfigurationAddCallbackMock(void){}
00222 void operator()(const coil::Properties& config_set)
00223 {
00224
00225 result = true;
00226 }
00227 bool result;
00228 };
00229
00230 class OnRemoveConfigurationSetCallbackMock : public RTC::OnRemoveConfigurationSetCallback
00231 {
00232 public:
00233 OnRemoveConfigurationSetCallbackMock(void) : result(false) {}
00234 virtual ~OnRemoveConfigurationSetCallbackMock(void){}
00235 void operator()(const char* config_set)
00236 {
00237
00238 result = true;
00239 }
00240 bool result;
00241 };
00242
00243 class OnActivateSetCallbackMock : public RTC::OnActivateSetCallback
00244 {
00245 public:
00246 OnActivateSetCallbackMock(void) : result(false) {}
00247 virtual ~OnActivateSetCallbackMock(void){}
00248 void operator()(const char* config_id)
00249 {
00250
00251 result = true;
00252 }
00253 bool result;
00254 };
00255
00256
00257 class ConfigAdminMock : public RTC::ConfigAdmin
00258 {
00259 public:
00260 ConfigAdminMock(coil::Properties& configsets)
00261 : RTC::ConfigAdmin(configsets) {}
00262 virtual ~ConfigAdminMock(void){}
00263
00264 void onUpdateMock(const char* config_set)
00265 {
00266
00267 RTC::ConfigAdmin::onUpdate(config_set);
00268
00269 }
00270 void onUpdateParamMock(const char* config_set, const char* config_param)
00271 {
00272
00273 RTC::ConfigAdmin::onUpdateParam(config_set, config_param);
00274
00275 }
00276 void onSetConfigurationSetMock(const coil::Properties& config_set)
00277 {
00278
00279 RTC::ConfigAdmin::onSetConfigurationSet(config_set);
00280
00281 }
00282 void onAddConfigurationSetMock(const coil::Properties& config_set)
00283 {
00284
00285 RTC::ConfigAdmin::onAddConfigurationSet(config_set);
00286
00287 }
00288 void onRemoveConfigurationSetMock(const char* config_id)
00289 {
00290
00291 RTC::ConfigAdmin::onRemoveConfigurationSet(config_id);
00292
00293 }
00294 void onActivateSetMock(const char* config_id)
00295 {
00296
00297 RTC::ConfigAdmin::onActivateSet(config_id);
00298
00299 }
00300 };
00301
00302
00303 class ConfigAdminTests
00304 : public CppUnit::TestFixture
00305 {
00306 CPPUNIT_TEST_SUITE(ConfigAdminTests);
00307
00308 CPPUNIT_TEST(test_setOnUpdate);
00309 CPPUNIT_TEST(test_setOnUpdateParam);
00310 CPPUNIT_TEST(test_setOnSetConfigurationSet);
00311 CPPUNIT_TEST(test_setOnAddConfigurationSet);
00312 CPPUNIT_TEST(test_setOnRemoveConfigurationSet);
00313 CPPUNIT_TEST(test_setOnActivateSet);
00314 CPPUNIT_TEST(test_constructor);
00315 CPPUNIT_TEST(test_bindParameter);
00316 CPPUNIT_TEST(test_bindParameter_already_exist);
00317 CPPUNIT_TEST(test_bindParameter_illegal_default_value);
00318 CPPUNIT_TEST(test_update);
00319 CPPUNIT_TEST(test_update_by_inexist_configuration_set);
00320 CPPUNIT_TEST(test_update_with_specified_parameter_name);
00321 CPPUNIT_TEST(test_update_by_active_configuration_set);
00322 CPPUNIT_TEST(test_isExist);
00323 CPPUNIT_TEST(test_isChanged_on_addConfigurationSet);
00324 CPPUNIT_TEST(test_isChanged_on_removeConfigurationSet);
00325 CPPUNIT_TEST(test_isChanged_on_activateConfigurationSet);
00326 CPPUNIT_TEST(test_getActiveId);
00327 CPPUNIT_TEST(test_haveConfig);
00328 CPPUNIT_TEST(test_isActive_on_addConfigurationSet);
00329 CPPUNIT_TEST(test_isActive_on_removeConfigurationSet);
00330 CPPUNIT_TEST(test_getConfigurationSets);
00331 CPPUNIT_TEST(test_addConfigurationSet_and_getConfigurationSet);
00332 CPPUNIT_TEST(test_setConfigurationSetValues);
00333 CPPUNIT_TEST(test_setConfigurationSetValues_with_inexist_configuration_set);
00334 CPPUNIT_TEST(test_getActiveConfigurationSet);
00335 CPPUNIT_TEST(test_removeConfigurationSet);
00336 CPPUNIT_TEST(test_removeConfigurationSet_with_inexist_configuration_id);
00337
00338 CPPUNIT_TEST_SUITE_END();
00339
00340 private:
00341
00342 const coil::Properties* getPropertiesBy(
00343 const std::string& name,
00344 const std::vector<coil::Properties*>& propertiesSet) const
00345 {
00346 for (int i = 0; i < (int) propertiesSet.size(); ++i)
00347 {
00348 if (std::string(propertiesSet[i]->getName()) == name)
00349 {
00350 return propertiesSet[i];
00351 }
00352 }
00353
00354 return 0;
00355 }
00356
00357 public:
00361 ConfigAdminTests()
00362 {
00363 }
00364
00368 ~ConfigAdminTests()
00369 {
00370 }
00371
00375 virtual void setUp()
00376 {
00377 }
00378
00382 virtual void tearDown()
00383 {
00384 }
00385
00391 void test_constructor()
00392 {
00393 coil::Properties configSet("config_id");
00394 configSet.setProperty("config_id.key", "value");
00395
00396 RTC::ConfigAdmin configAdmin(configSet);
00397
00398
00399 const coil::Properties& activeConfigSet = configAdmin.getConfigurationSet("config_id");
00400 CPPUNIT_ASSERT_EQUAL(std::string("value"), activeConfigSet.getProperty("key"));
00401 }
00402
00409 void test_bindParameter()
00410 {
00411 coil::Properties nullProp;
00412 RTC::ConfigAdmin configAdmin(nullProp);
00413
00414
00415 const char* varName = "name";
00416 double var = 0.0;
00417 const char* default_value = "3.14159";
00418 CPPUNIT_ASSERT_EQUAL(
00419 true, configAdmin.bindParameter(varName, var, default_value));
00420
00421
00422 CPPUNIT_ASSERT_EQUAL(3.14159, var);
00423 }
00424
00430 void test_bindParameter_already_exist()
00431 {
00432 coil::Properties nullProp;
00433 RTC::ConfigAdmin configAdmin(nullProp);
00434
00435
00436 const char* varName1 = "name";
00437 double var1 = 0.0;
00438 const char* default_value1 = "3.14159";
00439 CPPUNIT_ASSERT_EQUAL(
00440 true, configAdmin.bindParameter(varName1, var1, default_value1));
00441 CPPUNIT_ASSERT_EQUAL(3.14159, var1);
00442
00443
00444 const char* varName2 = varName1;
00445 double var2 = 1.0;
00446 const char* default_value2 = "1.41421356";
00447 CPPUNIT_ASSERT_EQUAL(
00448 false, configAdmin.bindParameter(varName2, var2, default_value2));
00449
00450
00451 CPPUNIT_ASSERT_EQUAL(3.14159, var1);
00452 }
00453
00459 void test_bindParameter_illegal_default_value()
00460 {
00461 coil::Properties nullProp;
00462 RTC::ConfigAdmin configAdmin(nullProp);
00463
00464
00465 const char* varName = "name";
00466 double var = 0.0;
00467 const char* default_value = "Illegal default value";
00468 CPPUNIT_ASSERT_EQUAL(
00469 false, configAdmin.bindParameter(varName, var, default_value));
00470 }
00471
00477 void test_update()
00478 {
00479 coil::Properties nullProp;
00480 RTC::ConfigAdmin configAdmin(nullProp);
00481
00482
00483 coil::Properties configSet1("set 1");
00484 configSet1.setProperty("name", "1.41421356");
00485
00486
00487 coil::Properties configSet2("set 2");
00488 configSet2.setProperty("name", "1.7320508");
00489
00490
00491 CPPUNIT_ASSERT_EQUAL(true, configAdmin.addConfigurationSet(configSet1));
00492 CPPUNIT_ASSERT_EQUAL(true, configAdmin.addConfigurationSet(configSet2));
00493
00494
00495 const char* varName = "name";
00496 double var = 0.0;
00497 const char* default_value = "3.14159";
00498 CPPUNIT_ASSERT_EQUAL(
00499 true, configAdmin.bindParameter(varName, var, default_value));
00500
00501
00502 CPPUNIT_ASSERT_EQUAL(3.14159, var);
00503
00504
00505 configAdmin.update("set 1");
00506 CPPUNIT_ASSERT_EQUAL(1.41421356, var);
00507
00508
00509 configAdmin.update("set 2");
00510 CPPUNIT_ASSERT_EQUAL(1.7320508, var);
00511 }
00512
00519 void test_update_by_inexist_configuration_set()
00520 {
00521 coil::Properties nullProp;
00522 RTC::ConfigAdmin configAdmin(nullProp);
00523
00524
00525 coil::Properties configSet("set");
00526 configSet.setProperty("name", "1.41421356");
00527 CPPUNIT_ASSERT_EQUAL(true, configAdmin.addConfigurationSet(configSet));
00528
00529
00530 const char* varName = "name";
00531 double var = 0.0;
00532 const char* default_value = "3.14159";
00533 CPPUNIT_ASSERT_EQUAL(
00534 true, configAdmin.bindParameter(varName, var, default_value));
00535 CPPUNIT_ASSERT_EQUAL(3.14159, var);
00536
00537
00538
00539 configAdmin.update("inexist set");
00540 CPPUNIT_ASSERT_EQUAL(3.14159, var);
00541 }
00542
00548 void test_update_with_specified_parameter_name()
00549 {
00550 coil::Properties nullProp;
00551 RTC::ConfigAdmin configAdmin(nullProp);
00552
00553
00554 coil::Properties configSet1("set 1");
00555 configSet1.setProperty("name 1", "1.41421356");
00556 configSet1.setProperty("name 2", "1.7320508");
00557 CPPUNIT_ASSERT_EQUAL(true, configAdmin.addConfigurationSet(configSet1));
00558
00559 coil::Properties configSet2("set 2");
00560 configSet2.setProperty("name 1", "3.14159");
00561 configSet2.setProperty("name 2", "2.71828");
00562 CPPUNIT_ASSERT_EQUAL(true, configAdmin.addConfigurationSet(configSet2));
00563
00564
00565 const char* varName1 = "name 1";
00566 double var1 = 0.0;
00567 const char* default_value1 = "2.23620679";
00568 CPPUNIT_ASSERT_EQUAL(
00569 true, configAdmin.bindParameter(varName1, var1, default_value1));
00570 CPPUNIT_ASSERT_EQUAL(2.23620679, var1);
00571
00572 const char* varName2 = "name 2";
00573 double var2 = 0.0;
00574 const char* default_value2 = "2.4494897";
00575 CPPUNIT_ASSERT_EQUAL(
00576 true, configAdmin.bindParameter(varName2, var2, default_value2));
00577 CPPUNIT_ASSERT_EQUAL(2.4494897, var2);
00578
00579
00580 configAdmin.update("set 2", "name 1");
00581 CPPUNIT_ASSERT_EQUAL(3.14159, var1);
00582 CPPUNIT_ASSERT_EQUAL(2.4494897, var2);
00583 }
00584
00590 void test_update_by_active_configuration_set()
00591 {
00592 coil::Properties nullProp;
00593 RTC::ConfigAdmin configAdmin(nullProp);
00594
00595
00596 coil::Properties configSet1("set 1");
00597 configSet1.setProperty("name", "1.41421356");
00598 CPPUNIT_ASSERT_EQUAL(true, configAdmin.addConfigurationSet(configSet1));
00599
00600 coil::Properties configSet2("set 2");
00601 configSet2.setProperty("name", "1.7320508");
00602 CPPUNIT_ASSERT_EQUAL(true, configAdmin.addConfigurationSet(configSet2));
00603
00604
00605 const char* varName = "name";
00606 double var = 0.0;
00607 const char* default_value = "3.14159";
00608 CPPUNIT_ASSERT_EQUAL(
00609 true, configAdmin.bindParameter(varName, var, default_value));
00610 CPPUNIT_ASSERT_EQUAL(3.14159, var);
00611
00612
00613 CPPUNIT_ASSERT_EQUAL(true, configAdmin.activateConfigurationSet("set 1"));
00614
00615
00616 CPPUNIT_ASSERT_EQUAL(3.14159, var);
00617
00618
00619 configAdmin.update();
00620 CPPUNIT_ASSERT_EQUAL(1.41421356, var);
00621
00622
00623 CPPUNIT_ASSERT_EQUAL(true, configAdmin.activateConfigurationSet("set 2"));
00624
00625
00626 CPPUNIT_ASSERT_EQUAL(1.41421356, var);
00627
00628
00629 configAdmin.update();
00630 CPPUNIT_ASSERT_EQUAL(1.7320508, var);
00631 }
00632
00639 void test_isExist()
00640 {
00641 coil::Properties nullProp;
00642 RTC::ConfigAdmin configAdmin(nullProp);
00643
00644
00645 const char* varName = "name";
00646 double var = 0.0;
00647 const char* default_value = "3.14159";
00648 CPPUNIT_ASSERT_EQUAL(
00649 true, configAdmin.bindParameter(varName, var, default_value));
00650 CPPUNIT_ASSERT_EQUAL(3.14159, var);
00651
00652
00653 CPPUNIT_ASSERT_EQUAL(true, configAdmin.isExist("name"));
00654
00655
00656 CPPUNIT_ASSERT_EQUAL(false, configAdmin.isExist("inexist name"));
00657 }
00658
00664 void test_isChanged_on_addConfigurationSet()
00665 {
00666 coil::Properties nullProp;
00667 RTC::ConfigAdmin configAdmin(nullProp);
00668
00669
00670 configAdmin.update();
00671 CPPUNIT_ASSERT_EQUAL(false, configAdmin.isChanged());
00672
00673
00674 coil::Properties configSet("id");
00675 configSet.setProperty("key", "value");
00676 CPPUNIT_ASSERT_EQUAL(true, configAdmin.addConfigurationSet(configSet));
00677
00678
00679 CPPUNIT_ASSERT_EQUAL(true, configAdmin.isChanged());
00680 }
00681
00687 void test_isChanged_on_removeConfigurationSet()
00688 {
00689 coil::Properties nullProp;
00690 RTC::ConfigAdmin configAdmin(nullProp);
00691
00692
00693 coil::Properties configSet("id");
00694 configSet.setProperty("key", "value");
00695 CPPUNIT_ASSERT_EQUAL(true, configAdmin.addConfigurationSet(configSet));
00696
00697
00698 CPPUNIT_ASSERT_EQUAL(true, configAdmin.activateConfigurationSet("id"));
00699 configAdmin.update();
00700 CPPUNIT_ASSERT_EQUAL(false, configAdmin.isChanged());
00701
00702
00703
00704
00705 }
00706
00712 void test_isChanged_on_activateConfigurationSet()
00713 {
00714 coil::Properties nullProp;
00715 RTC::ConfigAdmin configAdmin(nullProp);
00716
00717
00718 coil::Properties configSet1("set 1");
00719 CPPUNIT_ASSERT_EQUAL(true, configAdmin.addConfigurationSet(configSet1));
00720
00721 coil::Properties configSet2("set 2");
00722 CPPUNIT_ASSERT_EQUAL(true, configAdmin.addConfigurationSet(configSet2));
00723
00724
00725 CPPUNIT_ASSERT_EQUAL(true, configAdmin.activateConfigurationSet("set 1"));
00726
00727
00728 configAdmin.update();
00729 CPPUNIT_ASSERT_EQUAL(false, configAdmin.isChanged());
00730
00731
00732 CPPUNIT_ASSERT_EQUAL(true, configAdmin.activateConfigurationSet("set 2"));
00733 CPPUNIT_ASSERT_EQUAL(true, configAdmin.isChanged());
00734 }
00735
00736 void test_isChanged_on_setConfigurationSetValues()
00737 {
00738
00739 }
00740
00746 void test_getActiveId()
00747 {
00748 coil::Properties nullProp;
00749 RTC::ConfigAdmin configAdmin(nullProp);
00750
00751
00752 coil::Properties configSet1("set 1");
00753 CPPUNIT_ASSERT_EQUAL(true, configAdmin.addConfigurationSet(configSet1));
00754
00755 coil::Properties configSet2("set 2");
00756 CPPUNIT_ASSERT_EQUAL(true, configAdmin.addConfigurationSet(configSet2));
00757
00758
00759 CPPUNIT_ASSERT_EQUAL(std::string("default"), std::string(configAdmin.getActiveId()));
00760
00761
00762 CPPUNIT_ASSERT_EQUAL(true, configAdmin.activateConfigurationSet("set 1"));
00763 CPPUNIT_ASSERT_EQUAL(std::string("set 1"), std::string(configAdmin.getActiveId()));
00764
00765
00766 CPPUNIT_ASSERT_EQUAL(true, configAdmin.activateConfigurationSet("set 2"));
00767 CPPUNIT_ASSERT_EQUAL(std::string("set 2"), std::string(configAdmin.getActiveId()));
00768 }
00769
00776 void test_haveConfig()
00777 {
00778 coil::Properties nullProp;
00779 RTC::ConfigAdmin configAdmin(nullProp);
00780
00781
00782 coil::Properties configSet1("id");
00783 CPPUNIT_ASSERT_EQUAL(true, configAdmin.addConfigurationSet(configSet1));
00784
00785
00786 CPPUNIT_ASSERT_EQUAL(true, configAdmin.haveConfig("id"));
00787
00788
00789 CPPUNIT_ASSERT_EQUAL(false, configAdmin.haveConfig("inexist id"));
00790 }
00791
00798 void test_isActive_on_addConfigurationSet()
00799 {
00800 coil::Properties nullProp;
00801 RTC::ConfigAdmin configAdmin(nullProp);
00802
00803
00804 coil::Properties configSet("id");
00805 CPPUNIT_ASSERT_EQUAL(true, configAdmin.addConfigurationSet(configSet));
00806 CPPUNIT_ASSERT_EQUAL(false, configAdmin.isActive());
00807
00808
00809 CPPUNIT_ASSERT_EQUAL(true, configAdmin.activateConfigurationSet("id"));
00810 CPPUNIT_ASSERT_EQUAL(true, configAdmin.isActive());
00811 }
00812
00818 void test_isActive_on_removeConfigurationSet()
00819 {
00820 coil::Properties nullProp;
00821 RTC::ConfigAdmin configAdmin(nullProp);
00822
00823
00824 coil::Properties configSet("id");
00825 CPPUNIT_ASSERT_EQUAL(true, configAdmin.addConfigurationSet(configSet));
00826 CPPUNIT_ASSERT_EQUAL(true, configAdmin.activateConfigurationSet("id"));
00827 CPPUNIT_ASSERT_EQUAL(true, configAdmin.isActive());
00828
00829
00830
00831
00832
00833 }
00834
00840 void test_isActive_on_activateConfigurationSet()
00841 {
00842
00843 }
00844
00845 void test_isActive_on_setConfigurationSetValues()
00846 {
00847
00848 }
00849
00855 void test_getConfigurationSets()
00856 {
00857 coil::Properties nullProp;
00858 RTC::ConfigAdmin configAdmin(nullProp);
00859
00860
00861 coil::Properties configSet1("set 1");
00862 configSet1.setProperty("name 1", "1.41421356");
00863 configSet1.setProperty("name 2", "1.7320508");
00864 CPPUNIT_ASSERT_EQUAL(true, configAdmin.addConfigurationSet(configSet1));
00865
00866 coil::Properties configSet2("set 2");
00867 configSet2.setProperty("name 1", "3.14159");
00868 configSet2.setProperty("name 2", "2.71828");
00869 CPPUNIT_ASSERT_EQUAL(true, configAdmin.addConfigurationSet(configSet2));
00870
00871
00872
00873 std::vector<coil::Properties*> expectedConfigSets;
00874 expectedConfigSets.push_back(&configSet1);
00875 expectedConfigSets.push_back(&configSet2);
00876
00877 const std::vector<coil::Properties*>& configSets
00878 = configAdmin.getConfigurationSets();
00879
00880 CPPUNIT_ASSERT_EQUAL(
00881 std::string("1.41421356"),
00882 getPropertiesBy("set 1", configSets)->getProperty("name 1"));
00883 CPPUNIT_ASSERT_EQUAL(
00884 std::string("1.7320508"),
00885 getPropertiesBy("set 1", configSets)->getProperty("name 2"));
00886
00887 CPPUNIT_ASSERT_EQUAL(
00888 std::string("3.14159"),
00889 getPropertiesBy("set 2", configSets)->getProperty("name 1"));
00890 CPPUNIT_ASSERT_EQUAL(
00891 std::string("2.71828"),
00892 getPropertiesBy("set 2", configSets)->getProperty("name 2"));
00893 }
00894
00901 void test_addConfigurationSet_and_getConfigurationSet()
00902 {
00903 coil::Properties nullProp;
00904 RTC::ConfigAdmin configAdmin(nullProp);
00905
00906
00907 coil::Properties configSet("id");
00908 configSet.setProperty("key", "value");
00909 configAdmin.addConfigurationSet(configSet);
00910
00911
00912 const coil::Properties& configSetRet = configAdmin.getConfigurationSet("id");
00913 CPPUNIT_ASSERT_EQUAL(std::string("value"), configSetRet.getProperty("key"));
00914 }
00915
00921 void test_setConfigurationSetValues()
00922 {
00923 coil::Properties nullProp;
00924 RTC::ConfigAdmin configAdmin(nullProp);
00925
00926 coil::Properties configSet1("id");
00927 configSet1.setProperty("name 1", "1.41421356");
00928 CPPUNIT_ASSERT_EQUAL(true, configAdmin.addConfigurationSet(configSet1));
00929
00930
00931 coil::Properties configSet2("id");
00932 configSet2.setProperty("name 2", "1.7320508");
00933 CPPUNIT_ASSERT_EQUAL(true, configAdmin.setConfigurationSetValues(configSet2));
00934
00935
00936 const coil::Properties& configSetRet = configAdmin.getConfigurationSet("id");
00937 CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), configSetRet.getProperty("name 1"));
00938 CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), configSetRet.getProperty("name 2"));
00939 }
00940
00947 void test_setConfigurationSetValues_with_inexist_configuration_set()
00948 {
00949 coil::Properties nullProp;
00950 RTC::ConfigAdmin configAdmin(nullProp);
00951
00952 coil::Properties configSet1("id");
00953 configSet1.setProperty("name 1", "1.41421356");
00954 CPPUNIT_ASSERT_EQUAL(true, configAdmin.addConfigurationSet(configSet1));
00955
00956
00957 coil::Properties configSet2("inexist id");
00958 configSet2.setProperty("name 2", "1.7320508");
00959 CPPUNIT_ASSERT_EQUAL(true, configAdmin.setConfigurationSetValues(configSet2));
00960
00961
00962 const coil::Properties& configSetRet = configAdmin.getConfigurationSet("id");
00963 CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), configSetRet.getProperty("name 1"));
00964 CPPUNIT_ASSERT_EQUAL(std::string(""), configSetRet.getProperty("name 2"));
00965 }
00966
00972 void test_getActiveConfigurationSet()
00973 {
00974 coil::Properties nullProp;
00975 RTC::ConfigAdmin configAdmin(nullProp);
00976
00977
00978 coil::Properties configSet1("set 1");
00979 configSet1.setProperty("name 1", "1.41421356");
00980 configSet1.setProperty("name 2", "1.7320508");
00981 CPPUNIT_ASSERT_EQUAL(true, configAdmin.addConfigurationSet(configSet1));
00982
00983 coil::Properties configSet2("set 2");
00984 configSet2.setProperty("name 1", "3.14159");
00985 configSet2.setProperty("name 2", "2.71828");
00986 CPPUNIT_ASSERT_EQUAL(true, configAdmin.addConfigurationSet(configSet2));
00987
00988
00989 CPPUNIT_ASSERT_EQUAL(true, configAdmin.activateConfigurationSet("set 1"));
00990 const coil::Properties& activeConfigSet1 = configAdmin.getActiveConfigurationSet();
00991 CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), activeConfigSet1.getProperty("name 1"));
00992 CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), activeConfigSet1.getProperty("name 2"));
00993
00994
00995 CPPUNIT_ASSERT_EQUAL(true, configAdmin.activateConfigurationSet("set 2"));
00996 const coil::Properties& activeConfigSet2 = configAdmin.getActiveConfigurationSet();
00997 CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), activeConfigSet2.getProperty("name 1"));
00998 CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), activeConfigSet2.getProperty("name 2"));
00999 }
01000
01006 void test_removeConfigurationSet()
01007 {
01008 coil::Properties nullProp;
01009 RTC::ConfigAdmin configAdmin(nullProp);
01010
01011
01012 coil::Properties configSet("id");
01013 configSet.setProperty("key", "value");
01014 CPPUNIT_ASSERT_EQUAL(true, configAdmin.addConfigurationSet(configSet));
01015 CPPUNIT_ASSERT_EQUAL(true, configAdmin.haveConfig("id"));
01016
01017
01018 CPPUNIT_ASSERT_EQUAL(true, configAdmin.removeConfigurationSet("id"));
01019
01020
01021 CPPUNIT_ASSERT_EQUAL(false, configAdmin.haveConfig("id"));
01022 }
01023
01029 void test_removeConfigurationSet_with_inexist_configuration_id()
01030 {
01031 coil::Properties nullProp;
01032 RTC::ConfigAdmin configAdmin(nullProp);
01033
01034
01035 coil::Properties configSet("id");
01036 configSet.setProperty("key", "value");
01037 CPPUNIT_ASSERT_EQUAL(true, configAdmin.addConfigurationSet(configSet));
01038 CPPUNIT_ASSERT_EQUAL(true, configAdmin.haveConfig("id"));
01039
01040
01041 CPPUNIT_ASSERT_EQUAL(false, configAdmin.removeConfigurationSet("inexist id"));
01042
01043
01044 CPPUNIT_ASSERT_EQUAL(true, configAdmin.haveConfig("id"));
01045 }
01046
01047 void test_activateConfigurationSet()
01048 {
01049
01050 }
01051
01057 void test_setOnUpdate()
01058 {
01059 coil::Properties configSet("config_id");
01060 configSet.setProperty("config_id.key", "value");
01061 ConfigAdminMock configAdmin(configSet);
01062
01063 OnUpdateCallbackMock* cdm1 = new OnUpdateCallbackMock();
01064 OnUpdateCallbackMock* cdm2 = new OnUpdateCallbackMock();
01065
01066
01067 configAdmin.setOnUpdate(cdm1);
01068 CPPUNIT_ASSERT(!cdm1->result);
01069 configAdmin.onUpdateMock("config_id");
01070 CPPUNIT_ASSERT(cdm1->result);
01071
01072
01073 configAdmin.setOnUpdate(cdm2);
01074 CPPUNIT_ASSERT(!cdm2->result);
01075 configAdmin.onUpdateMock("config_id");
01076 CPPUNIT_ASSERT(cdm2->result);
01077
01078
01079
01080 }
01081
01087 void test_setOnUpdateParam()
01088 {
01089 coil::Properties configSet("config_id");
01090 configSet.setProperty("config_id.key", "value");
01091 ConfigAdminMock configAdmin(configSet);
01092
01093 OnUpdateParamCallbackMock* cdm1 = new OnUpdateParamCallbackMock();
01094 OnUpdateParamCallbackMock* cdm2 = new OnUpdateParamCallbackMock();
01095
01096
01097 configAdmin.setOnUpdateParam(cdm1);
01098 CPPUNIT_ASSERT(!cdm1->result);
01099 configAdmin.onUpdateParamMock("config_id", "param1");
01100 CPPUNIT_ASSERT(cdm1->result);
01101
01102
01103 configAdmin.setOnUpdateParam(cdm2);
01104 CPPUNIT_ASSERT(!cdm2->result);
01105 configAdmin.onUpdateParamMock("config_id", "param2");
01106 CPPUNIT_ASSERT(cdm2->result);
01107
01108
01109
01110 }
01111
01117 void test_setOnSetConfigurationSet()
01118 {
01119 coil::Properties configSet("config_id");
01120 configSet.setProperty("config_id.key", "value");
01121 ConfigAdminMock configAdmin(configSet);
01122 coil::Properties configSet2("config_id2");
01123 configSet2.setProperty("config_id2.key", "value2");
01124
01125 OnSetConfigurationSetCallbackMock* cdm1 = new OnSetConfigurationSetCallbackMock();
01126 OnSetConfigurationSetCallbackMock* cdm2 = new OnSetConfigurationSetCallbackMock();
01127
01128
01129 configAdmin.setOnSetConfigurationSet(cdm1);
01130 CPPUNIT_ASSERT(!cdm1->result);
01131 configAdmin.onSetConfigurationSetMock(configSet);
01132 CPPUNIT_ASSERT(cdm1->result);
01133
01134
01135 configAdmin.setOnSetConfigurationSet(cdm2);
01136 CPPUNIT_ASSERT(!cdm2->result);
01137 configAdmin.onSetConfigurationSetMock(configSet2);
01138 CPPUNIT_ASSERT(cdm2->result);
01139
01140
01141
01142 }
01143
01149 void test_setOnAddConfigurationSet()
01150 {
01151 coil::Properties configSet("config_id");
01152 configSet.setProperty("config_id.key", "value");
01153 ConfigAdminMock configAdmin(configSet);
01154 coil::Properties configSet2("config_id2");
01155 configSet2.setProperty("config_id2.key", "value2");
01156
01157 OnAddConfigurationAddCallbackMock* cdm1 = new OnAddConfigurationAddCallbackMock();
01158 OnAddConfigurationAddCallbackMock* cdm2 = new OnAddConfigurationAddCallbackMock();
01159
01160
01161 configAdmin.setOnAddConfigurationSet(cdm1);
01162 CPPUNIT_ASSERT(!cdm1->result);
01163 configAdmin.onAddConfigurationSetMock(configSet);
01164 CPPUNIT_ASSERT(cdm1->result);
01165
01166
01167 configAdmin.setOnAddConfigurationSet(cdm2);
01168 CPPUNIT_ASSERT(!cdm2->result);
01169 configAdmin.onAddConfigurationSetMock(configSet2);
01170 CPPUNIT_ASSERT(cdm2->result);
01171
01172
01173
01174 }
01175
01181 void test_setOnRemoveConfigurationSet()
01182 {
01183 coil::Properties configSet("config_id");
01184 configSet.setProperty("config_id.key", "value");
01185 ConfigAdminMock configAdmin(configSet);
01186
01187 OnRemoveConfigurationSetCallbackMock* cdm1 = new OnRemoveConfigurationSetCallbackMock();
01188 OnRemoveConfigurationSetCallbackMock* cdm2 = new OnRemoveConfigurationSetCallbackMock();
01189
01190
01191 configAdmin.setOnRemoveConfigurationSet(cdm1);
01192 CPPUNIT_ASSERT(!cdm1->result);
01193 configAdmin.onRemoveConfigurationSetMock("config_id");
01194 CPPUNIT_ASSERT(cdm1->result);
01195
01196
01197 configAdmin.setOnRemoveConfigurationSet(cdm2);
01198 CPPUNIT_ASSERT(!cdm2->result);
01199 configAdmin.onRemoveConfigurationSetMock("config_id2");
01200 CPPUNIT_ASSERT(cdm2->result);
01201
01202
01203
01204 }
01205
01211 void test_setOnActivateSet()
01212 {
01213 coil::Properties configSet("config_id");
01214 configSet.setProperty("config_id.key", "value");
01215 ConfigAdminMock configAdmin(configSet);
01216
01217 OnActivateSetCallbackMock* cdm1 = new OnActivateSetCallbackMock();
01218 OnActivateSetCallbackMock* cdm2 = new OnActivateSetCallbackMock();
01219
01220
01221 configAdmin.setOnActivateSet(cdm1);
01222 CPPUNIT_ASSERT(!cdm1->result);
01223 configAdmin.onActivateSetMock("config_id");
01224 CPPUNIT_ASSERT(cdm1->result);
01225
01226
01227 configAdmin.setOnActivateSet(cdm2);
01228 CPPUNIT_ASSERT(!cdm2->result);
01229 configAdmin.onActivateSetMock("config_id2");
01230 CPPUNIT_ASSERT(cdm2->result);
01231
01232
01233
01234 }
01235
01236
01237 };
01238 };
01239
01240
01241
01242
01243
01244 CPPUNIT_TEST_SUITE_REGISTRATION(Config::ConfigTests);
01245 CPPUNIT_TEST_SUITE_REGISTRATION(ConfigAdmin::ConfigAdminTests);
01246
01247 #ifdef LOCAL_MAIN
01248 int main(int argc, char* argv[])
01249 {
01250
01251 FORMAT format = TEXT_OUT;
01252 int target = 0;
01253 std::string xsl;
01254 std::string ns;
01255 std::string fname;
01256 std::ofstream ofs;
01257
01258 int i(1);
01259 while (i < argc)
01260 {
01261 std::string arg(argv[i]);
01262 std::string next_arg;
01263 if (i + 1 < argc) next_arg = argv[i + 1];
01264 else next_arg = "";
01265
01266 if (arg == "--text") { format = TEXT_OUT; break; }
01267 if (arg == "--xml")
01268 {
01269 if (next_arg == "")
01270 {
01271 fname = argv[0];
01272 fname += ".xml";
01273 }
01274 else
01275 {
01276 fname = next_arg;
01277 }
01278 format = XML_OUT;
01279 ofs.open(fname.c_str());
01280 }
01281 if ( arg == "--compiler" ) { format = COMPILER_OUT; break; }
01282 if ( arg == "--cerr" ) { target = 1; break; }
01283 if ( arg == "--xsl" )
01284 {
01285 if (next_arg == "") xsl = "default.xsl";
01286 else xsl = next_arg;
01287 }
01288 if ( arg == "--namespace" )
01289 {
01290 if (next_arg == "")
01291 {
01292 std::cerr << "no namespace specified" << std::endl;
01293 exit(1);
01294 }
01295 else
01296 {
01297 xsl = next_arg;
01298 }
01299 }
01300 ++i;
01301 }
01302 CppUnit::TextUi::TestRunner runner;
01303 if ( ns.empty() )
01304 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
01305 else
01306 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
01307 CppUnit::Outputter* outputter = 0;
01308 std::ostream* stream = target ? &std::cerr : &std::cout;
01309 switch ( format )
01310 {
01311 case TEXT_OUT :
01312 outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
01313 break;
01314 case XML_OUT :
01315 std::cout << "XML_OUT" << std::endl;
01316 outputter = new CppUnit::XmlOutputter(&runner.result(),
01317 ofs, "shift_jis");
01318 static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
01319 break;
01320 case COMPILER_OUT :
01321 outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
01322 break;
01323 }
01324 runner.setOutputter(outputter);
01325 runner.run();
01326 return 0;
01327 }
01328 #endif // MAIN
01329 #endif // ConfigAdmin_cpp