00001
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 #ifndef SdoConfiguration_cpp
00050 #define SdoConfiguration_cpp
00051
00052 #include <cppunit/ui/text/TestRunner.h>
00053 #include <cppunit/TextOutputter.h>
00054 #include <cppunit/extensions/TestFactoryRegistry.h>
00055 #include <cppunit/extensions/HelperMacros.h>
00056 #include <cppunit/TestAssert.h>
00057
00058 #include <vector>
00059 #include <string>
00060
00061 #include <rtm/CORBA_SeqUtil.h>
00062 #include <rtm/SdoConfiguration.h>
00063 #include <rtm/RTObject.h>
00064 #include <rtm/Manager.h>
00065 #include <rtm/SdoOrganization.h>
00066
00071 namespace SdoConfiguration
00072 {
00073 using namespace SDOPackage;
00074 using namespace std;
00075
00076 struct ServiceProfileFinder
00077 {
00078 ServiceProfileFinder(const std::string& id) : _id(id) { }
00079
00080 bool operator()(const ServiceProfile& svcProf)
00081 {
00082 return (_id == std::string(svcProf.id));
00083 }
00084
00085 std::string _id;
00086 };
00087
00088 class SdoConfigurationTests
00089 : public CppUnit::TestFixture
00090 {
00091 CPPUNIT_TEST_SUITE(SdoConfigurationTests);
00092
00093 CPPUNIT_TEST(test_set_device_profile_and_getDeviceProfile);
00094 CPPUNIT_TEST(test_set_service_profile_and_getServiceProfile);
00095 CPPUNIT_TEST(test_getServiceProfiles);
00096 CPPUNIT_TEST(test_remove_service_profile);
00097 CPPUNIT_TEST(test_add_organization_and_getOrganizations);
00098 CPPUNIT_TEST(test_remove_organization);
00099 CPPUNIT_TEST(test_add_configuration_set_and_get_configuration_set);
00100 CPPUNIT_TEST(test_remove_configuration_set);
00101 CPPUNIT_TEST(test_set_configuration_set_values);
00102 CPPUNIT_TEST(test_activate_configuration_set_and_get_active_configuration_set);
00103
00104
00105
00106
00107
00108 CPPUNIT_TEST_SUITE_END();
00109
00110 private:
00111 CORBA::ORB_ptr m_pORB;
00112 PortableServer::POA_ptr m_pPOA;
00113
00114 public:
00118 SdoConfigurationTests()
00119 {
00120 int argc(0);
00121 char** argv(NULL);
00122 m_pORB = CORBA::ORB_init(argc, argv);
00123 m_pPOA = PortableServer::POA::_narrow(
00124 m_pORB->resolve_initial_references("RootPOA"));
00125 m_pPOA->the_POAManager()->activate();
00126 }
00127
00131 ~SdoConfigurationTests()
00132 {
00133 }
00134
00138 virtual void setUp()
00139 {
00140 usleep(100000);
00141 }
00142
00146 virtual void tearDown()
00147 {
00148 }
00149
00155 void test_set_device_profile_and_getDeviceProfile()
00156 {
00157
00158 coil::Properties cfgAdminProp;
00159 RTC::ConfigAdmin cfgAdmin(cfgAdminProp);
00160 SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin);
00161
00162
00163 SDOPackage::DeviceProfile devProf;
00164 devProf.device_type = "DEVICE_TYPE";
00165 devProf.manufacturer = "MANUFACTURER";
00166 devProf.model = "MODEL";
00167 devProf.version = "VERSION";
00168 {
00169 SDOPackage::NVList properties;
00170 properties.length(2);
00171 properties[0].name = "name 0";
00172 properties[0].value <<= CORBA::Float(3.14159);
00173 properties[1].name = "name 1";
00174 properties[1].value <<= CORBA::Float(2.71828);
00175 devProf.properties = properties;
00176 }
00177
00178
00179 CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_device_profile(devProf));
00180
00181
00182 const SDOPackage::DeviceProfile devProfRet = sdoCfg->getDeviceProfile();
00183 CPPUNIT_ASSERT_EQUAL(std::string("DEVICE_TYPE"),
00184 std::string(devProfRet.device_type));
00185 CPPUNIT_ASSERT_EQUAL(std::string("MANUFACTURER"),
00186 std::string(devProfRet.manufacturer));
00187 CPPUNIT_ASSERT_EQUAL(std::string("MODEL"),
00188 std::string(devProfRet.model));
00189 CPPUNIT_ASSERT_EQUAL(std::string("VERSION"),
00190 std::string(devProfRet.version));
00191 CPPUNIT_ASSERT_EQUAL(std::string("name 0"),
00192 std::string(devProfRet.properties[0].name));
00193 {
00194 CORBA::Float value; devProfRet.properties[0].value >>= value;
00195 CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value);
00196 }
00197 CPPUNIT_ASSERT_EQUAL(std::string("name 1"),
00198 std::string(devProfRet.properties[1].name));
00199 {
00200 CORBA::Float value; devProfRet.properties[1].value >>= value;
00201 CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value);
00202 }
00203 sdoCfg->_remove_ref();
00204
00205 }
00206
00212 void test_set_service_profile_and_getServiceProfile()
00213 {
00214
00215 coil::Properties cfgAdminProp;
00216 RTC::ConfigAdmin cfgAdmin(cfgAdminProp);
00217 SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin);
00218
00219
00220 SDOPackage::ServiceProfile svcProf;
00221 svcProf.id = "ID";
00222 svcProf.interface_type = "INTERFACE_TYPE";
00223 {
00224 SDOPackage::NVList properties;
00225 properties.length(2);
00226 properties[0].name = "name 0";
00227 properties[0].value <<= CORBA::Float(3.14159);
00228 properties[1].name = "name 1";
00229 properties[1].value <<= CORBA::Float(2.71828);
00230 svcProf.properties = properties;
00231 }
00232
00233
00234 CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf));
00235
00236
00237 const SDOPackage::ServiceProfile svcProfRet = sdoCfg->getServiceProfile("ID");
00238 CPPUNIT_ASSERT_EQUAL(std::string("ID"), std::string(svcProfRet.id));
00239 CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE"),
00240 std::string(svcProfRet.interface_type));
00241 CPPUNIT_ASSERT_EQUAL(std::string("name 0"),
00242 std::string(svcProfRet.properties[0].name));
00243 {
00244 CORBA::Float value; svcProfRet.properties[0].value >>= value;
00245 CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value);
00246 }
00247 CPPUNIT_ASSERT_EQUAL(std::string("name 1"),
00248 std::string(svcProfRet.properties[1].name));
00249 {
00250 CORBA::Float value; svcProfRet.properties[1].value >>= value;
00251 CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value);
00252 }
00253 sdoCfg->_remove_ref();
00254
00255 }
00256
00262 void test_getServiceProfiles()
00263 {
00264
00265 coil::Properties cfgAdminProp;
00266 RTC::ConfigAdmin cfgAdmin(cfgAdminProp);
00267 SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin);
00268
00269
00270 SDOPackage::ServiceProfile svcProf0;
00271 svcProf0.id = "ID 0";
00272 svcProf0.interface_type = "INTERFACE_TYPE 0";
00273 {
00274 SDOPackage::NVList properties;
00275 properties.length(2);
00276 properties[0].name = "name 0-0";
00277 properties[0].value <<= CORBA::Float(3.14159);
00278 properties[1].name = "name 0-1";
00279 properties[1].value <<= CORBA::Float(2.71828);
00280 svcProf0.properties = properties;
00281 }
00282
00283 SDOPackage::ServiceProfile svcProf1;
00284 svcProf1.id = "ID 1";
00285 svcProf1.interface_type = "INTERFACE_TYPE 1";
00286 {
00287 SDOPackage::NVList properties;
00288 properties.length(2);
00289 properties[0].name = "name 1-0";
00290 properties[0].value <<= CORBA::Float(1.41421356);
00291 properties[1].name = "name 1-1";
00292 properties[1].value <<= CORBA::Float(1.7320508);
00293 svcProf1.properties = properties;
00294 }
00295
00296
00297 CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf0));
00298 CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf1));
00299
00300
00301 const SDOPackage::ServiceProfileList svcProfList = sdoCfg->getServiceProfiles();
00302 CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), svcProfList.length());
00303
00304
00305 {
00306 CORBA::ULong idx = CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 0"));
00307
00308 CPPUNIT_ASSERT_EQUAL(std::string("ID 0"),
00309 std::string(svcProfList[idx].id));
00310 CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 0"),
00311 std::string(svcProfList[idx].interface_type));
00312 CPPUNIT_ASSERT_EQUAL(std::string("name 0-0"),
00313 std::string(svcProfList[idx].properties[0].name));
00314 {
00315 CORBA::Float value; svcProfList[idx].properties[0].value >>= value;
00316 CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value);
00317 }
00318 CPPUNIT_ASSERT_EQUAL(std::string("name 0-1"),
00319 std::string(svcProfList[idx].properties[1].name));
00320 {
00321 CORBA::Float value; svcProfList[idx].properties[1].value >>= value;
00322 CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value);
00323 }
00324 }
00325
00326 {
00327 CORBA::ULong idx = CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 1"));
00328
00329 CPPUNIT_ASSERT_EQUAL(std::string("ID 1"),
00330 std::string(svcProfList[idx].id));
00331 CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"),
00332 std::string(svcProfList[idx].interface_type));
00333 CPPUNIT_ASSERT_EQUAL(std::string("name 1-0"),
00334 std::string(svcProfList[idx].properties[0].name));
00335 {
00336 CORBA::Float value; svcProfList[idx].properties[0].value >>= value;
00337 CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.41421356), value);
00338 }
00339 CPPUNIT_ASSERT_EQUAL(std::string("name 1-1"),
00340 std::string(svcProfList[idx].properties[1].name));
00341 {
00342 CORBA::Float value; svcProfList[idx].properties[1].value >>= value;
00343 CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.7320508), value);
00344 }
00345 }
00346 sdoCfg->_remove_ref();
00347
00348 }
00349
00355 void test_remove_service_profile()
00356 {
00357
00358 coil::Properties cfgAdminProp;
00359 RTC::ConfigAdmin cfgAdmin(cfgAdminProp);
00360 SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin);
00361
00362
00363 SDOPackage::ServiceProfile svcProf0;
00364 svcProf0.id = "ID 0";
00365 svcProf0.interface_type = "INTERFACE_TYPE 0";
00366 {
00367 SDOPackage::NVList properties;
00368 properties.length(2);
00369 properties[0].name = "name 0-0";
00370 properties[0].value <<= CORBA::Float(3.14159);
00371 properties[1].name = "name 0-1";
00372 properties[1].value <<= CORBA::Float(2.71828);
00373 svcProf0.properties = properties;
00374 }
00375
00376 SDOPackage::ServiceProfile svcProf1;
00377 svcProf1.id = "ID 1";
00378 svcProf1.interface_type = "INTERFACE_TYPE 1";
00379 {
00380 SDOPackage::NVList properties;
00381 properties.length(2);
00382 properties[0].name = "name 1-0";
00383 properties[0].value <<= CORBA::Float(1.41421356);
00384 properties[1].name = "name 1-1";
00385 properties[1].value <<= CORBA::Float(1.7320508);
00386 svcProf1.properties = properties;
00387 }
00388
00389
00390 CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf0));
00391 CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf1));
00392
00393
00394 CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_service_profile("ID 0"));
00395
00396
00397 const SDOPackage::ServiceProfileList svcProfList = sdoCfg->getServiceProfiles();
00398 CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfList.length());
00399 CPPUNIT_ASSERT_EQUAL(CORBA::Long(-1),
00400 CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 0")));
00401
00402
00403 CPPUNIT_ASSERT_EQUAL(CORBA::Long(0),
00404 CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 1")));
00405
00406 sdoCfg->_remove_ref();
00407
00408 }
00409
00410
00411
00412
00413
00414
00415
00416 void test_add_organization_and_getOrganizations()
00417 {
00418
00419 coil::Properties cfgAdminProp;
00420 RTC::ConfigAdmin cfgAdmin(cfgAdminProp);
00421 SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin);
00422
00423
00424 SDOPackage::Organization_var org1;
00425 CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true),
00426 sdoCfg->add_organization(org1._retn()));
00427
00428 SDOPackage::Organization_var org2;
00429 CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true),
00430 sdoCfg->add_organization(org2._retn()));
00431
00432
00433 SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations();
00434 CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList.length());
00435
00436 sdoCfg->_remove_ref();
00437
00438 }
00439
00440
00441
00442
00443
00444 void test_remove_organization()
00445 {
00446
00447 coil::Properties cfgAdminProp;
00448 RTC::ConfigAdmin cfgAdmin(cfgAdminProp);
00449 SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin);
00450 RTC::RTObject_impl* rtobj;
00451 SDOPackage::Organization_impl* m_pOi;
00452 RTC::Manager& mgr(RTC::Manager::instance());
00453 rtobj = new ::RTC::RTObject_impl(&mgr);
00454 m_pOi = new Organization_impl(rtobj->getObjRef());
00455
00456
00457 CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true),
00458 sdoCfg->add_organization(m_pOi->getObjRef()));
00459
00460
00461 std::string id(m_pOi->get_organization_id());
00462
00463
00464 CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true),
00465 sdoCfg->remove_organization(id.c_str()));
00466
00467
00468 SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations();
00469 CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), orgList.length());
00470
00471 m_pOi->_remove_ref();
00472 rtobj->_remove_ref();
00473 sdoCfg->_remove_ref();
00474
00475 }
00476
00477
00478
00479
00480 void test_get_configuration_parameters()
00481 {
00482
00483
00484
00485
00486 }
00487
00491 void test_get_configuration_parameter_values()
00492 {
00493
00494
00495
00496
00497 }
00498
00502 void test_get_configuration_parameter_value()
00503 {
00504
00505
00506
00507
00508 }
00509
00513 void test_set_configuration_parameter()
00514 {
00515
00516
00517
00518
00519 }
00520
00527 void test_add_configuration_set_and_get_configuration_set()
00528 {
00529
00530 coil::Properties cfgAdminProp;
00531 RTC::ConfigAdmin cfgAdmin(cfgAdminProp);
00532 SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin);
00533
00534
00535 SDOPackage::ConfigurationSet cfgSet0;
00536 cfgSet0.id = "ID 0";
00537 cfgSet0.description = "DESCRIPTION 0";
00538 cfgSet0.configuration_data.length(2);
00539 cfgSet0.configuration_data[0].name = "NAME 0-0";
00540 cfgSet0.configuration_data[0].value <<= "3.14159";
00541 cfgSet0.configuration_data[1].name = "NAME 0-1";
00542 cfgSet0.configuration_data[1].value <<= "2.71828";
00543
00544 SDOPackage::ConfigurationSet cfgSet1;
00545 cfgSet1.id = "ID 1";
00546 cfgSet1.description = "DESCRIPTION 1";
00547 cfgSet1.configuration_data.length(2);
00548 cfgSet1.configuration_data[0].name = "NAME 1-0";
00549 cfgSet1.configuration_data[0].value <<= "1.41421356";
00550 cfgSet1.configuration_data[1].name = "NAME 1-1";
00551 cfgSet1.configuration_data[1].value <<= "1.7320508";
00552
00553
00554 CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0));
00555 CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1));
00556
00557
00558 SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_configuration_set("ID 0");
00559 CPPUNIT_ASSERT_EQUAL(std::string("ID 0"),
00560 std::string(cfgSetRet0->id));
00561
00562
00563
00564 CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2),
00565 cfgSetRet0->configuration_data.length());
00566 CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"),
00567 std::string(cfgSetRet0->configuration_data[0].name));
00568 {
00569 const char* value; cfgSetRet0->configuration_data[0].value >>= value;
00570 CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value));
00571 }
00572 CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"),
00573 std::string(cfgSetRet0->configuration_data[1].name));
00574 {
00575 const char* value; cfgSetRet0->configuration_data[1].value >>= value;
00576 CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value));
00577 }
00578
00579 SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_configuration_set("ID 1");
00580 CPPUNIT_ASSERT_EQUAL(std::string("ID 1"),
00581 std::string(cfgSetRet1->id));
00582
00583
00584
00585 CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2),
00586 cfgSetRet1->configuration_data.length());
00587 CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"),
00588 std::string(cfgSetRet1->configuration_data[0].name));
00589 {
00590 const char* value; cfgSetRet1->configuration_data[0].value >>= value;
00591 CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value));
00592 }
00593 CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"),
00594 std::string(cfgSetRet1->configuration_data[1].name));
00595 {
00596 const char* value; cfgSetRet1->configuration_data[1].value >>= value;
00597 CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value));
00598 }
00599
00600 sdoCfg->_remove_ref();
00601
00602 }
00603
00610 void test_remove_configuration_set()
00611 {
00612
00613 coil::Properties cfgAdminProp;
00614 RTC::ConfigAdmin cfgAdmin(cfgAdminProp);
00615 SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin);
00616
00617
00618 SDOPackage::ConfigurationSet cfgSet0;
00619 cfgSet0.id = "ID 0";
00620 cfgSet0.description = "DESCRIPTION 0";
00621 cfgSet0.configuration_data.length(2);
00622 cfgSet0.configuration_data[0].name = "NAME 0-0";
00623 cfgSet0.configuration_data[0].value <<= "3.14159";
00624 cfgSet0.configuration_data[1].name = "NAME 0-1";
00625 cfgSet0.configuration_data[1].value <<= "2.71828";
00626
00627 SDOPackage::ConfigurationSet cfgSet1;
00628 cfgSet1.id = "ID 1";
00629 cfgSet1.description = "DESCRIPTION 1";
00630 cfgSet1.configuration_data.length(2);
00631 cfgSet1.configuration_data[0].name = "NAME 1-0";
00632 cfgSet1.configuration_data[0].value <<= "1.41421356";
00633 cfgSet1.configuration_data[1].name = "NAME 1-1";
00634 cfgSet1.configuration_data[1].value <<= "1.7320508";
00635
00636
00637 CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0));
00638 CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1));
00639
00640
00641 CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_configuration_set("ID 0"));
00642
00643
00644
00645 try
00646 {
00647 sdoCfg->get_configuration_set("ID 0");
00648 CPPUNIT_FAIL("ID 0 was not removed.");
00649 }
00650 catch (SDOPackage::InvalidParameter expected) {}
00651 catch (...) {}
00652
00653
00654
00655 try
00656 {
00657 sdoCfg->get_configuration_set("");
00658 CPPUNIT_FAIL("ID Not set.");
00659 }
00660 catch (SDOPackage::InvalidParameter expected) {}
00661 catch (...) {}
00662
00663
00664 SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1");
00665 CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id));
00666
00667
00668 try
00669 {
00670 sdoCfg->remove_configuration_set("inexist ID");
00671 CPPUNIT_FAIL("Exception not thrown.");
00672 }
00673 catch (SDOPackage::InvalidParameter expected) {}
00674 catch (...) {}
00675
00676 sdoCfg->_remove_ref();
00677
00678 }
00679
00686 void test_set_configuration_set_values()
00687 {
00688
00689 coil::Properties cfgAdminProp;
00690 RTC::ConfigAdmin cfgAdmin(cfgAdminProp);
00691 SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin);
00692
00693
00694 SDOPackage::ConfigurationSet cfgSet0;
00695 cfgSet0.id = "ID 0";
00696 cfgSet0.description = "DESCRIPTION 0";
00697 cfgSet0.configuration_data.length(2);
00698 cfgSet0.configuration_data[0].name = "NAME 0-0";
00699 cfgSet0.configuration_data[0].value <<= "3.14159";
00700 cfgSet0.configuration_data[1].name = "NAME 0-1";
00701 cfgSet0.configuration_data[1].value <<= "2.71828";
00702
00703 SDOPackage::ConfigurationSet cfgSet1;
00704 cfgSet1.id = "ID 1";
00705 cfgSet1.description = "DESCRIPTION 1";
00706 cfgSet1.configuration_data.length(2);
00707 cfgSet1.configuration_data[0].name = "NAME 1-0";
00708 cfgSet1.configuration_data[0].value <<= "1.41421356";
00709 cfgSet1.configuration_data[1].name = "NAME 1-1";
00710 cfgSet1.configuration_data[1].value <<= "1.7320508";
00711
00712 SDOPackage::ConfigurationSet cfgSet1_Modified;
00713 cfgSet1_Modified.id = "ID 1";
00714 cfgSet1_Modified.description = "DESCRIPTION 1 M";
00715 cfgSet1_Modified.configuration_data.length(2);
00716 cfgSet1_Modified.configuration_data[0].name = "NAME 1-0";
00717 cfgSet1_Modified.configuration_data[0].value <<= "2.23620679";
00718 cfgSet1_Modified.configuration_data[1].name = "NAME 1-1";
00719 cfgSet1_Modified.configuration_data[1].value <<= "2.44948974";
00720
00721
00722 CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0));
00723 CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1));
00724
00725
00726 CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true),
00727 sdoCfg->set_configuration_set_values(cfgSet1_Modified));
00728
00729
00730 SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1");
00731 CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id));
00732
00733
00734
00735
00736 CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2),
00737 cfgSetRet->configuration_data.length());
00738
00739 {
00740 const char* value; cfgSetRet->configuration_data[0].value >>= value;
00741 CPPUNIT_ASSERT_EQUAL(std::string("2.23620679"), std::string(value));
00742 }
00743 {
00744 const char* value; cfgSetRet->configuration_data[1].value >>= value;
00745 CPPUNIT_ASSERT_EQUAL(std::string("2.44948974"), std::string(value));
00746 }
00747
00748
00749
00750 try
00751 {
00752 cfgSet1_Modified.id = "";
00753 sdoCfg->set_configuration_set_values(cfgSet1_Modified);
00754 CPPUNIT_FAIL("Exception not thrown.");
00755 }
00756 catch (SDOPackage::InvalidParameter expected) {
00757 }
00758
00759 sdoCfg->_remove_ref();
00760
00761 }
00762
00768 void test_activate_configuration_set_and_get_active_configuration_set()
00769 {
00770
00771 coil::Properties cfgAdminProp;
00772 RTC::ConfigAdmin cfgAdmin(cfgAdminProp);
00773 SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin);
00774
00775
00776 SDOPackage::ConfigurationSet cfgSet0;
00777 cfgSet0.id = "ID 0";
00778 cfgSet0.description = "DESCRIPTION 0";
00779 cfgSet0.configuration_data.length(2);
00780 cfgSet0.configuration_data[0].name = "NAME 0-0";
00781 cfgSet0.configuration_data[0].value <<= "3.14159";
00782 cfgSet0.configuration_data[1].name = "NAME 0-1";
00783 cfgSet0.configuration_data[1].value <<= "2.71828";
00784
00785 SDOPackage::ConfigurationSet cfgSet1;
00786 cfgSet1.id = "ID 1";
00787 cfgSet1.description = "DESCRIPTION 1";
00788 cfgSet1.configuration_data.length(2);
00789 cfgSet1.configuration_data[0].name = "NAME 1-0";
00790 cfgSet1.configuration_data[0].value <<= "1.41421356";
00791 cfgSet1.configuration_data[1].name = "NAME 1-1";
00792 cfgSet1.configuration_data[1].value <<= "1.7320508";
00793
00794
00795 CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0));
00796 CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1));
00797
00798
00799 ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets());
00800
00801
00802 CPPUNIT_ASSERT(config_sets->length() == 2);
00803 CPPUNIT_ASSERT_EQUAL(std::string("ID 0"),
00804 std::string(config_sets[0].id));
00805 CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"),
00806 std::string(config_sets[0].configuration_data[0].name));
00807 {
00808 const char* value; config_sets[0].configuration_data[0].value >>= value;
00809 CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value));
00810 }
00811 CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"),
00812 std::string(config_sets[0].configuration_data[1].name));
00813 {
00814 const char* value; config_sets[0].configuration_data[1].value >>= value;
00815 CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value));
00816 }
00817
00818 CPPUNIT_ASSERT_EQUAL(std::string("ID 1"),
00819 std::string(config_sets[1].id));
00820 CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"),
00821 std::string(config_sets[1].configuration_data[0].name));
00822 {
00823 const char* value; config_sets[1].configuration_data[0].value >>= value;
00824 CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value));
00825 }
00826 CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"),
00827 std::string(config_sets[1].configuration_data[1].name));
00828 {
00829 const char* value; config_sets[1].configuration_data[1].value >>= value;
00830 CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value));
00831 }
00832
00833
00834 CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0"));
00835
00836
00837 SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set();
00838 CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id));
00839
00840
00841
00842
00843 CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2),
00844 cfgSetRet0->configuration_data.length());
00845 CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"),
00846 std::string(cfgSetRet0->configuration_data[0].name));
00847 {
00848 const char* value; cfgSetRet0->configuration_data[0].value >>= value;
00849 CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value));
00850 }
00851 CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"),
00852 std::string(cfgSetRet0->configuration_data[1].name));
00853 {
00854 const char* value; cfgSetRet0->configuration_data[1].value >>= value;
00855 CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value));
00856 }
00857
00858
00859 CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1"));
00860
00861
00862 SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set();
00863 CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id));
00864
00865
00866
00867
00868 CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2),
00869 cfgSetRet1->configuration_data.length());
00870 CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"),
00871 std::string(cfgSetRet1->configuration_data[0].name));
00872 {
00873 const char* value; cfgSetRet1->configuration_data[0].value >>= value;
00874 CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value));
00875 }
00876 CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"),
00877 std::string(cfgSetRet1->configuration_data[1].name));
00878 {
00879 const char* value; cfgSetRet1->configuration_data[1].value >>= value;
00880 CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value));
00881 }
00882
00883
00884 try
00885 {
00886 sdoCfg->activate_configuration_set("inexist ID");
00887 CPPUNIT_FAIL("Exception not thrown.");
00888 }
00889 catch (SDOPackage::InvalidParameter expected) {}
00890
00891 sdoCfg->_remove_ref();
00892
00893 }
00894
00895 };
00896 };
00897
00898
00899
00900
00901 CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests);
00902
00903 #ifdef LOCAL_MAIN
00904 int main(int argc, char* argv[])
00905 {
00906
00907 FORMAT format = TEXT_OUT;
00908 int target = 0;
00909 std::string xsl;
00910 std::string ns;
00911 std::string fname;
00912 std::ofstream ofs;
00913
00914 int i(1);
00915 while (i < argc)
00916 {
00917 std::string arg(argv[i]);
00918 std::string next_arg;
00919 if (i + 1 < argc) next_arg = argv[i + 1];
00920 else next_arg = "";
00921
00922 if (arg == "--text") { format = TEXT_OUT; break; }
00923 if (arg == "--xml")
00924 {
00925 if (next_arg == "")
00926 {
00927 fname = argv[0];
00928 fname += ".xml";
00929 }
00930 else
00931 {
00932 fname = next_arg;
00933 }
00934 format = XML_OUT;
00935 ofs.open(fname.c_str());
00936 }
00937 if ( arg == "--compiler" ) { format = COMPILER_OUT; break; }
00938 if ( arg == "--cerr" ) { target = 1; break; }
00939 if ( arg == "--xsl" )
00940 {
00941 if (next_arg == "") xsl = "default.xsl";
00942 else xsl = next_arg;
00943 }
00944 if ( arg == "--namespace" )
00945 {
00946 if (next_arg == "")
00947 {
00948 std::cerr << "no namespace specified" << std::endl;
00949 exit(1);
00950 }
00951 else
00952 {
00953 xsl = next_arg;
00954 }
00955 }
00956 ++i;
00957 }
00958 CppUnit::TextUi::TestRunner runner;
00959 if ( ns.empty() )
00960 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
00961 else
00962 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
00963 CppUnit::Outputter* outputter = 0;
00964 std::ostream* stream = target ? &std::cerr : &std::cout;
00965 switch ( format )
00966 {
00967 case TEXT_OUT :
00968 outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
00969 break;
00970 case XML_OUT :
00971 std::cout << "XML_OUT" << std::endl;
00972 outputter = new CppUnit::XmlOutputter(&runner.result(),
00973 ofs, "shift_jis");
00974 static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
00975 break;
00976 case COMPILER_OUT :
00977 outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
00978 break;
00979 }
00980 runner.setOutputter(outputter);
00981 runner.run();
00982 return 0;
00983 }
00984 #endif // MAIN
00985 #endif // SdoConfiguration_cpp