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
852 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
854 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
866 POA_RTC::LightweightRTObject* rto
886 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
888 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
900 POA_RTC::LightweightRTObject* rto
925 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
927 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
939 POA_RTC::LightweightRTObject* rto
953 CPPUNIT_ASSERT_EQUAL(0, mock->
countLog(
"on_activated"));
961 CPPUNIT_ASSERT_EQUAL(1, mock->
countLog(
"on_activated"));
968 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
970 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
982 POA_RTC::LightweightRTObject* rto
995 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
997 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
1009 POA_RTC::LightweightRTObject* rto
1030 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
1032 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
1044 POA_RTC::LightweightRTObject* rto
1058 CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(
false), rto->is_alive(NULL));
1064 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
1066 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
1078 POA_RTC::LightweightRTObject* rto
1097 CPPUNIT_ASSERT_EQUAL(0, mock->
countLog(
"on_deactivated"));
1105 CPPUNIT_ASSERT_EQUAL(1, mock->
countLog(
"on_deactivated"));
1108 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
1110 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
1122 POA_RTC::LightweightRTObject* rto
1135 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
1137 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
1149 POA_RTC::LightweightRTObject* rto
1170 CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(
false), rto->is_alive(NULL));
1176 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
1178 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
1190 POA_RTC::LightweightRTObject* rto
1208 CPPUNIT_ASSERT_EQUAL(0, mock->
countLog(
"on_reset"));
1214 CPPUNIT_ASSERT_EQUAL(1, mock->
countLog(
"on_reset"));
1217 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
1219 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
1231 POA_RTC::LightweightRTObject* rto
1247 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
1249 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
1261 POA_RTC::LightweightRTObject* rto
1268 CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(
false), rto->is_alive(NULL));
1275 CPPUNIT_ASSERT_EQUAL(
RTC::RTC_OK, ec->add_component(rto->_this()));
1281 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
1283 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
1297 prop.
setProperty(
"exec_cxt.periodic.type",
"PeriodicExecutionContext");
1298 prop.
setProperty(
"exec_cxt.periodic.rate",
"1000");
1311 for (
int i = 0; i < 1000; ++i)
1318 ec->
m_refmock = RTC::ExecutionContextService::_nil();
1326 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
1328 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
1341 int main(
int argc,
char* argv[])
1354 std::string arg(argv[i]);
1355 std::string next_arg;
1356 if (i + 1 < argc) next_arg = argv[i + 1];
1359 if (arg ==
"--text") { format =
TEXT_OUT;
break; }
1372 ofs.open(fname.c_str());
1374 if ( arg ==
"--compiler" ) { format =
COMPILER_OUT;
break; }
1375 if ( arg ==
"--cerr" ) { target = 1;
break; }
1376 if ( arg ==
"--xsl" )
1378 if (next_arg ==
"") xsl =
"default.xsl";
1379 else xsl = next_arg;
1381 if ( arg ==
"--namespace" )
1385 std::cerr <<
"no namespace specified" << std::endl;
1395 CppUnit::TextUi::TestRunner runner;
1397 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
1399 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
1400 CppUnit::Outputter* outputter = 0;
1401 std::ostream* stream = target ? &std::cerr : &std::cout;
1405 outputter =
new CppUnit::TextOutputter(&runner.result(),*stream);
1408 std::cout <<
"XML_OUT" << std::endl;
1409 outputter =
new CppUnit::XmlOutputter(&runner.result(),
1411 static_cast<CppUnit::XmlOutputter*
>(outputter)->setStyleSheet(xsl);
1414 outputter =
new CppUnit::CompilerOutputter(&runner.result(),*stream);
1417 runner.setOutputter(outputter);
1422 #endif // PeriodicExecutionContext_cpp
virtual RTC::ReturnCode_t on_activated(RTC::UniqueId ec_id)
#define RTC_ERROR(fmt)
Error log output macro.
virtual SDOPackage::SDOService_ptr get_sdo_service(const char *id)
int main(int argc, char **argv)
int countLog(std::string line)
virtual RTC::PortServiceList * get_ports()
EXECUTION_HANDLE_TYPE_NATIVE ExecutionContextHandle_t
RTC::ExecutionContextService_var m_refmock
void test_start_with_not_alive()
start()メソッドのテスト
void test_start_invoking_on_startup()
start()メソッドのテスト
void test_start_and_stop_multiple_times()
start()メソッドとstop()メソッドのテスト
void test_deactivate_component_invoking_on_deactivated()
deactivate_component()メソッドのテスト
void test_reset_component_invoking_on_reset()
reset_component()メソッドのテスト
virtual ReturnCode_t remove_component(LightweightRTObject_ptr comp)
Remove the RT-Component from participant list.
CORBA::Long m_nextUniqueId
virtual RTC::ReturnCode_t on_state_update(RTC::UniqueId ec_id)
void test_add_invoking_attach_executioncontext()
add()メソッドのテスト
unsigned int sleep(unsigned int seconds)
Stop a processing at specified second time.
virtual ~PeriodicExecutionContextTests()
Destructor.
void test_is_running()
is_running()メソッドのテスト
std::vector< Comp > m_comps
List of the participating component.
virtual SDOPackage::ServiceProfileList * get_service_profiles()
virtual SDOPackage::DeviceProfile * get_device_profile()
virtual RTC::ExecutionContextList * get_participating_contexts()
virtual CORBA::Boolean is_alive(RTC::_objref_ExecutionContext *exec_context)
std::vector< std::pair< std::string, std::string > > NVList
virtual RTC::ReturnCode_t bindComponent(RTObject_impl *rtc)
Bind the component.
void test_remove_invoking_detach_executioncontext()
remove()メソッドのテスト
virtual RTC::ReturnCode_t on_finalize()
void test_activate_component_in_Error_state()
activate_component()メソッドのテスト
void test_remove_when_component_is_inactive()
remove()メソッドのテスト
RTC::ReturnCode_t returnCode(RTC::ReturnCode_t rc)
virtual RTC::ReturnCode_t on_initialize()
virtual ~PeriodicExecutionContextMock(void)
virtual ReturnCode_t add_component(LightweightRTObject_ptr comp)
Add an RT-component.
virtual RTC::ReturnCode_t on_reset(RTC::UniqueId ec_id)
virtual CORBA::Boolean is_running(void)
Check for ExecutionContext running state.
virtual RTC::ReturnCode_t detach_context(RTC::UniqueId ec_id)
void test_start_with_running()
start()メソッドのテスト
virtual RTC::ExecutionContextList * get_owned_contexts()
void test_reset_component_not_in_Alive_state()
reset_component()メソッドのテスト
PeriodicExecutionContextTests()
Constructor.
virtual RTC::ReturnCode_t exit()
void test_activate_component_not_in_Alive_state()
activate_component()メソッドのテスト
void test_activate_component_without_participating()
void test_reset_component_not_in_Error_state()
reset_component()メソッドのテスト
virtual ~RTObjectMock(void)
virtual RTC::ReturnCode_t initialize()
virtual RTC::ComponentProfile * get_component_profile()
std::vector< ExecutionContext * > ExecutionContextList
virtual CORBA::Any * get_status(const char *name)
RTObjectMock(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa)
virtual RTC::ReturnCode_t finalize()
virtual SDOPackage::NVList * get_status_list()
ExecutionContextHandle_t UniqueId
std::vector< std::string > m_log
virtual RTC::ReturnCode_t on_error(RTC::UniqueId ec_id)
virtual RTC::ReturnCode_t on_execute(RTC::UniqueId ec_id)
virtual RTC::ReturnCode_t on_shutdown(RTC::UniqueId ec_id)
virtual SDOPackage::ServiceProfile * get_service_profile(const char *id)
virtual ReturnCode_t start(void)
Start the ExecutionContext.
void test_set_rate_with_zero_or_negative_rate()
set_rate()メソッドのテスト
void test_remove_with_not_attached_component()
remove()メソッドのテスト
void test_deactivate_component_without_participating()
deactivate_component()メソッドのテスト
std::string setProperty(const std::string &key, const std::string &value)
Set a value associated with key in the property list.
virtual char * get_sdo_type()
void setError(bool error)
std::map< RTC::UniqueId, RTC::ExecutionContext_ptr > ExecContexts
virtual ReturnCode_t activate_component(LightweightRTObject_ptr comp)
Activate an RT-component.
CORBA sequence utility template functions.
void test_add_not_with_data_flow_component()
add()メソッドのテスト
virtual RTC::ReturnCode_t on_deactivated(RTC::UniqueId ec_id)
PeriodicExecutionContextMock()
virtual void tearDown()
Test finalization.
virtual SDOPackage::OrganizationList * get_organizations()
virtual ReturnCode_t reset_component(LightweightRTObject_ptr comp)
Reset the RT-component.
prop
Organization::get_organization_property ();.
virtual ReturnCode_t stop(void)
Stop the ExecutionContext.
virtual ReturnCode_t deactivate_component(LightweightRTObject_ptr comp)
Deactivate an RT-component.
void test_stop_invoking_on_shutdown()
stop()メソッドのテスト
Class represents a set of properties.
virtual ReturnCode_t set_rate(CORBA::Double rate)
Set execution rate(Hz) of ExecutionContext.
virtual RTC::UniqueId attach_context(RTC::ExecutionContext_ptr exec_context)
virtual ExecutionKind get_kind(void)
Get the ExecutionKind.
std::vector< IPortService * > PortServiceList
void test_activate_component_invoking_on_activated()
activate()メソッドのテスト
PeriodicExecutionContext class.
PortableServer::POA_ptr m_pPOA
virtual void setUp()
Test initialization.
virtual RTC::ReturnCode_t on_aborting(RTC::UniqueId ec_id)
virtual RTC::_objref_ExecutionContext * get_context(RTC::ExecutionContextHandle_t)
virtual RTC::ReturnCode_t on_rate_changed(RTC::UniqueId ec_id)
ExecutionContextService_var m_ref
Reference to ExecutionContextService object.
PeriodicExecutionContext class.
virtual LifeCycleState get_component_state(LightweightRTObject_ptr comp)
Get RT-component's state.
void test_remove_when_component_is_still_active()
remove()メソッドのテスト
ExecContexts m_execContexts
void setAlive(bool alive)
virtual SDOPackage::Monitoring_ptr get_monitoring()
virtual CORBA::Double get_rate(void)
Get execution rate(Hz) of ExecutionContext.
void test_set_rate_and_get_rate()
set_rate()メソッドとget_rate()メソッドのテスト
virtual RTC::ExecutionContextServiceList * get_execution_context_services()
void test_set_rate_invoking_on_rate_changed()
void test_bindComponent()
bindComponent()メソッドのテスト
CPPUNIT_TEST_SUITE_REGISTRATION(PeriodicExecutionContext::PeriodicExecutionContextTests)
virtual SDOPackage::Configuration_ptr get_configuration()
void setProperties(const coil::Properties &prop)
[local interface] Set RTC property
LightweightRTObjectMock()
virtual ExecutionContextProfile * get_profile(void)
Get the ExecutionContextProfile.
virtual RTC::ReturnCode_t on_startup(RTC::UniqueId ec_id)
RTC::Local::ExecutionContextProfile ExecutionContextProfile
virtual char * get_sdo_id()
int usleep(useconds_t usec)
Stop a processing at specified micro second time.
virtual RTC::ExecutionContextHandle_t get_context_handle(RTC::_objref_ExecutionContext *)
void test_deactivate_component_not_in_Alive_state()
deactivate_component()メソッドのテスト
virtual SDOPackage::OrganizationList * get_owned_organizations()
void test_stop_with_not_running()
stop()メソッドのテスト