RTObjectTests.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00011 /*
00012  * $Log: RTObjectTests.cpp,v $
00013  * Revision 1.1  2008/04/24 08:49:57  arafune
00014  * The first commitment.
00015  *
00016  */
00017 
00018 #ifndef RTObject_cpp
00019 #define RTObject_cpp
00020 
00021 #include <cppunit/ui/text/TestRunner.h>
00022 #include <cppunit/TextOutputter.h>
00023 #include <cppunit/extensions/TestFactoryRegistry.h>
00024 #include <cppunit/extensions/HelperMacros.h>
00025 #include <cppunit/TestAssert.h>
00026 
00027 #include <rtm/RTC.h>
00028 #include <rtm/PeriodicExecutionContext.h>
00029 #include <rtm/RTObject.h>
00030 
00035 namespace RTObject
00036 {
00037   class RTObjectMock
00038     : public RTC::RTObject_impl
00039   {
00040   public:
00041     RTObjectMock(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa)
00042       : RTC::RTObject_impl(orb, poa)
00043     {
00044     }
00045 
00046     virtual ~RTObjectMock()
00047     {
00048     }
00049                 
00050     virtual RTC::ReturnCode_t on_initialize()
00051       throw (CORBA::SystemException)
00052     {
00053       log("on_initialize");
00054       return RTC::RTObject_impl::on_initialize();
00055     }
00056                 
00057     virtual RTC::ReturnCode_t on_finalize()
00058       throw (CORBA::SystemException)
00059     {
00060       log("on_finalize");
00061       return RTC::RTObject_impl::on_finalize();
00062     }
00063 
00064     virtual RTC::UniqueId bindContext(RTC::ExecutionContext_ptr exec_context)
00065     {
00066       RTC::UniqueId id;
00067       id = RTC::RTObject_impl::bindContext(exec_context);
00068       ecMine = RTC::RTObject_impl::m_ecMine;
00069       return id;
00070     }
00071     RTC::ExecutionContextServiceList ecMine;
00072 
00073     // protected: m_ecMineの設定
00074     void set_ecMine()
00075     {
00076       RTC::RTObject_impl::m_ecMine = ecMine;
00077     }
00078 
00079     // protected: m_ecMineの判定
00080     bool chk_ecMine(int id, RTC::ExecutionContext_ptr exec_context)
00081     {
00082       RTC::ExecutionContextService_var ecs;
00083       ecs = RTC::ExecutionContextService::_narrow(exec_context);
00084       if (RTC::RTObject_impl::m_ecMine[id] == ecs)
00085       {
00086         return true;
00087       }
00088       else
00089       {
00090         return false;
00091       }
00092     }
00093 
00094     std::vector<RTC::ExecutionContextBase*> eclist;
00095     // protected: m_eclistの取得
00096     int get_eclist()
00097     {
00098       int len(RTC::RTObject_impl::m_eclist.size());
00099       eclist = RTC::RTObject_impl::m_eclist;
00100       return len;
00101     }
00102 
00103                 
00104   public: // helper for test
00105     int countLog(std::string line)
00106     {
00107       int count = 0;
00108       for (int i = 0; i < (int) m_log.size(); ++i)
00109         {
00110           if (m_log[i] == line) ++count;
00111         }
00112       return count;
00113     }
00114                 
00115     void set_status(const char* name, const CORBA::Any& value)
00116     {
00117       CORBA::Long idx = NVUtil::find_index(m_sdoStatus, name);
00118       if (idx < 0)
00119         {
00120           SDOPackage::NameValue nv = NVUtil::newNVAny(name, value);
00121           CORBA_SeqUtil::push_back(m_sdoStatus, nv);
00122         }
00123       else
00124         {
00125           m_sdoStatus[idx].value <<= value;
00126         }
00127     }
00128     
00129     void shutdown() 
00130     {
00131       RTObject_impl::shutdown();
00132     }
00133     
00134                 
00135   private:
00136     void log(const std::string& msg)
00137     {
00138       m_log.push_back(msg);
00139     }
00140                 
00141   private:
00142     std::vector<std::string> m_log;
00143   };
00144         
00145   class PortMock
00146     : public RTC::PortBase
00147   {
00148   protected:
00149     virtual RTC::ReturnCode_t publishInterfaces(RTC::ConnectorProfile& connector_profile)
00150     {
00151       return RTC::RTC_OK;
00152     }
00153     virtual RTC::ReturnCode_t subscribeInterfaces(const RTC::ConnectorProfile& connector_profile)
00154     {
00155       return RTC::RTC_OK;
00156     }
00157     virtual void unsubscribeInterfaces(const RTC::ConnectorProfile& connector_profile)
00158     {
00159     }
00160     virtual void activateInterfaces()
00161     {
00162     }
00163     virtual void deactivateInterfaces()
00164     {
00165     }
00166   };
00167 
00168   class InPortMock
00169     : public RTC::InPortBase
00170   {
00171   public:
00172     InPortMock(const char* name, const char* data_type)
00173       :RTC::InPortBase(name, data_type),
00174        m_return(true),
00175        m_cnt(0)
00176     {
00177       return;
00178     }
00179     
00180     bool read(){
00181       ++m_cnt;
00182       return m_return;
00183     }
00184 
00185     void set_return(bool ret)
00186     {
00187       m_return = ret;
00188     }
00189 
00190     int get_counter()
00191     {
00192       return m_cnt;
00193     }
00194 
00195   private:
00196     bool m_return;
00197     int m_cnt;
00198   };
00199         
00200   class OutPortMock
00201     : public RTC::OutPortBase
00202   {
00203   public:
00204     OutPortMock(const char* name, const char* data_type)
00205       : OutPortBase(name, data_type),
00206        m_return(true),
00207        m_cnt(0)
00208     {
00209       return;
00210     }
00211 
00212     bool write() {
00213       ++m_cnt;
00214       return m_return;
00215     }
00216     void set_return(bool ret)
00217     {
00218       m_return = ret;
00219     }
00220 
00221     int get_counter()
00222     {
00223       return m_cnt;
00224     }
00225   private:
00226     bool m_return;
00227     int m_cnt;
00228   };
00229         
00230   class SDOServiceMock
00231     : public POA_SDOPackage::SDOService,
00232       public virtual PortableServer::RefCountServantBase
00233   {
00234   };
00235         
00236   struct PortFinder
00237   {
00238     PortFinder(const RTC::PortService_ptr& port) : m_port(port) {}
00239     bool operator()(const RTC::PortService_ptr& port)
00240     {
00241       return m_port->_is_equivalent(port);
00242     }
00243                 
00244     const RTC::PortService_ptr& m_port;
00245   };
00246         
00247   class SDOSystemElementMock
00248     : public POA_SDOPackage::SDOSystemElement,
00249       public virtual PortableServer::RefCountServantBase
00250   {
00251   };
00252         
00253   class OrganizationMock
00254     : public POA_SDOPackage::Organization,
00255       public virtual PortableServer::RefCountServantBase
00256   {
00257   public:
00258     OrganizationMock(const char* id) : m_id(id)
00259     {
00260     }
00261                 
00262     virtual char* get_organization_id()
00263     {
00264       return CORBA::string_dup(m_id);
00265     }
00266                 
00267     virtual SDOPackage::OrganizationProperty* get_organization_property()
00268     {
00269       return NULL;
00270     }
00271                 
00272     virtual CORBA::Any* get_organization_property_value(const char* name)
00273     {
00274       return NULL;
00275     }
00276                 
00277     virtual CORBA::Boolean add_organization_property(const SDOPackage::OrganizationProperty& organization_property)
00278     {
00279       return false;
00280     }
00281                 
00282     virtual CORBA::Boolean set_organization_property_value(const char* name, const CORBA::Any& value)
00283     {
00284       return false;
00285     }
00286                 
00287     virtual CORBA::Boolean remove_organization_property(const char* name)
00288     {
00289       return false;
00290     }
00291                 
00292     virtual SDOPackage::SDOSystemElement_ptr get_owner()
00293     {
00294       return NULL;
00295     }
00296                 
00297     virtual CORBA::Boolean set_owner(SDOPackage::SDOSystemElement_ptr sdo)
00298     {
00299       return false;
00300     }
00301                 
00302     virtual SDOPackage::SDOList* get_members()
00303     {
00304       return NULL;
00305     }
00306                 
00307     virtual CORBA::Boolean set_members(const SDOPackage::SDOList& sdos)
00308     {
00309       return false;
00310     }
00311                 
00312     virtual CORBA::Boolean add_members(const SDOPackage::SDOList& sdo_list)
00313     {
00314       return false;
00315     }
00316                 
00317     virtual CORBA::Boolean remove_member(const char* id)
00318     {
00319       return false;
00320     }
00321                 
00322     virtual SDOPackage::DependencyType get_dependency()
00323     {
00324       return SDOPackage::NO_DEPENDENCY;
00325     }
00326                 
00327     virtual CORBA::Boolean set_dependency(SDOPackage::DependencyType dependency)
00328     {
00329       return false;
00330     }
00331                 
00332   private:
00333     const char* m_id;
00334   };
00335         
00336   struct ExecutionContextServiceFinder
00337   {
00338     ExecutionContextServiceFinder(const RTC::ExecutionContextService_ptr& ecSvc)
00339       : m_ecSvc(ecSvc) {}
00340     bool operator()(const RTC::ExecutionContextService_ptr& ecSvc)
00341     {
00342       return m_ecSvc->_is_equivalent(ecSvc);
00343     }
00344     const RTC::ExecutionContextService_ptr& m_ecSvc;
00345   };
00346         
00347   struct ServiceProfileFinder
00348   {
00349     ServiceProfileFinder(const char* id) : m_id(id) {}
00350     bool operator()(const SDOPackage::ServiceProfile& svcProf)
00351     {
00352       return strcmp(m_id, (const char*)(svcProf.id)) == 0;
00353     }
00354     const char* m_id;
00355   };
00356         
00357   struct OrganizationFinder
00358   {
00359     OrganizationFinder(const char* id) : m_id(id) {}
00360     bool operator()(const SDOPackage::Organization_ptr& org)
00361     {
00362       return strcmp(m_id, org->get_organization_id()) == 0;
00363     }
00364     const char* m_id;
00365   };
00366         
00367   class RTObjectTests
00368     : public CppUnit::TestFixture
00369   {
00370     CPPUNIT_TEST_SUITE(RTObjectTests);
00371 
00372     CPPUNIT_TEST(test_finalizeContexts);
00373     CPPUNIT_TEST(test_bindContext);
00374     CPPUNIT_TEST(test_add_removePort);
00375     CPPUNIT_TEST(test_readAll);
00376     CPPUNIT_TEST(test_writeAll);
00377     CPPUNIT_TEST(test_initialize_invoking_on_initialize);
00378     CPPUNIT_TEST(test_initialize_in_Alive);
00379     CPPUNIT_TEST(test_finalize_invoking_on_finalize);
00380     CPPUNIT_TEST(test_finalize_participating_in_execution_context);
00381     CPPUNIT_TEST(test_finalize_in_Created);
00382     //          CPPUNIT_TEST(test_is_alive);
00383     CPPUNIT_TEST(test_exit);
00384     CPPUNIT_TEST(test_exit_in_Created);
00385     CPPUNIT_TEST(test_detach_executioncontext);
00386     CPPUNIT_TEST(test_detach_executioncontext_with_illegal_id);
00387     CPPUNIT_TEST(test_get_context);
00388     CPPUNIT_TEST(test_get_contexts);
00389     CPPUNIT_TEST(test_get_component_profile);
00390     CPPUNIT_TEST(test_get_ports);
00391 //    CPPUNIT_TEST(test_get_execution_context_services);
00392     //          CPPUNIT_TEST(test_get_owned_organizations);
00393     CPPUNIT_TEST(test_get_sdo_id);
00394     CPPUNIT_TEST(test_get_sdo_type);
00395     //          CPPUNIT_TEST(test_get_device_profile);
00396     //          CPPUNIT_TEST(test_get_service_profile);
00397     CPPUNIT_TEST(test_get_service_profile_with_illegal_arguments);
00398     CPPUNIT_TEST(test_get_sdo_service);
00399     CPPUNIT_TEST(test_get_sdo_service_with_illegal_arguments);
00400     CPPUNIT_TEST(test_get_configuration_and_set_device_profile_and_get_device_profile);
00401     CPPUNIT_TEST(test_get_configuration_and_set_service_profile_and_get_service_profile);
00402     CPPUNIT_TEST(test_get_configuration_and_set_service_profile_and_get_service_profiles);
00403     CPPUNIT_TEST(test_get_configuration_and_set_service_profile_and_get_sdo_service);
00404     CPPUNIT_TEST(test_get_configuration_and_remove_service_profile);
00405     CPPUNIT_TEST(test_get_configuration_and_add_organization_and_get_organizations);
00406     CPPUNIT_TEST(test_get_configuration_and_remove_organization);
00407     //          CPPUNIT_TEST(test_get_monitoring);
00408     CPPUNIT_TEST(test_get_status);
00409     CPPUNIT_TEST(test_get_status_list);
00410 
00411     CPPUNIT_TEST_SUITE_END();
00412         
00413   private:
00414     CORBA::ORB_ptr m_pORB;
00415     PortableServer::POA_ptr m_pPOA;
00416         
00417   public:
00421     RTObjectTests()
00422     {
00423       int argc(0);
00424       char** argv(NULL);
00425       m_pORB = CORBA::ORB_init(argc, argv);
00426       m_pPOA = PortableServer::POA::_narrow(
00427                                             m_pORB->resolve_initial_references("RootPOA"));
00428       m_pPOA->the_POAManager()->activate();
00429     }
00430                     
00434     virtual ~RTObjectTests()
00435     {
00436     }
00437                   
00441     virtual void setUp()
00442     {
00443     }
00444     
00448     virtual void tearDown()
00449     { 
00450     }
00451                 
00457     void test_initialize_invoking_on_initialize()
00458     {
00459       RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
00460                         
00461       // initialize()メソッド呼出により、on_initialize()コールバックが呼び出されるか?
00462       CPPUNIT_ASSERT_EQUAL(0, rto->countLog("on_initialize"));
00463       coil::Properties prop;
00464       prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext");
00465       prop.setProperty("exec_cxt.periodic.rate","1000");
00466       rto->setProperties(prop);
00467       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize());
00468       CPPUNIT_ASSERT_EQUAL(1, rto->countLog("on_initialize"));
00469       rto->exit();
00470       delete rto;
00471     }
00472                 
00478     void test_initialize_in_Alive()
00479     {
00480       RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
00481                         
00482       // initialize()メソッド呼出しを行い、Alive状態に遷移させる
00483       coil::Properties prop;
00484       prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext");
00485       prop.setProperty("exec_cxt.periodic.rate","1000");
00486       rto->setProperties(prop);
00487       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize());
00488 
00489       RTC::ExecutionContext_ptr ec;
00490       ec = rto->get_context(0);
00491       CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec));
00492                         
00493       // Alive状態でinitialize()メソッド呼出しを行った場合、正常に動作するか?
00494       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize());
00495       rto->exit();
00496       delete rto;
00497     }
00498                 
00504     void test_finalize_invoking_on_finalize()
00505     {
00506       RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
00507                         
00508       // initialize()メソッド呼出しを行い、Alive状態に遷移させる
00509       coil::Properties prop;
00510       prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext");
00511       prop.setProperty("exec_cxt.periodic.rate","1000");
00512       rto->setProperties(prop);
00513       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize());
00514       RTC::ExecutionContext_ptr ec;
00515       ec = rto->get_context(0);
00516       CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec));
00517                         
00518       // finalize()呼出しにより、on_finalize()コールバックが呼び出されるか?
00519       CPPUNIT_ASSERT_EQUAL(0, rto->countLog("on_finalize"));
00520                         
00521       CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec));
00522       // exit()呼び出しで、finalize()が有効となり実行される
00523       rto->exit();
00524       CPPUNIT_ASSERT_EQUAL(1, rto->countLog("on_finalize"));
00525       delete rto;
00526     }
00527                 
00533     void test_finalize_participating_in_execution_context()
00534     {
00535       RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
00536                         
00537       // initialize()メソッド呼出しを行い、Alive状態に遷移させる
00538       coil::Properties prop;
00539       prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext");
00540       prop.setProperty("exec_cxt.periodic.rate","1000");
00541       rto->setProperties(prop);
00542       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize());
00543 
00544       RTC::ExecutionContext_ptr ec;
00545       ec = rto->get_context(0);
00546       CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec));
00547                         
00548       // ExecutionContextに登録しておく
00549       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this()));
00550                         
00551       // ExecutionContextに登録された状態でfinalize()を呼び出した場合、意図どおりのエラーを返すか?
00552       CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, rto->finalize());
00553 
00554       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->remove_component(rto->_this()));
00555       rto->exit();
00556       delete rto;
00557     }
00558                 
00564     void test_finalize_in_Created()
00565     {
00566       RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
00567                         
00568       // Created状態でfinalize()を呼出した場合、意図どおりのエラーで返るか?
00569       CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, rto->finalize());
00570       rto->shutdown();
00571       delete rto;
00572     }
00573                 
00577     void test_is_alive()
00578     {
00579       // test_initialize_in_Alive()にてテストを兼ねている
00580     }
00581                 
00588     void test_exit()
00589     {
00590       RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
00591       rto->setObjRef(rto->_this());
00592                         
00593       // initialize()メソッド呼出しを行い、Alive状態に遷移させる
00594       coil::Properties prop;
00595       prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext");
00596       prop.setProperty("exec_cxt.periodic.rate","1000");
00597       rto->setProperties(prop);
00598       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize());
00599 
00600       RTC::ExecutionContext_ptr ec;
00601       ec = rto->get_context(0);
00602       CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec));
00603                         
00604       // コンポーネントをExecutionContextに登録してアクティブ化する
00605       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this()));
00606       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->activate_component(rto->_this()));
00607       //Call start() for the state machine drive. 
00608       ec->start();
00609       coil::sleep(1);
00610                         
00611       // exit()呼出しにより、当該コンポーネントがfinalize()されるか?
00612       // exit()呼出しにより、当該コンポーネントが終状態に遷移するか?
00613       CPPUNIT_ASSERT_EQUAL(0, rto->countLog("on_finalize"));
00614       CPPUNIT_ASSERT_EQUAL(RTC::ACTIVE_STATE, ec->get_component_state(rto->_this()));
00615       ec->stop();
00616       coil::sleep(1);
00617       //Call remove_component(),to cancel the registered component.
00618       ec->remove_component(rto->_this());
00619       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->exit());
00620       CPPUNIT_ASSERT_EQUAL(1, rto->countLog("on_finalize"));
00621       CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec));
00622 
00623       delete rto;
00624     }
00625 
00631     void test_exit_in_Created()
00632     {
00633       RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
00634       rto->setObjRef(rto->_this());
00635                         
00636       // Create状態でexit()を呼出した場合、意図どおりのエラーを返すか?
00637       CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, rto->exit());
00638 
00639       rto->shutdown();
00640       delete rto;
00641     }
00642                 
00648     void test_detach_executioncontext()
00649     {
00650       RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
00651                         
00652       // ExecutionContextを生成する
00653       RTC::PeriodicExecutionContext* ec
00654         = new RTC::PeriodicExecutionContext(); // will be deleted automatically
00655                         
00656       // ExecutionContextにattachしておく
00657       RTC::UniqueId id = rto->attach_context(ec->_this());
00658       CPPUNIT_ASSERT(RTC::UniqueId(-1) != id);
00659                         
00660       // 正常にdetachできるか?
00661       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->detach_context(id));
00662       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
00663       delete ec;
00664       rto->shutdown();
00665       delete rto;
00666     }
00667                 
00673     void test_detach_executioncontext_with_illegal_id()
00674     {
00675       RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
00676                         
00677       // 存在しないIDでRTCのdetachを試みた場合、意図どおりのエラーを返すか?
00678       CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,
00679                            rto->detach_context(RTC::UniqueId(1)));
00680       rto->shutdown();
00681       delete rto;
00682     }
00683                 
00689     void test_get_context()
00690     {
00691       RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
00692                         
00693       // ExecutionContextを生成する
00694       RTC::PeriodicExecutionContext* ec1
00695         = new RTC::PeriodicExecutionContext(); // will be deleted automatically
00696       RTC::PeriodicExecutionContext* ec2
00697         = new RTC::PeriodicExecutionContext(); // will be deleted automatically
00698                         
00699       // ExecutionContextにattachしておく
00700       RTC::UniqueId id1 = rto->attach_context(ec1->_this());
00701       CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1);
00702       RTC::UniqueId id2 = rto->attach_context(ec2->_this());
00703       CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2);
00704       CPPUNIT_ASSERT(id1 != id2);
00705                         
00706       // 指定したIDのExecutionContextを正しく取得できるか?
00707       RTC::ExecutionContext_ptr ecPtr1 = rto->get_context(id1);
00708       CPPUNIT_ASSERT(ecPtr1->_is_equivalent(ec1->_this()));
00709       RTC::ExecutionContext_ptr ecPtr2 = rto->get_context(id2);
00710       CPPUNIT_ASSERT(ecPtr2->_is_equivalent(ec2->_this()));
00711 
00712       rto->detach_context(id2);
00713       rto->detach_context(id1);
00714       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec2));
00715       delete ec2;
00716       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec1));
00717       delete ec1;
00718 
00719       rto->shutdown();
00720       delete rto;
00721 
00722     }
00723                 
00729     void test_get_contexts()
00730     {
00731       RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
00732                         
00733       // ExecutionContextを生成する
00734       RTC::PeriodicExecutionContext* ec1
00735         = new RTC::PeriodicExecutionContext(); // will be deleted automatically
00736       RTC::PeriodicExecutionContext* ec2
00737         = new RTC::PeriodicExecutionContext(); // will be deleted automatically
00738 
00739       // ExecutionContextにattachしておく
00740       RTC::UniqueId id1 = rto->attach_context(ec1->_this());
00741       CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1);
00742       RTC::UniqueId id2 = rto->attach_context(ec2->_this());
00743       CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2);
00744                         
00745       // attachされているExecutionContextをすべて正しく取得できるか?
00746       RTC::ExecutionContextList* ecList = rto->get_participating_contexts();
00747       CPPUNIT_ASSERT(ecList != NULL);
00748       CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), ecList->length());
00749       CPPUNIT_ASSERT(! (*ecList)[0]->_is_equivalent((*ecList)[1]));
00750       CPPUNIT_ASSERT((*ecList)[0]->_is_equivalent(ec1->_this())
00751                      || (*ecList)[0]->_is_equivalent(ec2->_this()));
00752       CPPUNIT_ASSERT((*ecList)[1]->_is_equivalent(ec1->_this())
00753                      || (*ecList)[1]->_is_equivalent(ec2->_this()));
00754 
00755 
00756       rto->detach_context(id2);
00757       rto->detach_context(id1);
00758 
00759       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec2));
00760       delete ec2;
00761       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec1));
00762       delete ec1;
00763 
00764       rto->shutdown();
00765       delete rto;
00766     }
00767                 
00773     void test_get_component_profile()
00774     {
00775       RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
00776                         
00777       // ComponentProfileとして取得されるべき情報をあらかじめ設定しておく
00778       coil::Properties prop;
00779       prop.setProperty("instance_name", "INSTANCE_NAME");
00780       prop.setProperty("type_name", "TYPE_NAME");
00781       prop.setProperty("description", "DESCRIPTION");
00782       prop.setProperty("version", "VERSION");
00783       prop.setProperty("vendor", "VENDOR");
00784       prop.setProperty("category", "CATEGORY");
00785       rto->setProperties(prop);
00786                         
00787       // ComponentProfileを正しく取得できるか?
00788       RTC::ComponentProfile* compProf = rto->get_component_profile();
00789       CPPUNIT_ASSERT(compProf != NULL);
00790                         
00791       CPPUNIT_ASSERT_EQUAL(std::string("INSTANCE_NAME"),
00792                            std::string(compProf->instance_name));
00793       CPPUNIT_ASSERT_EQUAL(std::string("TYPE_NAME"),
00794                            std::string(compProf->type_name));
00795       CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION"),
00796                            std::string(compProf->description));
00797       CPPUNIT_ASSERT_EQUAL(std::string("VERSION"),
00798                            std::string(compProf->version));
00799       CPPUNIT_ASSERT_EQUAL(std::string("VENDOR"),
00800                            std::string(compProf->vendor));
00801       CPPUNIT_ASSERT_EQUAL(std::string("CATEGORY"),
00802                            std::string(compProf->category));
00803       rto->shutdown();
00804       delete rto;
00805       
00806     }
00807                 
00815     void test_add_removePort()
00816     {
00817       RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
00818 
00819       PortMock* port0 = new PortMock();
00820       port0->setName("port0");
00821       // Portを正しく登録できるか?
00822       CPPUNIT_ASSERT_EQUAL(true, rto->addPort(*port0));
00823       // 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか?
00824       // PortBase::updateConnectors()内、Guard guard(m_profile_mutex);でロックされ、
00825       // 処理が戻ってこない。(デッドロック???)
00826       // CPPUNIT_ASSERT_EQUAL(false, rto->addPort(*port0));
00827 
00828       PortMock* port1 = new PortMock();
00829       port1->setName("port1");
00830       CPPUNIT_ASSERT_EQUAL(true, rto->addPort(*port1));
00831                         
00832       // 登録したPort参照をすべて正しく取得できるか?
00833       RTC::PortServiceList* portList = rto->get_ports();
00834       CPPUNIT_ASSERT(portList != NULL);
00835       CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length());
00836 
00837       // 登録済みのPortを正しく削除できるか?
00838       CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port1));
00839       CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port0));
00840 
00841       InPortMock*  inport0  = new InPortMock("in","TimedLong");
00842       OutPortMock* outport0 = new OutPortMock("out","TimedLong");
00843       // InPort, OutPortを正しく登録できるか?
00844       CPPUNIT_ASSERT_EQUAL(true, rto->addInPort("in",*inport0));
00845       CPPUNIT_ASSERT_EQUAL(true, rto->addOutPort("out", *outport0));
00846       // 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか?
00847       // PortBase::updateConnectors()内、Guard guard(m_profile_mutex);でロックされ、
00848       // 処理が戻ってこない。(デッドロック???)
00849       // CPPUNIT_ASSERT_EQUAL(false, rto->addInPort("in",*inport0));
00850       // CPPUNIT_ASSERT_EQUAL(false, rto->addOutPort("out", *outport0));
00851 
00852       // 登録したPort参照をすべて正しく取得できるか?
00853       portList = rto->get_ports();
00854       CPPUNIT_ASSERT(portList != NULL);
00855       CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length());
00856 
00857       // 登録済みのPortを正しく削除できるか?
00858       CPPUNIT_ASSERT_EQUAL(true, rto->removeInPort(*inport0));
00859       CPPUNIT_ASSERT_EQUAL(true, rto->removeOutPort(*outport0));
00860 
00861       portList = rto->get_ports();
00862       CPPUNIT_ASSERT(portList != NULL);
00863       CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), portList->length());
00864 
00865       delete outport0;
00866       delete inport0;
00867       delete port1;
00868       delete port0;
00869 
00870       rto->shutdown();
00871       delete rto;
00872 
00873     }
00874 
00882     void test_readAll()
00883     {
00884       RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
00885 
00886       InPortMock*  inport0  = new InPortMock("in","TimedLong");
00887       InPortMock*  inport1  = new InPortMock("in2","TimedLong");
00888       OutPortMock* outport0 = new OutPortMock("out","TimedLong");
00889 
00890       rto->addInPort("in",*inport0);
00891       rto->addInPort("in2",*inport1);
00892       rto->addOutPort("out", *outport0);
00893 
00894       // readAll()で全てのInPortのread()がコールされるか?
00895       CPPUNIT_ASSERT_EQUAL(true, rto->readAll());
00896       CPPUNIT_ASSERT_EQUAL(1, inport0->get_counter());
00897       CPPUNIT_ASSERT_EQUAL(1, inport1->get_counter());
00898 
00899       // setReadAll()で全てのInPortのread()がコールされるか?
00900       rto->setReadAll();
00901       rto->on_execute(0);
00902       CPPUNIT_ASSERT_EQUAL(2, inport0->get_counter());
00903       CPPUNIT_ASSERT_EQUAL(2, inport1->get_counter());
00904 
00905       // setReadAll(),readAll()が正しく機能しているか?
00906       inport0->set_return(false);
00907       rto->setReadAll(true,false);
00908       CPPUNIT_ASSERT_EQUAL(false, rto->readAll());
00909       CPPUNIT_ASSERT_EQUAL(3, inport0->get_counter());
00910       // Because setReadAll(true,false) was called,
00911       // inport1.read() was not called.
00912       // inport0.read() return false.
00913       CPPUNIT_ASSERT_EQUAL(2, inport1->get_counter());
00914 
00915       rto->setReadAll(true,true);
00916       CPPUNIT_ASSERT_EQUAL(false, rto->readAll());
00917       CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter());
00918       // Because setReadAll(true,true) was called,
00919       // inport0.read() return false,
00920       // but inport1.read() was called.
00921       CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter());
00922 
00923       rto->setReadAll(false,true);
00924       rto->on_execute(0);
00925       // Because setReadAll(false,true) was called,
00926       // inport0.read() and inport1.read() was not called.
00927       CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter());
00928       CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter());
00929       
00930       rto->setReadAll(false,false);
00931       rto->on_execute(0);
00932       // Because setReadAll(false,true) was called,
00933       // inport0.read() and inport1.read() was not called.
00934       CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter());
00935       CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter());
00936       
00937       rto->removeInPort(*inport0);
00938       rto->removeInPort(*inport1);
00939       rto->removeOutPort(*outport0);
00940       
00941       delete outport0;
00942       delete inport0;
00943       delete inport1;
00944 
00945       rto->shutdown();
00946       delete rto;
00947     }
00948 
00949 
00957     void test_writeAll()
00958     {
00959       RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
00960 
00961       OutPortMock*  outport0  = new OutPortMock("out","TimedLong");
00962       OutPortMock*  outport1  = new OutPortMock("out2","TimedLong");
00963       InPortMock*  inport0 = new InPortMock("in","TimedLong");
00964 
00965       rto->addOutPort("out",*outport0);
00966       rto->addOutPort("out2",*outport1);
00967       rto->addInPort("in", *inport0);
00968 
00969       // writeAll()で全てのOutPortのwrite()がコールされるか?
00970       CPPUNIT_ASSERT_EQUAL(true, rto->writeAll());
00971       CPPUNIT_ASSERT_EQUAL(1, outport0->get_counter());
00972       CPPUNIT_ASSERT_EQUAL(1, outport1->get_counter());
00973 
00974       // setWriteAll()で全てのOutPortのwrite()がコールされるか?
00975       rto->setWriteAll();
00976       rto->on_execute(0);
00977       CPPUNIT_ASSERT_EQUAL(2, outport0->get_counter());
00978       CPPUNIT_ASSERT_EQUAL(2, outport1->get_counter());
00979 
00980       // setWriteAll(),writeAll()が正しく機能しているか?
00981       outport0->set_return(false);
00982       rto->setWriteAll(true,false);
00983       CPPUNIT_ASSERT_EQUAL(false, rto->writeAll());
00984       CPPUNIT_ASSERT_EQUAL(3, outport0->get_counter());
00985       // Because setWriteAll(true,false) was called,
00986       // outport1.write() was not called.
00987       // outport0.write() return false.
00988       CPPUNIT_ASSERT_EQUAL(2, outport1->get_counter());
00989 
00990       rto->setWriteAll(true,true);
00991       CPPUNIT_ASSERT_EQUAL(false, rto->writeAll());
00992       CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter());
00993       // Because setWriteAll(true,true) was called,
00994       // outport0.write() return false,
00995       // but outport1.write() was called.
00996       CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter());
00997 
00998       rto->setWriteAll(false,true);
00999       rto->on_execute(0);
01000       // Because setWriteAll(false,true) was called,
01001       // outport0.write() and outport1.write() was not called.
01002       CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter());
01003       CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter());
01004       
01005       rto->setWriteAll(false,false);
01006       rto->on_execute(0);
01007       // Because setWriteAll(false,true) was called,
01008       // outport0.write() and outport1.write() was not called.
01009       CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter());
01010       CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter());
01011       
01012       rto->removeOutPort(*outport0);
01013       rto->removeOutPort(*outport1);
01014       rto->removeInPort(*inport0);
01015       
01016       delete outport0;
01017       delete outport1;
01018       delete inport0;
01019 
01020       rto->shutdown();
01021       delete rto;
01022     }
01023 
01024 
01030     void test_get_ports()
01031     {
01032       RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
01033 
01034       // Portを登録しておく
01035       PortMock* port0 = new PortMock();
01036       port0->setName("port0");
01037       rto->addPort(*port0);
01038 
01039       PortMock* port1 = new PortMock();
01040       port1->setName("port1");
01041       rto->addPort(*port1);
01042                         
01043       // 登録したPort参照をすべて正しく取得できるか?
01044       RTC::PortServiceList* portList = rto->get_ports();
01045       CPPUNIT_ASSERT(portList != NULL);
01046       CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length());
01047       CPPUNIT_ASSERT(CORBA::Long(-1)
01048                      != CORBA_SeqUtil::find(*portList, PortFinder(port0->_this())));
01049       CPPUNIT_ASSERT(CORBA::Long(-1)
01050                      != CORBA_SeqUtil::find(*portList, PortFinder(port1->_this())));
01051 
01052       CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port1));
01053       CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port0));
01054 
01055       delete port1;
01056       delete port0;
01057 
01058       rto->shutdown();
01059       delete rto;
01060 
01061     }
01062                 
01068 /*
01069     void test_get_execution_context_services()
01070     {
01071       RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
01072 
01073       // ExecutionContextを生成する
01074       RTC::PeriodicExecutionContext* ec1
01075         = new RTC::PeriodicExecutionContext(); // will be deleted automatically
01076       RTC::PeriodicExecutionContext* ec2
01077         = new RTC::PeriodicExecutionContext(); // will be deleted automatically
01078 
01079       // ExecutionContextにattachしておく
01080       RTC::UniqueId id1 = rto->attach_context(ec1->_this());
01081       CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1);
01082       RTC::UniqueId id2 = rto->attach_context(ec2->_this());
01083       CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2);
01084 
01085       // ExecutionContextServiceをすべて正しく取得できるか?
01086       // (注) RTC::PeriodicExecutionContextはExecutionContextServiceのサブクラスになっている。
01087       RTC::ExecutionContextServiceList* ecSvcList
01088 //      = rto->get_execution_context_services();
01089         = rto->get_owned_contexts();
01090       CPPUNIT_ASSERT(ecSvcList != NULL);
01091       CPPUNIT_ASSERT(CORBA::Long(-1)
01092                      != CORBA_SeqUtil::find(*ecSvcList, ExecutionContextServiceFinder(ec1->_this())));
01093       CPPUNIT_ASSERT(CORBA::Long(-1)
01094                      != CORBA_SeqUtil::find(*ecSvcList, ExecutionContextServiceFinder(ec2->_this())));
01095     }
01096 */              
01097     void test_get_owned_organizations()
01098     {
01099       // テスト対象が未実装につき、テスト未実装
01100     }
01101                 
01108     void test_get_sdo_id()
01109     {
01110       RTObjectMock* rto1 = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
01111       rto1->setInstanceName("INSTANCE_NAME 1");
01112       std::string str1(rto1->getInstanceName());
01113       CPPUNIT_ASSERT("INSTANCE_NAME 1" == str1);
01114       RTObjectMock* rto2 = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
01115       rto2->setInstanceName("INSTANCE_NAME 2");
01116       std::string str2(rto2->getInstanceName());
01117       CPPUNIT_ASSERT("INSTANCE_NAME 2" == str2);
01118 
01119       // SDO IDを取得できるか?
01120       char* id1 = rto1->get_sdo_id();
01121       CPPUNIT_ASSERT(id1 != NULL);
01122       char* id2 = rto2->get_sdo_id();
01123       CPPUNIT_ASSERT(id2 != NULL);
01124                         
01125       // 取得されたSDO IDは一意か?
01126       // (注) instance_nameがSDO IDとしてそのまま使用されることに注意。
01127       //      つまり、実装上、SDO IDの一意性はinstance_nameの一意性に基づいている。
01128       //      仕様上、instance_nameは一意でなければならないので、首尾一貫している。
01129       CPPUNIT_ASSERT(id1 != id2);
01130 
01131       rto2->shutdown();
01132       delete rto2;
01133       rto1->shutdown();
01134       delete rto1;
01135     }
01136                 
01142     void test_get_sdo_type()
01143     {
01144       RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
01145                                 
01146       // ※ 実装上、type_nameがSDOタイプとして使用されているため、ここで準備設定している
01147       coil::Properties prop;
01148       prop.setProperty("type_name", "TYPE_NAME");
01149       rto->setProperties(prop);
01150                         
01151       // SDOタイプを取得できるか?
01152       char* sdoType = rto->get_sdo_type();
01153       CPPUNIT_ASSERT(sdoType != NULL);
01154 
01155       rto->shutdown();
01156       delete rto;
01157     }
01158                 
01164     void test_get_device_profile()
01165     {
01166       // test_get_configuration_and_set_device_profile_and_get_device_profileで兼ねる
01167     }
01168                 
01174     void test_get_service_profile()
01175     {
01176       // test_get_configuration_and_set_service_profile_and_get_service_profileで兼ねる
01177     }
01178                 
01185     void test_get_service_profile_with_illegal_arguments()
01186     {
01187       RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
01188                         
01189       // 引数にNULLを指定した場合、意図どおりの例外がスローされるか?
01190       try
01191         {
01192           rto->get_service_profile(NULL);
01193           CPPUNIT_FAIL("Exception not thrown.");
01194         }
01195       catch (SDOPackage::InvalidParameter expected)
01196         {
01197           // 意図どおりの例外をキャッチした
01198         }
01199       catch (...)
01200         {
01201           // 意図しない例外をキャッチした
01202           CPPUNIT_FAIL("Unexpected exception caught.");
01203         }
01204                         
01205       // 引数に存在しないIDを指定した場合、意図どおりの例外がスローされるか?
01206       try
01207         {
01208           rto->get_service_profile("INEXIST ID");
01209           CPPUNIT_FAIL("Exception not thrown.");
01210         }
01211       catch (SDOPackage::InvalidParameter expected)
01212         {
01213           // 意図どおりの例外をキャッチした
01214         }
01215       catch (...)
01216         {
01217           // 意図しない例外をキャッチした
01218           CPPUNIT_FAIL("Unexpected exception caught.");
01219         }
01220       rto->shutdown();
01221       delete rto;
01222     }
01223                 
01229     void test_get_sdo_service()
01230     {
01231       // test_get_configuration_and_set_service_profile_and_get_sdo_serviceで兼ねる
01232     }
01233                 
01234     void test_get_sdo_service_with_illegal_arguments()
01235     {
01236       RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
01237                         
01238       // 引数にNULLを指定した場合、意図どおりの例外がスローされるか?
01239       try
01240         {
01241           rto->get_sdo_service(NULL);
01242           CPPUNIT_FAIL("Exception not thrown.");
01243         }
01244       catch (SDOPackage::InvalidParameter expected)
01245         {
01246           // 意図どおりの例外をキャッチした
01247         }
01248       catch (...)
01249         {
01250           // 意図しない例外をキャッチした
01251           CPPUNIT_FAIL("Unexpected exception caught.");
01252         }
01253                         
01254       // 引数に、存在しないIDを指定した場合、意図どおりの例外がスローされるか?
01255       try
01256         {
01257           rto->get_sdo_service("INEXIST ID");
01258           CPPUNIT_FAIL("Exception not thrown.");
01259         }
01260       catch (SDOPackage::InvalidParameter expected)
01261         {
01262           // 意図どおりの例外をキャッチした
01263         }
01264       catch (...)
01265         {
01266           // 意図しない例外をキャッチした
01267           CPPUNIT_FAIL("Unexpected exception caught.");
01268         }
01269 
01270       rto->shutdown();
01271       delete rto;
01272     }
01273                 
01280     void test_get_configuration_and_set_device_profile_and_get_device_profile()
01281     {
01282       RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
01283                         
01284       // DeviceProfileを準備しておく
01285       SDOPackage::DeviceProfile devProf;
01286       devProf.device_type = "DEVICE_TYPE";
01287       devProf.manufacturer = "MANUFACTURER";
01288       devProf.model = "MODEL";
01289       devProf.version = "VERSION";
01290       devProf.properties.length(1);
01291       devProf.properties[0].name = "PROPERTIES NAME";
01292       devProf.properties[0].value <<= "PROPERTIES VALUE";
01293                         
01294       // Configurationインタフェースを取得し、DeviceProfileを設定する
01295       SDOPackage::Configuration_ptr cfg = rto->get_configuration();
01296       cfg->set_device_profile(devProf);
01297       // DeviceProfileを取得して、正しく設定されたことを確認する
01298       SDOPackage::DeviceProfile* devProfRet = rto->get_device_profile();
01299       CPPUNIT_ASSERT_EQUAL(std::string("DEVICE_TYPE"),
01300                            std::string(devProfRet->device_type));
01301       CPPUNIT_ASSERT_EQUAL(std::string("MANUFACTURER"),
01302                            std::string(devProfRet->manufacturer));
01303       CPPUNIT_ASSERT_EQUAL(std::string("MODEL"),
01304                            std::string(devProfRet->model));
01305       CPPUNIT_ASSERT_EQUAL(std::string("VERSION"),
01306                            std::string(devProfRet->version));
01307       CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), devProfRet->properties.length());
01308       CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME"),
01309                            std::string(devProfRet->properties[0].name));
01310       {
01311         const char* value; devProfRet->properties[0].value >>= value;
01312         CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES VALUE"), std::string(value));
01313       }
01314 
01315       rto->shutdown();
01316       delete rto;
01317     }
01318                 
01325     void test_get_configuration_and_set_service_profile_and_get_service_profile()
01326     {
01327       RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
01328 
01329       // SDOServiceを準備する
01330       SDOServiceMock* sdoSvc1 = new SDOServiceMock();
01331       SDOServiceMock* sdoSvc2 = new SDOServiceMock();
01332                         
01333       // ServiceProfileを準備しておく
01334       SDOPackage::ServiceProfile svcProf1;
01335       svcProf1.id = "ID 1";
01336       svcProf1.interface_type = "INTERFACE_TYPE 1";
01337       svcProf1.properties.length(1);
01338       svcProf1.properties[0].name = "PROPERTIES NAME 1";
01339       svcProf1.properties[0].value <<= "3.14159";
01340       svcProf1.service = sdoSvc1->_this();
01341 
01342       SDOPackage::ServiceProfile svcProf2;
01343       svcProf2.id = "ID 2";
01344       svcProf2.interface_type = "INTERFACE_TYPE 2";
01345       svcProf2.properties.length(1);
01346       svcProf2.properties[0].name = "PROPERTIES NAME 2";
01347       svcProf2.properties[0].value <<= "2.71828";
01348       svcProf2.service = sdoSvc2->_this();
01349                         
01350       // Configurationインタフェースを取得し、ServiceProfileを設定する
01351       SDOPackage::Configuration_ptr cfg = rto->get_configuration();
01352       CPPUNIT_ASSERT(! CORBA::is_nil(cfg));
01353       cfg->add_service_profile(svcProf1);
01354       cfg->add_service_profile(svcProf2);
01355                         
01356       // get_service_profile()を用いてServiceProfileを取得して、正しく設定されたことを確認する
01357       SDOPackage::ServiceProfile* svcProfRet1 = rto->get_service_profile("ID 1");
01358       CPPUNIT_ASSERT(svcProfRet1 != NULL);
01359       CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(svcProfRet1->id));
01360       CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"),
01361                            std::string(svcProfRet1->interface_type));
01362       CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet1->properties.length());
01363       CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"),
01364                            std::string(svcProfRet1->properties[0].name));
01365       {
01366         const char* value; svcProfRet1->properties[0].value >>= value;
01367         CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value));
01368       }
01369                         
01370       SDOPackage::ServiceProfile* svcProfRet2 = rto->get_service_profile("ID 2");
01371       CPPUNIT_ASSERT(svcProfRet2 != NULL);
01372       CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string(svcProfRet2->id));
01373       CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"),
01374                            std::string(svcProfRet2->interface_type));
01375       CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet2->properties.length());
01376       CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"),
01377                            std::string(svcProfRet2->properties[0].name));
01378       {
01379         const char* value; svcProfRet2->properties[0].value >>= value;
01380         CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value));
01381       }
01382 
01383       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2));
01384       delete sdoSvc2;
01385       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1));
01386       delete sdoSvc1;
01387 
01388       rto->shutdown();
01389       delete rto;
01390     }
01391                 
01397     void test_get_configuration_and_set_service_profile_and_get_service_profiles()
01398     {
01399       RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
01400 
01401       // SDOServiceを準備する
01402       SDOServiceMock* sdoSvc1 = new SDOServiceMock();
01403       SDOServiceMock* sdoSvc2 = new SDOServiceMock();
01404                         
01405       // ServiceProfileを準備しておく
01406       SDOPackage::ServiceProfile svcProf1;
01407       svcProf1.id = "ID 1";
01408       svcProf1.interface_type = "INTERFACE_TYPE 1";
01409       svcProf1.properties.length(1);
01410       svcProf1.properties[0].name = "PROPERTIES NAME 1";
01411       svcProf1.properties[0].value <<= "3.14159";
01412       svcProf1.service = sdoSvc1->_this();
01413 
01414       SDOPackage::ServiceProfile svcProf2;
01415       svcProf2.id = "ID 2";
01416       svcProf2.interface_type = "INTERFACE_TYPE 2";
01417       svcProf2.properties.length(1);
01418       svcProf2.properties[0].name = "PROPERTIES NAME 2";
01419       svcProf2.properties[0].value <<= "2.71828";
01420       svcProf2.service = sdoSvc2->_this();
01421                         
01422       // Configurationインタフェースを取得し、ServiceProfileを設定する
01423       SDOPackage::Configuration_ptr cfg = rto->get_configuration();
01424       CPPUNIT_ASSERT(! CORBA::is_nil(cfg));
01425       cfg->add_service_profile(svcProf1);
01426       cfg->add_service_profile(svcProf2);
01427                         
01428       // get_service_profiles()を使ってServiceProfile群を取得して、正しく設定されたことを確認する
01429       SDOPackage::ServiceProfileList* svcProfList = rto->get_service_profiles();
01430       CPPUNIT_ASSERT(svcProfList != NULL);
01431                         
01432       CORBA::Long svcProfIdx1 = CORBA_SeqUtil::find(
01433                                                     *svcProfList, ServiceProfileFinder("ID 1"));
01434       CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx1);
01435       CPPUNIT_ASSERT_EQUAL(std::string("ID 1"),
01436                            std::string((*svcProfList)[svcProfIdx1].id));
01437       CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"),
01438                            std::string((*svcProfList)[svcProfIdx1].interface_type));
01439       CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1),
01440                            (*svcProfList)[svcProfIdx1].properties.length());
01441       CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"),
01442                            std::string((*svcProfList)[svcProfIdx1].properties[0].name));
01443       {
01444         const char* value; (*svcProfList)[svcProfIdx1].properties[0].value >>= value;
01445         CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value));
01446       }
01447                         
01448       CORBA::Long svcProfIdx2 = CORBA_SeqUtil::find(
01449                                                     *svcProfList, ServiceProfileFinder("ID 2"));
01450       CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx2);
01451       CPPUNIT_ASSERT_EQUAL(std::string("ID 2"),
01452                            std::string((*svcProfList)[svcProfIdx2].id));
01453       CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"),
01454                            std::string((*svcProfList)[svcProfIdx2].interface_type));
01455       CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1),
01456                            (*svcProfList)[svcProfIdx2].properties.length());
01457       CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"),
01458                            std::string((*svcProfList)[svcProfIdx2].properties[0].name));
01459       {
01460         const char* value; (*svcProfList)[svcProfIdx2].properties[0].value >>= value;
01461         CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value));
01462       }
01463       
01464       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2));
01465       delete sdoSvc2;
01466       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1));
01467       delete sdoSvc1;
01468 
01469       rto->shutdown();
01470       delete rto;
01471     }
01472                 
01479     void test_get_configuration_and_set_service_profile_and_get_sdo_service()
01480     {
01481       RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
01482 
01483       // SDOServiceを準備する
01484       SDOServiceMock* sdoSvc1 = new SDOServiceMock();
01485       SDOServiceMock* sdoSvc2 = new SDOServiceMock();
01486                         
01487       // ServiceProfileを準備しておく
01488       SDOPackage::ServiceProfile svcProf1;
01489       svcProf1.id = "ID 1";
01490       svcProf1.interface_type = "INTERFACE_TYPE 1";
01491       svcProf1.properties.length(1);
01492       svcProf1.properties[0].name = "PROPERTIES NAME 1";
01493       svcProf1.properties[0].value <<= "3.14159";
01494       svcProf1.service = sdoSvc1->_this();
01495 
01496       SDOPackage::ServiceProfile svcProf2;
01497       svcProf2.id = "ID 2";
01498       svcProf2.interface_type = "INTERFACE_TYPE 2";
01499       svcProf2.properties.length(1);
01500       svcProf2.properties[0].name = "PROPERTIES NAME 2";
01501       svcProf2.properties[0].value <<= "2.71828";
01502       svcProf2.service = sdoSvc2->_this();
01503                         
01504       // Configurationインタフェースを取得し、ServiceProfileを設定する
01505       SDOPackage::Configuration_ptr cfg = rto->get_configuration();
01506       CPPUNIT_ASSERT(! CORBA::is_nil(cfg));
01507       cfg->add_service_profile(svcProf1);
01508       cfg->add_service_profile(svcProf2);
01509                         
01510       // 指定したIDのSDOServiceを正しく取得できるか?
01511       SDOPackage::SDOService_ptr sdoSvcRet1 = rto->get_sdo_service("ID 1");
01512       CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet1));
01513       CPPUNIT_ASSERT(sdoSvcRet1->_is_equivalent(sdoSvc1->_this()));
01514 
01515       SDOPackage::SDOService_ptr sdoSvcRet2 = rto->get_sdo_service("ID 2");
01516       CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet2));
01517       CPPUNIT_ASSERT(sdoSvcRet2->_is_equivalent(sdoSvc2->_this()));
01518 
01519       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2));
01520       delete sdoSvc2;
01521       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1));
01522       delete sdoSvc1;
01523 
01524       rto->shutdown();
01525       delete rto;
01526 
01527     }
01528                 
01534     void test_get_configuration_and_remove_service_profile()
01535     {
01536       RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
01537 
01538       // SDOServiceを準備する
01539       SDOServiceMock* sdoSvc1 = new SDOServiceMock();
01540       SDOServiceMock* sdoSvc2 = new SDOServiceMock();
01541                         
01542       // ServiceProfileを準備しておく
01543       SDOPackage::ServiceProfile svcProf1;
01544       svcProf1.id = "ID 1";
01545       svcProf1.interface_type = "INTERFACE_TYPE 1";
01546       svcProf1.properties.length(1);
01547       svcProf1.properties[0].name = "PROPERTIES NAME 1";
01548       svcProf1.properties[0].value <<= "3.14159";
01549       svcProf1.service = sdoSvc1->_this();
01550 
01551       SDOPackage::ServiceProfile svcProf2;
01552       svcProf2.id = "ID 2";
01553       svcProf2.interface_type = "INTERFACE_TYPE 2";
01554       svcProf2.properties.length(1);
01555       svcProf2.properties[0].name = "PROPERTIES NAME 2";
01556       svcProf2.properties[0].value <<= "2.71828";
01557       svcProf2.service = sdoSvc2->_this();
01558                         
01559       // Configurationインタフェースを取得し、ServiceProfileを設定する
01560       SDOPackage::Configuration_ptr cfg = rto->get_configuration();
01561       CPPUNIT_ASSERT(! CORBA::is_nil(cfg));
01562       cfg->add_service_profile(svcProf1);
01563       cfg->add_service_profile(svcProf2);
01564       CPPUNIT_ASSERT(rto->get_service_profile("ID 1") != NULL);
01565       CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL);
01566                         
01567       // 設定したうち、片方のServiceProfileをremoveして、正しくremoveされたことを確認する
01568       CPPUNIT_ASSERT_EQUAL(true, cfg->remove_service_profile("ID 1"));
01569       try
01570         {
01571           rto->get_service_profile("ID 1");
01572           CPPUNIT_FAIL("Expected exception not thrown.");
01573         }
01574       catch (SDOPackage::InvalidParameter expected) {}
01575       CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL);
01576 
01577       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2));
01578       delete sdoSvc2;
01579       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1));
01580       delete sdoSvc1;
01581 
01582       rto->shutdown();
01583       delete rto;
01584     }
01585                 
01592     void test_get_configuration_and_add_organization_and_get_organizations()
01593     {
01594       RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
01595                         
01596       // Organizationを準備する
01597       OrganizationMock* org1 = new OrganizationMock("ORG 1");
01598       OrganizationMock* org2 = new OrganizationMock("ORG 2");
01599 
01600       // Configurationインタフェースを取得し、Organizationを追加する
01601       SDOPackage::Configuration_ptr cfg = rto->get_configuration();
01602       CPPUNIT_ASSERT(! CORBA::is_nil(cfg));
01603       CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this()));
01604       CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this()));
01605                         
01606       // get_organizations()を用いてOrganization群を正しく取得できるか?
01607       SDOPackage::OrganizationList* orgList = rto->get_organizations();
01608       CPPUNIT_ASSERT(orgList != NULL);
01609       CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length());
01610                         
01611       CORBA::Long orgIdx1 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 1"));
01612       CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx1);
01613       CPPUNIT_ASSERT_EQUAL(std::string("ORG 1"),
01614                            std::string((*orgList)[orgIdx1]->get_organization_id()));
01615 
01616       CORBA::Long orgIdx2 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 2"));
01617       CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx2);
01618       CPPUNIT_ASSERT_EQUAL(std::string("ORG 2"),
01619                            std::string((*orgList)[orgIdx2]->get_organization_id()));
01620 
01621       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2));
01622       delete org2;
01623       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1));
01624       delete org1;
01625 
01626       rto->shutdown();
01627       delete rto;
01628     }
01629                 
01635     void test_get_configuration_and_remove_organization()
01636     {
01637       RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
01638                         
01639       // Organizationを準備する
01640       OrganizationMock* org1 = new OrganizationMock("ORG 1");
01641       OrganizationMock* org2 = new OrganizationMock("ORG 2");
01642 
01643       // Configurationインタフェースを取得し、Organizationを追加する
01644       SDOPackage::Configuration_ptr cfg = rto->get_configuration();
01645       CPPUNIT_ASSERT(! CORBA::is_nil(cfg));
01646       CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this()));
01647       CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this()));
01648                         
01649       // 追加されていることを確認しておく
01650       SDOPackage::OrganizationList* orgList = rto->get_organizations();
01651       CPPUNIT_ASSERT(orgList != NULL);
01652       CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length());
01653                         
01654       // 追加したうち、片方のOrganizationをremoveし、正しくremoveされていることを確認する
01655       CPPUNIT_ASSERT_EQUAL(true, cfg->remove_organization("ORG 1"));
01656       orgList = rto->get_organizations();
01657       CPPUNIT_ASSERT(orgList != NULL);
01658       CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), orgList->length());
01659 
01660       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2));
01661       delete org2;
01662       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1));
01663       delete org1;
01664 
01665       rto->shutdown();
01666       delete rto;
01667     }
01668                 
01672     void test_get_monitoring()
01673     {
01674       // テスト対象が未実装につき、テストも未実装
01675     }
01676                 
01682     void test_get_status()
01683     {
01684       RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
01685                         
01686       // Mockの機能を用いてstatusを設定しておく
01687       CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159);
01688       rto->set_status("STATUS 1", valueAny1);
01689                         
01690       CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828);
01691       rto->set_status("STATUS 2", valueAny2);
01692                         
01693       // 設定したstatusを正しく取得できるか?
01694       CORBA::Any* valueAnyRet1 = rto->get_status("STATUS 1");
01695       CPPUNIT_ASSERT(valueAnyRet1 != NULL);
01696       {
01697         CORBA::Float value; *valueAnyRet1 >>= value;
01698         CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value);
01699       }
01700                         
01701       CORBA::Any* valueAnyRet2 = rto->get_status("STATUS 2");
01702       CPPUNIT_ASSERT(valueAnyRet2 != NULL);
01703       {
01704         CORBA::Float value; *valueAnyRet2 >>= value;
01705         CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value);
01706       }
01707       
01708       rto->shutdown();
01709       delete rto;
01710 
01711     }
01712                 
01718     void test_get_status_list()
01719     {
01720       RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
01721                         
01722       // Mockの機能を用いてstatusを設定しておく
01723       CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159);
01724       rto->set_status("STATUS 1", valueAny1);
01725                         
01726       CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828);
01727       rto->set_status("STATUS 2", valueAny2);
01728                         
01729       // 設定したstatusを正しく取得できるか?
01730       SDOPackage::NVList* statusList = rto->get_status_list();
01731       CPPUNIT_ASSERT(statusList != NULL);
01732       CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), statusList->length());
01733                         
01734       const CORBA::Any& valueAnyRet1 = NVUtil::find(*statusList, "STATUS 1");
01735       {
01736         CORBA::Float value; valueAnyRet1 >>= value;
01737         CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value);
01738       }
01739 
01740       const CORBA::Any& valueAnyRet2 = NVUtil::find(*statusList, "STATUS 2");
01741       {
01742         CORBA::Float value; valueAnyRet2 >>= value;
01743         CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value);
01744       }
01745 
01746       rto->shutdown();
01747       delete rto;
01748     }
01749                 
01755     void test_finalizeContexts()
01756     {
01757       RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA);
01758       coil::Properties prop;
01759       prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext");
01760       prop.setProperty("exec_cxt.periodic.rate","1000");
01761       rto->setProperties(prop);
01762       // initialize()で、m_eclistへ登録し、m_ecMineをstart
01763       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize());
01764       CPPUNIT_ASSERT_EQUAL(1, rto->get_eclist());
01765       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize());
01766       CPPUNIT_ASSERT_EQUAL(2, rto->get_eclist());
01767       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize());
01768       CPPUNIT_ASSERT_EQUAL(3, rto->get_eclist());
01769 
01770       RTC::ExecutionContext_ptr ec;
01771       ec = rto->get_context(0);
01772       CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec));
01773       rto->finalizeContexts();
01774 
01775       // 全コンテキストが削除されたか?
01776       CPPUNIT_ASSERT_EQUAL(0, rto->get_eclist());
01777       rto->exit();
01778       delete rto;
01779     }
01780                 
01786     void test_bindContext()
01787     {
01788       RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA);
01789       coil::Properties prop;
01790       prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext");
01791       prop.setProperty("exec_cxt.periodic.rate","1000");
01792       rto->setProperties(prop);
01793 
01794       RTC::ExecutionContext_ptr ec;
01795 
01796       // nilを設定した場合、-1を返すか?
01797       ec = RTC::ExecutionContext::_nil();
01798       int id = (int)(rto->bindContext(ec));
01799       CPPUNIT_ASSERT_EQUAL(-1, id);
01800 
01801       // m_ecMine 未登録の場合、m_ecMineの番号を返すか?
01802       RTC::PeriodicExecutionContext* pec = new RTC::PeriodicExecutionContext();
01803       ec = pec->getObjRef();
01804       id = (int)(rto->bindContext(ec));
01805 
01806       // [0]に登録されるか?
01807       CPPUNIT_ASSERT_EQUAL(0, id);
01808 
01809       // 正しく登録されているか?
01810       CPPUNIT_ASSERT(rto->chk_ecMine(id,ec));
01811 
01812       // m_ecMine 登録済みで nil の場合、m_ecMineの番号を返すか?
01813       rto->ecMine[0] = RTC::ExecutionContextService::_nil();
01814       rto->set_ecMine();
01815       RTC::PeriodicExecutionContext* pec2 = new RTC::PeriodicExecutionContext();
01816       ec = pec2->getObjRef();
01817       id = (int)(rto->bindContext(ec));
01818 
01819       // [0]に登録されるか?
01820       CPPUNIT_ASSERT_EQUAL(0, id);
01821 
01822       // 正しく登録されているか?
01823       CPPUNIT_ASSERT(rto->chk_ecMine(id,ec));
01824 
01825       rto->exit();
01826 
01827       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec));
01828       delete pec;
01829       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec2));
01830       delete pec2;
01831 
01832       rto->shutdown();
01833       delete rto;
01834 
01835     }
01836                 
01837   };
01838 }; // namespace RTObject
01839 
01840 /*
01841  * Register test suite
01842  */
01843 CPPUNIT_TEST_SUITE_REGISTRATION(RTObject::RTObjectTests);
01844 
01845 #ifdef LOCAL_MAIN
01846 int main(int argc, char* argv[])
01847 {
01848 
01849   FORMAT format = TEXT_OUT;
01850   int target = 0;
01851   std::string xsl;
01852   std::string ns;
01853   std::string fname;
01854   std::ofstream ofs;
01855 
01856   int i(1);
01857   while (i < argc)
01858     {
01859       std::string arg(argv[i]);
01860       std::string next_arg;
01861       if (i + 1 < argc) next_arg = argv[i + 1];
01862       else              next_arg = "";
01863 
01864       if (arg == "--text") { format = TEXT_OUT; break; }
01865       if (arg == "--xml")
01866         {
01867           if (next_arg == "")
01868             {
01869               fname = argv[0];
01870               fname += ".xml";
01871             }
01872           else
01873             {
01874               fname = next_arg;
01875             }
01876           format = XML_OUT;
01877           ofs.open(fname.c_str());
01878         }
01879       if ( arg == "--compiler"  ) { format = COMPILER_OUT; break; }
01880       if ( arg == "--cerr"      ) { target = 1; break; }
01881       if ( arg == "--xsl"       )
01882         {
01883           if (next_arg == "") xsl = "default.xsl"; 
01884           else                xsl = next_arg;
01885         }
01886       if ( arg == "--namespace" )
01887         {
01888           if (next_arg == "")
01889             {
01890               std::cerr << "no namespace specified" << std::endl;
01891               exit(1); 
01892             }
01893           else
01894             {
01895               xsl = next_arg;
01896             }
01897         }
01898       ++i;
01899     }
01900   CppUnit::TextUi::TestRunner runner;
01901   if ( ns.empty() )
01902     runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
01903   else
01904     runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
01905   CppUnit::Outputter* outputter = 0;
01906   std::ostream* stream = target ? &std::cerr : &std::cout;
01907   switch ( format )
01908     {
01909     case TEXT_OUT :
01910       outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
01911       break;
01912     case XML_OUT :
01913       std::cout << "XML_OUT" << std::endl;
01914       outputter = new CppUnit::XmlOutputter(&runner.result(),
01915                                             ofs, "shift_jis");
01916       static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
01917       break;
01918     case COMPILER_OUT :
01919       outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
01920       break;
01921     }
01922   runner.setOutputter(outputter);
01923   runner.run();
01924   return 0; // runner.run() ? 0 : 1;
01925 }
01926 #endif // MAIN
01927 #endif // RTObject_cpp


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sun Mar 26 2017 03:37:17