32 #ifndef PeriodicExecutionContext_cpp 33 #define PeriodicExecutionContext_cpp 35 #include <cppunit/ui/text/TestRunner.h> 36 #include <cppunit/TextOutputter.h> 37 #include <cppunit/extensions/TestFactoryRegistry.h> 38 #include <cppunit/extensions/HelperMacros.h> 39 #include <cppunit/TestAssert.h> 41 #include <rtm/idl/RTCSkel.h> 53 :
public virtual POA_RTC::LightweightRTObject,
54 public virtual PortableServer::RefCountServantBase
57 typedef std::map<RTC::UniqueId, RTC::ExecutionContext_ptr>
ExecContexts;
66 : m_alive(true), m_error(false)
73 m_log.push_back(
"attach_executioncontext");
74 m_execContexts.insert(
75 std::pair<RTC::UniqueId, RTC::ExecutionContext_ptr>(m_nextUniqueId++, exec_context));
80 m_log.push_back(
"detach_executioncontext");
81 m_execContexts.erase(ec_id);
86 m_log.push_back(
"on_initialize");
91 m_log.push_back(
"on_finalize");
96 m_log.push_back(
"on_startup");
101 m_log.push_back(
"on_shutdown");
106 m_log.push_back(
"on_activated");
111 m_log.push_back(
"on_deactivated");
116 m_log.push_back(
"on_aborting");
121 m_log.push_back(
"on_error");
126 m_log.push_back(
"on_reset");
133 m_log.push_back(
"initialize");
138 m_log.push_back(
"finalize");
143 m_log.push_back(
"exit");
146 virtual CORBA::Boolean
is_alive(RTC::_objref_ExecutionContext* exec_context)
148 m_log.push_back(
"is_alive");
149 return CORBA::Boolean(m_alive);
153 m_log.push_back(
"get_contexts");
158 m_log.push_back(
"get_context");
175 for (
int i = 0; i < (int) m_log.size(); ++i)
177 if (m_log[i] == line) ++count;
201 :
public virtual POA_OpenRTM::DataFlowComponent,
209 m_log.push_back(
"get_owned_organizations");
215 m_log.push_back(
"get_sdo_id");
221 m_log.push_back(
"get_sdo_type");
227 m_log.push_back(
"get_device_profile");
233 m_log.push_back(
"get_service_profiles");
237 throw (SDOPackage::InvalidParameter, SDOPackage::NotAvailable, SDOPackage::InternalError)
239 m_log.push_back(
"get_service_profile");
243 throw (SDOPackage::InvalidParameter, SDOPackage::NotAvailable, SDOPackage::InternalError)
245 m_log.push_back(
"get_sdo_service");
246 return SDOPackage::SDOService::_nil();
251 m_log.push_back(
"get_configuration");
252 return SDOPackage::Configuration::_nil();
257 m_log.push_back(
"get_monitoring");
258 return SDOPackage::Monitoring::_nil();
263 m_log.push_back(
"get_organizations");
269 m_log.push_back(
"get_status_list");
273 throw (SDOPackage::InvalidParameter, SDOPackage::NotAvailable, SDOPackage::InternalError)
275 m_log.push_back(
"get_status");
282 m_log.push_back(
"get_component_profile");
284 RTC::ComponentProfile_var prof(
new RTC::ComponentProfile());
289 m_log.push_back(
"get_ports");
293 return ports._retn();
297 m_log.push_back(
"get_execution_context_services");
299 RTC::ExecutionContextServiceList_var
ec =
new RTC::ExecutionContextServiceList();
307 m_log.push_back(
"on_execute");
312 m_log.push_back(
"on_state_update");
317 m_log.push_back(
"on_rate_changed");
327 :
RTC::RTObject_impl(orb, poa)
356 :
public CppUnit::TestFixture
360 CPPUNIT_TEST(test_is_running);
361 CPPUNIT_TEST(test_start_invoking_on_startup);
362 CPPUNIT_TEST(test_start_with_running);
363 CPPUNIT_TEST(test_start_with_not_alive);
364 CPPUNIT_TEST(test_stop_invoking_on_shutdown);
365 CPPUNIT_TEST(test_stop_with_not_running);
366 CPPUNIT_TEST(test_start_and_stop_multiple_times);
367 CPPUNIT_TEST(test_set_rate_and_get_rate);
368 CPPUNIT_TEST(test_set_rate_with_zero_or_negative_rate);
369 CPPUNIT_TEST(test_set_rate_invoking_on_rate_changed);
370 CPPUNIT_TEST(test_add_invoking_attach_executioncontext);
371 CPPUNIT_TEST(test_add_not_with_data_flow_component);
372 CPPUNIT_TEST(test_remove_invoking_detach_executioncontext);
373 CPPUNIT_TEST(test_remove_with_not_attached_component);
374 CPPUNIT_TEST(test_remove_when_component_is_still_active);
375 CPPUNIT_TEST(test_remove_when_component_is_inactive);
376 CPPUNIT_TEST(test_activate_component_invoking_on_activated);
377 CPPUNIT_TEST(test_activate_component_without_participating);
378 CPPUNIT_TEST(test_activate_component_in_Error_state);
379 CPPUNIT_TEST(test_activate_component_not_in_Alive_state);
380 CPPUNIT_TEST(test_deactivate_component_invoking_on_deactivated);
381 CPPUNIT_TEST(test_deactivate_component_without_participating);
382 CPPUNIT_TEST(test_deactivate_component_not_in_Alive_state);
383 CPPUNIT_TEST(test_reset_component_invoking_on_reset);
384 CPPUNIT_TEST(test_reset_component_not_in_Error_state);
385 CPPUNIT_TEST(test_reset_component_not_in_Alive_state);
386 CPPUNIT_TEST(test_bindComponent);
388 CPPUNIT_TEST_SUITE_END();
403 m_pORB = CORBA::ORB_init(argc, argv);
404 m_pPOA = PortableServer::POA::_narrow(
405 m_pORB->resolve_initial_references(
"RootPOA"));
406 m_pPOA->the_POAManager()->activate();
444 CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(
false), ec->
is_running());
448 CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(
true), ec->
is_running());
452 CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(
false), ec->
is_running());
454 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
466 POA_RTC::LightweightRTObject* rto
479 CPPUNIT_ASSERT_EQUAL(0, mock->
countLog(
"on_startup"));
485 CPPUNIT_ASSERT_EQUAL(1, mock->
countLog(
"on_startup"));
488 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
490 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
505 CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(
false), ec->
is_running());
509 CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(
true), ec->
is_running());
515 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
527 POA_RTC::LightweightRTObject* rto
541 CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(
false), rto->is_alive(NULL));
544 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
546 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
558 POA_RTC::LightweightRTObject* rto
574 CPPUNIT_ASSERT_EQUAL(0, mock->
countLog(
"on_shutdown"));
580 CPPUNIT_ASSERT_EQUAL(1, mock->
countLog(
"on_shutdown"));
582 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
584 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
601 CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(
false), ec->
is_running());
608 CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(
true), ec->
is_running());
612 CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(
false), ec->
is_running());
615 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
631 for (
int i = 0; i < 1000; ++i)
640 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
656 for (
int i = 1; i <= 10; ++i)
658 CORBA::Double rate((
double) 1.0 * i);
660 CPPUNIT_ASSERT_EQUAL(rate, ec->
get_rate());
664 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
681 for (
int i = 0; i < 10; ++i)
683 CORBA::Double rate((
double) - 1.0 * i);
688 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
700 POA_RTC::LightweightRTObject* rto
714 CPPUNIT_ASSERT_EQUAL(0, mock->
countLog(
"on_rate_changed"));
718 CPPUNIT_ASSERT_EQUAL(CORBA::Double(1000000), ecp->rate);
723 CPPUNIT_ASSERT_EQUAL(CORBA::Double(1.0), ecp->rate);
726 CPPUNIT_ASSERT_EQUAL(1, mock->
countLog(
"on_rate_changed"));
729 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
731 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
743 POA_RTC::LightweightRTObject* rto
753 CPPUNIT_ASSERT_EQUAL(0, mock->
countLog(
"attach_executioncontext"));
759 CPPUNIT_ASSERT_EQUAL(1, mock->
countLog(
"attach_executioncontext"));
762 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
764 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
777 POA_RTC::LightweightRTObject* rto
790 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
792 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
804 POA_RTC::LightweightRTObject* rto
817 CPPUNIT_ASSERT_EQUAL(0, mock->
countLog(
"detach_executioncontext"));
823 CPPUNIT_ASSERT_EQUAL(1, mock->
countLog(
"detach_executioncontext"));
826 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
828 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
840 POA_RTC::LightweightRTObject* rto