00001
00012
00013
00014
00015
00016
00017 #ifndef ManagerServant_cpp
00018 #define ManagerServant_cpp
00019
00020 #include <cppunit/ui/text/TestRunner.h>
00021 #include <cppunit/TextOutputter.h>
00022 #include <cppunit/extensions/TestFactoryRegistry.h>
00023 #include <cppunit/extensions/HelperMacros.h>
00024 #include <cppunit/TestAssert.h>
00025 #include <string>
00026 #include <iostream>
00027 #include <idl/SDOPackageSkel.h>
00028 #include <idl/RTCSkel.h>
00029 #include <rtm/idl/ManagerSkel.h>
00030 #include <rtm/ManagerServant.h>
00031 #include <rtm/NVUtil.h>
00032
00037 namespace ManagerServant
00038 {
00044 class Logger
00045 {
00046 public:
00047 void log(const std::string& msg)
00048 {
00049 m_log.push_back(msg);
00050 }
00051
00052 int countLog(const std::string& msg)
00053 {
00054 int count = 0;
00055 for (int i = 0; i < (int) m_log.size(); ++i)
00056 {
00057 if (m_log[i] == msg) ++count;
00058 }
00059 return count;
00060 }
00061
00062 private:
00063 std::vector<std::string> m_log;
00064 };
00065
00066 class ManagerServantTests
00067 : public CppUnit::TestFixture
00068 {
00069 CPPUNIT_TEST_SUITE(ManagerServantTests);
00070
00071 CPPUNIT_TEST(test_add_master_manager);
00072 CPPUNIT_TEST(test_add_slave_manager);
00073 CPPUNIT_TEST(test_get_loadable_modules);
00074 CPPUNIT_TEST(test_load_module);
00075 CPPUNIT_TEST(test_unload_modules);
00076 CPPUNIT_TEST(test_get_loaded_modules);
00077 CPPUNIT_TEST(test_get_factory_profiles);
00078 CPPUNIT_TEST(test_create_component);
00079 CPPUNIT_TEST(test_get_components);
00080 CPPUNIT_TEST(test_get_component_profiles);
00081 CPPUNIT_TEST(test_get_profile);
00082 CPPUNIT_TEST(test_get_configuration);
00083 CPPUNIT_TEST(test_set_configuration);
00084 CPPUNIT_TEST(test_fork);
00085 CPPUNIT_TEST(test_get_service);
00086 CPPUNIT_TEST(test_getObjRef);
00087 CPPUNIT_TEST(test_delete_component);
00088
00089
00090
00091 CPPUNIT_TEST_SUITE_END();
00092
00093 private:
00094 CORBA::ORB_ptr m_pORB;
00095 PortableServer::POA_ptr m_pPOA;
00096 RTM::Manager_ptr m_objref;
00097
00101 bool isFound(const ::RTM::ModuleProfileList* list, const std::string& mod)
00102 {
00103 const char *pch;
00104 for (CORBA::ULong ic = 0; ic < list->length(); ++ic)
00105 {
00106 if( (*list)[ic].properties[0].value >>= pch )
00107 {
00108 if(mod == ::std::string(pch))
00109 {
00110 return true;
00111 }
00112 }
00113 }
00114 return false;
00115 }
00116
00117 public:
00118
00122 ManagerServantTests()
00123 {
00124
00125 int argc = 0;
00126 char** argv = NULL;
00127 m_pORB = CORBA::ORB_init(argc, argv);
00128 m_pPOA = PortableServer::POA::_narrow(
00129 m_pORB->resolve_initial_references("RootPOA"));
00130 m_pPOA->the_POAManager()->activate();
00131
00132 }
00133
00137 ~ManagerServantTests()
00138 {
00139 }
00140
00144 virtual void setUp()
00145 {
00146 }
00147
00151 virtual void tearDown()
00152 {
00153 }
00154
00155
00161 void test_add_master_manager()
00162 {
00163 ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
00164 RTM::ManagerList* list;
00165 try
00166 {
00167 ::RTC::ReturnCode_t ret;
00168 CORBA::Boolean cbret;
00169 cbret = pman->is_master();
00170
00171 CPPUNIT_ASSERT(!cbret);
00172
00173
00174 list = pman->get_master_managers();
00175 CPPUNIT_ASSERT_EQUAL(0, (int)list->length());
00176
00177
00178 bool bret = pman->createINSManager();
00179 CPPUNIT_ASSERT(bret);
00180
00181 bret = pman->createINSManager();
00182 CPPUNIT_ASSERT(!bret);
00183
00184 std::string host_port("localhost:2810");
00185 RTM::Manager_var owner;
00186
00187 owner = pman->findManager(host_port.c_str());
00188
00189
00190 ret = pman->add_master_manager(owner);
00191 CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ret);
00192 list = pman->get_master_managers();
00193 CPPUNIT_ASSERT_EQUAL(1, (int)list->length());
00194
00195
00196 ret = pman->remove_master_manager(RTM::Manager::_duplicate(owner));
00197 CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ret);
00198 list = pman->get_master_managers();
00199 CPPUNIT_ASSERT_EQUAL(0, (int)list->length());
00200
00201 CORBA::Object_var obj;
00202 obj = m_pORB->resolve_initial_references("omniINSPOA");
00203 PortableServer::POA_ptr poa = PortableServer::POA::_narrow(obj);
00204 poa->the_POAManager()->deactivate(false, true);
00205 }
00206 catch(CORBA::SystemException& e)
00207 {
00208 std::cout << "test_add_master_manager() SystemException: " << e._name() << std::endl;
00209 }
00210 catch (...)
00211 {
00212 std::cout << "test_add_master_manager() other Exception" << std::endl;
00213 }
00214
00215 delete list;
00216 delete pman;
00217 }
00218
00224 void test_add_slave_manager()
00225 {
00226 ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
00227 RTM::ManagerList* list;
00228 try
00229 {
00230 ::RTC::ReturnCode_t ret;
00231
00232
00233 list = pman->get_slave_managers();
00234 CPPUNIT_ASSERT_EQUAL(0, (int)list->length());
00235
00236
00237 bool bret = pman->createINSManager();
00238 CPPUNIT_ASSERT(!bret);
00239
00240 std::string host_port("localhost:2810");
00241 RTM::Manager_var owner;
00242
00243
00244 owner = pman->findManager(host_port.c_str());
00245
00246
00247 ret = pman->add_slave_manager(owner);
00248 CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ret);
00249 list = pman->get_slave_managers();
00250 CPPUNIT_ASSERT_EQUAL(1, (int)list->length());
00251
00252
00253 ret = pman->remove_slave_manager(RTM::Manager::_duplicate(owner));
00254 CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ret);
00255 list = pman->get_slave_managers();
00256 CPPUNIT_ASSERT_EQUAL(0, (int)list->length());
00257
00258 CORBA::Object_var obj;
00259 obj = m_pORB->resolve_initial_references("omniINSPOA");
00260 PortableServer::POA_ptr poa = PortableServer::POA::_narrow(obj);
00261 poa->the_POAManager()->deactivate(false, true);
00262 }
00263 catch(CORBA::SystemException& e)
00264 {
00265 std::cout << "test_add_slave_manager() SystemException: " << e._name() << std::endl;
00266 }
00267 catch (...)
00268 {
00269 std::cout << "test_add_slave_manager() other Exception" << std::endl;
00270 }
00271
00272 delete list;
00273 delete pman;
00274 }
00275
00282 void test_load_module()
00283 {
00284 ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
00285 ::RTC::ReturnCode_t ret;
00286 try
00287 {
00288 ret = pman->load_module(".libs/DummyModule1.so","DummyModule1Init");
00289 CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
00290 CPPUNIT_ASSERT(isFound(pman->get_loaded_modules(),
00291 ".//.libs/DummyModule1.so"));
00292 }
00293 catch(...)
00294 {
00295 CPPUNIT_FAIL("Exception thrown.");
00296 }
00297
00298
00299 try
00300 {
00301 ret = pman->load_module("bar.so","DummyModule1Init");
00302 CPPUNIT_FAIL("Exception not thrown.");
00303 }
00304 catch(...)
00305 {
00306 CPPUNIT_ASSERT(!isFound(pman->get_loaded_modules(), ".//bar.so"));
00307 }
00308
00309 try
00310 {
00311 ret = pman->load_module("DummyModule1i.so","foo");
00312 CPPUNIT_FAIL("Exception not thrown.");
00313 }
00314 catch(...)
00315 {
00316 CPPUNIT_ASSERT(isFound(pman->get_loaded_modules(),
00317 ".//.libs/DummyModule1.so"));
00318 }
00319
00320 ret = pman->load_module(".libs/DummyModule1.so","DummyModule1Init");
00321 CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
00322 CPPUNIT_ASSERT(isFound(pman->get_loaded_modules(),
00323 ".//.libs/DummyModule1.so"));
00324
00325
00326 ret = pman->load_module(".libs/DummyModule2.so","DummyModule2Init");
00327 CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
00328 CPPUNIT_ASSERT(isFound(pman->get_loaded_modules(),
00329 ".//.libs/DummyModule2.so"));
00330
00331 delete pman;
00332 }
00339 void test_unload_modules()
00340 {
00341 ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
00342 ::RTC::ReturnCode_t ret;
00343 try
00344 {
00345 ret = pman->load_module(".libs/DummyModule1.so","DummyModule1Init");
00346 CPPUNIT_ASSERT(isFound(pman->get_loaded_modules(),
00347 ".//.libs/DummyModule1.so"));
00348 CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
00349 }
00350 catch(...)
00351 {
00352 CPPUNIT_FAIL("Exception thrown.");
00353 }
00354 try
00355 {
00356 ret = pman->load_module(".libs/DummyModule2.so","DummyModule2Init");
00357 CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
00358 CPPUNIT_ASSERT(isFound(pman->get_loaded_modules(),
00359 ".//.libs/DummyModule2.so"));
00360 }
00361 catch(...)
00362 {
00363 CPPUNIT_FAIL("Exception thrown.");
00364 }
00365
00366 try
00367 {
00368 ret = pman->unload_module(".//.libs/DummyModule2.so");
00369 CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
00370 }
00371 catch(...)
00372 {
00373 CPPUNIT_FAIL( "unload error" );
00374 }
00375
00376 try
00377 {
00378 pman->unload_module("non-loaded-module.so");
00379 CPPUNIT_FAIL("Exception not thrown.");
00380 }
00381 catch(...)
00382 {
00383
00384 }
00385 delete pman;
00386 }
00393 void test_get_loaded_modules()
00394 {
00395 ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
00396 ::RTC::ReturnCode_t ret;
00397 try
00398 {
00399 ret = pman->load_module(".libs/DummyModule1.so","DummyModule1Init");
00400 CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
00401 CPPUNIT_ASSERT(isFound(pman->get_loaded_modules(),
00402 ".//.libs/DummyModule1.so"));
00403 }
00404 catch(...)
00405 {
00406 CPPUNIT_FAIL("Exception thrown.");
00407 }
00408 try
00409 {
00410 ret = pman->load_module(".libs/DummyModule2.so","DummyModule2Init");
00411 CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
00412 CPPUNIT_ASSERT(isFound(pman->get_loaded_modules(),
00413 ".//.libs/DummyModule2.so"));
00414 }
00415 catch(...)
00416 {
00417 CPPUNIT_FAIL("Exception thrown.");
00418 }
00419
00420
00421 ::RTM::ModuleProfileList* list;
00422 list = pman->get_loaded_modules();
00423 ::RTM::ModuleProfileList modlist(*list);
00424 delete list;
00425
00426
00427 CPPUNIT_ASSERT_EQUAL((::CORBA::ULong)2, modlist.length());
00428 CPPUNIT_ASSERT_EQUAL(::std::string("file_path"),
00429 ::std::string(modlist[0].properties[0].name));
00430 const char* ch;
00431 if( modlist[0].properties[0].value >>= ch )
00432 {
00433 CPPUNIT_ASSERT_EQUAL(::std::string(".//.libs/DummyModule1.so"),
00434 ::std::string(ch));
00435 }
00436 else
00437 {
00438 CPPUNIT_FAIL( "ModuleProfileList is illegal." );
00439 }
00440
00441 CPPUNIT_ASSERT_EQUAL(::std::string("file_path"),
00442 ::std::string(modlist[1].properties[0].name));
00443
00444 if( modlist[1].properties[0].value >>= ch )
00445 {
00446 CPPUNIT_ASSERT_EQUAL(::std::string(".//.libs/DummyModule2.so"),
00447 ::std::string(ch));
00448 }
00449 else
00450 {
00451 CPPUNIT_FAIL( "ModuleProfileList is illegal." );
00452 }
00453 delete pman;
00454 }
00461 void test_get_factory_profiles()
00462 {
00463 typedef struct data_struct {
00464 ::std::string name;
00465 ::std::string value;
00466 } DATA_STRUCT;
00467 DATA_STRUCT composite_spec[] =
00468 {
00469 {"implementation_id", "PeriodicECSharedComposite"},
00470 {"type_name", "PeriodicECSharedComposite"},
00471 {"description", "PeriodicECSharedComposite"},
00472 {"version", "1.0"},
00473 {"vendor", "jp.go.aist"},
00474 {"category", "composite.PeriodicECShared"},
00475 {"activity_type", "DataFlowComponent"},
00476 {"max_instance", "0"},
00477 {"language", "C++"},
00478 {"lang_type", "compile"},
00479 {"exported_ports", ""},
00480 {"conf.default.members", ""},
00481 {"conf.default.exported_ports", ""},
00482 {"",""},
00483 };
00484 DATA_STRUCT consolein_spec[] =
00485 {
00486 {"implementation_id", "DummyModule1"},
00487 {"type_name", "DummyModule1"},
00488 {"description", "Console input component"},
00489 {"version", "1.0"},
00490 {"vendor", "Noriaki Ando, AIST"},
00491 {"category", "example"},
00492 {"activity_type", "DataFlowComponent"},
00493 {"max_instance", "10"},
00494 {"language", "C++"},
00495 {"lang_type", "compile"},
00496 {"",""},
00497 };
00498 DATA_STRUCT consoleout_spec[] =
00499 {
00500 {"implementation_id", "DummyModule2"},
00501 {"type_name", "DummyModule2"},
00502 {"description", "Console output component"},
00503 {"version", "1.0"},
00504 {"vendor", "Noriaki Ando, AIST"},
00505 {"category", "example"},
00506 {"activity_type", "DataFlowComponent"},
00507 {"max_instance", "10"},
00508 {"language", "C++"},
00509 {"lang_type", "compile"},
00510 {"",""},
00511 };
00512 ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
00513
00514
00515 ::RTC::ReturnCode_t ret;
00516 ret = pman->load_module(".libs/DummyModule1.so","DummyModule1Init");
00517 CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
00518 CPPUNIT_ASSERT(isFound(pman->get_loaded_modules(),
00519 ".//.libs/DummyModule1.so"));
00520 ret = pman->load_module(".libs/DummyModule2.so","DummyModule2Init");
00521 CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
00522 CPPUNIT_ASSERT(isFound(pman->get_loaded_modules(),
00523 ".//.libs/DummyModule2.so"));
00524
00525
00526 ::RTM::ModuleProfileList *list;
00527 list = pman->get_factory_profiles();
00528 ::RTM::ModuleProfileList profiles(*list);
00529 delete list;
00530
00531
00532 ::CORBA::ULong len;
00533 CPPUNIT_ASSERT_EQUAL((::CORBA::ULong)3, profiles.length());
00534 len = profiles[0].properties.length();
00535 CPPUNIT_ASSERT_EQUAL((::CORBA::ULong)13, len);
00536 for (CORBA::ULong ic = 0; ic < len; ++ic)
00537 {
00538 CPPUNIT_ASSERT_EQUAL(composite_spec[ic].name,
00539 ::std::string(profiles[0].properties[ic].name));
00540
00541 const char* ch;
00542 if( profiles[0].properties[ic].value >>= ch )
00543 {
00544 CPPUNIT_ASSERT_EQUAL(composite_spec[ic].value,
00545 ::std::string(ch));
00546 }
00547 else
00548 {
00549 CPPUNIT_FAIL( "ModuleProfileList is illegal." );
00550 }
00551 }
00552 len =profiles[1].properties.length();
00553 CPPUNIT_ASSERT_EQUAL((::CORBA::ULong)10, len);
00554 for (CORBA::ULong ic = 0; ic < len; ++ic)
00555 {
00556 CPPUNIT_ASSERT_EQUAL(consolein_spec[ic].name,
00557 ::std::string(profiles[1].properties[ic].name));
00558
00559 const char* ch;
00560 if( profiles[1].properties[ic].value >>= ch )
00561 {
00562 CPPUNIT_ASSERT_EQUAL(consolein_spec[ic].value,
00563 ::std::string(ch));
00564 }
00565 else
00566 {
00567 CPPUNIT_FAIL( "ModuleProfileList is illegal." );
00568 }
00569 }
00570 len =profiles[2].properties.length();
00571 CPPUNIT_ASSERT_EQUAL((::CORBA::ULong)10, len);
00572 for (CORBA::ULong ic = 0; ic < len; ++ic)
00573 {
00574 CPPUNIT_ASSERT_EQUAL(consoleout_spec[ic].name,
00575 ::std::string(profiles[2].properties[ic].name));
00576
00577 const char* ch;
00578 if( profiles[2].properties[ic].value >>= ch )
00579 {
00580 CPPUNIT_ASSERT_EQUAL(consoleout_spec[ic].value,
00581 ::std::string(ch));
00582 }
00583 else
00584 {
00585 CPPUNIT_FAIL( "ModuleProfileList is illegal." );
00586 }
00587 }
00588 delete pman;
00589 }
00595 void test_create_component()
00596 {
00597 ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
00598
00599 ::RTC::ReturnCode_t ret;
00600 ret = pman->load_module(".libs/DummyModule1.so","DummyModule1Init");
00601 CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
00602 CPPUNIT_ASSERT(isFound(pman->get_loaded_modules(),
00603 ".//.libs/DummyModule1.so"));
00604 ret = pman->load_module(".libs/DummyModule2.so","DummyModule2Init");
00605 CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
00606 CPPUNIT_ASSERT(isFound(pman->get_loaded_modules(),
00607 ".//.libs/DummyModule2.so"));
00608
00609
00610 ::RTC::RTObject_ptr inobj;
00611 inobj = pman->create_component("DummyModule1AA");
00612 CPPUNIT_ASSERT(::CORBA::is_nil(inobj));
00613 inobj = pman->create_component("DummyModule1");
00614 CPPUNIT_ASSERT(!::CORBA::is_nil(inobj));
00615
00616 ::RTC::RTObject_ptr outobj;
00617 outobj = pman->create_component("DummyModule2");
00618 CPPUNIT_ASSERT(!::CORBA::is_nil(outobj));
00619 delete pman;
00620 }
00627 void test_delete_component()
00628 {
00629 ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
00630
00631 ::RTC::ReturnCode_t ret;
00632 ret = pman->load_module(".libs/DummyModule1.so","DummyModule1Init");
00633 CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
00634 CPPUNIT_ASSERT(isFound(pman->get_loaded_modules(),
00635 ".//.libs/DummyModule1.so"));
00636 ret = pman->load_module(".libs/DummyModule2.so","DummyModule2Init");
00637 CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
00638 CPPUNIT_ASSERT(isFound(pman->get_loaded_modules(),
00639 ".//.libs/DummyModule2.so"));
00640
00641 ::RTC::RTObject_ptr inobj;
00642 inobj = pman->create_component("DummyModule1");
00643 CPPUNIT_ASSERT(!::CORBA::is_nil(inobj));
00644
00645 ::RTC::RTObject_ptr outobj;
00646 outobj = pman->create_component("DummyModule2");
00647 CPPUNIT_ASSERT(!::CORBA::is_nil(outobj));
00648
00649 ::RTC::ComponentProfileList *list;
00650 list = pman->get_component_profiles();
00651 CPPUNIT_ASSERT(list!=NULL);
00652 ::RTC::ComponentProfileList profiles(*list);
00653 delete list;
00654
00655
00656 m_pPOA->the_POAManager()->deactivate(false, true);
00657 ret = pman->delete_component(profiles[0].instance_name);
00658 CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
00659
00660
00661
00662
00663
00664
00665 delete pman;
00666 }
00673 void test_get_components()
00674 {
00675 ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
00676 ::RTC::ReturnCode_t ret;
00677 ret = pman->load_module(".libs/DummyModule1.so","DummyModule1Init");
00678 CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
00679 CPPUNIT_ASSERT(isFound(pman->get_loaded_modules(),
00680 ".//.libs/DummyModule1.so"));
00681 ret = pman->load_module(".libs/DummyModule2.so","DummyModule2Init");
00682 CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
00683 CPPUNIT_ASSERT(isFound(pman->get_loaded_modules(),
00684 ".//.libs/DummyModule2.so"));
00685
00686 ::RTC::RTObject_ptr inobj;
00687 inobj = pman->create_component("DummyModule1");
00688 CPPUNIT_ASSERT(!::CORBA::is_nil(inobj));
00689
00690 ::RTC::RTObject_ptr outobj;
00691 outobj = pman->create_component("DummyModule2");
00692 CPPUNIT_ASSERT(!::CORBA::is_nil(outobj));
00693
00694
00695 ::RTC::RTCList *list;
00696 list = pman->get_components();
00697 CPPUNIT_ASSERT(list != NULL);
00698 ::RTC::RTCList rtclist(*list);
00699 delete list;
00700
00701 ::CORBA::ULong len(rtclist.length());
00702 bool bflag;
00703 bflag = false;
00704 for (::CORBA::ULong ic = 0; ic < len; ++ic)
00705 {
00706 if( rtclist[ic] == inobj )
00707 {
00708 bflag = true;
00709 }
00710 }
00711 CPPUNIT_ASSERT_EQUAL( bflag,true );
00712
00713 bflag = false;
00714 for (::CORBA::ULong ic = 0; ic < len; ++ic)
00715 {
00716 if( rtclist[ic] == outobj )
00717 {
00718 bflag = true;
00719 }
00720 }
00721 CPPUNIT_ASSERT_EQUAL( bflag,true );
00722 delete pman;
00723 }
00729 void test_get_component_profiles()
00730 {
00731 ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
00732 ::RTC::ReturnCode_t ret;
00733 ret = pman->load_module(".libs/DummyModule1.so","DummyModule1Init");
00734 CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
00735 CPPUNIT_ASSERT(isFound(pman->get_loaded_modules(),
00736 ".//.libs/DummyModule1.so"));
00737 ret = pman->load_module(".libs/DummyModule2.so","DummyModule2Init");
00738 CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
00739 CPPUNIT_ASSERT(isFound(pman->get_loaded_modules(),
00740 ".//.libs/DummyModule2.so"));
00741
00742
00743 ::RTC::RTObject_ptr inobj;
00744 inobj = pman->create_component("DummyModule1");
00745 CPPUNIT_ASSERT(!::CORBA::is_nil(inobj));
00746
00747 ::RTC::RTObject_ptr outobj;
00748 outobj = pman->create_component("DummyModule2");
00749 CPPUNIT_ASSERT(!::CORBA::is_nil(outobj));
00750
00751
00752 ::RTC::ComponentProfileList *list;
00753 list = pman->get_component_profiles();
00754 CPPUNIT_ASSERT(list!=NULL);
00755 ::RTC::ComponentProfileList profiles(*list);
00756 delete list;
00757
00758
00759 ::RTC::RTCList *plist;
00760 plist = pman->get_components();
00761 CPPUNIT_ASSERT(plist != NULL);
00762 ::RTC::RTCList rtclist(*plist);
00763 delete plist;
00764
00765 ::CORBA::ULong len(rtclist.length());
00766 bool bflag;
00767 bflag = false;
00768 for (::CORBA::ULong ic = 0; ic < len; ++ic)
00769 {
00770 if( rtclist[ic] == inobj )
00771 {
00772 bflag = true;
00773 ::std::string str(profiles[ic].instance_name);
00774 CPPUNIT_ASSERT(str.find("DummyModule1") != ::std::string::npos);
00775 CPPUNIT_ASSERT_EQUAL(::std::string("DummyModule1"),
00776 ::std::string(profiles[ic].type_name));
00777 CPPUNIT_ASSERT_EQUAL(::std::string("Console input component"),
00778 ::std::string(profiles[ic].description));
00779 CPPUNIT_ASSERT_EQUAL(::std::string("1.0"),
00780 ::std::string(profiles[ic].version));
00781 CPPUNIT_ASSERT_EQUAL(::std::string("Noriaki Ando, AIST"),
00782 ::std::string(profiles[ic].vendor));
00783 CPPUNIT_ASSERT_EQUAL(::std::string("example"),
00784 ::std::string(profiles[ic].category));
00785 break;
00786 }
00787 }
00788 CPPUNIT_ASSERT_EQUAL( bflag,true );
00789
00790 bflag = false;
00791 for (::CORBA::ULong ic = 0; ic < len; ++ic)
00792 {
00793 if( rtclist[ic] == outobj )
00794 {
00795 bflag = true;
00796 ::std::string str(profiles[ic].instance_name);
00797 CPPUNIT_ASSERT(str.find("DummyModule2") != ::std::string::npos);
00798 CPPUNIT_ASSERT_EQUAL(::std::string("DummyModule2"),
00799 ::std::string(profiles[ic].type_name));
00800 CPPUNIT_ASSERT_EQUAL(::std::string("Console output component"),
00801 ::std::string(profiles[ic].description));
00802 CPPUNIT_ASSERT_EQUAL(::std::string("1.0"),
00803 ::std::string(profiles[ic].version));
00804 CPPUNIT_ASSERT_EQUAL(::std::string("Noriaki Ando, AIST"),
00805 ::std::string(profiles[ic].vendor));
00806 CPPUNIT_ASSERT_EQUAL(::std::string("example"),
00807 ::std::string(profiles[ic].category));
00808 break;
00809 }
00810 }
00811 CPPUNIT_ASSERT_EQUAL( bflag,true );
00812 delete pman;
00813 }
00820 void test_get_profile()
00821 {
00822 typedef struct data_struct {
00823 ::std::string name;
00824 ::std::string value;
00825 } DATA_STRUCT;
00826 DATA_STRUCT manager_profile[] =
00827 {
00828 {"instance_name", "manager"},
00829 {"name", "manager"},
00830 {"naming_formats", "%h.host_cxt/%n.mgr"},
00831 {"pid", ""},
00832 {"refstring_path", "/var/log/rtcmanager.ref"},
00833 {"modules.load_path", ""},
00834 {"modules.abs_path_allowed", "YES"},
00835 {"modules.C++.manager_cmd", ""},
00836 {"modules.C++.profile_cmd", ""},
00837 {"modules.C++.suffixes", ""},
00838 {"modules.C++.load_paths", ""},
00839 {"modules.Python.manager_cmd",""},
00840 {"modules.Python.profile_cmd",""},
00841 {"modules.Python.suffixes", ""},
00842 {"modules.Python.load_paths",""},
00843 {"modules.Java.manager_cmd", ""},
00844 {"modules.Java.profile_cmd", ""},
00845 {"modules.Java.suffixes", ""},
00846 {"modules.Java.load_paths", ""},
00847 {"modules.config_path", ""},
00848 {"modules.download_allowed", ""},
00849 {"modules.init_func_suffix", ""},
00850 {"modules.init_func_prefix", ""},
00851
00852 {"is_master", ""},
00853 {"corba_servant", "YES"},
00854 {"shutdown_on_nortcs", "YES"},
00855 {"shutdown_auto", "YES"},
00856 {"command", "rtcd"},
00857 {"supported_languages", ""},
00858 {"os.name", "Linux"},
00859 {"os.release", ""},
00860 {"os.version", ""},
00861 {"os.arch", ""},
00862 {"os.hostname", ""},
00863 {"",""},
00864 };
00865
00866 ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
00867
00868
00869 ::RTM::ManagerProfile *list;
00870 list = pman->get_profile();
00871 ::RTM::ManagerProfile profile(*list);
00872 delete list;
00873 int len;
00874 len = profile.properties.length();
00875 CPPUNIT_ASSERT_EQUAL(34,len);
00876 for(int ic = 0; ic < len; ++ic)
00877 {
00878 CPPUNIT_ASSERT_EQUAL(manager_profile[ic].name,
00879 ::std::string(profile.properties[ic].name));
00880 const char* ch;
00881 if( profile.properties[ic].value >>= ch )
00882 {
00883 if(!manager_profile[ic].value.empty())
00884 {
00885 CPPUNIT_ASSERT_EQUAL(manager_profile[ic].value,
00886 ::std::string(ch));
00887 }
00888 }
00889 }
00890 delete pman;
00891 }
00898 void test_get_configuration()
00899 {
00900 typedef struct data_struct {
00901 ::std::string name;
00902 ::std::string value;
00903 } DATA_STRUCT;
00904 DATA_STRUCT config[] =
00905 {
00906 {"config.version", "1.0.0"},
00907 {"openrtm.version", "OpenRTM-aist-1.0.0"},
00908 {"manager.instance_name", "manager"},
00909 {"manager.name", "manager"},
00910 {"manager.naming_formats", "%h.host_cxt/%n.mgr"},
00911 {"manager.pid", ""},
00912 {"manager.refstring_path", "/var/log/rtcmanager.ref"},
00913 {"manager.modules.load_path", ""},
00914 {"manager.modules.abs_path_allowed","YES"},
00915 {"manager.modules.C++.manager_cmd", ""},
00916 {"manager.modules.C++.profile_cmd", ""},
00917 {"manager.modules.C++.suffixes", ""},
00918 {"manager.modules.C++.load_paths", ""},
00919 {"manager.modules.Python.manager_cmd",""},
00920 {"manager.modules.Python.profile_cmd",""},
00921 {"manager.modules.Python.suffixes", ""},
00922 {"manager.modules.Python.load_paths",""},
00923 {"manager.modules.Java.manager_cmd", ""},
00924 {"manager.modules.Java.profile_cmd", ""},
00925 {"manager.modules.Java.suffixes", ""},
00926 {"manager.modules.Java.load_paths", ""},
00927 {"manager.modules.config_path", ""},
00928 {"manager.modules.download_allowed",""},
00929 {"manager.modules.init_func_suffix",""},
00930 {"manager.modules.init_func_prefix",""},
00931 {"manager.is_master", ""},
00932 {"manager.corba_servant", "YES"},
00933 {"manager.shutdown_on_nortcs", "YES"},
00934 {"manager.shutdown_auto", "YES"},
00935 {"manager.command", "rtcd"},
00936 {"manager.supported_languages", ""},
00937 {"manager.os.name", "Linux"},
00938 {"manager.os.release", ""},
00939 {"manager.os.version", ""},
00940 {"manager.os.arch", ""},
00941 {"manager.os.hostname", ""},
00942 {"os.name", ""},
00943 {"os.release", ""},
00944 {"os.version", ""},
00945 {"os.arch", ""},
00946 {"os.hostname", ""},
00947 {"logger.enable", ""},
00948 {"logger.file_name", ""},
00949 {"logger.date_format", "%b %d %H:%M:%S"},
00950 {"logger.log_level", ""},
00951 {"logger.stream_lock", "NO"},
00952 {"logger.master_logger", ""},
00953 {"module.conf_path", ""},
00954 {"module.load_path", ""},
00955 {"naming.enable", "YES"},
00956 {"naming.type", "corba"},
00957 {"naming.formats", "%h.host_cxt/%n.rtc"},
00958 {"naming.update.enable", "YES"},
00959 {"naming.update.interval", "10.0"},
00960 {"timer.enable", "YES"},
00961 {"timer.tick", "0.1"},
00962 {"corba.args", ""},
00963 {"corba.endpoint", ""},
00964 {"corba.id", "omniORB"},
00965 {"corba.nameservers", ""},
00966 {"corba.master_manager", "localhost:2810"},
00967 {"corba.nameservice.replace_endpoint", "NO"},
00968
00969 {"exec_cxt.periodic.type", "PeriodicExecutionContext"},
00970 {"exec_cxt.periodic.rate", "1000"},
00971 {"exec_cxt.evdriven.type", "EventDrivenExecutionContext"},
00972 {"example.DummyModule10.config_file", ""},
00973 {"example.DummyModule1.config_file", ""},
00974 {"example.DummyModule20.config_file", ""},
00975 {"example.DummyModule2.config_file", ""},
00976 {"example.DummyModule11.config_file", ""},
00977 {"example.DummyModule21.config_file", ""},
00978 {"example.DummyModule12.config_file", ""},
00979 {"example.DummyModule22.config_file", ""},
00980 {"",""},
00981 };
00982
00983 ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
00984 ::RTM::NVList* list;
00985 list = pman->get_configuration();
00986 ::RTM::NVList conf(*list);
00987 delete list;
00988 ::CORBA::ULong len;
00989 len = conf.length();
00990 CPPUNIT_ASSERT_EQUAL((::CORBA::ULong)73,len);
00991 for(::CORBA::ULong ic = 0; ic < len; ++ic)
00992 {
00993 CPPUNIT_ASSERT_EQUAL(config[ic].name,
00994 ::std::string(conf[ic].name));
00995 const char* ch;
00996 if( conf[ic].value >>= ch )
00997 {
00998 if(!config[ic].value.empty())
00999 {
01000 CPPUNIT_ASSERT_EQUAL(config[ic].value,
01001 ::std::string(ch));
01002 }
01003 }
01004 }
01005 delete pman;
01006 }
01013 void test_set_configuration()
01014 {
01015 typedef struct data_struct {
01016 ::std::string name;
01017 ::std::string value;
01018 } DATA_STRUCT;
01019 DATA_STRUCT config[] =
01020 {
01021 {"config.version", "1.0.0"},
01022 {"openrtm.version", "OpenRTM-aist-1.0.0"},
01023 {"manager.naming_formats", "%n.rtc"},
01024 {"manager.modules.load_path", "./,./.libs"},
01025 {"manager.modules.abs_path_allowed","NO"},
01026 {"manager.os.release", "2.6.22-14-generic"},
01027 {"manager.os.version", "2008"},
01028 {"manager.os.arch", "64"},
01029 {"manager.os.hostname", "ubuntur810"},
01030 };
01031 ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
01032 ::RTC::ReturnCode_t ret;
01033 int len;
01034 len = sizeof config/sizeof config[0];
01035 for(int ic = 0; ic < len; ++ic)
01036 {
01037 ret = pman->set_configuration(config[ic].name.c_str(),
01038 config[ic].value.c_str());
01039 CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
01040 }
01041
01042 ::RTM::NVList* list;
01043 list = pman->get_configuration();
01044 ::RTM::NVList conf(*list);
01045 delete list;
01046 ::CORBA::ULong leng;
01047 leng = conf.length();
01048 CPPUNIT_ASSERT_EQUAL((::CORBA::ULong)73,leng);
01049 for(::CORBA::ULong ic = 0; ic < leng; ++ic)
01050 {
01051 if(config[0].name == ::std::string(conf[ic].name))
01052 {
01053 CPPUNIT_ASSERT_EQUAL(config[ic].name,
01054 ::std::string(conf[ic].name));
01055 const char* ch;
01056 if( conf[ic].value >>= ch )
01057 {
01058 if(!config[ic].value.empty())
01059 {
01060 CPPUNIT_ASSERT_EQUAL(config[ic].value,
01061 ::std::string(ch));
01062 }
01063 }
01064 }
01065 }
01066 delete pman;
01067 }
01068
01075 void test_shutdown()
01076 {
01077
01078 ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
01079
01080 try
01081 {
01082 ::RTC::ReturnCode_t retcode;
01083 retcode = pman->shutdown();
01084 CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, retcode);
01085 ::coil::sleep(3);
01086 delete pman;
01087 }
01088 catch(...)
01089 {
01090 CPPUNIT_FAIL("Exception thrown.");
01091 }
01092 delete pman;
01093 }
01100 void test_get_loadable_modules()
01101 {
01102 ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
01103
01104
01105 ::RTC::ReturnCode_t ret;
01106
01107
01108
01109 try
01110 {
01111 ret = pman->load_module(".libs/DummyModule1.so","DummyModule1Init");
01112 CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
01113 CPPUNIT_ASSERT(isFound(pman->get_loadable_modules(),
01114 "DummyModule1"));
01115 }
01116 catch(...)
01117 {
01118 CPPUNIT_FAIL("Exception thrown.");
01119 }
01120
01121
01122 try
01123 {
01124 ret = pman->load_module(".libs/DummyModule2.so","DummyModule2Init");
01125 CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
01126 CPPUNIT_ASSERT(isFound(pman->get_loadable_modules(),
01127 "DummyModule2"));
01128 }
01129 catch(...)
01130 {
01131 CPPUNIT_FAIL("Exception thrown.");
01132 }
01133
01134
01135 ::RTM::ModuleProfileList* list;
01136 list = pman->get_loadable_modules();
01137 ::RTM::ModuleProfileList modlist(*list);
01138 delete list;
01139
01140
01141 CPPUNIT_ASSERT_EQUAL((::CORBA::ULong)2, modlist.length());
01142
01143 CORBA::Long long_ret = NVUtil::find_index(modlist[0].properties,"module_file_name");
01144 CPPUNIT_ASSERT(long_ret!=-1);
01145
01146 const char* ch;
01147 if( modlist[0].properties[long_ret].value >>= ch )
01148 {
01149 CPPUNIT_ASSERT_EQUAL(::std::string("DummyModule2.so"),
01150 ::std::string(ch));
01151 }
01152 else
01153 {
01154 CPPUNIT_FAIL( "ModuleProfileList is illegal." );
01155 }
01156
01157 long_ret = NVUtil::find_index(modlist[1].properties,"module_file_name");
01158 CPPUNIT_ASSERT(long_ret!=-1);
01159
01160 if( modlist[1].properties[long_ret].value >>= ch )
01161 {
01162 CPPUNIT_ASSERT_EQUAL(::std::string("DummyModule1.so"),
01163 ::std::string(ch));
01164 }
01165 else
01166 {
01167 CPPUNIT_FAIL( "ModuleProfileList is illegal." );
01168 }
01169 delete pman;
01170 }
01171
01172
01179 void test_fork()
01180 {
01181 ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
01182 CPPUNIT_ASSERT(pman->fork() == ::RTC::RTC_OK);
01183 delete pman;
01184 }
01185
01192 void test_restart()
01193 {
01194 ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
01195 CPPUNIT_ASSERT(pman->restart() == ::RTC::RTC_OK);
01196 delete pman;
01197 }
01198
01205 void test_get_service()
01206 {
01207 std::string name("service0");
01208 ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
01209 CPPUNIT_ASSERT(CORBA::is_nil(pman->get_service(name.c_str())));
01210 delete pman;
01211 }
01212
01219 void test_getObjRef()
01220 {
01221 ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
01222 m_objref = pman->getObjRef();
01223
01224 delete pman;
01225 }
01226
01227 };
01228 };
01229
01230
01231
01232
01233 CPPUNIT_TEST_SUITE_REGISTRATION(ManagerServant::ManagerServantTests);
01234
01235 #ifdef LOCAL_MAIN
01236 int main(int argc, char* argv[])
01237 {
01238 CppUnit::TextUi::TestRunner runner;
01239 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
01240 CppUnit::Outputter* outputter =
01241 new CppUnit::TextOutputter(&runner.result(), std::cout);
01242 runner.setOutputter(outputter);
01243 bool retcode = runner.run();
01244 return !retcode;
01245 }
01246 #endif // MAIN
01247 #endif // ManagerServant_cpp