00001
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef ManagerTests_cpp
00024 #define ManagerTests_cpp
00025
00026 #include <cppunit/ui/text/TestRunner.h>
00027 #include <cppunit/TextOutputter.h>
00028 #include <cppunit/extensions/TestFactoryRegistry.h>
00029 #include <cppunit/extensions/HelperMacros.h>
00030 #include <cppunit/TestAssert.h>
00031
00032 #include <coil/Task.h>
00033 #include <coil/DynamicLib.h>
00034
00035 #include <rtm/Manager.h>
00036 #include <rtm/RTObject.h>
00037 #include <rtm/ECFactory.h>
00038 #include <rtm/PeriodicExecutionContext.h>
00039 #include <rtm/ExtTrigExecutionContext.h>
00040 #include <rtm/NamingManager.h>
00041
00042 #include <rtm/CdrRingBuffer.h>
00043 #include <rtm/DefaultPeriodicTask.h>
00044 #include <rtm/PeriodicTaskFactory.h>
00045 #include <rtm/PublisherFlush.h>
00046 #include <rtm/PublisherNew.h>
00047 #include <rtm/PublisherPeriodic.h>
00048 #include <rtm/InPortCorbaCdrProvider.h>
00049 #include <rtm/InPortCorbaCdrConsumer.h>
00050 #include <rtm/OutPortCorbaCdrConsumer.h>
00051 #include <rtm/OutPortCorbaCdrProvider.h>
00052 #include <rtm/PeriodicECSharedComposite.h>
00053
00058 namespace Tests
00059 {
00060
00061
00062
00063 void shutdown_ORB(RTC::Manager* mgr)
00064 {
00065
00066 if(mgr == NULL)
00067 {
00068 return;
00069 }
00070 if(CORBA::is_nil(mgr->getORB()))
00071 {
00072 return;
00073 }
00074 try
00075 {
00076 while (mgr->getORB()->work_pending())
00077 {
00078 if (mgr->getORB()->work_pending())
00079 mgr->getORB()->perform_work();
00080 }
00081 }
00082 catch(...)
00083 {
00084 std::cout<<"Caught SystemException during perform_work."<<std::endl;
00085 }
00086
00087 if (!CORBA::is_nil(mgr->getPOA()))
00088 {
00089 try
00090 {
00091 if (!CORBA::is_nil(mgr->getPOAManager()))
00092 {
00093 mgr->getPOAManager()->deactivate(false, true);
00094 }
00095 mgr->getPOA()->destroy(false, true);
00096 }
00097 catch (CORBA::SystemException& ex)
00098 {
00099 std::cout<<"Caught SystemException during root POA destruction"<<std::endl;
00100 }
00101 catch (...)
00102 {
00103 std::cout<<"Caught unknown exception during POA destruction."<<std::endl;
00104 }
00105 }
00106 if(!CORBA::is_nil(mgr->getORB()))
00107 {
00108 try
00109 {
00110 mgr->getORB()->shutdown(true);
00111 mgr->getORB()->destroy();
00112 }
00113 catch (CORBA::SystemException& ex)
00114 {
00115 std::cout<<"Caught CORBA::SystemException during ORB shutdown"<<std::endl;;
00116 }
00117 catch (...)
00118 {
00119 std::cout<<"Caught unknown exception during ORB shutdown."<<std::endl;;
00120 }
00121 }
00122 }
00123
00124 class Logger
00125 {
00126 public:
00127 void log(const std::string& msg)
00128 {
00129 m_log.push_back(msg);
00130 }
00131
00132 int countLog(const std::string& msg)
00133 {
00134 int count = 0;
00135 for (int i = 0; i < (int) m_log.size(); ++i)
00136 {
00137 if (m_log[i] == msg) ++count;
00138 }
00139 return count;
00140 }
00141
00142 private:
00143 std::vector<std::string> m_log;
00144 };
00145
00146
00147 class ManagerMock : public RTC::Manager
00148 {
00149 public:
00150 static void clearInstance()
00151 {
00152 manager = NULL;
00153 }
00154 };
00155
00156
00157
00158 class ManagerTestMock : public RTC::Manager
00159 {
00160 public:
00161
00162 ManagerTestMock() : RTC::Manager() {}
00163 virtual ~ManagerTestMock(void) {}
00164
00165
00166 bool procContextArgs(const char* ec_args,
00167 std::string& ec_id,
00168 coil::Properties& ec_conf)
00169 {
00170 bool bret = RTC::Manager::procContextArgs(ec_args, ec_id, ec_conf);
00171 return bret;
00172 }
00173
00174 };
00175
00176
00177 class ModuleMock
00178 {
00179 public:
00180 static void setLogger(Logger* logger)
00181 {
00182 m_logger = logger;
00183 }
00184
00185 static void InitProc(RTC::Manager* manager)
00186 {
00187 if (m_logger != NULL) m_logger->log("InitProc");
00188 }
00189
00190 private:
00191 static Logger* m_logger;
00192 };
00193
00194 Logger* ModuleMock::m_logger = NULL;
00195
00196
00197 class RTObjectMock
00198 : virtual public RTC::RTObject_impl
00199 {
00200 public:
00201 RTObjectMock(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa)
00202 : RTC::RTObject_impl(orb, poa), m_logger(NULL)
00203 {
00204 }
00205
00206 virtual RTC::ReturnCode_t initialize()
00207 throw (CORBA::SystemException)
00208 {
00209 RTC::RTObject_impl::initialize();
00210 if (m_logger != NULL) m_logger->log("initialize");
00211 return RTC::RTC_OK;
00212 }
00213
00214 void setLogger(Logger* logger)
00215 {
00216 m_logger = logger;
00217 }
00218
00219 private:
00220 Logger* m_logger;
00221 };
00222
00223
00224 class DataFlowComponentMock
00225 : virtual public RTC::RTObject_impl
00226 {
00227 public:
00228 DataFlowComponentMock(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa)
00229 : RTC::RTObject_impl(orb, poa)
00230 {
00231 }
00232
00233 RTC::UniqueId attach_context(RTC::ExecutionContext_ptr exec_context)
00234 throw (CORBA::SystemException)
00235 {
00236 return RTC::RTObject_impl::attach_context(exec_context);
00237 }
00238 };
00239
00240 RTC::RtcBase* CreateDataFlowComponentMock(RTC::Manager* manager)
00241 {
00242 CORBA::ORB_ptr orb = manager->getORB();
00243 PortableServer::POA_ptr poa = manager->getPOA();
00244 DataFlowComponentMock* comp = new DataFlowComponentMock(orb, poa);
00245 comp->setObjRef(comp->_this());
00246 return comp;
00247 }
00248
00249 void DeleteDataFlowComponentMock(RTC::RtcBase* rtc)
00250 {
00251 if (rtc != NULL) rtc->_remove_ref();
00252 }
00253
00254
00255 class ManagerTests
00256 : public CppUnit::TestFixture
00257 {
00258 CPPUNIT_TEST_SUITE(ManagerTests);
00259
00260
00261 CPPUNIT_TEST(test_getLogLevel);
00262 CPPUNIT_TEST(test_getLoadedModules);
00263 CPPUNIT_TEST(test_getFactoryProfiles);
00264 CPPUNIT_TEST(test_createContext);
00265 CPPUNIT_TEST(test_init2);
00266 CPPUNIT_TEST(test_initFactories);
00267 CPPUNIT_TEST(test_initComposite);
00268 CPPUNIT_TEST(test_procContextArgs);
00269 CPPUNIT_TEST(test_init_without_arguments);
00270 CPPUNIT_TEST(test_instance);
00271 CPPUNIT_TEST(test_instance_without_init);
00272
00273
00274
00275
00276 CPPUNIT_TEST(test_getConfig);
00277 CPPUNIT_TEST(test_setModuleInitProc);
00278
00279
00280
00281 CPPUNIT_TEST(test_load);
00282 CPPUNIT_TEST(test_unload);
00283 CPPUNIT_TEST(test_unloadAll);
00284 CPPUNIT_TEST(test_registerFactory);
00285 CPPUNIT_TEST(test_registerECFactory);
00286 CPPUNIT_TEST(test_getModulesFactories);
00287
00288 CPPUNIT_TEST(test_getLoadableModules);
00289 CPPUNIT_TEST(test_notifyFinalized);
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305 CPPUNIT_TEST_SUITE_END();
00306
00307 private:
00308 RTC::Manager* m_mgr;
00309
00310
00311 private:
00312 bool isFound(const std::vector<std::string>& list, const std::string& target)
00313 {
00314 return ! (list.end() == std::find(list.begin(), list.end(), target));
00315 }
00316
00317 CosNaming::NamingContext_var getRootContext(const std::string& name_server)
00318 {
00319 std::string nsName
00320 = std::string("corbaloc::")
00321 + name_server
00322 + std::string("/NameService");
00323
00324 CORBA::Object_var obj = m_mgr->getORB()->string_to_object(nsName.c_str());
00325 CosNaming::NamingContext_var rootContext = CosNaming::NamingContext::_narrow(obj);
00326 if (CORBA::is_nil(rootContext))
00327 {
00328 throw std::bad_alloc();
00329 }
00330
00331 return rootContext;
00332 }
00333
00334 bool canResolve(const char* name_server, const char* id, const char* kind)
00335 {
00336 CosNaming::NamingContext_var nc = getRootContext(name_server);
00337 if (CORBA::is_nil(nc)) return false;
00338 CosNaming::Name name;
00339 name.length(1);
00340 name[0].id = id;
00341 name[0].kind = kind;
00342
00343 CORBA::Object_var obj;
00344 try
00345 {
00346 obj = nc->resolve(name);
00347 }
00348 catch (CosNaming::NamingContext::NotFound e)
00349 {
00350 return false;
00351 }
00352 catch (...)
00353 {
00354 std::cout << "nameserver->resolve() failed" << std::endl;
00355 return false;
00356 }
00357 return !CORBA::is_nil(obj);
00358 }
00359
00360 public:
00364 ManagerTests()
00365 {
00366 }
00367
00371 virtual ~ManagerTests()
00372 {
00373 }
00374
00378 virtual void setUp()
00379 {
00380 ManagerMock::clearInstance();
00381 m_mgr = NULL;
00382 coil::usleep(100000);
00383 }
00384
00388 virtual void tearDown()
00389 {
00390 coil::usleep(100000);
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406 }
00412 void test_init_without_arguments()
00413 {
00414
00415 m_mgr = RTC::Manager::init(0, NULL);
00416 CPPUNIT_ASSERT(m_mgr != NULL);
00417
00418 }
00419
00425 void test_instance()
00426 {
00427 int argc = 0;
00428 char* argv[] = {};
00429
00430 m_mgr = RTC::Manager::init(argc, argv);
00431 CPPUNIT_ASSERT(m_mgr != NULL);
00432
00433
00434 RTC::Manager& instance = RTC::Manager::instance();
00435 CPPUNIT_ASSERT_EQUAL(m_mgr, &instance);
00436 }
00437
00443 void test_instance_without_init()
00444 {
00445
00446 RTC::Manager::instance();
00447 }
00448
00454 void test_terminate_immediately_after_the_initialization()
00455 {
00456
00457 int argc = 0;
00458 char* argv[] = {};
00459
00460 m_mgr = RTC::Manager::init(argc, argv);
00461 CPPUNIT_ASSERT(m_mgr != NULL);
00462 CPPUNIT_ASSERT(m_mgr->getORB() != NULL);
00463 CPPUNIT_ASSERT(m_mgr->getPOA() != NULL);
00464
00465
00466 CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB()));
00467 CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA()));
00468 m_mgr->terminate();
00469 coil::sleep(3);
00470 CPPUNIT_ASSERT(CORBA::is_nil(m_mgr->getORB()));
00471 CPPUNIT_ASSERT(CORBA::is_nil(m_mgr->getPOA()));
00472 m_mgr = NULL;
00473 }
00474
00480 void test_terminate_after_the_activation()
00481 {
00482
00483 int argc = 0;
00484 char* argv[] = {};
00485
00486 m_mgr = RTC::Manager::init(argc, argv);
00487 CPPUNIT_ASSERT(m_mgr != NULL);
00488 CPPUNIT_ASSERT(m_mgr->getORB() != NULL);
00489
00490
00491 CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA()));
00492 CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager()));
00493
00494
00495 CPPUNIT_ASSERT(m_mgr->activateManager());
00496
00497
00498 CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB()));
00499 CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA()));
00500 m_mgr->terminate();
00501 coil::sleep(3);
00502 CPPUNIT_ASSERT(CORBA::is_nil(m_mgr->getORB()));
00503 CPPUNIT_ASSERT(CORBA::is_nil(m_mgr->getPOA()));
00504 }
00505
00506 void test_notifyFinalized()
00507 {
00508
00509 }
00510
00511 void test_shutdown()
00512 {
00513
00514 }
00515
00516 void test_join()
00517 {
00518
00519
00520 }
00521
00527 void test_getConfig()
00528 {
00529
00530 int argc = 3;
00531 char* argv[] = { "ManagerTests","-f","fixture2.conf" };
00532
00533 m_mgr = RTC::Manager::init(argc, argv);
00534 CPPUNIT_ASSERT(m_mgr != NULL);
00535
00536
00537 coil::Properties& properties = m_mgr->getConfig();
00538 CPPUNIT_ASSERT_EQUAL(std::string("NO"),
00539 properties.getProperty("logger.enable"));
00540 CPPUNIT_ASSERT_EQUAL(std::string("fixture2.log"),
00541 properties.getProperty("logger.file_name"));
00542 }
00543
00549 void test_setModuleInitProc()
00550 {
00551
00552 Logger logger;
00553 ModuleMock::setLogger(&logger);
00554
00555
00556 int argc = 0;
00557 char* argv[] = {};
00558
00559 m_mgr = RTC::Manager::init(argc, argv);
00560 CPPUNIT_ASSERT(m_mgr != NULL);
00561
00562
00563 m_mgr->setModuleInitProc(&ModuleMock::InitProc);
00564
00565
00566 CPPUNIT_ASSERT_EQUAL(0, logger.countLog("InitProc"));
00567 CPPUNIT_ASSERT(m_mgr->activateManager());
00568 CPPUNIT_ASSERT_EQUAL(1, logger.countLog("InitProc"));
00569 }
00570
00571 void test_activateManager()
00572 {
00573
00574 }
00575
00581 void test_runManager_no_block()
00582 {
00583
00584 int argc = 0;
00585 char* argv[] = {};
00586 m_mgr = RTC::Manager::init(argc, argv);
00587 CPPUNIT_ASSERT(m_mgr != NULL);
00588
00589
00590 CORBA::ORB_ptr orb = m_mgr->getORB();
00591 CPPUNIT_ASSERT(! CORBA::is_nil(orb));
00592 PortableServer::POA_ptr poa = m_mgr->getPOA();
00593 CPPUNIT_ASSERT(! CORBA::is_nil(poa));
00594
00595 RTObjectMock* rto = new RTObjectMock(orb, poa);
00596 CPPUNIT_ASSERT(rto != NULL);
00597
00598
00599 PortableServer::ObjectId_var rtoId;
00600 try
00601 {
00602 rtoId = poa->activate_object(rto);
00603 }
00604 catch(const ::PortableServer::POA::ServantAlreadyActive &)
00605 {
00606 rtoId = poa->servant_to_id(rto);
00607 }
00608
00609
00610 RTC::DataFlowComponent_ptr rtoRef
00611 = RTC::DataFlowComponent::_narrow(poa->id_to_reference(rtoId));
00612 CPPUNIT_ASSERT(! CORBA::is_nil(rtoRef));
00613
00614 Logger logger;
00615 rto->setLogger(&logger);
00616
00617
00618 CPPUNIT_ASSERT(m_mgr->activateManager());
00619 m_mgr->runManager(true);
00620
00621
00622
00623
00624 CPPUNIT_ASSERT_EQUAL(0, logger.countLog("initialize"));
00625 rtoRef->initialize();
00626 coil::sleep(3);
00627 CPPUNIT_ASSERT_EQUAL(1, logger.countLog("initialize"));
00628
00629 poa->deactivate_object(rtoId);
00630 delete rto;
00631 }
00632
00638 void test_runManager_block()
00639 {
00640
00641 int argc = 0;
00642 char* argv[] = {};
00643
00644 m_mgr = RTC::Manager::init(argc, argv);
00645 CPPUNIT_ASSERT(m_mgr != NULL);
00646
00647
00648 CORBA::ORB_ptr orb = m_mgr->getORB();
00649 CPPUNIT_ASSERT(! CORBA::is_nil(orb));
00650 PortableServer::POA_ptr poa = m_mgr->getPOA();
00651 CPPUNIT_ASSERT(! CORBA::is_nil(poa));
00652
00653 RTObjectMock* rto = new RTObjectMock(orb, poa);
00654 CPPUNIT_ASSERT(rto != NULL);
00655
00656 PortableServer::ObjectId_var rtoId;
00657 try
00658 {
00659 rtoId = poa->activate_object(rto);
00660 }
00661 catch(const ::PortableServer::POA::ServantAlreadyActive &)
00662 {
00663 rtoId = poa->servant_to_id(rto);
00664 }
00665
00666 RTC::DataFlowComponent_ptr rtoRef
00667 = RTC::DataFlowComponent::_narrow(poa->id_to_reference(rtoId));
00668 CPPUNIT_ASSERT(! CORBA::is_nil(rtoRef));
00669
00670
00671 Logger logger;
00672 rto->setLogger(&logger);
00673
00674
00675 CPPUNIT_ASSERT(m_mgr->activateManager());
00676 CPPUNIT_ASSERT_EQUAL(0, logger.countLog("initialize"));
00677 {
00678 InvokerMock invoker(rtoRef, m_mgr);
00679 m_mgr->runManager(false);
00680 coil::sleep(3);
00681 }
00682 CPPUNIT_ASSERT_EQUAL(1, logger.countLog("initialize"));
00683
00684 poa->deactivate_object(rtoId);
00685 delete rto;
00686 }
00687
00688 class InvokerMock
00689 : public coil::Task
00690 {
00691 public:
00692 InvokerMock(const RTC::DataFlowComponent_ptr& rtoRef, RTC::Manager* mgr)
00693 {
00694 m_rtoRef = RTC::DataFlowComponent::_duplicate(rtoRef);
00695 m_mgr = mgr;
00696 activate();
00697 }
00698
00699 ~InvokerMock()
00700 {
00701 wait();
00702 }
00703
00704 virtual int svc(void)
00705 {
00706 m_rtoRef->initialize();
00707 coil::sleep(1);
00708
00709
00710 m_rtoRef->exit();
00711 m_mgr->shutdown();
00712 m_mgr->join();
00713
00714 return 0;
00715 }
00716
00717 private:
00718 RTC::DataFlowComponent_ptr m_rtoRef;
00719 RTC::Manager* m_mgr;
00720 };
00721
00727 void test_load()
00728 {
00729
00730 int argc = 3;
00731 char* argv[] = { "ManagerTests","-f","fixture3.conf" };
00732
00733 m_mgr = RTC::Manager::init(argc, argv);
00734 CPPUNIT_ASSERT(m_mgr != NULL);
00735
00736
00737 typedef int (*FUNC_GETINITPROCCOUNT)();
00738 typedef void (*FUNC_RESETINITPROCCOUNT)();
00739 coil::DynamicLib loader("./.libs/DummyModule.so");
00740
00741 FUNC_GETINITPROCCOUNT pGetInitProcCount
00742 = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount");
00743 CPPUNIT_ASSERT(pGetInitProcCount != NULL);
00744
00745 FUNC_RESETINITPROCCOUNT pResetInitProcCount
00746 = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount");
00747 CPPUNIT_ASSERT(pResetInitProcCount != NULL);
00748
00749 (*pResetInitProcCount)();
00750
00751
00752 CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)());
00753
00754 m_mgr->load("./.libs/DummyModule.so", "InitProc");
00755
00756
00757
00758 }
00759
00765 void test_unload()
00766 {
00767
00768 int argc = 1;
00769 char* argv[] = { "-f fixture3.conf" };
00770
00771 m_mgr = RTC::Manager::init(argc, argv);
00772 CPPUNIT_ASSERT(m_mgr != NULL);
00773
00774
00775 typedef int (*FUNC_GETINITPROCCOUNT)();
00776 typedef void (*FUNC_RESETINITPROCCOUNT)();
00777 coil::DynamicLib loader("./.libs/DummyModule.so");
00778
00779 FUNC_GETINITPROCCOUNT pGetInitProcCount
00780 = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount");
00781 CPPUNIT_ASSERT(pGetInitProcCount != NULL);
00782
00783 FUNC_RESETINITPROCCOUNT pResetInitProcCount
00784 = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount");
00785 CPPUNIT_ASSERT(pResetInitProcCount != NULL);
00786
00787 (*pResetInitProcCount)();
00788
00789
00790 CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)());
00791 m_mgr->load("./.libs/DummyModule.so", "InitProc");
00792
00793
00794
00795
00796
00797
00798
00799 }
00800
00806 void test_unloadAll()
00807 {
00808
00809 int argc = 3;
00810 char* argv[] = { "ManagerTests","-f","fixture3.conf" };
00811
00812 m_mgr = RTC::Manager::init(argc, argv);
00813 CPPUNIT_ASSERT(m_mgr != NULL);
00814
00815
00816 typedef int (*FUNC_GETINITPROCCOUNT)();
00817 typedef void (*FUNC_RESETINITPROCCOUNT)();
00818
00819 coil::DynamicLib loader1("./.libs/DummyModule.so");
00820 coil::DynamicLib loader2("./.libs/DummyModule2.so");
00821
00822 FUNC_GETINITPROCCOUNT pGetInitProcCount1
00823 = (FUNC_GETINITPROCCOUNT) loader1.symbol("getInitProcCount");
00824 CPPUNIT_ASSERT(pGetInitProcCount1 != NULL);
00825
00826 FUNC_RESETINITPROCCOUNT pResetInitProcCount1
00827 = (FUNC_RESETINITPROCCOUNT) loader1.symbol("resetInitProcCount");
00828 CPPUNIT_ASSERT(pResetInitProcCount1 != NULL);
00829
00830 FUNC_GETINITPROCCOUNT pGetInitProcCount2
00831 = (FUNC_GETINITPROCCOUNT) loader2.symbol("getInitProcCount");
00832 CPPUNIT_ASSERT(pGetInitProcCount2 != NULL);
00833
00834 FUNC_RESETINITPROCCOUNT pResetInitProcCount2
00835 = (FUNC_RESETINITPROCCOUNT) loader2.symbol("resetInitProcCount");
00836 CPPUNIT_ASSERT(pResetInitProcCount2 != NULL);
00837
00838 (*pResetInitProcCount1)();
00839 (*pResetInitProcCount2)();
00840
00841
00842 CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount1)());
00843 CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount2)());
00844
00845
00846
00847 m_mgr->load("./.libs/DummyModule.so", "InitProc");
00848 m_mgr->load("./.libs/DummyModule2.so", "InitProc");
00849
00850
00851
00852
00853
00854
00855
00856
00857 m_mgr->unloadAll();
00858
00859
00860 }
00861
00867 void test_getLoadableModules()
00868 {
00869 int argc = 3;
00870 char* argv[] = { "ManagerTests","-f","fixture3.conf" };
00871
00872 m_mgr = RTC::Manager::init(argc, argv);
00873 CPPUNIT_ASSERT(m_mgr != NULL);
00874
00875
00876 typedef int (*FUNC_GETINITPROCCOUNT)();
00877 typedef void (*FUNC_RESETINITPROCCOUNT)();
00878 coil::DynamicLib loader("./.libs/DummyModule.so");
00879
00880 FUNC_GETINITPROCCOUNT pGetInitProcCount
00881 = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount");
00882 CPPUNIT_ASSERT(pGetInitProcCount != NULL);
00883
00884 FUNC_RESETINITPROCCOUNT pResetInitProcCount
00885 = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount");
00886 CPPUNIT_ASSERT(pResetInitProcCount != NULL);
00887
00888 (*pResetInitProcCount)();
00889
00890 CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)());
00891 m_mgr->load("./.libs/DummyModule.so", "InitProc");
00892
00893
00894 std::vector<coil::Properties> props = m_mgr->getLoadableModules();
00895 CPPUNIT_ASSERT(props.size() > 0);
00896
00897
00898
00899
00900
00901
00902 CPPUNIT_ASSERT_EQUAL(std::string("./.libs/DummyModule2.so"),
00903 props[0].getProperty("module_file_path"));
00904 }
00905
00911 void test_registerFactory()
00912 {
00913
00914 int argc = 0;
00915 char* argv[] = {};
00916
00917 m_mgr = RTC::Manager::init(argc, argv);
00918 CPPUNIT_ASSERT(m_mgr != NULL);
00919
00920
00921 coil::Properties properties;
00922 properties.setProperty("implementation_id", "ID");
00923
00924 CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID"));
00925 CPPUNIT_ASSERT(m_mgr->registerFactory(
00926 properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock));
00927 CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID"));
00928 }
00929
00935 void test_registerECFactory()
00936 {
00937
00938 int argc = 0;
00939 char* argv[] = {};
00940
00941 m_mgr = RTC::Manager::init(argc, argv);
00942 CPPUNIT_ASSERT(m_mgr != NULL);
00943
00944
00945 CPPUNIT_ASSERT(m_mgr->registerECFactory(
00946 "PeriodicEC",
00947 RTC::ECCreate<RTC::PeriodicExecutionContext>,
00948 RTC::ECDelete<RTC::PeriodicExecutionContext>));
00949
00950
00951 CPPUNIT_ASSERT(! m_mgr->registerECFactory(
00952 "PeriodicEC",
00953 RTC::ECCreate<RTC::PeriodicExecutionContext>,
00954 RTC::ECDelete<RTC::PeriodicExecutionContext>));
00955 }
00956
00962 void test_getModulesFactories()
00963 {
00964
00965 int argc = 0;
00966 char* argv[] = {};
00967
00968 m_mgr = RTC::Manager::init(argc, argv);
00969 CPPUNIT_ASSERT(m_mgr != NULL);
00970
00971
00972 coil::Properties properties1;
00973 properties1.setProperty("implementation_id", "ID 1");
00974 CPPUNIT_ASSERT(m_mgr->registerFactory(
00975 properties1, CreateDataFlowComponentMock, DeleteDataFlowComponentMock));
00976
00977 coil::Properties properties2;
00978 properties2.setProperty("implementation_id", "ID 2");
00979 CPPUNIT_ASSERT(m_mgr->registerFactory(
00980 properties2, CreateDataFlowComponentMock, DeleteDataFlowComponentMock));
00981
00982
00983 CPPUNIT_ASSERT_EQUAL(3, (int) m_mgr->getModulesFactories().size());
00984 CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID 1"));
00985 CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID 2"));
00986
00987 }
00988
00994 void test_createComponent_DataFlowComponent()
00995 {
00996
00997 int argc = 3;
00998 char* argv[] = { "ManagerTests","-f","fixture4.conf" };
00999
01000 m_mgr = RTC::Manager::init(argc, argv);
01001 CPPUNIT_ASSERT(m_mgr != NULL);
01002 CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB()));
01003 CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA()));
01004 CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager()));
01005
01006
01007 CPPUNIT_ASSERT(m_mgr->activateManager());
01008 m_mgr->runManager(true);
01009
01010
01011 coil::Properties properties;
01012 properties.setProperty("implementation_id", "DataFlowComponentFactory");
01013 properties.setProperty("type_name", "DataFlowComponent");
01014 CPPUNIT_ASSERT(m_mgr->registerFactory(
01015 properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock));
01016
01017
01018 CPPUNIT_ASSERT(m_mgr->registerECFactory(
01019 "PeriodicEC",
01020 RTC::ECCreate<RTC::PeriodicExecutionContext>,
01021 RTC::ECDelete<RTC::PeriodicExecutionContext>));
01022
01023
01024 RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory");
01025 CPPUNIT_ASSERT(comp != NULL);
01026 CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL);
01027 CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this()));
01028 CPPUNIT_ASSERT_EQUAL(
01029 std::string("DataFlowComponent0"),
01030 std::string(comp->getInstanceName()));
01031
01032
01033 RTC::ExecutionContextList* ecList = comp->get_owned_contexts();
01034 CPPUNIT_ASSERT(ecList != NULL);
01035 CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length());
01036
01037
01038
01039 RTC::NamingManager nmgr(m_mgr);
01040 const char* name_server = "localhost:2809";
01041 nmgr.registerNameServer("corba", name_server);
01042 CPPUNIT_ASSERT(canResolve(name_server, "DataFlowComponent0", "rtc"));
01043
01044 comp->exit();
01045 m_mgr->terminate();
01046 }
01047
01048 void test_createComponent_Non_DataFlowComponent()
01049 {
01050
01051 }
01052
01059 void test_createComponent_with_illegal_module_name()
01060 {
01061
01062 int argc = 0;
01063 char* argv[] = {};
01064
01065 m_mgr = RTC::Manager::init(argc, argv);
01066 CPPUNIT_ASSERT(m_mgr != NULL);
01067 CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB()));
01068 CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA()));
01069 CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager()));
01070
01071
01072 RTC::RtcBase* comp1 = m_mgr->createComponent("illegal_module_name");
01073 CPPUNIT_ASSERT(comp1 == NULL);
01074
01075
01076 RTC::RtcBase* comp2 = m_mgr->createComponent(NULL);
01077 CPPUNIT_ASSERT(comp2 == NULL);
01078 }
01079
01080 void test_createComponent_failed_in_bindExecutionContext()
01081 {
01082
01083 int argc = 3;
01084 char* argv[] = { "ManagerTests","-f","fixture4.conf" };
01085
01086 m_mgr = RTC::Manager::init(argc, argv);
01087 CPPUNIT_ASSERT(m_mgr != NULL);
01088 CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB()));
01089 CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA()));
01090 CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager()));
01091
01092
01093 CPPUNIT_ASSERT(m_mgr->activateManager());
01094 m_mgr->runManager(true);
01095
01096
01097 coil::Properties properties;
01098 properties.setProperty("implementation_id", "DataFlowComponentFactory");
01099 properties.setProperty("type_name", "DataFlowComponent");
01100 CPPUNIT_ASSERT(m_mgr->registerFactory(
01101 properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock));
01102
01103
01104
01105
01106 RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory");
01107 CPPUNIT_ASSERT(comp == NULL);
01108
01109 m_mgr->terminate();
01110 coil::usleep(3000000);
01111 }
01112
01119 void test_cleanupComponent()
01120 {
01121
01122
01123
01124 int argc = 3;
01125 char* argv[] = { "ManagerTests","-f","fixture4.conf" };
01126
01127 m_mgr = RTC::Manager::init(argc, argv);
01128 CPPUNIT_ASSERT(m_mgr != NULL);
01129 CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB()));
01130 CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA()));
01131 CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager()));
01132
01133
01134 CPPUNIT_ASSERT(m_mgr->activateManager());
01135 m_mgr->runManager(true);
01136
01137
01138 coil::Properties properties;
01139 properties.setProperty("implementation_id", "DataFlowComponentFactory");
01140 properties.setProperty("type_name", "DataFlowComponent");
01141 CPPUNIT_ASSERT(m_mgr->registerFactory(
01142 properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock));
01143
01144
01145 CPPUNIT_ASSERT(m_mgr->registerECFactory(
01146 "PeriodicEC",
01147 RTC::ECCreate<RTC::PeriodicExecutionContext>,
01148 RTC::ECDelete<RTC::PeriodicExecutionContext>));
01149
01150
01151
01152 RTC::NamingManager nmgr(m_mgr);
01153 const char* name_server = "localhost:2809";
01154 nmgr.registerNameServer("corba", name_server);
01155
01156
01157 RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory");
01158
01159 CPPUNIT_ASSERT(comp != NULL);
01160 CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL);
01161 CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this()));
01162 CPPUNIT_ASSERT_EQUAL(
01163 std::string("DataFlowComponent0"),
01164 std::string(comp->getInstanceName()));
01165
01166
01167 RTC::ExecutionContextList* ecList = comp->get_owned_contexts();
01168 CPPUNIT_ASSERT(ecList != NULL);
01169 CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length());
01170
01171
01172
01173
01174 CPPUNIT_ASSERT(!canResolve(name_server, "DataFlowComponent0", "rtc"));
01175 CPPUNIT_ASSERT_EQUAL(comp, m_mgr->getComponent("DataFlowComponent0"));
01176
01177 m_mgr->cleanupComponent(comp);
01178 CPPUNIT_ASSERT(! canResolve(name_server, "DataFlowComponent0", "rtc"));
01179 CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL);
01180
01181 comp->exit();
01182 usleep(10000);
01183 m_mgr->terminate();
01184
01185 }
01186
01187 void test_unregisterComponent()
01188 {
01189
01190 }
01191
01192 void test_bindExecutionContext()
01193 {
01194
01195 }
01196
01197 void test_getComponent()
01198 {
01199
01200 }
01201
01208 void test_getComponents()
01209 {
01210
01211 int argc = 3;
01212 char* argv[] = { "ManagerTests","-f","fixture4.conf" };
01213
01214 m_mgr = RTC::Manager::init(argc, argv);
01215 CPPUNIT_ASSERT(m_mgr != NULL);
01216 CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB()));
01217 CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA()));
01218 CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager()));
01219
01220
01221 CPPUNIT_ASSERT(m_mgr->activateManager());
01222 m_mgr->runManager(true);
01223
01224
01225 coil::Properties properties;
01226 properties.setProperty("implementation_id", "DataFlowComponentFactory");
01227 properties.setProperty("type_name", "DataFlowComponent");
01228 CPPUNIT_ASSERT(m_mgr->registerFactory(
01229 properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock));
01230
01231
01232 CPPUNIT_ASSERT(m_mgr->registerECFactory(
01233 "PeriodicEC",
01234 RTC::ECCreate<RTC::PeriodicExecutionContext>,
01235 RTC::ECDelete<RTC::PeriodicExecutionContext>));
01236
01237
01238 RTC::RtcBase* comp1 = m_mgr->createComponent("DataFlowComponentFactory");
01239 CPPUNIT_ASSERT(comp1 != NULL);
01240 CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp1) != NULL);
01241 CPPUNIT_ASSERT(! CORBA::is_nil(comp1->_this()));
01242
01243 RTC::RtcBase* comp2 = m_mgr->createComponent("DataFlowComponentFactory");
01244 CPPUNIT_ASSERT(comp2 != NULL);
01245 CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp2) != NULL);
01246 CPPUNIT_ASSERT(! CORBA::is_nil(comp2->_this()));
01247
01248 CPPUNIT_ASSERT(comp1 != comp2);
01249
01250
01251 std::vector<RTC::RtcBase*> comps = m_mgr->getComponents();
01252 CPPUNIT_ASSERT_EQUAL(2, (int) comps.size());
01253 CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) != comps.end());
01254 CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end());
01255
01256
01257 m_mgr->cleanupComponent(comp1);
01258 comps = m_mgr->getComponents();
01259 CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) == comps.end());
01260 CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end());
01261
01262 comp1->exit();
01263 comp2->exit();
01264 m_mgr->terminate();
01265 }
01266
01267 void test_getORB()
01268 {
01269
01270 }
01271
01272 void test_getPOA()
01273 {
01274
01275 }
01276
01277 void test_getPOAManager()
01278 {
01279
01280 }
01281
01287 void test_initFactories()
01288 {
01289
01290 m_mgr = RTC::Manager::init(0, NULL);
01291 CPPUNIT_ASSERT(m_mgr != NULL);
01292
01293
01294 bool bret = RTC::CdrBufferFactory::instance().hasFactory("ring_buffer");
01295 CPPUNIT_ASSERT(bret);
01296
01297 bret = RTC::PeriodicTaskFactory::instance().hasFactory("default");
01298 CPPUNIT_ASSERT(bret);
01299
01300 bret = RTC::PublisherFactory::instance().hasFactory("flush");
01301 CPPUNIT_ASSERT(bret);
01302
01303 bret = RTC::PublisherFactory::instance().hasFactory("new");
01304 CPPUNIT_ASSERT(bret);
01305
01306 bret = RTC::PublisherFactory::instance().hasFactory("periodic");
01307 CPPUNIT_ASSERT(bret);
01308
01309 RTC::InPortProviderFactory& factory1(RTC::InPortProviderFactory::instance());
01310 bret = factory1.hasFactory("corba_cdr");
01311 CPPUNIT_ASSERT(bret);
01312
01313 RTC::InPortConsumerFactory& factory2(RTC::InPortConsumerFactory::instance());
01314 bret = factory2.hasFactory("corba_cdr");
01315 CPPUNIT_ASSERT(bret);
01316
01317 RTC::OutPortConsumerFactory& factory3(RTC::OutPortConsumerFactory::instance());
01318 bret = factory3.hasFactory("corba_cdr");
01319 CPPUNIT_ASSERT(bret);
01320
01321 RTC::OutPortProviderFactory& factory4(RTC::OutPortProviderFactory::instance());
01322 bret = factory4.hasFactory("corba_cdr");
01323 CPPUNIT_ASSERT(bret);
01324 }
01325
01331 void test_initComposite()
01332 {
01333
01334 m_mgr = RTC::Manager::init(0, NULL);
01335 CPPUNIT_ASSERT(m_mgr != NULL);
01336
01337
01338
01339 CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "PeriodicECSharedComposite"));
01340 }
01341
01347 void test_procContextArgs()
01348 {
01349 std::string ec_args;
01350 std::string ec_id;
01351 coil::Properties ec_prop;
01352
01353
01354 ManagerTestMock* man = new ManagerTestMock();
01355
01356
01357 ec_args = "";
01358 bool bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop);
01359 CPPUNIT_ASSERT(!bret);
01360
01361
01362 ec_args = "periodic?rate=1000?policy=skip";
01363 bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop);
01364 CPPUNIT_ASSERT(!bret);
01365
01366
01367 ec_args = "?rate=1000";
01368 bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop);
01369 CPPUNIT_ASSERT(!bret);
01370
01371
01372 ec_args = "periodic?rate=1000";
01373 bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop);
01374 CPPUNIT_ASSERT(bret);
01375 std::string chk_val("periodic");
01376 CPPUNIT_ASSERT_EQUAL(chk_val, ec_id);
01377 chk_val = "1000";
01378 CPPUNIT_ASSERT_EQUAL(chk_val, ec_prop["rate"]);
01379
01380 delete man;
01381 }
01382
01388 void test_getLogLevel()
01389 {
01390 m_mgr = RTC::Manager::init(0, NULL);
01391 CPPUNIT_ASSERT(m_mgr != NULL);
01392 std::string log_level = m_mgr->getLogLevel();
01393 CPPUNIT_ASSERT_EQUAL(std::string("INFO"), log_level);
01394 }
01395
01401 void test_getLoadedModules()
01402 {
01403 int argc = 3;
01404 char* argv[] = { "ManagerTests","-f","fixture3.conf" };
01405
01406 m_mgr = RTC::Manager::init(argc, argv);
01407 CPPUNIT_ASSERT(m_mgr != NULL);
01408
01409
01410 typedef int (*FUNC_GETINITPROCCOUNT)();
01411 typedef void (*FUNC_RESETINITPROCCOUNT)();
01412 coil::DynamicLib loader("./.libs/DummyModule.so");
01413
01414
01415
01416
01417
01418
01419
01420
01421
01422
01423
01424
01425
01426
01427
01428
01429
01430
01431
01432
01433
01434 }
01435
01441 void test_getFactoryProfiles()
01442 {
01443 m_mgr = RTC::Manager::init(0, NULL);
01444 CPPUNIT_ASSERT(m_mgr != NULL);
01445
01446
01447 coil::Properties properties;
01448 properties.setProperty("implementation_id", "ID");
01449
01450 CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID"));
01451 CPPUNIT_ASSERT(m_mgr->registerFactory(
01452 properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock));
01453 CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID"));
01454
01455 std::vector<coil::Properties> props = m_mgr->getFactoryProfiles();
01456 CPPUNIT_ASSERT(props.size() > 0);
01457
01458 CPPUNIT_ASSERT_EQUAL(std::string("PeriodicECSharedComposite"),
01459 props[0].getProperty("implementation_id"));
01460 CPPUNIT_ASSERT_EQUAL(std::string("ID"),
01461 props[1].getProperty("implementation_id"));
01462 }
01463
01469 void test_createContext()
01470 {
01471 RTC::ExecutionContextBase* ec;
01472 std::string ec_args;
01473
01474 m_mgr = RTC::Manager::init(0, NULL);
01475 CPPUNIT_ASSERT(m_mgr != NULL);
01476
01477
01478 ec_args = "";
01479 ec = m_mgr->createContext(ec_args.c_str());
01480 CPPUNIT_ASSERT(ec == NULL);
01481
01482
01483 ec_args = "periodic?rate=1000";
01484 ec = m_mgr->createContext(ec_args.c_str());
01485 CPPUNIT_ASSERT(ec == NULL);
01486
01487
01488 m_mgr->registerECFactory("PeriodicEC",
01489 RTC::ECCreate<RTC::PeriodicExecutionContext>,
01490 RTC::ECDelete<RTC::PeriodicExecutionContext>);
01491 ec_args = "PeriodicEC?rate=1000";
01492 ec = m_mgr->createContext(ec_args.c_str());
01493 CPPUNIT_ASSERT(ec != NULL);
01494 }
01495
01501 void test_deleteComponent()
01502 {
01503 int argc = 3;
01504 char* argv[] = { "ManagerTests","-f","fixture4.conf" };
01505
01506 m_mgr = RTC::Manager::init(argc, argv);
01507 CPPUNIT_ASSERT(m_mgr != NULL);
01508 CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB()));
01509 CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA()));
01510 CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager()));
01511
01512
01513 CPPUNIT_ASSERT(m_mgr->activateManager());
01514 m_mgr->runManager(true);
01515
01516
01517 coil::Properties properties;
01518 properties.setProperty("implementation_id", "DataFlowComponentFactory");
01519 properties.setProperty("type_name", "DataFlowComponent");
01520 CPPUNIT_ASSERT(m_mgr->registerFactory(
01521 properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock));
01522
01523
01524 CPPUNIT_ASSERT(m_mgr->registerECFactory(
01525 "PeriodicEC",
01526 RTC::ECCreate<RTC::PeriodicExecutionContext>,
01527 RTC::ECDelete<RTC::PeriodicExecutionContext>));
01528
01529
01530 RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory");
01531 CPPUNIT_ASSERT(comp != NULL);
01532 CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL);
01533 CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this()));
01534 CPPUNIT_ASSERT_EQUAL(
01535 std::string("DataFlowComponent0"),
01536 std::string(comp->getInstanceName()));
01537
01538 CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") != NULL);
01539 std::vector<RTC::RTObject_impl*> comps = m_mgr->getComponents();
01540 CPPUNIT_ASSERT(comps.size() > 0);
01541
01542
01543 m_mgr->deleteComponent("DataFlowComponent0");
01544 CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL);
01545
01546
01547 }
01548
01554 void test_init2()
01555 {
01556
01557
01558
01559
01560
01561
01562
01563
01564
01565
01566
01567
01568
01569
01570
01571
01572
01573 }
01574
01575 };
01576 };
01577
01578
01579
01580
01581 CPPUNIT_TEST_SUITE_REGISTRATION(Tests::ManagerTests);
01582
01583 #ifdef LOCAL_MAIN
01584 int main(int argc, char* argv[])
01585 {
01586
01587 FORMAT format = TEXT_OUT;
01588 int target = 0;
01589 std::string xsl;
01590 std::string ns;
01591 std::string fname;
01592 std::ofstream ofs;
01593
01594 int i(1);
01595 while (i < argc)
01596 {
01597 std::string arg(argv[i]);
01598 std::string next_arg;
01599 if (i + 1 < argc) next_arg = argv[i + 1];
01600 else next_arg = "";
01601
01602 if (arg == "--text") { format = TEXT_OUT; break; }
01603 if (arg == "--xml")
01604 {
01605 if (next_arg == "")
01606 {
01607 fname = argv[0];
01608 fname += ".xml";
01609 }
01610 else
01611 {
01612 fname = next_arg;
01613 }
01614 format = XML_OUT;
01615 ofs.open(fname.c_str());
01616 }
01617 if ( arg == "--compiler" ) { format = COMPILER_OUT; break; }
01618 if ( arg == "--cerr" ) { target = 1; break; }
01619 if ( arg == "--xsl" )
01620 {
01621 if (next_arg == "") xsl = "default.xsl";
01622 else xsl = next_arg;
01623 }
01624 if ( arg == "--namespace" )
01625 {
01626 if (next_arg == "")
01627 {
01628 std::cerr << "no namespace specified" << std::endl;
01629 exit(1);
01630 }
01631 else
01632 {
01633 xsl = next_arg;
01634 }
01635 }
01636 ++i;
01637 }
01638 CppUnit::TextUi::TestRunner runner;
01639 if ( ns.empty() )
01640 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
01641 else
01642 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
01643 CppUnit::Outputter* outputter = 0;
01644 std::ostream* stream = target ? &std::cerr : &std::cout;
01645 switch ( format )
01646 {
01647 case TEXT_OUT :
01648 outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
01649 break;
01650 case XML_OUT :
01651 std::cout << "XML_OUT" << std::endl;
01652 outputter = new CppUnit::XmlOutputter(&runner.result(),
01653 ofs, "shift_jis");
01654 static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
01655 break;
01656 case COMPILER_OUT :
01657 outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
01658 break;
01659 }
01660 runner.setOutputter(outputter);
01661 runner.run();
01662 return 0;
01663 }
01664 #endif // MAIN
01665 #endif // ManagerTests_cpp