RTCUtilTests.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
11 /*
12  * $Log: RTCUtilTests.cpp,v $
13  * Revision 1.1 2008/05/02 11:29:13 arafune
14  * The first commitment.
15  *
16  *
17  */
18 
19 #ifndef RTCUtil_cpp
20 #define RTCUtil_cpp
21 
22 #include <cppunit/ui/text/TestRunner.h>
23 #include <cppunit/TextOutputter.h>
24 #include <cppunit/extensions/TestFactoryRegistry.h>
25 #include <cppunit/extensions/HelperMacros.h>
26 #include <cppunit/TestAssert.h>
27 
28 #include <idl/SDOPackageSkel.h>
29 #include <idl/RTCSkel.h>
30 #include <idl/OpenRTMSkel.h>
31 #include <rtm/RTCUtil.h>
32 
37 namespace Tests
38 {
39  class DataFlowComponentMock
40  : public virtual POA_OpenRTM::DataFlowComponent,
41  public virtual PortableServer::RefCountServantBase
42  {
43  public:
46  // _impl_SDOSystemElement
47  virtual SDOPackage::OrganizationList* get_owned_organizations() { return NULL; }
48 
49  // SDOPackage::_impl_SDO
50  virtual char* get_sdo_id() { return NULL; }
51  virtual char* get_sdo_type() { return NULL; }
52  virtual SDOPackage::DeviceProfile* get_device_profile() { return NULL; }
53  virtual SDOPackage::ServiceProfileList* get_service_profiles() { return NULL; }
54  virtual SDOPackage::ServiceProfile* get_service_profile(const char*) { return NULL; }
55  virtual SDOPackage::_objref_SDOService* get_sdo_service(const char*) { return NULL; }
56  virtual SDOPackage::_objref_Configuration* get_configuration() { return NULL; }
57  virtual SDOPackage::_objref_Monitoring* get_monitoring() { return NULL; }
58  virtual SDOPackage::OrganizationList* get_organizations() { return NULL; }
59  virtual SDOPackage::NVList* get_status_list() { return NULL; }
60  virtual CORBA::Any* get_status(const char*) { return NULL; }
61 
62  // RTC::_impl_DataFlowComponentAction
66  virtual RTC::ExecutionContextHandle_t attach_context(RTC::_objref_ExecutionContext*) { return RTC::ExecutionContextHandle_t(0); }
78  {
79  return 0;
80  }
82  {
83  return 0;
84  }
85  virtual RTC::ExecutionContextHandle_t get_context_handle(RTC::_objref_ExecutionContext*)
86  {
87  return 0;
88  }
90  {
91  return RTC::RTC_OK;
92  }
93  // RTC::_impl_LightweightRTObjec:t
95  virtual RTC::ReturnCode_t finalize() { return RTC::RTC_OK; }
96  virtual RTC::ReturnCode_t exit() { return RTC::RTC_OK; }
97  virtual CORBA::Boolean is_alive(RTC::_objref_ExecutionContext*) { return true; }
98  virtual RTC::_objref_ExecutionContext* get_context(RTC::ExecutionContextHandle_t) { return NULL; }
99 
100  // RTC::_impl_RTObject
101  virtual RTC::ComponentProfile* get_component_profile() { return NULL; }
102  virtual RTC::PortServiceList* get_ports() { return NULL; }
103  };
104 
106  : public virtual POA_RTC::FsmObject
107  {
108  // RTC::_impl_FsmObject
111  {
112  return RTC::RTC_OK;
113  }
114  };
115 
117  : public virtual POA_RTC::MultiModeObject
118  {
119  // RTC::_impl_ModeCapable
120  virtual RTC::_objref_Mode* get_default_mode() { return NULL; }
121  virtual RTC::_objref_Mode* get_current_mode() { return NULL; }
122  virtual RTC::_objref_Mode* get_current_mode_in_context(RTC::_objref_ExecutionContext*) { return NULL; }
123  virtual RTC::_objref_Mode* get_pending_mode() { return NULL; }
124  virtual RTC::_objref_Mode* get_pending_mode_in_context(RTC::_objref_ExecutionContext*) { return NULL; }
125  virtual RTC::ReturnCode_t set_mode(RTC::_objref_Mode*, CORBA::Boolean) { return RTC::RTC_OK; }
126 
127  // RTC::_impl_MultiModeComponentAction
129  {
130  return RTC::RTC_OK;
131  }
132 
134  {
135  return RTC::RTC_OK;
136  }
138  {
139  return RTC::RTC_OK;
140  }
142  {
143  return RTC::RTC_OK;
144  }
146  {
147  return RTC::RTC_OK;
148  }
150  {
151  return RTC::RTC_OK;
152  }
154  {
155  return RTC::RTC_OK;
156  }
158  {
159  return RTC::RTC_OK;
160  }
162  {
163  return RTC::RTC_OK;
164  }
166  {
167  return RTC::RTC_OK;
168  }
170  {
171  return RTC::RTC_OK;
172  }
174  {
175  return RTC::RTC_OK;
176  }
178  {
179  return RTC::RTC_OK;
180  }
181  virtual CORBA::Boolean is_alive(RTC::_objref_ExecutionContext*)
182  {
183  return 0;
184  }
186  {
187  return RTC::RTC_OK;
188  }
189  virtual RTC::ExecutionContextHandle_t attach_context(RTC::_objref_ExecutionContext*)
190  {
192  }
194  {
195  return RTC::RTC_OK;
196  }
197  virtual RTC::_objref_ExecutionContext* get_context(RTC::ExecutionContextHandle_t)
198  {
199  return 0;
200  }
202  {
203  return NULL;
204  }
206  {
207  return NULL;
208  }
209  virtual RTC::ExecutionContextHandle_t get_context_handle(RTC::_objref_ExecutionContext*)
210  {
211  return 0;
212  }
213 
214  };
215 
217  : public CppUnit::TestFixture
218  {
219  CPPUNIT_TEST_SUITE(RTCUtilTests);
220 
221  CPPUNIT_TEST(test_isDataFlowComponent_DataFlowComponent);
222  CPPUNIT_TEST(test_isDataFlowComponent_FsmObject);
223  CPPUNIT_TEST(test_isDataFlowComponent_MultiModeObject);
224 
225  CPPUNIT_TEST(test_isFsmParticipant_DataFlowComponent);
226  CPPUNIT_TEST(test_isFsmParticipant_FsmObject);
227  CPPUNIT_TEST(test_isFsmParticipant_MultiModeObject);
228 
229  CPPUNIT_TEST(test_isFsmObject_DataFlowComponent);
230  CPPUNIT_TEST(test_isFsmObject_FsmObject);
231  CPPUNIT_TEST(test_isFsmObject_MultiModeObject);
232 
233  CPPUNIT_TEST(test_isMultiModeObject_DataFlowComponent);
234  CPPUNIT_TEST(test_isMultiModeObject_FsmObject);
235  CPPUNIT_TEST(test_isMultiModeObject_MultiModeObject);
236 
237  CPPUNIT_TEST_SUITE_END();
238 
239  private:
240  CORBA::ORB_ptr m_pORB;
241  PortableServer::POA_ptr m_pPOA;
242 
243  public:
248  {
249  int argc = 0;
250  char** argv = NULL;
251  m_pORB = CORBA::ORB_init(argc, argv);
252  m_pPOA = PortableServer::POA::_narrow(
253  m_pORB->resolve_initial_references("RootPOA"));
254  m_pPOA->the_POAManager()->activate();
255  }
256 
260  virtual ~RTCUtilTests()
261  {
262  }
263 
267  virtual void setUp()
268  {
269  }
270 
274  virtual void tearDown()
275  {
276  }
277 
279  {
281  CORBA::Object_ptr ref = obj->_this();
282  CPPUNIT_ASSERT(! CORBA::is_nil(ref));
283 
284  CPPUNIT_ASSERT(RTC_Utils::isDataFlowComponent(ref));
285  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(obj));
286  delete obj;
287  }
288 
290  {
291  FsmObjectMock* obj = new FsmObjectMock();
292  CORBA::Object_ptr ref = obj->_this();
293  CPPUNIT_ASSERT(! CORBA::is_nil(ref));
294 
295  CPPUNIT_ASSERT(! RTC_Utils::isDataFlowComponent(ref));
296  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(obj));
297  delete obj;
298  }
299 
301  {
303 
304  CORBA::Object_ptr ref = obj->_this();
305  CPPUNIT_ASSERT(! CORBA::is_nil(ref));
306 
307  CPPUNIT_ASSERT(! RTC_Utils::isDataFlowComponent(ref));
308  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(obj));
309  delete obj;
310  }
311 
313  {
315  CORBA::Object_ptr ref = obj->_this();
316  CPPUNIT_ASSERT(! CORBA::is_nil(ref));
317 
318  CPPUNIT_ASSERT(! RTC_Utils::isFsmParticipant(ref));
319  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(obj));
320  delete obj;
321  }
322 
324  {
325  FsmObjectMock* obj = new FsmObjectMock();
326  CORBA::Object_ptr ref = obj->_this();
327  CPPUNIT_ASSERT(! CORBA::is_nil(ref));
328 
329  CPPUNIT_ASSERT(! RTC_Utils::isFsmParticipant(ref));
330  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(obj));
331  delete obj;
332  }
333 
335  {
337 
338  CORBA::Object_ptr ref = obj->_this();
339  CPPUNIT_ASSERT(! CORBA::is_nil(ref));
340 
341  CPPUNIT_ASSERT(! RTC_Utils::isFsmParticipant(ref));
342  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(obj));
343  delete obj;
344  }
345 
347  {
349  CORBA::Object_ptr ref = obj->_this();
350  CPPUNIT_ASSERT(! CORBA::is_nil(ref));
351 
352  CPPUNIT_ASSERT(! RTC_Utils::isFsmObject(ref));
353  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(obj));
354  delete obj;
355  }
356 
358  {
359  FsmObjectMock* obj = new FsmObjectMock();
360  CORBA::Object_ptr ref = obj->_this();
361  CPPUNIT_ASSERT(! CORBA::is_nil(ref));
362 
363  CPPUNIT_ASSERT(RTC_Utils::isFsmObject(ref));
364  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(obj));
365  delete obj;
366  }
367 
369  {
371 
372  CORBA::Object_ptr ref = obj->_this();
373  CPPUNIT_ASSERT(! CORBA::is_nil(ref));
374 
375  CPPUNIT_ASSERT(! RTC_Utils::isFsmObject(ref));
376  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(obj));
377  delete obj;
378  }
379 
381  {
383  CORBA::Object_ptr ref = obj->_this();
384  CPPUNIT_ASSERT(! CORBA::is_nil(ref));
385 
386  CPPUNIT_ASSERT(! RTC_Utils::isMultiModeObject(ref));
387  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(obj));
388  delete obj;
389  }
390 
392  {
393  FsmObjectMock* obj = new FsmObjectMock();
394  CORBA::Object_ptr ref = obj->_this();
395  CPPUNIT_ASSERT(! CORBA::is_nil(ref));
396 
397  CPPUNIT_ASSERT(! RTC_Utils::isMultiModeObject(ref));
398  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(obj));
399  delete obj;
400  }
401 
403  {
405 
406  CORBA::Object_ptr ref = obj->_this();
407  CPPUNIT_ASSERT(! CORBA::is_nil(ref));
408 
409  CPPUNIT_ASSERT(RTC_Utils::isMultiModeObject(ref));
410  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(obj));
411  delete obj;
412  }
413 
414  };
415 }; // namespace RTCUtil
416 
417 /*
418  * Register test suite
419  */
421 
422 #ifdef LOCAL_MAIN
423 int main(int argc, char* argv[])
424 {
425 
426  FORMAT format = TEXT_OUT;
427  int target = 0;
428  std::string xsl;
429  std::string ns;
430  std::string fname;
431  std::ofstream ofs;
432 
433  int i(1);
434  while (i < argc)
435  {
436  std::string arg(argv[i]);
437  std::string next_arg;
438  if (i + 1 < argc) next_arg = argv[i + 1];
439  else next_arg = "";
440 
441  if (arg == "--text") { format = TEXT_OUT; break; }
442  if (arg == "--xml")
443  {
444  if (next_arg == "")
445  {
446  fname = argv[0];
447  fname += ".xml";
448  }
449  else
450  {
451  fname = next_arg;
452  }
453  format = XML_OUT;
454  ofs.open(fname.c_str());
455  }
456  if ( arg == "--compiler" ) { format = COMPILER_OUT; break; }
457  if ( arg == "--cerr" ) { target = 1; break; }
458  if ( arg == "--xsl" )
459  {
460  if (next_arg == "") xsl = "default.xsl";
461  else xsl = next_arg;
462  }
463  if ( arg == "--namespace" )
464  {
465  if (next_arg == "")
466  {
467  std::cerr << "no namespace specified" << std::endl;
468  exit(1);
469  }
470  else
471  {
472  xsl = next_arg;
473  }
474  }
475  ++i;
476  }
477  CppUnit::TextUi::TestRunner runner;
478  if ( ns.empty() )
479  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
480  else
481  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
482  CppUnit::Outputter* outputter = 0;
483  std::ostream* stream = target ? &std::cerr : &std::cout;
484  switch ( format )
485  {
486  case TEXT_OUT :
487  outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
488  break;
489  case XML_OUT :
490  std::cout << "XML_OUT" << std::endl;
491  outputter = new CppUnit::XmlOutputter(&runner.result(),
492  ofs, "shift_jis");
493  static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
494  break;
495  case COMPILER_OUT :
496  outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
497  break;
498  }
499  runner.setOutputter(outputter);
500  runner.run();
501  return 0; // runner.run() ? 0 : 1;
502 }
503 
504 #endif // MAIN
505 #endif // RTCUtil_cpp
virtual RTC::ExecutionContextHandle_t get_context_handle(RTC::_objref_ExecutionContext *)
bool isDataFlowComponent(CORBA::Object_ptr obj)
Confirm whether specified RT-Component is DataFlowComponent.
Definition: RTCUtil.cpp:31
int main(int argc, char **argv)
virtual RTC::ReturnCode_t finalize()
[CORBA interface] Finalize the RTC for destruction
bool isMultiModeObject(CORBA::Object_ptr obj)
Confirm whether specified RT-Component is multiModeComponent.
Definition: RTCUtil.cpp:73
EXECUTION_HANDLE_TYPE_NATIVE ExecutionContextHandle_t
Definition: IRTC.h:63
virtual RTC::ExecutionContextHandle_t get_context_handle(RTC::_objref_ExecutionContext *)
virtual RTC::ReturnCode_t on_deactivated(RTC::ExecutionContextHandle_t)
virtual SDOPackage::_objref_SDOService * get_sdo_service(const char *)
[SDO interface] Get specified SDO Service&#39;s reference
RTComponent utils.
void test_isMultiModeObject_MultiModeObject()
virtual char * get_sdo_id()
[SDO interface] Get the SDO ID
virtual RTC::ExecutionContextHandle_t attach_context(RTC::_objref_ExecutionContext *)
virtual RTC::ReturnCode_t send_stimulus(const char *, RTC::ExecutionContextHandle_t)
virtual SDOPackage::ServiceProfile * get_service_profile(const char *)
[SDO interface] Get specified ServiceProfile
virtual RTC::_objref_Mode * get_current_mode_in_context(RTC::_objref_ExecutionContext *)
PortableServer::POA_ptr m_pPOA
ReturnCode_t
Definition: doil.h:53
std::vector< std::pair< std::string, std::string > > NVList
Definition: IRTC.h:67
void test_isFsmObject_DataFlowComponent()
void test_isFsmObject_MultiModeObject()
bool isFsmParticipant(CORBA::Object_ptr obj)
Confirm whether specified RT-Component is FsmParticipant.
Definition: RTCUtil.cpp:45
virtual RTC::ReturnCode_t on_shutdown(RTC::ExecutionContextHandle_t)
virtual SDOPackage::OrganizationList * get_organizations()
[SDO interface] Get Organization list
virtual RTC::ReturnCode_t on_initialize()
virtual RTC::ReturnCode_t on_startup(RTC::ExecutionContextHandle_t)
void test_isFsmParticipant_MultiModeObject()
virtual RTC::ReturnCode_t on_finalize()
virtual RTC::ReturnCode_t on_startup(RTC::ExecutionContextHandle_t)
virtual RTC::ReturnCode_t send_stimulus(const char *, RTC::ExecutionContextHandle_t)
virtual RTC::ReturnCode_t finalize()
virtual SDOPackage::NVList * get_status_list()
[SDO interface] Get SDO Status list
virtual RTC::_objref_ExecutionContext * get_context(RTC::ExecutionContextHandle_t)
virtual RTC::ReturnCode_t on_finalize()
[ComponentAction CORBA interface] Finalize RTC
void test_isDataFlowComponent_MultiModeObject()
void test_isDataFlowComponent_DataFlowComponent()
virtual CORBA::Boolean is_alive(RTC::_objref_ExecutionContext *)
void test_isMultiModeObject_FsmObject()
CPPUNIT_TEST_SUITE_REGISTRATION(Tests::RTCUtilTests)
virtual CORBA::Any * get_status(const char *)
[SDO interface] Get SDO Status
virtual RTC::ExecutionContextList * get_participating_contexts()
[CORBA interface] Get participating ExecutionContextList.
virtual RTC::ReturnCode_t on_error(RTC::ExecutionContextHandle_t)
virtual RTC::ReturnCode_t detach_context(RTC::ExecutionContextHandle_t)
virtual RTC::ReturnCode_t on_mode_changed(RTC::ExecutionContextHandle_t)
virtual SDOPackage::DeviceProfile * get_device_profile()
[SDO interface] Get SDO DeviceProfile list
virtual RTC::ReturnCode_t exit()
std::vector< ExecutionContext * > ExecutionContextList
Definition: IRTC.h:69
virtual RTC::ReturnCode_t on_activated(RTC::ExecutionContextHandle_t)
virtual RTC::ReturnCode_t on_error(RTC::ExecutionContextHandle_t)
virtual RTC::ExecutionContextHandle_t attach_context(RTC::_objref_ExecutionContext *)
virtual RTC::ExecutionContextList * get_owned_contexts()
[CORBA interface] Get ExecutionContextList.
virtual RTC::PortServiceList * get_ports()
[RTObject CORBA interface] Get Ports
virtual SDOPackage::OrganizationList * get_owned_organizations()
[SDO interface] Get Organization list
virtual RTC::_objref_Mode * get_current_mode()
virtual SDOPackage::_objref_Configuration * get_configuration()
[SDO interface] Get Configuration object
virtual RTC::_objref_Mode * get_pending_mode()
virtual RTC::_objref_ExecutionContext * get_context(RTC::ExecutionContextHandle_t)
virtual ~RTCUtilTests()
Destructor.
virtual RTC::_objref_Mode * get_pending_mode_in_context(RTC::_objref_ExecutionContext *)
virtual RTC::ReturnCode_t on_deactivated(RTC::ExecutionContextHandle_t)
virtual RTC::ReturnCode_t on_aborting(RTC::ExecutionContextHandle_t)
virtual RTC::ReturnCode_t initialize()
[CORBA interface] Initialize the RTC that realizes this interface.
virtual RTC::ReturnCode_t on_aborting(RTC::ExecutionContextHandle_t)
virtual RTC::ReturnCode_t stimulate(const char *, RTC::ExecutionContextHandle_t)
void test_isFsmParticipant_DataFlowComponent()
virtual RTC::ReturnCode_t exit()
[CORBA interface]top the RTC&#39;s execution context(s) and finalize it along with its contents...
virtual RTC::ReturnCode_t send_stimulus(const char *, RTC::ExecutionContextHandle_t)
virtual RTC::ReturnCode_t on_activated(RTC::ExecutionContextHandle_t)
virtual RTC::ReturnCode_t detach_context(RTC::ExecutionContextHandle_t)
virtual RTC::ReturnCode_t on_reset(RTC::ExecutionContextHandle_t)
virtual RTC::ReturnCode_t on_initialize()
[RTObject CORBA interface] Get ExecutionContextAdmin
virtual RTC::ReturnCode_t on_state_update(RTC::ExecutionContextHandle_t)
virtual RTC::ReturnCode_t set_mode(RTC::_objref_Mode *, CORBA::Boolean)
virtual RTC::ExecutionContextList * get_participating_contexts()
std::vector< IPortService * > PortServiceList
Definition: IPortService.h:39
void test_isFsmObject_FsmObject()
void test_isMultiModeObject_DataFlowComponent()
virtual RTC::ExecutionContextList * get_owned_contexts()
bool isFsmObject(CORBA::Object_ptr obj)
Confirm whether specified RT-Component is Fsm.
Definition: RTCUtil.cpp:59
RTCUtilTests()
Constructor.
virtual RTC::ReturnCode_t on_execute(RTC::ExecutionContextHandle_t)
virtual RTC::ComponentProfile * get_component_profile()
[RTObject CORBA interface] Get RTC&#39;s profile
virtual void setUp()
Test initialization.
virtual RTC::ReturnCode_t on_rate_changed(RTC::ExecutionContextHandle_t)
void test_isFsmParticipant_FsmObject()
virtual RTC::_objref_Mode * get_default_mode()
virtual char * get_sdo_type()
[SDO interface] Get SDO type
virtual SDOPackage::ServiceProfileList * get_service_profiles()
[SDO interface] Get SDO ServiceProfile
virtual CORBA::Boolean is_alive(RTC::_objref_ExecutionContext *)
void test_isDataFlowComponent_FsmObject()
virtual RTC::ReturnCode_t on_shutdown(RTC::ExecutionContextHandle_t)
virtual SDOPackage::_objref_Monitoring * get_monitoring()
[SDO interface] Get Monitoring object
virtual void tearDown()
Test finalization.
virtual RTC::ReturnCode_t initialize()
CORBA::ORB_ptr m_pORB
virtual RTC::ReturnCode_t on_reset(RTC::ExecutionContextHandle_t)


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