ManagerTests.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
11 /*
12  * $Log: ManagerTests.cpp,v $
13  * Revision 1.2 2008/05/12 03:58:45 arafune
14  * Added some tests.
15  * Rearranged tests in a different order.
16  *
17  * Revision 1.1 2008/05/09 12:01:44 arafune
18  * The first commitment.
19  *
20  *
21  */
22 
23 #ifndef ManagerTests_cpp
24 #define ManagerTests_cpp
25 
26 #include <cppunit/ui/text/TestRunner.h>
27 #include <cppunit/TextOutputter.h>
28 #include <cppunit/extensions/TestFactoryRegistry.h>
29 #include <cppunit/extensions/HelperMacros.h>
30 #include <cppunit/TestAssert.h>
31 
32 #include <coil/Task.h>
33 #include <coil/DynamicLib.h>
34 
35 #include <rtm/Manager.h>
36 #include <rtm/RTObject.h>
37 #include <rtm/ECFactory.h>
40 #include <rtm/NamingManager.h>
41 
42 #include <rtm/CdrRingBuffer.h>
45 #include <rtm/PublisherFlush.h>
46 #include <rtm/PublisherNew.h>
47 #include <rtm/PublisherPeriodic.h>
53 
58 namespace Tests
59 {
60  // shutdown ORB for ManagerTests.
61  // - This funcuion is added, because Manager::init() function does not destroy ORB.
62  //
64  {
65 
66  if(mgr == NULL)
67  {
68  return;
69  }
70  if(CORBA::is_nil(mgr->getORB()))
71  {
72  return;
73  }
74  try
75  {
76  while (mgr->getORB()->work_pending())
77  {
78  if (mgr->getORB()->work_pending())
79  mgr->getORB()->perform_work();
80  }
81  }
82  catch(...)
83  {
84  std::cout<<"Caught SystemException during perform_work."<<std::endl;
85  }
86 
87  if (!CORBA::is_nil(mgr->getPOA()))
88  {
89  try
90  {
91  if (!CORBA::is_nil(mgr->getPOAManager()))
92  {
93  mgr->getPOAManager()->deactivate(false, true);
94  }
95  mgr->getPOA()->destroy(false, true);
96  }
97  catch (CORBA::SystemException& ex)
98  {
99  std::cout<<"Caught SystemException during root POA destruction"<<std::endl;
100  }
101  catch (...)
102  {
103  std::cout<<"Caught unknown exception during POA destruction."<<std::endl;
104  }
105  }
106  if(!CORBA::is_nil(mgr->getORB()))
107  {
108  try
109  {
110  mgr->getORB()->shutdown(true);
111  mgr->getORB()->destroy();
112  }
113  catch (CORBA::SystemException& ex)
114  {
115  std::cout<<"Caught CORBA::SystemException during ORB shutdown"<<std::endl;;
116  }
117  catch (...)
118  {
119  std::cout<<"Caught unknown exception during ORB shutdown."<<std::endl;;
120  }
121  }
122  }
123 
124  class Logger
125  {
126  public:
127  void log(const std::string& msg)
128  {
129  m_log.push_back(msg);
130  }
131 
132  int countLog(const std::string& msg)
133  {
134  int count = 0;
135  for (int i = 0; i < (int) m_log.size(); ++i)
136  {
137  if (m_log[i] == msg) ++count;
138  }
139  return count;
140  }
141 
142  private:
143  std::vector<std::string> m_log;
144  };
145 
146 
147  class ManagerMock : public RTC::Manager
148  {
149  public: // for test
150  static void clearInstance()
151  {
152  manager = NULL;
153  }
154  };
155 
156 
157  // protected: 関数のテスト用 class ManagerTestMock : public RTC::Manager { public: // コンストラクト ManagerTestMock() : RTC::Manager() {} virtual ~ManagerTestMock(void) {} // Manager::procContextArgs は、protected: の為ここへ定義。 bool procContextArgs(const char* ec_args, std::string& ec_id, coil::Properties& ec_conf) { bool bret = RTC::Manager::procContextArgs(ec_args, ec_id, ec_conf); return bret; } }; class ModuleMock { public: static void setLogger(Logger* logger) { m_logger = logger; } static void InitProc(RTC::Manager* manager) { if (m_logger != NULL) m_logger->log("InitProc"); } private: static Logger* m_logger; }; Logger* ModuleMock::m_logger = NULL; class RTObjectMock : virtual public RTC::RTObject_impl { public: RTObjectMock(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa) : RTC::RTObject_impl(orb, poa), m_logger(NULL) { } virtual RTC::ReturnCode_t initialize() throw (CORBA::SystemException) { RTC::RTObject_impl::initialize(); if (m_logger != NULL) m_logger->log("initialize"); return RTC::RTC_OK; } void setLogger(Logger* logger) { m_logger = logger; } private: Logger* m_logger; }; class DataFlowComponentMock : virtual public RTC::RTObject_impl { public: DataFlowComponentMock(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa) : RTC::RTObject_impl(orb, poa) { } RTC::UniqueId attach_context(RTC::ExecutionContext_ptr exec_context) throw (CORBA::SystemException) { return RTC::RTObject_impl::attach_context(exec_context); } }; RTC::RtcBase* CreateDataFlowComponentMock(RTC::Manager* manager) { CORBA::ORB_ptr orb = manager->getORB(); PortableServer::POA_ptr poa = manager->getPOA(); DataFlowComponentMock* comp = new DataFlowComponentMock(orb, poa); comp->setObjRef(comp->_this()); return comp; } void DeleteDataFlowComponentMock(RTC::RtcBase* rtc) { if (rtc != NULL) rtc->_remove_ref(); } class ManagerTests : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(ManagerTests); // CPPUNIT_TEST(test_deleteComponent); //OK CPPUNIT_TEST(test_getLogLevel); CPPUNIT_TEST(test_getLoadedModules); CPPUNIT_TEST(test_getFactoryProfiles); CPPUNIT_TEST(test_createContext); CPPUNIT_TEST(test_init2); CPPUNIT_TEST(test_initFactories); CPPUNIT_TEST(test_initComposite); CPPUNIT_TEST(test_procContextArgs); CPPUNIT_TEST(test_init_without_arguments); CPPUNIT_TEST(test_instance); CPPUNIT_TEST(test_instance_without_init); // CPPUNIT_TEST(test_terminate_immediately_after_the_initialization); //OK // CPPUNIT_TEST(test_terminate_after_the_activation); //OK CPPUNIT_TEST(test_getConfig); CPPUNIT_TEST(test_setModuleInitProc); // CPPUNIT_TEST(test_runManager_no_block); //OK // CPPUNIT_TEST(test_runManager_block); CPPUNIT_TEST(test_load); CPPUNIT_TEST(test_unload); CPPUNIT_TEST(test_unloadAll); CPPUNIT_TEST(test_registerFactory); CPPUNIT_TEST(test_registerECFactory); CPPUNIT_TEST(test_getModulesFactories); CPPUNIT_TEST(test_getLoadableModules); CPPUNIT_TEST(test_notifyFinalized); // CPPUNIT_TEST(test_cleanupComponent); //OK // CPPUNIT_TEST(test_getComponents); //OK // ※現在、各テスト間の独立性を完全に確保できていないため、下記テストは実施順序を変更しないこと。 // また、テスト内容を変更したり、他テストを追加したりする場合は、必ずしもテスト間の独立性が // 保たれない点に留意すること。なお、独立性が保てないのは、omniORBを用いた場合に、 // CORBA::ORB::destroy()が失敗する場合があり、次テスト時のCORBA::ORB_init()呼出が // 新ORBインスタンスを返さない場合があるため。詳しい原因は現時点では不明。 // // CPPUNIT_TEST(test_createComponent_DataFlowComponent); // CPPUNIT_TEST(test_createComponent_Non_DataFlowComponent); //OK // CPPUNIT_TEST(test_createComponent_failed_in_bindExecutionContext); //OK // CPPUNIT_TEST(test_createComponent_with_illegal_module_name); CPPUNIT_TEST_SUITE_END(); private: RTC::Manager* m_mgr; private: bool isFound(const std::vector<std::string>& list, const std::string& target) { return ! (list.end() == std::find(list.begin(), list.end(), target)); } CosNaming::NamingContext_var getRootContext(const std::string& name_server) { std::string nsName = std::string("corbaloc::") + name_server + std::string("/NameService"); CORBA::Object_var obj = m_mgr->getORB()->string_to_object(nsName.c_str()); CosNaming::NamingContext_var rootContext = CosNaming::NamingContext::_narrow(obj); if (CORBA::is_nil(rootContext)) { throw std::bad_alloc(); } return rootContext; } bool canResolve(const char* name_server, const char* id, const char* kind) { CosNaming::NamingContext_var nc = getRootContext(name_server); if (CORBA::is_nil(nc)) return false; CosNaming::Name name; name.length(1); name[0].id = id; name[0].kind = kind; CORBA::Object_var obj; try { obj = nc->resolve(name); } catch (CosNaming::NamingContext::NotFound e) { return false; } catch (...) { std::cout << "nameserver->resolve() failed" << std::endl; return false; } return !CORBA::is_nil(obj); } public: /*! * @brief Constructor */ ManagerTests() { } /*! * @brief Destructor */ virtual ~ManagerTests() { } /*! * @brief Test initialization */ virtual void setUp() { ManagerMock::clearInstance(); m_mgr = NULL; coil::usleep(100000); } /*! * @brief Test finalization */ virtual void tearDown() { coil::usleep(100000); /* if (m_mgr != NULL) { try { CORBA::ORB_ptr orb = m_mgr->getORB(); if (! CORBA::is_nil(orb)) { orb->destroy(); sleep(3); } } catch (...) {} } */ } /*! * @brief init()メソッドのテスト * * - コマンドライン引数なしでinit()を正常に呼出して、インスタンスを取得できるか? */ void test_init_without_arguments() { // コマンドライン引数なしでinit()を正常に呼出して、インスタンスを取得できるか? m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // m_mgr->terminate(); } /*! * @brief instance()メソッドのテスト * * - instance()を通じて取得したインスタンスは、init()時に得たインスタンスと同一か? */ void test_instance() { int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // instance()を通じて取得したインスタンスは、init()時に得たインスタンスと同一か? RTC::Manager& instance = RTC::Manager::instance(); CPPUNIT_ASSERT_EQUAL(m_mgr, &instance); } /*! * @brief instance()メソッドのテスト * * - 事前にinit()を呼出さずにinstance()を呼出した場合、正常にインスタンスが生成されるか? */ void test_instance_without_init() { // 事前にinit()を呼出さずにinstance()を呼出した場合、正常にインスタンスが生成されるか? RTC::Manager::instance(); } /*! * @brief terminate()メソッドのテスト * * - 初期化後すぐにterminate()を呼出し、正常に終了できるか? */ void test_terminate_immediately_after_the_initialization() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(m_mgr->getORB() != NULL); CPPUNIT_ASSERT(m_mgr->getPOA() != NULL); // 初期化後すぐにterminate()を呼出し、正常に終了できるか? CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); m_mgr->terminate(); coil::sleep(3); CPPUNIT_ASSERT(CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(CORBA::is_nil(m_mgr->getPOA())); m_mgr = NULL; } /*! * @brief terminate()メソッドのテスト * * - active化の後でterminate()を呼出し、正常に終了できるか? */ void test_terminate_after_the_activation() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(m_mgr->getORB() != NULL); // CPPUNIT_ASSERT(m_mgr->getPOA() != NULL); // CPPUNIT_ASSERT(m_mgr->getPOAManager() != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // active化する CPPUNIT_ASSERT(m_mgr->activateManager()); // active化の後でterminate()を呼出し、正常に終了できるか? CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); m_mgr->terminate(); coil::sleep(3); CPPUNIT_ASSERT(CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(CORBA::is_nil(m_mgr->getPOA())); } void test_notifyFinalized() { // shutdown()を通じて呼び出されるメソッドであるため、直接のテスト対象とはしない } void test_shutdown() { // terminate()を通じて呼び出されるメソッドであるため、直接のテスト対象とはしない } void test_join() { // shutdown()の中で使用されるメソッドであるため、直接のテスト対象とはしない // ※そもそも、なぜpublicメソッドになっているのだろうか? } /*! * @brief getConfig()メソッドのテスト * * - confファイルで指定した各種設定を、getConfig()を通じて正しく取得できるか? */ void test_getConfig() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture2.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // confファイルで指定した各種設定を、getConfig()を通じて正しく取得できるか? coil::Properties& properties = m_mgr->getConfig(); CPPUNIT_ASSERT_EQUAL(std::string("NO"), properties.getProperty("logger.enable")); CPPUNIT_ASSERT_EQUAL(std::string("fixture2.log"), properties.getProperty("logger.file_name")); } /*! * @brief setModuleInitProc()メソッドのテスト * * - アクティブ化により、設定した初期化プロシージャが正しく呼び出されるか? */ void test_setModuleInitProc() { // Mockの準備 Logger logger; ModuleMock::setLogger(&logger); // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // 初期化プロシージャを登録する m_mgr->setModuleInitProc(&ModuleMock::InitProc); // アクティブ化により、設定した初期化プロシージャが正しく呼び出されるか? CPPUNIT_ASSERT_EQUAL(0, logger.countLog("InitProc")); CPPUNIT_ASSERT(m_mgr->activateManager()); CPPUNIT_ASSERT_EQUAL(1, logger.countLog("InitProc")); } void test_activateManager() { // 他テスト中で使用されているため省略する } /*! * @brief runManager()メソッドのテスト(非ブロッキングモード) * * - POAManagerがアクティブ化されるか? */ void test_runManager_no_block() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // オブジェクトを生成して、参照を得る CORBA::ORB_ptr orb = m_mgr->getORB(); CPPUNIT_ASSERT(! CORBA::is_nil(orb)); PortableServer::POA_ptr poa = m_mgr->getPOA(); CPPUNIT_ASSERT(! CORBA::is_nil(poa)); RTObjectMock* rto = new RTObjectMock(orb, poa); CPPUNIT_ASSERT(rto != NULL); // PortableServer::ObjectId_var rtoId = poa->activate_object(rto); PortableServer::ObjectId_var rtoId; try { rtoId = poa->activate_object(rto); } catch(const ::PortableServer::POA::ServantAlreadyActive &) { rtoId = poa->servant_to_id(rto); } RTC::DataFlowComponent_ptr rtoRef = RTC::DataFlowComponent::_narrow(poa->id_to_reference(rtoId)); CPPUNIT_ASSERT(! CORBA::is_nil(rtoRef)); // テスト用にロガーを設定しておく Logger logger; rto->setLogger(&logger); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // runManager()によりPOAManagerが正しくactive化されているか? // (取得したオブジェクト参照に対してメソッド呼出を行い、 // リモート側が呼出されたことによりPOAManagerのアクティブ化を確認する) CPPUNIT_ASSERT_EQUAL(0, logger.countLog("initialize")); rtoRef->initialize(); coil::sleep(3); CPPUNIT_ASSERT_EQUAL(1, logger.countLog("initialize")); poa->deactivate_object(rtoId); delete rto; } /*! * @brief runManager()メソッドのテスト(ブロッキングモード) * * - POAManagerがアクティブ化されるか? */ void test_runManager_block() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // オブジェクトを生成して、参照を得る CORBA::ORB_ptr orb = m_mgr->getORB(); CPPUNIT_ASSERT(! CORBA::is_nil(orb)); PortableServer::POA_ptr poa = m_mgr->getPOA(); CPPUNIT_ASSERT(! CORBA::is_nil(poa)); RTObjectMock* rto = new RTObjectMock(orb, poa); CPPUNIT_ASSERT(rto != NULL); PortableServer::ObjectId_var rtoId; try { rtoId = poa->activate_object(rto); } catch(const ::PortableServer::POA::ServantAlreadyActive &) { rtoId = poa->servant_to_id(rto); } RTC::DataFlowComponent_ptr rtoRef = RTC::DataFlowComponent::_narrow(poa->id_to_reference(rtoId)); CPPUNIT_ASSERT(! CORBA::is_nil(rtoRef)); // テスト用にロガーを設定しておく Logger logger; rto->setLogger(&logger); // ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); CPPUNIT_ASSERT_EQUAL(0, logger.countLog("initialize")); { InvokerMock invoker(rtoRef, m_mgr); m_mgr->runManager(false); // true:非ブロッキング,false:ブロッキング coil::sleep(3); } CPPUNIT_ASSERT_EQUAL(1, logger.countLog("initialize")); poa->deactivate_object(rtoId); delete rto; } class InvokerMock : public coil::Task { public: InvokerMock(const RTC::DataFlowComponent_ptr& rtoRef, RTC::Manager* mgr) { m_rtoRef = RTC::DataFlowComponent::_duplicate(rtoRef); m_mgr = mgr; activate(); } ~InvokerMock() { wait(); } virtual int svc(void) { m_rtoRef->initialize(); coil::sleep(1); // ブロックされているrunManager呼出をブロック解除する m_rtoRef->exit(); m_mgr->shutdown(); m_mgr->join(); return 0; } private: RTC::DataFlowComponent_ptr m_rtoRef; RTC::Manager* m_mgr; }; /*! * @brief load()メソッドのテスト * * - 指定したモジュールをロードして、指定の初期化関数が正しく呼び出されるか? */ void test_load() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア // モジュールロードにより、指定した初期化関数が呼び出されるか? CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); // std::string moduleName = m_mgr->load("DummyModule.so", "InitProc"); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName)); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount)()); } /*! * @brief unload()メソッドのテスト * * - いったんloadしたモジュールを、正しくunloadできるか? */ void test_unload() { // 初期化を行う int argc = 1; char* argv[] = { "-f fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア // いったんloadしておく CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // std::string moduleName = m_mgr->load("DummyModule.so", "InitProc"); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName)); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount)()); // いったんloadしたモジュールを、正しくunloadできるか? // m_mgr->unload(moduleName.c_str()); // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName)); } /*! * @brief unloadAll()メソッドのテスト * * - unloadAll()により、ロードしたモジュールがすべてアンロードされるか? */ void test_unloadAll() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader1("./.libs/DummyModule.so"); coil::DynamicLib loader2("./.libs/DummyModule2.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount1 = (FUNC_GETINITPROCCOUNT) loader1.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount1 != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount1 = (FUNC_RESETINITPROCCOUNT) loader1.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount1 != NULL); FUNC_GETINITPROCCOUNT pGetInitProcCount2 = (FUNC_GETINITPROCCOUNT) loader2.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount2 != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount2 = (FUNC_RESETINITPROCCOUNT) loader2.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount2 != NULL); (*pResetInitProcCount1)(); // カウンタクリア (*pResetInitProcCount2)(); // カウンタクリア // いったんloadしておく CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount1)()); CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount2)()); // std::string moduleName1 = m_mgr->load("DummyModule.so", "InitProc"); // std::string moduleName2 = m_mgr->load("DummyModule2.so", "InitProc"); m_mgr->load("./.libs/DummyModule.so", "InitProc"); m_mgr->load("./.libs/DummyModule2.so", "InitProc"); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName1)); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName2)); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount1)()); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount2)()); // unloadAll()により、ロードしたモジュールがすべてアンロードされるか? m_mgr->unloadAll(); // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName1)); // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName2)); } /*! * @brief getLoadableModules()メソッドのテスト * * - ロード可能なモジュールリストを正しく取得できるか? */ void test_getLoadableModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード可能なモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadableModules(); CPPUNIT_ASSERT(props.size() > 0); //for(int i=0;i<props.size(); ++i) //{ // std::cout << "--------------- props[" << i << "] dump ---------------" << std::endl; // props[i].list(std::cout); //} CPPUNIT_ASSERT_EQUAL(std::string("./.libs/DummyModule2.so"), props[0].getProperty("module_file_path")); } /*! * @brief registerFactory()メソッドのテスト * * - Factoryを正常に登録できるか? */ void test_registerFactory() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); } /*! * @brief registerECFactory() * * - 正常にECFactoryを登録できるか? */ void test_registerECFactory() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // 正常にECFactoryを登録できるか? CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 登録済みのECFactoryと同一の名称で登録を試みた場合、意図どおり登録失敗するか? CPPUNIT_ASSERT(! m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); } /*! * @brief getModulesFactories()メソッドのテスト * * - 登録されているFactoryの("implementation_id"プロパティの)リストを正しく取得できるか? */ void test_getModulesFactories() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // 複数のFactoryを登録しておく coil::Properties properties1; properties1.setProperty("implementation_id", "ID 1"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties1, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); coil::Properties properties2; properties2.setProperty("implementation_id", "ID 2"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties2, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // 登録されているFactoryの("implementation_id"プロパティの)リストを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(3, (int) m_mgr->getModulesFactories().size()); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID 1")); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID 2")); } /*! * @brief createComponent()メソッドのテスト(DataFlowComponentの場合) * * - 正しくコンポーネントを生成できるか? */ void test_createComponent_DataFlowComponent() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), // ※末尾の0はNumberingPolicyにより付加される std::string(comp->getInstanceName())); // コンポーネントに、意図どおりExecutionContextがアタッチされているか? RTC::ExecutionContextList* ecList = comp->get_owned_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length()); // 生成されたコンポーネントは、正しくネームサービスに登録されているか? // ※fixture4.confの各設定に合わせている点に注意 RTC::NamingManager nmgr(m_mgr); const char* name_server = "localhost:2809"; nmgr.registerNameServer("corba", name_server); CPPUNIT_ASSERT(canResolve(name_server, "DataFlowComponent0", "rtc")); comp->exit(); m_mgr->terminate(); } void test_createComponent_Non_DataFlowComponent() { // 現時点では、Manager側がDataFlowComponentのみに対応しているため、テスト省略する } /*! * @brief createComponent()メソッドのテスト * * - 登録されていないモジュール名を指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? * - モジュール名にNULLを指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? */ void test_createComponent_with_illegal_module_name() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 登録されていないモジュール名を指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp1 = m_mgr->createComponent("illegal_module_name"); CPPUNIT_ASSERT(comp1 == NULL); // モジュール名にNULLを指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp2 = m_mgr->createComponent(NULL); CPPUNIT_ASSERT(comp2 == NULL); } void test_createComponent_failed_in_bindExecutionContext() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // bindExecutionContext()で失敗するように、意図的にECFactoryを登録せずにおく // コンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp == NULL); m_mgr->terminate(); coil::usleep(3000000); } /*! * @brief cleanupComponent()メソッドのテスト * * - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? * - 登録したコンポーネントが、Managerから正しく登録解除されるか? */ void test_cleanupComponent() { // 初期化を行う // int argc = 1; // char* argv[] = { "-f fixture4.conf" }; int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 確認用にネームサービスへのアクセス手段としてNamingManagerを準備しておく // ※fixture4.confの各設定に合わせている点に注意 RTC::NamingManager nmgr(m_mgr); const char* name_server = "localhost:2809"; nmgr.registerNameServer("corba", name_server); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), // ※末尾の0はNumberingPolicyにより付加される std::string(comp->getInstanceName())); // コンポーネントに、意図どおりExecutionContextがアタッチされているか? RTC::ExecutionContextList* ecList = comp->get_owned_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length()); // cleanupComponent()により、正しく登録解除されるか? // - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? // - 登録したコンポーネントが、Managerから正しく登録解除されるか? CPPUNIT_ASSERT(!canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT_EQUAL(comp, m_mgr->getComponent("DataFlowComponent0")); m_mgr->cleanupComponent(comp); CPPUNIT_ASSERT(! canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); comp->exit(); usleep(10000); m_mgr->terminate(); } void test_unregisterComponent() { // Manager::cleanupComponent()内で使用されているので、ここではテスト省略する } void test_bindExecutionContext() { // Manager::createComponent()内で使用されているので、ここではテスト省略する } void test_getComponent() { // 他テスト内で使用されているので、そちらで兼ねるものとして、ここではテスト省略する } /*! * @brief getComponents()メソッドのテスト * * - getComponents()で、生成したすべてのコンポーネントを取得できるか? * - 登録解除したコンポーネントが、正しく一覧から除外されているか? */ void test_getComponents() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 複数のコンポーネントを生成しておく RTC::RtcBase* comp1 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp1 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp1) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp1->_this())); RTC::RtcBase* comp2 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp2 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp2) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp2->_this())); CPPUNIT_ASSERT(comp1 != comp2); // getComponents()で、生成したすべてのコンポーネントを取得できるか? std::vector<RTC::RtcBase*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT_EQUAL(2, (int) comps.size()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) != comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); // コンポーネントを1つだけ登録解除した場合、解除したものが一覧から除外されているか? m_mgr->cleanupComponent(comp1); comps = m_mgr->getComponents(); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) == comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); comp1->exit(); comp2->exit(); m_mgr->terminate(); } void test_getORB() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOA() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOAManager() { // 他テスト内で使用されているので、ここではテスト省略する } /*! * @brief initFactories()メソッドのテスト * * - init()実行後、initFactories()の実行結果としてFactoryMapに正しく登録されているか? */ void test_initFactories() { // init()の中でinitFactories()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initFactories()の実行結果としてFactoryMapに正しく登録されているか? bool bret = RTC::CdrBufferFactory::instance().hasFactory("ring_buffer"); CPPUNIT_ASSERT(bret); bret = RTC::PeriodicTaskFactory::instance().hasFactory("default"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("flush"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("new"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("periodic"); CPPUNIT_ASSERT(bret); RTC::InPortProviderFactory& factory1(RTC::InPortProviderFactory::instance()); bret = factory1.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::InPortConsumerFactory& factory2(RTC::InPortConsumerFactory::instance()); bret = factory2.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortConsumerFactory& factory3(RTC::OutPortConsumerFactory::instance()); bret = factory3.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortProviderFactory& factory4(RTC::OutPortProviderFactory::instance()); bret = factory4.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); } /*! * @brief initComposite()メソッドのテスト * * - init()実行後、initComposite()の実行結果としてFactoryManagerに正しく登録されているか? */ void test_initComposite() { // init()の中でinitComposite()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initComposite()の実行結果としてFactoryManagerに正しく登録されているか? // "implementation_id"には, "PeriodicECSharedComposite"が設定されている CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "PeriodicECSharedComposite")); } /*! * @brief procContextArgs()メソッドのテスト * * - 引数ec_argsにより戻り値true・falseが正しく返却されるか? */ void test_procContextArgs() { std::string ec_args; std::string ec_id; coil::Properties ec_prop; // インスタンス生成 ManagerTestMock* man = new ManagerTestMock(); // falseを返すケース1:ec_args.size=0 ec_args = ""; bool bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース2:ec_args.size=3 ec_args = "periodic?rate=1000?policy=skip"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース3:ec_args[0].empty ec_args = "?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // trueを返すケース4:ec_args.size=2 ec_args = "periodic?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(bret); std::string chk_val("periodic"); CPPUNIT_ASSERT_EQUAL(chk_val, ec_id); chk_val = "1000"; CPPUNIT_ASSERT_EQUAL(chk_val, ec_prop["rate"]); delete man; } /*! * @brief getLogLevel()メソッドのテスト * * - log_levelが正しく返却されるか? */ void test_getLogLevel() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); std::string log_level = m_mgr->getLogLevel(); CPPUNIT_ASSERT_EQUAL(std::string("INFO"), log_level); } /*! * @brief getLoadedModules()メソッドのテスト * * - ロード済みのモジュールリストを正しく取得できるか? */ void test_getLoadedModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); /* FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード済みのモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadedModules(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string(".//./.libs/DummyModule.so"), props[0].getProperty("file_path")); */ } /*! * @brief getFactoryProfiles()メソッドのテスト * * - RTコンポーネント用ファクトリをリストを正しく取得できるか? */ void test_getFactoryProfiles() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); std::vector<coil::Properties> props = m_mgr->getFactoryProfiles(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string("PeriodicECSharedComposite"), props[0].getProperty("implementation_id")); CPPUNIT_ASSERT_EQUAL(std::string("ID"), props[1].getProperty("implementation_id")); } /*! * @brief createContext()メソッドのテスト * * - ExecutionContextBaseを正しく取得できるか? */ void test_createContext() { RTC::ExecutionContextBase* ec; std::string ec_args; m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // return NULL check ec_args = ""; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return NULL check (Factory not found) ec_args = "periodic?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return any check m_mgr->registerECFactory("PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>); ec_args = "PeriodicEC?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec != NULL); } /*! * @brief deleteComponent()メソッドのテスト * * - RTコンポーネントの削除が正しくできるか? */ void test_deleteComponent() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), std::string(comp->getInstanceName())); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") != NULL); std::vector<RTC::RTObject_impl*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT(comps.size() > 0); // 正しくコンポーネントを削除できるか? m_mgr->deleteComponent("DataFlowComponent0"); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); // deleteComponent()でexit()を実行しているため、これ以降のテストはできません。 } /*! * @brief init()、shutdown()から呼ばれるprotected関数のテスト * * - protected関数が正しく動作しているか? */ void test_init2() { // Manager::init()よりprotected関数が使用されているので、ここではテスト省略する // initManager() // initLogger() // initORB() // initNaming() // initFactories() // initExecContext() // initComposite() // initTimer() // initManagerServant() // Manager::shutdown()よりprotected関数が使用されているので、ここではテスト省略する // shutdownComponents(); // shutdownNaming(); // shutdownORB(); // shutdownManager(); // shutdownLogger(); } }; }; // namespace Tests /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(Tests::ManagerTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // ManagerTests_cpp
159  {
160  public:
161  // コンストラクト ManagerTestMock() : RTC::Manager() {} virtual ~ManagerTestMock(void) {} // Manager::procContextArgs は、protected: の為ここへ定義。 bool procContextArgs(const char* ec_args, std::string& ec_id, coil::Properties& ec_conf) { bool bret = RTC::Manager::procContextArgs(ec_args, ec_id, ec_conf); return bret; } }; class ModuleMock { public: static void setLogger(Logger* logger) { m_logger = logger; } static void InitProc(RTC::Manager* manager) { if (m_logger != NULL) m_logger->log("InitProc"); } private: static Logger* m_logger; }; Logger* ModuleMock::m_logger = NULL; class RTObjectMock : virtual public RTC::RTObject_impl { public: RTObjectMock(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa) : RTC::RTObject_impl(orb, poa), m_logger(NULL) { } virtual RTC::ReturnCode_t initialize() throw (CORBA::SystemException) { RTC::RTObject_impl::initialize(); if (m_logger != NULL) m_logger->log("initialize"); return RTC::RTC_OK; } void setLogger(Logger* logger) { m_logger = logger; } private: Logger* m_logger; }; class DataFlowComponentMock : virtual public RTC::RTObject_impl { public: DataFlowComponentMock(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa) : RTC::RTObject_impl(orb, poa) { } RTC::UniqueId attach_context(RTC::ExecutionContext_ptr exec_context) throw (CORBA::SystemException) { return RTC::RTObject_impl::attach_context(exec_context); } }; RTC::RtcBase* CreateDataFlowComponentMock(RTC::Manager* manager) { CORBA::ORB_ptr orb = manager->getORB(); PortableServer::POA_ptr poa = manager->getPOA(); DataFlowComponentMock* comp = new DataFlowComponentMock(orb, poa); comp->setObjRef(comp->_this()); return comp; } void DeleteDataFlowComponentMock(RTC::RtcBase* rtc) { if (rtc != NULL) rtc->_remove_ref(); } class ManagerTests : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(ManagerTests); // CPPUNIT_TEST(test_deleteComponent); //OK CPPUNIT_TEST(test_getLogLevel); CPPUNIT_TEST(test_getLoadedModules); CPPUNIT_TEST(test_getFactoryProfiles); CPPUNIT_TEST(test_createContext); CPPUNIT_TEST(test_init2); CPPUNIT_TEST(test_initFactories); CPPUNIT_TEST(test_initComposite); CPPUNIT_TEST(test_procContextArgs); CPPUNIT_TEST(test_init_without_arguments); CPPUNIT_TEST(test_instance); CPPUNIT_TEST(test_instance_without_init); // CPPUNIT_TEST(test_terminate_immediately_after_the_initialization); //OK // CPPUNIT_TEST(test_terminate_after_the_activation); //OK CPPUNIT_TEST(test_getConfig); CPPUNIT_TEST(test_setModuleInitProc); // CPPUNIT_TEST(test_runManager_no_block); //OK // CPPUNIT_TEST(test_runManager_block); CPPUNIT_TEST(test_load); CPPUNIT_TEST(test_unload); CPPUNIT_TEST(test_unloadAll); CPPUNIT_TEST(test_registerFactory); CPPUNIT_TEST(test_registerECFactory); CPPUNIT_TEST(test_getModulesFactories); CPPUNIT_TEST(test_getLoadableModules); CPPUNIT_TEST(test_notifyFinalized); // CPPUNIT_TEST(test_cleanupComponent); //OK // CPPUNIT_TEST(test_getComponents); //OK // ※現在、各テスト間の独立性を完全に確保できていないため、下記テストは実施順序を変更しないこと。 // また、テスト内容を変更したり、他テストを追加したりする場合は、必ずしもテスト間の独立性が // 保たれない点に留意すること。なお、独立性が保てないのは、omniORBを用いた場合に、 // CORBA::ORB::destroy()が失敗する場合があり、次テスト時のCORBA::ORB_init()呼出が // 新ORBインスタンスを返さない場合があるため。詳しい原因は現時点では不明。 // // CPPUNIT_TEST(test_createComponent_DataFlowComponent); // CPPUNIT_TEST(test_createComponent_Non_DataFlowComponent); //OK // CPPUNIT_TEST(test_createComponent_failed_in_bindExecutionContext); //OK // CPPUNIT_TEST(test_createComponent_with_illegal_module_name); CPPUNIT_TEST_SUITE_END(); private: RTC::Manager* m_mgr; private: bool isFound(const std::vector<std::string>& list, const std::string& target) { return ! (list.end() == std::find(list.begin(), list.end(), target)); } CosNaming::NamingContext_var getRootContext(const std::string& name_server) { std::string nsName = std::string("corbaloc::") + name_server + std::string("/NameService"); CORBA::Object_var obj = m_mgr->getORB()->string_to_object(nsName.c_str()); CosNaming::NamingContext_var rootContext = CosNaming::NamingContext::_narrow(obj); if (CORBA::is_nil(rootContext)) { throw std::bad_alloc(); } return rootContext; } bool canResolve(const char* name_server, const char* id, const char* kind) { CosNaming::NamingContext_var nc = getRootContext(name_server); if (CORBA::is_nil(nc)) return false; CosNaming::Name name; name.length(1); name[0].id = id; name[0].kind = kind; CORBA::Object_var obj; try { obj = nc->resolve(name); } catch (CosNaming::NamingContext::NotFound e) { return false; } catch (...) { std::cout << "nameserver->resolve() failed" << std::endl; return false; } return !CORBA::is_nil(obj); } public: /*! * @brief Constructor */ ManagerTests() { } /*! * @brief Destructor */ virtual ~ManagerTests() { } /*! * @brief Test initialization */ virtual void setUp() { ManagerMock::clearInstance(); m_mgr = NULL; coil::usleep(100000); } /*! * @brief Test finalization */ virtual void tearDown() { coil::usleep(100000); /* if (m_mgr != NULL) { try { CORBA::ORB_ptr orb = m_mgr->getORB(); if (! CORBA::is_nil(orb)) { orb->destroy(); sleep(3); } } catch (...) {} } */ } /*! * @brief init()メソッドのテスト * * - コマンドライン引数なしでinit()を正常に呼出して、インスタンスを取得できるか? */ void test_init_without_arguments() { // コマンドライン引数なしでinit()を正常に呼出して、インスタンスを取得できるか? m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // m_mgr->terminate(); } /*! * @brief instance()メソッドのテスト * * - instance()を通じて取得したインスタンスは、init()時に得たインスタンスと同一か? */ void test_instance() { int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // instance()を通じて取得したインスタンスは、init()時に得たインスタンスと同一か? RTC::Manager& instance = RTC::Manager::instance(); CPPUNIT_ASSERT_EQUAL(m_mgr, &instance); } /*! * @brief instance()メソッドのテスト * * - 事前にinit()を呼出さずにinstance()を呼出した場合、正常にインスタンスが生成されるか? */ void test_instance_without_init() { // 事前にinit()を呼出さずにinstance()を呼出した場合、正常にインスタンスが生成されるか? RTC::Manager::instance(); } /*! * @brief terminate()メソッドのテスト * * - 初期化後すぐにterminate()を呼出し、正常に終了できるか? */ void test_terminate_immediately_after_the_initialization() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(m_mgr->getORB() != NULL); CPPUNIT_ASSERT(m_mgr->getPOA() != NULL); // 初期化後すぐにterminate()を呼出し、正常に終了できるか? CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); m_mgr->terminate(); coil::sleep(3); CPPUNIT_ASSERT(CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(CORBA::is_nil(m_mgr->getPOA())); m_mgr = NULL; } /*! * @brief terminate()メソッドのテスト * * - active化の後でterminate()を呼出し、正常に終了できるか? */ void test_terminate_after_the_activation() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(m_mgr->getORB() != NULL); // CPPUNIT_ASSERT(m_mgr->getPOA() != NULL); // CPPUNIT_ASSERT(m_mgr->getPOAManager() != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // active化する CPPUNIT_ASSERT(m_mgr->activateManager()); // active化の後でterminate()を呼出し、正常に終了できるか? CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); m_mgr->terminate(); coil::sleep(3); CPPUNIT_ASSERT(CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(CORBA::is_nil(m_mgr->getPOA())); } void test_notifyFinalized() { // shutdown()を通じて呼び出されるメソッドであるため、直接のテスト対象とはしない } void test_shutdown() { // terminate()を通じて呼び出されるメソッドであるため、直接のテスト対象とはしない } void test_join() { // shutdown()の中で使用されるメソッドであるため、直接のテスト対象とはしない // ※そもそも、なぜpublicメソッドになっているのだろうか? } /*! * @brief getConfig()メソッドのテスト * * - confファイルで指定した各種設定を、getConfig()を通じて正しく取得できるか? */ void test_getConfig() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture2.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // confファイルで指定した各種設定を、getConfig()を通じて正しく取得できるか? coil::Properties& properties = m_mgr->getConfig(); CPPUNIT_ASSERT_EQUAL(std::string("NO"), properties.getProperty("logger.enable")); CPPUNIT_ASSERT_EQUAL(std::string("fixture2.log"), properties.getProperty("logger.file_name")); } /*! * @brief setModuleInitProc()メソッドのテスト * * - アクティブ化により、設定した初期化プロシージャが正しく呼び出されるか? */ void test_setModuleInitProc() { // Mockの準備 Logger logger; ModuleMock::setLogger(&logger); // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // 初期化プロシージャを登録する m_mgr->setModuleInitProc(&ModuleMock::InitProc); // アクティブ化により、設定した初期化プロシージャが正しく呼び出されるか? CPPUNIT_ASSERT_EQUAL(0, logger.countLog("InitProc")); CPPUNIT_ASSERT(m_mgr->activateManager()); CPPUNIT_ASSERT_EQUAL(1, logger.countLog("InitProc")); } void test_activateManager() { // 他テスト中で使用されているため省略する } /*! * @brief runManager()メソッドのテスト(非ブロッキングモード) * * - POAManagerがアクティブ化されるか? */ void test_runManager_no_block() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // オブジェクトを生成して、参照を得る CORBA::ORB_ptr orb = m_mgr->getORB(); CPPUNIT_ASSERT(! CORBA::is_nil(orb)); PortableServer::POA_ptr poa = m_mgr->getPOA(); CPPUNIT_ASSERT(! CORBA::is_nil(poa)); RTObjectMock* rto = new RTObjectMock(orb, poa); CPPUNIT_ASSERT(rto != NULL); // PortableServer::ObjectId_var rtoId = poa->activate_object(rto); PortableServer::ObjectId_var rtoId; try { rtoId = poa->activate_object(rto); } catch(const ::PortableServer::POA::ServantAlreadyActive &) { rtoId = poa->servant_to_id(rto); } RTC::DataFlowComponent_ptr rtoRef = RTC::DataFlowComponent::_narrow(poa->id_to_reference(rtoId)); CPPUNIT_ASSERT(! CORBA::is_nil(rtoRef)); // テスト用にロガーを設定しておく Logger logger; rto->setLogger(&logger); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // runManager()によりPOAManagerが正しくactive化されているか? // (取得したオブジェクト参照に対してメソッド呼出を行い、 // リモート側が呼出されたことによりPOAManagerのアクティブ化を確認する) CPPUNIT_ASSERT_EQUAL(0, logger.countLog("initialize")); rtoRef->initialize(); coil::sleep(3); CPPUNIT_ASSERT_EQUAL(1, logger.countLog("initialize")); poa->deactivate_object(rtoId); delete rto; } /*! * @brief runManager()メソッドのテスト(ブロッキングモード) * * - POAManagerがアクティブ化されるか? */ void test_runManager_block() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // オブジェクトを生成して、参照を得る CORBA::ORB_ptr orb = m_mgr->getORB(); CPPUNIT_ASSERT(! CORBA::is_nil(orb)); PortableServer::POA_ptr poa = m_mgr->getPOA(); CPPUNIT_ASSERT(! CORBA::is_nil(poa)); RTObjectMock* rto = new RTObjectMock(orb, poa); CPPUNIT_ASSERT(rto != NULL); PortableServer::ObjectId_var rtoId; try { rtoId = poa->activate_object(rto); } catch(const ::PortableServer::POA::ServantAlreadyActive &) { rtoId = poa->servant_to_id(rto); } RTC::DataFlowComponent_ptr rtoRef = RTC::DataFlowComponent::_narrow(poa->id_to_reference(rtoId)); CPPUNIT_ASSERT(! CORBA::is_nil(rtoRef)); // テスト用にロガーを設定しておく Logger logger; rto->setLogger(&logger); // ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); CPPUNIT_ASSERT_EQUAL(0, logger.countLog("initialize")); { InvokerMock invoker(rtoRef, m_mgr); m_mgr->runManager(false); // true:非ブロッキング,false:ブロッキング coil::sleep(3); } CPPUNIT_ASSERT_EQUAL(1, logger.countLog("initialize")); poa->deactivate_object(rtoId); delete rto; } class InvokerMock : public coil::Task { public: InvokerMock(const RTC::DataFlowComponent_ptr& rtoRef, RTC::Manager* mgr) { m_rtoRef = RTC::DataFlowComponent::_duplicate(rtoRef); m_mgr = mgr; activate(); } ~InvokerMock() { wait(); } virtual int svc(void) { m_rtoRef->initialize(); coil::sleep(1); // ブロックされているrunManager呼出をブロック解除する m_rtoRef->exit(); m_mgr->shutdown(); m_mgr->join(); return 0; } private: RTC::DataFlowComponent_ptr m_rtoRef; RTC::Manager* m_mgr; }; /*! * @brief load()メソッドのテスト * * - 指定したモジュールをロードして、指定の初期化関数が正しく呼び出されるか? */ void test_load() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア // モジュールロードにより、指定した初期化関数が呼び出されるか? CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); // std::string moduleName = m_mgr->load("DummyModule.so", "InitProc"); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName)); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount)()); } /*! * @brief unload()メソッドのテスト * * - いったんloadしたモジュールを、正しくunloadできるか? */ void test_unload() { // 初期化を行う int argc = 1; char* argv[] = { "-f fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア // いったんloadしておく CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // std::string moduleName = m_mgr->load("DummyModule.so", "InitProc"); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName)); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount)()); // いったんloadしたモジュールを、正しくunloadできるか? // m_mgr->unload(moduleName.c_str()); // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName)); } /*! * @brief unloadAll()メソッドのテスト * * - unloadAll()により、ロードしたモジュールがすべてアンロードされるか? */ void test_unloadAll() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader1("./.libs/DummyModule.so"); coil::DynamicLib loader2("./.libs/DummyModule2.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount1 = (FUNC_GETINITPROCCOUNT) loader1.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount1 != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount1 = (FUNC_RESETINITPROCCOUNT) loader1.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount1 != NULL); FUNC_GETINITPROCCOUNT pGetInitProcCount2 = (FUNC_GETINITPROCCOUNT) loader2.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount2 != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount2 = (FUNC_RESETINITPROCCOUNT) loader2.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount2 != NULL); (*pResetInitProcCount1)(); // カウンタクリア (*pResetInitProcCount2)(); // カウンタクリア // いったんloadしておく CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount1)()); CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount2)()); // std::string moduleName1 = m_mgr->load("DummyModule.so", "InitProc"); // std::string moduleName2 = m_mgr->load("DummyModule2.so", "InitProc"); m_mgr->load("./.libs/DummyModule.so", "InitProc"); m_mgr->load("./.libs/DummyModule2.so", "InitProc"); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName1)); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName2)); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount1)()); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount2)()); // unloadAll()により、ロードしたモジュールがすべてアンロードされるか? m_mgr->unloadAll(); // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName1)); // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName2)); } /*! * @brief getLoadableModules()メソッドのテスト * * - ロード可能なモジュールリストを正しく取得できるか? */ void test_getLoadableModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード可能なモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadableModules(); CPPUNIT_ASSERT(props.size() > 0); //for(int i=0;i<props.size(); ++i) //{ // std::cout << "--------------- props[" << i << "] dump ---------------" << std::endl; // props[i].list(std::cout); //} CPPUNIT_ASSERT_EQUAL(std::string("./.libs/DummyModule2.so"), props[0].getProperty("module_file_path")); } /*! * @brief registerFactory()メソッドのテスト * * - Factoryを正常に登録できるか? */ void test_registerFactory() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); } /*! * @brief registerECFactory() * * - 正常にECFactoryを登録できるか? */ void test_registerECFactory() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // 正常にECFactoryを登録できるか? CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 登録済みのECFactoryと同一の名称で登録を試みた場合、意図どおり登録失敗するか? CPPUNIT_ASSERT(! m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); } /*! * @brief getModulesFactories()メソッドのテスト * * - 登録されているFactoryの("implementation_id"プロパティの)リストを正しく取得できるか? */ void test_getModulesFactories() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // 複数のFactoryを登録しておく coil::Properties properties1; properties1.setProperty("implementation_id", "ID 1"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties1, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); coil::Properties properties2; properties2.setProperty("implementation_id", "ID 2"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties2, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // 登録されているFactoryの("implementation_id"プロパティの)リストを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(3, (int) m_mgr->getModulesFactories().size()); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID 1")); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID 2")); } /*! * @brief createComponent()メソッドのテスト(DataFlowComponentの場合) * * - 正しくコンポーネントを生成できるか? */ void test_createComponent_DataFlowComponent() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), // ※末尾の0はNumberingPolicyにより付加される std::string(comp->getInstanceName())); // コンポーネントに、意図どおりExecutionContextがアタッチされているか? RTC::ExecutionContextList* ecList = comp->get_owned_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length()); // 生成されたコンポーネントは、正しくネームサービスに登録されているか? // ※fixture4.confの各設定に合わせている点に注意 RTC::NamingManager nmgr(m_mgr); const char* name_server = "localhost:2809"; nmgr.registerNameServer("corba", name_server); CPPUNIT_ASSERT(canResolve(name_server, "DataFlowComponent0", "rtc")); comp->exit(); m_mgr->terminate(); } void test_createComponent_Non_DataFlowComponent() { // 現時点では、Manager側がDataFlowComponentのみに対応しているため、テスト省略する } /*! * @brief createComponent()メソッドのテスト * * - 登録されていないモジュール名を指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? * - モジュール名にNULLを指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? */ void test_createComponent_with_illegal_module_name() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 登録されていないモジュール名を指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp1 = m_mgr->createComponent("illegal_module_name"); CPPUNIT_ASSERT(comp1 == NULL); // モジュール名にNULLを指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp2 = m_mgr->createComponent(NULL); CPPUNIT_ASSERT(comp2 == NULL); } void test_createComponent_failed_in_bindExecutionContext() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // bindExecutionContext()で失敗するように、意図的にECFactoryを登録せずにおく // コンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp == NULL); m_mgr->terminate(); coil::usleep(3000000); } /*! * @brief cleanupComponent()メソッドのテスト * * - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? * - 登録したコンポーネントが、Managerから正しく登録解除されるか? */ void test_cleanupComponent() { // 初期化を行う // int argc = 1; // char* argv[] = { "-f fixture4.conf" }; int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 確認用にネームサービスへのアクセス手段としてNamingManagerを準備しておく // ※fixture4.confの各設定に合わせている点に注意 RTC::NamingManager nmgr(m_mgr); const char* name_server = "localhost:2809"; nmgr.registerNameServer("corba", name_server); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), // ※末尾の0はNumberingPolicyにより付加される std::string(comp->getInstanceName())); // コンポーネントに、意図どおりExecutionContextがアタッチされているか? RTC::ExecutionContextList* ecList = comp->get_owned_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length()); // cleanupComponent()により、正しく登録解除されるか? // - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? // - 登録したコンポーネントが、Managerから正しく登録解除されるか? CPPUNIT_ASSERT(!canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT_EQUAL(comp, m_mgr->getComponent("DataFlowComponent0")); m_mgr->cleanupComponent(comp); CPPUNIT_ASSERT(! canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); comp->exit(); usleep(10000); m_mgr->terminate(); } void test_unregisterComponent() { // Manager::cleanupComponent()内で使用されているので、ここではテスト省略する } void test_bindExecutionContext() { // Manager::createComponent()内で使用されているので、ここではテスト省略する } void test_getComponent() { // 他テスト内で使用されているので、そちらで兼ねるものとして、ここではテスト省略する } /*! * @brief getComponents()メソッドのテスト * * - getComponents()で、生成したすべてのコンポーネントを取得できるか? * - 登録解除したコンポーネントが、正しく一覧から除外されているか? */ void test_getComponents() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 複数のコンポーネントを生成しておく RTC::RtcBase* comp1 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp1 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp1) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp1->_this())); RTC::RtcBase* comp2 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp2 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp2) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp2->_this())); CPPUNIT_ASSERT(comp1 != comp2); // getComponents()で、生成したすべてのコンポーネントを取得できるか? std::vector<RTC::RtcBase*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT_EQUAL(2, (int) comps.size()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) != comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); // コンポーネントを1つだけ登録解除した場合、解除したものが一覧から除外されているか? m_mgr->cleanupComponent(comp1); comps = m_mgr->getComponents(); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) == comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); comp1->exit(); comp2->exit(); m_mgr->terminate(); } void test_getORB() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOA() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOAManager() { // 他テスト内で使用されているので、ここではテスト省略する } /*! * @brief initFactories()メソッドのテスト * * - init()実行後、initFactories()の実行結果としてFactoryMapに正しく登録されているか? */ void test_initFactories() { // init()の中でinitFactories()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initFactories()の実行結果としてFactoryMapに正しく登録されているか? bool bret = RTC::CdrBufferFactory::instance().hasFactory("ring_buffer"); CPPUNIT_ASSERT(bret); bret = RTC::PeriodicTaskFactory::instance().hasFactory("default"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("flush"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("new"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("periodic"); CPPUNIT_ASSERT(bret); RTC::InPortProviderFactory& factory1(RTC::InPortProviderFactory::instance()); bret = factory1.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::InPortConsumerFactory& factory2(RTC::InPortConsumerFactory::instance()); bret = factory2.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortConsumerFactory& factory3(RTC::OutPortConsumerFactory::instance()); bret = factory3.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortProviderFactory& factory4(RTC::OutPortProviderFactory::instance()); bret = factory4.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); } /*! * @brief initComposite()メソッドのテスト * * - init()実行後、initComposite()の実行結果としてFactoryManagerに正しく登録されているか? */ void test_initComposite() { // init()の中でinitComposite()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initComposite()の実行結果としてFactoryManagerに正しく登録されているか? // "implementation_id"には, "PeriodicECSharedComposite"が設定されている CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "PeriodicECSharedComposite")); } /*! * @brief procContextArgs()メソッドのテスト * * - 引数ec_argsにより戻り値true・falseが正しく返却されるか? */ void test_procContextArgs() { std::string ec_args; std::string ec_id; coil::Properties ec_prop; // インスタンス生成 ManagerTestMock* man = new ManagerTestMock(); // falseを返すケース1:ec_args.size=0 ec_args = ""; bool bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース2:ec_args.size=3 ec_args = "periodic?rate=1000?policy=skip"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース3:ec_args[0].empty ec_args = "?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // trueを返すケース4:ec_args.size=2 ec_args = "periodic?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(bret); std::string chk_val("periodic"); CPPUNIT_ASSERT_EQUAL(chk_val, ec_id); chk_val = "1000"; CPPUNIT_ASSERT_EQUAL(chk_val, ec_prop["rate"]); delete man; } /*! * @brief getLogLevel()メソッドのテスト * * - log_levelが正しく返却されるか? */ void test_getLogLevel() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); std::string log_level = m_mgr->getLogLevel(); CPPUNIT_ASSERT_EQUAL(std::string("INFO"), log_level); } /*! * @brief getLoadedModules()メソッドのテスト * * - ロード済みのモジュールリストを正しく取得できるか? */ void test_getLoadedModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); /* FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード済みのモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadedModules(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string(".//./.libs/DummyModule.so"), props[0].getProperty("file_path")); */ } /*! * @brief getFactoryProfiles()メソッドのテスト * * - RTコンポーネント用ファクトリをリストを正しく取得できるか? */ void test_getFactoryProfiles() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); std::vector<coil::Properties> props = m_mgr->getFactoryProfiles(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string("PeriodicECSharedComposite"), props[0].getProperty("implementation_id")); CPPUNIT_ASSERT_EQUAL(std::string("ID"), props[1].getProperty("implementation_id")); } /*! * @brief createContext()メソッドのテスト * * - ExecutionContextBaseを正しく取得できるか? */ void test_createContext() { RTC::ExecutionContextBase* ec; std::string ec_args; m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // return NULL check ec_args = ""; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return NULL check (Factory not found) ec_args = "periodic?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return any check m_mgr->registerECFactory("PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>); ec_args = "PeriodicEC?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec != NULL); } /*! * @brief deleteComponent()メソッドのテスト * * - RTコンポーネントの削除が正しくできるか? */ void test_deleteComponent() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), std::string(comp->getInstanceName())); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") != NULL); std::vector<RTC::RTObject_impl*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT(comps.size() > 0); // 正しくコンポーネントを削除できるか? m_mgr->deleteComponent("DataFlowComponent0"); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); // deleteComponent()でexit()を実行しているため、これ以降のテストはできません。 } /*! * @brief init()、shutdown()から呼ばれるprotected関数のテスト * * - protected関数が正しく動作しているか? */ void test_init2() { // Manager::init()よりprotected関数が使用されているので、ここではテスト省略する // initManager() // initLogger() // initORB() // initNaming() // initFactories() // initExecContext() // initComposite() // initTimer() // initManagerServant() // Manager::shutdown()よりprotected関数が使用されているので、ここではテスト省略する // shutdownComponents(); // shutdownNaming(); // shutdownORB(); // shutdownManager(); // shutdownLogger(); } }; }; // namespace Tests /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(Tests::ManagerTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // ManagerTests_cpp
162  ManagerTestMock() : RTC::Manager() {}
163  virtual ~ManagerTestMock(void) {}
164 
165  // Manager::procContextArgs は、protected: の為ここへ定義。
166  bool procContextArgs(const char* ec_args,
167  std::string& ec_id,
168  coil::Properties& ec_conf)
169  {
170  bool bret = RTC::Manager::procContextArgs(ec_args, ec_id, ec_conf);
171  return bret;
172  }
173 
174  };
175 
176 
178  {
179  public:
180  static void setLogger(Logger* logger)
181  {
182  m_logger = logger;
183  }
184 
186  {
187  if (m_logger != NULL) m_logger->log("InitProc");
188  }
189 
190  private:
191  static Logger* m_logger;
192  };
193 
195 
196 
197  class RTObjectMock
198  : virtual public RTC::RTObject_impl
199  {
200  public:
201  RTObjectMock(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa)
202  : RTC::RTObject_impl(orb, poa), m_logger(NULL)
203  {
204  }
205 
207  throw (CORBA::SystemException)
208  {
210  if (m_logger != NULL) m_logger->log("initialize");
211  return RTC::RTC_OK;
212  }
213 
215  {
216  m_logger = logger;
217  }
218 
219  private:
220  Logger* m_logger;
221  };
222 
223 
225  : virtual public RTC::RTObject_impl
226  {
227  public:
228  DataFlowComponentMock(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa)
229  : RTC::RTObject_impl(orb, poa)
230  {
231  }
232 
233  RTC::UniqueId attach_context(RTC::ExecutionContext_ptr exec_context)
234  throw (CORBA::SystemException)
235  {
236  return RTC::RTObject_impl::attach_context(exec_context);
237  }
238  };
239 
241  {
242  CORBA::ORB_ptr orb = manager->getORB();
243  PortableServer::POA_ptr poa = manager->getPOA();
244  DataFlowComponentMock* comp = new DataFlowComponentMock(orb, poa);
245  comp->setObjRef(comp->_this());
246  return comp;
247  }
248 
250  {
251  if (rtc != NULL) rtc->_remove_ref();
252  }
253 
254 
256  : public CppUnit::TestFixture
257  {
258  CPPUNIT_TEST_SUITE(ManagerTests);
259 
260 // CPPUNIT_TEST(test_deleteComponent); //OK
261  CPPUNIT_TEST(test_getLogLevel);
262  CPPUNIT_TEST(test_getLoadedModules);
263  CPPUNIT_TEST(test_getFactoryProfiles);
264  CPPUNIT_TEST(test_createContext);
265  CPPUNIT_TEST(test_init2);
266  CPPUNIT_TEST(test_initFactories);
267  CPPUNIT_TEST(test_initComposite);
268  CPPUNIT_TEST(test_procContextArgs);
269  CPPUNIT_TEST(test_init_without_arguments);
270  CPPUNIT_TEST(test_instance);
271  CPPUNIT_TEST(test_instance_without_init);
272 
273 // CPPUNIT_TEST(test_terminate_immediately_after_the_initialization); //OK
274 // CPPUNIT_TEST(test_terminate_after_the_activation); //OK
275 
276  CPPUNIT_TEST(test_getConfig);
277  CPPUNIT_TEST(test_setModuleInitProc);
278 
279 // CPPUNIT_TEST(test_runManager_no_block); //OK
280 // CPPUNIT_TEST(test_runManager_block);
281  CPPUNIT_TEST(test_load);
282  CPPUNIT_TEST(test_unload);
283  CPPUNIT_TEST(test_unloadAll);
284  CPPUNIT_TEST(test_registerFactory);
285  CPPUNIT_TEST(test_registerECFactory);
286  CPPUNIT_TEST(test_getModulesFactories);
287 
288  CPPUNIT_TEST(test_getLoadableModules);
289  CPPUNIT_TEST(test_notifyFinalized);
290 
291 // CPPUNIT_TEST(test_cleanupComponent); //OK
292 // CPPUNIT_TEST(test_getComponents); //OK
293 
294  // ※現在、各テスト間の独立性を完全に確保できていないため、下記テストは実施順序を変更しないこと。
295  // また、テスト内容を変更したり、他テストを追加したりする場合は、必ずしもテスト間の独立性が
296  // 保たれない点に留意すること。なお、独立性が保てないのは、omniORBを用いた場合に、
297  // CORBA::ORB::destroy()が失敗する場合があり、次テスト時のCORBA::ORB_init()呼出が
298  // 新ORBインスタンスを返さない場合があるため。詳しい原因は現時点では不明。
299  //
300  // CPPUNIT_TEST(test_createComponent_DataFlowComponent);
301  // CPPUNIT_TEST(test_createComponent_Non_DataFlowComponent); //OK
302  // CPPUNIT_TEST(test_createComponent_failed_in_bindExecutionContext); //OK
303  // CPPUNIT_TEST(test_createComponent_with_illegal_module_name);
304 
305  CPPUNIT_TEST_SUITE_END();
306 
307  private:
309 
310 
311  private:
312  bool isFound(const std::vector<std::string>& list, const std::string& target)
313  {
314  return ! (list.end() == std::find(list.begin(), list.end(), target));
315  }
316 
317  CosNaming::NamingContext_var getRootContext(const std::string& name_server)
318  {
319  std::string nsName
320  = std::string("corbaloc::")
321  + name_server
322  + std::string("/NameService");
323 
324  CORBA::Object_var obj = m_mgr->getORB()->string_to_object(nsName.c_str());
325  CosNaming::NamingContext_var rootContext = CosNaming::NamingContext::_narrow(obj);
326  if (CORBA::is_nil(rootContext))
327  {
328  throw std::bad_alloc();
329  }
330 
331  return rootContext;
332  }
333 
334  bool canResolve(const char* name_server, const char* id, const char* kind)
335  {
336  CosNaming::NamingContext_var nc = getRootContext(name_server);
337  if (CORBA::is_nil(nc)) return false;
338  CosNaming::Name name;
339  name.length(1);
340  name[0].id = id;
341  name[0].kind = kind;
342 
343  CORBA::Object_var obj;
344  try
345  {
346  obj = nc->resolve(name);
347  }
348  catch (CosNaming::NamingContext::NotFound e)
349  {
350  return false;
351  }
352  catch (...)
353  {
354  std::cout << "nameserver->resolve() failed" << std::endl;
355  return false;
356  }
357  return !CORBA::is_nil(obj);
358  }
359 
360  public:
365  {
366  }
367 
371  virtual ~ManagerTests()
372  {
373  }
374 
378  virtual void setUp()
379  {
381  m_mgr = NULL;
382  coil::usleep(100000);
383  }
384 
388  virtual void tearDown()
389  {
390  coil::usleep(100000);
391  /*
392  if (m_mgr != NULL)
393  {
394  try
395  {
396  CORBA::ORB_ptr orb = m_mgr->getORB();
397  if (! CORBA::is_nil(orb))
398  {
399  orb->destroy();
400  sleep(3);
401  }
402  }
403  catch (...) {}
404  }
405  */
406  }
413  {
414  // コマンドライン引数なしでinit()を正常に呼出して、インスタンスを取得できるか?
415  m_mgr = RTC::Manager::init(0, NULL);
416  CPPUNIT_ASSERT(m_mgr != NULL);
417  // m_mgr->terminate();
418  }
419 
426  {
427  int argc = 0;
428  char* argv[] = {};
429 
430  m_mgr = RTC::Manager::init(argc, argv);
431  CPPUNIT_ASSERT(m_mgr != NULL);
432 
433  // instance()を通じて取得したインスタンスは、init()時に得たインスタンスと同一か?
434  RTC::Manager& instance = RTC::Manager::instance();
435  CPPUNIT_ASSERT_EQUAL(m_mgr, &instance);
436  }
437 
444  {
445  // 事前にinit()を呼出さずにinstance()を呼出した場合、正常にインスタンスが生成されるか?
447  }
448 
455  {
456  // 初期化を行う
457  int argc = 0;
458  char* argv[] = {};
459 
460  m_mgr = RTC::Manager::init(argc, argv);
461  CPPUNIT_ASSERT(m_mgr != NULL);
462  CPPUNIT_ASSERT(m_mgr->getORB() != NULL);
463  CPPUNIT_ASSERT(m_mgr->getPOA() != NULL);
464 
465  // 初期化後すぐにterminate()を呼出し、正常に終了できるか?
466  CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB()));
467  CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA()));
468  m_mgr->terminate();
469  coil::sleep(3);
470  CPPUNIT_ASSERT(CORBA::is_nil(m_mgr->getORB()));
471  CPPUNIT_ASSERT(CORBA::is_nil(m_mgr->getPOA()));
472  m_mgr = NULL;
473  }
474 
481  {
482  // 初期化を行う
483  int argc = 0;
484  char* argv[] = {};
485 
486  m_mgr = RTC::Manager::init(argc, argv);
487  CPPUNIT_ASSERT(m_mgr != NULL);
488  CPPUNIT_ASSERT(m_mgr->getORB() != NULL);
489 // CPPUNIT_ASSERT(m_mgr->getPOA() != NULL);
490 // CPPUNIT_ASSERT(m_mgr->getPOAManager() != NULL);
491  CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA()));
492  CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager()));
493 
494  // active化する CPPUNIT_ASSERT(m_mgr->activateManager()); // active化の後でterminate()を呼出し、正常に終了できるか? CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); m_mgr->terminate(); coil::sleep(3); CPPUNIT_ASSERT(CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(CORBA::is_nil(m_mgr->getPOA())); } void test_notifyFinalized() { // shutdown()を通じて呼び出されるメソッドであるため、直接のテスト対象とはしない } void test_shutdown() { // terminate()を通じて呼び出されるメソッドであるため、直接のテスト対象とはしない } void test_join() { // shutdown()の中で使用されるメソッドであるため、直接のテスト対象とはしない // ※そもそも、なぜpublicメソッドになっているのだろうか? } /*! * @brief getConfig()メソッドのテスト * * - confファイルで指定した各種設定を、getConfig()を通じて正しく取得できるか? */ void test_getConfig() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture2.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // confファイルで指定した各種設定を、getConfig()を通じて正しく取得できるか? coil::Properties& properties = m_mgr->getConfig(); CPPUNIT_ASSERT_EQUAL(std::string("NO"), properties.getProperty("logger.enable")); CPPUNIT_ASSERT_EQUAL(std::string("fixture2.log"), properties.getProperty("logger.file_name")); } /*! * @brief setModuleInitProc()メソッドのテスト * * - アクティブ化により、設定した初期化プロシージャが正しく呼び出されるか? */ void test_setModuleInitProc() { // Mockの準備 Logger logger; ModuleMock::setLogger(&logger); // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // 初期化プロシージャを登録する m_mgr->setModuleInitProc(&ModuleMock::InitProc); // アクティブ化により、設定した初期化プロシージャが正しく呼び出されるか? CPPUNIT_ASSERT_EQUAL(0, logger.countLog("InitProc")); CPPUNIT_ASSERT(m_mgr->activateManager()); CPPUNIT_ASSERT_EQUAL(1, logger.countLog("InitProc")); } void test_activateManager() { // 他テスト中で使用されているため省略する } /*! * @brief runManager()メソッドのテスト(非ブロッキングモード) * * - POAManagerがアクティブ化されるか? */ void test_runManager_no_block() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // オブジェクトを生成して、参照を得る CORBA::ORB_ptr orb = m_mgr->getORB(); CPPUNIT_ASSERT(! CORBA::is_nil(orb)); PortableServer::POA_ptr poa = m_mgr->getPOA(); CPPUNIT_ASSERT(! CORBA::is_nil(poa)); RTObjectMock* rto = new RTObjectMock(orb, poa); CPPUNIT_ASSERT(rto != NULL); // PortableServer::ObjectId_var rtoId = poa->activate_object(rto); PortableServer::ObjectId_var rtoId; try { rtoId = poa->activate_object(rto); } catch(const ::PortableServer::POA::ServantAlreadyActive &) { rtoId = poa->servant_to_id(rto); } RTC::DataFlowComponent_ptr rtoRef = RTC::DataFlowComponent::_narrow(poa->id_to_reference(rtoId)); CPPUNIT_ASSERT(! CORBA::is_nil(rtoRef)); // テスト用にロガーを設定しておく Logger logger; rto->setLogger(&logger); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // runManager()によりPOAManagerが正しくactive化されているか? // (取得したオブジェクト参照に対してメソッド呼出を行い、 // リモート側が呼出されたことによりPOAManagerのアクティブ化を確認する) CPPUNIT_ASSERT_EQUAL(0, logger.countLog("initialize")); rtoRef->initialize(); coil::sleep(3); CPPUNIT_ASSERT_EQUAL(1, logger.countLog("initialize")); poa->deactivate_object(rtoId); delete rto; } /*! * @brief runManager()メソッドのテスト(ブロッキングモード) * * - POAManagerがアクティブ化されるか? */ void test_runManager_block() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // オブジェクトを生成して、参照を得る CORBA::ORB_ptr orb = m_mgr->getORB(); CPPUNIT_ASSERT(! CORBA::is_nil(orb)); PortableServer::POA_ptr poa = m_mgr->getPOA(); CPPUNIT_ASSERT(! CORBA::is_nil(poa)); RTObjectMock* rto = new RTObjectMock(orb, poa); CPPUNIT_ASSERT(rto != NULL); PortableServer::ObjectId_var rtoId; try { rtoId = poa->activate_object(rto); } catch(const ::PortableServer::POA::ServantAlreadyActive &) { rtoId = poa->servant_to_id(rto); } RTC::DataFlowComponent_ptr rtoRef = RTC::DataFlowComponent::_narrow(poa->id_to_reference(rtoId)); CPPUNIT_ASSERT(! CORBA::is_nil(rtoRef)); // テスト用にロガーを設定しておく Logger logger; rto->setLogger(&logger); // ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); CPPUNIT_ASSERT_EQUAL(0, logger.countLog("initialize")); { InvokerMock invoker(rtoRef, m_mgr); m_mgr->runManager(false); // true:非ブロッキング,false:ブロッキング coil::sleep(3); } CPPUNIT_ASSERT_EQUAL(1, logger.countLog("initialize")); poa->deactivate_object(rtoId); delete rto; } class InvokerMock : public coil::Task { public: InvokerMock(const RTC::DataFlowComponent_ptr& rtoRef, RTC::Manager* mgr) { m_rtoRef = RTC::DataFlowComponent::_duplicate(rtoRef); m_mgr = mgr; activate(); } ~InvokerMock() { wait(); } virtual int svc(void) { m_rtoRef->initialize(); coil::sleep(1); // ブロックされているrunManager呼出をブロック解除する m_rtoRef->exit(); m_mgr->shutdown(); m_mgr->join(); return 0; } private: RTC::DataFlowComponent_ptr m_rtoRef; RTC::Manager* m_mgr; }; /*! * @brief load()メソッドのテスト * * - 指定したモジュールをロードして、指定の初期化関数が正しく呼び出されるか? */ void test_load() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア // モジュールロードにより、指定した初期化関数が呼び出されるか? CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); // std::string moduleName = m_mgr->load("DummyModule.so", "InitProc"); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName)); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount)()); } /*! * @brief unload()メソッドのテスト * * - いったんloadしたモジュールを、正しくunloadできるか? */ void test_unload() { // 初期化を行う int argc = 1; char* argv[] = { "-f fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア // いったんloadしておく CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // std::string moduleName = m_mgr->load("DummyModule.so", "InitProc"); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName)); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount)()); // いったんloadしたモジュールを、正しくunloadできるか? // m_mgr->unload(moduleName.c_str()); // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName)); } /*! * @brief unloadAll()メソッドのテスト * * - unloadAll()により、ロードしたモジュールがすべてアンロードされるか? */ void test_unloadAll() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader1("./.libs/DummyModule.so"); coil::DynamicLib loader2("./.libs/DummyModule2.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount1 = (FUNC_GETINITPROCCOUNT) loader1.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount1 != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount1 = (FUNC_RESETINITPROCCOUNT) loader1.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount1 != NULL); FUNC_GETINITPROCCOUNT pGetInitProcCount2 = (FUNC_GETINITPROCCOUNT) loader2.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount2 != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount2 = (FUNC_RESETINITPROCCOUNT) loader2.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount2 != NULL); (*pResetInitProcCount1)(); // カウンタクリア (*pResetInitProcCount2)(); // カウンタクリア // いったんloadしておく CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount1)()); CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount2)()); // std::string moduleName1 = m_mgr->load("DummyModule.so", "InitProc"); // std::string moduleName2 = m_mgr->load("DummyModule2.so", "InitProc"); m_mgr->load("./.libs/DummyModule.so", "InitProc"); m_mgr->load("./.libs/DummyModule2.so", "InitProc"); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName1)); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName2)); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount1)()); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount2)()); // unloadAll()により、ロードしたモジュールがすべてアンロードされるか? m_mgr->unloadAll(); // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName1)); // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName2)); } /*! * @brief getLoadableModules()メソッドのテスト * * - ロード可能なモジュールリストを正しく取得できるか? */ void test_getLoadableModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード可能なモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadableModules(); CPPUNIT_ASSERT(props.size() > 0); //for(int i=0;i<props.size(); ++i) //{ // std::cout << "--------------- props[" << i << "] dump ---------------" << std::endl; // props[i].list(std::cout); //} CPPUNIT_ASSERT_EQUAL(std::string("./.libs/DummyModule2.so"), props[0].getProperty("module_file_path")); } /*! * @brief registerFactory()メソッドのテスト * * - Factoryを正常に登録できるか? */ void test_registerFactory() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); } /*! * @brief registerECFactory() * * - 正常にECFactoryを登録できるか? */ void test_registerECFactory() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // 正常にECFactoryを登録できるか? CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 登録済みのECFactoryと同一の名称で登録を試みた場合、意図どおり登録失敗するか? CPPUNIT_ASSERT(! m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); } /*! * @brief getModulesFactories()メソッドのテスト * * - 登録されているFactoryの("implementation_id"プロパティの)リストを正しく取得できるか? */ void test_getModulesFactories() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // 複数のFactoryを登録しておく coil::Properties properties1; properties1.setProperty("implementation_id", "ID 1"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties1, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); coil::Properties properties2; properties2.setProperty("implementation_id", "ID 2"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties2, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // 登録されているFactoryの("implementation_id"プロパティの)リストを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(3, (int) m_mgr->getModulesFactories().size()); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID 1")); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID 2")); } /*! * @brief createComponent()メソッドのテスト(DataFlowComponentの場合) * * - 正しくコンポーネントを生成できるか? */ void test_createComponent_DataFlowComponent() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), // ※末尾の0はNumberingPolicyにより付加される std::string(comp->getInstanceName())); // コンポーネントに、意図どおりExecutionContextがアタッチされているか? RTC::ExecutionContextList* ecList = comp->get_owned_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length()); // 生成されたコンポーネントは、正しくネームサービスに登録されているか? // ※fixture4.confの各設定に合わせている点に注意 RTC::NamingManager nmgr(m_mgr); const char* name_server = "localhost:2809"; nmgr.registerNameServer("corba", name_server); CPPUNIT_ASSERT(canResolve(name_server, "DataFlowComponent0", "rtc")); comp->exit(); m_mgr->terminate(); } void test_createComponent_Non_DataFlowComponent() { // 現時点では、Manager側がDataFlowComponentのみに対応しているため、テスト省略する } /*! * @brief createComponent()メソッドのテスト * * - 登録されていないモジュール名を指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? * - モジュール名にNULLを指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? */ void test_createComponent_with_illegal_module_name() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 登録されていないモジュール名を指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp1 = m_mgr->createComponent("illegal_module_name"); CPPUNIT_ASSERT(comp1 == NULL); // モジュール名にNULLを指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp2 = m_mgr->createComponent(NULL); CPPUNIT_ASSERT(comp2 == NULL); } void test_createComponent_failed_in_bindExecutionContext() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // bindExecutionContext()で失敗するように、意図的にECFactoryを登録せずにおく // コンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp == NULL); m_mgr->terminate(); coil::usleep(3000000); } /*! * @brief cleanupComponent()メソッドのテスト * * - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? * - 登録したコンポーネントが、Managerから正しく登録解除されるか? */ void test_cleanupComponent() { // 初期化を行う // int argc = 1; // char* argv[] = { "-f fixture4.conf" }; int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 確認用にネームサービスへのアクセス手段としてNamingManagerを準備しておく // ※fixture4.confの各設定に合わせている点に注意 RTC::NamingManager nmgr(m_mgr); const char* name_server = "localhost:2809"; nmgr.registerNameServer("corba", name_server); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), // ※末尾の0はNumberingPolicyにより付加される std::string(comp->getInstanceName())); // コンポーネントに、意図どおりExecutionContextがアタッチされているか? RTC::ExecutionContextList* ecList = comp->get_owned_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length()); // cleanupComponent()により、正しく登録解除されるか? // - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? // - 登録したコンポーネントが、Managerから正しく登録解除されるか? CPPUNIT_ASSERT(!canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT_EQUAL(comp, m_mgr->getComponent("DataFlowComponent0")); m_mgr->cleanupComponent(comp); CPPUNIT_ASSERT(! canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); comp->exit(); usleep(10000); m_mgr->terminate(); } void test_unregisterComponent() { // Manager::cleanupComponent()内で使用されているので、ここではテスト省略する } void test_bindExecutionContext() { // Manager::createComponent()内で使用されているので、ここではテスト省略する } void test_getComponent() { // 他テスト内で使用されているので、そちらで兼ねるものとして、ここではテスト省略する } /*! * @brief getComponents()メソッドのテスト * * - getComponents()で、生成したすべてのコンポーネントを取得できるか? * - 登録解除したコンポーネントが、正しく一覧から除外されているか? */ void test_getComponents() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 複数のコンポーネントを生成しておく RTC::RtcBase* comp1 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp1 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp1) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp1->_this())); RTC::RtcBase* comp2 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp2 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp2) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp2->_this())); CPPUNIT_ASSERT(comp1 != comp2); // getComponents()で、生成したすべてのコンポーネントを取得できるか? std::vector<RTC::RtcBase*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT_EQUAL(2, (int) comps.size()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) != comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); // コンポーネントを1つだけ登録解除した場合、解除したものが一覧から除外されているか? m_mgr->cleanupComponent(comp1); comps = m_mgr->getComponents(); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) == comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); comp1->exit(); comp2->exit(); m_mgr->terminate(); } void test_getORB() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOA() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOAManager() { // 他テスト内で使用されているので、ここではテスト省略する } /*! * @brief initFactories()メソッドのテスト * * - init()実行後、initFactories()の実行結果としてFactoryMapに正しく登録されているか? */ void test_initFactories() { // init()の中でinitFactories()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initFactories()の実行結果としてFactoryMapに正しく登録されているか? bool bret = RTC::CdrBufferFactory::instance().hasFactory("ring_buffer"); CPPUNIT_ASSERT(bret); bret = RTC::PeriodicTaskFactory::instance().hasFactory("default"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("flush"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("new"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("periodic"); CPPUNIT_ASSERT(bret); RTC::InPortProviderFactory& factory1(RTC::InPortProviderFactory::instance()); bret = factory1.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::InPortConsumerFactory& factory2(RTC::InPortConsumerFactory::instance()); bret = factory2.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortConsumerFactory& factory3(RTC::OutPortConsumerFactory::instance()); bret = factory3.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortProviderFactory& factory4(RTC::OutPortProviderFactory::instance()); bret = factory4.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); } /*! * @brief initComposite()メソッドのテスト * * - init()実行後、initComposite()の実行結果としてFactoryManagerに正しく登録されているか? */ void test_initComposite() { // init()の中でinitComposite()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initComposite()の実行結果としてFactoryManagerに正しく登録されているか? // "implementation_id"には, "PeriodicECSharedComposite"が設定されている CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "PeriodicECSharedComposite")); } /*! * @brief procContextArgs()メソッドのテスト * * - 引数ec_argsにより戻り値true・falseが正しく返却されるか? */ void test_procContextArgs() { std::string ec_args; std::string ec_id; coil::Properties ec_prop; // インスタンス生成 ManagerTestMock* man = new ManagerTestMock(); // falseを返すケース1:ec_args.size=0 ec_args = ""; bool bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース2:ec_args.size=3 ec_args = "periodic?rate=1000?policy=skip"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース3:ec_args[0].empty ec_args = "?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // trueを返すケース4:ec_args.size=2 ec_args = "periodic?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(bret); std::string chk_val("periodic"); CPPUNIT_ASSERT_EQUAL(chk_val, ec_id); chk_val = "1000"; CPPUNIT_ASSERT_EQUAL(chk_val, ec_prop["rate"]); delete man; } /*! * @brief getLogLevel()メソッドのテスト * * - log_levelが正しく返却されるか? */ void test_getLogLevel() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); std::string log_level = m_mgr->getLogLevel(); CPPUNIT_ASSERT_EQUAL(std::string("INFO"), log_level); } /*! * @brief getLoadedModules()メソッドのテスト * * - ロード済みのモジュールリストを正しく取得できるか? */ void test_getLoadedModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); /* FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード済みのモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadedModules(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string(".//./.libs/DummyModule.so"), props[0].getProperty("file_path")); */ } /*! * @brief getFactoryProfiles()メソッドのテスト * * - RTコンポーネント用ファクトリをリストを正しく取得できるか? */ void test_getFactoryProfiles() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); std::vector<coil::Properties> props = m_mgr->getFactoryProfiles(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string("PeriodicECSharedComposite"), props[0].getProperty("implementation_id")); CPPUNIT_ASSERT_EQUAL(std::string("ID"), props[1].getProperty("implementation_id")); } /*! * @brief createContext()メソッドのテスト * * - ExecutionContextBaseを正しく取得できるか? */ void test_createContext() { RTC::ExecutionContextBase* ec; std::string ec_args; m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // return NULL check ec_args = ""; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return NULL check (Factory not found) ec_args = "periodic?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return any check m_mgr->registerECFactory("PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>); ec_args = "PeriodicEC?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec != NULL); } /*! * @brief deleteComponent()メソッドのテスト * * - RTコンポーネントの削除が正しくできるか? */ void test_deleteComponent() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), std::string(comp->getInstanceName())); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") != NULL); std::vector<RTC::RTObject_impl*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT(comps.size() > 0); // 正しくコンポーネントを削除できるか? m_mgr->deleteComponent("DataFlowComponent0"); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); // deleteComponent()でexit()を実行しているため、これ以降のテストはできません。 } /*! * @brief init()、shutdown()から呼ばれるprotected関数のテスト * * - protected関数が正しく動作しているか? */ void test_init2() { // Manager::init()よりprotected関数が使用されているので、ここではテスト省略する // initManager() // initLogger() // initORB() // initNaming() // initFactories() // initExecContext() // initComposite() // initTimer() // initManagerServant() // Manager::shutdown()よりprotected関数が使用されているので、ここではテスト省略する // shutdownComponents(); // shutdownNaming(); // shutdownORB(); // shutdownManager(); // shutdownLogger(); } }; }; // namespace Tests /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(Tests::ManagerTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // ManagerTests_cpp
495  CPPUNIT_ASSERT(m_mgr->activateManager());
496 
497  // active化の後でterminate()を呼出し、正常に終了できるか?
498  CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB()));
499  CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA()));
500  m_mgr->terminate();
501  coil::sleep(3);
502  CPPUNIT_ASSERT(CORBA::is_nil(m_mgr->getORB()));
503  CPPUNIT_ASSERT(CORBA::is_nil(m_mgr->getPOA()));
504  }
505 
507  {
508  // shutdown()を通じて呼び出されるメソッドであるため、直接のテスト対象とはしない
509  }
510 
512  {
513  // terminate()を通じて呼び出されるメソッドであるため、直接のテスト対象とはしない
514  }
515 
516  void test_join()
517  {
518  // shutdown()の中で使用されるメソッドであるため、直接のテスト対象とはしない
519  // ※そもそも、なぜpublicメソッドになっているのだろうか?
520  }
521 
528  {
529  // 初期化を行う
530  int argc = 3;
531  char* argv[] = { "ManagerTests","-f","fixture2.conf" };
532 
533  m_mgr = RTC::Manager::init(argc, argv);
534  CPPUNIT_ASSERT(m_mgr != NULL);
535 
536  // confファイルで指定した各種設定を、getConfig()を通じて正しく取得できるか?
537  coil::Properties& properties = m_mgr->getConfig();
538  CPPUNIT_ASSERT_EQUAL(std::string("NO"),
539  properties.getProperty("logger.enable"));
540  CPPUNIT_ASSERT_EQUAL(std::string("fixture2.log"),
541  properties.getProperty("logger.file_name"));
542  }
543 
550  {
551  // Mockの準備 Logger logger; ModuleMock::setLogger(&logger); // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // 初期化プロシージャを登録する m_mgr->setModuleInitProc(&ModuleMock::InitProc); // アクティブ化により、設定した初期化プロシージャが正しく呼び出されるか? CPPUNIT_ASSERT_EQUAL(0, logger.countLog("InitProc")); CPPUNIT_ASSERT(m_mgr->activateManager()); CPPUNIT_ASSERT_EQUAL(1, logger.countLog("InitProc")); } void test_activateManager() { // 他テスト中で使用されているため省略する } /*! * @brief runManager()メソッドのテスト(非ブロッキングモード) * * - POAManagerがアクティブ化されるか? */ void test_runManager_no_block() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // オブジェクトを生成して、参照を得る CORBA::ORB_ptr orb = m_mgr->getORB(); CPPUNIT_ASSERT(! CORBA::is_nil(orb)); PortableServer::POA_ptr poa = m_mgr->getPOA(); CPPUNIT_ASSERT(! CORBA::is_nil(poa)); RTObjectMock* rto = new RTObjectMock(orb, poa); CPPUNIT_ASSERT(rto != NULL); // PortableServer::ObjectId_var rtoId = poa->activate_object(rto); PortableServer::ObjectId_var rtoId; try { rtoId = poa->activate_object(rto); } catch(const ::PortableServer::POA::ServantAlreadyActive &) { rtoId = poa->servant_to_id(rto); } RTC::DataFlowComponent_ptr rtoRef = RTC::DataFlowComponent::_narrow(poa->id_to_reference(rtoId)); CPPUNIT_ASSERT(! CORBA::is_nil(rtoRef)); // テスト用にロガーを設定しておく Logger logger; rto->setLogger(&logger); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // runManager()によりPOAManagerが正しくactive化されているか? // (取得したオブジェクト参照に対してメソッド呼出を行い、 // リモート側が呼出されたことによりPOAManagerのアクティブ化を確認する) CPPUNIT_ASSERT_EQUAL(0, logger.countLog("initialize")); rtoRef->initialize(); coil::sleep(3); CPPUNIT_ASSERT_EQUAL(1, logger.countLog("initialize")); poa->deactivate_object(rtoId); delete rto; } /*! * @brief runManager()メソッドのテスト(ブロッキングモード) * * - POAManagerがアクティブ化されるか? */ void test_runManager_block() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // オブジェクトを生成して、参照を得る CORBA::ORB_ptr orb = m_mgr->getORB(); CPPUNIT_ASSERT(! CORBA::is_nil(orb)); PortableServer::POA_ptr poa = m_mgr->getPOA(); CPPUNIT_ASSERT(! CORBA::is_nil(poa)); RTObjectMock* rto = new RTObjectMock(orb, poa); CPPUNIT_ASSERT(rto != NULL); PortableServer::ObjectId_var rtoId; try { rtoId = poa->activate_object(rto); } catch(const ::PortableServer::POA::ServantAlreadyActive &) { rtoId = poa->servant_to_id(rto); } RTC::DataFlowComponent_ptr rtoRef = RTC::DataFlowComponent::_narrow(poa->id_to_reference(rtoId)); CPPUNIT_ASSERT(! CORBA::is_nil(rtoRef)); // テスト用にロガーを設定しておく Logger logger; rto->setLogger(&logger); // ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); CPPUNIT_ASSERT_EQUAL(0, logger.countLog("initialize")); { InvokerMock invoker(rtoRef, m_mgr); m_mgr->runManager(false); // true:非ブロッキング,false:ブロッキング coil::sleep(3); } CPPUNIT_ASSERT_EQUAL(1, logger.countLog("initialize")); poa->deactivate_object(rtoId); delete rto; } class InvokerMock : public coil::Task { public: InvokerMock(const RTC::DataFlowComponent_ptr& rtoRef, RTC::Manager* mgr) { m_rtoRef = RTC::DataFlowComponent::_duplicate(rtoRef); m_mgr = mgr; activate(); } ~InvokerMock() { wait(); } virtual int svc(void) { m_rtoRef->initialize(); coil::sleep(1); // ブロックされているrunManager呼出をブロック解除する m_rtoRef->exit(); m_mgr->shutdown(); m_mgr->join(); return 0; } private: RTC::DataFlowComponent_ptr m_rtoRef; RTC::Manager* m_mgr; }; /*! * @brief load()メソッドのテスト * * - 指定したモジュールをロードして、指定の初期化関数が正しく呼び出されるか? */ void test_load() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア // モジュールロードにより、指定した初期化関数が呼び出されるか? CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); // std::string moduleName = m_mgr->load("DummyModule.so", "InitProc"); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName)); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount)()); } /*! * @brief unload()メソッドのテスト * * - いったんloadしたモジュールを、正しくunloadできるか? */ void test_unload() { // 初期化を行う int argc = 1; char* argv[] = { "-f fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア // いったんloadしておく CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // std::string moduleName = m_mgr->load("DummyModule.so", "InitProc"); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName)); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount)()); // いったんloadしたモジュールを、正しくunloadできるか? // m_mgr->unload(moduleName.c_str()); // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName)); } /*! * @brief unloadAll()メソッドのテスト * * - unloadAll()により、ロードしたモジュールがすべてアンロードされるか? */ void test_unloadAll() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader1("./.libs/DummyModule.so"); coil::DynamicLib loader2("./.libs/DummyModule2.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount1 = (FUNC_GETINITPROCCOUNT) loader1.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount1 != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount1 = (FUNC_RESETINITPROCCOUNT) loader1.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount1 != NULL); FUNC_GETINITPROCCOUNT pGetInitProcCount2 = (FUNC_GETINITPROCCOUNT) loader2.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount2 != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount2 = (FUNC_RESETINITPROCCOUNT) loader2.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount2 != NULL); (*pResetInitProcCount1)(); // カウンタクリア (*pResetInitProcCount2)(); // カウンタクリア // いったんloadしておく CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount1)()); CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount2)()); // std::string moduleName1 = m_mgr->load("DummyModule.so", "InitProc"); // std::string moduleName2 = m_mgr->load("DummyModule2.so", "InitProc"); m_mgr->load("./.libs/DummyModule.so", "InitProc"); m_mgr->load("./.libs/DummyModule2.so", "InitProc"); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName1)); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName2)); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount1)()); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount2)()); // unloadAll()により、ロードしたモジュールがすべてアンロードされるか? m_mgr->unloadAll(); // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName1)); // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName2)); } /*! * @brief getLoadableModules()メソッドのテスト * * - ロード可能なモジュールリストを正しく取得できるか? */ void test_getLoadableModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード可能なモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadableModules(); CPPUNIT_ASSERT(props.size() > 0); //for(int i=0;i<props.size(); ++i) //{ // std::cout << "--------------- props[" << i << "] dump ---------------" << std::endl; // props[i].list(std::cout); //} CPPUNIT_ASSERT_EQUAL(std::string("./.libs/DummyModule2.so"), props[0].getProperty("module_file_path")); } /*! * @brief registerFactory()メソッドのテスト * * - Factoryを正常に登録できるか? */ void test_registerFactory() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); } /*! * @brief registerECFactory() * * - 正常にECFactoryを登録できるか? */ void test_registerECFactory() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // 正常にECFactoryを登録できるか? CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 登録済みのECFactoryと同一の名称で登録を試みた場合、意図どおり登録失敗するか? CPPUNIT_ASSERT(! m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); } /*! * @brief getModulesFactories()メソッドのテスト * * - 登録されているFactoryの("implementation_id"プロパティの)リストを正しく取得できるか? */ void test_getModulesFactories() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // 複数のFactoryを登録しておく coil::Properties properties1; properties1.setProperty("implementation_id", "ID 1"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties1, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); coil::Properties properties2; properties2.setProperty("implementation_id", "ID 2"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties2, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // 登録されているFactoryの("implementation_id"プロパティの)リストを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(3, (int) m_mgr->getModulesFactories().size()); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID 1")); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID 2")); } /*! * @brief createComponent()メソッドのテスト(DataFlowComponentの場合) * * - 正しくコンポーネントを生成できるか? */ void test_createComponent_DataFlowComponent() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), // ※末尾の0はNumberingPolicyにより付加される std::string(comp->getInstanceName())); // コンポーネントに、意図どおりExecutionContextがアタッチされているか? RTC::ExecutionContextList* ecList = comp->get_owned_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length()); // 生成されたコンポーネントは、正しくネームサービスに登録されているか? // ※fixture4.confの各設定に合わせている点に注意 RTC::NamingManager nmgr(m_mgr); const char* name_server = "localhost:2809"; nmgr.registerNameServer("corba", name_server); CPPUNIT_ASSERT(canResolve(name_server, "DataFlowComponent0", "rtc")); comp->exit(); m_mgr->terminate(); } void test_createComponent_Non_DataFlowComponent() { // 現時点では、Manager側がDataFlowComponentのみに対応しているため、テスト省略する } /*! * @brief createComponent()メソッドのテスト * * - 登録されていないモジュール名を指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? * - モジュール名にNULLを指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? */ void test_createComponent_with_illegal_module_name() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 登録されていないモジュール名を指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp1 = m_mgr->createComponent("illegal_module_name"); CPPUNIT_ASSERT(comp1 == NULL); // モジュール名にNULLを指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp2 = m_mgr->createComponent(NULL); CPPUNIT_ASSERT(comp2 == NULL); } void test_createComponent_failed_in_bindExecutionContext() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // bindExecutionContext()で失敗するように、意図的にECFactoryを登録せずにおく // コンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp == NULL); m_mgr->terminate(); coil::usleep(3000000); } /*! * @brief cleanupComponent()メソッドのテスト * * - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? * - 登録したコンポーネントが、Managerから正しく登録解除されるか? */ void test_cleanupComponent() { // 初期化を行う // int argc = 1; // char* argv[] = { "-f fixture4.conf" }; int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 確認用にネームサービスへのアクセス手段としてNamingManagerを準備しておく // ※fixture4.confの各設定に合わせている点に注意 RTC::NamingManager nmgr(m_mgr); const char* name_server = "localhost:2809"; nmgr.registerNameServer("corba", name_server); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), // ※末尾の0はNumberingPolicyにより付加される std::string(comp->getInstanceName())); // コンポーネントに、意図どおりExecutionContextがアタッチされているか? RTC::ExecutionContextList* ecList = comp->get_owned_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length()); // cleanupComponent()により、正しく登録解除されるか? // - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? // - 登録したコンポーネントが、Managerから正しく登録解除されるか? CPPUNIT_ASSERT(!canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT_EQUAL(comp, m_mgr->getComponent("DataFlowComponent0")); m_mgr->cleanupComponent(comp); CPPUNIT_ASSERT(! canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); comp->exit(); usleep(10000); m_mgr->terminate(); } void test_unregisterComponent() { // Manager::cleanupComponent()内で使用されているので、ここではテスト省略する } void test_bindExecutionContext() { // Manager::createComponent()内で使用されているので、ここではテスト省略する } void test_getComponent() { // 他テスト内で使用されているので、そちらで兼ねるものとして、ここではテスト省略する } /*! * @brief getComponents()メソッドのテスト * * - getComponents()で、生成したすべてのコンポーネントを取得できるか? * - 登録解除したコンポーネントが、正しく一覧から除外されているか? */ void test_getComponents() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 複数のコンポーネントを生成しておく RTC::RtcBase* comp1 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp1 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp1) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp1->_this())); RTC::RtcBase* comp2 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp2 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp2) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp2->_this())); CPPUNIT_ASSERT(comp1 != comp2); // getComponents()で、生成したすべてのコンポーネントを取得できるか? std::vector<RTC::RtcBase*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT_EQUAL(2, (int) comps.size()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) != comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); // コンポーネントを1つだけ登録解除した場合、解除したものが一覧から除外されているか? m_mgr->cleanupComponent(comp1); comps = m_mgr->getComponents(); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) == comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); comp1->exit(); comp2->exit(); m_mgr->terminate(); } void test_getORB() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOA() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOAManager() { // 他テスト内で使用されているので、ここではテスト省略する } /*! * @brief initFactories()メソッドのテスト * * - init()実行後、initFactories()の実行結果としてFactoryMapに正しく登録されているか? */ void test_initFactories() { // init()の中でinitFactories()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initFactories()の実行結果としてFactoryMapに正しく登録されているか? bool bret = RTC::CdrBufferFactory::instance().hasFactory("ring_buffer"); CPPUNIT_ASSERT(bret); bret = RTC::PeriodicTaskFactory::instance().hasFactory("default"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("flush"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("new"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("periodic"); CPPUNIT_ASSERT(bret); RTC::InPortProviderFactory& factory1(RTC::InPortProviderFactory::instance()); bret = factory1.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::InPortConsumerFactory& factory2(RTC::InPortConsumerFactory::instance()); bret = factory2.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortConsumerFactory& factory3(RTC::OutPortConsumerFactory::instance()); bret = factory3.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortProviderFactory& factory4(RTC::OutPortProviderFactory::instance()); bret = factory4.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); } /*! * @brief initComposite()メソッドのテスト * * - init()実行後、initComposite()の実行結果としてFactoryManagerに正しく登録されているか? */ void test_initComposite() { // init()の中でinitComposite()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initComposite()の実行結果としてFactoryManagerに正しく登録されているか? // "implementation_id"には, "PeriodicECSharedComposite"が設定されている CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "PeriodicECSharedComposite")); } /*! * @brief procContextArgs()メソッドのテスト * * - 引数ec_argsにより戻り値true・falseが正しく返却されるか? */ void test_procContextArgs() { std::string ec_args; std::string ec_id; coil::Properties ec_prop; // インスタンス生成 ManagerTestMock* man = new ManagerTestMock(); // falseを返すケース1:ec_args.size=0 ec_args = ""; bool bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース2:ec_args.size=3 ec_args = "periodic?rate=1000?policy=skip"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース3:ec_args[0].empty ec_args = "?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // trueを返すケース4:ec_args.size=2 ec_args = "periodic?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(bret); std::string chk_val("periodic"); CPPUNIT_ASSERT_EQUAL(chk_val, ec_id); chk_val = "1000"; CPPUNIT_ASSERT_EQUAL(chk_val, ec_prop["rate"]); delete man; } /*! * @brief getLogLevel()メソッドのテスト * * - log_levelが正しく返却されるか? */ void test_getLogLevel() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); std::string log_level = m_mgr->getLogLevel(); CPPUNIT_ASSERT_EQUAL(std::string("INFO"), log_level); } /*! * @brief getLoadedModules()メソッドのテスト * * - ロード済みのモジュールリストを正しく取得できるか? */ void test_getLoadedModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); /* FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード済みのモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadedModules(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string(".//./.libs/DummyModule.so"), props[0].getProperty("file_path")); */ } /*! * @brief getFactoryProfiles()メソッドのテスト * * - RTコンポーネント用ファクトリをリストを正しく取得できるか? */ void test_getFactoryProfiles() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); std::vector<coil::Properties> props = m_mgr->getFactoryProfiles(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string("PeriodicECSharedComposite"), props[0].getProperty("implementation_id")); CPPUNIT_ASSERT_EQUAL(std::string("ID"), props[1].getProperty("implementation_id")); } /*! * @brief createContext()メソッドのテスト * * - ExecutionContextBaseを正しく取得できるか? */ void test_createContext() { RTC::ExecutionContextBase* ec; std::string ec_args; m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // return NULL check ec_args = ""; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return NULL check (Factory not found) ec_args = "periodic?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return any check m_mgr->registerECFactory("PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>); ec_args = "PeriodicEC?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec != NULL); } /*! * @brief deleteComponent()メソッドのテスト * * - RTコンポーネントの削除が正しくできるか? */ void test_deleteComponent() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), std::string(comp->getInstanceName())); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") != NULL); std::vector<RTC::RTObject_impl*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT(comps.size() > 0); // 正しくコンポーネントを削除できるか? m_mgr->deleteComponent("DataFlowComponent0"); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); // deleteComponent()でexit()を実行しているため、これ以降のテストはできません。 } /*! * @brief init()、shutdown()から呼ばれるprotected関数のテスト * * - protected関数が正しく動作しているか? */ void test_init2() { // Manager::init()よりprotected関数が使用されているので、ここではテスト省略する // initManager() // initLogger() // initORB() // initNaming() // initFactories() // initExecContext() // initComposite() // initTimer() // initManagerServant() // Manager::shutdown()よりprotected関数が使用されているので、ここではテスト省略する // shutdownComponents(); // shutdownNaming(); // shutdownORB(); // shutdownManager(); // shutdownLogger(); } }; }; // namespace Tests /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(Tests::ManagerTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // ManagerTests_cpp
552  Logger logger;
553  ModuleMock::setLogger(&logger);
554 
555  // 初期化を行う
556  int argc = 0;
557  char* argv[] = {};
558 
559  m_mgr = RTC::Manager::init(argc, argv);
560  CPPUNIT_ASSERT(m_mgr != NULL);
561 
562  // 初期化プロシージャを登録する m_mgr->setModuleInitProc(&ModuleMock::InitProc); // アクティブ化により、設定した初期化プロシージャが正しく呼び出されるか? CPPUNIT_ASSERT_EQUAL(0, logger.countLog("InitProc")); CPPUNIT_ASSERT(m_mgr->activateManager()); CPPUNIT_ASSERT_EQUAL(1, logger.countLog("InitProc")); } void test_activateManager() { // 他テスト中で使用されているため省略する } /*! * @brief runManager()メソッドのテスト(非ブロッキングモード) * * - POAManagerがアクティブ化されるか? */ void test_runManager_no_block() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // オブジェクトを生成して、参照を得る CORBA::ORB_ptr orb = m_mgr->getORB(); CPPUNIT_ASSERT(! CORBA::is_nil(orb)); PortableServer::POA_ptr poa = m_mgr->getPOA(); CPPUNIT_ASSERT(! CORBA::is_nil(poa)); RTObjectMock* rto = new RTObjectMock(orb, poa); CPPUNIT_ASSERT(rto != NULL); // PortableServer::ObjectId_var rtoId = poa->activate_object(rto); PortableServer::ObjectId_var rtoId; try { rtoId = poa->activate_object(rto); } catch(const ::PortableServer::POA::ServantAlreadyActive &) { rtoId = poa->servant_to_id(rto); } RTC::DataFlowComponent_ptr rtoRef = RTC::DataFlowComponent::_narrow(poa->id_to_reference(rtoId)); CPPUNIT_ASSERT(! CORBA::is_nil(rtoRef)); // テスト用にロガーを設定しておく Logger logger; rto->setLogger(&logger); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // runManager()によりPOAManagerが正しくactive化されているか? // (取得したオブジェクト参照に対してメソッド呼出を行い、 // リモート側が呼出されたことによりPOAManagerのアクティブ化を確認する) CPPUNIT_ASSERT_EQUAL(0, logger.countLog("initialize")); rtoRef->initialize(); coil::sleep(3); CPPUNIT_ASSERT_EQUAL(1, logger.countLog("initialize")); poa->deactivate_object(rtoId); delete rto; } /*! * @brief runManager()メソッドのテスト(ブロッキングモード) * * - POAManagerがアクティブ化されるか? */ void test_runManager_block() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // オブジェクトを生成して、参照を得る CORBA::ORB_ptr orb = m_mgr->getORB(); CPPUNIT_ASSERT(! CORBA::is_nil(orb)); PortableServer::POA_ptr poa = m_mgr->getPOA(); CPPUNIT_ASSERT(! CORBA::is_nil(poa)); RTObjectMock* rto = new RTObjectMock(orb, poa); CPPUNIT_ASSERT(rto != NULL); PortableServer::ObjectId_var rtoId; try { rtoId = poa->activate_object(rto); } catch(const ::PortableServer::POA::ServantAlreadyActive &) { rtoId = poa->servant_to_id(rto); } RTC::DataFlowComponent_ptr rtoRef = RTC::DataFlowComponent::_narrow(poa->id_to_reference(rtoId)); CPPUNIT_ASSERT(! CORBA::is_nil(rtoRef)); // テスト用にロガーを設定しておく Logger logger; rto->setLogger(&logger); // ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); CPPUNIT_ASSERT_EQUAL(0, logger.countLog("initialize")); { InvokerMock invoker(rtoRef, m_mgr); m_mgr->runManager(false); // true:非ブロッキング,false:ブロッキング coil::sleep(3); } CPPUNIT_ASSERT_EQUAL(1, logger.countLog("initialize")); poa->deactivate_object(rtoId); delete rto; } class InvokerMock : public coil::Task { public: InvokerMock(const RTC::DataFlowComponent_ptr& rtoRef, RTC::Manager* mgr) { m_rtoRef = RTC::DataFlowComponent::_duplicate(rtoRef); m_mgr = mgr; activate(); } ~InvokerMock() { wait(); } virtual int svc(void) { m_rtoRef->initialize(); coil::sleep(1); // ブロックされているrunManager呼出をブロック解除する m_rtoRef->exit(); m_mgr->shutdown(); m_mgr->join(); return 0; } private: RTC::DataFlowComponent_ptr m_rtoRef; RTC::Manager* m_mgr; }; /*! * @brief load()メソッドのテスト * * - 指定したモジュールをロードして、指定の初期化関数が正しく呼び出されるか? */ void test_load() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア // モジュールロードにより、指定した初期化関数が呼び出されるか? CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); // std::string moduleName = m_mgr->load("DummyModule.so", "InitProc"); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName)); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount)()); } /*! * @brief unload()メソッドのテスト * * - いったんloadしたモジュールを、正しくunloadできるか? */ void test_unload() { // 初期化を行う int argc = 1; char* argv[] = { "-f fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア // いったんloadしておく CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // std::string moduleName = m_mgr->load("DummyModule.so", "InitProc"); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName)); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount)()); // いったんloadしたモジュールを、正しくunloadできるか? // m_mgr->unload(moduleName.c_str()); // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName)); } /*! * @brief unloadAll()メソッドのテスト * * - unloadAll()により、ロードしたモジュールがすべてアンロードされるか? */ void test_unloadAll() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader1("./.libs/DummyModule.so"); coil::DynamicLib loader2("./.libs/DummyModule2.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount1 = (FUNC_GETINITPROCCOUNT) loader1.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount1 != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount1 = (FUNC_RESETINITPROCCOUNT) loader1.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount1 != NULL); FUNC_GETINITPROCCOUNT pGetInitProcCount2 = (FUNC_GETINITPROCCOUNT) loader2.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount2 != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount2 = (FUNC_RESETINITPROCCOUNT) loader2.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount2 != NULL); (*pResetInitProcCount1)(); // カウンタクリア (*pResetInitProcCount2)(); // カウンタクリア // いったんloadしておく CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount1)()); CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount2)()); // std::string moduleName1 = m_mgr->load("DummyModule.so", "InitProc"); // std::string moduleName2 = m_mgr->load("DummyModule2.so", "InitProc"); m_mgr->load("./.libs/DummyModule.so", "InitProc"); m_mgr->load("./.libs/DummyModule2.so", "InitProc"); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName1)); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName2)); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount1)()); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount2)()); // unloadAll()により、ロードしたモジュールがすべてアンロードされるか? m_mgr->unloadAll(); // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName1)); // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName2)); } /*! * @brief getLoadableModules()メソッドのテスト * * - ロード可能なモジュールリストを正しく取得できるか? */ void test_getLoadableModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード可能なモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadableModules(); CPPUNIT_ASSERT(props.size() > 0); //for(int i=0;i<props.size(); ++i) //{ // std::cout << "--------------- props[" << i << "] dump ---------------" << std::endl; // props[i].list(std::cout); //} CPPUNIT_ASSERT_EQUAL(std::string("./.libs/DummyModule2.so"), props[0].getProperty("module_file_path")); } /*! * @brief registerFactory()メソッドのテスト * * - Factoryを正常に登録できるか? */ void test_registerFactory() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); } /*! * @brief registerECFactory() * * - 正常にECFactoryを登録できるか? */ void test_registerECFactory() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // 正常にECFactoryを登録できるか? CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 登録済みのECFactoryと同一の名称で登録を試みた場合、意図どおり登録失敗するか? CPPUNIT_ASSERT(! m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); } /*! * @brief getModulesFactories()メソッドのテスト * * - 登録されているFactoryの("implementation_id"プロパティの)リストを正しく取得できるか? */ void test_getModulesFactories() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // 複数のFactoryを登録しておく coil::Properties properties1; properties1.setProperty("implementation_id", "ID 1"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties1, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); coil::Properties properties2; properties2.setProperty("implementation_id", "ID 2"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties2, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // 登録されているFactoryの("implementation_id"プロパティの)リストを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(3, (int) m_mgr->getModulesFactories().size()); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID 1")); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID 2")); } /*! * @brief createComponent()メソッドのテスト(DataFlowComponentの場合) * * - 正しくコンポーネントを生成できるか? */ void test_createComponent_DataFlowComponent() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), // ※末尾の0はNumberingPolicyにより付加される std::string(comp->getInstanceName())); // コンポーネントに、意図どおりExecutionContextがアタッチされているか? RTC::ExecutionContextList* ecList = comp->get_owned_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length()); // 生成されたコンポーネントは、正しくネームサービスに登録されているか? // ※fixture4.confの各設定に合わせている点に注意 RTC::NamingManager nmgr(m_mgr); const char* name_server = "localhost:2809"; nmgr.registerNameServer("corba", name_server); CPPUNIT_ASSERT(canResolve(name_server, "DataFlowComponent0", "rtc")); comp->exit(); m_mgr->terminate(); } void test_createComponent_Non_DataFlowComponent() { // 現時点では、Manager側がDataFlowComponentのみに対応しているため、テスト省略する } /*! * @brief createComponent()メソッドのテスト * * - 登録されていないモジュール名を指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? * - モジュール名にNULLを指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? */ void test_createComponent_with_illegal_module_name() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 登録されていないモジュール名を指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp1 = m_mgr->createComponent("illegal_module_name"); CPPUNIT_ASSERT(comp1 == NULL); // モジュール名にNULLを指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp2 = m_mgr->createComponent(NULL); CPPUNIT_ASSERT(comp2 == NULL); } void test_createComponent_failed_in_bindExecutionContext() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // bindExecutionContext()で失敗するように、意図的にECFactoryを登録せずにおく // コンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp == NULL); m_mgr->terminate(); coil::usleep(3000000); } /*! * @brief cleanupComponent()メソッドのテスト * * - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? * - 登録したコンポーネントが、Managerから正しく登録解除されるか? */ void test_cleanupComponent() { // 初期化を行う // int argc = 1; // char* argv[] = { "-f fixture4.conf" }; int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 確認用にネームサービスへのアクセス手段としてNamingManagerを準備しておく // ※fixture4.confの各設定に合わせている点に注意 RTC::NamingManager nmgr(m_mgr); const char* name_server = "localhost:2809"; nmgr.registerNameServer("corba", name_server); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), // ※末尾の0はNumberingPolicyにより付加される std::string(comp->getInstanceName())); // コンポーネントに、意図どおりExecutionContextがアタッチされているか? RTC::ExecutionContextList* ecList = comp->get_owned_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length()); // cleanupComponent()により、正しく登録解除されるか? // - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? // - 登録したコンポーネントが、Managerから正しく登録解除されるか? CPPUNIT_ASSERT(!canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT_EQUAL(comp, m_mgr->getComponent("DataFlowComponent0")); m_mgr->cleanupComponent(comp); CPPUNIT_ASSERT(! canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); comp->exit(); usleep(10000); m_mgr->terminate(); } void test_unregisterComponent() { // Manager::cleanupComponent()内で使用されているので、ここではテスト省略する } void test_bindExecutionContext() { // Manager::createComponent()内で使用されているので、ここではテスト省略する } void test_getComponent() { // 他テスト内で使用されているので、そちらで兼ねるものとして、ここではテスト省略する } /*! * @brief getComponents()メソッドのテスト * * - getComponents()で、生成したすべてのコンポーネントを取得できるか? * - 登録解除したコンポーネントが、正しく一覧から除外されているか? */ void test_getComponents() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 複数のコンポーネントを生成しておく RTC::RtcBase* comp1 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp1 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp1) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp1->_this())); RTC::RtcBase* comp2 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp2 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp2) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp2->_this())); CPPUNIT_ASSERT(comp1 != comp2); // getComponents()で、生成したすべてのコンポーネントを取得できるか? std::vector<RTC::RtcBase*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT_EQUAL(2, (int) comps.size()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) != comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); // コンポーネントを1つだけ登録解除した場合、解除したものが一覧から除外されているか? m_mgr->cleanupComponent(comp1); comps = m_mgr->getComponents(); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) == comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); comp1->exit(); comp2->exit(); m_mgr->terminate(); } void test_getORB() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOA() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOAManager() { // 他テスト内で使用されているので、ここではテスト省略する } /*! * @brief initFactories()メソッドのテスト * * - init()実行後、initFactories()の実行結果としてFactoryMapに正しく登録されているか? */ void test_initFactories() { // init()の中でinitFactories()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initFactories()の実行結果としてFactoryMapに正しく登録されているか? bool bret = RTC::CdrBufferFactory::instance().hasFactory("ring_buffer"); CPPUNIT_ASSERT(bret); bret = RTC::PeriodicTaskFactory::instance().hasFactory("default"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("flush"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("new"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("periodic"); CPPUNIT_ASSERT(bret); RTC::InPortProviderFactory& factory1(RTC::InPortProviderFactory::instance()); bret = factory1.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::InPortConsumerFactory& factory2(RTC::InPortConsumerFactory::instance()); bret = factory2.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortConsumerFactory& factory3(RTC::OutPortConsumerFactory::instance()); bret = factory3.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortProviderFactory& factory4(RTC::OutPortProviderFactory::instance()); bret = factory4.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); } /*! * @brief initComposite()メソッドのテスト * * - init()実行後、initComposite()の実行結果としてFactoryManagerに正しく登録されているか? */ void test_initComposite() { // init()の中でinitComposite()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initComposite()の実行結果としてFactoryManagerに正しく登録されているか? // "implementation_id"には, "PeriodicECSharedComposite"が設定されている CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "PeriodicECSharedComposite")); } /*! * @brief procContextArgs()メソッドのテスト * * - 引数ec_argsにより戻り値true・falseが正しく返却されるか? */ void test_procContextArgs() { std::string ec_args; std::string ec_id; coil::Properties ec_prop; // インスタンス生成 ManagerTestMock* man = new ManagerTestMock(); // falseを返すケース1:ec_args.size=0 ec_args = ""; bool bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース2:ec_args.size=3 ec_args = "periodic?rate=1000?policy=skip"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース3:ec_args[0].empty ec_args = "?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // trueを返すケース4:ec_args.size=2 ec_args = "periodic?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(bret); std::string chk_val("periodic"); CPPUNIT_ASSERT_EQUAL(chk_val, ec_id); chk_val = "1000"; CPPUNIT_ASSERT_EQUAL(chk_val, ec_prop["rate"]); delete man; } /*! * @brief getLogLevel()メソッドのテスト * * - log_levelが正しく返却されるか? */ void test_getLogLevel() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); std::string log_level = m_mgr->getLogLevel(); CPPUNIT_ASSERT_EQUAL(std::string("INFO"), log_level); } /*! * @brief getLoadedModules()メソッドのテスト * * - ロード済みのモジュールリストを正しく取得できるか? */ void test_getLoadedModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); /* FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード済みのモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadedModules(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string(".//./.libs/DummyModule.so"), props[0].getProperty("file_path")); */ } /*! * @brief getFactoryProfiles()メソッドのテスト * * - RTコンポーネント用ファクトリをリストを正しく取得できるか? */ void test_getFactoryProfiles() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); std::vector<coil::Properties> props = m_mgr->getFactoryProfiles(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string("PeriodicECSharedComposite"), props[0].getProperty("implementation_id")); CPPUNIT_ASSERT_EQUAL(std::string("ID"), props[1].getProperty("implementation_id")); } /*! * @brief createContext()メソッドのテスト * * - ExecutionContextBaseを正しく取得できるか? */ void test_createContext() { RTC::ExecutionContextBase* ec; std::string ec_args; m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // return NULL check ec_args = ""; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return NULL check (Factory not found) ec_args = "periodic?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return any check m_mgr->registerECFactory("PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>); ec_args = "PeriodicEC?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec != NULL); } /*! * @brief deleteComponent()メソッドのテスト * * - RTコンポーネントの削除が正しくできるか? */ void test_deleteComponent() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), std::string(comp->getInstanceName())); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") != NULL); std::vector<RTC::RTObject_impl*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT(comps.size() > 0); // 正しくコンポーネントを削除できるか? m_mgr->deleteComponent("DataFlowComponent0"); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); // deleteComponent()でexit()を実行しているため、これ以降のテストはできません。 } /*! * @brief init()、shutdown()から呼ばれるprotected関数のテスト * * - protected関数が正しく動作しているか? */ void test_init2() { // Manager::init()よりprotected関数が使用されているので、ここではテスト省略する // initManager() // initLogger() // initORB() // initNaming() // initFactories() // initExecContext() // initComposite() // initTimer() // initManagerServant() // Manager::shutdown()よりprotected関数が使用されているので、ここではテスト省略する // shutdownComponents(); // shutdownNaming(); // shutdownORB(); // shutdownManager(); // shutdownLogger(); } }; }; // namespace Tests /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(Tests::ManagerTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // ManagerTests_cpp
564 
565  // アクティブ化により、設定した初期化プロシージャが正しく呼び出されるか?
566  CPPUNIT_ASSERT_EQUAL(0, logger.countLog("InitProc"));
567  CPPUNIT_ASSERT(m_mgr->activateManager());
568  CPPUNIT_ASSERT_EQUAL(1, logger.countLog("InitProc"));
569  }
570 
572  {
573  // 他テスト中で使用されているため省略する } /*! * @brief runManager()メソッドのテスト(非ブロッキングモード) * * - POAManagerがアクティブ化されるか? */ void test_runManager_no_block() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // オブジェクトを生成して、参照を得る CORBA::ORB_ptr orb = m_mgr->getORB(); CPPUNIT_ASSERT(! CORBA::is_nil(orb)); PortableServer::POA_ptr poa = m_mgr->getPOA(); CPPUNIT_ASSERT(! CORBA::is_nil(poa)); RTObjectMock* rto = new RTObjectMock(orb, poa); CPPUNIT_ASSERT(rto != NULL); // PortableServer::ObjectId_var rtoId = poa->activate_object(rto); PortableServer::ObjectId_var rtoId; try { rtoId = poa->activate_object(rto); } catch(const ::PortableServer::POA::ServantAlreadyActive &) { rtoId = poa->servant_to_id(rto); } RTC::DataFlowComponent_ptr rtoRef = RTC::DataFlowComponent::_narrow(poa->id_to_reference(rtoId)); CPPUNIT_ASSERT(! CORBA::is_nil(rtoRef)); // テスト用にロガーを設定しておく Logger logger; rto->setLogger(&logger); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // runManager()によりPOAManagerが正しくactive化されているか? // (取得したオブジェクト参照に対してメソッド呼出を行い、 // リモート側が呼出されたことによりPOAManagerのアクティブ化を確認する) CPPUNIT_ASSERT_EQUAL(0, logger.countLog("initialize")); rtoRef->initialize(); coil::sleep(3); CPPUNIT_ASSERT_EQUAL(1, logger.countLog("initialize")); poa->deactivate_object(rtoId); delete rto; } /*! * @brief runManager()メソッドのテスト(ブロッキングモード) * * - POAManagerがアクティブ化されるか? */ void test_runManager_block() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // オブジェクトを生成して、参照を得る CORBA::ORB_ptr orb = m_mgr->getORB(); CPPUNIT_ASSERT(! CORBA::is_nil(orb)); PortableServer::POA_ptr poa = m_mgr->getPOA(); CPPUNIT_ASSERT(! CORBA::is_nil(poa)); RTObjectMock* rto = new RTObjectMock(orb, poa); CPPUNIT_ASSERT(rto != NULL); PortableServer::ObjectId_var rtoId; try { rtoId = poa->activate_object(rto); } catch(const ::PortableServer::POA::ServantAlreadyActive &) { rtoId = poa->servant_to_id(rto); } RTC::DataFlowComponent_ptr rtoRef = RTC::DataFlowComponent::_narrow(poa->id_to_reference(rtoId)); CPPUNIT_ASSERT(! CORBA::is_nil(rtoRef)); // テスト用にロガーを設定しておく Logger logger; rto->setLogger(&logger); // ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); CPPUNIT_ASSERT_EQUAL(0, logger.countLog("initialize")); { InvokerMock invoker(rtoRef, m_mgr); m_mgr->runManager(false); // true:非ブロッキング,false:ブロッキング coil::sleep(3); } CPPUNIT_ASSERT_EQUAL(1, logger.countLog("initialize")); poa->deactivate_object(rtoId); delete rto; } class InvokerMock : public coil::Task { public: InvokerMock(const RTC::DataFlowComponent_ptr& rtoRef, RTC::Manager* mgr) { m_rtoRef = RTC::DataFlowComponent::_duplicate(rtoRef); m_mgr = mgr; activate(); } ~InvokerMock() { wait(); } virtual int svc(void) { m_rtoRef->initialize(); coil::sleep(1); // ブロックされているrunManager呼出をブロック解除する m_rtoRef->exit(); m_mgr->shutdown(); m_mgr->join(); return 0; } private: RTC::DataFlowComponent_ptr m_rtoRef; RTC::Manager* m_mgr; }; /*! * @brief load()メソッドのテスト * * - 指定したモジュールをロードして、指定の初期化関数が正しく呼び出されるか? */ void test_load() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア // モジュールロードにより、指定した初期化関数が呼び出されるか? CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); // std::string moduleName = m_mgr->load("DummyModule.so", "InitProc"); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName)); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount)()); } /*! * @brief unload()メソッドのテスト * * - いったんloadしたモジュールを、正しくunloadできるか? */ void test_unload() { // 初期化を行う int argc = 1; char* argv[] = { "-f fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア // いったんloadしておく CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // std::string moduleName = m_mgr->load("DummyModule.so", "InitProc"); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName)); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount)()); // いったんloadしたモジュールを、正しくunloadできるか? // m_mgr->unload(moduleName.c_str()); // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName)); } /*! * @brief unloadAll()メソッドのテスト * * - unloadAll()により、ロードしたモジュールがすべてアンロードされるか? */ void test_unloadAll() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader1("./.libs/DummyModule.so"); coil::DynamicLib loader2("./.libs/DummyModule2.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount1 = (FUNC_GETINITPROCCOUNT) loader1.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount1 != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount1 = (FUNC_RESETINITPROCCOUNT) loader1.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount1 != NULL); FUNC_GETINITPROCCOUNT pGetInitProcCount2 = (FUNC_GETINITPROCCOUNT) loader2.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount2 != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount2 = (FUNC_RESETINITPROCCOUNT) loader2.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount2 != NULL); (*pResetInitProcCount1)(); // カウンタクリア (*pResetInitProcCount2)(); // カウンタクリア // いったんloadしておく CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount1)()); CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount2)()); // std::string moduleName1 = m_mgr->load("DummyModule.so", "InitProc"); // std::string moduleName2 = m_mgr->load("DummyModule2.so", "InitProc"); m_mgr->load("./.libs/DummyModule.so", "InitProc"); m_mgr->load("./.libs/DummyModule2.so", "InitProc"); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName1)); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName2)); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount1)()); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount2)()); // unloadAll()により、ロードしたモジュールがすべてアンロードされるか? m_mgr->unloadAll(); // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName1)); // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName2)); } /*! * @brief getLoadableModules()メソッドのテスト * * - ロード可能なモジュールリストを正しく取得できるか? */ void test_getLoadableModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード可能なモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadableModules(); CPPUNIT_ASSERT(props.size() > 0); //for(int i=0;i<props.size(); ++i) //{ // std::cout << "--------------- props[" << i << "] dump ---------------" << std::endl; // props[i].list(std::cout); //} CPPUNIT_ASSERT_EQUAL(std::string("./.libs/DummyModule2.so"), props[0].getProperty("module_file_path")); } /*! * @brief registerFactory()メソッドのテスト * * - Factoryを正常に登録できるか? */ void test_registerFactory() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); } /*! * @brief registerECFactory() * * - 正常にECFactoryを登録できるか? */ void test_registerECFactory() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // 正常にECFactoryを登録できるか? CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 登録済みのECFactoryと同一の名称で登録を試みた場合、意図どおり登録失敗するか? CPPUNIT_ASSERT(! m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); } /*! * @brief getModulesFactories()メソッドのテスト * * - 登録されているFactoryの("implementation_id"プロパティの)リストを正しく取得できるか? */ void test_getModulesFactories() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // 複数のFactoryを登録しておく coil::Properties properties1; properties1.setProperty("implementation_id", "ID 1"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties1, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); coil::Properties properties2; properties2.setProperty("implementation_id", "ID 2"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties2, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // 登録されているFactoryの("implementation_id"プロパティの)リストを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(3, (int) m_mgr->getModulesFactories().size()); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID 1")); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID 2")); } /*! * @brief createComponent()メソッドのテスト(DataFlowComponentの場合) * * - 正しくコンポーネントを生成できるか? */ void test_createComponent_DataFlowComponent() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), // ※末尾の0はNumberingPolicyにより付加される std::string(comp->getInstanceName())); // コンポーネントに、意図どおりExecutionContextがアタッチされているか? RTC::ExecutionContextList* ecList = comp->get_owned_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length()); // 生成されたコンポーネントは、正しくネームサービスに登録されているか? // ※fixture4.confの各設定に合わせている点に注意 RTC::NamingManager nmgr(m_mgr); const char* name_server = "localhost:2809"; nmgr.registerNameServer("corba", name_server); CPPUNIT_ASSERT(canResolve(name_server, "DataFlowComponent0", "rtc")); comp->exit(); m_mgr->terminate(); } void test_createComponent_Non_DataFlowComponent() { // 現時点では、Manager側がDataFlowComponentのみに対応しているため、テスト省略する } /*! * @brief createComponent()メソッドのテスト * * - 登録されていないモジュール名を指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? * - モジュール名にNULLを指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? */ void test_createComponent_with_illegal_module_name() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 登録されていないモジュール名を指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp1 = m_mgr->createComponent("illegal_module_name"); CPPUNIT_ASSERT(comp1 == NULL); // モジュール名にNULLを指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp2 = m_mgr->createComponent(NULL); CPPUNIT_ASSERT(comp2 == NULL); } void test_createComponent_failed_in_bindExecutionContext() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // bindExecutionContext()で失敗するように、意図的にECFactoryを登録せずにおく // コンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp == NULL); m_mgr->terminate(); coil::usleep(3000000); } /*! * @brief cleanupComponent()メソッドのテスト * * - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? * - 登録したコンポーネントが、Managerから正しく登録解除されるか? */ void test_cleanupComponent() { // 初期化を行う // int argc = 1; // char* argv[] = { "-f fixture4.conf" }; int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 確認用にネームサービスへのアクセス手段としてNamingManagerを準備しておく // ※fixture4.confの各設定に合わせている点に注意 RTC::NamingManager nmgr(m_mgr); const char* name_server = "localhost:2809"; nmgr.registerNameServer("corba", name_server); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), // ※末尾の0はNumberingPolicyにより付加される std::string(comp->getInstanceName())); // コンポーネントに、意図どおりExecutionContextがアタッチされているか? RTC::ExecutionContextList* ecList = comp->get_owned_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length()); // cleanupComponent()により、正しく登録解除されるか? // - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? // - 登録したコンポーネントが、Managerから正しく登録解除されるか? CPPUNIT_ASSERT(!canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT_EQUAL(comp, m_mgr->getComponent("DataFlowComponent0")); m_mgr->cleanupComponent(comp); CPPUNIT_ASSERT(! canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); comp->exit(); usleep(10000); m_mgr->terminate(); } void test_unregisterComponent() { // Manager::cleanupComponent()内で使用されているので、ここではテスト省略する } void test_bindExecutionContext() { // Manager::createComponent()内で使用されているので、ここではテスト省略する } void test_getComponent() { // 他テスト内で使用されているので、そちらで兼ねるものとして、ここではテスト省略する } /*! * @brief getComponents()メソッドのテスト * * - getComponents()で、生成したすべてのコンポーネントを取得できるか? * - 登録解除したコンポーネントが、正しく一覧から除外されているか? */ void test_getComponents() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 複数のコンポーネントを生成しておく RTC::RtcBase* comp1 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp1 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp1) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp1->_this())); RTC::RtcBase* comp2 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp2 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp2) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp2->_this())); CPPUNIT_ASSERT(comp1 != comp2); // getComponents()で、生成したすべてのコンポーネントを取得できるか? std::vector<RTC::RtcBase*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT_EQUAL(2, (int) comps.size()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) != comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); // コンポーネントを1つだけ登録解除した場合、解除したものが一覧から除外されているか? m_mgr->cleanupComponent(comp1); comps = m_mgr->getComponents(); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) == comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); comp1->exit(); comp2->exit(); m_mgr->terminate(); } void test_getORB() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOA() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOAManager() { // 他テスト内で使用されているので、ここではテスト省略する } /*! * @brief initFactories()メソッドのテスト * * - init()実行後、initFactories()の実行結果としてFactoryMapに正しく登録されているか? */ void test_initFactories() { // init()の中でinitFactories()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initFactories()の実行結果としてFactoryMapに正しく登録されているか? bool bret = RTC::CdrBufferFactory::instance().hasFactory("ring_buffer"); CPPUNIT_ASSERT(bret); bret = RTC::PeriodicTaskFactory::instance().hasFactory("default"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("flush"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("new"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("periodic"); CPPUNIT_ASSERT(bret); RTC::InPortProviderFactory& factory1(RTC::InPortProviderFactory::instance()); bret = factory1.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::InPortConsumerFactory& factory2(RTC::InPortConsumerFactory::instance()); bret = factory2.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortConsumerFactory& factory3(RTC::OutPortConsumerFactory::instance()); bret = factory3.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortProviderFactory& factory4(RTC::OutPortProviderFactory::instance()); bret = factory4.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); } /*! * @brief initComposite()メソッドのテスト * * - init()実行後、initComposite()の実行結果としてFactoryManagerに正しく登録されているか? */ void test_initComposite() { // init()の中でinitComposite()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initComposite()の実行結果としてFactoryManagerに正しく登録されているか? // "implementation_id"には, "PeriodicECSharedComposite"が設定されている CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "PeriodicECSharedComposite")); } /*! * @brief procContextArgs()メソッドのテスト * * - 引数ec_argsにより戻り値true・falseが正しく返却されるか? */ void test_procContextArgs() { std::string ec_args; std::string ec_id; coil::Properties ec_prop; // インスタンス生成 ManagerTestMock* man = new ManagerTestMock(); // falseを返すケース1:ec_args.size=0 ec_args = ""; bool bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース2:ec_args.size=3 ec_args = "periodic?rate=1000?policy=skip"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース3:ec_args[0].empty ec_args = "?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // trueを返すケース4:ec_args.size=2 ec_args = "periodic?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(bret); std::string chk_val("periodic"); CPPUNIT_ASSERT_EQUAL(chk_val, ec_id); chk_val = "1000"; CPPUNIT_ASSERT_EQUAL(chk_val, ec_prop["rate"]); delete man; } /*! * @brief getLogLevel()メソッドのテスト * * - log_levelが正しく返却されるか? */ void test_getLogLevel() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); std::string log_level = m_mgr->getLogLevel(); CPPUNIT_ASSERT_EQUAL(std::string("INFO"), log_level); } /*! * @brief getLoadedModules()メソッドのテスト * * - ロード済みのモジュールリストを正しく取得できるか? */ void test_getLoadedModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); /* FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード済みのモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadedModules(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string(".//./.libs/DummyModule.so"), props[0].getProperty("file_path")); */ } /*! * @brief getFactoryProfiles()メソッドのテスト * * - RTコンポーネント用ファクトリをリストを正しく取得できるか? */ void test_getFactoryProfiles() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); std::vector<coil::Properties> props = m_mgr->getFactoryProfiles(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string("PeriodicECSharedComposite"), props[0].getProperty("implementation_id")); CPPUNIT_ASSERT_EQUAL(std::string("ID"), props[1].getProperty("implementation_id")); } /*! * @brief createContext()メソッドのテスト * * - ExecutionContextBaseを正しく取得できるか? */ void test_createContext() { RTC::ExecutionContextBase* ec; std::string ec_args; m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // return NULL check ec_args = ""; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return NULL check (Factory not found) ec_args = "periodic?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return any check m_mgr->registerECFactory("PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>); ec_args = "PeriodicEC?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec != NULL); } /*! * @brief deleteComponent()メソッドのテスト * * - RTコンポーネントの削除が正しくできるか? */ void test_deleteComponent() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), std::string(comp->getInstanceName())); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") != NULL); std::vector<RTC::RTObject_impl*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT(comps.size() > 0); // 正しくコンポーネントを削除できるか? m_mgr->deleteComponent("DataFlowComponent0"); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); // deleteComponent()でexit()を実行しているため、これ以降のテストはできません。 } /*! * @brief init()、shutdown()から呼ばれるprotected関数のテスト * * - protected関数が正しく動作しているか? */ void test_init2() { // Manager::init()よりprotected関数が使用されているので、ここではテスト省略する // initManager() // initLogger() // initORB() // initNaming() // initFactories() // initExecContext() // initComposite() // initTimer() // initManagerServant() // Manager::shutdown()よりprotected関数が使用されているので、ここではテスト省略する // shutdownComponents(); // shutdownNaming(); // shutdownORB(); // shutdownManager(); // shutdownLogger(); } }; }; // namespace Tests /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(Tests::ManagerTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // ManagerTests_cpp
574  }
575 
582  {
583  // 初期化を行う
584  int argc = 0;
585  char* argv[] = {};
586  m_mgr = RTC::Manager::init(argc, argv);
587  CPPUNIT_ASSERT(m_mgr != NULL);
588 
589  // オブジェクトを生成して、参照を得る CORBA::ORB_ptr orb = m_mgr->getORB(); CPPUNIT_ASSERT(! CORBA::is_nil(orb)); PortableServer::POA_ptr poa = m_mgr->getPOA(); CPPUNIT_ASSERT(! CORBA::is_nil(poa)); RTObjectMock* rto = new RTObjectMock(orb, poa); CPPUNIT_ASSERT(rto != NULL); // PortableServer::ObjectId_var rtoId = poa->activate_object(rto); PortableServer::ObjectId_var rtoId; try { rtoId = poa->activate_object(rto); } catch(const ::PortableServer::POA::ServantAlreadyActive &) { rtoId = poa->servant_to_id(rto); } RTC::DataFlowComponent_ptr rtoRef = RTC::DataFlowComponent::_narrow(poa->id_to_reference(rtoId)); CPPUNIT_ASSERT(! CORBA::is_nil(rtoRef)); // テスト用にロガーを設定しておく Logger logger; rto->setLogger(&logger); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // runManager()によりPOAManagerが正しくactive化されているか? // (取得したオブジェクト参照に対してメソッド呼出を行い、 // リモート側が呼出されたことによりPOAManagerのアクティブ化を確認する) CPPUNIT_ASSERT_EQUAL(0, logger.countLog("initialize")); rtoRef->initialize(); coil::sleep(3); CPPUNIT_ASSERT_EQUAL(1, logger.countLog("initialize")); poa->deactivate_object(rtoId); delete rto; } /*! * @brief runManager()メソッドのテスト(ブロッキングモード) * * - POAManagerがアクティブ化されるか? */ void test_runManager_block() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // オブジェクトを生成して、参照を得る CORBA::ORB_ptr orb = m_mgr->getORB(); CPPUNIT_ASSERT(! CORBA::is_nil(orb)); PortableServer::POA_ptr poa = m_mgr->getPOA(); CPPUNIT_ASSERT(! CORBA::is_nil(poa)); RTObjectMock* rto = new RTObjectMock(orb, poa); CPPUNIT_ASSERT(rto != NULL); PortableServer::ObjectId_var rtoId; try { rtoId = poa->activate_object(rto); } catch(const ::PortableServer::POA::ServantAlreadyActive &) { rtoId = poa->servant_to_id(rto); } RTC::DataFlowComponent_ptr rtoRef = RTC::DataFlowComponent::_narrow(poa->id_to_reference(rtoId)); CPPUNIT_ASSERT(! CORBA::is_nil(rtoRef)); // テスト用にロガーを設定しておく Logger logger; rto->setLogger(&logger); // ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); CPPUNIT_ASSERT_EQUAL(0, logger.countLog("initialize")); { InvokerMock invoker(rtoRef, m_mgr); m_mgr->runManager(false); // true:非ブロッキング,false:ブロッキング coil::sleep(3); } CPPUNIT_ASSERT_EQUAL(1, logger.countLog("initialize")); poa->deactivate_object(rtoId); delete rto; } class InvokerMock : public coil::Task { public: InvokerMock(const RTC::DataFlowComponent_ptr& rtoRef, RTC::Manager* mgr) { m_rtoRef = RTC::DataFlowComponent::_duplicate(rtoRef); m_mgr = mgr; activate(); } ~InvokerMock() { wait(); } virtual int svc(void) { m_rtoRef->initialize(); coil::sleep(1); // ブロックされているrunManager呼出をブロック解除する m_rtoRef->exit(); m_mgr->shutdown(); m_mgr->join(); return 0; } private: RTC::DataFlowComponent_ptr m_rtoRef; RTC::Manager* m_mgr; }; /*! * @brief load()メソッドのテスト * * - 指定したモジュールをロードして、指定の初期化関数が正しく呼び出されるか? */ void test_load() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア // モジュールロードにより、指定した初期化関数が呼び出されるか? CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); // std::string moduleName = m_mgr->load("DummyModule.so", "InitProc"); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName)); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount)()); } /*! * @brief unload()メソッドのテスト * * - いったんloadしたモジュールを、正しくunloadできるか? */ void test_unload() { // 初期化を行う int argc = 1; char* argv[] = { "-f fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア // いったんloadしておく CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // std::string moduleName = m_mgr->load("DummyModule.so", "InitProc"); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName)); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount)()); // いったんloadしたモジュールを、正しくunloadできるか? // m_mgr->unload(moduleName.c_str()); // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName)); } /*! * @brief unloadAll()メソッドのテスト * * - unloadAll()により、ロードしたモジュールがすべてアンロードされるか? */ void test_unloadAll() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader1("./.libs/DummyModule.so"); coil::DynamicLib loader2("./.libs/DummyModule2.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount1 = (FUNC_GETINITPROCCOUNT) loader1.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount1 != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount1 = (FUNC_RESETINITPROCCOUNT) loader1.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount1 != NULL); FUNC_GETINITPROCCOUNT pGetInitProcCount2 = (FUNC_GETINITPROCCOUNT) loader2.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount2 != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount2 = (FUNC_RESETINITPROCCOUNT) loader2.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount2 != NULL); (*pResetInitProcCount1)(); // カウンタクリア (*pResetInitProcCount2)(); // カウンタクリア // いったんloadしておく CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount1)()); CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount2)()); // std::string moduleName1 = m_mgr->load("DummyModule.so", "InitProc"); // std::string moduleName2 = m_mgr->load("DummyModule2.so", "InitProc"); m_mgr->load("./.libs/DummyModule.so", "InitProc"); m_mgr->load("./.libs/DummyModule2.so", "InitProc"); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName1)); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName2)); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount1)()); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount2)()); // unloadAll()により、ロードしたモジュールがすべてアンロードされるか? m_mgr->unloadAll(); // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName1)); // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName2)); } /*! * @brief getLoadableModules()メソッドのテスト * * - ロード可能なモジュールリストを正しく取得できるか? */ void test_getLoadableModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード可能なモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadableModules(); CPPUNIT_ASSERT(props.size() > 0); //for(int i=0;i<props.size(); ++i) //{ // std::cout << "--------------- props[" << i << "] dump ---------------" << std::endl; // props[i].list(std::cout); //} CPPUNIT_ASSERT_EQUAL(std::string("./.libs/DummyModule2.so"), props[0].getProperty("module_file_path")); } /*! * @brief registerFactory()メソッドのテスト * * - Factoryを正常に登録できるか? */ void test_registerFactory() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); } /*! * @brief registerECFactory() * * - 正常にECFactoryを登録できるか? */ void test_registerECFactory() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // 正常にECFactoryを登録できるか? CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 登録済みのECFactoryと同一の名称で登録を試みた場合、意図どおり登録失敗するか? CPPUNIT_ASSERT(! m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); } /*! * @brief getModulesFactories()メソッドのテスト * * - 登録されているFactoryの("implementation_id"プロパティの)リストを正しく取得できるか? */ void test_getModulesFactories() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // 複数のFactoryを登録しておく coil::Properties properties1; properties1.setProperty("implementation_id", "ID 1"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties1, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); coil::Properties properties2; properties2.setProperty("implementation_id", "ID 2"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties2, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // 登録されているFactoryの("implementation_id"プロパティの)リストを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(3, (int) m_mgr->getModulesFactories().size()); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID 1")); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID 2")); } /*! * @brief createComponent()メソッドのテスト(DataFlowComponentの場合) * * - 正しくコンポーネントを生成できるか? */ void test_createComponent_DataFlowComponent() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), // ※末尾の0はNumberingPolicyにより付加される std::string(comp->getInstanceName())); // コンポーネントに、意図どおりExecutionContextがアタッチされているか? RTC::ExecutionContextList* ecList = comp->get_owned_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length()); // 生成されたコンポーネントは、正しくネームサービスに登録されているか? // ※fixture4.confの各設定に合わせている点に注意 RTC::NamingManager nmgr(m_mgr); const char* name_server = "localhost:2809"; nmgr.registerNameServer("corba", name_server); CPPUNIT_ASSERT(canResolve(name_server, "DataFlowComponent0", "rtc")); comp->exit(); m_mgr->terminate(); } void test_createComponent_Non_DataFlowComponent() { // 現時点では、Manager側がDataFlowComponentのみに対応しているため、テスト省略する } /*! * @brief createComponent()メソッドのテスト * * - 登録されていないモジュール名を指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? * - モジュール名にNULLを指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? */ void test_createComponent_with_illegal_module_name() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 登録されていないモジュール名を指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp1 = m_mgr->createComponent("illegal_module_name"); CPPUNIT_ASSERT(comp1 == NULL); // モジュール名にNULLを指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp2 = m_mgr->createComponent(NULL); CPPUNIT_ASSERT(comp2 == NULL); } void test_createComponent_failed_in_bindExecutionContext() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // bindExecutionContext()で失敗するように、意図的にECFactoryを登録せずにおく // コンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp == NULL); m_mgr->terminate(); coil::usleep(3000000); } /*! * @brief cleanupComponent()メソッドのテスト * * - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? * - 登録したコンポーネントが、Managerから正しく登録解除されるか? */ void test_cleanupComponent() { // 初期化を行う // int argc = 1; // char* argv[] = { "-f fixture4.conf" }; int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 確認用にネームサービスへのアクセス手段としてNamingManagerを準備しておく // ※fixture4.confの各設定に合わせている点に注意 RTC::NamingManager nmgr(m_mgr); const char* name_server = "localhost:2809"; nmgr.registerNameServer("corba", name_server); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), // ※末尾の0はNumberingPolicyにより付加される std::string(comp->getInstanceName())); // コンポーネントに、意図どおりExecutionContextがアタッチされているか? RTC::ExecutionContextList* ecList = comp->get_owned_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length()); // cleanupComponent()により、正しく登録解除されるか? // - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? // - 登録したコンポーネントが、Managerから正しく登録解除されるか? CPPUNIT_ASSERT(!canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT_EQUAL(comp, m_mgr->getComponent("DataFlowComponent0")); m_mgr->cleanupComponent(comp); CPPUNIT_ASSERT(! canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); comp->exit(); usleep(10000); m_mgr->terminate(); } void test_unregisterComponent() { // Manager::cleanupComponent()内で使用されているので、ここではテスト省略する } void test_bindExecutionContext() { // Manager::createComponent()内で使用されているので、ここではテスト省略する } void test_getComponent() { // 他テスト内で使用されているので、そちらで兼ねるものとして、ここではテスト省略する } /*! * @brief getComponents()メソッドのテスト * * - getComponents()で、生成したすべてのコンポーネントを取得できるか? * - 登録解除したコンポーネントが、正しく一覧から除外されているか? */ void test_getComponents() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 複数のコンポーネントを生成しておく RTC::RtcBase* comp1 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp1 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp1) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp1->_this())); RTC::RtcBase* comp2 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp2 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp2) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp2->_this())); CPPUNIT_ASSERT(comp1 != comp2); // getComponents()で、生成したすべてのコンポーネントを取得できるか? std::vector<RTC::RtcBase*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT_EQUAL(2, (int) comps.size()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) != comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); // コンポーネントを1つだけ登録解除した場合、解除したものが一覧から除外されているか? m_mgr->cleanupComponent(comp1); comps = m_mgr->getComponents(); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) == comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); comp1->exit(); comp2->exit(); m_mgr->terminate(); } void test_getORB() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOA() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOAManager() { // 他テスト内で使用されているので、ここではテスト省略する } /*! * @brief initFactories()メソッドのテスト * * - init()実行後、initFactories()の実行結果としてFactoryMapに正しく登録されているか? */ void test_initFactories() { // init()の中でinitFactories()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initFactories()の実行結果としてFactoryMapに正しく登録されているか? bool bret = RTC::CdrBufferFactory::instance().hasFactory("ring_buffer"); CPPUNIT_ASSERT(bret); bret = RTC::PeriodicTaskFactory::instance().hasFactory("default"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("flush"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("new"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("periodic"); CPPUNIT_ASSERT(bret); RTC::InPortProviderFactory& factory1(RTC::InPortProviderFactory::instance()); bret = factory1.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::InPortConsumerFactory& factory2(RTC::InPortConsumerFactory::instance()); bret = factory2.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortConsumerFactory& factory3(RTC::OutPortConsumerFactory::instance()); bret = factory3.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortProviderFactory& factory4(RTC::OutPortProviderFactory::instance()); bret = factory4.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); } /*! * @brief initComposite()メソッドのテスト * * - init()実行後、initComposite()の実行結果としてFactoryManagerに正しく登録されているか? */ void test_initComposite() { // init()の中でinitComposite()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initComposite()の実行結果としてFactoryManagerに正しく登録されているか? // "implementation_id"には, "PeriodicECSharedComposite"が設定されている CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "PeriodicECSharedComposite")); } /*! * @brief procContextArgs()メソッドのテスト * * - 引数ec_argsにより戻り値true・falseが正しく返却されるか? */ void test_procContextArgs() { std::string ec_args; std::string ec_id; coil::Properties ec_prop; // インスタンス生成 ManagerTestMock* man = new ManagerTestMock(); // falseを返すケース1:ec_args.size=0 ec_args = ""; bool bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース2:ec_args.size=3 ec_args = "periodic?rate=1000?policy=skip"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース3:ec_args[0].empty ec_args = "?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // trueを返すケース4:ec_args.size=2 ec_args = "periodic?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(bret); std::string chk_val("periodic"); CPPUNIT_ASSERT_EQUAL(chk_val, ec_id); chk_val = "1000"; CPPUNIT_ASSERT_EQUAL(chk_val, ec_prop["rate"]); delete man; } /*! * @brief getLogLevel()メソッドのテスト * * - log_levelが正しく返却されるか? */ void test_getLogLevel() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); std::string log_level = m_mgr->getLogLevel(); CPPUNIT_ASSERT_EQUAL(std::string("INFO"), log_level); } /*! * @brief getLoadedModules()メソッドのテスト * * - ロード済みのモジュールリストを正しく取得できるか? */ void test_getLoadedModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); /* FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード済みのモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadedModules(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string(".//./.libs/DummyModule.so"), props[0].getProperty("file_path")); */ } /*! * @brief getFactoryProfiles()メソッドのテスト * * - RTコンポーネント用ファクトリをリストを正しく取得できるか? */ void test_getFactoryProfiles() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); std::vector<coil::Properties> props = m_mgr->getFactoryProfiles(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string("PeriodicECSharedComposite"), props[0].getProperty("implementation_id")); CPPUNIT_ASSERT_EQUAL(std::string("ID"), props[1].getProperty("implementation_id")); } /*! * @brief createContext()メソッドのテスト * * - ExecutionContextBaseを正しく取得できるか? */ void test_createContext() { RTC::ExecutionContextBase* ec; std::string ec_args; m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // return NULL check ec_args = ""; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return NULL check (Factory not found) ec_args = "periodic?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return any check m_mgr->registerECFactory("PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>); ec_args = "PeriodicEC?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec != NULL); } /*! * @brief deleteComponent()メソッドのテスト * * - RTコンポーネントの削除が正しくできるか? */ void test_deleteComponent() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), std::string(comp->getInstanceName())); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") != NULL); std::vector<RTC::RTObject_impl*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT(comps.size() > 0); // 正しくコンポーネントを削除できるか? m_mgr->deleteComponent("DataFlowComponent0"); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); // deleteComponent()でexit()を実行しているため、これ以降のテストはできません。 } /*! * @brief init()、shutdown()から呼ばれるprotected関数のテスト * * - protected関数が正しく動作しているか? */ void test_init2() { // Manager::init()よりprotected関数が使用されているので、ここではテスト省略する // initManager() // initLogger() // initORB() // initNaming() // initFactories() // initExecContext() // initComposite() // initTimer() // initManagerServant() // Manager::shutdown()よりprotected関数が使用されているので、ここではテスト省略する // shutdownComponents(); // shutdownNaming(); // shutdownORB(); // shutdownManager(); // shutdownLogger(); } }; }; // namespace Tests /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(Tests::ManagerTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // ManagerTests_cpp
590  CORBA::ORB_ptr orb = m_mgr->getORB();
591  CPPUNIT_ASSERT(! CORBA::is_nil(orb));
592  PortableServer::POA_ptr poa = m_mgr->getPOA();
593  CPPUNIT_ASSERT(! CORBA::is_nil(poa));
594 
595  RTObjectMock* rto = new RTObjectMock(orb, poa);
596  CPPUNIT_ASSERT(rto != NULL);
597 
598 // PortableServer::ObjectId_var rtoId = poa->activate_object(rto);
599  PortableServer::ObjectId_var rtoId;
600  try
601  {
602  rtoId = poa->activate_object(rto);
603  }
604  catch(const ::PortableServer::POA::ServantAlreadyActive &)
605  {
606  rtoId = poa->servant_to_id(rto);
607  }
608 
609 
610  RTC::DataFlowComponent_ptr rtoRef
611  = RTC::DataFlowComponent::_narrow(poa->id_to_reference(rtoId));
612  CPPUNIT_ASSERT(! CORBA::is_nil(rtoRef));
613  // テスト用にロガーを設定しておく
614  Logger logger;
615  rto->setLogger(&logger);
616 
617  // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // runManager()によりPOAManagerが正しくactive化されているか? // (取得したオブジェクト参照に対してメソッド呼出を行い、 // リモート側が呼出されたことによりPOAManagerのアクティブ化を確認する) CPPUNIT_ASSERT_EQUAL(0, logger.countLog("initialize")); rtoRef->initialize(); coil::sleep(3); CPPUNIT_ASSERT_EQUAL(1, logger.countLog("initialize")); poa->deactivate_object(rtoId); delete rto; } /*! * @brief runManager()メソッドのテスト(ブロッキングモード) * * - POAManagerがアクティブ化されるか? */ void test_runManager_block() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // オブジェクトを生成して、参照を得る CORBA::ORB_ptr orb = m_mgr->getORB(); CPPUNIT_ASSERT(! CORBA::is_nil(orb)); PortableServer::POA_ptr poa = m_mgr->getPOA(); CPPUNIT_ASSERT(! CORBA::is_nil(poa)); RTObjectMock* rto = new RTObjectMock(orb, poa); CPPUNIT_ASSERT(rto != NULL); PortableServer::ObjectId_var rtoId; try { rtoId = poa->activate_object(rto); } catch(const ::PortableServer::POA::ServantAlreadyActive &) { rtoId = poa->servant_to_id(rto); } RTC::DataFlowComponent_ptr rtoRef = RTC::DataFlowComponent::_narrow(poa->id_to_reference(rtoId)); CPPUNIT_ASSERT(! CORBA::is_nil(rtoRef)); // テスト用にロガーを設定しておく Logger logger; rto->setLogger(&logger); // ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); CPPUNIT_ASSERT_EQUAL(0, logger.countLog("initialize")); { InvokerMock invoker(rtoRef, m_mgr); m_mgr->runManager(false); // true:非ブロッキング,false:ブロッキング coil::sleep(3); } CPPUNIT_ASSERT_EQUAL(1, logger.countLog("initialize")); poa->deactivate_object(rtoId); delete rto; } class InvokerMock : public coil::Task { public: InvokerMock(const RTC::DataFlowComponent_ptr& rtoRef, RTC::Manager* mgr) { m_rtoRef = RTC::DataFlowComponent::_duplicate(rtoRef); m_mgr = mgr; activate(); } ~InvokerMock() { wait(); } virtual int svc(void) { m_rtoRef->initialize(); coil::sleep(1); // ブロックされているrunManager呼出をブロック解除する m_rtoRef->exit(); m_mgr->shutdown(); m_mgr->join(); return 0; } private: RTC::DataFlowComponent_ptr m_rtoRef; RTC::Manager* m_mgr; }; /*! * @brief load()メソッドのテスト * * - 指定したモジュールをロードして、指定の初期化関数が正しく呼び出されるか? */ void test_load() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア // モジュールロードにより、指定した初期化関数が呼び出されるか? CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); // std::string moduleName = m_mgr->load("DummyModule.so", "InitProc"); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName)); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount)()); } /*! * @brief unload()メソッドのテスト * * - いったんloadしたモジュールを、正しくunloadできるか? */ void test_unload() { // 初期化を行う int argc = 1; char* argv[] = { "-f fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア // いったんloadしておく CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // std::string moduleName = m_mgr->load("DummyModule.so", "InitProc"); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName)); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount)()); // いったんloadしたモジュールを、正しくunloadできるか? // m_mgr->unload(moduleName.c_str()); // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName)); } /*! * @brief unloadAll()メソッドのテスト * * - unloadAll()により、ロードしたモジュールがすべてアンロードされるか? */ void test_unloadAll() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader1("./.libs/DummyModule.so"); coil::DynamicLib loader2("./.libs/DummyModule2.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount1 = (FUNC_GETINITPROCCOUNT) loader1.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount1 != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount1 = (FUNC_RESETINITPROCCOUNT) loader1.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount1 != NULL); FUNC_GETINITPROCCOUNT pGetInitProcCount2 = (FUNC_GETINITPROCCOUNT) loader2.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount2 != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount2 = (FUNC_RESETINITPROCCOUNT) loader2.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount2 != NULL); (*pResetInitProcCount1)(); // カウンタクリア (*pResetInitProcCount2)(); // カウンタクリア // いったんloadしておく CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount1)()); CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount2)()); // std::string moduleName1 = m_mgr->load("DummyModule.so", "InitProc"); // std::string moduleName2 = m_mgr->load("DummyModule2.so", "InitProc"); m_mgr->load("./.libs/DummyModule.so", "InitProc"); m_mgr->load("./.libs/DummyModule2.so", "InitProc"); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName1)); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName2)); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount1)()); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount2)()); // unloadAll()により、ロードしたモジュールがすべてアンロードされるか? m_mgr->unloadAll(); // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName1)); // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName2)); } /*! * @brief getLoadableModules()メソッドのテスト * * - ロード可能なモジュールリストを正しく取得できるか? */ void test_getLoadableModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード可能なモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadableModules(); CPPUNIT_ASSERT(props.size() > 0); //for(int i=0;i<props.size(); ++i) //{ // std::cout << "--------------- props[" << i << "] dump ---------------" << std::endl; // props[i].list(std::cout); //} CPPUNIT_ASSERT_EQUAL(std::string("./.libs/DummyModule2.so"), props[0].getProperty("module_file_path")); } /*! * @brief registerFactory()メソッドのテスト * * - Factoryを正常に登録できるか? */ void test_registerFactory() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); } /*! * @brief registerECFactory() * * - 正常にECFactoryを登録できるか? */ void test_registerECFactory() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // 正常にECFactoryを登録できるか? CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 登録済みのECFactoryと同一の名称で登録を試みた場合、意図どおり登録失敗するか? CPPUNIT_ASSERT(! m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); } /*! * @brief getModulesFactories()メソッドのテスト * * - 登録されているFactoryの("implementation_id"プロパティの)リストを正しく取得できるか? */ void test_getModulesFactories() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // 複数のFactoryを登録しておく coil::Properties properties1; properties1.setProperty("implementation_id", "ID 1"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties1, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); coil::Properties properties2; properties2.setProperty("implementation_id", "ID 2"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties2, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // 登録されているFactoryの("implementation_id"プロパティの)リストを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(3, (int) m_mgr->getModulesFactories().size()); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID 1")); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID 2")); } /*! * @brief createComponent()メソッドのテスト(DataFlowComponentの場合) * * - 正しくコンポーネントを生成できるか? */ void test_createComponent_DataFlowComponent() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), // ※末尾の0はNumberingPolicyにより付加される std::string(comp->getInstanceName())); // コンポーネントに、意図どおりExecutionContextがアタッチされているか? RTC::ExecutionContextList* ecList = comp->get_owned_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length()); // 生成されたコンポーネントは、正しくネームサービスに登録されているか? // ※fixture4.confの各設定に合わせている点に注意 RTC::NamingManager nmgr(m_mgr); const char* name_server = "localhost:2809"; nmgr.registerNameServer("corba", name_server); CPPUNIT_ASSERT(canResolve(name_server, "DataFlowComponent0", "rtc")); comp->exit(); m_mgr->terminate(); } void test_createComponent_Non_DataFlowComponent() { // 現時点では、Manager側がDataFlowComponentのみに対応しているため、テスト省略する } /*! * @brief createComponent()メソッドのテスト * * - 登録されていないモジュール名を指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? * - モジュール名にNULLを指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? */ void test_createComponent_with_illegal_module_name() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 登録されていないモジュール名を指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp1 = m_mgr->createComponent("illegal_module_name"); CPPUNIT_ASSERT(comp1 == NULL); // モジュール名にNULLを指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp2 = m_mgr->createComponent(NULL); CPPUNIT_ASSERT(comp2 == NULL); } void test_createComponent_failed_in_bindExecutionContext() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // bindExecutionContext()で失敗するように、意図的にECFactoryを登録せずにおく // コンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp == NULL); m_mgr->terminate(); coil::usleep(3000000); } /*! * @brief cleanupComponent()メソッドのテスト * * - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? * - 登録したコンポーネントが、Managerから正しく登録解除されるか? */ void test_cleanupComponent() { // 初期化を行う // int argc = 1; // char* argv[] = { "-f fixture4.conf" }; int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 確認用にネームサービスへのアクセス手段としてNamingManagerを準備しておく // ※fixture4.confの各設定に合わせている点に注意 RTC::NamingManager nmgr(m_mgr); const char* name_server = "localhost:2809"; nmgr.registerNameServer("corba", name_server); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), // ※末尾の0はNumberingPolicyにより付加される std::string(comp->getInstanceName())); // コンポーネントに、意図どおりExecutionContextがアタッチされているか? RTC::ExecutionContextList* ecList = comp->get_owned_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length()); // cleanupComponent()により、正しく登録解除されるか? // - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? // - 登録したコンポーネントが、Managerから正しく登録解除されるか? CPPUNIT_ASSERT(!canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT_EQUAL(comp, m_mgr->getComponent("DataFlowComponent0")); m_mgr->cleanupComponent(comp); CPPUNIT_ASSERT(! canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); comp->exit(); usleep(10000); m_mgr->terminate(); } void test_unregisterComponent() { // Manager::cleanupComponent()内で使用されているので、ここではテスト省略する } void test_bindExecutionContext() { // Manager::createComponent()内で使用されているので、ここではテスト省略する } void test_getComponent() { // 他テスト内で使用されているので、そちらで兼ねるものとして、ここではテスト省略する } /*! * @brief getComponents()メソッドのテスト * * - getComponents()で、生成したすべてのコンポーネントを取得できるか? * - 登録解除したコンポーネントが、正しく一覧から除外されているか? */ void test_getComponents() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 複数のコンポーネントを生成しておく RTC::RtcBase* comp1 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp1 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp1) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp1->_this())); RTC::RtcBase* comp2 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp2 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp2) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp2->_this())); CPPUNIT_ASSERT(comp1 != comp2); // getComponents()で、生成したすべてのコンポーネントを取得できるか? std::vector<RTC::RtcBase*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT_EQUAL(2, (int) comps.size()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) != comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); // コンポーネントを1つだけ登録解除した場合、解除したものが一覧から除外されているか? m_mgr->cleanupComponent(comp1); comps = m_mgr->getComponents(); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) == comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); comp1->exit(); comp2->exit(); m_mgr->terminate(); } void test_getORB() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOA() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOAManager() { // 他テスト内で使用されているので、ここではテスト省略する } /*! * @brief initFactories()メソッドのテスト * * - init()実行後、initFactories()の実行結果としてFactoryMapに正しく登録されているか? */ void test_initFactories() { // init()の中でinitFactories()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initFactories()の実行結果としてFactoryMapに正しく登録されているか? bool bret = RTC::CdrBufferFactory::instance().hasFactory("ring_buffer"); CPPUNIT_ASSERT(bret); bret = RTC::PeriodicTaskFactory::instance().hasFactory("default"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("flush"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("new"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("periodic"); CPPUNIT_ASSERT(bret); RTC::InPortProviderFactory& factory1(RTC::InPortProviderFactory::instance()); bret = factory1.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::InPortConsumerFactory& factory2(RTC::InPortConsumerFactory::instance()); bret = factory2.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortConsumerFactory& factory3(RTC::OutPortConsumerFactory::instance()); bret = factory3.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortProviderFactory& factory4(RTC::OutPortProviderFactory::instance()); bret = factory4.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); } /*! * @brief initComposite()メソッドのテスト * * - init()実行後、initComposite()の実行結果としてFactoryManagerに正しく登録されているか? */ void test_initComposite() { // init()の中でinitComposite()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initComposite()の実行結果としてFactoryManagerに正しく登録されているか? // "implementation_id"には, "PeriodicECSharedComposite"が設定されている CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "PeriodicECSharedComposite")); } /*! * @brief procContextArgs()メソッドのテスト * * - 引数ec_argsにより戻り値true・falseが正しく返却されるか? */ void test_procContextArgs() { std::string ec_args; std::string ec_id; coil::Properties ec_prop; // インスタンス生成 ManagerTestMock* man = new ManagerTestMock(); // falseを返すケース1:ec_args.size=0 ec_args = ""; bool bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース2:ec_args.size=3 ec_args = "periodic?rate=1000?policy=skip"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース3:ec_args[0].empty ec_args = "?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // trueを返すケース4:ec_args.size=2 ec_args = "periodic?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(bret); std::string chk_val("periodic"); CPPUNIT_ASSERT_EQUAL(chk_val, ec_id); chk_val = "1000"; CPPUNIT_ASSERT_EQUAL(chk_val, ec_prop["rate"]); delete man; } /*! * @brief getLogLevel()メソッドのテスト * * - log_levelが正しく返却されるか? */ void test_getLogLevel() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); std::string log_level = m_mgr->getLogLevel(); CPPUNIT_ASSERT_EQUAL(std::string("INFO"), log_level); } /*! * @brief getLoadedModules()メソッドのテスト * * - ロード済みのモジュールリストを正しく取得できるか? */ void test_getLoadedModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); /* FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード済みのモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadedModules(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string(".//./.libs/DummyModule.so"), props[0].getProperty("file_path")); */ } /*! * @brief getFactoryProfiles()メソッドのテスト * * - RTコンポーネント用ファクトリをリストを正しく取得できるか? */ void test_getFactoryProfiles() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); std::vector<coil::Properties> props = m_mgr->getFactoryProfiles(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string("PeriodicECSharedComposite"), props[0].getProperty("implementation_id")); CPPUNIT_ASSERT_EQUAL(std::string("ID"), props[1].getProperty("implementation_id")); } /*! * @brief createContext()メソッドのテスト * * - ExecutionContextBaseを正しく取得できるか? */ void test_createContext() { RTC::ExecutionContextBase* ec; std::string ec_args; m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // return NULL check ec_args = ""; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return NULL check (Factory not found) ec_args = "periodic?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return any check m_mgr->registerECFactory("PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>); ec_args = "PeriodicEC?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec != NULL); } /*! * @brief deleteComponent()メソッドのテスト * * - RTコンポーネントの削除が正しくできるか? */ void test_deleteComponent() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), std::string(comp->getInstanceName())); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") != NULL); std::vector<RTC::RTObject_impl*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT(comps.size() > 0); // 正しくコンポーネントを削除できるか? m_mgr->deleteComponent("DataFlowComponent0"); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); // deleteComponent()でexit()を実行しているため、これ以降のテストはできません。 } /*! * @brief init()、shutdown()から呼ばれるprotected関数のテスト * * - protected関数が正しく動作しているか? */ void test_init2() { // Manager::init()よりprotected関数が使用されているので、ここではテスト省略する // initManager() // initLogger() // initORB() // initNaming() // initFactories() // initExecContext() // initComposite() // initTimer() // initManagerServant() // Manager::shutdown()よりprotected関数が使用されているので、ここではテスト省略する // shutdownComponents(); // shutdownNaming(); // shutdownORB(); // shutdownManager(); // shutdownLogger(); } }; }; // namespace Tests /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(Tests::ManagerTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // ManagerTests_cpp
618  CPPUNIT_ASSERT(m_mgr->activateManager());
619  m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング
620 
621  // runManager()によりPOAManagerが正しくactive化されているか?
622  // (取得したオブジェクト参照に対してメソッド呼出を行い、
623  // リモート側が呼出されたことによりPOAManagerのアクティブ化を確認する) CPPUNIT_ASSERT_EQUAL(0, logger.countLog("initialize")); rtoRef->initialize(); coil::sleep(3); CPPUNIT_ASSERT_EQUAL(1, logger.countLog("initialize")); poa->deactivate_object(rtoId); delete rto; } /*! * @brief runManager()メソッドのテスト(ブロッキングモード) * * - POAManagerがアクティブ化されるか? */ void test_runManager_block() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // オブジェクトを生成して、参照を得る CORBA::ORB_ptr orb = m_mgr->getORB(); CPPUNIT_ASSERT(! CORBA::is_nil(orb)); PortableServer::POA_ptr poa = m_mgr->getPOA(); CPPUNIT_ASSERT(! CORBA::is_nil(poa)); RTObjectMock* rto = new RTObjectMock(orb, poa); CPPUNIT_ASSERT(rto != NULL); PortableServer::ObjectId_var rtoId; try { rtoId = poa->activate_object(rto); } catch(const ::PortableServer::POA::ServantAlreadyActive &) { rtoId = poa->servant_to_id(rto); } RTC::DataFlowComponent_ptr rtoRef = RTC::DataFlowComponent::_narrow(poa->id_to_reference(rtoId)); CPPUNIT_ASSERT(! CORBA::is_nil(rtoRef)); // テスト用にロガーを設定しておく Logger logger; rto->setLogger(&logger); // ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); CPPUNIT_ASSERT_EQUAL(0, logger.countLog("initialize")); { InvokerMock invoker(rtoRef, m_mgr); m_mgr->runManager(false); // true:非ブロッキング,false:ブロッキング coil::sleep(3); } CPPUNIT_ASSERT_EQUAL(1, logger.countLog("initialize")); poa->deactivate_object(rtoId); delete rto; } class InvokerMock : public coil::Task { public: InvokerMock(const RTC::DataFlowComponent_ptr& rtoRef, RTC::Manager* mgr) { m_rtoRef = RTC::DataFlowComponent::_duplicate(rtoRef); m_mgr = mgr; activate(); } ~InvokerMock() { wait(); } virtual int svc(void) { m_rtoRef->initialize(); coil::sleep(1); // ブロックされているrunManager呼出をブロック解除する m_rtoRef->exit(); m_mgr->shutdown(); m_mgr->join(); return 0; } private: RTC::DataFlowComponent_ptr m_rtoRef; RTC::Manager* m_mgr; }; /*! * @brief load()メソッドのテスト * * - 指定したモジュールをロードして、指定の初期化関数が正しく呼び出されるか? */ void test_load() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア // モジュールロードにより、指定した初期化関数が呼び出されるか? CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); // std::string moduleName = m_mgr->load("DummyModule.so", "InitProc"); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName)); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount)()); } /*! * @brief unload()メソッドのテスト * * - いったんloadしたモジュールを、正しくunloadできるか? */ void test_unload() { // 初期化を行う int argc = 1; char* argv[] = { "-f fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア // いったんloadしておく CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // std::string moduleName = m_mgr->load("DummyModule.so", "InitProc"); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName)); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount)()); // いったんloadしたモジュールを、正しくunloadできるか? // m_mgr->unload(moduleName.c_str()); // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName)); } /*! * @brief unloadAll()メソッドのテスト * * - unloadAll()により、ロードしたモジュールがすべてアンロードされるか? */ void test_unloadAll() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader1("./.libs/DummyModule.so"); coil::DynamicLib loader2("./.libs/DummyModule2.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount1 = (FUNC_GETINITPROCCOUNT) loader1.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount1 != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount1 = (FUNC_RESETINITPROCCOUNT) loader1.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount1 != NULL); FUNC_GETINITPROCCOUNT pGetInitProcCount2 = (FUNC_GETINITPROCCOUNT) loader2.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount2 != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount2 = (FUNC_RESETINITPROCCOUNT) loader2.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount2 != NULL); (*pResetInitProcCount1)(); // カウンタクリア (*pResetInitProcCount2)(); // カウンタクリア // いったんloadしておく CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount1)()); CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount2)()); // std::string moduleName1 = m_mgr->load("DummyModule.so", "InitProc"); // std::string moduleName2 = m_mgr->load("DummyModule2.so", "InitProc"); m_mgr->load("./.libs/DummyModule.so", "InitProc"); m_mgr->load("./.libs/DummyModule2.so", "InitProc"); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName1)); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName2)); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount1)()); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount2)()); // unloadAll()により、ロードしたモジュールがすべてアンロードされるか? m_mgr->unloadAll(); // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName1)); // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName2)); } /*! * @brief getLoadableModules()メソッドのテスト * * - ロード可能なモジュールリストを正しく取得できるか? */ void test_getLoadableModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード可能なモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadableModules(); CPPUNIT_ASSERT(props.size() > 0); //for(int i=0;i<props.size(); ++i) //{ // std::cout << "--------------- props[" << i << "] dump ---------------" << std::endl; // props[i].list(std::cout); //} CPPUNIT_ASSERT_EQUAL(std::string("./.libs/DummyModule2.so"), props[0].getProperty("module_file_path")); } /*! * @brief registerFactory()メソッドのテスト * * - Factoryを正常に登録できるか? */ void test_registerFactory() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); } /*! * @brief registerECFactory() * * - 正常にECFactoryを登録できるか? */ void test_registerECFactory() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // 正常にECFactoryを登録できるか? CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 登録済みのECFactoryと同一の名称で登録を試みた場合、意図どおり登録失敗するか? CPPUNIT_ASSERT(! m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); } /*! * @brief getModulesFactories()メソッドのテスト * * - 登録されているFactoryの("implementation_id"プロパティの)リストを正しく取得できるか? */ void test_getModulesFactories() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // 複数のFactoryを登録しておく coil::Properties properties1; properties1.setProperty("implementation_id", "ID 1"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties1, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); coil::Properties properties2; properties2.setProperty("implementation_id", "ID 2"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties2, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // 登録されているFactoryの("implementation_id"プロパティの)リストを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(3, (int) m_mgr->getModulesFactories().size()); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID 1")); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID 2")); } /*! * @brief createComponent()メソッドのテスト(DataFlowComponentの場合) * * - 正しくコンポーネントを生成できるか? */ void test_createComponent_DataFlowComponent() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), // ※末尾の0はNumberingPolicyにより付加される std::string(comp->getInstanceName())); // コンポーネントに、意図どおりExecutionContextがアタッチされているか? RTC::ExecutionContextList* ecList = comp->get_owned_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length()); // 生成されたコンポーネントは、正しくネームサービスに登録されているか? // ※fixture4.confの各設定に合わせている点に注意 RTC::NamingManager nmgr(m_mgr); const char* name_server = "localhost:2809"; nmgr.registerNameServer("corba", name_server); CPPUNIT_ASSERT(canResolve(name_server, "DataFlowComponent0", "rtc")); comp->exit(); m_mgr->terminate(); } void test_createComponent_Non_DataFlowComponent() { // 現時点では、Manager側がDataFlowComponentのみに対応しているため、テスト省略する } /*! * @brief createComponent()メソッドのテスト * * - 登録されていないモジュール名を指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? * - モジュール名にNULLを指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? */ void test_createComponent_with_illegal_module_name() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 登録されていないモジュール名を指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp1 = m_mgr->createComponent("illegal_module_name"); CPPUNIT_ASSERT(comp1 == NULL); // モジュール名にNULLを指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp2 = m_mgr->createComponent(NULL); CPPUNIT_ASSERT(comp2 == NULL); } void test_createComponent_failed_in_bindExecutionContext() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // bindExecutionContext()で失敗するように、意図的にECFactoryを登録せずにおく // コンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp == NULL); m_mgr->terminate(); coil::usleep(3000000); } /*! * @brief cleanupComponent()メソッドのテスト * * - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? * - 登録したコンポーネントが、Managerから正しく登録解除されるか? */ void test_cleanupComponent() { // 初期化を行う // int argc = 1; // char* argv[] = { "-f fixture4.conf" }; int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 確認用にネームサービスへのアクセス手段としてNamingManagerを準備しておく // ※fixture4.confの各設定に合わせている点に注意 RTC::NamingManager nmgr(m_mgr); const char* name_server = "localhost:2809"; nmgr.registerNameServer("corba", name_server); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), // ※末尾の0はNumberingPolicyにより付加される std::string(comp->getInstanceName())); // コンポーネントに、意図どおりExecutionContextがアタッチされているか? RTC::ExecutionContextList* ecList = comp->get_owned_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length()); // cleanupComponent()により、正しく登録解除されるか? // - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? // - 登録したコンポーネントが、Managerから正しく登録解除されるか? CPPUNIT_ASSERT(!canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT_EQUAL(comp, m_mgr->getComponent("DataFlowComponent0")); m_mgr->cleanupComponent(comp); CPPUNIT_ASSERT(! canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); comp->exit(); usleep(10000); m_mgr->terminate(); } void test_unregisterComponent() { // Manager::cleanupComponent()内で使用されているので、ここではテスト省略する } void test_bindExecutionContext() { // Manager::createComponent()内で使用されているので、ここではテスト省略する } void test_getComponent() { // 他テスト内で使用されているので、そちらで兼ねるものとして、ここではテスト省略する } /*! * @brief getComponents()メソッドのテスト * * - getComponents()で、生成したすべてのコンポーネントを取得できるか? * - 登録解除したコンポーネントが、正しく一覧から除外されているか? */ void test_getComponents() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 複数のコンポーネントを生成しておく RTC::RtcBase* comp1 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp1 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp1) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp1->_this())); RTC::RtcBase* comp2 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp2 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp2) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp2->_this())); CPPUNIT_ASSERT(comp1 != comp2); // getComponents()で、生成したすべてのコンポーネントを取得できるか? std::vector<RTC::RtcBase*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT_EQUAL(2, (int) comps.size()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) != comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); // コンポーネントを1つだけ登録解除した場合、解除したものが一覧から除外されているか? m_mgr->cleanupComponent(comp1); comps = m_mgr->getComponents(); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) == comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); comp1->exit(); comp2->exit(); m_mgr->terminate(); } void test_getORB() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOA() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOAManager() { // 他テスト内で使用されているので、ここではテスト省略する } /*! * @brief initFactories()メソッドのテスト * * - init()実行後、initFactories()の実行結果としてFactoryMapに正しく登録されているか? */ void test_initFactories() { // init()の中でinitFactories()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initFactories()の実行結果としてFactoryMapに正しく登録されているか? bool bret = RTC::CdrBufferFactory::instance().hasFactory("ring_buffer"); CPPUNIT_ASSERT(bret); bret = RTC::PeriodicTaskFactory::instance().hasFactory("default"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("flush"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("new"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("periodic"); CPPUNIT_ASSERT(bret); RTC::InPortProviderFactory& factory1(RTC::InPortProviderFactory::instance()); bret = factory1.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::InPortConsumerFactory& factory2(RTC::InPortConsumerFactory::instance()); bret = factory2.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortConsumerFactory& factory3(RTC::OutPortConsumerFactory::instance()); bret = factory3.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortProviderFactory& factory4(RTC::OutPortProviderFactory::instance()); bret = factory4.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); } /*! * @brief initComposite()メソッドのテスト * * - init()実行後、initComposite()の実行結果としてFactoryManagerに正しく登録されているか? */ void test_initComposite() { // init()の中でinitComposite()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initComposite()の実行結果としてFactoryManagerに正しく登録されているか? // "implementation_id"には, "PeriodicECSharedComposite"が設定されている CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "PeriodicECSharedComposite")); } /*! * @brief procContextArgs()メソッドのテスト * * - 引数ec_argsにより戻り値true・falseが正しく返却されるか? */ void test_procContextArgs() { std::string ec_args; std::string ec_id; coil::Properties ec_prop; // インスタンス生成 ManagerTestMock* man = new ManagerTestMock(); // falseを返すケース1:ec_args.size=0 ec_args = ""; bool bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース2:ec_args.size=3 ec_args = "periodic?rate=1000?policy=skip"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース3:ec_args[0].empty ec_args = "?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // trueを返すケース4:ec_args.size=2 ec_args = "periodic?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(bret); std::string chk_val("periodic"); CPPUNIT_ASSERT_EQUAL(chk_val, ec_id); chk_val = "1000"; CPPUNIT_ASSERT_EQUAL(chk_val, ec_prop["rate"]); delete man; } /*! * @brief getLogLevel()メソッドのテスト * * - log_levelが正しく返却されるか? */ void test_getLogLevel() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); std::string log_level = m_mgr->getLogLevel(); CPPUNIT_ASSERT_EQUAL(std::string("INFO"), log_level); } /*! * @brief getLoadedModules()メソッドのテスト * * - ロード済みのモジュールリストを正しく取得できるか? */ void test_getLoadedModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); /* FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード済みのモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadedModules(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string(".//./.libs/DummyModule.so"), props[0].getProperty("file_path")); */ } /*! * @brief getFactoryProfiles()メソッドのテスト * * - RTコンポーネント用ファクトリをリストを正しく取得できるか? */ void test_getFactoryProfiles() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); std::vector<coil::Properties> props = m_mgr->getFactoryProfiles(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string("PeriodicECSharedComposite"), props[0].getProperty("implementation_id")); CPPUNIT_ASSERT_EQUAL(std::string("ID"), props[1].getProperty("implementation_id")); } /*! * @brief createContext()メソッドのテスト * * - ExecutionContextBaseを正しく取得できるか? */ void test_createContext() { RTC::ExecutionContextBase* ec; std::string ec_args; m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // return NULL check ec_args = ""; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return NULL check (Factory not found) ec_args = "periodic?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return any check m_mgr->registerECFactory("PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>); ec_args = "PeriodicEC?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec != NULL); } /*! * @brief deleteComponent()メソッドのテスト * * - RTコンポーネントの削除が正しくできるか? */ void test_deleteComponent() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), std::string(comp->getInstanceName())); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") != NULL); std::vector<RTC::RTObject_impl*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT(comps.size() > 0); // 正しくコンポーネントを削除できるか? m_mgr->deleteComponent("DataFlowComponent0"); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); // deleteComponent()でexit()を実行しているため、これ以降のテストはできません。 } /*! * @brief init()、shutdown()から呼ばれるprotected関数のテスト * * - protected関数が正しく動作しているか? */ void test_init2() { // Manager::init()よりprotected関数が使用されているので、ここではテスト省略する // initManager() // initLogger() // initORB() // initNaming() // initFactories() // initExecContext() // initComposite() // initTimer() // initManagerServant() // Manager::shutdown()よりprotected関数が使用されているので、ここではテスト省略する // shutdownComponents(); // shutdownNaming(); // shutdownORB(); // shutdownManager(); // shutdownLogger(); } }; }; // namespace Tests /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(Tests::ManagerTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // ManagerTests_cpp
624  CPPUNIT_ASSERT_EQUAL(0, logger.countLog("initialize"));
625  rtoRef->initialize();
626  coil::sleep(3);
627  CPPUNIT_ASSERT_EQUAL(1, logger.countLog("initialize"));
628 
629  poa->deactivate_object(rtoId);
630  delete rto;
631  }
632 
639  {
640  // 初期化を行う
641  int argc = 0;
642  char* argv[] = {};
643 
644  m_mgr = RTC::Manager::init(argc, argv);
645  CPPUNIT_ASSERT(m_mgr != NULL);
646 
647  // オブジェクトを生成して、参照を得る CORBA::ORB_ptr orb = m_mgr->getORB(); CPPUNIT_ASSERT(! CORBA::is_nil(orb)); PortableServer::POA_ptr poa = m_mgr->getPOA(); CPPUNIT_ASSERT(! CORBA::is_nil(poa)); RTObjectMock* rto = new RTObjectMock(orb, poa); CPPUNIT_ASSERT(rto != NULL); PortableServer::ObjectId_var rtoId; try { rtoId = poa->activate_object(rto); } catch(const ::PortableServer::POA::ServantAlreadyActive &) { rtoId = poa->servant_to_id(rto); } RTC::DataFlowComponent_ptr rtoRef = RTC::DataFlowComponent::_narrow(poa->id_to_reference(rtoId)); CPPUNIT_ASSERT(! CORBA::is_nil(rtoRef)); // テスト用にロガーを設定しておく Logger logger; rto->setLogger(&logger); // ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); CPPUNIT_ASSERT_EQUAL(0, logger.countLog("initialize")); { InvokerMock invoker(rtoRef, m_mgr); m_mgr->runManager(false); // true:非ブロッキング,false:ブロッキング coil::sleep(3); } CPPUNIT_ASSERT_EQUAL(1, logger.countLog("initialize")); poa->deactivate_object(rtoId); delete rto; } class InvokerMock : public coil::Task { public: InvokerMock(const RTC::DataFlowComponent_ptr& rtoRef, RTC::Manager* mgr) { m_rtoRef = RTC::DataFlowComponent::_duplicate(rtoRef); m_mgr = mgr; activate(); } ~InvokerMock() { wait(); } virtual int svc(void) { m_rtoRef->initialize(); coil::sleep(1); // ブロックされているrunManager呼出をブロック解除する m_rtoRef->exit(); m_mgr->shutdown(); m_mgr->join(); return 0; } private: RTC::DataFlowComponent_ptr m_rtoRef; RTC::Manager* m_mgr; }; /*! * @brief load()メソッドのテスト * * - 指定したモジュールをロードして、指定の初期化関数が正しく呼び出されるか? */ void test_load() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア // モジュールロードにより、指定した初期化関数が呼び出されるか? CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); // std::string moduleName = m_mgr->load("DummyModule.so", "InitProc"); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName)); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount)()); } /*! * @brief unload()メソッドのテスト * * - いったんloadしたモジュールを、正しくunloadできるか? */ void test_unload() { // 初期化を行う int argc = 1; char* argv[] = { "-f fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア // いったんloadしておく CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // std::string moduleName = m_mgr->load("DummyModule.so", "InitProc"); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName)); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount)()); // いったんloadしたモジュールを、正しくunloadできるか? // m_mgr->unload(moduleName.c_str()); // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName)); } /*! * @brief unloadAll()メソッドのテスト * * - unloadAll()により、ロードしたモジュールがすべてアンロードされるか? */ void test_unloadAll() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader1("./.libs/DummyModule.so"); coil::DynamicLib loader2("./.libs/DummyModule2.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount1 = (FUNC_GETINITPROCCOUNT) loader1.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount1 != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount1 = (FUNC_RESETINITPROCCOUNT) loader1.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount1 != NULL); FUNC_GETINITPROCCOUNT pGetInitProcCount2 = (FUNC_GETINITPROCCOUNT) loader2.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount2 != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount2 = (FUNC_RESETINITPROCCOUNT) loader2.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount2 != NULL); (*pResetInitProcCount1)(); // カウンタクリア (*pResetInitProcCount2)(); // カウンタクリア // いったんloadしておく CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount1)()); CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount2)()); // std::string moduleName1 = m_mgr->load("DummyModule.so", "InitProc"); // std::string moduleName2 = m_mgr->load("DummyModule2.so", "InitProc"); m_mgr->load("./.libs/DummyModule.so", "InitProc"); m_mgr->load("./.libs/DummyModule2.so", "InitProc"); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName1)); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName2)); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount1)()); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount2)()); // unloadAll()により、ロードしたモジュールがすべてアンロードされるか? m_mgr->unloadAll(); // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName1)); // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName2)); } /*! * @brief getLoadableModules()メソッドのテスト * * - ロード可能なモジュールリストを正しく取得できるか? */ void test_getLoadableModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード可能なモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadableModules(); CPPUNIT_ASSERT(props.size() > 0); //for(int i=0;i<props.size(); ++i) //{ // std::cout << "--------------- props[" << i << "] dump ---------------" << std::endl; // props[i].list(std::cout); //} CPPUNIT_ASSERT_EQUAL(std::string("./.libs/DummyModule2.so"), props[0].getProperty("module_file_path")); } /*! * @brief registerFactory()メソッドのテスト * * - Factoryを正常に登録できるか? */ void test_registerFactory() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); } /*! * @brief registerECFactory() * * - 正常にECFactoryを登録できるか? */ void test_registerECFactory() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // 正常にECFactoryを登録できるか? CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 登録済みのECFactoryと同一の名称で登録を試みた場合、意図どおり登録失敗するか? CPPUNIT_ASSERT(! m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); } /*! * @brief getModulesFactories()メソッドのテスト * * - 登録されているFactoryの("implementation_id"プロパティの)リストを正しく取得できるか? */ void test_getModulesFactories() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // 複数のFactoryを登録しておく coil::Properties properties1; properties1.setProperty("implementation_id", "ID 1"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties1, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); coil::Properties properties2; properties2.setProperty("implementation_id", "ID 2"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties2, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // 登録されているFactoryの("implementation_id"プロパティの)リストを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(3, (int) m_mgr->getModulesFactories().size()); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID 1")); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID 2")); } /*! * @brief createComponent()メソッドのテスト(DataFlowComponentの場合) * * - 正しくコンポーネントを生成できるか? */ void test_createComponent_DataFlowComponent() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), // ※末尾の0はNumberingPolicyにより付加される std::string(comp->getInstanceName())); // コンポーネントに、意図どおりExecutionContextがアタッチされているか? RTC::ExecutionContextList* ecList = comp->get_owned_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length()); // 生成されたコンポーネントは、正しくネームサービスに登録されているか? // ※fixture4.confの各設定に合わせている点に注意 RTC::NamingManager nmgr(m_mgr); const char* name_server = "localhost:2809"; nmgr.registerNameServer("corba", name_server); CPPUNIT_ASSERT(canResolve(name_server, "DataFlowComponent0", "rtc")); comp->exit(); m_mgr->terminate(); } void test_createComponent_Non_DataFlowComponent() { // 現時点では、Manager側がDataFlowComponentのみに対応しているため、テスト省略する } /*! * @brief createComponent()メソッドのテスト * * - 登録されていないモジュール名を指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? * - モジュール名にNULLを指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? */ void test_createComponent_with_illegal_module_name() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 登録されていないモジュール名を指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp1 = m_mgr->createComponent("illegal_module_name"); CPPUNIT_ASSERT(comp1 == NULL); // モジュール名にNULLを指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp2 = m_mgr->createComponent(NULL); CPPUNIT_ASSERT(comp2 == NULL); } void test_createComponent_failed_in_bindExecutionContext() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // bindExecutionContext()で失敗するように、意図的にECFactoryを登録せずにおく // コンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp == NULL); m_mgr->terminate(); coil::usleep(3000000); } /*! * @brief cleanupComponent()メソッドのテスト * * - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? * - 登録したコンポーネントが、Managerから正しく登録解除されるか? */ void test_cleanupComponent() { // 初期化を行う // int argc = 1; // char* argv[] = { "-f fixture4.conf" }; int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 確認用にネームサービスへのアクセス手段としてNamingManagerを準備しておく // ※fixture4.confの各設定に合わせている点に注意 RTC::NamingManager nmgr(m_mgr); const char* name_server = "localhost:2809"; nmgr.registerNameServer("corba", name_server); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), // ※末尾の0はNumberingPolicyにより付加される std::string(comp->getInstanceName())); // コンポーネントに、意図どおりExecutionContextがアタッチされているか? RTC::ExecutionContextList* ecList = comp->get_owned_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length()); // cleanupComponent()により、正しく登録解除されるか? // - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? // - 登録したコンポーネントが、Managerから正しく登録解除されるか? CPPUNIT_ASSERT(!canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT_EQUAL(comp, m_mgr->getComponent("DataFlowComponent0")); m_mgr->cleanupComponent(comp); CPPUNIT_ASSERT(! canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); comp->exit(); usleep(10000); m_mgr->terminate(); } void test_unregisterComponent() { // Manager::cleanupComponent()内で使用されているので、ここではテスト省略する } void test_bindExecutionContext() { // Manager::createComponent()内で使用されているので、ここではテスト省略する } void test_getComponent() { // 他テスト内で使用されているので、そちらで兼ねるものとして、ここではテスト省略する } /*! * @brief getComponents()メソッドのテスト * * - getComponents()で、生成したすべてのコンポーネントを取得できるか? * - 登録解除したコンポーネントが、正しく一覧から除外されているか? */ void test_getComponents() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 複数のコンポーネントを生成しておく RTC::RtcBase* comp1 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp1 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp1) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp1->_this())); RTC::RtcBase* comp2 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp2 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp2) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp2->_this())); CPPUNIT_ASSERT(comp1 != comp2); // getComponents()で、生成したすべてのコンポーネントを取得できるか? std::vector<RTC::RtcBase*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT_EQUAL(2, (int) comps.size()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) != comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); // コンポーネントを1つだけ登録解除した場合、解除したものが一覧から除外されているか? m_mgr->cleanupComponent(comp1); comps = m_mgr->getComponents(); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) == comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); comp1->exit(); comp2->exit(); m_mgr->terminate(); } void test_getORB() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOA() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOAManager() { // 他テスト内で使用されているので、ここではテスト省略する } /*! * @brief initFactories()メソッドのテスト * * - init()実行後、initFactories()の実行結果としてFactoryMapに正しく登録されているか? */ void test_initFactories() { // init()の中でinitFactories()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initFactories()の実行結果としてFactoryMapに正しく登録されているか? bool bret = RTC::CdrBufferFactory::instance().hasFactory("ring_buffer"); CPPUNIT_ASSERT(bret); bret = RTC::PeriodicTaskFactory::instance().hasFactory("default"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("flush"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("new"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("periodic"); CPPUNIT_ASSERT(bret); RTC::InPortProviderFactory& factory1(RTC::InPortProviderFactory::instance()); bret = factory1.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::InPortConsumerFactory& factory2(RTC::InPortConsumerFactory::instance()); bret = factory2.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortConsumerFactory& factory3(RTC::OutPortConsumerFactory::instance()); bret = factory3.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortProviderFactory& factory4(RTC::OutPortProviderFactory::instance()); bret = factory4.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); } /*! * @brief initComposite()メソッドのテスト * * - init()実行後、initComposite()の実行結果としてFactoryManagerに正しく登録されているか? */ void test_initComposite() { // init()の中でinitComposite()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initComposite()の実行結果としてFactoryManagerに正しく登録されているか? // "implementation_id"には, "PeriodicECSharedComposite"が設定されている CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "PeriodicECSharedComposite")); } /*! * @brief procContextArgs()メソッドのテスト * * - 引数ec_argsにより戻り値true・falseが正しく返却されるか? */ void test_procContextArgs() { std::string ec_args; std::string ec_id; coil::Properties ec_prop; // インスタンス生成 ManagerTestMock* man = new ManagerTestMock(); // falseを返すケース1:ec_args.size=0 ec_args = ""; bool bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース2:ec_args.size=3 ec_args = "periodic?rate=1000?policy=skip"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース3:ec_args[0].empty ec_args = "?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // trueを返すケース4:ec_args.size=2 ec_args = "periodic?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(bret); std::string chk_val("periodic"); CPPUNIT_ASSERT_EQUAL(chk_val, ec_id); chk_val = "1000"; CPPUNIT_ASSERT_EQUAL(chk_val, ec_prop["rate"]); delete man; } /*! * @brief getLogLevel()メソッドのテスト * * - log_levelが正しく返却されるか? */ void test_getLogLevel() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); std::string log_level = m_mgr->getLogLevel(); CPPUNIT_ASSERT_EQUAL(std::string("INFO"), log_level); } /*! * @brief getLoadedModules()メソッドのテスト * * - ロード済みのモジュールリストを正しく取得できるか? */ void test_getLoadedModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); /* FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード済みのモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadedModules(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string(".//./.libs/DummyModule.so"), props[0].getProperty("file_path")); */ } /*! * @brief getFactoryProfiles()メソッドのテスト * * - RTコンポーネント用ファクトリをリストを正しく取得できるか? */ void test_getFactoryProfiles() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); std::vector<coil::Properties> props = m_mgr->getFactoryProfiles(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string("PeriodicECSharedComposite"), props[0].getProperty("implementation_id")); CPPUNIT_ASSERT_EQUAL(std::string("ID"), props[1].getProperty("implementation_id")); } /*! * @brief createContext()メソッドのテスト * * - ExecutionContextBaseを正しく取得できるか? */ void test_createContext() { RTC::ExecutionContextBase* ec; std::string ec_args; m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // return NULL check ec_args = ""; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return NULL check (Factory not found) ec_args = "periodic?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return any check m_mgr->registerECFactory("PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>); ec_args = "PeriodicEC?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec != NULL); } /*! * @brief deleteComponent()メソッドのテスト * * - RTコンポーネントの削除が正しくできるか? */ void test_deleteComponent() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), std::string(comp->getInstanceName())); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") != NULL); std::vector<RTC::RTObject_impl*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT(comps.size() > 0); // 正しくコンポーネントを削除できるか? m_mgr->deleteComponent("DataFlowComponent0"); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); // deleteComponent()でexit()を実行しているため、これ以降のテストはできません。 } /*! * @brief init()、shutdown()から呼ばれるprotected関数のテスト * * - protected関数が正しく動作しているか? */ void test_init2() { // Manager::init()よりprotected関数が使用されているので、ここではテスト省略する // initManager() // initLogger() // initORB() // initNaming() // initFactories() // initExecContext() // initComposite() // initTimer() // initManagerServant() // Manager::shutdown()よりprotected関数が使用されているので、ここではテスト省略する // shutdownComponents(); // shutdownNaming(); // shutdownORB(); // shutdownManager(); // shutdownLogger(); } }; }; // namespace Tests /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(Tests::ManagerTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // ManagerTests_cpp
648  CORBA::ORB_ptr orb = m_mgr->getORB();
649  CPPUNIT_ASSERT(! CORBA::is_nil(orb));
650  PortableServer::POA_ptr poa = m_mgr->getPOA();
651  CPPUNIT_ASSERT(! CORBA::is_nil(poa));
652 
653  RTObjectMock* rto = new RTObjectMock(orb, poa);
654  CPPUNIT_ASSERT(rto != NULL);
655 
656  PortableServer::ObjectId_var rtoId;
657  try
658  {
659  rtoId = poa->activate_object(rto);
660  }
661  catch(const ::PortableServer::POA::ServantAlreadyActive &)
662  {
663  rtoId = poa->servant_to_id(rto);
664  }
665 
666  RTC::DataFlowComponent_ptr rtoRef
667  = RTC::DataFlowComponent::_narrow(poa->id_to_reference(rtoId));
668  CPPUNIT_ASSERT(! CORBA::is_nil(rtoRef));
669 
670  // テスト用にロガーを設定しておく
671  Logger logger;
672  rto->setLogger(&logger);
673 
674  // ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); CPPUNIT_ASSERT_EQUAL(0, logger.countLog("initialize")); { InvokerMock invoker(rtoRef, m_mgr); m_mgr->runManager(false); // true:非ブロッキング,false:ブロッキング coil::sleep(3); } CPPUNIT_ASSERT_EQUAL(1, logger.countLog("initialize")); poa->deactivate_object(rtoId); delete rto; } class InvokerMock : public coil::Task { public: InvokerMock(const RTC::DataFlowComponent_ptr& rtoRef, RTC::Manager* mgr) { m_rtoRef = RTC::DataFlowComponent::_duplicate(rtoRef); m_mgr = mgr; activate(); } ~InvokerMock() { wait(); } virtual int svc(void) { m_rtoRef->initialize(); coil::sleep(1); // ブロックされているrunManager呼出をブロック解除する m_rtoRef->exit(); m_mgr->shutdown(); m_mgr->join(); return 0; } private: RTC::DataFlowComponent_ptr m_rtoRef; RTC::Manager* m_mgr; }; /*! * @brief load()メソッドのテスト * * - 指定したモジュールをロードして、指定の初期化関数が正しく呼び出されるか? */ void test_load() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア // モジュールロードにより、指定した初期化関数が呼び出されるか? CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); // std::string moduleName = m_mgr->load("DummyModule.so", "InitProc"); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName)); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount)()); } /*! * @brief unload()メソッドのテスト * * - いったんloadしたモジュールを、正しくunloadできるか? */ void test_unload() { // 初期化を行う int argc = 1; char* argv[] = { "-f fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア // いったんloadしておく CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // std::string moduleName = m_mgr->load("DummyModule.so", "InitProc"); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName)); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount)()); // いったんloadしたモジュールを、正しくunloadできるか? // m_mgr->unload(moduleName.c_str()); // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName)); } /*! * @brief unloadAll()メソッドのテスト * * - unloadAll()により、ロードしたモジュールがすべてアンロードされるか? */ void test_unloadAll() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader1("./.libs/DummyModule.so"); coil::DynamicLib loader2("./.libs/DummyModule2.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount1 = (FUNC_GETINITPROCCOUNT) loader1.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount1 != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount1 = (FUNC_RESETINITPROCCOUNT) loader1.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount1 != NULL); FUNC_GETINITPROCCOUNT pGetInitProcCount2 = (FUNC_GETINITPROCCOUNT) loader2.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount2 != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount2 = (FUNC_RESETINITPROCCOUNT) loader2.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount2 != NULL); (*pResetInitProcCount1)(); // カウンタクリア (*pResetInitProcCount2)(); // カウンタクリア // いったんloadしておく CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount1)()); CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount2)()); // std::string moduleName1 = m_mgr->load("DummyModule.so", "InitProc"); // std::string moduleName2 = m_mgr->load("DummyModule2.so", "InitProc"); m_mgr->load("./.libs/DummyModule.so", "InitProc"); m_mgr->load("./.libs/DummyModule2.so", "InitProc"); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName1)); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName2)); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount1)()); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount2)()); // unloadAll()により、ロードしたモジュールがすべてアンロードされるか? m_mgr->unloadAll(); // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName1)); // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName2)); } /*! * @brief getLoadableModules()メソッドのテスト * * - ロード可能なモジュールリストを正しく取得できるか? */ void test_getLoadableModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード可能なモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadableModules(); CPPUNIT_ASSERT(props.size() > 0); //for(int i=0;i<props.size(); ++i) //{ // std::cout << "--------------- props[" << i << "] dump ---------------" << std::endl; // props[i].list(std::cout); //} CPPUNIT_ASSERT_EQUAL(std::string("./.libs/DummyModule2.so"), props[0].getProperty("module_file_path")); } /*! * @brief registerFactory()メソッドのテスト * * - Factoryを正常に登録できるか? */ void test_registerFactory() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); } /*! * @brief registerECFactory() * * - 正常にECFactoryを登録できるか? */ void test_registerECFactory() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // 正常にECFactoryを登録できるか? CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 登録済みのECFactoryと同一の名称で登録を試みた場合、意図どおり登録失敗するか? CPPUNIT_ASSERT(! m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); } /*! * @brief getModulesFactories()メソッドのテスト * * - 登録されているFactoryの("implementation_id"プロパティの)リストを正しく取得できるか? */ void test_getModulesFactories() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // 複数のFactoryを登録しておく coil::Properties properties1; properties1.setProperty("implementation_id", "ID 1"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties1, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); coil::Properties properties2; properties2.setProperty("implementation_id", "ID 2"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties2, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // 登録されているFactoryの("implementation_id"プロパティの)リストを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(3, (int) m_mgr->getModulesFactories().size()); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID 1")); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID 2")); } /*! * @brief createComponent()メソッドのテスト(DataFlowComponentの場合) * * - 正しくコンポーネントを生成できるか? */ void test_createComponent_DataFlowComponent() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), // ※末尾の0はNumberingPolicyにより付加される std::string(comp->getInstanceName())); // コンポーネントに、意図どおりExecutionContextがアタッチされているか? RTC::ExecutionContextList* ecList = comp->get_owned_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length()); // 生成されたコンポーネントは、正しくネームサービスに登録されているか? // ※fixture4.confの各設定に合わせている点に注意 RTC::NamingManager nmgr(m_mgr); const char* name_server = "localhost:2809"; nmgr.registerNameServer("corba", name_server); CPPUNIT_ASSERT(canResolve(name_server, "DataFlowComponent0", "rtc")); comp->exit(); m_mgr->terminate(); } void test_createComponent_Non_DataFlowComponent() { // 現時点では、Manager側がDataFlowComponentのみに対応しているため、テスト省略する } /*! * @brief createComponent()メソッドのテスト * * - 登録されていないモジュール名を指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? * - モジュール名にNULLを指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? */ void test_createComponent_with_illegal_module_name() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 登録されていないモジュール名を指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp1 = m_mgr->createComponent("illegal_module_name"); CPPUNIT_ASSERT(comp1 == NULL); // モジュール名にNULLを指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp2 = m_mgr->createComponent(NULL); CPPUNIT_ASSERT(comp2 == NULL); } void test_createComponent_failed_in_bindExecutionContext() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // bindExecutionContext()で失敗するように、意図的にECFactoryを登録せずにおく // コンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp == NULL); m_mgr->terminate(); coil::usleep(3000000); } /*! * @brief cleanupComponent()メソッドのテスト * * - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? * - 登録したコンポーネントが、Managerから正しく登録解除されるか? */ void test_cleanupComponent() { // 初期化を行う // int argc = 1; // char* argv[] = { "-f fixture4.conf" }; int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 確認用にネームサービスへのアクセス手段としてNamingManagerを準備しておく // ※fixture4.confの各設定に合わせている点に注意 RTC::NamingManager nmgr(m_mgr); const char* name_server = "localhost:2809"; nmgr.registerNameServer("corba", name_server); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), // ※末尾の0はNumberingPolicyにより付加される std::string(comp->getInstanceName())); // コンポーネントに、意図どおりExecutionContextがアタッチされているか? RTC::ExecutionContextList* ecList = comp->get_owned_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length()); // cleanupComponent()により、正しく登録解除されるか? // - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? // - 登録したコンポーネントが、Managerから正しく登録解除されるか? CPPUNIT_ASSERT(!canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT_EQUAL(comp, m_mgr->getComponent("DataFlowComponent0")); m_mgr->cleanupComponent(comp); CPPUNIT_ASSERT(! canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); comp->exit(); usleep(10000); m_mgr->terminate(); } void test_unregisterComponent() { // Manager::cleanupComponent()内で使用されているので、ここではテスト省略する } void test_bindExecutionContext() { // Manager::createComponent()内で使用されているので、ここではテスト省略する } void test_getComponent() { // 他テスト内で使用されているので、そちらで兼ねるものとして、ここではテスト省略する } /*! * @brief getComponents()メソッドのテスト * * - getComponents()で、生成したすべてのコンポーネントを取得できるか? * - 登録解除したコンポーネントが、正しく一覧から除外されているか? */ void test_getComponents() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 複数のコンポーネントを生成しておく RTC::RtcBase* comp1 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp1 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp1) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp1->_this())); RTC::RtcBase* comp2 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp2 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp2) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp2->_this())); CPPUNIT_ASSERT(comp1 != comp2); // getComponents()で、生成したすべてのコンポーネントを取得できるか? std::vector<RTC::RtcBase*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT_EQUAL(2, (int) comps.size()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) != comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); // コンポーネントを1つだけ登録解除した場合、解除したものが一覧から除外されているか? m_mgr->cleanupComponent(comp1); comps = m_mgr->getComponents(); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) == comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); comp1->exit(); comp2->exit(); m_mgr->terminate(); } void test_getORB() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOA() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOAManager() { // 他テスト内で使用されているので、ここではテスト省略する } /*! * @brief initFactories()メソッドのテスト * * - init()実行後、initFactories()の実行結果としてFactoryMapに正しく登録されているか? */ void test_initFactories() { // init()の中でinitFactories()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initFactories()の実行結果としてFactoryMapに正しく登録されているか? bool bret = RTC::CdrBufferFactory::instance().hasFactory("ring_buffer"); CPPUNIT_ASSERT(bret); bret = RTC::PeriodicTaskFactory::instance().hasFactory("default"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("flush"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("new"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("periodic"); CPPUNIT_ASSERT(bret); RTC::InPortProviderFactory& factory1(RTC::InPortProviderFactory::instance()); bret = factory1.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::InPortConsumerFactory& factory2(RTC::InPortConsumerFactory::instance()); bret = factory2.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortConsumerFactory& factory3(RTC::OutPortConsumerFactory::instance()); bret = factory3.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortProviderFactory& factory4(RTC::OutPortProviderFactory::instance()); bret = factory4.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); } /*! * @brief initComposite()メソッドのテスト * * - init()実行後、initComposite()の実行結果としてFactoryManagerに正しく登録されているか? */ void test_initComposite() { // init()の中でinitComposite()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initComposite()の実行結果としてFactoryManagerに正しく登録されているか? // "implementation_id"には, "PeriodicECSharedComposite"が設定されている CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "PeriodicECSharedComposite")); } /*! * @brief procContextArgs()メソッドのテスト * * - 引数ec_argsにより戻り値true・falseが正しく返却されるか? */ void test_procContextArgs() { std::string ec_args; std::string ec_id; coil::Properties ec_prop; // インスタンス生成 ManagerTestMock* man = new ManagerTestMock(); // falseを返すケース1:ec_args.size=0 ec_args = ""; bool bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース2:ec_args.size=3 ec_args = "periodic?rate=1000?policy=skip"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース3:ec_args[0].empty ec_args = "?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // trueを返すケース4:ec_args.size=2 ec_args = "periodic?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(bret); std::string chk_val("periodic"); CPPUNIT_ASSERT_EQUAL(chk_val, ec_id); chk_val = "1000"; CPPUNIT_ASSERT_EQUAL(chk_val, ec_prop["rate"]); delete man; } /*! * @brief getLogLevel()メソッドのテスト * * - log_levelが正しく返却されるか? */ void test_getLogLevel() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); std::string log_level = m_mgr->getLogLevel(); CPPUNIT_ASSERT_EQUAL(std::string("INFO"), log_level); } /*! * @brief getLoadedModules()メソッドのテスト * * - ロード済みのモジュールリストを正しく取得できるか? */ void test_getLoadedModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); /* FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード済みのモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadedModules(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string(".//./.libs/DummyModule.so"), props[0].getProperty("file_path")); */ } /*! * @brief getFactoryProfiles()メソッドのテスト * * - RTコンポーネント用ファクトリをリストを正しく取得できるか? */ void test_getFactoryProfiles() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); std::vector<coil::Properties> props = m_mgr->getFactoryProfiles(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string("PeriodicECSharedComposite"), props[0].getProperty("implementation_id")); CPPUNIT_ASSERT_EQUAL(std::string("ID"), props[1].getProperty("implementation_id")); } /*! * @brief createContext()メソッドのテスト * * - ExecutionContextBaseを正しく取得できるか? */ void test_createContext() { RTC::ExecutionContextBase* ec; std::string ec_args; m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // return NULL check ec_args = ""; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return NULL check (Factory not found) ec_args = "periodic?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return any check m_mgr->registerECFactory("PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>); ec_args = "PeriodicEC?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec != NULL); } /*! * @brief deleteComponent()メソッドのテスト * * - RTコンポーネントの削除が正しくできるか? */ void test_deleteComponent() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), std::string(comp->getInstanceName())); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") != NULL); std::vector<RTC::RTObject_impl*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT(comps.size() > 0); // 正しくコンポーネントを削除できるか? m_mgr->deleteComponent("DataFlowComponent0"); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); // deleteComponent()でexit()を実行しているため、これ以降のテストはできません。 } /*! * @brief init()、shutdown()から呼ばれるprotected関数のテスト * * - protected関数が正しく動作しているか? */ void test_init2() { // Manager::init()よりprotected関数が使用されているので、ここではテスト省略する // initManager() // initLogger() // initORB() // initNaming() // initFactories() // initExecContext() // initComposite() // initTimer() // initManagerServant() // Manager::shutdown()よりprotected関数が使用されているので、ここではテスト省略する // shutdownComponents(); // shutdownNaming(); // shutdownORB(); // shutdownManager(); // shutdownLogger(); } }; }; // namespace Tests /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(Tests::ManagerTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // ManagerTests_cpp
675  CPPUNIT_ASSERT(m_mgr->activateManager());
676  CPPUNIT_ASSERT_EQUAL(0, logger.countLog("initialize"));
677  {
678  InvokerMock invoker(rtoRef, m_mgr);
679  m_mgr->runManager(false); // true:非ブロッキング,false:ブロッキング
680  coil::sleep(3);
681  }
682  CPPUNIT_ASSERT_EQUAL(1, logger.countLog("initialize"));
683 
684  poa->deactivate_object(rtoId);
685  delete rto;
686  }
687 
689  : public coil::Task
690  {
691  public:
692  InvokerMock(const RTC::DataFlowComponent_ptr& rtoRef, RTC::Manager* mgr)
693  {
694  m_rtoRef = RTC::DataFlowComponent::_duplicate(rtoRef);
695  m_mgr = mgr;
696  activate();
697  }
698 
700  {
701  wait();
702  }
703 
704  virtual int svc(void)
705  {
706  m_rtoRef->initialize();
707  coil::sleep(1);
708 
709  // ブロックされているrunManager呼出をブロック解除する m_rtoRef->exit(); m_mgr->shutdown(); m_mgr->join(); return 0; } private: RTC::DataFlowComponent_ptr m_rtoRef; RTC::Manager* m_mgr; }; /*! * @brief load()メソッドのテスト * * - 指定したモジュールをロードして、指定の初期化関数が正しく呼び出されるか? */ void test_load() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア // モジュールロードにより、指定した初期化関数が呼び出されるか? CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); // std::string moduleName = m_mgr->load("DummyModule.so", "InitProc"); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName)); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount)()); } /*! * @brief unload()メソッドのテスト * * - いったんloadしたモジュールを、正しくunloadできるか? */ void test_unload() { // 初期化を行う int argc = 1; char* argv[] = { "-f fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア // いったんloadしておく CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // std::string moduleName = m_mgr->load("DummyModule.so", "InitProc"); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName)); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount)()); // いったんloadしたモジュールを、正しくunloadできるか? // m_mgr->unload(moduleName.c_str()); // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName)); } /*! * @brief unloadAll()メソッドのテスト * * - unloadAll()により、ロードしたモジュールがすべてアンロードされるか? */ void test_unloadAll() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader1("./.libs/DummyModule.so"); coil::DynamicLib loader2("./.libs/DummyModule2.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount1 = (FUNC_GETINITPROCCOUNT) loader1.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount1 != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount1 = (FUNC_RESETINITPROCCOUNT) loader1.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount1 != NULL); FUNC_GETINITPROCCOUNT pGetInitProcCount2 = (FUNC_GETINITPROCCOUNT) loader2.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount2 != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount2 = (FUNC_RESETINITPROCCOUNT) loader2.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount2 != NULL); (*pResetInitProcCount1)(); // カウンタクリア (*pResetInitProcCount2)(); // カウンタクリア // いったんloadしておく CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount1)()); CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount2)()); // std::string moduleName1 = m_mgr->load("DummyModule.so", "InitProc"); // std::string moduleName2 = m_mgr->load("DummyModule2.so", "InitProc"); m_mgr->load("./.libs/DummyModule.so", "InitProc"); m_mgr->load("./.libs/DummyModule2.so", "InitProc"); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName1)); // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName2)); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount1)()); // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount2)()); // unloadAll()により、ロードしたモジュールがすべてアンロードされるか? m_mgr->unloadAll(); // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName1)); // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName2)); } /*! * @brief getLoadableModules()メソッドのテスト * * - ロード可能なモジュールリストを正しく取得できるか? */ void test_getLoadableModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード可能なモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadableModules(); CPPUNIT_ASSERT(props.size() > 0); //for(int i=0;i<props.size(); ++i) //{ // std::cout << "--------------- props[" << i << "] dump ---------------" << std::endl; // props[i].list(std::cout); //} CPPUNIT_ASSERT_EQUAL(std::string("./.libs/DummyModule2.so"), props[0].getProperty("module_file_path")); } /*! * @brief registerFactory()メソッドのテスト * * - Factoryを正常に登録できるか? */ void test_registerFactory() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); } /*! * @brief registerECFactory() * * - 正常にECFactoryを登録できるか? */ void test_registerECFactory() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // 正常にECFactoryを登録できるか? CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 登録済みのECFactoryと同一の名称で登録を試みた場合、意図どおり登録失敗するか? CPPUNIT_ASSERT(! m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); } /*! * @brief getModulesFactories()メソッドのテスト * * - 登録されているFactoryの("implementation_id"プロパティの)リストを正しく取得できるか? */ void test_getModulesFactories() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // 複数のFactoryを登録しておく coil::Properties properties1; properties1.setProperty("implementation_id", "ID 1"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties1, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); coil::Properties properties2; properties2.setProperty("implementation_id", "ID 2"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties2, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // 登録されているFactoryの("implementation_id"プロパティの)リストを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(3, (int) m_mgr->getModulesFactories().size()); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID 1")); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID 2")); } /*! * @brief createComponent()メソッドのテスト(DataFlowComponentの場合) * * - 正しくコンポーネントを生成できるか? */ void test_createComponent_DataFlowComponent() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), // ※末尾の0はNumberingPolicyにより付加される std::string(comp->getInstanceName())); // コンポーネントに、意図どおりExecutionContextがアタッチされているか? RTC::ExecutionContextList* ecList = comp->get_owned_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length()); // 生成されたコンポーネントは、正しくネームサービスに登録されているか? // ※fixture4.confの各設定に合わせている点に注意 RTC::NamingManager nmgr(m_mgr); const char* name_server = "localhost:2809"; nmgr.registerNameServer("corba", name_server); CPPUNIT_ASSERT(canResolve(name_server, "DataFlowComponent0", "rtc")); comp->exit(); m_mgr->terminate(); } void test_createComponent_Non_DataFlowComponent() { // 現時点では、Manager側がDataFlowComponentのみに対応しているため、テスト省略する } /*! * @brief createComponent()メソッドのテスト * * - 登録されていないモジュール名を指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? * - モジュール名にNULLを指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? */ void test_createComponent_with_illegal_module_name() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 登録されていないモジュール名を指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp1 = m_mgr->createComponent("illegal_module_name"); CPPUNIT_ASSERT(comp1 == NULL); // モジュール名にNULLを指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp2 = m_mgr->createComponent(NULL); CPPUNIT_ASSERT(comp2 == NULL); } void test_createComponent_failed_in_bindExecutionContext() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // bindExecutionContext()で失敗するように、意図的にECFactoryを登録せずにおく // コンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp == NULL); m_mgr->terminate(); coil::usleep(3000000); } /*! * @brief cleanupComponent()メソッドのテスト * * - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? * - 登録したコンポーネントが、Managerから正しく登録解除されるか? */ void test_cleanupComponent() { // 初期化を行う // int argc = 1; // char* argv[] = { "-f fixture4.conf" }; int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 確認用にネームサービスへのアクセス手段としてNamingManagerを準備しておく // ※fixture4.confの各設定に合わせている点に注意 RTC::NamingManager nmgr(m_mgr); const char* name_server = "localhost:2809"; nmgr.registerNameServer("corba", name_server); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), // ※末尾の0はNumberingPolicyにより付加される std::string(comp->getInstanceName())); // コンポーネントに、意図どおりExecutionContextがアタッチされているか? RTC::ExecutionContextList* ecList = comp->get_owned_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length()); // cleanupComponent()により、正しく登録解除されるか? // - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? // - 登録したコンポーネントが、Managerから正しく登録解除されるか? CPPUNIT_ASSERT(!canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT_EQUAL(comp, m_mgr->getComponent("DataFlowComponent0")); m_mgr->cleanupComponent(comp); CPPUNIT_ASSERT(! canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); comp->exit(); usleep(10000); m_mgr->terminate(); } void test_unregisterComponent() { // Manager::cleanupComponent()内で使用されているので、ここではテスト省略する } void test_bindExecutionContext() { // Manager::createComponent()内で使用されているので、ここではテスト省略する } void test_getComponent() { // 他テスト内で使用されているので、そちらで兼ねるものとして、ここではテスト省略する } /*! * @brief getComponents()メソッドのテスト * * - getComponents()で、生成したすべてのコンポーネントを取得できるか? * - 登録解除したコンポーネントが、正しく一覧から除外されているか? */ void test_getComponents() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 複数のコンポーネントを生成しておく RTC::RtcBase* comp1 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp1 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp1) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp1->_this())); RTC::RtcBase* comp2 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp2 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp2) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp2->_this())); CPPUNIT_ASSERT(comp1 != comp2); // getComponents()で、生成したすべてのコンポーネントを取得できるか? std::vector<RTC::RtcBase*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT_EQUAL(2, (int) comps.size()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) != comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); // コンポーネントを1つだけ登録解除した場合、解除したものが一覧から除外されているか? m_mgr->cleanupComponent(comp1); comps = m_mgr->getComponents(); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) == comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); comp1->exit(); comp2->exit(); m_mgr->terminate(); } void test_getORB() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOA() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOAManager() { // 他テスト内で使用されているので、ここではテスト省略する } /*! * @brief initFactories()メソッドのテスト * * - init()実行後、initFactories()の実行結果としてFactoryMapに正しく登録されているか? */ void test_initFactories() { // init()の中でinitFactories()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initFactories()の実行結果としてFactoryMapに正しく登録されているか? bool bret = RTC::CdrBufferFactory::instance().hasFactory("ring_buffer"); CPPUNIT_ASSERT(bret); bret = RTC::PeriodicTaskFactory::instance().hasFactory("default"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("flush"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("new"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("periodic"); CPPUNIT_ASSERT(bret); RTC::InPortProviderFactory& factory1(RTC::InPortProviderFactory::instance()); bret = factory1.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::InPortConsumerFactory& factory2(RTC::InPortConsumerFactory::instance()); bret = factory2.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortConsumerFactory& factory3(RTC::OutPortConsumerFactory::instance()); bret = factory3.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortProviderFactory& factory4(RTC::OutPortProviderFactory::instance()); bret = factory4.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); } /*! * @brief initComposite()メソッドのテスト * * - init()実行後、initComposite()の実行結果としてFactoryManagerに正しく登録されているか? */ void test_initComposite() { // init()の中でinitComposite()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initComposite()の実行結果としてFactoryManagerに正しく登録されているか? // "implementation_id"には, "PeriodicECSharedComposite"が設定されている CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "PeriodicECSharedComposite")); } /*! * @brief procContextArgs()メソッドのテスト * * - 引数ec_argsにより戻り値true・falseが正しく返却されるか? */ void test_procContextArgs() { std::string ec_args; std::string ec_id; coil::Properties ec_prop; // インスタンス生成 ManagerTestMock* man = new ManagerTestMock(); // falseを返すケース1:ec_args.size=0 ec_args = ""; bool bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース2:ec_args.size=3 ec_args = "periodic?rate=1000?policy=skip"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース3:ec_args[0].empty ec_args = "?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // trueを返すケース4:ec_args.size=2 ec_args = "periodic?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(bret); std::string chk_val("periodic"); CPPUNIT_ASSERT_EQUAL(chk_val, ec_id); chk_val = "1000"; CPPUNIT_ASSERT_EQUAL(chk_val, ec_prop["rate"]); delete man; } /*! * @brief getLogLevel()メソッドのテスト * * - log_levelが正しく返却されるか? */ void test_getLogLevel() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); std::string log_level = m_mgr->getLogLevel(); CPPUNIT_ASSERT_EQUAL(std::string("INFO"), log_level); } /*! * @brief getLoadedModules()メソッドのテスト * * - ロード済みのモジュールリストを正しく取得できるか? */ void test_getLoadedModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); /* FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード済みのモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadedModules(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string(".//./.libs/DummyModule.so"), props[0].getProperty("file_path")); */ } /*! * @brief getFactoryProfiles()メソッドのテスト * * - RTコンポーネント用ファクトリをリストを正しく取得できるか? */ void test_getFactoryProfiles() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); std::vector<coil::Properties> props = m_mgr->getFactoryProfiles(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string("PeriodicECSharedComposite"), props[0].getProperty("implementation_id")); CPPUNIT_ASSERT_EQUAL(std::string("ID"), props[1].getProperty("implementation_id")); } /*! * @brief createContext()メソッドのテスト * * - ExecutionContextBaseを正しく取得できるか? */ void test_createContext() { RTC::ExecutionContextBase* ec; std::string ec_args; m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // return NULL check ec_args = ""; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return NULL check (Factory not found) ec_args = "periodic?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return any check m_mgr->registerECFactory("PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>); ec_args = "PeriodicEC?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec != NULL); } /*! * @brief deleteComponent()メソッドのテスト * * - RTコンポーネントの削除が正しくできるか? */ void test_deleteComponent() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), std::string(comp->getInstanceName())); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") != NULL); std::vector<RTC::RTObject_impl*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT(comps.size() > 0); // 正しくコンポーネントを削除できるか? m_mgr->deleteComponent("DataFlowComponent0"); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); // deleteComponent()でexit()を実行しているため、これ以降のテストはできません。 } /*! * @brief init()、shutdown()から呼ばれるprotected関数のテスト * * - protected関数が正しく動作しているか? */ void test_init2() { // Manager::init()よりprotected関数が使用されているので、ここではテスト省略する // initManager() // initLogger() // initORB() // initNaming() // initFactories() // initExecContext() // initComposite() // initTimer() // initManagerServant() // Manager::shutdown()よりprotected関数が使用されているので、ここではテスト省略する // shutdownComponents(); // shutdownNaming(); // shutdownORB(); // shutdownManager(); // shutdownLogger(); } }; }; // namespace Tests /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(Tests::ManagerTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // ManagerTests_cpp
710  m_rtoRef->exit();
711  m_mgr->shutdown();
712  m_mgr->join();
713 
714  return 0;
715  }
716 
717  private:
718  RTC::DataFlowComponent_ptr m_rtoRef;
720  };
721 
727  void test_load()
728  {
729  // 初期化を行う
730  int argc = 3;
731  char* argv[] = { "ManagerTests","-f","fixture3.conf" };
732 
733  m_mgr = RTC::Manager::init(argc, argv);
734  CPPUNIT_ASSERT(m_mgr != NULL);
735 
736  // Managerとは別に、確認用にモジュールへのシンボルを取得しておく
737  typedef int (*FUNC_GETINITPROCCOUNT)();
738  typedef void (*FUNC_RESETINITPROCCOUNT)();
739  coil::DynamicLib loader("./.libs/DummyModule.so");
740 
741  FUNC_GETINITPROCCOUNT pGetInitProcCount
742  = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount");
743  CPPUNIT_ASSERT(pGetInitProcCount != NULL);
744 
745  FUNC_RESETINITPROCCOUNT pResetInitProcCount
746  = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount");
747  CPPUNIT_ASSERT(pResetInitProcCount != NULL);
748 
749  (*pResetInitProcCount)(); // カウンタクリア
750 
751  // モジュールロードにより、指定した初期化関数が呼び出されるか?
752  CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)());
753  // std::string moduleName = m_mgr->load("DummyModule.so", "InitProc");
754  m_mgr->load("./.libs/DummyModule.so", "InitProc");
755  // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName));
756  // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount)());
757 
758  }
759 
765  void test_unload()
766  {
767  // 初期化を行う
768  int argc = 1;
769  char* argv[] = { "-f fixture3.conf" };
770 
771  m_mgr = RTC::Manager::init(argc, argv);
772  CPPUNIT_ASSERT(m_mgr != NULL);
773 
774  // Managerとは別に、確認用にモジュールへのシンボルを取得しておく
775  typedef int (*FUNC_GETINITPROCCOUNT)();
776  typedef void (*FUNC_RESETINITPROCCOUNT)();
777  coil::DynamicLib loader("./.libs/DummyModule.so");
778 
779  FUNC_GETINITPROCCOUNT pGetInitProcCount
780  = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount");
781  CPPUNIT_ASSERT(pGetInitProcCount != NULL);
782 
783  FUNC_RESETINITPROCCOUNT pResetInitProcCount
784  = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount");
785  CPPUNIT_ASSERT(pResetInitProcCount != NULL);
786 
787  (*pResetInitProcCount)(); // カウンタクリア
788 
789  // いったんloadしておく
790  CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)());
791  m_mgr->load("./.libs/DummyModule.so", "InitProc");
792  // std::string moduleName = m_mgr->load("DummyModule.so", "InitProc");
793  // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName));
794  // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount)());
795 
796  // いったんloadしたモジュールを、正しくunloadできるか?
797  // m_mgr->unload(moduleName.c_str());
798  // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName));
799  }
800 
807  {
808  // 初期化を行う
809  int argc = 3;
810  char* argv[] = { "ManagerTests","-f","fixture3.conf" };
811 
812  m_mgr = RTC::Manager::init(argc, argv);
813  CPPUNIT_ASSERT(m_mgr != NULL);
814 
815  // Managerとは別に、確認用にモジュールへのシンボルを取得しておく
816  typedef int (*FUNC_GETINITPROCCOUNT)();
817  typedef void (*FUNC_RESETINITPROCCOUNT)();
818 
819  coil::DynamicLib loader1("./.libs/DummyModule.so");
820  coil::DynamicLib loader2("./.libs/DummyModule2.so");
821 
822  FUNC_GETINITPROCCOUNT pGetInitProcCount1
823  = (FUNC_GETINITPROCCOUNT) loader1.symbol("getInitProcCount");
824  CPPUNIT_ASSERT(pGetInitProcCount1 != NULL);
825 
826  FUNC_RESETINITPROCCOUNT pResetInitProcCount1
827  = (FUNC_RESETINITPROCCOUNT) loader1.symbol("resetInitProcCount");
828  CPPUNIT_ASSERT(pResetInitProcCount1 != NULL);
829 
830  FUNC_GETINITPROCCOUNT pGetInitProcCount2
831  = (FUNC_GETINITPROCCOUNT) loader2.symbol("getInitProcCount");
832  CPPUNIT_ASSERT(pGetInitProcCount2 != NULL);
833 
834  FUNC_RESETINITPROCCOUNT pResetInitProcCount2
835  = (FUNC_RESETINITPROCCOUNT) loader2.symbol("resetInitProcCount");
836  CPPUNIT_ASSERT(pResetInitProcCount2 != NULL);
837 
838  (*pResetInitProcCount1)(); // カウンタクリア
839  (*pResetInitProcCount2)(); // カウンタクリア
840 
841  // いったんloadしておく
842  CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount1)());
843  CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount2)());
844 
845  // std::string moduleName1 = m_mgr->load("DummyModule.so", "InitProc");
846  // std::string moduleName2 = m_mgr->load("DummyModule2.so", "InitProc");
847  m_mgr->load("./.libs/DummyModule.so", "InitProc");
848  m_mgr->load("./.libs/DummyModule2.so", "InitProc");
849 
850  // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName1));
851  // CPPUNIT_ASSERT(isFound(m_mgr->getLoadedModules(), moduleName2));
852 
853  // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount1)());
854  // CPPUNIT_ASSERT_EQUAL(1, (*pGetInitProcCount2)());
855 
856  // unloadAll()により、ロードしたモジュールがすべてアンロードされるか?
857  m_mgr->unloadAll();
858  // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName1));
859  // CPPUNIT_ASSERT(! isFound(m_mgr->getLoadedModules(), moduleName2));
860  }
861 
868  {
869  int argc = 3;
870  char* argv[] = { "ManagerTests","-f","fixture3.conf" };
871 
872  m_mgr = RTC::Manager::init(argc, argv);
873  CPPUNIT_ASSERT(m_mgr != NULL);
874 
875  // Managerとは別に、確認用にモジュールへのシンボルを取得しておく
876  typedef int (*FUNC_GETINITPROCCOUNT)();
877  typedef void (*FUNC_RESETINITPROCCOUNT)();
878  coil::DynamicLib loader("./.libs/DummyModule.so");
879 
880  FUNC_GETINITPROCCOUNT pGetInitProcCount
881  = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount");
882  CPPUNIT_ASSERT(pGetInitProcCount != NULL);
883 
884  FUNC_RESETINITPROCCOUNT pResetInitProcCount
885  = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount");
886  CPPUNIT_ASSERT(pResetInitProcCount != NULL);
887 
888  (*pResetInitProcCount)(); // カウンタクリア
889 
890  CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)());
891  m_mgr->load("./.libs/DummyModule.so", "InitProc");
892 
893  // ロード可能なモジュールリストを正しく取得できるか?
894  std::vector<coil::Properties> props = m_mgr->getLoadableModules();
895  CPPUNIT_ASSERT(props.size() > 0);
896 
897  //for(int i=0;i<props.size(); ++i)
898  //{
899  // std::cout << "--------------- props[" << i << "] dump ---------------" << std::endl;
900  // props[i].list(std::cout);
901  //}
902  CPPUNIT_ASSERT_EQUAL(std::string("./.libs/DummyModule2.so"),
903  props[0].getProperty("module_file_path"));
904  }
905 
912  {
913  // 初期化を行う
914  int argc = 0;
915  char* argv[] = {};
916 
917  m_mgr = RTC::Manager::init(argc, argv);
918  CPPUNIT_ASSERT(m_mgr != NULL);
919 
920  // Factoryを正常に登録できるか?
921  coil::Properties properties;
922  properties.setProperty("implementation_id", "ID");
923 
924  CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID"));
925  CPPUNIT_ASSERT(m_mgr->registerFactory(
927  CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID"));
928  }
929 
936  {
937  // 初期化を行う
938  int argc = 0;
939  char* argv[] = {};
940 
941  m_mgr = RTC::Manager::init(argc, argv);
942  CPPUNIT_ASSERT(m_mgr != NULL);
943 
944  // 正常にECFactoryを登録できるか?
945  CPPUNIT_ASSERT(m_mgr->registerECFactory(
946  "PeriodicEC",
947  RTC::ECCreate<RTC::PeriodicExecutionContext>,
948  RTC::ECDelete<RTC::PeriodicExecutionContext>));
949 
950  // 登録済みのECFactoryと同一の名称で登録を試みた場合、意図どおり登録失敗するか?
951  CPPUNIT_ASSERT(! m_mgr->registerECFactory(
952  "PeriodicEC",
953  RTC::ECCreate<RTC::PeriodicExecutionContext>,
954  RTC::ECDelete<RTC::PeriodicExecutionContext>));
955  }
956 
963  {
964  // 初期化を行う
965  int argc = 0;
966  char* argv[] = {};
967 
968  m_mgr = RTC::Manager::init(argc, argv);
969  CPPUNIT_ASSERT(m_mgr != NULL);
970 
971  // 複数のFactoryを登録しておく
972  coil::Properties properties1;
973  properties1.setProperty("implementation_id", "ID 1");
974  CPPUNIT_ASSERT(m_mgr->registerFactory(
976 
977  coil::Properties properties2;
978  properties2.setProperty("implementation_id", "ID 2");
979  CPPUNIT_ASSERT(m_mgr->registerFactory(
981 
982  // 登録されているFactoryの("implementation_id"プロパティの)リストを正しく取得できるか?
983  CPPUNIT_ASSERT_EQUAL(3, (int) m_mgr->getModulesFactories().size());
984  CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID 1"));
985  CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID 2"));
986 
987  }
988 
995  {
996  // 初期化を行う
997  int argc = 3;
998  char* argv[] = { "ManagerTests","-f","fixture4.conf" };
999 
1000  m_mgr = RTC::Manager::init(argc, argv);
1001  CPPUNIT_ASSERT(m_mgr != NULL);
1002  CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB()));
1003  CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA()));
1004  CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager()));
1005 
1006  // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), // ※末尾の0はNumberingPolicyにより付加される std::string(comp->getInstanceName())); // コンポーネントに、意図どおりExecutionContextがアタッチされているか? RTC::ExecutionContextList* ecList = comp->get_owned_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length()); // 生成されたコンポーネントは、正しくネームサービスに登録されているか? // ※fixture4.confの各設定に合わせている点に注意 RTC::NamingManager nmgr(m_mgr); const char* name_server = "localhost:2809"; nmgr.registerNameServer("corba", name_server); CPPUNIT_ASSERT(canResolve(name_server, "DataFlowComponent0", "rtc")); comp->exit(); m_mgr->terminate(); } void test_createComponent_Non_DataFlowComponent() { // 現時点では、Manager側がDataFlowComponentのみに対応しているため、テスト省略する } /*! * @brief createComponent()メソッドのテスト * * - 登録されていないモジュール名を指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? * - モジュール名にNULLを指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? */ void test_createComponent_with_illegal_module_name() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 登録されていないモジュール名を指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp1 = m_mgr->createComponent("illegal_module_name"); CPPUNIT_ASSERT(comp1 == NULL); // モジュール名にNULLを指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp2 = m_mgr->createComponent(NULL); CPPUNIT_ASSERT(comp2 == NULL); } void test_createComponent_failed_in_bindExecutionContext() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // bindExecutionContext()で失敗するように、意図的にECFactoryを登録せずにおく // コンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp == NULL); m_mgr->terminate(); coil::usleep(3000000); } /*! * @brief cleanupComponent()メソッドのテスト * * - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? * - 登録したコンポーネントが、Managerから正しく登録解除されるか? */ void test_cleanupComponent() { // 初期化を行う // int argc = 1; // char* argv[] = { "-f fixture4.conf" }; int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 確認用にネームサービスへのアクセス手段としてNamingManagerを準備しておく // ※fixture4.confの各設定に合わせている点に注意 RTC::NamingManager nmgr(m_mgr); const char* name_server = "localhost:2809"; nmgr.registerNameServer("corba", name_server); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), // ※末尾の0はNumberingPolicyにより付加される std::string(comp->getInstanceName())); // コンポーネントに、意図どおりExecutionContextがアタッチされているか? RTC::ExecutionContextList* ecList = comp->get_owned_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length()); // cleanupComponent()により、正しく登録解除されるか? // - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? // - 登録したコンポーネントが、Managerから正しく登録解除されるか? CPPUNIT_ASSERT(!canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT_EQUAL(comp, m_mgr->getComponent("DataFlowComponent0")); m_mgr->cleanupComponent(comp); CPPUNIT_ASSERT(! canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); comp->exit(); usleep(10000); m_mgr->terminate(); } void test_unregisterComponent() { // Manager::cleanupComponent()内で使用されているので、ここではテスト省略する } void test_bindExecutionContext() { // Manager::createComponent()内で使用されているので、ここではテスト省略する } void test_getComponent() { // 他テスト内で使用されているので、そちらで兼ねるものとして、ここではテスト省略する } /*! * @brief getComponents()メソッドのテスト * * - getComponents()で、生成したすべてのコンポーネントを取得できるか? * - 登録解除したコンポーネントが、正しく一覧から除外されているか? */ void test_getComponents() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 複数のコンポーネントを生成しておく RTC::RtcBase* comp1 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp1 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp1) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp1->_this())); RTC::RtcBase* comp2 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp2 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp2) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp2->_this())); CPPUNIT_ASSERT(comp1 != comp2); // getComponents()で、生成したすべてのコンポーネントを取得できるか? std::vector<RTC::RtcBase*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT_EQUAL(2, (int) comps.size()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) != comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); // コンポーネントを1つだけ登録解除した場合、解除したものが一覧から除外されているか? m_mgr->cleanupComponent(comp1); comps = m_mgr->getComponents(); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) == comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); comp1->exit(); comp2->exit(); m_mgr->terminate(); } void test_getORB() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOA() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOAManager() { // 他テスト内で使用されているので、ここではテスト省略する } /*! * @brief initFactories()メソッドのテスト * * - init()実行後、initFactories()の実行結果としてFactoryMapに正しく登録されているか? */ void test_initFactories() { // init()の中でinitFactories()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initFactories()の実行結果としてFactoryMapに正しく登録されているか? bool bret = RTC::CdrBufferFactory::instance().hasFactory("ring_buffer"); CPPUNIT_ASSERT(bret); bret = RTC::PeriodicTaskFactory::instance().hasFactory("default"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("flush"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("new"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("periodic"); CPPUNIT_ASSERT(bret); RTC::InPortProviderFactory& factory1(RTC::InPortProviderFactory::instance()); bret = factory1.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::InPortConsumerFactory& factory2(RTC::InPortConsumerFactory::instance()); bret = factory2.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortConsumerFactory& factory3(RTC::OutPortConsumerFactory::instance()); bret = factory3.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortProviderFactory& factory4(RTC::OutPortProviderFactory::instance()); bret = factory4.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); } /*! * @brief initComposite()メソッドのテスト * * - init()実行後、initComposite()の実行結果としてFactoryManagerに正しく登録されているか? */ void test_initComposite() { // init()の中でinitComposite()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initComposite()の実行結果としてFactoryManagerに正しく登録されているか? // "implementation_id"には, "PeriodicECSharedComposite"が設定されている CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "PeriodicECSharedComposite")); } /*! * @brief procContextArgs()メソッドのテスト * * - 引数ec_argsにより戻り値true・falseが正しく返却されるか? */ void test_procContextArgs() { std::string ec_args; std::string ec_id; coil::Properties ec_prop; // インスタンス生成 ManagerTestMock* man = new ManagerTestMock(); // falseを返すケース1:ec_args.size=0 ec_args = ""; bool bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース2:ec_args.size=3 ec_args = "periodic?rate=1000?policy=skip"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース3:ec_args[0].empty ec_args = "?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // trueを返すケース4:ec_args.size=2 ec_args = "periodic?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(bret); std::string chk_val("periodic"); CPPUNIT_ASSERT_EQUAL(chk_val, ec_id); chk_val = "1000"; CPPUNIT_ASSERT_EQUAL(chk_val, ec_prop["rate"]); delete man; } /*! * @brief getLogLevel()メソッドのテスト * * - log_levelが正しく返却されるか? */ void test_getLogLevel() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); std::string log_level = m_mgr->getLogLevel(); CPPUNIT_ASSERT_EQUAL(std::string("INFO"), log_level); } /*! * @brief getLoadedModules()メソッドのテスト * * - ロード済みのモジュールリストを正しく取得できるか? */ void test_getLoadedModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); /* FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード済みのモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadedModules(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string(".//./.libs/DummyModule.so"), props[0].getProperty("file_path")); */ } /*! * @brief getFactoryProfiles()メソッドのテスト * * - RTコンポーネント用ファクトリをリストを正しく取得できるか? */ void test_getFactoryProfiles() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); std::vector<coil::Properties> props = m_mgr->getFactoryProfiles(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string("PeriodicECSharedComposite"), props[0].getProperty("implementation_id")); CPPUNIT_ASSERT_EQUAL(std::string("ID"), props[1].getProperty("implementation_id")); } /*! * @brief createContext()メソッドのテスト * * - ExecutionContextBaseを正しく取得できるか? */ void test_createContext() { RTC::ExecutionContextBase* ec; std::string ec_args; m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // return NULL check ec_args = ""; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return NULL check (Factory not found) ec_args = "periodic?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return any check m_mgr->registerECFactory("PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>); ec_args = "PeriodicEC?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec != NULL); } /*! * @brief deleteComponent()メソッドのテスト * * - RTコンポーネントの削除が正しくできるか? */ void test_deleteComponent() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), std::string(comp->getInstanceName())); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") != NULL); std::vector<RTC::RTObject_impl*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT(comps.size() > 0); // 正しくコンポーネントを削除できるか? m_mgr->deleteComponent("DataFlowComponent0"); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); // deleteComponent()でexit()を実行しているため、これ以降のテストはできません。 } /*! * @brief init()、shutdown()から呼ばれるprotected関数のテスト * * - protected関数が正しく動作しているか? */ void test_init2() { // Manager::init()よりprotected関数が使用されているので、ここではテスト省略する // initManager() // initLogger() // initORB() // initNaming() // initFactories() // initExecContext() // initComposite() // initTimer() // initManagerServant() // Manager::shutdown()よりprotected関数が使用されているので、ここではテスト省略する // shutdownComponents(); // shutdownNaming(); // shutdownORB(); // shutdownManager(); // shutdownLogger(); } }; }; // namespace Tests /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(Tests::ManagerTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // ManagerTests_cpp
1007  CPPUNIT_ASSERT(m_mgr->activateManager());
1008  m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング
1009 
1010  // Factoryを登録しておく
1011  coil::Properties properties;
1012  properties.setProperty("implementation_id", "DataFlowComponentFactory");
1013  properties.setProperty("type_name", "DataFlowComponent");
1014  CPPUNIT_ASSERT(m_mgr->registerFactory(
1016 
1017  // ECFactoryを登録しておく
1018  CPPUNIT_ASSERT(m_mgr->registerECFactory(
1019  "PeriodicEC",
1020  RTC::ECCreate<RTC::PeriodicExecutionContext>,
1021  RTC::ECDelete<RTC::PeriodicExecutionContext>));
1022 
1023  // 正しくコンポーネントを生成できるか?
1024  RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory");
1025  CPPUNIT_ASSERT(comp != NULL);
1026  CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL);
1027  CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this()));
1028  CPPUNIT_ASSERT_EQUAL(
1029  std::string("DataFlowComponent0"), // ※末尾の0はNumberingPolicyにより付加される std::string(comp->getInstanceName())); // コンポーネントに、意図どおりExecutionContextがアタッチされているか? RTC::ExecutionContextList* ecList = comp->get_owned_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length()); // 生成されたコンポーネントは、正しくネームサービスに登録されているか? // ※fixture4.confの各設定に合わせている点に注意 RTC::NamingManager nmgr(m_mgr); const char* name_server = "localhost:2809"; nmgr.registerNameServer("corba", name_server); CPPUNIT_ASSERT(canResolve(name_server, "DataFlowComponent0", "rtc")); comp->exit(); m_mgr->terminate(); } void test_createComponent_Non_DataFlowComponent() { // 現時点では、Manager側がDataFlowComponentのみに対応しているため、テスト省略する } /*! * @brief createComponent()メソッドのテスト * * - 登録されていないモジュール名を指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? * - モジュール名にNULLを指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? */ void test_createComponent_with_illegal_module_name() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 登録されていないモジュール名を指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp1 = m_mgr->createComponent("illegal_module_name"); CPPUNIT_ASSERT(comp1 == NULL); // モジュール名にNULLを指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp2 = m_mgr->createComponent(NULL); CPPUNIT_ASSERT(comp2 == NULL); } void test_createComponent_failed_in_bindExecutionContext() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // bindExecutionContext()で失敗するように、意図的にECFactoryを登録せずにおく // コンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp == NULL); m_mgr->terminate(); coil::usleep(3000000); } /*! * @brief cleanupComponent()メソッドのテスト * * - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? * - 登録したコンポーネントが、Managerから正しく登録解除されるか? */ void test_cleanupComponent() { // 初期化を行う // int argc = 1; // char* argv[] = { "-f fixture4.conf" }; int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 確認用にネームサービスへのアクセス手段としてNamingManagerを準備しておく // ※fixture4.confの各設定に合わせている点に注意 RTC::NamingManager nmgr(m_mgr); const char* name_server = "localhost:2809"; nmgr.registerNameServer("corba", name_server); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), // ※末尾の0はNumberingPolicyにより付加される std::string(comp->getInstanceName())); // コンポーネントに、意図どおりExecutionContextがアタッチされているか? RTC::ExecutionContextList* ecList = comp->get_owned_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length()); // cleanupComponent()により、正しく登録解除されるか? // - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? // - 登録したコンポーネントが、Managerから正しく登録解除されるか? CPPUNIT_ASSERT(!canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT_EQUAL(comp, m_mgr->getComponent("DataFlowComponent0")); m_mgr->cleanupComponent(comp); CPPUNIT_ASSERT(! canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); comp->exit(); usleep(10000); m_mgr->terminate(); } void test_unregisterComponent() { // Manager::cleanupComponent()内で使用されているので、ここではテスト省略する } void test_bindExecutionContext() { // Manager::createComponent()内で使用されているので、ここではテスト省略する } void test_getComponent() { // 他テスト内で使用されているので、そちらで兼ねるものとして、ここではテスト省略する } /*! * @brief getComponents()メソッドのテスト * * - getComponents()で、生成したすべてのコンポーネントを取得できるか? * - 登録解除したコンポーネントが、正しく一覧から除外されているか? */ void test_getComponents() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 複数のコンポーネントを生成しておく RTC::RtcBase* comp1 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp1 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp1) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp1->_this())); RTC::RtcBase* comp2 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp2 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp2) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp2->_this())); CPPUNIT_ASSERT(comp1 != comp2); // getComponents()で、生成したすべてのコンポーネントを取得できるか? std::vector<RTC::RtcBase*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT_EQUAL(2, (int) comps.size()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) != comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); // コンポーネントを1つだけ登録解除した場合、解除したものが一覧から除外されているか? m_mgr->cleanupComponent(comp1); comps = m_mgr->getComponents(); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) == comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); comp1->exit(); comp2->exit(); m_mgr->terminate(); } void test_getORB() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOA() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOAManager() { // 他テスト内で使用されているので、ここではテスト省略する } /*! * @brief initFactories()メソッドのテスト * * - init()実行後、initFactories()の実行結果としてFactoryMapに正しく登録されているか? */ void test_initFactories() { // init()の中でinitFactories()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initFactories()の実行結果としてFactoryMapに正しく登録されているか? bool bret = RTC::CdrBufferFactory::instance().hasFactory("ring_buffer"); CPPUNIT_ASSERT(bret); bret = RTC::PeriodicTaskFactory::instance().hasFactory("default"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("flush"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("new"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("periodic"); CPPUNIT_ASSERT(bret); RTC::InPortProviderFactory& factory1(RTC::InPortProviderFactory::instance()); bret = factory1.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::InPortConsumerFactory& factory2(RTC::InPortConsumerFactory::instance()); bret = factory2.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortConsumerFactory& factory3(RTC::OutPortConsumerFactory::instance()); bret = factory3.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortProviderFactory& factory4(RTC::OutPortProviderFactory::instance()); bret = factory4.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); } /*! * @brief initComposite()メソッドのテスト * * - init()実行後、initComposite()の実行結果としてFactoryManagerに正しく登録されているか? */ void test_initComposite() { // init()の中でinitComposite()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initComposite()の実行結果としてFactoryManagerに正しく登録されているか? // "implementation_id"には, "PeriodicECSharedComposite"が設定されている CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "PeriodicECSharedComposite")); } /*! * @brief procContextArgs()メソッドのテスト * * - 引数ec_argsにより戻り値true・falseが正しく返却されるか? */ void test_procContextArgs() { std::string ec_args; std::string ec_id; coil::Properties ec_prop; // インスタンス生成 ManagerTestMock* man = new ManagerTestMock(); // falseを返すケース1:ec_args.size=0 ec_args = ""; bool bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース2:ec_args.size=3 ec_args = "periodic?rate=1000?policy=skip"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース3:ec_args[0].empty ec_args = "?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // trueを返すケース4:ec_args.size=2 ec_args = "periodic?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(bret); std::string chk_val("periodic"); CPPUNIT_ASSERT_EQUAL(chk_val, ec_id); chk_val = "1000"; CPPUNIT_ASSERT_EQUAL(chk_val, ec_prop["rate"]); delete man; } /*! * @brief getLogLevel()メソッドのテスト * * - log_levelが正しく返却されるか? */ void test_getLogLevel() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); std::string log_level = m_mgr->getLogLevel(); CPPUNIT_ASSERT_EQUAL(std::string("INFO"), log_level); } /*! * @brief getLoadedModules()メソッドのテスト * * - ロード済みのモジュールリストを正しく取得できるか? */ void test_getLoadedModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); /* FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード済みのモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadedModules(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string(".//./.libs/DummyModule.so"), props[0].getProperty("file_path")); */ } /*! * @brief getFactoryProfiles()メソッドのテスト * * - RTコンポーネント用ファクトリをリストを正しく取得できるか? */ void test_getFactoryProfiles() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); std::vector<coil::Properties> props = m_mgr->getFactoryProfiles(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string("PeriodicECSharedComposite"), props[0].getProperty("implementation_id")); CPPUNIT_ASSERT_EQUAL(std::string("ID"), props[1].getProperty("implementation_id")); } /*! * @brief createContext()メソッドのテスト * * - ExecutionContextBaseを正しく取得できるか? */ void test_createContext() { RTC::ExecutionContextBase* ec; std::string ec_args; m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // return NULL check ec_args = ""; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return NULL check (Factory not found) ec_args = "periodic?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return any check m_mgr->registerECFactory("PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>); ec_args = "PeriodicEC?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec != NULL); } /*! * @brief deleteComponent()メソッドのテスト * * - RTコンポーネントの削除が正しくできるか? */ void test_deleteComponent() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), std::string(comp->getInstanceName())); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") != NULL); std::vector<RTC::RTObject_impl*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT(comps.size() > 0); // 正しくコンポーネントを削除できるか? m_mgr->deleteComponent("DataFlowComponent0"); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); // deleteComponent()でexit()を実行しているため、これ以降のテストはできません。 } /*! * @brief init()、shutdown()から呼ばれるprotected関数のテスト * * - protected関数が正しく動作しているか? */ void test_init2() { // Manager::init()よりprotected関数が使用されているので、ここではテスト省略する // initManager() // initLogger() // initORB() // initNaming() // initFactories() // initExecContext() // initComposite() // initTimer() // initManagerServant() // Manager::shutdown()よりprotected関数が使用されているので、ここではテスト省略する // shutdownComponents(); // shutdownNaming(); // shutdownORB(); // shutdownManager(); // shutdownLogger(); } }; }; // namespace Tests /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(Tests::ManagerTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // ManagerTests_cpp
1030  std::string(comp->getInstanceName()));
1031 
1032  // コンポーネントに、意図どおりExecutionContextがアタッチされているか?
1033  RTC::ExecutionContextList* ecList = comp->get_owned_contexts();
1034  CPPUNIT_ASSERT(ecList != NULL);
1035  CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length());
1036 
1037  // 生成されたコンポーネントは、正しくネームサービスに登録されているか?
1038  // ※fixture4.confの各設定に合わせている点に注意 RTC::NamingManager nmgr(m_mgr); const char* name_server = "localhost:2809"; nmgr.registerNameServer("corba", name_server); CPPUNIT_ASSERT(canResolve(name_server, "DataFlowComponent0", "rtc")); comp->exit(); m_mgr->terminate(); } void test_createComponent_Non_DataFlowComponent() { // 現時点では、Manager側がDataFlowComponentのみに対応しているため、テスト省略する } /*! * @brief createComponent()メソッドのテスト * * - 登録されていないモジュール名を指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? * - モジュール名にNULLを指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? */ void test_createComponent_with_illegal_module_name() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 登録されていないモジュール名を指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp1 = m_mgr->createComponent("illegal_module_name"); CPPUNIT_ASSERT(comp1 == NULL); // モジュール名にNULLを指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp2 = m_mgr->createComponent(NULL); CPPUNIT_ASSERT(comp2 == NULL); } void test_createComponent_failed_in_bindExecutionContext() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // bindExecutionContext()で失敗するように、意図的にECFactoryを登録せずにおく // コンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp == NULL); m_mgr->terminate(); coil::usleep(3000000); } /*! * @brief cleanupComponent()メソッドのテスト * * - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? * - 登録したコンポーネントが、Managerから正しく登録解除されるか? */ void test_cleanupComponent() { // 初期化を行う // int argc = 1; // char* argv[] = { "-f fixture4.conf" }; int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 確認用にネームサービスへのアクセス手段としてNamingManagerを準備しておく // ※fixture4.confの各設定に合わせている点に注意 RTC::NamingManager nmgr(m_mgr); const char* name_server = "localhost:2809"; nmgr.registerNameServer("corba", name_server); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), // ※末尾の0はNumberingPolicyにより付加される std::string(comp->getInstanceName())); // コンポーネントに、意図どおりExecutionContextがアタッチされているか? RTC::ExecutionContextList* ecList = comp->get_owned_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length()); // cleanupComponent()により、正しく登録解除されるか? // - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? // - 登録したコンポーネントが、Managerから正しく登録解除されるか? CPPUNIT_ASSERT(!canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT_EQUAL(comp, m_mgr->getComponent("DataFlowComponent0")); m_mgr->cleanupComponent(comp); CPPUNIT_ASSERT(! canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); comp->exit(); usleep(10000); m_mgr->terminate(); } void test_unregisterComponent() { // Manager::cleanupComponent()内で使用されているので、ここではテスト省略する } void test_bindExecutionContext() { // Manager::createComponent()内で使用されているので、ここではテスト省略する } void test_getComponent() { // 他テスト内で使用されているので、そちらで兼ねるものとして、ここではテスト省略する } /*! * @brief getComponents()メソッドのテスト * * - getComponents()で、生成したすべてのコンポーネントを取得できるか? * - 登録解除したコンポーネントが、正しく一覧から除外されているか? */ void test_getComponents() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 複数のコンポーネントを生成しておく RTC::RtcBase* comp1 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp1 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp1) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp1->_this())); RTC::RtcBase* comp2 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp2 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp2) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp2->_this())); CPPUNIT_ASSERT(comp1 != comp2); // getComponents()で、生成したすべてのコンポーネントを取得できるか? std::vector<RTC::RtcBase*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT_EQUAL(2, (int) comps.size()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) != comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); // コンポーネントを1つだけ登録解除した場合、解除したものが一覧から除外されているか? m_mgr->cleanupComponent(comp1); comps = m_mgr->getComponents(); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) == comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); comp1->exit(); comp2->exit(); m_mgr->terminate(); } void test_getORB() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOA() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOAManager() { // 他テスト内で使用されているので、ここではテスト省略する } /*! * @brief initFactories()メソッドのテスト * * - init()実行後、initFactories()の実行結果としてFactoryMapに正しく登録されているか? */ void test_initFactories() { // init()の中でinitFactories()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initFactories()の実行結果としてFactoryMapに正しく登録されているか? bool bret = RTC::CdrBufferFactory::instance().hasFactory("ring_buffer"); CPPUNIT_ASSERT(bret); bret = RTC::PeriodicTaskFactory::instance().hasFactory("default"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("flush"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("new"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("periodic"); CPPUNIT_ASSERT(bret); RTC::InPortProviderFactory& factory1(RTC::InPortProviderFactory::instance()); bret = factory1.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::InPortConsumerFactory& factory2(RTC::InPortConsumerFactory::instance()); bret = factory2.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortConsumerFactory& factory3(RTC::OutPortConsumerFactory::instance()); bret = factory3.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortProviderFactory& factory4(RTC::OutPortProviderFactory::instance()); bret = factory4.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); } /*! * @brief initComposite()メソッドのテスト * * - init()実行後、initComposite()の実行結果としてFactoryManagerに正しく登録されているか? */ void test_initComposite() { // init()の中でinitComposite()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initComposite()の実行結果としてFactoryManagerに正しく登録されているか? // "implementation_id"には, "PeriodicECSharedComposite"が設定されている CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "PeriodicECSharedComposite")); } /*! * @brief procContextArgs()メソッドのテスト * * - 引数ec_argsにより戻り値true・falseが正しく返却されるか? */ void test_procContextArgs() { std::string ec_args; std::string ec_id; coil::Properties ec_prop; // インスタンス生成 ManagerTestMock* man = new ManagerTestMock(); // falseを返すケース1:ec_args.size=0 ec_args = ""; bool bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース2:ec_args.size=3 ec_args = "periodic?rate=1000?policy=skip"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース3:ec_args[0].empty ec_args = "?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // trueを返すケース4:ec_args.size=2 ec_args = "periodic?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(bret); std::string chk_val("periodic"); CPPUNIT_ASSERT_EQUAL(chk_val, ec_id); chk_val = "1000"; CPPUNIT_ASSERT_EQUAL(chk_val, ec_prop["rate"]); delete man; } /*! * @brief getLogLevel()メソッドのテスト * * - log_levelが正しく返却されるか? */ void test_getLogLevel() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); std::string log_level = m_mgr->getLogLevel(); CPPUNIT_ASSERT_EQUAL(std::string("INFO"), log_level); } /*! * @brief getLoadedModules()メソッドのテスト * * - ロード済みのモジュールリストを正しく取得できるか? */ void test_getLoadedModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); /* FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード済みのモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadedModules(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string(".//./.libs/DummyModule.so"), props[0].getProperty("file_path")); */ } /*! * @brief getFactoryProfiles()メソッドのテスト * * - RTコンポーネント用ファクトリをリストを正しく取得できるか? */ void test_getFactoryProfiles() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); std::vector<coil::Properties> props = m_mgr->getFactoryProfiles(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string("PeriodicECSharedComposite"), props[0].getProperty("implementation_id")); CPPUNIT_ASSERT_EQUAL(std::string("ID"), props[1].getProperty("implementation_id")); } /*! * @brief createContext()メソッドのテスト * * - ExecutionContextBaseを正しく取得できるか? */ void test_createContext() { RTC::ExecutionContextBase* ec; std::string ec_args; m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // return NULL check ec_args = ""; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return NULL check (Factory not found) ec_args = "periodic?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return any check m_mgr->registerECFactory("PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>); ec_args = "PeriodicEC?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec != NULL); } /*! * @brief deleteComponent()メソッドのテスト * * - RTコンポーネントの削除が正しくできるか? */ void test_deleteComponent() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), std::string(comp->getInstanceName())); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") != NULL); std::vector<RTC::RTObject_impl*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT(comps.size() > 0); // 正しくコンポーネントを削除できるか? m_mgr->deleteComponent("DataFlowComponent0"); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); // deleteComponent()でexit()を実行しているため、これ以降のテストはできません。 } /*! * @brief init()、shutdown()から呼ばれるprotected関数のテスト * * - protected関数が正しく動作しているか? */ void test_init2() { // Manager::init()よりprotected関数が使用されているので、ここではテスト省略する // initManager() // initLogger() // initORB() // initNaming() // initFactories() // initExecContext() // initComposite() // initTimer() // initManagerServant() // Manager::shutdown()よりprotected関数が使用されているので、ここではテスト省略する // shutdownComponents(); // shutdownNaming(); // shutdownORB(); // shutdownManager(); // shutdownLogger(); } }; }; // namespace Tests /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(Tests::ManagerTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // ManagerTests_cpp
1039  RTC::NamingManager nmgr(m_mgr);
1040  const char* name_server = "localhost:2809";
1041  nmgr.registerNameServer("corba", name_server);
1042  CPPUNIT_ASSERT(canResolve(name_server, "DataFlowComponent0", "rtc"));
1043 
1044  comp->exit();
1045  m_mgr->terminate();
1046  }
1047 
1049  {
1050  // 現時点では、Manager側がDataFlowComponentのみに対応しているため、テスト省略する } /*! * @brief createComponent()メソッドのテスト * * - 登録されていないモジュール名を指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? * - モジュール名にNULLを指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? */ void test_createComponent_with_illegal_module_name() { // 初期化を行う int argc = 0; char* argv[] = {}; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 登録されていないモジュール名を指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp1 = m_mgr->createComponent("illegal_module_name"); CPPUNIT_ASSERT(comp1 == NULL); // モジュール名にNULLを指定してコンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp2 = m_mgr->createComponent(NULL); CPPUNIT_ASSERT(comp2 == NULL); } void test_createComponent_failed_in_bindExecutionContext() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // bindExecutionContext()で失敗するように、意図的にECFactoryを登録せずにおく // コンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp == NULL); m_mgr->terminate(); coil::usleep(3000000); } /*! * @brief cleanupComponent()メソッドのテスト * * - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? * - 登録したコンポーネントが、Managerから正しく登録解除されるか? */ void test_cleanupComponent() { // 初期化を行う // int argc = 1; // char* argv[] = { "-f fixture4.conf" }; int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 確認用にネームサービスへのアクセス手段としてNamingManagerを準備しておく // ※fixture4.confの各設定に合わせている点に注意 RTC::NamingManager nmgr(m_mgr); const char* name_server = "localhost:2809"; nmgr.registerNameServer("corba", name_server); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), // ※末尾の0はNumberingPolicyにより付加される std::string(comp->getInstanceName())); // コンポーネントに、意図どおりExecutionContextがアタッチされているか? RTC::ExecutionContextList* ecList = comp->get_owned_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length()); // cleanupComponent()により、正しく登録解除されるか? // - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? // - 登録したコンポーネントが、Managerから正しく登録解除されるか? CPPUNIT_ASSERT(!canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT_EQUAL(comp, m_mgr->getComponent("DataFlowComponent0")); m_mgr->cleanupComponent(comp); CPPUNIT_ASSERT(! canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); comp->exit(); usleep(10000); m_mgr->terminate(); } void test_unregisterComponent() { // Manager::cleanupComponent()内で使用されているので、ここではテスト省略する } void test_bindExecutionContext() { // Manager::createComponent()内で使用されているので、ここではテスト省略する } void test_getComponent() { // 他テスト内で使用されているので、そちらで兼ねるものとして、ここではテスト省略する } /*! * @brief getComponents()メソッドのテスト * * - getComponents()で、生成したすべてのコンポーネントを取得できるか? * - 登録解除したコンポーネントが、正しく一覧から除外されているか? */ void test_getComponents() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 複数のコンポーネントを生成しておく RTC::RtcBase* comp1 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp1 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp1) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp1->_this())); RTC::RtcBase* comp2 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp2 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp2) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp2->_this())); CPPUNIT_ASSERT(comp1 != comp2); // getComponents()で、生成したすべてのコンポーネントを取得できるか? std::vector<RTC::RtcBase*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT_EQUAL(2, (int) comps.size()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) != comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); // コンポーネントを1つだけ登録解除した場合、解除したものが一覧から除外されているか? m_mgr->cleanupComponent(comp1); comps = m_mgr->getComponents(); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) == comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); comp1->exit(); comp2->exit(); m_mgr->terminate(); } void test_getORB() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOA() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOAManager() { // 他テスト内で使用されているので、ここではテスト省略する } /*! * @brief initFactories()メソッドのテスト * * - init()実行後、initFactories()の実行結果としてFactoryMapに正しく登録されているか? */ void test_initFactories() { // init()の中でinitFactories()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initFactories()の実行結果としてFactoryMapに正しく登録されているか? bool bret = RTC::CdrBufferFactory::instance().hasFactory("ring_buffer"); CPPUNIT_ASSERT(bret); bret = RTC::PeriodicTaskFactory::instance().hasFactory("default"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("flush"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("new"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("periodic"); CPPUNIT_ASSERT(bret); RTC::InPortProviderFactory& factory1(RTC::InPortProviderFactory::instance()); bret = factory1.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::InPortConsumerFactory& factory2(RTC::InPortConsumerFactory::instance()); bret = factory2.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortConsumerFactory& factory3(RTC::OutPortConsumerFactory::instance()); bret = factory3.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortProviderFactory& factory4(RTC::OutPortProviderFactory::instance()); bret = factory4.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); } /*! * @brief initComposite()メソッドのテスト * * - init()実行後、initComposite()の実行結果としてFactoryManagerに正しく登録されているか? */ void test_initComposite() { // init()の中でinitComposite()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initComposite()の実行結果としてFactoryManagerに正しく登録されているか? // "implementation_id"には, "PeriodicECSharedComposite"が設定されている CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "PeriodicECSharedComposite")); } /*! * @brief procContextArgs()メソッドのテスト * * - 引数ec_argsにより戻り値true・falseが正しく返却されるか? */ void test_procContextArgs() { std::string ec_args; std::string ec_id; coil::Properties ec_prop; // インスタンス生成 ManagerTestMock* man = new ManagerTestMock(); // falseを返すケース1:ec_args.size=0 ec_args = ""; bool bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース2:ec_args.size=3 ec_args = "periodic?rate=1000?policy=skip"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース3:ec_args[0].empty ec_args = "?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // trueを返すケース4:ec_args.size=2 ec_args = "periodic?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(bret); std::string chk_val("periodic"); CPPUNIT_ASSERT_EQUAL(chk_val, ec_id); chk_val = "1000"; CPPUNIT_ASSERT_EQUAL(chk_val, ec_prop["rate"]); delete man; } /*! * @brief getLogLevel()メソッドのテスト * * - log_levelが正しく返却されるか? */ void test_getLogLevel() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); std::string log_level = m_mgr->getLogLevel(); CPPUNIT_ASSERT_EQUAL(std::string("INFO"), log_level); } /*! * @brief getLoadedModules()メソッドのテスト * * - ロード済みのモジュールリストを正しく取得できるか? */ void test_getLoadedModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); /* FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード済みのモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadedModules(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string(".//./.libs/DummyModule.so"), props[0].getProperty("file_path")); */ } /*! * @brief getFactoryProfiles()メソッドのテスト * * - RTコンポーネント用ファクトリをリストを正しく取得できるか? */ void test_getFactoryProfiles() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); std::vector<coil::Properties> props = m_mgr->getFactoryProfiles(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string("PeriodicECSharedComposite"), props[0].getProperty("implementation_id")); CPPUNIT_ASSERT_EQUAL(std::string("ID"), props[1].getProperty("implementation_id")); } /*! * @brief createContext()メソッドのテスト * * - ExecutionContextBaseを正しく取得できるか? */ void test_createContext() { RTC::ExecutionContextBase* ec; std::string ec_args; m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // return NULL check ec_args = ""; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return NULL check (Factory not found) ec_args = "periodic?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return any check m_mgr->registerECFactory("PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>); ec_args = "PeriodicEC?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec != NULL); } /*! * @brief deleteComponent()メソッドのテスト * * - RTコンポーネントの削除が正しくできるか? */ void test_deleteComponent() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), std::string(comp->getInstanceName())); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") != NULL); std::vector<RTC::RTObject_impl*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT(comps.size() > 0); // 正しくコンポーネントを削除できるか? m_mgr->deleteComponent("DataFlowComponent0"); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); // deleteComponent()でexit()を実行しているため、これ以降のテストはできません。 } /*! * @brief init()、shutdown()から呼ばれるprotected関数のテスト * * - protected関数が正しく動作しているか? */ void test_init2() { // Manager::init()よりprotected関数が使用されているので、ここではテスト省略する // initManager() // initLogger() // initORB() // initNaming() // initFactories() // initExecContext() // initComposite() // initTimer() // initManagerServant() // Manager::shutdown()よりprotected関数が使用されているので、ここではテスト省略する // shutdownComponents(); // shutdownNaming(); // shutdownORB(); // shutdownManager(); // shutdownLogger(); } }; }; // namespace Tests /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(Tests::ManagerTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // ManagerTests_cpp
1051  }
1052 
1060  {
1061  // 初期化を行う
1062  int argc = 0;
1063  char* argv[] = {};
1064 
1065  m_mgr = RTC::Manager::init(argc, argv);
1066  CPPUNIT_ASSERT(m_mgr != NULL);
1067  CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB()));
1068  CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA()));
1069  CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager()));
1070 
1071  // 登録されていないモジュール名を指定してコンポーネント生成を試みて、意図どおりNULLで戻るか?
1072  RTC::RtcBase* comp1 = m_mgr->createComponent("illegal_module_name");
1073  CPPUNIT_ASSERT(comp1 == NULL);
1074 
1075  // モジュール名にNULLを指定してコンポーネント生成を試みて、意図どおりNULLで戻るか?
1076  RTC::RtcBase* comp2 = m_mgr->createComponent(NULL);
1077  CPPUNIT_ASSERT(comp2 == NULL);
1078  }
1079 
1081  {
1082  // 初期化を行う
1083  int argc = 3;
1084  char* argv[] = { "ManagerTests","-f","fixture4.conf" };
1085 
1086  m_mgr = RTC::Manager::init(argc, argv);
1087  CPPUNIT_ASSERT(m_mgr != NULL);
1088  CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB()));
1089  CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA()));
1090  CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager()));
1091 
1092  // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // bindExecutionContext()で失敗するように、意図的にECFactoryを登録せずにおく // コンポーネント生成を試みて、意図どおりNULLで戻るか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp == NULL); m_mgr->terminate(); coil::usleep(3000000); } /*! * @brief cleanupComponent()メソッドのテスト * * - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? * - 登録したコンポーネントが、Managerから正しく登録解除されるか? */ void test_cleanupComponent() { // 初期化を行う // int argc = 1; // char* argv[] = { "-f fixture4.conf" }; int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 確認用にネームサービスへのアクセス手段としてNamingManagerを準備しておく // ※fixture4.confの各設定に合わせている点に注意 RTC::NamingManager nmgr(m_mgr); const char* name_server = "localhost:2809"; nmgr.registerNameServer("corba", name_server); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), // ※末尾の0はNumberingPolicyにより付加される std::string(comp->getInstanceName())); // コンポーネントに、意図どおりExecutionContextがアタッチされているか? RTC::ExecutionContextList* ecList = comp->get_owned_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length()); // cleanupComponent()により、正しく登録解除されるか? // - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? // - 登録したコンポーネントが、Managerから正しく登録解除されるか? CPPUNIT_ASSERT(!canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT_EQUAL(comp, m_mgr->getComponent("DataFlowComponent0")); m_mgr->cleanupComponent(comp); CPPUNIT_ASSERT(! canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); comp->exit(); usleep(10000); m_mgr->terminate(); } void test_unregisterComponent() { // Manager::cleanupComponent()内で使用されているので、ここではテスト省略する } void test_bindExecutionContext() { // Manager::createComponent()内で使用されているので、ここではテスト省略する } void test_getComponent() { // 他テスト内で使用されているので、そちらで兼ねるものとして、ここではテスト省略する } /*! * @brief getComponents()メソッドのテスト * * - getComponents()で、生成したすべてのコンポーネントを取得できるか? * - 登録解除したコンポーネントが、正しく一覧から除外されているか? */ void test_getComponents() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 複数のコンポーネントを生成しておく RTC::RtcBase* comp1 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp1 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp1) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp1->_this())); RTC::RtcBase* comp2 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp2 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp2) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp2->_this())); CPPUNIT_ASSERT(comp1 != comp2); // getComponents()で、生成したすべてのコンポーネントを取得できるか? std::vector<RTC::RtcBase*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT_EQUAL(2, (int) comps.size()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) != comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); // コンポーネントを1つだけ登録解除した場合、解除したものが一覧から除外されているか? m_mgr->cleanupComponent(comp1); comps = m_mgr->getComponents(); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) == comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); comp1->exit(); comp2->exit(); m_mgr->terminate(); } void test_getORB() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOA() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOAManager() { // 他テスト内で使用されているので、ここではテスト省略する } /*! * @brief initFactories()メソッドのテスト * * - init()実行後、initFactories()の実行結果としてFactoryMapに正しく登録されているか? */ void test_initFactories() { // init()の中でinitFactories()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initFactories()の実行結果としてFactoryMapに正しく登録されているか? bool bret = RTC::CdrBufferFactory::instance().hasFactory("ring_buffer"); CPPUNIT_ASSERT(bret); bret = RTC::PeriodicTaskFactory::instance().hasFactory("default"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("flush"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("new"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("periodic"); CPPUNIT_ASSERT(bret); RTC::InPortProviderFactory& factory1(RTC::InPortProviderFactory::instance()); bret = factory1.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::InPortConsumerFactory& factory2(RTC::InPortConsumerFactory::instance()); bret = factory2.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortConsumerFactory& factory3(RTC::OutPortConsumerFactory::instance()); bret = factory3.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortProviderFactory& factory4(RTC::OutPortProviderFactory::instance()); bret = factory4.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); } /*! * @brief initComposite()メソッドのテスト * * - init()実行後、initComposite()の実行結果としてFactoryManagerに正しく登録されているか? */ void test_initComposite() { // init()の中でinitComposite()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initComposite()の実行結果としてFactoryManagerに正しく登録されているか? // "implementation_id"には, "PeriodicECSharedComposite"が設定されている CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "PeriodicECSharedComposite")); } /*! * @brief procContextArgs()メソッドのテスト * * - 引数ec_argsにより戻り値true・falseが正しく返却されるか? */ void test_procContextArgs() { std::string ec_args; std::string ec_id; coil::Properties ec_prop; // インスタンス生成 ManagerTestMock* man = new ManagerTestMock(); // falseを返すケース1:ec_args.size=0 ec_args = ""; bool bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース2:ec_args.size=3 ec_args = "periodic?rate=1000?policy=skip"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース3:ec_args[0].empty ec_args = "?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // trueを返すケース4:ec_args.size=2 ec_args = "periodic?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(bret); std::string chk_val("periodic"); CPPUNIT_ASSERT_EQUAL(chk_val, ec_id); chk_val = "1000"; CPPUNIT_ASSERT_EQUAL(chk_val, ec_prop["rate"]); delete man; } /*! * @brief getLogLevel()メソッドのテスト * * - log_levelが正しく返却されるか? */ void test_getLogLevel() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); std::string log_level = m_mgr->getLogLevel(); CPPUNIT_ASSERT_EQUAL(std::string("INFO"), log_level); } /*! * @brief getLoadedModules()メソッドのテスト * * - ロード済みのモジュールリストを正しく取得できるか? */ void test_getLoadedModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); /* FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード済みのモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadedModules(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string(".//./.libs/DummyModule.so"), props[0].getProperty("file_path")); */ } /*! * @brief getFactoryProfiles()メソッドのテスト * * - RTコンポーネント用ファクトリをリストを正しく取得できるか? */ void test_getFactoryProfiles() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); std::vector<coil::Properties> props = m_mgr->getFactoryProfiles(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string("PeriodicECSharedComposite"), props[0].getProperty("implementation_id")); CPPUNIT_ASSERT_EQUAL(std::string("ID"), props[1].getProperty("implementation_id")); } /*! * @brief createContext()メソッドのテスト * * - ExecutionContextBaseを正しく取得できるか? */ void test_createContext() { RTC::ExecutionContextBase* ec; std::string ec_args; m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // return NULL check ec_args = ""; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return NULL check (Factory not found) ec_args = "periodic?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return any check m_mgr->registerECFactory("PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>); ec_args = "PeriodicEC?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec != NULL); } /*! * @brief deleteComponent()メソッドのテスト * * - RTコンポーネントの削除が正しくできるか? */ void test_deleteComponent() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), std::string(comp->getInstanceName())); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") != NULL); std::vector<RTC::RTObject_impl*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT(comps.size() > 0); // 正しくコンポーネントを削除できるか? m_mgr->deleteComponent("DataFlowComponent0"); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); // deleteComponent()でexit()を実行しているため、これ以降のテストはできません。 } /*! * @brief init()、shutdown()から呼ばれるprotected関数のテスト * * - protected関数が正しく動作しているか? */ void test_init2() { // Manager::init()よりprotected関数が使用されているので、ここではテスト省略する // initManager() // initLogger() // initORB() // initNaming() // initFactories() // initExecContext() // initComposite() // initTimer() // initManagerServant() // Manager::shutdown()よりprotected関数が使用されているので、ここではテスト省略する // shutdownComponents(); // shutdownNaming(); // shutdownORB(); // shutdownManager(); // shutdownLogger(); } }; }; // namespace Tests /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(Tests::ManagerTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // ManagerTests_cpp
1093  CPPUNIT_ASSERT(m_mgr->activateManager());
1094  m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング
1095 
1096  // Factoryを登録しておく
1097  coil::Properties properties;
1098  properties.setProperty("implementation_id", "DataFlowComponentFactory");
1099  properties.setProperty("type_name", "DataFlowComponent");
1100  CPPUNIT_ASSERT(m_mgr->registerFactory(
1102 
1103  // bindExecutionContext()で失敗するように、意図的にECFactoryを登録せずにおく
1104 
1105  // コンポーネント生成を試みて、意図どおりNULLで戻るか?
1106  RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory");
1107  CPPUNIT_ASSERT(comp == NULL);
1108 
1109  m_mgr->terminate();
1110  coil::usleep(3000000);
1111  }
1112 
1120  {
1121  // 初期化を行う
1122 // int argc = 1;
1123 // char* argv[] = { "-f fixture4.conf" };
1124  int argc = 3;
1125  char* argv[] = { "ManagerTests","-f","fixture4.conf" };
1126 
1127  m_mgr = RTC::Manager::init(argc, argv);
1128  CPPUNIT_ASSERT(m_mgr != NULL);
1129  CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB()));
1130  CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA()));
1131  CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager()));
1132 
1133  // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 確認用にネームサービスへのアクセス手段としてNamingManagerを準備しておく // ※fixture4.confの各設定に合わせている点に注意 RTC::NamingManager nmgr(m_mgr); const char* name_server = "localhost:2809"; nmgr.registerNameServer("corba", name_server); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), // ※末尾の0はNumberingPolicyにより付加される std::string(comp->getInstanceName())); // コンポーネントに、意図どおりExecutionContextがアタッチされているか? RTC::ExecutionContextList* ecList = comp->get_owned_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length()); // cleanupComponent()により、正しく登録解除されるか? // - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? // - 登録したコンポーネントが、Managerから正しく登録解除されるか? CPPUNIT_ASSERT(!canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT_EQUAL(comp, m_mgr->getComponent("DataFlowComponent0")); m_mgr->cleanupComponent(comp); CPPUNIT_ASSERT(! canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); comp->exit(); usleep(10000); m_mgr->terminate(); } void test_unregisterComponent() { // Manager::cleanupComponent()内で使用されているので、ここではテスト省略する } void test_bindExecutionContext() { // Manager::createComponent()内で使用されているので、ここではテスト省略する } void test_getComponent() { // 他テスト内で使用されているので、そちらで兼ねるものとして、ここではテスト省略する } /*! * @brief getComponents()メソッドのテスト * * - getComponents()で、生成したすべてのコンポーネントを取得できるか? * - 登録解除したコンポーネントが、正しく一覧から除外されているか? */ void test_getComponents() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 複数のコンポーネントを生成しておく RTC::RtcBase* comp1 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp1 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp1) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp1->_this())); RTC::RtcBase* comp2 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp2 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp2) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp2->_this())); CPPUNIT_ASSERT(comp1 != comp2); // getComponents()で、生成したすべてのコンポーネントを取得できるか? std::vector<RTC::RtcBase*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT_EQUAL(2, (int) comps.size()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) != comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); // コンポーネントを1つだけ登録解除した場合、解除したものが一覧から除外されているか? m_mgr->cleanupComponent(comp1); comps = m_mgr->getComponents(); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) == comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); comp1->exit(); comp2->exit(); m_mgr->terminate(); } void test_getORB() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOA() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOAManager() { // 他テスト内で使用されているので、ここではテスト省略する } /*! * @brief initFactories()メソッドのテスト * * - init()実行後、initFactories()の実行結果としてFactoryMapに正しく登録されているか? */ void test_initFactories() { // init()の中でinitFactories()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initFactories()の実行結果としてFactoryMapに正しく登録されているか? bool bret = RTC::CdrBufferFactory::instance().hasFactory("ring_buffer"); CPPUNIT_ASSERT(bret); bret = RTC::PeriodicTaskFactory::instance().hasFactory("default"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("flush"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("new"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("periodic"); CPPUNIT_ASSERT(bret); RTC::InPortProviderFactory& factory1(RTC::InPortProviderFactory::instance()); bret = factory1.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::InPortConsumerFactory& factory2(RTC::InPortConsumerFactory::instance()); bret = factory2.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortConsumerFactory& factory3(RTC::OutPortConsumerFactory::instance()); bret = factory3.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortProviderFactory& factory4(RTC::OutPortProviderFactory::instance()); bret = factory4.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); } /*! * @brief initComposite()メソッドのテスト * * - init()実行後、initComposite()の実行結果としてFactoryManagerに正しく登録されているか? */ void test_initComposite() { // init()の中でinitComposite()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initComposite()の実行結果としてFactoryManagerに正しく登録されているか? // "implementation_id"には, "PeriodicECSharedComposite"が設定されている CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "PeriodicECSharedComposite")); } /*! * @brief procContextArgs()メソッドのテスト * * - 引数ec_argsにより戻り値true・falseが正しく返却されるか? */ void test_procContextArgs() { std::string ec_args; std::string ec_id; coil::Properties ec_prop; // インスタンス生成 ManagerTestMock* man = new ManagerTestMock(); // falseを返すケース1:ec_args.size=0 ec_args = ""; bool bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース2:ec_args.size=3 ec_args = "periodic?rate=1000?policy=skip"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース3:ec_args[0].empty ec_args = "?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // trueを返すケース4:ec_args.size=2 ec_args = "periodic?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(bret); std::string chk_val("periodic"); CPPUNIT_ASSERT_EQUAL(chk_val, ec_id); chk_val = "1000"; CPPUNIT_ASSERT_EQUAL(chk_val, ec_prop["rate"]); delete man; } /*! * @brief getLogLevel()メソッドのテスト * * - log_levelが正しく返却されるか? */ void test_getLogLevel() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); std::string log_level = m_mgr->getLogLevel(); CPPUNIT_ASSERT_EQUAL(std::string("INFO"), log_level); } /*! * @brief getLoadedModules()メソッドのテスト * * - ロード済みのモジュールリストを正しく取得できるか? */ void test_getLoadedModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); /* FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード済みのモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadedModules(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string(".//./.libs/DummyModule.so"), props[0].getProperty("file_path")); */ } /*! * @brief getFactoryProfiles()メソッドのテスト * * - RTコンポーネント用ファクトリをリストを正しく取得できるか? */ void test_getFactoryProfiles() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); std::vector<coil::Properties> props = m_mgr->getFactoryProfiles(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string("PeriodicECSharedComposite"), props[0].getProperty("implementation_id")); CPPUNIT_ASSERT_EQUAL(std::string("ID"), props[1].getProperty("implementation_id")); } /*! * @brief createContext()メソッドのテスト * * - ExecutionContextBaseを正しく取得できるか? */ void test_createContext() { RTC::ExecutionContextBase* ec; std::string ec_args; m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // return NULL check ec_args = ""; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return NULL check (Factory not found) ec_args = "periodic?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return any check m_mgr->registerECFactory("PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>); ec_args = "PeriodicEC?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec != NULL); } /*! * @brief deleteComponent()メソッドのテスト * * - RTコンポーネントの削除が正しくできるか? */ void test_deleteComponent() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), std::string(comp->getInstanceName())); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") != NULL); std::vector<RTC::RTObject_impl*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT(comps.size() > 0); // 正しくコンポーネントを削除できるか? m_mgr->deleteComponent("DataFlowComponent0"); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); // deleteComponent()でexit()を実行しているため、これ以降のテストはできません。 } /*! * @brief init()、shutdown()から呼ばれるprotected関数のテスト * * - protected関数が正しく動作しているか? */ void test_init2() { // Manager::init()よりprotected関数が使用されているので、ここではテスト省略する // initManager() // initLogger() // initORB() // initNaming() // initFactories() // initExecContext() // initComposite() // initTimer() // initManagerServant() // Manager::shutdown()よりprotected関数が使用されているので、ここではテスト省略する // shutdownComponents(); // shutdownNaming(); // shutdownORB(); // shutdownManager(); // shutdownLogger(); } }; }; // namespace Tests /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(Tests::ManagerTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // ManagerTests_cpp
1134  CPPUNIT_ASSERT(m_mgr->activateManager());
1135  m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング
1136 
1137  // Factoryを登録しておく
1138  coil::Properties properties;
1139  properties.setProperty("implementation_id", "DataFlowComponentFactory");
1140  properties.setProperty("type_name", "DataFlowComponent");
1141  CPPUNIT_ASSERT(m_mgr->registerFactory(
1143 
1144  // ECFactoryを登録しておく
1145  CPPUNIT_ASSERT(m_mgr->registerECFactory(
1146  "PeriodicEC",
1147  RTC::ECCreate<RTC::PeriodicExecutionContext>,
1148  RTC::ECDelete<RTC::PeriodicExecutionContext>));
1149 
1150  // 確認用にネームサービスへのアクセス手段としてNamingManagerを準備しておく
1151  // ※fixture4.confの各設定に合わせている点に注意 RTC::NamingManager nmgr(m_mgr); const char* name_server = "localhost:2809"; nmgr.registerNameServer("corba", name_server); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), // ※末尾の0はNumberingPolicyにより付加される std::string(comp->getInstanceName())); // コンポーネントに、意図どおりExecutionContextがアタッチされているか? RTC::ExecutionContextList* ecList = comp->get_owned_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length()); // cleanupComponent()により、正しく登録解除されるか? // - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? // - 登録したコンポーネントが、Managerから正しく登録解除されるか? CPPUNIT_ASSERT(!canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT_EQUAL(comp, m_mgr->getComponent("DataFlowComponent0")); m_mgr->cleanupComponent(comp); CPPUNIT_ASSERT(! canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); comp->exit(); usleep(10000); m_mgr->terminate(); } void test_unregisterComponent() { // Manager::cleanupComponent()内で使用されているので、ここではテスト省略する } void test_bindExecutionContext() { // Manager::createComponent()内で使用されているので、ここではテスト省略する } void test_getComponent() { // 他テスト内で使用されているので、そちらで兼ねるものとして、ここではテスト省略する } /*! * @brief getComponents()メソッドのテスト * * - getComponents()で、生成したすべてのコンポーネントを取得できるか? * - 登録解除したコンポーネントが、正しく一覧から除外されているか? */ void test_getComponents() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 複数のコンポーネントを生成しておく RTC::RtcBase* comp1 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp1 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp1) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp1->_this())); RTC::RtcBase* comp2 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp2 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp2) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp2->_this())); CPPUNIT_ASSERT(comp1 != comp2); // getComponents()で、生成したすべてのコンポーネントを取得できるか? std::vector<RTC::RtcBase*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT_EQUAL(2, (int) comps.size()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) != comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); // コンポーネントを1つだけ登録解除した場合、解除したものが一覧から除外されているか? m_mgr->cleanupComponent(comp1); comps = m_mgr->getComponents(); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) == comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); comp1->exit(); comp2->exit(); m_mgr->terminate(); } void test_getORB() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOA() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOAManager() { // 他テスト内で使用されているので、ここではテスト省略する } /*! * @brief initFactories()メソッドのテスト * * - init()実行後、initFactories()の実行結果としてFactoryMapに正しく登録されているか? */ void test_initFactories() { // init()の中でinitFactories()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initFactories()の実行結果としてFactoryMapに正しく登録されているか? bool bret = RTC::CdrBufferFactory::instance().hasFactory("ring_buffer"); CPPUNIT_ASSERT(bret); bret = RTC::PeriodicTaskFactory::instance().hasFactory("default"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("flush"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("new"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("periodic"); CPPUNIT_ASSERT(bret); RTC::InPortProviderFactory& factory1(RTC::InPortProviderFactory::instance()); bret = factory1.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::InPortConsumerFactory& factory2(RTC::InPortConsumerFactory::instance()); bret = factory2.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortConsumerFactory& factory3(RTC::OutPortConsumerFactory::instance()); bret = factory3.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortProviderFactory& factory4(RTC::OutPortProviderFactory::instance()); bret = factory4.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); } /*! * @brief initComposite()メソッドのテスト * * - init()実行後、initComposite()の実行結果としてFactoryManagerに正しく登録されているか? */ void test_initComposite() { // init()の中でinitComposite()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initComposite()の実行結果としてFactoryManagerに正しく登録されているか? // "implementation_id"には, "PeriodicECSharedComposite"が設定されている CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "PeriodicECSharedComposite")); } /*! * @brief procContextArgs()メソッドのテスト * * - 引数ec_argsにより戻り値true・falseが正しく返却されるか? */ void test_procContextArgs() { std::string ec_args; std::string ec_id; coil::Properties ec_prop; // インスタンス生成 ManagerTestMock* man = new ManagerTestMock(); // falseを返すケース1:ec_args.size=0 ec_args = ""; bool bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース2:ec_args.size=3 ec_args = "periodic?rate=1000?policy=skip"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース3:ec_args[0].empty ec_args = "?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // trueを返すケース4:ec_args.size=2 ec_args = "periodic?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(bret); std::string chk_val("periodic"); CPPUNIT_ASSERT_EQUAL(chk_val, ec_id); chk_val = "1000"; CPPUNIT_ASSERT_EQUAL(chk_val, ec_prop["rate"]); delete man; } /*! * @brief getLogLevel()メソッドのテスト * * - log_levelが正しく返却されるか? */ void test_getLogLevel() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); std::string log_level = m_mgr->getLogLevel(); CPPUNIT_ASSERT_EQUAL(std::string("INFO"), log_level); } /*! * @brief getLoadedModules()メソッドのテスト * * - ロード済みのモジュールリストを正しく取得できるか? */ void test_getLoadedModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); /* FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード済みのモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadedModules(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string(".//./.libs/DummyModule.so"), props[0].getProperty("file_path")); */ } /*! * @brief getFactoryProfiles()メソッドのテスト * * - RTコンポーネント用ファクトリをリストを正しく取得できるか? */ void test_getFactoryProfiles() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); std::vector<coil::Properties> props = m_mgr->getFactoryProfiles(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string("PeriodicECSharedComposite"), props[0].getProperty("implementation_id")); CPPUNIT_ASSERT_EQUAL(std::string("ID"), props[1].getProperty("implementation_id")); } /*! * @brief createContext()メソッドのテスト * * - ExecutionContextBaseを正しく取得できるか? */ void test_createContext() { RTC::ExecutionContextBase* ec; std::string ec_args; m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // return NULL check ec_args = ""; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return NULL check (Factory not found) ec_args = "periodic?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return any check m_mgr->registerECFactory("PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>); ec_args = "PeriodicEC?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec != NULL); } /*! * @brief deleteComponent()メソッドのテスト * * - RTコンポーネントの削除が正しくできるか? */ void test_deleteComponent() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), std::string(comp->getInstanceName())); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") != NULL); std::vector<RTC::RTObject_impl*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT(comps.size() > 0); // 正しくコンポーネントを削除できるか? m_mgr->deleteComponent("DataFlowComponent0"); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); // deleteComponent()でexit()を実行しているため、これ以降のテストはできません。 } /*! * @brief init()、shutdown()から呼ばれるprotected関数のテスト * * - protected関数が正しく動作しているか? */ void test_init2() { // Manager::init()よりprotected関数が使用されているので、ここではテスト省略する // initManager() // initLogger() // initORB() // initNaming() // initFactories() // initExecContext() // initComposite() // initTimer() // initManagerServant() // Manager::shutdown()よりprotected関数が使用されているので、ここではテスト省略する // shutdownComponents(); // shutdownNaming(); // shutdownORB(); // shutdownManager(); // shutdownLogger(); } }; }; // namespace Tests /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(Tests::ManagerTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // ManagerTests_cpp
1152  RTC::NamingManager nmgr(m_mgr);
1153  const char* name_server = "localhost:2809";
1154  nmgr.registerNameServer("corba", name_server);
1155 
1156  // 正しくコンポーネントを生成できるか?
1157  RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory");
1158 
1159  CPPUNIT_ASSERT(comp != NULL);
1160  CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL);
1161  CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this()));
1162  CPPUNIT_ASSERT_EQUAL(
1163  std::string("DataFlowComponent0"), // ※末尾の0はNumberingPolicyにより付加される std::string(comp->getInstanceName())); // コンポーネントに、意図どおりExecutionContextがアタッチされているか? RTC::ExecutionContextList* ecList = comp->get_owned_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length()); // cleanupComponent()により、正しく登録解除されるか? // - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか? // - 登録したコンポーネントが、Managerから正しく登録解除されるか? CPPUNIT_ASSERT(!canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT_EQUAL(comp, m_mgr->getComponent("DataFlowComponent0")); m_mgr->cleanupComponent(comp); CPPUNIT_ASSERT(! canResolve(name_server, "DataFlowComponent0", "rtc")); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); comp->exit(); usleep(10000); m_mgr->terminate(); } void test_unregisterComponent() { // Manager::cleanupComponent()内で使用されているので、ここではテスト省略する } void test_bindExecutionContext() { // Manager::createComponent()内で使用されているので、ここではテスト省略する } void test_getComponent() { // 他テスト内で使用されているので、そちらで兼ねるものとして、ここではテスト省略する } /*! * @brief getComponents()メソッドのテスト * * - getComponents()で、生成したすべてのコンポーネントを取得できるか? * - 登録解除したコンポーネントが、正しく一覧から除外されているか? */ void test_getComponents() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 複数のコンポーネントを生成しておく RTC::RtcBase* comp1 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp1 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp1) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp1->_this())); RTC::RtcBase* comp2 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp2 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp2) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp2->_this())); CPPUNIT_ASSERT(comp1 != comp2); // getComponents()で、生成したすべてのコンポーネントを取得できるか? std::vector<RTC::RtcBase*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT_EQUAL(2, (int) comps.size()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) != comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); // コンポーネントを1つだけ登録解除した場合、解除したものが一覧から除外されているか? m_mgr->cleanupComponent(comp1); comps = m_mgr->getComponents(); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) == comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); comp1->exit(); comp2->exit(); m_mgr->terminate(); } void test_getORB() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOA() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOAManager() { // 他テスト内で使用されているので、ここではテスト省略する } /*! * @brief initFactories()メソッドのテスト * * - init()実行後、initFactories()の実行結果としてFactoryMapに正しく登録されているか? */ void test_initFactories() { // init()の中でinitFactories()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initFactories()の実行結果としてFactoryMapに正しく登録されているか? bool bret = RTC::CdrBufferFactory::instance().hasFactory("ring_buffer"); CPPUNIT_ASSERT(bret); bret = RTC::PeriodicTaskFactory::instance().hasFactory("default"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("flush"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("new"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("periodic"); CPPUNIT_ASSERT(bret); RTC::InPortProviderFactory& factory1(RTC::InPortProviderFactory::instance()); bret = factory1.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::InPortConsumerFactory& factory2(RTC::InPortConsumerFactory::instance()); bret = factory2.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortConsumerFactory& factory3(RTC::OutPortConsumerFactory::instance()); bret = factory3.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortProviderFactory& factory4(RTC::OutPortProviderFactory::instance()); bret = factory4.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); } /*! * @brief initComposite()メソッドのテスト * * - init()実行後、initComposite()の実行結果としてFactoryManagerに正しく登録されているか? */ void test_initComposite() { // init()の中でinitComposite()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initComposite()の実行結果としてFactoryManagerに正しく登録されているか? // "implementation_id"には, "PeriodicECSharedComposite"が設定されている CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "PeriodicECSharedComposite")); } /*! * @brief procContextArgs()メソッドのテスト * * - 引数ec_argsにより戻り値true・falseが正しく返却されるか? */ void test_procContextArgs() { std::string ec_args; std::string ec_id; coil::Properties ec_prop; // インスタンス生成 ManagerTestMock* man = new ManagerTestMock(); // falseを返すケース1:ec_args.size=0 ec_args = ""; bool bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース2:ec_args.size=3 ec_args = "periodic?rate=1000?policy=skip"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース3:ec_args[0].empty ec_args = "?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // trueを返すケース4:ec_args.size=2 ec_args = "periodic?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(bret); std::string chk_val("periodic"); CPPUNIT_ASSERT_EQUAL(chk_val, ec_id); chk_val = "1000"; CPPUNIT_ASSERT_EQUAL(chk_val, ec_prop["rate"]); delete man; } /*! * @brief getLogLevel()メソッドのテスト * * - log_levelが正しく返却されるか? */ void test_getLogLevel() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); std::string log_level = m_mgr->getLogLevel(); CPPUNIT_ASSERT_EQUAL(std::string("INFO"), log_level); } /*! * @brief getLoadedModules()メソッドのテスト * * - ロード済みのモジュールリストを正しく取得できるか? */ void test_getLoadedModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); /* FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード済みのモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadedModules(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string(".//./.libs/DummyModule.so"), props[0].getProperty("file_path")); */ } /*! * @brief getFactoryProfiles()メソッドのテスト * * - RTコンポーネント用ファクトリをリストを正しく取得できるか? */ void test_getFactoryProfiles() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); std::vector<coil::Properties> props = m_mgr->getFactoryProfiles(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string("PeriodicECSharedComposite"), props[0].getProperty("implementation_id")); CPPUNIT_ASSERT_EQUAL(std::string("ID"), props[1].getProperty("implementation_id")); } /*! * @brief createContext()メソッドのテスト * * - ExecutionContextBaseを正しく取得できるか? */ void test_createContext() { RTC::ExecutionContextBase* ec; std::string ec_args; m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // return NULL check ec_args = ""; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return NULL check (Factory not found) ec_args = "periodic?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return any check m_mgr->registerECFactory("PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>); ec_args = "PeriodicEC?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec != NULL); } /*! * @brief deleteComponent()メソッドのテスト * * - RTコンポーネントの削除が正しくできるか? */ void test_deleteComponent() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), std::string(comp->getInstanceName())); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") != NULL); std::vector<RTC::RTObject_impl*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT(comps.size() > 0); // 正しくコンポーネントを削除できるか? m_mgr->deleteComponent("DataFlowComponent0"); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); // deleteComponent()でexit()を実行しているため、これ以降のテストはできません。 } /*! * @brief init()、shutdown()から呼ばれるprotected関数のテスト * * - protected関数が正しく動作しているか? */ void test_init2() { // Manager::init()よりprotected関数が使用されているので、ここではテスト省略する // initManager() // initLogger() // initORB() // initNaming() // initFactories() // initExecContext() // initComposite() // initTimer() // initManagerServant() // Manager::shutdown()よりprotected関数が使用されているので、ここではテスト省略する // shutdownComponents(); // shutdownNaming(); // shutdownORB(); // shutdownManager(); // shutdownLogger(); } }; }; // namespace Tests /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(Tests::ManagerTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // ManagerTests_cpp
1164  std::string(comp->getInstanceName()));
1165 
1166  // コンポーネントに、意図どおりExecutionContextがアタッチされているか?
1168  CPPUNIT_ASSERT(ecList != NULL);
1169  CPPUNIT_ASSERT_EQUAL(1, (int) ecList->length());
1170 
1171  // cleanupComponent()により、正しく登録解除されるか?
1172  // - 登録したコンポーネントが、ネームサービスから正しく登録解除されるか?
1173  // - 登録したコンポーネントが、Managerから正しく登録解除されるか?
1174  CPPUNIT_ASSERT(!canResolve(name_server, "DataFlowComponent0", "rtc"));
1175  CPPUNIT_ASSERT_EQUAL(comp, m_mgr->getComponent("DataFlowComponent0"));
1176 
1177  m_mgr->cleanupComponent(comp);
1178  CPPUNIT_ASSERT(! canResolve(name_server, "DataFlowComponent0", "rtc"));
1179  CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL);
1180 
1181  comp->exit();
1182  usleep(10000);
1183  m_mgr->terminate();
1184 
1185  }
1186 
1188  {
1189  // Manager::cleanupComponent()内で使用されているので、ここではテスト省略する } void test_bindExecutionContext() { // Manager::createComponent()内で使用されているので、ここではテスト省略する } void test_getComponent() { // 他テスト内で使用されているので、そちらで兼ねるものとして、ここではテスト省略する } /*! * @brief getComponents()メソッドのテスト * * - getComponents()で、生成したすべてのコンポーネントを取得できるか? * - 登録解除したコンポーネントが、正しく一覧から除外されているか? */ void test_getComponents() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 複数のコンポーネントを生成しておく RTC::RtcBase* comp1 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp1 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp1) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp1->_this())); RTC::RtcBase* comp2 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp2 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp2) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp2->_this())); CPPUNIT_ASSERT(comp1 != comp2); // getComponents()で、生成したすべてのコンポーネントを取得できるか? std::vector<RTC::RtcBase*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT_EQUAL(2, (int) comps.size()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) != comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); // コンポーネントを1つだけ登録解除した場合、解除したものが一覧から除外されているか? m_mgr->cleanupComponent(comp1); comps = m_mgr->getComponents(); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) == comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); comp1->exit(); comp2->exit(); m_mgr->terminate(); } void test_getORB() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOA() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOAManager() { // 他テスト内で使用されているので、ここではテスト省略する } /*! * @brief initFactories()メソッドのテスト * * - init()実行後、initFactories()の実行結果としてFactoryMapに正しく登録されているか? */ void test_initFactories() { // init()の中でinitFactories()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initFactories()の実行結果としてFactoryMapに正しく登録されているか? bool bret = RTC::CdrBufferFactory::instance().hasFactory("ring_buffer"); CPPUNIT_ASSERT(bret); bret = RTC::PeriodicTaskFactory::instance().hasFactory("default"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("flush"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("new"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("periodic"); CPPUNIT_ASSERT(bret); RTC::InPortProviderFactory& factory1(RTC::InPortProviderFactory::instance()); bret = factory1.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::InPortConsumerFactory& factory2(RTC::InPortConsumerFactory::instance()); bret = factory2.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortConsumerFactory& factory3(RTC::OutPortConsumerFactory::instance()); bret = factory3.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortProviderFactory& factory4(RTC::OutPortProviderFactory::instance()); bret = factory4.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); } /*! * @brief initComposite()メソッドのテスト * * - init()実行後、initComposite()の実行結果としてFactoryManagerに正しく登録されているか? */ void test_initComposite() { // init()の中でinitComposite()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initComposite()の実行結果としてFactoryManagerに正しく登録されているか? // "implementation_id"には, "PeriodicECSharedComposite"が設定されている CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "PeriodicECSharedComposite")); } /*! * @brief procContextArgs()メソッドのテスト * * - 引数ec_argsにより戻り値true・falseが正しく返却されるか? */ void test_procContextArgs() { std::string ec_args; std::string ec_id; coil::Properties ec_prop; // インスタンス生成 ManagerTestMock* man = new ManagerTestMock(); // falseを返すケース1:ec_args.size=0 ec_args = ""; bool bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース2:ec_args.size=3 ec_args = "periodic?rate=1000?policy=skip"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース3:ec_args[0].empty ec_args = "?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // trueを返すケース4:ec_args.size=2 ec_args = "periodic?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(bret); std::string chk_val("periodic"); CPPUNIT_ASSERT_EQUAL(chk_val, ec_id); chk_val = "1000"; CPPUNIT_ASSERT_EQUAL(chk_val, ec_prop["rate"]); delete man; } /*! * @brief getLogLevel()メソッドのテスト * * - log_levelが正しく返却されるか? */ void test_getLogLevel() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); std::string log_level = m_mgr->getLogLevel(); CPPUNIT_ASSERT_EQUAL(std::string("INFO"), log_level); } /*! * @brief getLoadedModules()メソッドのテスト * * - ロード済みのモジュールリストを正しく取得できるか? */ void test_getLoadedModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); /* FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード済みのモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadedModules(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string(".//./.libs/DummyModule.so"), props[0].getProperty("file_path")); */ } /*! * @brief getFactoryProfiles()メソッドのテスト * * - RTコンポーネント用ファクトリをリストを正しく取得できるか? */ void test_getFactoryProfiles() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); std::vector<coil::Properties> props = m_mgr->getFactoryProfiles(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string("PeriodicECSharedComposite"), props[0].getProperty("implementation_id")); CPPUNIT_ASSERT_EQUAL(std::string("ID"), props[1].getProperty("implementation_id")); } /*! * @brief createContext()メソッドのテスト * * - ExecutionContextBaseを正しく取得できるか? */ void test_createContext() { RTC::ExecutionContextBase* ec; std::string ec_args; m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // return NULL check ec_args = ""; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return NULL check (Factory not found) ec_args = "periodic?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return any check m_mgr->registerECFactory("PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>); ec_args = "PeriodicEC?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec != NULL); } /*! * @brief deleteComponent()メソッドのテスト * * - RTコンポーネントの削除が正しくできるか? */ void test_deleteComponent() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), std::string(comp->getInstanceName())); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") != NULL); std::vector<RTC::RTObject_impl*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT(comps.size() > 0); // 正しくコンポーネントを削除できるか? m_mgr->deleteComponent("DataFlowComponent0"); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); // deleteComponent()でexit()を実行しているため、これ以降のテストはできません。 } /*! * @brief init()、shutdown()から呼ばれるprotected関数のテスト * * - protected関数が正しく動作しているか? */ void test_init2() { // Manager::init()よりprotected関数が使用されているので、ここではテスト省略する // initManager() // initLogger() // initORB() // initNaming() // initFactories() // initExecContext() // initComposite() // initTimer() // initManagerServant() // Manager::shutdown()よりprotected関数が使用されているので、ここではテスト省略する // shutdownComponents(); // shutdownNaming(); // shutdownORB(); // shutdownManager(); // shutdownLogger(); } }; }; // namespace Tests /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(Tests::ManagerTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // ManagerTests_cpp
1190  }
1191 
1193  {
1194  // Manager::createComponent()内で使用されているので、ここではテスト省略する } void test_getComponent() { // 他テスト内で使用されているので、そちらで兼ねるものとして、ここではテスト省略する } /*! * @brief getComponents()メソッドのテスト * * - getComponents()で、生成したすべてのコンポーネントを取得できるか? * - 登録解除したコンポーネントが、正しく一覧から除外されているか? */ void test_getComponents() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 複数のコンポーネントを生成しておく RTC::RtcBase* comp1 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp1 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp1) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp1->_this())); RTC::RtcBase* comp2 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp2 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp2) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp2->_this())); CPPUNIT_ASSERT(comp1 != comp2); // getComponents()で、生成したすべてのコンポーネントを取得できるか? std::vector<RTC::RtcBase*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT_EQUAL(2, (int) comps.size()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) != comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); // コンポーネントを1つだけ登録解除した場合、解除したものが一覧から除外されているか? m_mgr->cleanupComponent(comp1); comps = m_mgr->getComponents(); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) == comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); comp1->exit(); comp2->exit(); m_mgr->terminate(); } void test_getORB() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOA() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOAManager() { // 他テスト内で使用されているので、ここではテスト省略する } /*! * @brief initFactories()メソッドのテスト * * - init()実行後、initFactories()の実行結果としてFactoryMapに正しく登録されているか? */ void test_initFactories() { // init()の中でinitFactories()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initFactories()の実行結果としてFactoryMapに正しく登録されているか? bool bret = RTC::CdrBufferFactory::instance().hasFactory("ring_buffer"); CPPUNIT_ASSERT(bret); bret = RTC::PeriodicTaskFactory::instance().hasFactory("default"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("flush"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("new"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("periodic"); CPPUNIT_ASSERT(bret); RTC::InPortProviderFactory& factory1(RTC::InPortProviderFactory::instance()); bret = factory1.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::InPortConsumerFactory& factory2(RTC::InPortConsumerFactory::instance()); bret = factory2.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortConsumerFactory& factory3(RTC::OutPortConsumerFactory::instance()); bret = factory3.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortProviderFactory& factory4(RTC::OutPortProviderFactory::instance()); bret = factory4.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); } /*! * @brief initComposite()メソッドのテスト * * - init()実行後、initComposite()の実行結果としてFactoryManagerに正しく登録されているか? */ void test_initComposite() { // init()の中でinitComposite()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initComposite()の実行結果としてFactoryManagerに正しく登録されているか? // "implementation_id"には, "PeriodicECSharedComposite"が設定されている CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "PeriodicECSharedComposite")); } /*! * @brief procContextArgs()メソッドのテスト * * - 引数ec_argsにより戻り値true・falseが正しく返却されるか? */ void test_procContextArgs() { std::string ec_args; std::string ec_id; coil::Properties ec_prop; // インスタンス生成 ManagerTestMock* man = new ManagerTestMock(); // falseを返すケース1:ec_args.size=0 ec_args = ""; bool bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース2:ec_args.size=3 ec_args = "periodic?rate=1000?policy=skip"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース3:ec_args[0].empty ec_args = "?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // trueを返すケース4:ec_args.size=2 ec_args = "periodic?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(bret); std::string chk_val("periodic"); CPPUNIT_ASSERT_EQUAL(chk_val, ec_id); chk_val = "1000"; CPPUNIT_ASSERT_EQUAL(chk_val, ec_prop["rate"]); delete man; } /*! * @brief getLogLevel()メソッドのテスト * * - log_levelが正しく返却されるか? */ void test_getLogLevel() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); std::string log_level = m_mgr->getLogLevel(); CPPUNIT_ASSERT_EQUAL(std::string("INFO"), log_level); } /*! * @brief getLoadedModules()メソッドのテスト * * - ロード済みのモジュールリストを正しく取得できるか? */ void test_getLoadedModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); /* FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード済みのモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadedModules(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string(".//./.libs/DummyModule.so"), props[0].getProperty("file_path")); */ } /*! * @brief getFactoryProfiles()メソッドのテスト * * - RTコンポーネント用ファクトリをリストを正しく取得できるか? */ void test_getFactoryProfiles() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); std::vector<coil::Properties> props = m_mgr->getFactoryProfiles(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string("PeriodicECSharedComposite"), props[0].getProperty("implementation_id")); CPPUNIT_ASSERT_EQUAL(std::string("ID"), props[1].getProperty("implementation_id")); } /*! * @brief createContext()メソッドのテスト * * - ExecutionContextBaseを正しく取得できるか? */ void test_createContext() { RTC::ExecutionContextBase* ec; std::string ec_args; m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // return NULL check ec_args = ""; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return NULL check (Factory not found) ec_args = "periodic?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return any check m_mgr->registerECFactory("PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>); ec_args = "PeriodicEC?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec != NULL); } /*! * @brief deleteComponent()メソッドのテスト * * - RTコンポーネントの削除が正しくできるか? */ void test_deleteComponent() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), std::string(comp->getInstanceName())); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") != NULL); std::vector<RTC::RTObject_impl*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT(comps.size() > 0); // 正しくコンポーネントを削除できるか? m_mgr->deleteComponent("DataFlowComponent0"); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); // deleteComponent()でexit()を実行しているため、これ以降のテストはできません。 } /*! * @brief init()、shutdown()から呼ばれるprotected関数のテスト * * - protected関数が正しく動作しているか? */ void test_init2() { // Manager::init()よりprotected関数が使用されているので、ここではテスト省略する // initManager() // initLogger() // initORB() // initNaming() // initFactories() // initExecContext() // initComposite() // initTimer() // initManagerServant() // Manager::shutdown()よりprotected関数が使用されているので、ここではテスト省略する // shutdownComponents(); // shutdownNaming(); // shutdownORB(); // shutdownManager(); // shutdownLogger(); } }; }; // namespace Tests /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(Tests::ManagerTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // ManagerTests_cpp
1195  }
1196 
1198  {
1199  // 他テスト内で使用されているので、そちらで兼ねるものとして、ここではテスト省略する } /*! * @brief getComponents()メソッドのテスト * * - getComponents()で、生成したすべてのコンポーネントを取得できるか? * - 登録解除したコンポーネントが、正しく一覧から除外されているか? */ void test_getComponents() { // 初期化を行う int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 複数のコンポーネントを生成しておく RTC::RtcBase* comp1 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp1 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp1) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp1->_this())); RTC::RtcBase* comp2 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp2 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp2) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp2->_this())); CPPUNIT_ASSERT(comp1 != comp2); // getComponents()で、生成したすべてのコンポーネントを取得できるか? std::vector<RTC::RtcBase*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT_EQUAL(2, (int) comps.size()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) != comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); // コンポーネントを1つだけ登録解除した場合、解除したものが一覧から除外されているか? m_mgr->cleanupComponent(comp1); comps = m_mgr->getComponents(); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) == comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); comp1->exit(); comp2->exit(); m_mgr->terminate(); } void test_getORB() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOA() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOAManager() { // 他テスト内で使用されているので、ここではテスト省略する } /*! * @brief initFactories()メソッドのテスト * * - init()実行後、initFactories()の実行結果としてFactoryMapに正しく登録されているか? */ void test_initFactories() { // init()の中でinitFactories()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initFactories()の実行結果としてFactoryMapに正しく登録されているか? bool bret = RTC::CdrBufferFactory::instance().hasFactory("ring_buffer"); CPPUNIT_ASSERT(bret); bret = RTC::PeriodicTaskFactory::instance().hasFactory("default"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("flush"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("new"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("periodic"); CPPUNIT_ASSERT(bret); RTC::InPortProviderFactory& factory1(RTC::InPortProviderFactory::instance()); bret = factory1.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::InPortConsumerFactory& factory2(RTC::InPortConsumerFactory::instance()); bret = factory2.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortConsumerFactory& factory3(RTC::OutPortConsumerFactory::instance()); bret = factory3.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortProviderFactory& factory4(RTC::OutPortProviderFactory::instance()); bret = factory4.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); } /*! * @brief initComposite()メソッドのテスト * * - init()実行後、initComposite()の実行結果としてFactoryManagerに正しく登録されているか? */ void test_initComposite() { // init()の中でinitComposite()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initComposite()の実行結果としてFactoryManagerに正しく登録されているか? // "implementation_id"には, "PeriodicECSharedComposite"が設定されている CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "PeriodicECSharedComposite")); } /*! * @brief procContextArgs()メソッドのテスト * * - 引数ec_argsにより戻り値true・falseが正しく返却されるか? */ void test_procContextArgs() { std::string ec_args; std::string ec_id; coil::Properties ec_prop; // インスタンス生成 ManagerTestMock* man = new ManagerTestMock(); // falseを返すケース1:ec_args.size=0 ec_args = ""; bool bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース2:ec_args.size=3 ec_args = "periodic?rate=1000?policy=skip"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース3:ec_args[0].empty ec_args = "?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // trueを返すケース4:ec_args.size=2 ec_args = "periodic?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(bret); std::string chk_val("periodic"); CPPUNIT_ASSERT_EQUAL(chk_val, ec_id); chk_val = "1000"; CPPUNIT_ASSERT_EQUAL(chk_val, ec_prop["rate"]); delete man; } /*! * @brief getLogLevel()メソッドのテスト * * - log_levelが正しく返却されるか? */ void test_getLogLevel() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); std::string log_level = m_mgr->getLogLevel(); CPPUNIT_ASSERT_EQUAL(std::string("INFO"), log_level); } /*! * @brief getLoadedModules()メソッドのテスト * * - ロード済みのモジュールリストを正しく取得できるか? */ void test_getLoadedModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); /* FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード済みのモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadedModules(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string(".//./.libs/DummyModule.so"), props[0].getProperty("file_path")); */ } /*! * @brief getFactoryProfiles()メソッドのテスト * * - RTコンポーネント用ファクトリをリストを正しく取得できるか? */ void test_getFactoryProfiles() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); std::vector<coil::Properties> props = m_mgr->getFactoryProfiles(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string("PeriodicECSharedComposite"), props[0].getProperty("implementation_id")); CPPUNIT_ASSERT_EQUAL(std::string("ID"), props[1].getProperty("implementation_id")); } /*! * @brief createContext()メソッドのテスト * * - ExecutionContextBaseを正しく取得できるか? */ void test_createContext() { RTC::ExecutionContextBase* ec; std::string ec_args; m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // return NULL check ec_args = ""; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return NULL check (Factory not found) ec_args = "periodic?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return any check m_mgr->registerECFactory("PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>); ec_args = "PeriodicEC?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec != NULL); } /*! * @brief deleteComponent()メソッドのテスト * * - RTコンポーネントの削除が正しくできるか? */ void test_deleteComponent() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), std::string(comp->getInstanceName())); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") != NULL); std::vector<RTC::RTObject_impl*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT(comps.size() > 0); // 正しくコンポーネントを削除できるか? m_mgr->deleteComponent("DataFlowComponent0"); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); // deleteComponent()でexit()を実行しているため、これ以降のテストはできません。 } /*! * @brief init()、shutdown()から呼ばれるprotected関数のテスト * * - protected関数が正しく動作しているか? */ void test_init2() { // Manager::init()よりprotected関数が使用されているので、ここではテスト省略する // initManager() // initLogger() // initORB() // initNaming() // initFactories() // initExecContext() // initComposite() // initTimer() // initManagerServant() // Manager::shutdown()よりprotected関数が使用されているので、ここではテスト省略する // shutdownComponents(); // shutdownNaming(); // shutdownORB(); // shutdownManager(); // shutdownLogger(); } }; }; // namespace Tests /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(Tests::ManagerTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // ManagerTests_cpp
1200  }
1201 
1209  {
1210  // 初期化を行う
1211  int argc = 3;
1212  char* argv[] = { "ManagerTests","-f","fixture4.conf" };
1213 
1214  m_mgr = RTC::Manager::init(argc, argv);
1215  CPPUNIT_ASSERT(m_mgr != NULL);
1216  CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB()));
1217  CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA()));
1218  CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager()));
1219 
1220  // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 複数のコンポーネントを生成しておく RTC::RtcBase* comp1 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp1 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp1) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp1->_this())); RTC::RtcBase* comp2 = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp2 != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp2) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp2->_this())); CPPUNIT_ASSERT(comp1 != comp2); // getComponents()で、生成したすべてのコンポーネントを取得できるか? std::vector<RTC::RtcBase*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT_EQUAL(2, (int) comps.size()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) != comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); // コンポーネントを1つだけ登録解除した場合、解除したものが一覧から除外されているか? m_mgr->cleanupComponent(comp1); comps = m_mgr->getComponents(); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) == comps.end()); CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end()); comp1->exit(); comp2->exit(); m_mgr->terminate(); } void test_getORB() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOA() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOAManager() { // 他テスト内で使用されているので、ここではテスト省略する } /*! * @brief initFactories()メソッドのテスト * * - init()実行後、initFactories()の実行結果としてFactoryMapに正しく登録されているか? */ void test_initFactories() { // init()の中でinitFactories()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initFactories()の実行結果としてFactoryMapに正しく登録されているか? bool bret = RTC::CdrBufferFactory::instance().hasFactory("ring_buffer"); CPPUNIT_ASSERT(bret); bret = RTC::PeriodicTaskFactory::instance().hasFactory("default"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("flush"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("new"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("periodic"); CPPUNIT_ASSERT(bret); RTC::InPortProviderFactory& factory1(RTC::InPortProviderFactory::instance()); bret = factory1.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::InPortConsumerFactory& factory2(RTC::InPortConsumerFactory::instance()); bret = factory2.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortConsumerFactory& factory3(RTC::OutPortConsumerFactory::instance()); bret = factory3.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortProviderFactory& factory4(RTC::OutPortProviderFactory::instance()); bret = factory4.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); } /*! * @brief initComposite()メソッドのテスト * * - init()実行後、initComposite()の実行結果としてFactoryManagerに正しく登録されているか? */ void test_initComposite() { // init()の中でinitComposite()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initComposite()の実行結果としてFactoryManagerに正しく登録されているか? // "implementation_id"には, "PeriodicECSharedComposite"が設定されている CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "PeriodicECSharedComposite")); } /*! * @brief procContextArgs()メソッドのテスト * * - 引数ec_argsにより戻り値true・falseが正しく返却されるか? */ void test_procContextArgs() { std::string ec_args; std::string ec_id; coil::Properties ec_prop; // インスタンス生成 ManagerTestMock* man = new ManagerTestMock(); // falseを返すケース1:ec_args.size=0 ec_args = ""; bool bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース2:ec_args.size=3 ec_args = "periodic?rate=1000?policy=skip"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース3:ec_args[0].empty ec_args = "?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // trueを返すケース4:ec_args.size=2 ec_args = "periodic?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(bret); std::string chk_val("periodic"); CPPUNIT_ASSERT_EQUAL(chk_val, ec_id); chk_val = "1000"; CPPUNIT_ASSERT_EQUAL(chk_val, ec_prop["rate"]); delete man; } /*! * @brief getLogLevel()メソッドのテスト * * - log_levelが正しく返却されるか? */ void test_getLogLevel() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); std::string log_level = m_mgr->getLogLevel(); CPPUNIT_ASSERT_EQUAL(std::string("INFO"), log_level); } /*! * @brief getLoadedModules()メソッドのテスト * * - ロード済みのモジュールリストを正しく取得できるか? */ void test_getLoadedModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); /* FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード済みのモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadedModules(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string(".//./.libs/DummyModule.so"), props[0].getProperty("file_path")); */ } /*! * @brief getFactoryProfiles()メソッドのテスト * * - RTコンポーネント用ファクトリをリストを正しく取得できるか? */ void test_getFactoryProfiles() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); std::vector<coil::Properties> props = m_mgr->getFactoryProfiles(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string("PeriodicECSharedComposite"), props[0].getProperty("implementation_id")); CPPUNIT_ASSERT_EQUAL(std::string("ID"), props[1].getProperty("implementation_id")); } /*! * @brief createContext()メソッドのテスト * * - ExecutionContextBaseを正しく取得できるか? */ void test_createContext() { RTC::ExecutionContextBase* ec; std::string ec_args; m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // return NULL check ec_args = ""; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return NULL check (Factory not found) ec_args = "periodic?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return any check m_mgr->registerECFactory("PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>); ec_args = "PeriodicEC?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec != NULL); } /*! * @brief deleteComponent()メソッドのテスト * * - RTコンポーネントの削除が正しくできるか? */ void test_deleteComponent() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), std::string(comp->getInstanceName())); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") != NULL); std::vector<RTC::RTObject_impl*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT(comps.size() > 0); // 正しくコンポーネントを削除できるか? m_mgr->deleteComponent("DataFlowComponent0"); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); // deleteComponent()でexit()を実行しているため、これ以降のテストはできません。 } /*! * @brief init()、shutdown()から呼ばれるprotected関数のテスト * * - protected関数が正しく動作しているか? */ void test_init2() { // Manager::init()よりprotected関数が使用されているので、ここではテスト省略する // initManager() // initLogger() // initORB() // initNaming() // initFactories() // initExecContext() // initComposite() // initTimer() // initManagerServant() // Manager::shutdown()よりprotected関数が使用されているので、ここではテスト省略する // shutdownComponents(); // shutdownNaming(); // shutdownORB(); // shutdownManager(); // shutdownLogger(); } }; }; // namespace Tests /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(Tests::ManagerTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // ManagerTests_cpp
1221  CPPUNIT_ASSERT(m_mgr->activateManager());
1222  m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング
1223 
1224  // Factoryを登録しておく
1225  coil::Properties properties;
1226  properties.setProperty("implementation_id", "DataFlowComponentFactory");
1227  properties.setProperty("type_name", "DataFlowComponent");
1228  CPPUNIT_ASSERT(m_mgr->registerFactory(
1230 
1231  // ECFactoryを登録しておく
1232  CPPUNIT_ASSERT(m_mgr->registerECFactory(
1233  "PeriodicEC",
1234  RTC::ECCreate<RTC::PeriodicExecutionContext>,
1235  RTC::ECDelete<RTC::PeriodicExecutionContext>));
1236 
1237  // 複数のコンポーネントを生成しておく
1238  RTC::RtcBase* comp1 = m_mgr->createComponent("DataFlowComponentFactory");
1239  CPPUNIT_ASSERT(comp1 != NULL);
1240  CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp1) != NULL);
1241  CPPUNIT_ASSERT(! CORBA::is_nil(comp1->_this()));
1242 
1243  RTC::RtcBase* comp2 = m_mgr->createComponent("DataFlowComponentFactory");
1244  CPPUNIT_ASSERT(comp2 != NULL);
1245  CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp2) != NULL);
1246  CPPUNIT_ASSERT(! CORBA::is_nil(comp2->_this()));
1247 
1248  CPPUNIT_ASSERT(comp1 != comp2);
1249 
1250  // getComponents()で、生成したすべてのコンポーネントを取得できるか?
1251  std::vector<RTC::RtcBase*> comps = m_mgr->getComponents();
1252  CPPUNIT_ASSERT_EQUAL(2, (int) comps.size());
1253  CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) != comps.end());
1254  CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end());
1255 
1256  // コンポーネントを1つだけ登録解除した場合、解除したものが一覧から除外されているか?
1257  m_mgr->cleanupComponent(comp1);
1258  comps = m_mgr->getComponents();
1259  CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp1) == comps.end());
1260  CPPUNIT_ASSERT(std::find(comps.begin(), comps.end(), comp2) != comps.end());
1261 
1262  comp1->exit();
1263  comp2->exit();
1264  m_mgr->terminate();
1265  }
1266 
1268  {
1269  // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOA() { // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOAManager() { // 他テスト内で使用されているので、ここではテスト省略する } /*! * @brief initFactories()メソッドのテスト * * - init()実行後、initFactories()の実行結果としてFactoryMapに正しく登録されているか? */ void test_initFactories() { // init()の中でinitFactories()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initFactories()の実行結果としてFactoryMapに正しく登録されているか? bool bret = RTC::CdrBufferFactory::instance().hasFactory("ring_buffer"); CPPUNIT_ASSERT(bret); bret = RTC::PeriodicTaskFactory::instance().hasFactory("default"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("flush"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("new"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("periodic"); CPPUNIT_ASSERT(bret); RTC::InPortProviderFactory& factory1(RTC::InPortProviderFactory::instance()); bret = factory1.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::InPortConsumerFactory& factory2(RTC::InPortConsumerFactory::instance()); bret = factory2.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortConsumerFactory& factory3(RTC::OutPortConsumerFactory::instance()); bret = factory3.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortProviderFactory& factory4(RTC::OutPortProviderFactory::instance()); bret = factory4.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); } /*! * @brief initComposite()メソッドのテスト * * - init()実行後、initComposite()の実行結果としてFactoryManagerに正しく登録されているか? */ void test_initComposite() { // init()の中でinitComposite()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initComposite()の実行結果としてFactoryManagerに正しく登録されているか? // "implementation_id"には, "PeriodicECSharedComposite"が設定されている CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "PeriodicECSharedComposite")); } /*! * @brief procContextArgs()メソッドのテスト * * - 引数ec_argsにより戻り値true・falseが正しく返却されるか? */ void test_procContextArgs() { std::string ec_args; std::string ec_id; coil::Properties ec_prop; // インスタンス生成 ManagerTestMock* man = new ManagerTestMock(); // falseを返すケース1:ec_args.size=0 ec_args = ""; bool bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース2:ec_args.size=3 ec_args = "periodic?rate=1000?policy=skip"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース3:ec_args[0].empty ec_args = "?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // trueを返すケース4:ec_args.size=2 ec_args = "periodic?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(bret); std::string chk_val("periodic"); CPPUNIT_ASSERT_EQUAL(chk_val, ec_id); chk_val = "1000"; CPPUNIT_ASSERT_EQUAL(chk_val, ec_prop["rate"]); delete man; } /*! * @brief getLogLevel()メソッドのテスト * * - log_levelが正しく返却されるか? */ void test_getLogLevel() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); std::string log_level = m_mgr->getLogLevel(); CPPUNIT_ASSERT_EQUAL(std::string("INFO"), log_level); } /*! * @brief getLoadedModules()メソッドのテスト * * - ロード済みのモジュールリストを正しく取得できるか? */ void test_getLoadedModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); /* FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード済みのモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadedModules(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string(".//./.libs/DummyModule.so"), props[0].getProperty("file_path")); */ } /*! * @brief getFactoryProfiles()メソッドのテスト * * - RTコンポーネント用ファクトリをリストを正しく取得できるか? */ void test_getFactoryProfiles() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); std::vector<coil::Properties> props = m_mgr->getFactoryProfiles(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string("PeriodicECSharedComposite"), props[0].getProperty("implementation_id")); CPPUNIT_ASSERT_EQUAL(std::string("ID"), props[1].getProperty("implementation_id")); } /*! * @brief createContext()メソッドのテスト * * - ExecutionContextBaseを正しく取得できるか? */ void test_createContext() { RTC::ExecutionContextBase* ec; std::string ec_args; m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // return NULL check ec_args = ""; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return NULL check (Factory not found) ec_args = "periodic?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return any check m_mgr->registerECFactory("PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>); ec_args = "PeriodicEC?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec != NULL); } /*! * @brief deleteComponent()メソッドのテスト * * - RTコンポーネントの削除が正しくできるか? */ void test_deleteComponent() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), std::string(comp->getInstanceName())); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") != NULL); std::vector<RTC::RTObject_impl*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT(comps.size() > 0); // 正しくコンポーネントを削除できるか? m_mgr->deleteComponent("DataFlowComponent0"); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); // deleteComponent()でexit()を実行しているため、これ以降のテストはできません。 } /*! * @brief init()、shutdown()から呼ばれるprotected関数のテスト * * - protected関数が正しく動作しているか? */ void test_init2() { // Manager::init()よりprotected関数が使用されているので、ここではテスト省略する // initManager() // initLogger() // initORB() // initNaming() // initFactories() // initExecContext() // initComposite() // initTimer() // initManagerServant() // Manager::shutdown()よりprotected関数が使用されているので、ここではテスト省略する // shutdownComponents(); // shutdownNaming(); // shutdownORB(); // shutdownManager(); // shutdownLogger(); } }; }; // namespace Tests /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(Tests::ManagerTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // ManagerTests_cpp
1270  }
1271 
1273  {
1274  // 他テスト内で使用されているので、ここではテスト省略する } void test_getPOAManager() { // 他テスト内で使用されているので、ここではテスト省略する } /*! * @brief initFactories()メソッドのテスト * * - init()実行後、initFactories()の実行結果としてFactoryMapに正しく登録されているか? */ void test_initFactories() { // init()の中でinitFactories()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initFactories()の実行結果としてFactoryMapに正しく登録されているか? bool bret = RTC::CdrBufferFactory::instance().hasFactory("ring_buffer"); CPPUNIT_ASSERT(bret); bret = RTC::PeriodicTaskFactory::instance().hasFactory("default"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("flush"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("new"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("periodic"); CPPUNIT_ASSERT(bret); RTC::InPortProviderFactory& factory1(RTC::InPortProviderFactory::instance()); bret = factory1.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::InPortConsumerFactory& factory2(RTC::InPortConsumerFactory::instance()); bret = factory2.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortConsumerFactory& factory3(RTC::OutPortConsumerFactory::instance()); bret = factory3.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortProviderFactory& factory4(RTC::OutPortProviderFactory::instance()); bret = factory4.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); } /*! * @brief initComposite()メソッドのテスト * * - init()実行後、initComposite()の実行結果としてFactoryManagerに正しく登録されているか? */ void test_initComposite() { // init()の中でinitComposite()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initComposite()の実行結果としてFactoryManagerに正しく登録されているか? // "implementation_id"には, "PeriodicECSharedComposite"が設定されている CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "PeriodicECSharedComposite")); } /*! * @brief procContextArgs()メソッドのテスト * * - 引数ec_argsにより戻り値true・falseが正しく返却されるか? */ void test_procContextArgs() { std::string ec_args; std::string ec_id; coil::Properties ec_prop; // インスタンス生成 ManagerTestMock* man = new ManagerTestMock(); // falseを返すケース1:ec_args.size=0 ec_args = ""; bool bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース2:ec_args.size=3 ec_args = "periodic?rate=1000?policy=skip"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース3:ec_args[0].empty ec_args = "?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // trueを返すケース4:ec_args.size=2 ec_args = "periodic?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(bret); std::string chk_val("periodic"); CPPUNIT_ASSERT_EQUAL(chk_val, ec_id); chk_val = "1000"; CPPUNIT_ASSERT_EQUAL(chk_val, ec_prop["rate"]); delete man; } /*! * @brief getLogLevel()メソッドのテスト * * - log_levelが正しく返却されるか? */ void test_getLogLevel() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); std::string log_level = m_mgr->getLogLevel(); CPPUNIT_ASSERT_EQUAL(std::string("INFO"), log_level); } /*! * @brief getLoadedModules()メソッドのテスト * * - ロード済みのモジュールリストを正しく取得できるか? */ void test_getLoadedModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); /* FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード済みのモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadedModules(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string(".//./.libs/DummyModule.so"), props[0].getProperty("file_path")); */ } /*! * @brief getFactoryProfiles()メソッドのテスト * * - RTコンポーネント用ファクトリをリストを正しく取得できるか? */ void test_getFactoryProfiles() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); std::vector<coil::Properties> props = m_mgr->getFactoryProfiles(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string("PeriodicECSharedComposite"), props[0].getProperty("implementation_id")); CPPUNIT_ASSERT_EQUAL(std::string("ID"), props[1].getProperty("implementation_id")); } /*! * @brief createContext()メソッドのテスト * * - ExecutionContextBaseを正しく取得できるか? */ void test_createContext() { RTC::ExecutionContextBase* ec; std::string ec_args; m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // return NULL check ec_args = ""; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return NULL check (Factory not found) ec_args = "periodic?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return any check m_mgr->registerECFactory("PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>); ec_args = "PeriodicEC?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec != NULL); } /*! * @brief deleteComponent()メソッドのテスト * * - RTコンポーネントの削除が正しくできるか? */ void test_deleteComponent() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), std::string(comp->getInstanceName())); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") != NULL); std::vector<RTC::RTObject_impl*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT(comps.size() > 0); // 正しくコンポーネントを削除できるか? m_mgr->deleteComponent("DataFlowComponent0"); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); // deleteComponent()でexit()を実行しているため、これ以降のテストはできません。 } /*! * @brief init()、shutdown()から呼ばれるprotected関数のテスト * * - protected関数が正しく動作しているか? */ void test_init2() { // Manager::init()よりprotected関数が使用されているので、ここではテスト省略する // initManager() // initLogger() // initORB() // initNaming() // initFactories() // initExecContext() // initComposite() // initTimer() // initManagerServant() // Manager::shutdown()よりprotected関数が使用されているので、ここではテスト省略する // shutdownComponents(); // shutdownNaming(); // shutdownORB(); // shutdownManager(); // shutdownLogger(); } }; }; // namespace Tests /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(Tests::ManagerTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // ManagerTests_cpp
1275  }
1276 
1278  {
1279  // 他テスト内で使用されているので、ここではテスト省略する } /*! * @brief initFactories()メソッドのテスト * * - init()実行後、initFactories()の実行結果としてFactoryMapに正しく登録されているか? */ void test_initFactories() { // init()の中でinitFactories()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initFactories()の実行結果としてFactoryMapに正しく登録されているか? bool bret = RTC::CdrBufferFactory::instance().hasFactory("ring_buffer"); CPPUNIT_ASSERT(bret); bret = RTC::PeriodicTaskFactory::instance().hasFactory("default"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("flush"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("new"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("periodic"); CPPUNIT_ASSERT(bret); RTC::InPortProviderFactory& factory1(RTC::InPortProviderFactory::instance()); bret = factory1.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::InPortConsumerFactory& factory2(RTC::InPortConsumerFactory::instance()); bret = factory2.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortConsumerFactory& factory3(RTC::OutPortConsumerFactory::instance()); bret = factory3.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortProviderFactory& factory4(RTC::OutPortProviderFactory::instance()); bret = factory4.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); } /*! * @brief initComposite()メソッドのテスト * * - init()実行後、initComposite()の実行結果としてFactoryManagerに正しく登録されているか? */ void test_initComposite() { // init()の中でinitComposite()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initComposite()の実行結果としてFactoryManagerに正しく登録されているか? // "implementation_id"には, "PeriodicECSharedComposite"が設定されている CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "PeriodicECSharedComposite")); } /*! * @brief procContextArgs()メソッドのテスト * * - 引数ec_argsにより戻り値true・falseが正しく返却されるか? */ void test_procContextArgs() { std::string ec_args; std::string ec_id; coil::Properties ec_prop; // インスタンス生成 ManagerTestMock* man = new ManagerTestMock(); // falseを返すケース1:ec_args.size=0 ec_args = ""; bool bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース2:ec_args.size=3 ec_args = "periodic?rate=1000?policy=skip"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース3:ec_args[0].empty ec_args = "?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // trueを返すケース4:ec_args.size=2 ec_args = "periodic?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(bret); std::string chk_val("periodic"); CPPUNIT_ASSERT_EQUAL(chk_val, ec_id); chk_val = "1000"; CPPUNIT_ASSERT_EQUAL(chk_val, ec_prop["rate"]); delete man; } /*! * @brief getLogLevel()メソッドのテスト * * - log_levelが正しく返却されるか? */ void test_getLogLevel() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); std::string log_level = m_mgr->getLogLevel(); CPPUNIT_ASSERT_EQUAL(std::string("INFO"), log_level); } /*! * @brief getLoadedModules()メソッドのテスト * * - ロード済みのモジュールリストを正しく取得できるか? */ void test_getLoadedModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); /* FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード済みのモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadedModules(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string(".//./.libs/DummyModule.so"), props[0].getProperty("file_path")); */ } /*! * @brief getFactoryProfiles()メソッドのテスト * * - RTコンポーネント用ファクトリをリストを正しく取得できるか? */ void test_getFactoryProfiles() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); std::vector<coil::Properties> props = m_mgr->getFactoryProfiles(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string("PeriodicECSharedComposite"), props[0].getProperty("implementation_id")); CPPUNIT_ASSERT_EQUAL(std::string("ID"), props[1].getProperty("implementation_id")); } /*! * @brief createContext()メソッドのテスト * * - ExecutionContextBaseを正しく取得できるか? */ void test_createContext() { RTC::ExecutionContextBase* ec; std::string ec_args; m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // return NULL check ec_args = ""; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return NULL check (Factory not found) ec_args = "periodic?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return any check m_mgr->registerECFactory("PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>); ec_args = "PeriodicEC?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec != NULL); } /*! * @brief deleteComponent()メソッドのテスト * * - RTコンポーネントの削除が正しくできるか? */ void test_deleteComponent() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), std::string(comp->getInstanceName())); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") != NULL); std::vector<RTC::RTObject_impl*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT(comps.size() > 0); // 正しくコンポーネントを削除できるか? m_mgr->deleteComponent("DataFlowComponent0"); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); // deleteComponent()でexit()を実行しているため、これ以降のテストはできません。 } /*! * @brief init()、shutdown()から呼ばれるprotected関数のテスト * * - protected関数が正しく動作しているか? */ void test_init2() { // Manager::init()よりprotected関数が使用されているので、ここではテスト省略する // initManager() // initLogger() // initORB() // initNaming() // initFactories() // initExecContext() // initComposite() // initTimer() // initManagerServant() // Manager::shutdown()よりprotected関数が使用されているので、ここではテスト省略する // shutdownComponents(); // shutdownNaming(); // shutdownORB(); // shutdownManager(); // shutdownLogger(); } }; }; // namespace Tests /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(Tests::ManagerTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // ManagerTests_cpp
1280  }
1281 
1288  {
1289  // init()の中でinitFactories()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initFactories()の実行結果としてFactoryMapに正しく登録されているか? bool bret = RTC::CdrBufferFactory::instance().hasFactory("ring_buffer"); CPPUNIT_ASSERT(bret); bret = RTC::PeriodicTaskFactory::instance().hasFactory("default"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("flush"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("new"); CPPUNIT_ASSERT(bret); bret = RTC::PublisherFactory::instance().hasFactory("periodic"); CPPUNIT_ASSERT(bret); RTC::InPortProviderFactory& factory1(RTC::InPortProviderFactory::instance()); bret = factory1.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::InPortConsumerFactory& factory2(RTC::InPortConsumerFactory::instance()); bret = factory2.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortConsumerFactory& factory3(RTC::OutPortConsumerFactory::instance()); bret = factory3.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); RTC::OutPortProviderFactory& factory4(RTC::OutPortProviderFactory::instance()); bret = factory4.hasFactory("corba_cdr"); CPPUNIT_ASSERT(bret); } /*! * @brief initComposite()メソッドのテスト * * - init()実行後、initComposite()の実行結果としてFactoryManagerに正しく登録されているか? */ void test_initComposite() { // init()の中でinitComposite()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initComposite()の実行結果としてFactoryManagerに正しく登録されているか? // "implementation_id"には, "PeriodicECSharedComposite"が設定されている CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "PeriodicECSharedComposite")); } /*! * @brief procContextArgs()メソッドのテスト * * - 引数ec_argsにより戻り値true・falseが正しく返却されるか? */ void test_procContextArgs() { std::string ec_args; std::string ec_id; coil::Properties ec_prop; // インスタンス生成 ManagerTestMock* man = new ManagerTestMock(); // falseを返すケース1:ec_args.size=0 ec_args = ""; bool bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース2:ec_args.size=3 ec_args = "periodic?rate=1000?policy=skip"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース3:ec_args[0].empty ec_args = "?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // trueを返すケース4:ec_args.size=2 ec_args = "periodic?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(bret); std::string chk_val("periodic"); CPPUNIT_ASSERT_EQUAL(chk_val, ec_id); chk_val = "1000"; CPPUNIT_ASSERT_EQUAL(chk_val, ec_prop["rate"]); delete man; } /*! * @brief getLogLevel()メソッドのテスト * * - log_levelが正しく返却されるか? */ void test_getLogLevel() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); std::string log_level = m_mgr->getLogLevel(); CPPUNIT_ASSERT_EQUAL(std::string("INFO"), log_level); } /*! * @brief getLoadedModules()メソッドのテスト * * - ロード済みのモジュールリストを正しく取得できるか? */ void test_getLoadedModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); /* FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード済みのモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadedModules(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string(".//./.libs/DummyModule.so"), props[0].getProperty("file_path")); */ } /*! * @brief getFactoryProfiles()メソッドのテスト * * - RTコンポーネント用ファクトリをリストを正しく取得できるか? */ void test_getFactoryProfiles() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); std::vector<coil::Properties> props = m_mgr->getFactoryProfiles(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string("PeriodicECSharedComposite"), props[0].getProperty("implementation_id")); CPPUNIT_ASSERT_EQUAL(std::string("ID"), props[1].getProperty("implementation_id")); } /*! * @brief createContext()メソッドのテスト * * - ExecutionContextBaseを正しく取得できるか? */ void test_createContext() { RTC::ExecutionContextBase* ec; std::string ec_args; m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // return NULL check ec_args = ""; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return NULL check (Factory not found) ec_args = "periodic?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return any check m_mgr->registerECFactory("PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>); ec_args = "PeriodicEC?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec != NULL); } /*! * @brief deleteComponent()メソッドのテスト * * - RTコンポーネントの削除が正しくできるか? */ void test_deleteComponent() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), std::string(comp->getInstanceName())); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") != NULL); std::vector<RTC::RTObject_impl*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT(comps.size() > 0); // 正しくコンポーネントを削除できるか? m_mgr->deleteComponent("DataFlowComponent0"); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); // deleteComponent()でexit()を実行しているため、これ以降のテストはできません。 } /*! * @brief init()、shutdown()から呼ばれるprotected関数のテスト * * - protected関数が正しく動作しているか? */ void test_init2() { // Manager::init()よりprotected関数が使用されているので、ここではテスト省略する // initManager() // initLogger() // initORB() // initNaming() // initFactories() // initExecContext() // initComposite() // initTimer() // initManagerServant() // Manager::shutdown()よりprotected関数が使用されているので、ここではテスト省略する // shutdownComponents(); // shutdownNaming(); // shutdownORB(); // shutdownManager(); // shutdownLogger(); } }; }; // namespace Tests /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(Tests::ManagerTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // ManagerTests_cpp
1290  m_mgr = RTC::Manager::init(0, NULL);
1291  CPPUNIT_ASSERT(m_mgr != NULL);
1292 
1293  // initFactories()の実行結果としてFactoryMapに正しく登録されているか?
1294  bool bret = RTC::CdrBufferFactory::instance().hasFactory("ring_buffer");
1295  CPPUNIT_ASSERT(bret);
1296 
1297  bret = RTC::PeriodicTaskFactory::instance().hasFactory("default");
1298  CPPUNIT_ASSERT(bret);
1299 
1300  bret = RTC::PublisherFactory::instance().hasFactory("flush");
1301  CPPUNIT_ASSERT(bret);
1302 
1303  bret = RTC::PublisherFactory::instance().hasFactory("new");
1304  CPPUNIT_ASSERT(bret);
1305 
1306  bret = RTC::PublisherFactory::instance().hasFactory("periodic");
1307  CPPUNIT_ASSERT(bret);
1308 
1310  bret = factory1.hasFactory("corba_cdr");
1311  CPPUNIT_ASSERT(bret);
1312 
1314  bret = factory2.hasFactory("corba_cdr");
1315  CPPUNIT_ASSERT(bret);
1316 
1318  bret = factory3.hasFactory("corba_cdr");
1319  CPPUNIT_ASSERT(bret);
1320 
1322  bret = factory4.hasFactory("corba_cdr");
1323  CPPUNIT_ASSERT(bret);
1324  }
1325 
1332  {
1333  // init()の中でinitComposite()が実行される m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // initComposite()の実行結果としてFactoryManagerに正しく登録されているか? // "implementation_id"には, "PeriodicECSharedComposite"が設定されている CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "PeriodicECSharedComposite")); } /*! * @brief procContextArgs()メソッドのテスト * * - 引数ec_argsにより戻り値true・falseが正しく返却されるか? */ void test_procContextArgs() { std::string ec_args; std::string ec_id; coil::Properties ec_prop; // インスタンス生成 ManagerTestMock* man = new ManagerTestMock(); // falseを返すケース1:ec_args.size=0 ec_args = ""; bool bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース2:ec_args.size=3 ec_args = "periodic?rate=1000?policy=skip"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース3:ec_args[0].empty ec_args = "?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // trueを返すケース4:ec_args.size=2 ec_args = "periodic?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(bret); std::string chk_val("periodic"); CPPUNIT_ASSERT_EQUAL(chk_val, ec_id); chk_val = "1000"; CPPUNIT_ASSERT_EQUAL(chk_val, ec_prop["rate"]); delete man; } /*! * @brief getLogLevel()メソッドのテスト * * - log_levelが正しく返却されるか? */ void test_getLogLevel() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); std::string log_level = m_mgr->getLogLevel(); CPPUNIT_ASSERT_EQUAL(std::string("INFO"), log_level); } /*! * @brief getLoadedModules()メソッドのテスト * * - ロード済みのモジュールリストを正しく取得できるか? */ void test_getLoadedModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); /* FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード済みのモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadedModules(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string(".//./.libs/DummyModule.so"), props[0].getProperty("file_path")); */ } /*! * @brief getFactoryProfiles()メソッドのテスト * * - RTコンポーネント用ファクトリをリストを正しく取得できるか? */ void test_getFactoryProfiles() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); std::vector<coil::Properties> props = m_mgr->getFactoryProfiles(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string("PeriodicECSharedComposite"), props[0].getProperty("implementation_id")); CPPUNIT_ASSERT_EQUAL(std::string("ID"), props[1].getProperty("implementation_id")); } /*! * @brief createContext()メソッドのテスト * * - ExecutionContextBaseを正しく取得できるか? */ void test_createContext() { RTC::ExecutionContextBase* ec; std::string ec_args; m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // return NULL check ec_args = ""; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return NULL check (Factory not found) ec_args = "periodic?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return any check m_mgr->registerECFactory("PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>); ec_args = "PeriodicEC?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec != NULL); } /*! * @brief deleteComponent()メソッドのテスト * * - RTコンポーネントの削除が正しくできるか? */ void test_deleteComponent() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), std::string(comp->getInstanceName())); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") != NULL); std::vector<RTC::RTObject_impl*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT(comps.size() > 0); // 正しくコンポーネントを削除できるか? m_mgr->deleteComponent("DataFlowComponent0"); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); // deleteComponent()でexit()を実行しているため、これ以降のテストはできません。 } /*! * @brief init()、shutdown()から呼ばれるprotected関数のテスト * * - protected関数が正しく動作しているか? */ void test_init2() { // Manager::init()よりprotected関数が使用されているので、ここではテスト省略する // initManager() // initLogger() // initORB() // initNaming() // initFactories() // initExecContext() // initComposite() // initTimer() // initManagerServant() // Manager::shutdown()よりprotected関数が使用されているので、ここではテスト省略する // shutdownComponents(); // shutdownNaming(); // shutdownORB(); // shutdownManager(); // shutdownLogger(); } }; }; // namespace Tests /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(Tests::ManagerTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // ManagerTests_cpp
1334  m_mgr = RTC::Manager::init(0, NULL);
1335  CPPUNIT_ASSERT(m_mgr != NULL);
1336 
1337  // initComposite()の実行結果としてFactoryManagerに正しく登録されているか?
1338  // "implementation_id"には, "PeriodicECSharedComposite"が設定されている CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "PeriodicECSharedComposite")); } /*! * @brief procContextArgs()メソッドのテスト * * - 引数ec_argsにより戻り値true・falseが正しく返却されるか? */ void test_procContextArgs() { std::string ec_args; std::string ec_id; coil::Properties ec_prop; // インスタンス生成 ManagerTestMock* man = new ManagerTestMock(); // falseを返すケース1:ec_args.size=0 ec_args = ""; bool bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース2:ec_args.size=3 ec_args = "periodic?rate=1000?policy=skip"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // falseを返すケース3:ec_args[0].empty ec_args = "?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(!bret); // trueを返すケース4:ec_args.size=2 ec_args = "periodic?rate=1000"; bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop); CPPUNIT_ASSERT(bret); std::string chk_val("periodic"); CPPUNIT_ASSERT_EQUAL(chk_val, ec_id); chk_val = "1000"; CPPUNIT_ASSERT_EQUAL(chk_val, ec_prop["rate"]); delete man; } /*! * @brief getLogLevel()メソッドのテスト * * - log_levelが正しく返却されるか? */ void test_getLogLevel() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); std::string log_level = m_mgr->getLogLevel(); CPPUNIT_ASSERT_EQUAL(std::string("INFO"), log_level); } /*! * @brief getLoadedModules()メソッドのテスト * * - ロード済みのモジュールリストを正しく取得できるか? */ void test_getLoadedModules() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture3.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); // Managerとは別に、確認用にモジュールへのシンボルを取得しておく typedef int (*FUNC_GETINITPROCCOUNT)(); typedef void (*FUNC_RESETINITPROCCOUNT)(); coil::DynamicLib loader("./.libs/DummyModule.so"); /* FUNC_GETINITPROCCOUNT pGetInitProcCount = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount"); CPPUNIT_ASSERT(pGetInitProcCount != NULL); FUNC_RESETINITPROCCOUNT pResetInitProcCount = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount"); CPPUNIT_ASSERT(pResetInitProcCount != NULL); (*pResetInitProcCount)(); // カウンタクリア CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)()); m_mgr->load("./.libs/DummyModule.so", "InitProc"); // ロード済みのモジュールリストを正しく取得できるか? std::vector<coil::Properties> props = m_mgr->getLoadedModules(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string(".//./.libs/DummyModule.so"), props[0].getProperty("file_path")); */ } /*! * @brief getFactoryProfiles()メソッドのテスト * * - RTコンポーネント用ファクトリをリストを正しく取得できるか? */ void test_getFactoryProfiles() { m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // Factoryを正常に登録できるか? coil::Properties properties; properties.setProperty("implementation_id", "ID"); CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID")); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID")); std::vector<coil::Properties> props = m_mgr->getFactoryProfiles(); CPPUNIT_ASSERT(props.size() > 0); CPPUNIT_ASSERT_EQUAL(std::string("PeriodicECSharedComposite"), props[0].getProperty("implementation_id")); CPPUNIT_ASSERT_EQUAL(std::string("ID"), props[1].getProperty("implementation_id")); } /*! * @brief createContext()メソッドのテスト * * - ExecutionContextBaseを正しく取得できるか? */ void test_createContext() { RTC::ExecutionContextBase* ec; std::string ec_args; m_mgr = RTC::Manager::init(0, NULL); CPPUNIT_ASSERT(m_mgr != NULL); // return NULL check ec_args = ""; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return NULL check (Factory not found) ec_args = "periodic?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec == NULL); // return any check m_mgr->registerECFactory("PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>); ec_args = "PeriodicEC?rate=1000"; ec = m_mgr->createContext(ec_args.c_str()); CPPUNIT_ASSERT(ec != NULL); } /*! * @brief deleteComponent()メソッドのテスト * * - RTコンポーネントの削除が正しくできるか? */ void test_deleteComponent() { int argc = 3; char* argv[] = { "ManagerTests","-f","fixture4.conf" }; m_mgr = RTC::Manager::init(argc, argv); CPPUNIT_ASSERT(m_mgr != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA())); CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager())); // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), std::string(comp->getInstanceName())); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") != NULL); std::vector<RTC::RTObject_impl*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT(comps.size() > 0); // 正しくコンポーネントを削除できるか? m_mgr->deleteComponent("DataFlowComponent0"); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); // deleteComponent()でexit()を実行しているため、これ以降のテストはできません。 } /*! * @brief init()、shutdown()から呼ばれるprotected関数のテスト * * - protected関数が正しく動作しているか? */ void test_init2() { // Manager::init()よりprotected関数が使用されているので、ここではテスト省略する // initManager() // initLogger() // initORB() // initNaming() // initFactories() // initExecContext() // initComposite() // initTimer() // initManagerServant() // Manager::shutdown()よりprotected関数が使用されているので、ここではテスト省略する // shutdownComponents(); // shutdownNaming(); // shutdownORB(); // shutdownManager(); // shutdownLogger(); } }; }; // namespace Tests /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(Tests::ManagerTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // ManagerTests_cpp
1339  CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "PeriodicECSharedComposite"));
1340  }
1341 
1348  {
1349  std::string ec_args;
1350  std::string ec_id;
1351  coil::Properties ec_prop;
1352 
1353  // インスタンス生成
1354  ManagerTestMock* man = new ManagerTestMock();
1355 
1356  // falseを返すケース1:ec_args.size=0
1357  ec_args = "";
1358  bool bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop);
1359  CPPUNIT_ASSERT(!bret);
1360 
1361  // falseを返すケース2:ec_args.size=3
1362  ec_args = "periodic?rate=1000?policy=skip";
1363  bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop);
1364  CPPUNIT_ASSERT(!bret);
1365 
1366  // falseを返すケース3:ec_args[0].empty
1367  ec_args = "?rate=1000";
1368  bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop);
1369  CPPUNIT_ASSERT(!bret);
1370 
1371  // trueを返すケース4:ec_args.size=2
1372  ec_args = "periodic?rate=1000";
1373  bret = man->procContextArgs(ec_args.c_str(), ec_id, ec_prop);
1374  CPPUNIT_ASSERT(bret);
1375  std::string chk_val("periodic");
1376  CPPUNIT_ASSERT_EQUAL(chk_val, ec_id);
1377  chk_val = "1000";
1378  CPPUNIT_ASSERT_EQUAL(chk_val, ec_prop["rate"]);
1379 
1380  delete man;
1381  }
1382 
1389  {
1390  m_mgr = RTC::Manager::init(0, NULL);
1391  CPPUNIT_ASSERT(m_mgr != NULL);
1392  std::string log_level = m_mgr->getLogLevel();
1393  CPPUNIT_ASSERT_EQUAL(std::string("INFO"), log_level);
1394  }
1395 
1402  {
1403  int argc = 3;
1404  char* argv[] = { "ManagerTests","-f","fixture3.conf" };
1405 
1406  m_mgr = RTC::Manager::init(argc, argv);
1407  CPPUNIT_ASSERT(m_mgr != NULL);
1408 
1409  // Managerとは別に、確認用にモジュールへのシンボルを取得しておく
1410  typedef int (*FUNC_GETINITPROCCOUNT)();
1411  typedef void (*FUNC_RESETINITPROCCOUNT)();
1412  coil::DynamicLib loader("./.libs/DummyModule.so");
1413 /*
1414  FUNC_GETINITPROCCOUNT pGetInitProcCount
1415  = (FUNC_GETINITPROCCOUNT) loader.symbol("getInitProcCount");
1416  CPPUNIT_ASSERT(pGetInitProcCount != NULL);
1417 
1418  FUNC_RESETINITPROCCOUNT pResetInitProcCount
1419  = (FUNC_RESETINITPROCCOUNT) loader.symbol("resetInitProcCount");
1420  CPPUNIT_ASSERT(pResetInitProcCount != NULL);
1421 
1422  (*pResetInitProcCount)(); // カウンタクリア
1423 
1424  CPPUNIT_ASSERT_EQUAL(0, (*pGetInitProcCount)());
1425  m_mgr->load("./.libs/DummyModule.so", "InitProc");
1426 
1427  // ロード済みのモジュールリストを正しく取得できるか?
1428  std::vector<coil::Properties> props = m_mgr->getLoadedModules();
1429  CPPUNIT_ASSERT(props.size() > 0);
1430 
1431  CPPUNIT_ASSERT_EQUAL(std::string(".//./.libs/DummyModule.so"),
1432  props[0].getProperty("file_path"));
1433 */
1434  }
1435 
1442  {
1443  m_mgr = RTC::Manager::init(0, NULL);
1444  CPPUNIT_ASSERT(m_mgr != NULL);
1445 
1446  // Factoryを正常に登録できるか?
1447  coil::Properties properties;
1448  properties.setProperty("implementation_id", "ID");
1449 
1450  CPPUNIT_ASSERT(! isFound(m_mgr->getModulesFactories(), "ID"));
1451  CPPUNIT_ASSERT(m_mgr->registerFactory(
1453  CPPUNIT_ASSERT(isFound(m_mgr->getModulesFactories(), "ID"));
1454 
1455  std::vector<coil::Properties> props = m_mgr->getFactoryProfiles();
1456  CPPUNIT_ASSERT(props.size() > 0);
1457 
1458  CPPUNIT_ASSERT_EQUAL(std::string("PeriodicECSharedComposite"),
1459  props[0].getProperty("implementation_id"));
1460  CPPUNIT_ASSERT_EQUAL(std::string("ID"),
1461  props[1].getProperty("implementation_id"));
1462  }
1463 
1470  {
1472  std::string ec_args;
1473 
1474  m_mgr = RTC::Manager::init(0, NULL);
1475  CPPUNIT_ASSERT(m_mgr != NULL);
1476 
1477  // return NULL check
1478  ec_args = "";
1479  ec = m_mgr->createContext(ec_args.c_str());
1480  CPPUNIT_ASSERT(ec == NULL);
1481 
1482  // return NULL check (Factory not found)
1483  ec_args = "periodic?rate=1000";
1484  ec = m_mgr->createContext(ec_args.c_str());
1485  CPPUNIT_ASSERT(ec == NULL);
1486 
1487  // return any check
1488  m_mgr->registerECFactory("PeriodicEC",
1489  RTC::ECCreate<RTC::PeriodicExecutionContext>,
1490  RTC::ECDelete<RTC::PeriodicExecutionContext>);
1491  ec_args = "PeriodicEC?rate=1000";
1492  ec = m_mgr->createContext(ec_args.c_str());
1493  CPPUNIT_ASSERT(ec != NULL);
1494  }
1495 
1502  {
1503  int argc = 3;
1504  char* argv[] = { "ManagerTests","-f","fixture4.conf" };
1505 
1506  m_mgr = RTC::Manager::init(argc, argv);
1507  CPPUNIT_ASSERT(m_mgr != NULL);
1508  CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getORB()));
1509  CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOA()));
1510  CPPUNIT_ASSERT(! CORBA::is_nil(m_mgr->getPOAManager()));
1511 
1512  // 非ブロッキングモードでマネージャを作動させる CPPUNIT_ASSERT(m_mgr->activateManager()); m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング // Factoryを登録しておく coil::Properties properties; properties.setProperty("implementation_id", "DataFlowComponentFactory"); properties.setProperty("type_name", "DataFlowComponent"); CPPUNIT_ASSERT(m_mgr->registerFactory( properties, CreateDataFlowComponentMock, DeleteDataFlowComponentMock)); // ECFactoryを登録しておく CPPUNIT_ASSERT(m_mgr->registerECFactory( "PeriodicEC", RTC::ECCreate<RTC::PeriodicExecutionContext>, RTC::ECDelete<RTC::PeriodicExecutionContext>)); // 正しくコンポーネントを生成できるか? RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory"); CPPUNIT_ASSERT(comp != NULL); CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL); CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this())); CPPUNIT_ASSERT_EQUAL( std::string("DataFlowComponent0"), std::string(comp->getInstanceName())); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") != NULL); std::vector<RTC::RTObject_impl*> comps = m_mgr->getComponents(); CPPUNIT_ASSERT(comps.size() > 0); // 正しくコンポーネントを削除できるか? m_mgr->deleteComponent("DataFlowComponent0"); CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL); // deleteComponent()でexit()を実行しているため、これ以降のテストはできません。 } /*! * @brief init()、shutdown()から呼ばれるprotected関数のテスト * * - protected関数が正しく動作しているか? */ void test_init2() { // Manager::init()よりprotected関数が使用されているので、ここではテスト省略する // initManager() // initLogger() // initORB() // initNaming() // initFactories() // initExecContext() // initComposite() // initTimer() // initManagerServant() // Manager::shutdown()よりprotected関数が使用されているので、ここではテスト省略する // shutdownComponents(); // shutdownNaming(); // shutdownORB(); // shutdownManager(); // shutdownLogger(); } }; }; // namespace Tests /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(Tests::ManagerTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // ManagerTests_cpp
1513  CPPUNIT_ASSERT(m_mgr->activateManager());
1514  m_mgr->runManager(true); // true:非ブロッキング,false:ブロッキング
1515 
1516  // Factoryを登録しておく
1517  coil::Properties properties;
1518  properties.setProperty("implementation_id", "DataFlowComponentFactory");
1519  properties.setProperty("type_name", "DataFlowComponent");
1520  CPPUNIT_ASSERT(m_mgr->registerFactory(
1522 
1523  // ECFactoryを登録しておく
1524  CPPUNIT_ASSERT(m_mgr->registerECFactory(
1525  "PeriodicEC",
1526  RTC::ECCreate<RTC::PeriodicExecutionContext>,
1527  RTC::ECDelete<RTC::PeriodicExecutionContext>));
1528 
1529  // 正しくコンポーネントを生成できるか?
1530  RTC::RtcBase* comp = m_mgr->createComponent("DataFlowComponentFactory");
1531  CPPUNIT_ASSERT(comp != NULL);
1532  CPPUNIT_ASSERT(dynamic_cast<DataFlowComponentMock*>(comp) != NULL);
1533  CPPUNIT_ASSERT(! CORBA::is_nil(comp->_this()));
1534  CPPUNIT_ASSERT_EQUAL(
1535  std::string("DataFlowComponent0"),
1536  std::string(comp->getInstanceName()));
1537 
1538  CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") != NULL);
1539  std::vector<RTC::RTObject_impl*> comps = m_mgr->getComponents();
1540  CPPUNIT_ASSERT(comps.size() > 0);
1541 
1542  // 正しくコンポーネントを削除できるか?
1543  m_mgr->deleteComponent("DataFlowComponent0");
1544  CPPUNIT_ASSERT(m_mgr->getComponent("DataFlowComponent0") == NULL);
1545 
1546  // deleteComponent()でexit()を実行しているため、これ以降のテストはできません。
1547  }
1548 
1554  void test_init2()
1555  {
1556  // Manager::init()よりprotected関数が使用されているので、ここではテスト省略する // initManager() // initLogger() // initORB() // initNaming() // initFactories() // initExecContext() // initComposite() // initTimer() // initManagerServant() // Manager::shutdown()よりprotected関数が使用されているので、ここではテスト省略する // shutdownComponents(); // shutdownNaming(); // shutdownORB(); // shutdownManager(); // shutdownLogger(); } }; }; // namespace Tests /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(Tests::ManagerTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // ManagerTests_cpp
1557  // initManager()
1558  // initLogger()
1559  // initORB()
1560  // initNaming()
1561  // initFactories()
1562  // initExecContext()
1563  // initComposite()
1564  // initTimer()
1565  // initManagerServant()
1566 
1567  // Manager::shutdown()よりprotected関数が使用されているので、ここではテスト省略する // shutdownComponents(); // shutdownNaming(); // shutdownORB(); // shutdownManager(); // shutdownLogger(); } }; }; // namespace Tests /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(Tests::ManagerTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // ManagerTests_cpp
1568  // shutdownComponents();
1569  // shutdownNaming();
1570  // shutdownORB();
1571  // shutdownManager();
1572  // shutdownLogger();
1573  }
1574 
1575  };
1576 }; // namespace Tests
1577 
1578 /*
1579  * Register test suite
1580  */
1582 
1583 #ifdef LOCAL_MAIN
1584 int main(int argc, char* argv[])
1585 {
1586 
1587  FORMAT format = TEXT_OUT;
1588  int target = 0;
1589  std::string xsl;
1590  std::string ns;
1591  std::string fname;
1592  std::ofstream ofs;
1593 
1594  int i(1);
1595  while (i < argc)
1596  {
1597  std::string arg(argv[i]);
1598  std::string next_arg;
1599  if (i + 1 < argc) next_arg = argv[i + 1];
1600  else next_arg = "";
1601 
1602  if (arg == "--text") { format = TEXT_OUT; break; }
1603  if (arg == "--xml")
1604  {
1605  if (next_arg == "")
1606  {
1607  fname = argv[0];
1608  fname += ".xml";
1609  }
1610  else
1611  {
1612  fname = next_arg;
1613  }
1614  format = XML_OUT;
1615  ofs.open(fname.c_str());
1616  }
1617  if ( arg == "--compiler" ) { format = COMPILER_OUT; break; }
1618  if ( arg == "--cerr" ) { target = 1; break; }
1619  if ( arg == "--xsl" )
1620  {
1621  if (next_arg == "") xsl = "default.xsl";
1622  else xsl = next_arg;
1623  }
1624  if ( arg == "--namespace" )
1625  {
1626  if (next_arg == "")
1627  {
1628  std::cerr << "no namespace specified" << std::endl;
1629  exit(1);
1630  }
1631  else
1632  {
1633  xsl = next_arg;
1634  }
1635  }
1636  ++i;
1637  }
1638  CppUnit::TextUi::TestRunner runner;
1639  if ( ns.empty() )
1640  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
1641  else
1642  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
1643  CppUnit::Outputter* outputter = 0;
1644  std::ostream* stream = target ? &std::cerr : &std::cout;
1645  switch ( format )
1646  {
1647  case TEXT_OUT :
1648  outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
1649  break;
1650  case XML_OUT :
1651  std::cout << "XML_OUT" << std::endl;
1652  outputter = new CppUnit::XmlOutputter(&runner.result(),
1653  ofs, "shift_jis");
1654  static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
1655  break;
1656  case COMPILER_OUT :
1657  outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
1658  break;
1659  }
1660  runner.setOutputter(outputter);
1661  runner.run();
1662  return 0; // runner.run() ? 0 : 1;
1663 }
1664 #endif // MAIN
1665 #endif // ManagerTests_cpp
void test_registerECFactory()
registerECFactory()
int main(int argc, char **argv)
PortableServer::POAManager_ptr getPOAManager()
Get POAManager that Manager has.
Definition: Manager.cpp:858
RTObject_impl * createComponent(const char *comp_args)
Create RT-Components.
Definition: Manager.cpp:520
void test_init2()
init()、shutdown()から呼ばれるprotected関数のテスト
bool procContextArgs(const char *ec_args, std::string &ec_id, coil::Properties &ec_conf)
Extracting ExecutionContext&#39;s name/properties from the given string.
Definition: Manager.cpp:1616
InPortCorbaCdrConsumer class.
RT-Component.
void deleteComponent(RTObject_impl *comp)
Unregister RT-Components that have been registered to Manager.
Definition: Manager.cpp:748
void DeleteDataFlowComponentMock(RTC::RtcBase *rtc)
virtual ReturnCode_t initialize()
[CORBA interface] Initialize the RTC that realizes this interface.
Definition: RTObject.cpp:310
void test_unload()
unload()メソッドのテスト
bool hasFactory(const Identifier &id)
Factory presence check.
unsigned int sleep(unsigned int seconds)
Stop a processing at specified second time.
Definition: ace/coil/Time.h:40
void test_getLoadableModules()
getLoadableModules()メソッドのテスト
void test_createComponent_DataFlowComponent()
createComponent()メソッドのテスト(DataFlowComponentの場合)
PortableServer::POA_ptr getPOA()
Get a pointer to RootPOA held by Manager.
Definition: Manager.cpp:845
InvokerMock(const RTC::DataFlowComponent_ptr &rtoRef, RTC::Manager *mgr)
void log(const std::string &msg)
void * symbol(const char *symbol_name)
Return an address of the memory where a symbol was loaded.
void runManager(bool no_block=false)
Run the Manager.
Definition: Manager.cpp:318
RTObject_impl * getComponent(const char *instance_name)
Get RT-Component&#39;s pointer.
Definition: Manager.cpp:803
void test_createComponent_with_illegal_module_name()
createComponent()メソッドのテスト
ReturnCode_t
Definition: doil.h:53
void test_terminate_after_the_activation()
terminate()メソッドのテスト
void test_init_without_arguments()
init()メソッドのテスト
std::vector< coil::Properties > getLoadableModules()
Get a list of loadable modules.
Definition: Manager.cpp:417
void test_runManager_no_block()
runManager()メソッドのテスト(非ブロッキングモード)
bool canResolve(const char *name_server, const char *id, const char *kind)
void shutdown()
Shutdown Manager.
Definition: Manager.cpp:182
A base class for ExecutionContext.
std::string & getLogLevel()
Get the log level of the configuration.
Definition: Manager.h:286
void test_terminate_immediately_after_the_initialization()
terminate()メソッドのテスト
RT-Component class.
Definition: RTObject.h:89
void terminate()
Terminate manager.
Definition: Manager.cpp:169
void test_registerFactory()
registerFactory()メソッドのテスト
void load(const char *fname, const char *initfunc)
[CORBA interface] Load module
Definition: Manager.cpp:346
RTC::Manager * m_mgr
void test_unloadAll()
unloadAll()メソッドのテスト
std::vector< std::string > m_log
Manager class.
Definition: Manager.h:80
void test_cleanupComponent()
cleanupComponent()メソッドのテスト
static void setLogger(Logger *logger)
void test_getFactoryProfiles()
getFactoryProfiles()メソッドのテスト
CORBA::ORB_ptr getORB()
Get the pointer to ORB.
Definition: Manager.cpp:832
bool isFound(const std::vector< std::string > &list, const std::string &target)
void test_getModulesFactories()
getModulesFactories()メソッドのテスト
void test_createContext()
createContext()メソッドのテスト
static GlobalFactory< AbstractClass, Identifier, Compare, Creator, Destructor > & instance()
Create instance.
Definition: Singleton.h:131
static Manager & instance()
Get instance of the manager.
Definition: Manager.cpp:140
UniqueId attach_context(ExecutionContext_ptr exec_context)
[CORBA interface] Attach ExecutionContext
Definition: RTObject.cpp:583
GlobalFactory template class.
OutPortCorbaCdrConsumer class.
RTComponent manager class.
InPortCorbaCdrProvider class.
DynamicLib class.
virtual ~ManagerTests()
Destructor.
virtual void tearDown()
Test finalization.
void test_getLogLevel()
getLogLevel()メソッドのテスト
RTObjectMock(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa)
std::vector< coil::Properties > getFactoryProfiles()
Get profiles of factories.
Definition: Manager.cpp:456
std::vector< ExecutionContext * > ExecutionContextList
Definition: IRTC.h:69
static void InitProc(RTC::Manager *manager)
coil::Properties & getConfig()
Get the manager configuration.
Definition: Manager.h:305
virtual RTC::ReturnCode_t initialize()
[CORBA interface] Initialize the RTC that realizes this interface.
void test_instance()
instance()メソッドのテスト
Periodic Execution Context Shared Composite Component class.
void setObjRef(const RTObject_ptr rtobj)
[local interface] Set the object reference
Definition: RTObject.cpp:1470
ExecutionContextHandle_t UniqueId
PeiodicTaskFactory class.
void test_procContextArgs()
procContextArgs()メソッドのテスト
PublisherPeriodic class.
std::vector< std::string > getModulesFactories()
Get the list of all Factories.
Definition: Manager.cpp:502
CORBA::Long find(const CorbaSequence &seq, Functor f)
Return the index of CORBA sequence element that functor matches.
static Manager * init(int argc, char **argv)
Initialize manager.
Definition: Manager.cpp:110
DataFlowComponentMock(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa)
std::string setProperty(const std::string &key, const std::string &value)
Set a value associated with key in the property list.
Definition: Properties.cpp:236
RTC::UniqueId attach_context(RTC::ExecutionContext_ptr exec_context)
ExtTrigExecutionContext class.
static Logger * m_logger
RTC::RtcBase * CreateDataFlowComponentMock(RTC::Manager *manager)
ExecutionContextBase * createContext(const char *ec_args)
Create Context.
Definition: Manager.cpp:719
int countLog(const std::string &line)
void test_getComponents()
getComponents()メソッドのテスト
CPPUNIT_TEST_SUITE_REGISTRATION(Tests::ManagerTests)
void join()
Wait for Manager&#39;s termination.
Definition: Manager.cpp:208
virtual ReturnCode_t exit()
[CORBA interface]top the RTC&#39;s execution context(s) and finalize it along with its contents...
Definition: RTObject.cpp:394
void test_setModuleInitProc()
setModuleInitProc()メソッドのテスト
void test_createComponent_failed_in_bindExecutionContext()
const char * getInstanceName()
[local interface] Get instance name
Definition: RTObject.h:1952
bool activateManager()
Activate the Manager.
Definition: Manager.cpp:244
bool registerECFactory(const char *name, ECNewFunc new_func, ECDeleteFunc delete_func)
Register ExecutionContext Factory.
Definition: Manager.cpp:474
PublisherFlush class.
RingBuffer for CDR.
ManagerTests()
Constructor.
void shutdown_ORB(RTC::Manager *mgr)
naming Service helper class
virtual ExecutionContextList * get_owned_contexts()
[CORBA interface] Get ExecutionContextList.
Definition: RTObject.cpp:499
RTC::DataFlowComponent_ptr m_rtoRef
void unloadAll()
Unload all modules.
Definition: Manager.cpp:390
Class represents a set of properties.
Definition: Properties.h:101
void test_runManager_block()
runManager()メソッドのテスト(ブロッキングモード)
ExecutionContext Factory class.
CosNaming::NamingContext_var getRootContext(const std::string &name_server)
int countLog(const std::string &msg)
virtual void setUp()
Test initialization.
void setModuleInitProc(ModuleInitProc proc)
Set initial procedure.
Definition: Manager.cpp:232
PeriodicExecutionContext class.
void test_initFactories()
initFactories()メソッドのテスト
void test_instance_without_init()
instance()メソッドのテスト
Task class.
PeiodicTaskFactory class.
::OutPortBase::Logger logger
bret
7 送受信データ比較
Definition: ConnectTest.py:377
void setLogger(Logger *logger)
void cleanupComponent(RTObject_impl *comp)
Unregister RT-Components.
Definition: Manager.cpp:1524
bool procContextArgs(const char *ec_args, std::string &ec_id, coil::Properties &ec_conf)
void test_createComponent_Non_DataFlowComponent()
virtual ~ManagerTestMock(void)
void test_load()
load()メソッドのテスト
void test_getLoadedModules()
getLoadedModules()メソッドのテスト
void test_initComposite()
initComposite()メソッドのテスト
NamingServer management class.
void test_deleteComponent()
deleteComponent()メソッドのテスト
virtual int svc(void)
Execute thread.
bool registerFactory(coil::Properties &profile, RtcNewFunc new_func, RtcDeleteFunc delete_func)
Register RT-Component Factory.
Definition: Manager.cpp:433
PublisherNew class.
void test_getConfig()
getConfig()メソッドのテスト
static void clearInstance()
const std::string & getProperty(const std::string &key) const
Search for the property with the specified key in this property.
Definition: Properties.cpp:156
OutPortCorbaCdrProvider class.
std::vector< RTObject_impl * > getComponents()
Get all RT-Components registered in the Manager.
Definition: Manager.cpp:816
int usleep(useconds_t usec)
Stop a processing at specified micro second time.
Definition: ace/coil/Time.h:51


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Jun 10 2019 14:07:53