ExecutionContextProxyTests.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
12 /*
13  * $Log$
14  *
15  */
16 
17 #ifndef ExecutionContextProxy_cpp
18 #define ExecutionContextProxy_cpp
19 
20 #include <cppunit/ui/text/TestRunner.h>
21 #include <cppunit/TextOutputter.h>
22 #include <cppunit/extensions/TestFactoryRegistry.h>
23 #include <cppunit/extensions/HelperMacros.h>
24 #include <cppunit/TestAssert.h>
25 #include <string>
26 #include <iostream>
27 #include <sstream>
28 #include <idl/RTCSkel.h>
29 #include <ExecutionContextProxy.h>
30 #include <ILightweightRTObject.h>
36 {
42  class Logger
43  {
44  public:
45  void log(const std::string& msg)
46  {
47  m_log.push_back(msg);
48  }
49 
50  int countLog(const std::string& msg)
51  {
52  int count = 0;
53  for (int i = 0; i < (int) m_log.size(); ++i)
54  {
55  if (m_log[i] == msg) ++count;
56  }
57  return count;
58  }
59 
60  private:
61  std::vector<std::string> m_log;
62  };
63 
70  : public virtual ::POA_RTC::LightweightRTObject,
71  public virtual ::doil::CORBA::CORBAServantBase
72  {
73  public:
75  : ::doil::CORBA::CORBAServantBase(impl)
76  {
77  }
79  {
80  }
82  {
83  }
85  {
86  }
87  virtual ::CORBA::Boolean is_alive(::RTC::ExecutionContext_ptr exec_context)
88  {
89  }
91  {
92  }
93  virtual ::RTC::ExecutionContextHandle_t attach_context(::RTC::ExecutionContext_ptr exec_context)
94  {
95  }
97  {
98  }
99  virtual ::RTC::ExecutionContext_ptr get_context(::RTC::ExecutionContextHandle_t exec_handle)
100  {
101  }
103  {
104  }
106  {
107  }
109  {
110  }
112  {
113  }
115  {
116  }
118  {
119  }
121  {
122  }
124  {
125  }
127  {
128  }
130  {
131  }
133  {
134  }
136  {
137  }
138 
139 
140 
141 
142  private:
143  ::SDOPackage::Local::ISDOSystemElement* m_impl;
144  };
151  : public virtual ::RTC::Local::ILightweightRTObject
152  {
153  public:
155  : m_refcount(0)
156  {}
158  const char* id() {return "ILightweightRTObjectMock";}
159  const char* name() {return "ILightweightRTObjectMock";}
160  void incRef()
161  {
162  ++m_refcount;
163  }
164  void decRef()
165  {
166  --m_refcount;
167  if (m_refcount == 0)
168  delete this;
169  }
171  throw ()
172  {
173  }
175  throw ()
176  {
177  }
178  virtual bool is_alive(const ::RTC::Local::IExecutionContext* exec_context)
179  throw ()
180  {
181  }
182 
184  throw ()
185  {
186  }
187 
188  virtual ::RTC::Local::ExecutionContextHandle_t attach_context(const ::RTC::Local::IExecutionContext* exec_context)
189  throw ()
190  {
191  }
192 
194  throw ()
195  {
196  }
197 
198  virtual ::RTC::Local::IExecutionContext* get_context(::RTC::Local::ExecutionContextHandle_t exec_handle)
199  throw ()
200  {
201  }
202 
204  throw ()
205  {
206  }
207 
209  throw ()
210  {
211  }
212 
213  virtual ::RTC::Local::ExecutionContextHandle_t get_context_handle(const ::RTC::Local::IExecutionContext* cxt)
214  throw ()
215  {
216  }
218  throw ()
219  {
220  }
221 
223  throw ()
224  {
225  }
226 
228  throw ()
229  {
230  }
231 
233  throw ()
234  {
235  }
236 
238  throw ()
239  {
240  }
241 
243  throw ()
244  {
245  }
246 
248  throw ()
249  {
250  }
251 
253  throw ()
254  {
255  }
256 
258  throw ()
259  {
260  }
261  private:
262  std::string m_name;
264  };
271  : public virtual ::POA_RTC::ExecutionContext
272  {
273  protected:
274  std::vector<std::string> m_log;
275  public :
278 
283  {
284  m_logger = logger;
285  }
289  ::CORBA::Boolean is_running()
290  {
291  return false;
292  }
293 
294 
299  {
300  return RTC::RTC_OK;
301  }
302 
303 
308  {
309  return RTC::RTC_OK;
310  }
311 
312 
316  ::CORBA::Double get_rate()
317  {
318  if (m_logger != NULL)
319  {
320  m_logger->log("get_rate");
321  }
322  return (CORBA::Double)3.14159;
323  }
324 
325 
329  ::RTC::ReturnCode_t set_rate(::CORBA::Double rate)
330  {
331  if (m_logger != NULL)
332  {
333  m_logger->log("set_rate");
334  ::std::ostringstream os;
335  os<<rate;
336  m_logger->log(os.str());
337  }
338 
339  return RTC::BAD_PARAMETER;
340  }
341 
342 
346  ::RTC::ReturnCode_t activate_component(::RTC::LightweightRTObject_ptr comp)
347  {
348  return RTC::RTC_OK;
349  }
350 
351 
355  ::RTC::ReturnCode_t deactivate_component(::RTC::LightweightRTObject_ptr comp)
356  {
357  return RTC::RTC_OK;
358  }
359 
360 
364  ::RTC::ReturnCode_t reset_component(::RTC::LightweightRTObject_ptr comp)
365  {
366  return RTC::RTC_OK;
367  }
368 
369 
373  ::RTC::LifeCycleState get_component_state(::RTC::LightweightRTObject_ptr comp)
374  {
375  return RTC::INACTIVE_STATE;
376  }
377 
378 
383  {
384 // return m_profile.kind;
385  }
389  ::RTC::ReturnCode_t add_component(::RTC::LightweightRTObject_ptr comp)
390  {
391  if (m_logger != NULL)
392  {
393  m_logger->log("add_component");
394 // ::std::ostringstream os;
395 // os<<rate;
396 // m_logger->log(os.str());
397  }
398  return RTC::BAD_PARAMETER;
399  }
400 
401 
405  ::RTC::ReturnCode_t remove_component(::RTC::LightweightRTObject_ptr comp)
406  {
407  CORBA::ULong index;
408 // index = CORBA_SeqUtil::find(m_profile.participants,
409 // find_objref<RTObject_ptr>(RTC::RTObject::_narrow(comp)));
410 
411  if (index < 0) return RTC::BAD_PARAMETER;
412 // CORBA_SeqUtil::erase(m_profile.participants, index);
413  return RTC::RTC_OK;
414  }
415 
416  private:
418 
419  };
420 
427  : public CppUnit::TestFixture
428  {
429  CPPUNIT_TEST_SUITE(ExecutionContextProxyTests);
430 // CPPUNIT_TEST(test_case0);
431  CPPUNIT_TEST(test_get_rate);
432  CPPUNIT_TEST(test_set_rate);
433  CPPUNIT_TEST(test_add_component);
434  CPPUNIT_TEST_SUITE_END();
435 
436  private:
437  CORBA::ORB_ptr m_pORB;
438  PortableServer::POA_ptr m_pPOA;
439 
440  public:
441 
446  {
447  int argc = 0;
448  char** argv = NULL;
449  m_pORB = CORBA::ORB_init(argc, argv);
450  m_pPOA = PortableServer::POA::_narrow(
451  m_pORB->resolve_initial_references("RootPOA"));
452  m_pPOA->the_POAManager()->activate();
453  }
454 
459  {
460  }
461 
465  virtual void setUp()
466  {
467  }
468 
472  virtual void tearDown()
473  {
474  }
475 
482  {
483 
485  ::CORBA::Object_ptr ref = obj->_this();
486  if(::CORBA::is_nil(ref))
487  {
488  std::cout<<"ref is nil.Abort test."<<std::endl;
489  return;
490  }
491  ::RTC::CORBA::ExecutionContextProxy* ap
492  = new ::RTC::CORBA::ExecutionContextProxy(ref);
493 
494  Logger logger;
495  obj->setLogger(&logger);
496 
497  double ret;
498  CPPUNIT_ASSERT_EQUAL(0, logger.countLog("get_rate"));
499  ret = ap->get_rate();
500  CPPUNIT_ASSERT_EQUAL(1, logger.countLog("get_rate"));
501  CPPUNIT_ASSERT_EQUAL(3.14159, ret);
502 
503  delete ap;
504  CORBA::release(ref);
505 
506  }
507 
514  {
515 
517  ::CORBA::Object_ptr ref = obj->_this();
518  if(::CORBA::is_nil(ref))
519  {
520  std::cout<<"ref is nil.Abort test."<<std::endl;
521  return;
522  }
523  ::RTC::CORBA::ExecutionContextProxy* ap
524  = new ::RTC::CORBA::ExecutionContextProxy(ref);
525 
526  Logger logger;
527  obj->setLogger(&logger);
528 
529  double dbuf = 2.71828;
531  CPPUNIT_ASSERT_EQUAL(0, logger.countLog("2.71828"));
532  CPPUNIT_ASSERT_EQUAL(0, logger.countLog("set_rate"));
533  ret = ap->set_rate(dbuf);
534  CPPUNIT_ASSERT_EQUAL(1, logger.countLog("set_rate"));
535  CPPUNIT_ASSERT_EQUAL(::RTC::Local::BAD_PARAMETER, ret);
536  CPPUNIT_ASSERT_EQUAL(1, logger.countLog("2.71828"));
537 
538  delete ap;
539  CORBA::release(ref);
540 
541  }
548  {
551  std::cout <<"Manager Name==>"<< mgr.name() << std::endl;
552 
553 
555  ::CORBA::Object_ptr ref = obj->_this();
556  if(::CORBA::is_nil(ref))
557  {
558  std::cout<<"ref is nil.Abort test."<<std::endl;
559  return;
560  }
561  ::RTC::CORBA::ExecutionContextProxy* ap
562  = new ::RTC::CORBA::ExecutionContextProxy(ref);
563 
564  Logger logger;
565  obj->setLogger(&logger);
566 
569  mgr.registerFactory(comp->id(),
570  doil::New<LightweightRTObjectServantMock>,
571  doil::Delete<LightweightRTObjectServantMock>);
572  mgr.activateObject(comp);
573  CPPUNIT_ASSERT_EQUAL(0, logger.countLog("add_component"));
574  ret = ap->add_component(comp);
575  CPPUNIT_ASSERT_EQUAL(1, logger.countLog("add_component"));
576  CPPUNIT_ASSERT_EQUAL(::RTC::Local::BAD_PARAMETER, ret);
577 
578  delete ap;
579  CORBA::release(ref);
580 
581  }
582  /* test case */
583  void test_case0()
584  {
585  }
586  };
587 }; // namespace ExecutionContextProxy
588 
589 /*
590  * Register test suite
591  */
593 
594 #ifdef LOCAL_MAIN
595 int main(int argc, char* argv[])
596 {
597  CppUnit::TextUi::TestRunner runner;
598  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
599  CppUnit::Outputter* outputter =
600  new CppUnit::TextOutputter(&runner.result(), std::cout);
601  runner.setOutputter(outputter);
602  bool retcode = runner.run();
603  return !retcode;
604 }
605 #endif // MAIN
606 #endif // ExecutionContextProxy_cpp
::RTC::ReturnCode_t add_component(::RTC::LightweightRTObject_ptr comp)
virtual ::RTC::ExecutionContext_ptr get_context(::RTC::ExecutionContextHandle_t exec_handle)
int main(int argc, char **argv)
virtual const char * name()
Getting ORB&#39;s name.
EXECUTION_HANDLE_TYPE_NATIVE ExecutionContextHandle_t
Definition: IRTC.h:63
::RTC::LifeCycleState get_component_state(::RTC::LightweightRTObject_ptr comp)
virtual ::RTC::ExecutionContextHandle_t attach_context(::RTC::ExecutionContext_ptr exec_context)
virtual bool is_alive(const ::RTC::Local::IExecutionContext *exec_context)
virtual ReturnCode_t registerFactory(const char *id, doil::ServantNewFunc new_func, doil::ServantDeleteFunc delete_func)
Register servant&#39;s factory.
virtual ::RTC::Local::IExecutionContext * get_context(::RTC::Local::ExecutionContextHandle_t exec_handle)
ReturnCode_t
Definition: doil.h:53
static CORBAManager & instance()
getting instance
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
::RTC::ReturnCode_t activate_component(::RTC::LightweightRTObject_ptr comp)
virtual ::RTC::ExecutionContextList * get_participating_contexts()
CPPUNIT_TEST_SUITE_REGISTRATION(ExecutionContextProxy::ExecutionContextProxyTests)
virtual ::RTC::Local::ReturnCode_t on_activated(::RTC::Local::ExecutionContextHandle_t exec_handle)
virtual ::RTC::ReturnCode_t detach_context(::RTC::ExecutionContextHandle_t exec_handle)
virtual ::RTC::ExecutionContextHandle_t get_context_handle(::RTC::ExecutionContext_ptr cxt)
virtual ::RTC::Local::ExecutionContextHandle_t get_context_handle(const ::RTC::Local::IExecutionContext *cxt)
virtual ::RTC::Local::ExecutionContextHandle_t attach_context(const ::RTC::Local::IExecutionContext *exec_context)
std::vector< ExecutionContext * > ExecutionContextList
Definition: IRTC.h:69
int countLog(const std::string &msg)
virtual ::RTC::Local::ReturnCode_t on_shutdown(::RTC::Local::ExecutionContextHandle_t exec_handle)
virtual ::CORBA::Boolean is_alive(::RTC::ExecutionContext_ptr exec_context)
ExecutionKind
Definition: IRTC.h:48
virtual ::RTC::Local::ReturnCode_t on_deactivated(::RTC::Local::ExecutionContextHandle_t exec_handle)
virtual ::RTC::Local::ReturnCode_t detach_context(::RTC::Local::ExecutionContextHandle_t exec_handle)
virtual ::RTC::ReturnCode_t on_aborting(::RTC::ExecutionContextHandle_t exec_handle)
list index
Definition: rtimages.py:10
ReturnCode_t
Definition: IRTC.h:30
virtual ::RTC::ReturnCode_t on_startup(::RTC::ExecutionContextHandle_t exec_handle)
virtual ::RTC::Local::ReturnCode_t on_aborting(::RTC::Local::ExecutionContextHandle_t exec_handle)
::RTC::ReturnCode_t reset_component(::RTC::LightweightRTObject_ptr comp)
virtual ::RTC::Local::ReturnCode_t on_error(::RTC::Local::ExecutionContextHandle_t exec_handle)
virtual ::RTC::ReturnCode_t on_reset(::RTC::ExecutionContextHandle_t exec_handle)
virtual ::RTC::Local::ReturnCode_t on_reset(::RTC::Local::ExecutionContextHandle_t exec_handle)
virtual ::RTC::Local::ExecutionContextList get_owned_contexts()
virtual ::RTC::ReturnCode_t on_activated(::RTC::ExecutionContextHandle_t exec_handle)
::RTC::ReturnCode_t set_rate(::CORBA::Double rate)
::RTC::ReturnCode_t deactivate_component(::RTC::LightweightRTObject_ptr comp)
virtual ::RTC::ReturnCode_t on_error(::RTC::ExecutionContextHandle_t exec_handle)
LifeCycleState
Definition: IRTC.h:40
::OutPortBase::Logger logger
ILightweightRTObject interface class.
virtual ::RTC::Local::ExecutionContextList get_participating_contexts()
virtual ::RTC::ReturnCode_t on_shutdown(::RTC::ExecutionContextHandle_t exec_handle)
ILightweightRTObject interface class.
virtual ::RTC::Local::ReturnCode_t on_startup(::RTC::Local::ExecutionContextHandle_t exec_handle)
virtual ReturnCode_t activateObject(doil::ImplBase *impl)
Activate object.
::RTC::ReturnCode_t remove_component(::RTC::LightweightRTObject_ptr comp)
virtual ::RTC::ReturnCode_t on_deactivated(::RTC::ExecutionContextHandle_t exec_handle)


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Jun 6 2019 19:25:58