PeriodicExecutionContextTests.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00012 /*
00013  * $Log: PeriodicExecutionContextTests.cpp,v $
00014  * Revision 1.3  2008/04/11 13:19:07  arafune
00015  * Added some new tests.
00016  *
00017  * Revision 1.2  2008/04/09 13:10:37  arafune
00018  * Added attach_executioncontext/detach_executioncontext method to the DFP class.
00019  *
00020  * Revision 1.1  2007/12/20 07:50:19  arafune
00021  * *** empty log message ***
00022  *
00023  * Revision 1.2  2007/04/13 15:04:39  n-ando
00024  * Now RTC::OK becomes RTC::RTC_OK in RTC.idl.
00025  *
00026  * Revision 1.1  2007/01/21 13:07:20  n-ando
00027  * *** empty log message ***
00028  *
00029  *
00030  */
00031 
00032 #ifndef PeriodicExecutionContext_cpp
00033 #define PeriodicExecutionContext_cpp
00034 
00035 #include <cppunit/ui/text/TestRunner.h>
00036 #include <cppunit/TextOutputter.h>
00037 #include <cppunit/extensions/TestFactoryRegistry.h>
00038 #include <cppunit/extensions/HelperMacros.h>
00039 #include <cppunit/TestAssert.h>
00040 
00041 #include <rtm/idl/RTCSkel.h>
00042 #include <rtm/PeriodicExecutionContext.h>
00043 #include <rtm/CORBA_SeqUtil.h>
00044 #include <rtm/RTObject.h>
00045 
00050 namespace PeriodicExecutionContext
00051 {
00052   class LightweightRTObjectMock
00053     : public virtual POA_RTC::LightweightRTObject,
00054       public virtual PortableServer::RefCountServantBase
00055   {
00056   protected:
00057     typedef std::map<RTC::UniqueId, RTC::ExecutionContext_ptr> ExecContexts;
00058     CORBA::Long m_nextUniqueId;
00059     ExecContexts m_execContexts;
00060     std::vector<std::string> m_log;
00061     bool m_alive;
00062     bool m_error;
00063         
00064   public:
00065     LightweightRTObjectMock()
00066       : m_alive(true), m_error(false)
00067     {
00068     }
00069                 
00070     // RTC::_impl_ComponentAction
00071     virtual RTC::UniqueId attach_context(RTC::ExecutionContext_ptr exec_context)
00072     {
00073       m_log.push_back("attach_executioncontext");
00074       m_execContexts.insert(
00075                             std::pair<RTC::UniqueId, RTC::ExecutionContext_ptr>(m_nextUniqueId++, exec_context));
00076       return m_nextUniqueId;
00077     }
00078     virtual RTC::ReturnCode_t detach_context(RTC::UniqueId ec_id)
00079     {
00080       m_log.push_back("detach_executioncontext");
00081       m_execContexts.erase(ec_id);
00082       return RTC::RTC_OK;
00083     }
00084     virtual RTC::ReturnCode_t on_initialize()
00085     {
00086       m_log.push_back("on_initialize");
00087       return RTC::RTC_OK;
00088     }
00089     virtual RTC::ReturnCode_t on_finalize()
00090     {
00091       m_log.push_back("on_finalize");
00092       return RTC::RTC_OK;
00093     }
00094     virtual RTC::ReturnCode_t on_startup(RTC::UniqueId ec_id)
00095     {
00096       m_log.push_back("on_startup");
00097       return RTC::RTC_OK;
00098     }
00099     virtual RTC::ReturnCode_t on_shutdown(RTC::UniqueId ec_id)
00100     {
00101       m_log.push_back("on_shutdown");
00102       return RTC::RTC_OK;
00103     }
00104     virtual RTC::ReturnCode_t on_activated(RTC::UniqueId ec_id)
00105     {
00106       m_log.push_back("on_activated");
00107       return returnCode(RTC::RTC_OK);
00108     }
00109     virtual RTC::ReturnCode_t on_deactivated(RTC::UniqueId ec_id)
00110     {
00111       m_log.push_back("on_deactivated");
00112       return RTC::RTC_OK;
00113     }
00114     virtual RTC::ReturnCode_t on_aborting(RTC::UniqueId ec_id)
00115     {
00116       m_log.push_back("on_aborting");
00117       return RTC::RTC_OK;
00118     }
00119     virtual RTC::ReturnCode_t on_error(RTC::UniqueId ec_id)
00120     {
00121       m_log.push_back("on_error");
00122       return RTC::RTC_OK;
00123     }
00124     virtual RTC::ReturnCode_t on_reset(RTC::UniqueId ec_id)
00125     {
00126       m_log.push_back("on_reset");
00127       return RTC::RTC_OK;
00128     }
00129     
00130     // RTC::_impl_LightweightRTObject
00131     virtual RTC::ReturnCode_t initialize()
00132     {
00133       m_log.push_back("initialize");
00134       return RTC::RTC_OK;
00135     }
00136     virtual RTC::ReturnCode_t finalize()
00137     {
00138       m_log.push_back("finalize");
00139       return RTC::RTC_OK;
00140     }
00141     virtual RTC::ReturnCode_t exit()
00142     {
00143       m_log.push_back("exit");
00144       return RTC::RTC_OK;
00145     }
00146     virtual CORBA::Boolean is_alive(RTC::_objref_ExecutionContext* exec_context)
00147     { 
00148       m_log.push_back("is_alive");
00149       return CORBA::Boolean(m_alive);
00150     }
00151     virtual RTC::ExecutionContextList* get_owned_contexts()
00152     {
00153       m_log.push_back("get_contexts");
00154       return 0;
00155     }
00156     virtual RTC::ExecutionContextList* get_participating_contexts()
00157     {
00158       m_log.push_back("get_context");
00159       return 0;
00160 //      return m_execContexts[ec_id];
00161     }
00162 
00163     virtual RTC::_objref_ExecutionContext* get_context(RTC::ExecutionContextHandle_t)
00164     {
00165       return 0;
00166     }
00167     virtual RTC::ExecutionContextHandle_t get_context_handle(RTC::_objref_ExecutionContext*)
00168     {
00169       return 0;
00170     }
00171   public: // helper methods
00172     int countLog(std::string line)
00173     {
00174       int count = 0;
00175       for (int i = 0; i < (int) m_log.size(); ++i)
00176         {
00177           if (m_log[i] == line) ++count;
00178         }
00179       return count;
00180     }
00181                 
00182     void setAlive(bool alive)
00183     {
00184       m_alive = alive;
00185     }
00186                 
00187     void setError(bool error)
00188     {
00189       m_error = error;
00190     }
00191         
00192   private:
00193     RTC::ReturnCode_t returnCode(RTC::ReturnCode_t rc)
00194     {
00195       return m_error ? RTC::RTC_ERROR : rc;
00196     }
00197   };
00198         
00199   class DataFlowComponentMock
00200 //    : public virtual POA_RTC::DataFlowComponent,
00201     : public virtual POA_OpenRTM::DataFlowComponent,
00202       public virtual LightweightRTObjectMock
00203   {
00204   public:
00205     // SDOPackage::_impl_SDOSystemElement
00206     virtual SDOPackage::OrganizationList* get_owned_organizations()
00207       throw (SDOPackage::NotAvailable)
00208     {
00209       m_log.push_back("get_owned_organizations");
00210       return 0; // dummy
00211     }
00212     virtual char* get_sdo_id()
00213       throw (SDOPackage::NotAvailable, SDOPackage::InternalError)
00214     {
00215       m_log.push_back("get_sdo_id");
00216       return 0; // dummy
00217     }
00218     virtual char* get_sdo_type()
00219       throw (SDOPackage::NotAvailable, SDOPackage::InternalError)
00220     {
00221       m_log.push_back("get_sdo_type");
00222       return 0; // dummy
00223     }
00224     virtual SDOPackage::DeviceProfile* get_device_profile()
00225       throw (SDOPackage::NotAvailable, SDOPackage::InternalError)
00226     {
00227       m_log.push_back("get_device_profile");
00228       return 0; // dummy
00229     }
00230     virtual SDOPackage::ServiceProfileList* get_service_profiles()
00231       throw (SDOPackage::InvalidParameter, SDOPackage::NotAvailable, SDOPackage::InternalError)
00232     {
00233       m_log.push_back("get_service_profiles");
00234       return 0; // dummy
00235     }
00236     virtual SDOPackage::ServiceProfile* get_service_profile(const char* id)
00237       throw (SDOPackage::InvalidParameter, SDOPackage::NotAvailable, SDOPackage::InternalError)
00238     {
00239       m_log.push_back("get_service_profile");
00240       return 0; // dummy
00241     }
00242     virtual SDOPackage::SDOService_ptr get_sdo_service(const char* id)
00243       throw (SDOPackage::InvalidParameter, SDOPackage::NotAvailable, SDOPackage::InternalError)
00244     {
00245       m_log.push_back("get_sdo_service");
00246       return SDOPackage::SDOService::_nil(); // dummy
00247     }
00248     virtual SDOPackage::Configuration_ptr get_configuration()
00249       throw (SDOPackage::InterfaceNotImplemented, SDOPackage::NotAvailable, SDOPackage::InternalError)
00250     {
00251       m_log.push_back("get_configuration");
00252       return SDOPackage::Configuration::_nil(); // dummy
00253     }
00254     virtual SDOPackage::Monitoring_ptr get_monitoring()
00255       throw (SDOPackage::InterfaceNotImplemented, SDOPackage::NotAvailable, SDOPackage::InternalError)
00256     {
00257       m_log.push_back("get_monitoring");
00258       return SDOPackage::Monitoring::_nil(); // dummy
00259     }
00260     virtual SDOPackage::OrganizationList* get_organizations()
00261       throw (SDOPackage::NotAvailable, SDOPackage::InternalError)
00262     {
00263       m_log.push_back("get_organizations");
00264       return 0; // dummy
00265     }
00266     virtual SDOPackage::NVList* get_status_list()
00267       throw (SDOPackage::NotAvailable, SDOPackage::InternalError)
00268     {
00269       m_log.push_back("get_status_list");
00270       return 0; // dummy
00271     }
00272     virtual CORBA::Any* get_status(const char* name)
00273       throw (SDOPackage::InvalidParameter, SDOPackage::NotAvailable, SDOPackage::InternalError)
00274     {
00275       m_log.push_back("get_status");
00276       return 0; // dummy
00277     }
00278 
00279     // RTC::_impl_RTObject
00280     virtual RTC::ComponentProfile* get_component_profile()
00281     {
00282       m_log.push_back("get_component_profile");
00283       // dummy
00284       RTC::ComponentProfile_var prof(new RTC::ComponentProfile());
00285       return prof._retn();
00286     }
00287     virtual RTC::PortServiceList* get_ports()
00288     {
00289       m_log.push_back("get_ports");
00290       // dummy
00291       RTC::PortServiceList_var ports(new RTC::PortServiceList());
00292       ports->length(0);
00293       return ports._retn();
00294     }
00295     virtual RTC::ExecutionContextServiceList* get_execution_context_services()
00296     {
00297       m_log.push_back("get_execution_context_services");
00298       // dummy
00299       RTC::ExecutionContextServiceList_var ec = new RTC::ExecutionContextServiceList();
00300       ec->length(0);
00301       return ec._retn();
00302     }
00303 
00304     // RTC::_impl_DataFlowComponentAction
00305     virtual RTC::ReturnCode_t on_execute(RTC::UniqueId ec_id)
00306     {
00307       m_log.push_back("on_execute");
00308       return RTC::RTC_OK; // dummy
00309     }
00310     virtual RTC::ReturnCode_t on_state_update(RTC::UniqueId ec_id)
00311     {
00312       m_log.push_back("on_state_update");
00313       return RTC::RTC_OK; // dummy
00314     }
00315     virtual RTC::ReturnCode_t on_rate_changed(RTC::UniqueId ec_id)
00316     {
00317       m_log.push_back("on_rate_changed");
00318       return RTC::RTC_OK; // dummy
00319     }
00320   };
00321         
00322   class RTObjectMock
00323     : public RTC::RTObject_impl
00324   {
00325   public:
00326     RTObjectMock(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa)
00327       : RTC::RTObject_impl(orb, poa)
00328     {
00329     }
00330     virtual ~RTObjectMock(void){}
00331   };
00332 
00333   class PeriodicExecutionContextMock
00334     : public RTC::PeriodicExecutionContext
00335   {
00336   public:
00337     PeriodicExecutionContextMock() : RTC::PeriodicExecutionContext() {}
00338     virtual ~PeriodicExecutionContextMock(void){}
00339 
00340     // protected: 変数をここで更新
00341     void set_m_ref()
00342       {
00343         RTC::PeriodicExecutionContext::m_ref = m_refmock;
00344       }
00345     void clear_m_comps()
00346       {
00347         if (!RTC::PeriodicExecutionContext::m_comps.empty())
00348           {
00349             RTC::PeriodicExecutionContext::m_comps.clear();
00350           }
00351       }
00352     RTC::ExecutionContextService_var m_refmock;
00353   };
00354         
00355   class PeriodicExecutionContextTests
00356     : public CppUnit::TestFixture
00357   {
00358     CPPUNIT_TEST_SUITE(PeriodicExecutionContextTests);
00359 
00360     CPPUNIT_TEST(test_is_running);
00361     CPPUNIT_TEST(test_start_invoking_on_startup);
00362     CPPUNIT_TEST(test_start_with_running);
00363     CPPUNIT_TEST(test_start_with_not_alive);
00364     CPPUNIT_TEST(test_stop_invoking_on_shutdown);
00365     CPPUNIT_TEST(test_stop_with_not_running);
00366     CPPUNIT_TEST(test_start_and_stop_multiple_times);
00367     CPPUNIT_TEST(test_set_rate_and_get_rate);
00368     CPPUNIT_TEST(test_set_rate_with_zero_or_negative_rate);
00369     CPPUNIT_TEST(test_set_rate_invoking_on_rate_changed);
00370     CPPUNIT_TEST(test_add_invoking_attach_executioncontext);
00371     CPPUNIT_TEST(test_add_not_with_data_flow_component);
00372     CPPUNIT_TEST(test_remove_invoking_detach_executioncontext);
00373     CPPUNIT_TEST(test_remove_with_not_attached_component);
00374     CPPUNIT_TEST(test_remove_when_component_is_still_active);
00375     CPPUNIT_TEST(test_remove_when_component_is_inactive);
00376     CPPUNIT_TEST(test_activate_component_invoking_on_activated);
00377     CPPUNIT_TEST(test_activate_component_without_participating);
00378     CPPUNIT_TEST(test_activate_component_in_Error_state);
00379     CPPUNIT_TEST(test_activate_component_not_in_Alive_state);
00380     CPPUNIT_TEST(test_deactivate_component_invoking_on_deactivated);
00381     CPPUNIT_TEST(test_deactivate_component_without_participating);
00382     CPPUNIT_TEST(test_deactivate_component_not_in_Alive_state);
00383     CPPUNIT_TEST(test_reset_component_invoking_on_reset);
00384     CPPUNIT_TEST(test_reset_component_not_in_Error_state);
00385     CPPUNIT_TEST(test_reset_component_not_in_Alive_state);
00386     CPPUNIT_TEST(test_bindComponent);
00387 
00388     CPPUNIT_TEST_SUITE_END();
00389         
00390   private:
00391     CORBA::ORB_ptr m_pORB;
00392     PortableServer::POA_ptr m_pPOA;
00393         
00394   public:
00395 
00399     PeriodicExecutionContextTests()
00400     {
00401       int argc(0);
00402       char** argv(NULL);
00403       m_pORB = CORBA::ORB_init(argc, argv);
00404       m_pPOA = PortableServer::POA::_narrow(
00405                                             m_pORB->resolve_initial_references("RootPOA"));
00406       m_pPOA->the_POAManager()->activate();
00407     }
00408                     
00412     virtual ~PeriodicExecutionContextTests()
00413     {
00414     }
00415                   
00419     virtual void setUp()
00420     {
00421       coil::usleep(100000);
00422     }
00423     
00427     virtual void tearDown()
00428     { 
00429     }
00430                 
00438     void test_is_running()
00439     {
00440       RTC::PeriodicExecutionContext* ec
00441         = new RTC::PeriodicExecutionContext(); // will be deleted automatically
00442                         
00443       // start()呼出し前は、非running状態か?
00444       CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(false), ec->is_running());
00445                         
00446       // start()呼出し後は、running状態か?
00447       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->start());
00448       CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), ec->is_running());
00449                         
00450       // stop()呼出後は、非running状態か?
00451       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->stop());
00452       CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(false), ec->is_running());
00453 
00454       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
00455       delete ec;
00456     }
00457                 
00463     void test_start_invoking_on_startup()
00464     {
00465       // RTObjectを生成する
00466       POA_RTC::LightweightRTObject* rto
00467         = new DataFlowComponentMock(); // will be deleted automatically
00468       DataFlowComponentMock* mock
00469         = dynamic_cast<DataFlowComponentMock*>(rto);
00470                         
00471       // ExecutionContextを生成する
00472       RTC::PeriodicExecutionContext* ec
00473         = new RTC::PeriodicExecutionContext(); // will be deleted automatically
00474                                 
00475       // ExecutionContextにRTObjectを登録する
00476       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this()));
00477                         
00478       // この時点では、まだon_startup()は呼び出されていないはず
00479       CPPUNIT_ASSERT_EQUAL(0, mock->countLog("on_startup"));
00480                         
00481       // start()を呼び出す
00482       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->start());
00483                         
00484       // この時点で、on_startup()が1回だけ呼び出されているはず
00485       CPPUNIT_ASSERT_EQUAL(1, mock->countLog("on_startup"));
00486 
00487       ec->stop();
00488       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
00489       delete ec;
00490       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
00491       delete rto;
00492     }
00493                 
00499     void test_start_with_running()
00500     {
00501       RTC::PeriodicExecutionContext* ec
00502         = new RTC::PeriodicExecutionContext(); // will be deleted automatically
00503                         
00504       // start()呼出し前は、非running状態のはず
00505       CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(false), ec->is_running());
00506                         
00507       // start()呼出し後は、running状態のはず
00508       ec->start();
00509       CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), ec->is_running());
00510                         
00511       // さらにstart()呼出しを行い、意図どおりのエラーコードで戻ることを確認する
00512       CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, ec->start());
00513 
00514       ec->stop();
00515       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
00516       delete ec;
00517     }
00518                 
00524     void test_start_with_not_alive()
00525     {
00526       // RTObjectを生成する
00527       POA_RTC::LightweightRTObject* rto
00528         = new DataFlowComponentMock(); // will be deleted automatically
00529       DataFlowComponentMock* mock
00530         = dynamic_cast<DataFlowComponentMock*>(rto);
00531                         
00532       // ExecutionContextを生成する
00533       RTC::PeriodicExecutionContext* ec
00534         = new RTC::PeriodicExecutionContext(); // will be deleted automatically
00535                         
00536       // ExecutionContextにRTObjectを登録する
00537       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this()));
00538                         
00539       // 非Alive状態にしておく
00540       mock->setAlive(false);
00541       CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(false), rto->is_alive(NULL));
00542                         
00543       ec->stop();
00544       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
00545       delete ec;
00546       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
00547       delete rto;
00548     }
00549                 
00555     void test_stop_invoking_on_shutdown()
00556     {
00557       // RTObjectを生成する
00558       POA_RTC::LightweightRTObject* rto
00559         = new DataFlowComponentMock(); // will be deleted automatically
00560       DataFlowComponentMock* mock
00561         = dynamic_cast<DataFlowComponentMock*>(rto);
00562                         
00563       // ExecutionContextを生成する
00564       RTC::PeriodicExecutionContext* ec
00565         = new RTC::PeriodicExecutionContext(); // will be deleted automatically
00566                         
00567       // ExecutionContextにRTObjectを登録する
00568       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this()));
00569                         
00570       // start()を呼び出す
00571       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->start());
00572                         
00573       // この時点では、まだon_shutdown()は呼び出されていないはず
00574       CPPUNIT_ASSERT_EQUAL(0, mock->countLog("on_shutdown"));
00575 
00576       // stop()を呼び出す
00577       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->stop());
00578                         
00579       // この時点で、on_shutdown()が1回だけ呼び出されているはず
00580       CPPUNIT_ASSERT_EQUAL(1, mock->countLog("on_shutdown"));
00581 
00582       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
00583       delete ec;
00584       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
00585       delete rto;
00586     }
00587                 
00593     void test_stop_with_not_running()
00594     {
00595       // ExecutionContextを生成する
00596       RTC::PeriodicExecutionContext* ec
00597         = new RTC::PeriodicExecutionContext(); // will be deleted automatically
00598 
00599       // まだstart()していない状態で、つまり非runningの状態で、
00600       // stop()を呼び出し、意図どおりのエラーコードで戻ることを確認する
00601       CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(false), ec->is_running());
00602       CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, ec->stop());
00603 
00604       // start()を呼び出す
00605       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->start());
00606                         
00607       // stop()を呼び出す
00608       CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), ec->is_running());
00609       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->stop());
00610                         
00611       // さらにstop()を呼び出し、意図どおりのエラーコードで戻ることを確認する
00612       CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(false), ec->is_running());
00613       CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, ec->stop());
00614 
00615       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
00616       delete ec;
00617     }
00618                 
00624     void test_start_and_stop_multiple_times()
00625     {
00626       // ExecutionContextを生成する
00627       RTC::PeriodicExecutionContext* ec
00628         = new RTC::PeriodicExecutionContext(); // will be deleted automatically
00629                         
00630       // start(), stop()を連続して正常に呼び出せるか?
00631       for (int i = 0; i < 1000; ++i)
00632         {
00633           // start()を呼び出す
00634           CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->start());
00635 
00636           // stop()を呼び出す
00637           CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->stop());
00638         }
00639 
00640       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
00641       delete ec;
00642     }
00643                 
00649     void test_set_rate_and_get_rate()
00650     {
00651       // ExecutionContextを生成する
00652       RTC::PeriodicExecutionContext* ec
00653         = new RTC::PeriodicExecutionContext(); // will be deleted automatically
00654                         
00655       // set_rate()で設定したレートが、get_rate()で正しく取得できるか?
00656       for (int i = 1; i <= 10; ++i)
00657         {
00658           CORBA::Double rate((double) 1.0 * i);
00659           CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->set_rate(rate));
00660           CPPUNIT_ASSERT_EQUAL(rate, ec->get_rate());
00661         }
00662 
00663       ec->stop();
00664       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
00665       delete ec;
00666     }
00667                 
00674     void test_set_rate_with_zero_or_negative_rate()
00675     {
00676       // ExecutionContextを生成する
00677       RTC::PeriodicExecutionContext* ec
00678         = new RTC::PeriodicExecutionContext(); // will be deleted automatically
00679                         
00680       // 0または負数のレートを指定した場合、意図どおりのエラーコードで戻るか?
00681       for (int i = 0; i < 10; ++i)
00682         {
00683           CORBA::Double rate((double) - 1.0 * i);
00684           CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER, ec->set_rate(rate));
00685         }
00686 
00687       ec->stop();
00688       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
00689       delete ec;
00690     }
00691                 
00697     void test_set_rate_invoking_on_rate_changed()
00698     {
00699       // RTObjectを生成する
00700       POA_RTC::LightweightRTObject* rto
00701         = new DataFlowComponentMock(); // will be deleted automatically
00702       DataFlowComponentMock* mock
00703         = dynamic_cast<DataFlowComponentMock*>(rto);
00704                         
00705       // ExecutionContextを生成する
00706       RTC::PeriodicExecutionContext* ec
00707         = new RTC::PeriodicExecutionContext(); // will be deleted automatically
00708       CPPUNIT_ASSERT_EQUAL(RTC::PERIODIC, ec->get_kind());
00709                         
00710       // ExecutionContextにRTObjectを登録する
00711       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this()));
00712                         
00713       // この時点では、on_rate_changed()は1回も呼び出されていないはず
00714       CPPUNIT_ASSERT_EQUAL(0, mock->countLog("on_rate_changed"));
00715                         
00716       RTC::ExecutionContextProfile* ecp;
00717       ecp = ec->get_profile();
00718       CPPUNIT_ASSERT_EQUAL(CORBA::Double(1000000), ecp->rate);
00719 
00720       // set_rate()を呼出す
00721       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->set_rate(CORBA::Double(1.0)));
00722       ecp = ec->get_profile();
00723       CPPUNIT_ASSERT_EQUAL(CORBA::Double(1.0), ecp->rate);
00724                         
00725       // この時点で、on_rate_changed()が1回だけ呼び出されているはず
00726       CPPUNIT_ASSERT_EQUAL(1, mock->countLog("on_rate_changed"));
00727 
00728       ec->stop();
00729       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
00730       delete ec;
00731       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
00732       delete rto;
00733     }
00734                 
00740     void test_add_invoking_attach_executioncontext()
00741     {
00742       // RTObjectを生成する
00743       POA_RTC::LightweightRTObject* rto
00744         = new DataFlowComponentMock(); // will be deleted automatically
00745       DataFlowComponentMock* mock
00746         = dynamic_cast<DataFlowComponentMock*>(rto);
00747                         
00748       // ExecutionContextを生成する
00749       RTC::PeriodicExecutionContext* ec
00750         = new RTC::PeriodicExecutionContext(); // will be deleted automatically
00751                         
00752       // この時点では、attach_executioncontext()は1回も呼び出されていないはず
00753       CPPUNIT_ASSERT_EQUAL(0, mock->countLog("attach_executioncontext"));
00754 
00755       // ExecutionContextにRTObjectを登録する
00756       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this()));
00757                         
00758       // この時点で、attach_executioncontext()が1回だけ呼び出されているはず
00759       CPPUNIT_ASSERT_EQUAL(1, mock->countLog("attach_executioncontext"));
00760 
00761       ec->stop();
00762       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
00763       delete ec;
00764       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
00765       delete rto;
00766     }
00767                 
00773     void test_add_not_with_data_flow_component()
00774     {
00775       // RTObjectを生成する
00776 //      POA_RTC::LightweightRTObject* rto
00777       POA_RTC::LightweightRTObject* rto
00778         = new LightweightRTObjectMock(); // will be deleted automatically
00779 
00780       // ExecutionContextを生成する
00781       RTC::PeriodicExecutionContext* ec
00782         = new RTC::PeriodicExecutionContext(); // will be deleted automatically
00783       CPPUNIT_ASSERT_EQUAL(RTC::PERIODIC, ec->get_kind());
00784                         
00785       // LightweightRTObjectではあるが、DataFlowComponentではないRTObjectを用いて、
00786       // add()呼出しを試みて、意図どおりエラーコードで戻ることを確認する
00787       // CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, ec->add(rto->_this()));
00788 
00789       ec->stop();
00790       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
00791       delete ec;
00792       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
00793       delete rto;
00794     }
00795                 
00801     void test_remove_invoking_detach_executioncontext()
00802     {
00803       // RTObjectを生成する
00804       POA_RTC::LightweightRTObject* rto
00805         = new DataFlowComponentMock(); // will be deleted automatically
00806       DataFlowComponentMock* mock
00807         = dynamic_cast<DataFlowComponentMock*>(rto);
00808                         
00809       // ExecutionContextを生成する
00810       RTC::PeriodicExecutionContext* ec
00811         = new RTC::PeriodicExecutionContext(); // will be deleted automatically
00812                         
00813       // ExecutionContextにRTObjectを登録する
00814       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this()));
00815 
00816       // この時点では、attach_executioncontext()は1回も呼び出されていないはず
00817       CPPUNIT_ASSERT_EQUAL(0, mock->countLog("detach_executioncontext"));
00818                         
00819       // ExecutionContextへの登録を解除する
00820       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->remove_component(rto->_this()));
00821                         
00822       // この時点で、detach_executioncontext()が1回だけ呼び出されているはず
00823       CPPUNIT_ASSERT_EQUAL(1, mock->countLog("detach_executioncontext"));
00824 
00825       ec->stop();
00826       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
00827       delete ec;
00828       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
00829       delete rto;
00830     }
00831                 
00837     void test_remove_with_not_attached_component()
00838     {
00839       // RTObjectを生成する
00840       POA_RTC::LightweightRTObject* rto
00841         = new DataFlowComponentMock(); // will be deleted automatically
00842 
00843       // ExecutionContextを生成する
00844       RTC::PeriodicExecutionContext* ec
00845         = new RTC::PeriodicExecutionContext(); // will be deleted automatically
00846                         
00847       // まだ登録していないコンポーネントについてExecutionContextからの登録解除を試みて、
00848       // 意図どおりのエラーコードで戻ることを確認する
00849       CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER, ec->remove_component(rto->_this()));
00850 
00851       ec->stop();
00852       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
00853       delete ec;
00854       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
00855       delete rto;
00856     }
00857                 
00863     void test_remove_when_component_is_still_active()
00864     {
00865       // RTObjectを生成する
00866       POA_RTC::LightweightRTObject* rto
00867         = new DataFlowComponentMock(); // will be deleted automatically
00868 
00869       // ExecutionContextを生成する
00870       RTC::PeriodicExecutionContext* ec
00871         = new RTC::PeriodicExecutionContext(); // will be deleted automatically
00872       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->start());
00873 
00874       // ExecutionContextにRTObjectを登録する
00875       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this()));
00876                         
00877       // コンポーネントをActiveにする
00878       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->activate_component(rto->_this()));
00879       usleep(100000);
00880       CPPUNIT_ASSERT_EQUAL(RTC::ACTIVE_STATE, ec->get_component_state(rto->_this()));
00881 
00882       // コンポーネントがActiveのままでremove()を試みて、意図どおりのエラーコードが戻ることを確認する
00883       // CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, ec->remove(rto->_this()));
00884 
00885       ec->stop();
00886       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
00887       delete ec;
00888       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
00889       delete rto;
00890     }
00891                 
00897     void test_remove_when_component_is_inactive()
00898     {
00899       // RTObjectを生成する
00900       POA_RTC::LightweightRTObject* rto
00901         = new DataFlowComponentMock(); // will be deleted automatically
00902 
00903       // ExecutionContextを生成する
00904       RTC::PeriodicExecutionContext* ec
00905         = new RTC::PeriodicExecutionContext(); // will be deleted automatically
00906       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->start());
00907 
00908       // ExecutionContextにRTObjectを登録する
00909       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this()));
00910                         
00911       // コンポーネントをActiveにする
00912       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->activate_component(rto->_this()));
00913       coil::usleep(100000);
00914       CPPUNIT_ASSERT_EQUAL(RTC::ACTIVE_STATE, ec->get_component_state(rto->_this()));
00915                         
00916       // コンポーネントをInactiveにする
00917       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->deactivate_component(rto->_this()));
00918       coil::usleep(100000);
00919       CPPUNIT_ASSERT_EQUAL(RTC::INACTIVE_STATE, ec->get_component_state(rto->_this()));
00920                         
00921       // remove()が成功することを確認する
00922       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->remove_component(rto->_this()));
00923 
00924       ec->stop();
00925       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
00926       delete ec;
00927       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
00928       delete rto;
00929     }
00930                 
00936     void test_activate_component_invoking_on_activated()
00937     {
00938       // RTObjectを生成する
00939       POA_RTC::LightweightRTObject* rto
00940         = new DataFlowComponentMock(); // will be deleted automatically
00941       DataFlowComponentMock* mock
00942         = dynamic_cast<DataFlowComponentMock*>(rto);
00943 
00944       // ExecutionContextを生成する
00945       RTC::PeriodicExecutionContext* ec
00946         = new RTC::PeriodicExecutionContext(); // will be deleted automatically
00947       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->start());
00948 
00949       // ExecutionContextにRTObjectを登録する
00950       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this()));
00951                         
00952       // この時点では、まだon_activated()は1回も呼び出されていないはず
00953       CPPUNIT_ASSERT_EQUAL(0, mock->countLog("on_activated"));
00954                         
00955       // コンポーネントをActiveにする
00956       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->activate_component(rto->_this()));
00957                         
00958       coil::usleep(100000);
00959       // activate_component()からon_activated()の呼出しは同期呼出であり、
00960       // この時点で、on_activated()が1回だけ呼び出されているはず
00961       CPPUNIT_ASSERT_EQUAL(1, mock->countLog("on_activated"));
00962 
00963       // activate_component()からon_activated()の呼出しは同期呼出であり、
00964       // スレッドコンテキストを切替えることなく、Active状態に遷移していることを確認する
00965       CPPUNIT_ASSERT_EQUAL(RTC::ACTIVE_STATE, ec->get_component_state(rto->_this()));
00966 
00967       ec->stop();
00968       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
00969       delete ec;
00970       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
00971       delete rto;
00972     }
00973                 
00979     void test_activate_component_without_participating()
00980     {
00981       // RTObjectを生成する
00982       POA_RTC::LightweightRTObject* rto
00983         = new DataFlowComponentMock(); // will be deleted automatically
00984 
00985       // ExecutionContextを生成する
00986       RTC::PeriodicExecutionContext* ec
00987         = new RTC::PeriodicExecutionContext(); // will be deleted automatically
00988       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->start());
00989 
00990       // ExecutionContextにコンポーネント登録することなくactivate_component()を呼出し、
00991       // 意図どおりのエラコードで戻ることを確認する
00992       CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER, ec->activate_component(rto->_this()));
00993 
00994       ec->stop();
00995       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
00996       delete ec;
00997       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
00998       delete rto;
00999     }
01000                 
01006     void test_activate_component_in_Error_state()
01007     {
01008       // RTObjectを生成する
01009       POA_RTC::LightweightRTObject* rto
01010         = new DataFlowComponentMock(); // will be deleted automatically
01011       DataFlowComponentMock* mock
01012         = dynamic_cast<DataFlowComponentMock*>(rto);
01013 
01014       // ExecutionContextを生成する
01015       RTC::PeriodicExecutionContext* ec
01016         = new RTC::PeriodicExecutionContext(); // will be deleted automatically
01017       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->start());
01018                         
01019       // コンポーネントをError状態にまで遷移させる
01020       mock->setError(true);
01021       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this()));
01022       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->activate_component(rto->_this()));
01023       coil::sleep(1); // Error状態へ遷移するまで待つ。本来、このスリープが仕様上必要か否か?
01024       CPPUNIT_ASSERT_EQUAL(RTC::ERROR_STATE, ec->get_component_state(rto->_this()));
01025                         
01026       // Error状態でactivate_component()呼出しを行い、意図どおりのエラーコードで戻ることを確認する
01027       CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, ec->activate_component(rto->_this()));
01028 
01029       ec->stop();
01030       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
01031       delete ec;
01032       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
01033       delete rto;
01034     }
01035                 
01041     void test_activate_component_not_in_Alive_state()
01042     {
01043       // RTObjectを生成する
01044       POA_RTC::LightweightRTObject* rto
01045         = new DataFlowComponentMock(); // will be deleted automatically
01046       DataFlowComponentMock* mock
01047         = dynamic_cast<DataFlowComponentMock*>(rto);
01048                         
01049       // ExecutionContextを生成する
01050       RTC::PeriodicExecutionContext* ec
01051         = new RTC::PeriodicExecutionContext(); // will be deleted automatically
01052                         
01053       // ExecutionContextにRTObjectを登録する
01054       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this()));
01055                         
01056       // 非Alive状態にしておく
01057       mock->setAlive(false);
01058       CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(false), rto->is_alive(NULL));
01059                         
01060       // activate_component()呼出しを行い、意図どおりのエラーコードで戻ることを確認する
01061       // CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER, ec->activate_component(rto->_this()));
01062 
01063       ec->stop();
01064       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
01065       delete ec;
01066       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
01067       delete rto;
01068     }
01069                 
01075     void test_deactivate_component_invoking_on_deactivated()
01076     {
01077       // RTObjectを生成する
01078       POA_RTC::LightweightRTObject* rto
01079         = new DataFlowComponentMock(); // will be deleted automatically
01080       DataFlowComponentMock* mock
01081         = dynamic_cast<DataFlowComponentMock*>(rto);
01082 
01083       // ExecutionContextを生成する
01084       RTC::PeriodicExecutionContext* ec
01085         = new RTC::PeriodicExecutionContext(); // will be deleted automatically
01086       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->start());
01087 
01088       // ExecutionContextにRTObjectを登録する
01089       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this()));
01090                         
01091       // コンポーネントをactivateする
01092       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->activate_component(rto->_this()));
01093       coil::usleep(100000);
01094       CPPUNIT_ASSERT_EQUAL(RTC::ACTIVE_STATE, ec->get_component_state(rto->_this()));
01095 
01096       // この時点では、まだon_activated()は1回も呼び出されていないはず
01097       CPPUNIT_ASSERT_EQUAL(0, mock->countLog("on_deactivated"));
01098 
01099       // コンポーネントをdeactivateする
01100       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->deactivate_component(rto->_this()));
01101       coil::usleep(100000);
01102       CPPUNIT_ASSERT_EQUAL(RTC::INACTIVE_STATE, ec->get_component_state(rto->_this()));
01103 
01104       // この時点で、on_deactivated()は1回だけ呼び出されているはず
01105       CPPUNIT_ASSERT_EQUAL(1, mock->countLog("on_deactivated"));
01106 
01107       ec->stop();
01108       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
01109       delete ec;
01110       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
01111       delete rto;
01112     }
01113                 
01119     void test_deactivate_component_without_participating()
01120     {
01121       // RTObjectを生成する
01122       POA_RTC::LightweightRTObject* rto
01123         = new DataFlowComponentMock(); // will be deleted automatically
01124 
01125       // ExecutionContextを生成する
01126       RTC::PeriodicExecutionContext* ec
01127         = new RTC::PeriodicExecutionContext(); // will be deleted automatically
01128       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->start());
01129 
01130       // ExecutionContextに登録していないコンポーネントに対してdeactivateを試みて、
01131       // 意図どおりのエラーコードで戻ることを確認する
01132       CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER, ec->deactivate_component(rto->_this()));
01133 
01134       ec->stop();
01135       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
01136       delete ec;
01137       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
01138       delete rto;
01139     }
01140                 
01146     void test_deactivate_component_not_in_Alive_state()
01147     {
01148       // RTObjectを生成する
01149       POA_RTC::LightweightRTObject* rto
01150         = new DataFlowComponentMock(); // will be deleted automatically
01151       DataFlowComponentMock* mock
01152         = dynamic_cast<DataFlowComponentMock*>(rto);
01153                         
01154       // ExecutionContextを生成する
01155       RTC::PeriodicExecutionContext* ec
01156         = new RTC::PeriodicExecutionContext(); // will be deleted automatically
01157 
01158       ec->start();
01159                         
01160       // ExecutionContextにRTObjectを登録する
01161       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this()));
01162                         
01163       // コンポーネントをactivateする
01164       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->activate_component(rto->_this()));
01165       usleep(100000);
01166       CPPUNIT_ASSERT_EQUAL(RTC::ACTIVE_STATE, ec->get_component_state(rto->_this()));
01167 
01168       // 非Alive状態にしておく
01169       mock->setAlive(false);
01170       CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(false), rto->is_alive(NULL));
01171 
01172       // 非Alive状態のコンポーネントに対してdeactivateを試みて、意図どおりのエラーコードで戻ることを確認する
01173       // CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER, ec->deactivate_component(rto->_this()));
01174 
01175       ec->stop();
01176       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
01177       delete ec;
01178       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
01179       delete rto;
01180     }
01181                 
01187     void test_reset_component_invoking_on_reset()
01188     {
01189       // RTObjectを生成する
01190       POA_RTC::LightweightRTObject* rto
01191         = new DataFlowComponentMock(); // will be deleted automatically
01192       DataFlowComponentMock* mock
01193         = dynamic_cast<DataFlowComponentMock*>(rto);
01194 
01195       // ExecutionContextを生成する
01196       RTC::PeriodicExecutionContext* ec
01197         = new RTC::PeriodicExecutionContext(); // will be deleted automatically
01198       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->start());
01199                         
01200       // コンポーネントをError状態にまで遷移させる
01201       mock->setError(true);
01202       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this()));
01203       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->activate_component(rto->_this()));
01204       coil::sleep(1); // Error状態へ遷移するまで待つ。本来、このスリープが仕様上必要か否か?
01205       CPPUNIT_ASSERT_EQUAL(RTC::ERROR_STATE, ec->get_component_state(rto->_this()));
01206                         
01207       // この時点では、on_reset()は1回も呼び出されていないはず
01208       CPPUNIT_ASSERT_EQUAL(0, mock->countLog("on_reset"));
01209 
01210       // reset_component()を呼出し、成功することを確認する
01211       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->reset_component(rto->_this()));
01212       coil::usleep(100000);
01213       // この時点で、on_reset()が1回だけ呼び出されているはず
01214       CPPUNIT_ASSERT_EQUAL(1, mock->countLog("on_reset"));
01215 
01216       ec->stop();
01217       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
01218       delete ec;
01219       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
01220       delete rto;
01221     }
01222                 
01228     void test_reset_component_not_in_Error_state()
01229     {
01230       // RTObjectを生成する
01231       POA_RTC::LightweightRTObject* rto
01232         = new DataFlowComponentMock(); // will be deleted automatically
01233                         
01234       // ExecutionContextを生成する
01235       RTC::PeriodicExecutionContext* ec
01236         = new RTC::PeriodicExecutionContext(); // will be deleted automatically
01237       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->start());
01238                         
01239       // ExecutionContextにRTObjectを登録する
01240       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this()));
01241                         
01242       // この状態(Inactive)でreset_component()呼出しを行い、意図どおりのエラーコードで戻ることを確認する
01243       CPPUNIT_ASSERT_EQUAL(RTC::INACTIVE_STATE, ec->get_component_state(rto->_this()));
01244       CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, ec->reset_component(rto->_this()));
01245 
01246       ec->stop();
01247       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
01248       delete ec;
01249       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
01250       delete rto;
01251     }
01252                 
01258     void test_reset_component_not_in_Alive_state()
01259     {
01260       // RTObjectを生成する
01261       POA_RTC::LightweightRTObject* rto
01262         = new DataFlowComponentMock(); // will be deleted automatically
01263       DataFlowComponentMock* mock
01264         = dynamic_cast<DataFlowComponentMock*>(rto);
01265 
01266       // 非Alive状態(Create状態)にしておく
01267       mock->setAlive(false);
01268       CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(false), rto->is_alive(NULL));
01269                         
01270       // ExecutionContextを生成する
01271       RTC::PeriodicExecutionContext* ec
01272         = new RTC::PeriodicExecutionContext(); // will be deleted automatically
01273 
01274       // ExecutionContextにRTObjectを登録する
01275       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this()));
01276                         
01277       // この状態(Created)でreset_component()呼出しを行い、意図どおりのエラーコードで戻ることを確認する
01278       CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, ec->reset_component(rto->_this()));
01279 
01280       ec->stop();
01281       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
01282       delete ec;
01283       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
01284       delete rto;
01285     }
01286                 
01292     void test_bindComponent()
01293     {
01294       // RTObjectを生成する
01295       RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA);
01296       coil::Properties prop;
01297       prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext");
01298       prop.setProperty("exec_cxt.periodic.rate","1000");
01299       rto->setProperties(prop);
01300 
01301       // ExecutionContextを生成する
01302       PeriodicExecutionContextMock* ec = new PeriodicExecutionContextMock();
01303 
01304       // RTC::BAD_PARAMETER を返すか?
01305       CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER, ec->bindComponent(NULL));
01306 
01307       // RTC::RTC_OK を返すか?
01308       CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->bindComponent(rto));
01309 
01310       // 1000件登録後、(id > ECOTHER_OFFSET)判定のRTC::RTC_ERROR を返すか?
01311       for (int i = 0; i < 1000; ++i)
01312         {
01313           ec->bindComponent(rto);
01314         }
01315       CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR, ec->bindComponent(rto));
01316 
01317       // m_ref=_nil()値の場合、(id < 0)判定のRTC::RTC_ERROR を返すか?
01318       ec->m_refmock = RTC::ExecutionContextService::_nil();
01319       ec->set_m_ref();
01320       CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR, ec->bindComponent(rto));
01321 
01322       // 登録したコンポーネントの削除
01323       ec->clear_m_comps();
01324 
01325       ec->stop();
01326       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
01327       delete ec;
01328       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
01329       delete rto;
01330     }
01331 
01332   };
01333 }; // namespace PeriodicExecutionContext
01334 
01335 /*
01336  * Register test suite
01337  */
01338 CPPUNIT_TEST_SUITE_REGISTRATION(PeriodicExecutionContext::PeriodicExecutionContextTests);
01339 
01340 #ifdef LOCAL_MAIN
01341 int main(int argc, char* argv[])
01342 {
01343 
01344   FORMAT format = TEXT_OUT;
01345   int target = 0;
01346   std::string xsl;
01347   std::string ns;
01348   std::string fname;
01349   std::ofstream ofs;
01350 
01351   int i(1);
01352   while (i < argc)
01353     {
01354       std::string arg(argv[i]);
01355       std::string next_arg;
01356       if (i + 1 < argc) next_arg = argv[i + 1];
01357       else              next_arg = "";
01358 
01359       if (arg == "--text") { format = TEXT_OUT; break; }
01360       if (arg == "--xml")
01361         {
01362           if (next_arg == "")
01363             {
01364               fname = argv[0];
01365               fname += ".xml";
01366             }
01367           else
01368             {
01369               fname = next_arg;
01370             }
01371           format = XML_OUT;
01372           ofs.open(fname.c_str());
01373         }
01374       if ( arg == "--compiler"  ) { format = COMPILER_OUT; break; }
01375       if ( arg == "--cerr"      ) { target = 1; break; }
01376       if ( arg == "--xsl"       )
01377         {
01378           if (next_arg == "") xsl = "default.xsl"; 
01379           else                xsl = next_arg;
01380         }
01381       if ( arg == "--namespace" )
01382         {
01383           if (next_arg == "")
01384             {
01385               std::cerr << "no namespace specified" << std::endl;
01386               exit(1); 
01387             }
01388           else
01389             {
01390               xsl = next_arg;
01391             }
01392         }
01393       ++i;
01394     }
01395   CppUnit::TextUi::TestRunner runner;
01396   if ( ns.empty() )
01397     runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
01398   else
01399     runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
01400   CppUnit::Outputter* outputter = 0;
01401   std::ostream* stream = target ? &std::cerr : &std::cout;
01402   switch ( format )
01403     {
01404     case TEXT_OUT :
01405       outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
01406       break;
01407     case XML_OUT :
01408       std::cout << "XML_OUT" << std::endl;
01409       outputter = new CppUnit::XmlOutputter(&runner.result(),
01410                                             ofs, "shift_jis");
01411       static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
01412       break;
01413     case COMPILER_OUT :
01414       outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
01415       break;
01416     }
01417   runner.setOutputter(outputter);
01418   runner.run();
01419   return 0; // runner.run() ? 0 : 1;
01420 }
01421 #endif // MAIN
01422 #endif // PeriodicExecutionContext_cpp


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Aug 27 2015 14:16:38