PeriodicECSharedCompositeTests.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
12 /*
13  * $Log: PeriodicECSharedCompositeTests.cpp,v $
14  *
15  */
16 
17 #ifndef PeriodicECSharedComposite_cpp
18 #define PeriodicECSharedComposite_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 
26 #include <rtm/idl/RTCSkel.h>
27 #include <rtm/idl/OpenRTMSkel.h>
28 #include <rtm/RTC.h>
29 #include <rtm/RTObject.h>
32 #include <rtm/Manager.h>
33 #include <rtm/SdoOrganization.h>
34 
40 {
41  using namespace SDOPackage;
42 
44  : public CppUnit::TestFixture
45  {
46  CPPUNIT_TEST_SUITE(PeriodicECSharedCompositeTests);
47 
48  CPPUNIT_TEST(test_PeriodicECOrganization);
49  CPPUNIT_TEST(test_PeriodicECSharedComposite);
50 
51  CPPUNIT_TEST_SUITE_END();
52 
53  private:
54  CORBA::ORB_ptr m_pORB;
55  PortableServer::POA_ptr m_pPOA;
56 
57  public:
58 
63  {
64  int argc(0);
65  char** argv(NULL);
66  m_pORB = CORBA::ORB_init(argc, argv);
67  m_pPOA = PortableServer::POA::_narrow(
68  m_pORB->resolve_initial_references("RootPOA"));
69  m_pPOA->the_POAManager()->activate();
70  }
71 
76  {
77  }
78 
82  virtual void setUp()
83  {
84  }
85 
89  virtual void tearDown()
90  {
91  }
92 
98  {
99  CORBA::Boolean bret;
100  SDOPackage::SDO_var sdo;
101  SDOPackage::SDOList slist;
102 
104  RTC::RTObject_impl* rto = new RTC::RTObject_impl(&mgr);
106 
107  short sflg = -1;
108  try {
109  // set_members()
110  sdo = SDOPackage::SDO::_duplicate(rto->getObjRef());
111  rto->setInstanceName("obj1");
112  CORBA_SeqUtil::push_back(slist, sdo);
113  bret = peco->set_members(slist);
114  CPPUNIT_ASSERT(bret);
115  sflg = 0;
116  }
117  catch (InvalidParameter ip) {
118  //std::cout << "InvalidParameter exception." << std::endl;
119  sflg = 1;
120  }
121  catch (NotAvailable na) {
122  //std::cout << "NotAvailable exception." << std::endl;
123  sflg = 2;
124  }
125  catch (InternalError ie) {
126  //std::cout << "InternalError exception." << std::endl;
127  sflg = 3;
128  }
129  catch (...) {
130  //std::cout << "othrer exception." << std::endl;
131  sflg = 9;
132  }
133  CPPUNIT_ASSERT(sflg == 0);
134 
135  sflg = -1;
136  try {
137  // remove_member()
138  bret = peco->remove_member("obj1");
139  CPPUNIT_ASSERT(bret);
140  sflg = 0;
141  }
142  catch (InvalidParameter ip) {
143  //std::cout << "InvalidParameter exception." << std::endl;
144  sflg = 1;
145  }
146  catch (NotAvailable na) {
147  //std::cout << "NotAvailable exception." << std::endl;
148  sflg = 2;
149  }
150  catch (InternalError ie) {
151  //std::cout << "InternalError exception." << std::endl;
152  sflg = 3;
153  }
154  catch (...) {
155  //std::cout << "othrer exception." << std::endl;
156  sflg = 9;
157  }
158  CPPUNIT_ASSERT(sflg == 0);
159 
160  // updateDelegatedPorts()
161  peco->updateDelegatedPorts();
162 
163  // 削除後の例外チェック
164  sflg = -1;
165  try {
166  // remove_member()
167  bret = peco->remove_member("obj1");
168  sflg = 0;
169  }
170  catch (InvalidParameter ip) {
171  //std::cout << "InvalidParameter exception." << std::endl;
172  sflg = 1;
173  }
174  catch (NotAvailable na) {
175  //std::cout << "NotAvailable exception." << std::endl;
176  sflg = 2;
177  }
178  catch (InternalError ie) {
179  //std::cout << "InternalError exception." << std::endl;
180  sflg = 3;
181  }
182  catch (...) {
183  //std::cout << "othrer exception." << std::endl;
184  sflg = 9;
185  }
186  CPPUNIT_ASSERT(sflg == 1);
187 
188  sflg = -1;
189  try {
190  // add_members()
191  sdo = SDOPackage::SDO::_duplicate(rto->getObjRef());
192  rto->setInstanceName("obj2");
193  CORBA_SeqUtil::push_back(slist, sdo);
194  bret = peco->add_members(slist);
195  CPPUNIT_ASSERT(bret);
196  sflg = 0;
197  }
198  catch (InvalidParameter ip) {
199  //std::cout << "InvalidParameter exception." << std::endl;
200  sflg = 1;
201  }
202  catch (NotAvailable na) {
203  //std::cout << "NotAvailable exception." << std::endl;
204  sflg = 2;
205  }
206  catch (InternalError ie) {
207  //std::cout << "InternalError exception." << std::endl;
208  sflg = 3;
209  }
210  catch (...) {
211  //std::cout << "othrer exception." << std::endl;
212  sflg = 9;
213  }
214  CPPUNIT_ASSERT(sflg == 0);
215 
216  sflg = -1;
217  try {
218  // removeAllMembers()
219  peco->removeAllMembers();
220  sflg = 0;
221  }
222  catch (InvalidParameter ip) {
223  //std::cout << "InvalidParameter exception." << std::endl;
224  sflg = 1;
225  }
226  catch (NotAvailable na) {
227  //std::cout << "NotAvailable exception." << std::endl;
228  sflg = 2;
229  }
230  catch (InternalError ie) {
231  //std::cout << "InternalError exception." << std::endl;
232  sflg = 3;
233  }
234  catch (...) {
235  //std::cout << "othrer exception." << std::endl;
236  sflg = 9;
237  }
238  CPPUNIT_ASSERT(sflg == 0);
239 
240  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(peco));
241  delete peco;
242  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
243  delete rto;
244  }
245 
251  {
255  RTC::UniqueId id = 0;
256 
257  // onInitialize()
258  ret = pec->onInitialize();
259  CPPUNIT_ASSERT(ret == RTC::RTC_OK);
260  coil::usleep(100000);
261 
262  // onActivated()
263  ret = pec->onActivated(id);
264  CPPUNIT_ASSERT(ret == RTC::RTC_OK);
265  coil::usleep(100000);
266 
267  // onDeactivated()
268  ret = pec->onDeactivated(id);
269  CPPUNIT_ASSERT(ret == RTC::RTC_OK);
270  coil::usleep(100000);
271 
272  // onReset()
273  ret = pec->onReset(id);
274  CPPUNIT_ASSERT(ret == RTC::RTC_OK);
275  coil::usleep(100000);
276 
277  // onFinalize()
278  ret = pec->onFinalize();
279  CPPUNIT_ASSERT(ret == RTC::RTC_OK);
280  coil::usleep(10000);
281 
282  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec));
283  delete pec;
284  }
285 
286  };
287 
288 }; // namespace PeriodicECSharedComposite
289 
290 /*
291  * Register test suite
292  */
294 
295 #ifdef LOCAL_MAIN
296 int main(int argc, char* argv[])
297 {
298 
299  FORMAT format = TEXT_OUT;
300  int target = 0;
301  std::string xsl;
302  std::string ns;
303  std::string fname;
304  std::ofstream ofs;
305 
306  int i(1);
307  while (i < argc)
308  {
309  std::string arg(argv[i]);
310  std::string next_arg;
311  if (i + 1 < argc) next_arg = argv[i + 1];
312  else next_arg = "";
313 
314  if (arg == "--text") { format = TEXT_OUT; break; }
315  if (arg == "--xml")
316  {
317  if (next_arg == "")
318  {
319  fname = argv[0];
320  fname += ".xml";
321  }
322  else
323  {
324  fname = next_arg;
325  }
326  format = XML_OUT;
327  ofs.open(fname.c_str());
328  }
329  if ( arg == "--compiler" ) { format = COMPILER_OUT; break; }
330  if ( arg == "--cerr" ) { target = 1; break; }
331  if ( arg == "--xsl" )
332  {
333  if (next_arg == "") xsl = "default.xsl";
334  else xsl = next_arg;
335  }
336  if ( arg == "--namespace" )
337  {
338  if (next_arg == "")
339  {
340  std::cerr << "no namespace specified" << std::endl;
341  exit(1);
342  }
343  else
344  {
345  xsl = next_arg;
346  }
347  }
348  ++i;
349  }
350  CppUnit::TextUi::TestRunner runner;
351  if ( ns.empty() )
352  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
353  else
354  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
355  CppUnit::Outputter* outputter = 0;
356  std::ostream* stream = target ? &std::cerr : &std::cout;
357  switch ( format )
358  {
359  case TEXT_OUT :
360  outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
361  break;
362  case XML_OUT :
363  std::cout << "XML_OUT" << std::endl;
364  outputter = new CppUnit::XmlOutputter(&runner.result(),
365  ofs, "shift_jis");
366  static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
367  break;
368  case COMPILER_OUT :
369  outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
370  break;
371  }
372  runner.setOutputter(outputter);
373  runner.run();
374  return 0; // runner.run() ? 0 : 1;
375 }
376 #endif // MAIN
377 #endif // PeriodicECSharedComposite_cpp
virtual ReturnCode_t onActivated(RTC::UniqueId exec_handle)
Callback function to activate.
virtual ReturnCode_t onReset(RTC::UniqueId exec_handle)
Callback function to reset.
int main(int argc, char **argv)
void removeAllMembers(void)
Remove a member of Organization.
void test_PeriodicECOrganization()
add_members(), set_members(), remove_member(), removeAllMembers(), updateDelegatedPorts() メソッドのテスト ...
ReturnCode_t
Definition: doil.h:53
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
RT-Component class.
Definition: RTObject.h:89
Manager class.
Definition: Manager.h:80
SDO Organization implementation class.
static Manager & instance()
Get instance of the manager.
Definition: Manager.cpp:140
SDO Package.
virtual ReturnCode_t onFinalize(void)
[ComponentAction CORBA interface] Finalize RTC
RTComponent manager class.
PeriodicECSharedComposite class.
Periodic Execution Context Shared Composite Component class.
def bret
7 送受信データ比較
Definition: ConnectTest.py:377
ExecutionContextHandle_t UniqueId
virtual ::CORBA::Boolean remove_member(const char *id)
[CORBA interface] Remove a member of Organization
RTObject_ptr getObjRef() const
[local interface] Get the object reference
Definition: RTObject.cpp:1487
virtual ::CORBA::Boolean set_members(const SDOList &sdos)
[CORBA interface] Set Organization member
virtual ReturnCode_t onDeactivated(RTC::UniqueId exec_handle)
Callback function to deactivate.
PeriodicExecutionContext class.
CPPUNIT_TEST_SUITE_REGISTRATION(PeriodicECSharedComposite::PeriodicECSharedCompositeTests)
void push_back(CorbaSequence &seq, SequenceElement elem)
Push the new element back to the CORBA sequence.
void setInstanceName(const char *instance_name)
[local interface] Set instance name
Definition: RTObject.cpp:1441
RTComponent header.
void test_PeriodicECSharedComposite()
onInitialize(), onActivated(), onDeactivated(), onReset(), onFinalize() メソッドのテスト
virtual ReturnCode_t onInitialize(void)
Initialization.
virtual ::CORBA::Boolean add_members(const SDOList &sdo_list)
[CORBA interface] Add Organization member
void updateDelegatedPorts(void)
Update/Remove a member of Organization.
int usleep(useconds_t usec)
Stop a processing at specified micro second time.
Definition: ace/coil/Time.h:51


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Feb 28 2022 23:00:44