ManagerServantTests.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
12 /*
13  * $Log$
14  *
15  */
16 
17 #ifndef ManagerServant_cpp
18 #define ManagerServant_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 <idl/SDOPackageSkel.h>
28 #include <idl/RTCSkel.h>
29 #include <rtm/idl/ManagerSkel.h>
30 #include <rtm/ManagerServant.h>
31 #include <rtm/NVUtil.h>
32 
37 namespace ManagerServant
38 {
44  class Logger
45  {
46  public:
47  void log(const std::string& msg)
48  {
49  m_log.push_back(msg);
50  }
51 
52  int countLog(const std::string& msg)
53  {
54  int count = 0;
55  for (int i = 0; i < (int) m_log.size(); ++i)
56  {
57  if (m_log[i] == msg) ++count;
58  }
59  return count;
60  }
61 
62  private:
63  std::vector<std::string> m_log;
64  };
65 
67  : public CppUnit::TestFixture
68  {
69  CPPUNIT_TEST_SUITE(ManagerServantTests);
70 
71  CPPUNIT_TEST(test_add_master_manager);
72  CPPUNIT_TEST(test_add_slave_manager);
73  CPPUNIT_TEST(test_get_loadable_modules);
74  CPPUNIT_TEST(test_load_module);
75  CPPUNIT_TEST(test_unload_modules);
76  CPPUNIT_TEST(test_get_loaded_modules);
77  CPPUNIT_TEST(test_get_factory_profiles);
78  CPPUNIT_TEST(test_create_component);
79  CPPUNIT_TEST(test_get_components);
80  CPPUNIT_TEST(test_get_component_profiles);
81  CPPUNIT_TEST(test_get_profile);
82  CPPUNIT_TEST(test_get_configuration);
83  CPPUNIT_TEST(test_set_configuration);
84  CPPUNIT_TEST(test_fork);
85  CPPUNIT_TEST(test_get_service);
86  CPPUNIT_TEST(test_getObjRef);
87  CPPUNIT_TEST(test_delete_component);
88 
89 // CPPUNIT_TEST(test_shutdown); //OK
90 // CPPUNIT_TEST(test_restart); //OK
91  CPPUNIT_TEST_SUITE_END();
92 
93  private:
94  CORBA::ORB_ptr m_pORB;
95  PortableServer::POA_ptr m_pPOA;
96  RTM::Manager_ptr m_objref;
97 
101  bool isFound(const ::RTM::ModuleProfileList* list, const std::string& mod)
102  {
103  const char *pch;
104  for (CORBA::ULong ic = 0; ic < list->length(); ++ic)
105  {
106  if( (*list)[ic].properties[0].value >>= pch )
107  {
108  if(mod == ::std::string(pch))
109  {
110  return true;
111  }
112  }
113  }
114  return false;
115  }
116 
117  public:
118 
123  {
124 
125  int argc = 0;
126  char** argv = NULL;
127  m_pORB = CORBA::ORB_init(argc, argv);
128  m_pPOA = PortableServer::POA::_narrow(
129  m_pORB->resolve_initial_references("RootPOA"));
130  m_pPOA->the_POAManager()->activate();
131 
132  }
133 
138  {
139  }
140 
144  virtual void setUp()
145  {
146  }
147 
151  virtual void tearDown()
152  {
153  }
154 
155 
162  {
163  ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
164  RTM::ManagerList* list;
165  try
166  {
168  CORBA::Boolean cbret;
169  cbret = pman->is_master();
170  // is_master(), default is false
171  CPPUNIT_ASSERT(!cbret);
172 
173  // get_master_managers()
174  list = pman->get_master_managers();
175  CPPUNIT_ASSERT_EQUAL(0, (int)list->length());
176 
177  // createINSManager()
178  bool bret = pman->createINSManager();
179  CPPUNIT_ASSERT(bret);
180 
181  bret = pman->createINSManager();
182  CPPUNIT_ASSERT(!bret);
183 
184  std::string host_port("localhost:2810");
185  RTM::Manager_var owner;
186  // findManager()
187  owner = pman->findManager(host_port.c_str());
188 
189  // add_master_manager()
190  ret = pman->add_master_manager(owner);
191  CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ret);
192  list = pman->get_master_managers();
193  CPPUNIT_ASSERT_EQUAL(1, (int)list->length());
194 
195  // remove_master_manager()
196  ret = pman->remove_master_manager(RTM::Manager::_duplicate(owner));
197  CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ret);
198  list = pman->get_master_managers();
199  CPPUNIT_ASSERT_EQUAL(0, (int)list->length());
200 
201  CORBA::Object_var obj;
202  obj = m_pORB->resolve_initial_references("omniINSPOA");
203  PortableServer::POA_ptr poa = PortableServer::POA::_narrow(obj);
204  poa->the_POAManager()->deactivate(false, true);
205  }
206  catch(CORBA::SystemException& e)
207  {
208  std::cout << "test_add_master_manager() SystemException: " << e._name() << std::endl;
209  }
210  catch (...)
211  {
212  std::cout << "test_add_master_manager() other Exception" << std::endl;
213  }
214 
215  delete list;
216  delete pman;
217  }
218 
225  {
226  ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
227  RTM::ManagerList* list;
228  try
229  {
231 
232  // get_slave_managers()
233  list = pman->get_slave_managers();
234  CPPUNIT_ASSERT_EQUAL(0, (int)list->length());
235 
236  // createINSManager()
237  bool bret = pman->createINSManager();
238  CPPUNIT_ASSERT(!bret);
239 
240  std::string host_port("localhost:2810");
241  RTM::Manager_var owner;
242 
243  // findManager()
244  owner = pman->findManager(host_port.c_str());
245 
246  // add_slave_manager()
247  ret = pman->add_slave_manager(owner);
248  CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ret);
249  list = pman->get_slave_managers();
250  CPPUNIT_ASSERT_EQUAL(1, (int)list->length());
251 
252  // remove_slave_manager()
253  ret = pman->remove_slave_manager(RTM::Manager::_duplicate(owner));
254  CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ret);
255  list = pman->get_slave_managers();
256  CPPUNIT_ASSERT_EQUAL(0, (int)list->length());
257 
258  CORBA::Object_var obj;
259  obj = m_pORB->resolve_initial_references("omniINSPOA");
260  PortableServer::POA_ptr poa = PortableServer::POA::_narrow(obj);
261  poa->the_POAManager()->deactivate(false, true);
262  }
263  catch(CORBA::SystemException& e)
264  {
265  std::cout << "test_add_slave_manager() SystemException: " << e._name() << std::endl;
266  }
267  catch (...)
268  {
269  std::cout << "test_add_slave_manager() other Exception" << std::endl;
270  }
271 
272  delete list;
273  delete pman;
274  }
275 
283  {
284  ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
286  try
287  {
288  ret = pman->load_module(".libs/DummyModule1.so","DummyModule1Init");
289  CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
290  CPPUNIT_ASSERT(isFound(pman->get_loaded_modules(),
291  ".//.libs/DummyModule1.so"));
292  }
293  catch(...)
294  {
295  CPPUNIT_FAIL("Exception thrown.");
296  }
297 
298  //illegal file name.
299  try
300  {
301  ret = pman->load_module("bar.so","DummyModule1Init");
302  CPPUNIT_FAIL("Exception not thrown.");
303  }
304  catch(...)
305  {
306  CPPUNIT_ASSERT(!isFound(pman->get_loaded_modules(), ".//bar.so"));
307  }
308  //illegal function name.
309  try
310  {
311  ret = pman->load_module("DummyModule1i.so","foo");
312  CPPUNIT_FAIL("Exception not thrown.");
313  }
314  catch(...)
315  {
316  CPPUNIT_ASSERT(isFound(pman->get_loaded_modules(),
317  ".//.libs/DummyModule1.so"));
318  }
319  //loading overlaps
320  ret = pman->load_module(".libs/DummyModule1.so","DummyModule1Init");
321  CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
322  CPPUNIT_ASSERT(isFound(pman->get_loaded_modules(),
323  ".//.libs/DummyModule1.so"));
324 
325  //lodding another module
326  ret = pman->load_module(".libs/DummyModule2.so","DummyModule2Init");
327  CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
328  CPPUNIT_ASSERT(isFound(pman->get_loaded_modules(),
329  ".//.libs/DummyModule2.so"));
330 
331  delete pman;
332  }
340  {
341  ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
343  try
344  {
345  ret = pman->load_module(".libs/DummyModule1.so","DummyModule1Init");
346  CPPUNIT_ASSERT(isFound(pman->get_loaded_modules(),
347  ".//.libs/DummyModule1.so"));
348  CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
349  }
350  catch(...)
351  {
352  CPPUNIT_FAIL("Exception thrown.");
353  }
354  try
355  {
356  ret = pman->load_module(".libs/DummyModule2.so","DummyModule2Init");
357  CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
358  CPPUNIT_ASSERT(isFound(pman->get_loaded_modules(),
359  ".//.libs/DummyModule2.so"));
360  }
361  catch(...)
362  {
363  CPPUNIT_FAIL("Exception thrown.");
364  }
365  //
366  try
367  {
368  ret = pman->unload_module(".//.libs/DummyModule2.so");
369  CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
370  }
371  catch(...)
372  {
373  CPPUNIT_FAIL( "unload error" );
374  }
375  //
376  try
377  {
378  pman->unload_module("non-loaded-module.so");
379  CPPUNIT_FAIL("Exception not thrown.");
380  }
381  catch(...)
382  {
383 // CPPUNIT_FAIL( "unload error" ); //OK
384  }
385  delete pman;
386  }
394  {
395  ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
397  try
398  {
399  ret = pman->load_module(".libs/DummyModule1.so","DummyModule1Init");
400  CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
401  CPPUNIT_ASSERT(isFound(pman->get_loaded_modules(),
402  ".//.libs/DummyModule1.so"));
403  }
404  catch(...)
405  {
406  CPPUNIT_FAIL("Exception thrown.");
407  }
408  try
409  {
410  ret = pman->load_module(".libs/DummyModule2.so","DummyModule2Init");
411  CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
412  CPPUNIT_ASSERT(isFound(pman->get_loaded_modules(),
413  ".//.libs/DummyModule2.so"));
414  }
415  catch(...)
416  {
417  CPPUNIT_FAIL("Exception thrown.");
418  }
419 
420  //Execute the function
421  ::RTM::ModuleProfileList* list;
422  list = pman->get_loaded_modules();
423  ::RTM::ModuleProfileList modlist(*list);
424  delete list;
425 
426  //Check returns(ModuleProfileList).
427  CPPUNIT_ASSERT_EQUAL((::CORBA::ULong)2, modlist.length());
428  CPPUNIT_ASSERT_EQUAL(::std::string("file_path"),
429  ::std::string(modlist[0].properties[0].name));
430  const char* ch;
431  if( modlist[0].properties[0].value >>= ch )
432  {
433  CPPUNIT_ASSERT_EQUAL(::std::string(".//.libs/DummyModule1.so"),
434  ::std::string(ch));
435  }
436  else
437  {
438  CPPUNIT_FAIL( "ModuleProfileList is illegal." );
439  }
440 
441  CPPUNIT_ASSERT_EQUAL(::std::string("file_path"),
442  ::std::string(modlist[1].properties[0].name));
443 
444  if( modlist[1].properties[0].value >>= ch )
445  {
446  CPPUNIT_ASSERT_EQUAL(::std::string(".//.libs/DummyModule2.so"),
447  ::std::string(ch));
448  }
449  else
450  {
451  CPPUNIT_FAIL( "ModuleProfileList is illegal." );
452  }
453  delete pman;
454  }
462  {
463  typedef struct data_struct {
464  ::std::string name;
465  ::std::string value;
466  } DATA_STRUCT;
467  DATA_STRUCT composite_spec[] =
468  {
469  {"implementation_id", "PeriodicECSharedComposite"},
470  {"type_name", "PeriodicECSharedComposite"},
471  {"description", "PeriodicECSharedComposite"},
472  {"version", "1.0"},
473  {"vendor", "jp.go.aist"},
474  {"category", "composite.PeriodicECShared"},
475  {"activity_type", "DataFlowComponent"},
476  {"max_instance", "0"},
477  {"language", "C++"},
478  {"lang_type", "compile"},
479  {"exported_ports", ""},
480  {"conf.default.members", ""},
481  {"conf.default.exported_ports", ""},
482  {"",""},
483  };
484  DATA_STRUCT consolein_spec[] =
485  {
486  {"implementation_id", "DummyModule1"},
487  {"type_name", "DummyModule1"},
488  {"description", "Console input component"},
489  {"version", "1.0"},
490  {"vendor", "Noriaki Ando, AIST"},
491  {"category", "example"},
492  {"activity_type", "DataFlowComponent"},
493  {"max_instance", "10"},
494  {"language", "C++"},
495  {"lang_type", "compile"},
496  {"",""},
497  };
498  DATA_STRUCT consoleout_spec[] =
499  {
500  {"implementation_id", "DummyModule2"},
501  {"type_name", "DummyModule2"},
502  {"description", "Console output component"},
503  {"version", "1.0"},
504  {"vendor", "Noriaki Ando, AIST"},
505  {"category", "example"},
506  {"activity_type", "DataFlowComponent"},
507  {"max_instance", "10"},
508  {"language", "C++"},
509  {"lang_type", "compile"},
510  {"",""},
511  };
512  ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
513 
514  //Load modules.
516  ret = pman->load_module(".libs/DummyModule1.so","DummyModule1Init");
517  CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
518  CPPUNIT_ASSERT(isFound(pman->get_loaded_modules(),
519  ".//.libs/DummyModule1.so"));
520  ret = pman->load_module(".libs/DummyModule2.so","DummyModule2Init");
521  CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
522  CPPUNIT_ASSERT(isFound(pman->get_loaded_modules(),
523  ".//.libs/DummyModule2.so"));
524 
525  //Execute the function
526  ::RTM::ModuleProfileList *list;
527  list = pman->get_factory_profiles();
528  ::RTM::ModuleProfileList profiles(*list);
529  delete list;
530 
531  //Check returns(ModuleProfileList).
532  ::CORBA::ULong len;
533  CPPUNIT_ASSERT_EQUAL((::CORBA::ULong)3, profiles.length());
534  len = profiles[0].properties.length();
535  CPPUNIT_ASSERT_EQUAL((::CORBA::ULong)13, len);
536  for (CORBA::ULong ic = 0; ic < len; ++ic)
537  {
538  CPPUNIT_ASSERT_EQUAL(composite_spec[ic].name,
539  ::std::string(profiles[0].properties[ic].name));
540 
541  const char* ch;
542  if( profiles[0].properties[ic].value >>= ch )
543  {
544  CPPUNIT_ASSERT_EQUAL(composite_spec[ic].value,
545  ::std::string(ch));
546  }
547  else
548  {
549  CPPUNIT_FAIL( "ModuleProfileList is illegal." );
550  }
551  }
552  len =profiles[1].properties.length();
553  CPPUNIT_ASSERT_EQUAL((::CORBA::ULong)10, len);
554  for (CORBA::ULong ic = 0; ic < len; ++ic)
555  {
556  CPPUNIT_ASSERT_EQUAL(consolein_spec[ic].name,
557  ::std::string(profiles[1].properties[ic].name));
558 
559  const char* ch;
560  if( profiles[1].properties[ic].value >>= ch )
561  {
562  CPPUNIT_ASSERT_EQUAL(consolein_spec[ic].value,
563  ::std::string(ch));
564  }
565  else
566  {
567  CPPUNIT_FAIL( "ModuleProfileList is illegal." );
568  }
569  }
570  len =profiles[2].properties.length();
571  CPPUNIT_ASSERT_EQUAL((::CORBA::ULong)10, len);
572  for (CORBA::ULong ic = 0; ic < len; ++ic)
573  {
574  CPPUNIT_ASSERT_EQUAL(consoleout_spec[ic].name,
575  ::std::string(profiles[2].properties[ic].name));
576 
577  const char* ch;
578  if( profiles[2].properties[ic].value >>= ch )
579  {
580  CPPUNIT_ASSERT_EQUAL(consoleout_spec[ic].value,
581  ::std::string(ch));
582  }
583  else
584  {
585  CPPUNIT_FAIL( "ModuleProfileList is illegal." );
586  }
587  }
588  delete pman;
589  }
596  {
597  ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
598  //Load modules.
600  ret = pman->load_module(".libs/DummyModule1.so","DummyModule1Init");
601  CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
602  CPPUNIT_ASSERT(isFound(pman->get_loaded_modules(),
603  ".//.libs/DummyModule1.so"));
604  ret = pman->load_module(".libs/DummyModule2.so","DummyModule2Init");
605  CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
606  CPPUNIT_ASSERT(isFound(pman->get_loaded_modules(),
607  ".//.libs/DummyModule2.so"));
608 
609  //Execute the function
610  ::RTC::RTObject_ptr inobj;
611  inobj = pman->create_component("DummyModule1AA");
612  CPPUNIT_ASSERT(::CORBA::is_nil(inobj));
613  inobj = pman->create_component("DummyModule1");
614  CPPUNIT_ASSERT(!::CORBA::is_nil(inobj));
615 
616  ::RTC::RTObject_ptr outobj;
617  outobj = pman->create_component("DummyModule2");
618  CPPUNIT_ASSERT(!::CORBA::is_nil(outobj));
619  delete pman;
620  }
628  {
629  ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
630  //Load modules.
632  ret = pman->load_module(".libs/DummyModule1.so","DummyModule1Init");
633  CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
634  CPPUNIT_ASSERT(isFound(pman->get_loaded_modules(),
635  ".//.libs/DummyModule1.so"));
636  ret = pman->load_module(".libs/DummyModule2.so","DummyModule2Init");
637  CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
638  CPPUNIT_ASSERT(isFound(pman->get_loaded_modules(),
639  ".//.libs/DummyModule2.so"));
640 
641  ::RTC::RTObject_ptr inobj;
642  inobj = pman->create_component("DummyModule1");
643  CPPUNIT_ASSERT(!::CORBA::is_nil(inobj));
644 
645  ::RTC::RTObject_ptr outobj;
646  outobj = pman->create_component("DummyModule2");
647  CPPUNIT_ASSERT(!::CORBA::is_nil(outobj));
648 
649  ::RTC::ComponentProfileList *list;
650  list = pman->get_component_profiles();
651  CPPUNIT_ASSERT(list!=NULL);
652  ::RTC::ComponentProfileList profiles(*list);
653  delete list;
654 
655 // m_pPOA->deactivate_object(*m_pPOA->reference_to_id(inobj));
656  m_pPOA->the_POAManager()->deactivate(false, true);
657  ret = pman->delete_component(profiles[0].instance_name);
658  CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
659 
660  // deleteComponent()でexit()を実行しているため、これ以降のテストはできません。
661  // 以降のdelete_component は、実施せず。
662 // m_pPOA->deactivate_object(*m_pPOA->reference_to_id(outobj));
663 // ret = pman->delete_component(profiles[1].instance_name);
664 // CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
665  delete pman;
666  }
674  {
675  ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
677  ret = pman->load_module(".libs/DummyModule1.so","DummyModule1Init");
678  CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
679  CPPUNIT_ASSERT(isFound(pman->get_loaded_modules(),
680  ".//.libs/DummyModule1.so"));
681  ret = pman->load_module(".libs/DummyModule2.so","DummyModule2Init");
682  CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
683  CPPUNIT_ASSERT(isFound(pman->get_loaded_modules(),
684  ".//.libs/DummyModule2.so"));
685 
686  ::RTC::RTObject_ptr inobj;
687  inobj = pman->create_component("DummyModule1");
688  CPPUNIT_ASSERT(!::CORBA::is_nil(inobj));
689 
690  ::RTC::RTObject_ptr outobj;
691  outobj = pman->create_component("DummyModule2");
692  CPPUNIT_ASSERT(!::CORBA::is_nil(outobj));
693 
694  //Execute the functions
695  ::RTC::RTCList *list;
696  list = pman->get_components();
697  CPPUNIT_ASSERT(list != NULL);
698  ::RTC::RTCList rtclist(*list);
699  delete list;
700 
701  ::CORBA::ULong len(rtclist.length());
702  bool bflag;
703  bflag = false;
704  for (::CORBA::ULong ic = 0; ic < len; ++ic)
705  {
706  if( rtclist[ic] == inobj )
707  {
708  bflag = true;
709  }
710  }
711  CPPUNIT_ASSERT_EQUAL( bflag,true );
712 
713  bflag = false;
714  for (::CORBA::ULong ic = 0; ic < len; ++ic)
715  {
716  if( rtclist[ic] == outobj )
717  {
718  bflag = true;
719  }
720  }
721  CPPUNIT_ASSERT_EQUAL( bflag,true );
722  delete pman;
723  }
730  {
731  ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
733  ret = pman->load_module(".libs/DummyModule1.so","DummyModule1Init");
734  CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
735  CPPUNIT_ASSERT(isFound(pman->get_loaded_modules(),
736  ".//.libs/DummyModule1.so"));
737  ret = pman->load_module(".libs/DummyModule2.so","DummyModule2Init");
738  CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
739  CPPUNIT_ASSERT(isFound(pman->get_loaded_modules(),
740  ".//.libs/DummyModule2.so"));
741 
742  //create components.
743  ::RTC::RTObject_ptr inobj;
744  inobj = pman->create_component("DummyModule1");
745  CPPUNIT_ASSERT(!::CORBA::is_nil(inobj));
746 
747  ::RTC::RTObject_ptr outobj;
748  outobj = pman->create_component("DummyModule2");
749  CPPUNIT_ASSERT(!::CORBA::is_nil(outobj));
750 
751  //Execute the functions.
752  ::RTC::ComponentProfileList *list;
753  list = pman->get_component_profiles();
754  CPPUNIT_ASSERT(list!=NULL);
755  ::RTC::ComponentProfileList profiles(*list);
756  delete list;
757 
758  //Execute the functions
759  ::RTC::RTCList *plist;
760  plist = pman->get_components();
761  CPPUNIT_ASSERT(plist != NULL);
762  ::RTC::RTCList rtclist(*plist);
763  delete plist;
764 
765  ::CORBA::ULong len(rtclist.length());
766  bool bflag;
767  bflag = false;
768  for (::CORBA::ULong ic = 0; ic < len; ++ic)
769  {
770  if( rtclist[ic] == inobj )
771  {
772  bflag = true;
773  ::std::string str(profiles[ic].instance_name);
774  CPPUNIT_ASSERT(str.find("DummyModule1") != ::std::string::npos);
775  CPPUNIT_ASSERT_EQUAL(::std::string("DummyModule1"),
776  ::std::string(profiles[ic].type_name));
777  CPPUNIT_ASSERT_EQUAL(::std::string("Console input component"),
778  ::std::string(profiles[ic].description));
779  CPPUNIT_ASSERT_EQUAL(::std::string("1.0"),
780  ::std::string(profiles[ic].version));
781  CPPUNIT_ASSERT_EQUAL(::std::string("Noriaki Ando, AIST"),
782  ::std::string(profiles[ic].vendor));
783  CPPUNIT_ASSERT_EQUAL(::std::string("example"),
784  ::std::string(profiles[ic].category));
785  break;
786  }
787  }
788  CPPUNIT_ASSERT_EQUAL( bflag,true );
789 
790  bflag = false;
791  for (::CORBA::ULong ic = 0; ic < len; ++ic)
792  {
793  if( rtclist[ic] == outobj )
794  {
795  bflag = true;
796  ::std::string str(profiles[ic].instance_name);
797  CPPUNIT_ASSERT(str.find("DummyModule2") != ::std::string::npos);
798  CPPUNIT_ASSERT_EQUAL(::std::string("DummyModule2"),
799  ::std::string(profiles[ic].type_name));
800  CPPUNIT_ASSERT_EQUAL(::std::string("Console output component"),
801  ::std::string(profiles[ic].description));
802  CPPUNIT_ASSERT_EQUAL(::std::string("1.0"),
803  ::std::string(profiles[ic].version));
804  CPPUNIT_ASSERT_EQUAL(::std::string("Noriaki Ando, AIST"),
805  ::std::string(profiles[ic].vendor));
806  CPPUNIT_ASSERT_EQUAL(::std::string("example"),
807  ::std::string(profiles[ic].category));
808  break;
809  }
810  }
811  CPPUNIT_ASSERT_EQUAL( bflag,true );
812  delete pman;
813  }
821  {
822  typedef struct data_struct {
823  ::std::string name;
824  ::std::string value;
825  } DATA_STRUCT;
826  DATA_STRUCT manager_profile[] =
827  {
828  {"instance_name", "manager"},
829  {"name", "manager"},
830  {"naming_formats", "%h.host_cxt/%n.mgr"},
831  {"pid", ""},
832  {"refstring_path", "/var/log/rtcmanager.ref"},
833  {"modules.load_path", ""},
834  {"modules.abs_path_allowed", "YES"},
835  {"modules.C++.manager_cmd", ""},
836  {"modules.C++.profile_cmd", ""},
837  {"modules.C++.suffixes", ""},
838  {"modules.C++.load_paths", ""},
839  {"modules.Python.manager_cmd",""},
840  {"modules.Python.profile_cmd",""},
841  {"modules.Python.suffixes", ""},
842  {"modules.Python.load_paths",""},
843  {"modules.Java.manager_cmd", ""},
844  {"modules.Java.profile_cmd", ""},
845  {"modules.Java.suffixes", ""},
846  {"modules.Java.load_paths", ""},
847  {"modules.config_path", ""},
848  {"modules.download_allowed", ""},
849  {"modules.init_func_suffix", ""},
850  {"modules.init_func_prefix", ""},
851 // {"modules.config_ext", ""},
852  {"is_master", ""},
853  {"corba_servant", "YES"},
854  {"shutdown_on_nortcs", "YES"},
855  {"shutdown_auto", "YES"},
856  {"command", "rtcd"},
857  {"supported_languages", ""},
858  {"os.name", "Linux"},
859  {"os.release", ""},
860  {"os.version", ""},
861  {"os.arch", ""},
862  {"os.hostname", ""},
863  {"",""},
864  };
865 
866  ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
867 
868  //Execute the functions.
869  ::RTM::ManagerProfile *list;
870  list = pman->get_profile();
871  ::RTM::ManagerProfile profile(*list);
872  delete list;
873  int len;
874  len = profile.properties.length();
875  CPPUNIT_ASSERT_EQUAL(34,len);
876  for(int ic = 0; ic < len; ++ic)
877  {
878  CPPUNIT_ASSERT_EQUAL(manager_profile[ic].name,
879  ::std::string(profile.properties[ic].name));
880  const char* ch;
881  if( profile.properties[ic].value >>= ch )
882  {
883  if(!manager_profile[ic].value.empty())
884  {
885  CPPUNIT_ASSERT_EQUAL(manager_profile[ic].value,
886  ::std::string(ch));
887  }
888  }
889  }
890  delete pman;
891  }
899  {
900  typedef struct data_struct {
901  ::std::string name;
902  ::std::string value;
903  } DATA_STRUCT;
904  DATA_STRUCT config[] =
905  {
906  {"config.version", "1.0.0"},
907  {"openrtm.version", "OpenRTM-aist-1.0.0"},
908  {"manager.instance_name", "manager"},
909  {"manager.name", "manager"},
910  {"manager.naming_formats", "%h.host_cxt/%n.mgr"},
911  {"manager.pid", ""},
912  {"manager.refstring_path", "/var/log/rtcmanager.ref"},
913  {"manager.modules.load_path", ""},
914  {"manager.modules.abs_path_allowed","YES"},
915  {"manager.modules.C++.manager_cmd", ""},
916  {"manager.modules.C++.profile_cmd", ""},
917  {"manager.modules.C++.suffixes", ""},
918  {"manager.modules.C++.load_paths", ""},
919  {"manager.modules.Python.manager_cmd",""},
920  {"manager.modules.Python.profile_cmd",""},
921  {"manager.modules.Python.suffixes", ""},
922  {"manager.modules.Python.load_paths",""},
923  {"manager.modules.Java.manager_cmd", ""},
924  {"manager.modules.Java.profile_cmd", ""},
925  {"manager.modules.Java.suffixes", ""},
926  {"manager.modules.Java.load_paths", ""},
927  {"manager.modules.config_path", ""},
928  {"manager.modules.download_allowed",""},
929  {"manager.modules.init_func_suffix",""},
930  {"manager.modules.init_func_prefix",""},
931  {"manager.is_master", ""},
932  {"manager.corba_servant", "YES"},
933  {"manager.shutdown_on_nortcs", "YES"},
934  {"manager.shutdown_auto", "YES"},
935  {"manager.command", "rtcd"},
936  {"manager.supported_languages", ""},
937  {"manager.os.name", "Linux"},
938  {"manager.os.release", ""},
939  {"manager.os.version", ""},
940  {"manager.os.arch", ""},
941  {"manager.os.hostname", ""},
942  {"os.name", ""},
943  {"os.release", ""},
944  {"os.version", ""},
945  {"os.arch", ""},
946  {"os.hostname", ""},
947  {"logger.enable", ""},
948  {"logger.file_name", ""},
949  {"logger.date_format", "%b %d %H:%M:%S"},
950  {"logger.log_level", ""},
951  {"logger.stream_lock", "NO"},
952  {"logger.master_logger", ""},
953  {"module.conf_path", ""},
954  {"module.load_path", ""},
955  {"naming.enable", "YES"},
956  {"naming.type", "corba"},
957  {"naming.formats", "%h.host_cxt/%n.rtc"},
958  {"naming.update.enable", "YES"},
959  {"naming.update.interval", "10.0"},
960  {"timer.enable", "YES"},
961  {"timer.tick", "0.1"},
962  {"corba.args", ""},
963  {"corba.endpoint", ""},
964  {"corba.id", "omniORB"},
965  {"corba.nameservers", ""},
966  {"corba.master_manager", "localhost:2810"},
967  {"corba.nameservice.replace_endpoint", "NO"},
968 // {"corba.endpoints", ""},
969  {"exec_cxt.periodic.type", "PeriodicExecutionContext"},
970  {"exec_cxt.periodic.rate", "1000"},
971  {"exec_cxt.evdriven.type", "EventDrivenExecutionContext"},
972  {"example.DummyModule10.config_file", ""},
973  {"example.DummyModule1.config_file", ""},
974  {"example.DummyModule20.config_file", ""},
975  {"example.DummyModule2.config_file", ""},
976  {"example.DummyModule11.config_file", ""},
977  {"example.DummyModule21.config_file", ""},
978  {"example.DummyModule12.config_file", ""},
979  {"example.DummyModule22.config_file", ""},
980  {"",""},
981  };
982 
983  ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
984  ::RTM::NVList* list;
985  list = pman->get_configuration();
986  ::RTM::NVList conf(*list);
987  delete list;
988  ::CORBA::ULong len;
989  len = conf.length();
990  CPPUNIT_ASSERT_EQUAL((::CORBA::ULong)73,len);
991  for(::CORBA::ULong ic = 0; ic < len; ++ic)
992  {
993  CPPUNIT_ASSERT_EQUAL(config[ic].name,
994  ::std::string(conf[ic].name));
995  const char* ch;
996  if( conf[ic].value >>= ch )
997  {
998  if(!config[ic].value.empty())
999  {
1000  CPPUNIT_ASSERT_EQUAL(config[ic].value,
1001  ::std::string(ch));
1002  }
1003  }
1004  }
1005  delete pman;
1006  }
1014  {
1015  typedef struct data_struct {
1016  ::std::string name;
1017  ::std::string value;
1018  } DATA_STRUCT;
1019  DATA_STRUCT config[] =
1020  {
1021  {"config.version", "1.0.0"},
1022  {"openrtm.version", "OpenRTM-aist-1.0.0"},
1023  {"manager.naming_formats", "%n.rtc"},
1024  {"manager.modules.load_path", "./,./.libs"},
1025  {"manager.modules.abs_path_allowed","NO"},
1026  {"manager.os.release", "2.6.22-14-generic"},
1027  {"manager.os.version", "2008"},
1028  {"manager.os.arch", "64"},
1029  {"manager.os.hostname", "ubuntur810"},
1030  };
1031  ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
1033  int len;
1034  len = sizeof config/sizeof config[0];
1035  for(int ic = 0; ic < len; ++ic)
1036  {
1037  ret = pman->set_configuration(config[ic].name.c_str(),
1038  config[ic].value.c_str());
1039  CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
1040  }
1041 
1042  ::RTM::NVList* list;
1043  list = pman->get_configuration();
1044  ::RTM::NVList conf(*list);
1045  delete list;
1046  ::CORBA::ULong leng;
1047  leng = conf.length();
1048  CPPUNIT_ASSERT_EQUAL((::CORBA::ULong)73,leng);
1049  for(::CORBA::ULong ic = 0; ic < leng; ++ic)
1050  {
1051  if(config[0].name == ::std::string(conf[ic].name))
1052  {
1053  CPPUNIT_ASSERT_EQUAL(config[ic].name,
1054  ::std::string(conf[ic].name));
1055  const char* ch;
1056  if( conf[ic].value >>= ch )
1057  {
1058  if(!config[ic].value.empty())
1059  {
1060  CPPUNIT_ASSERT_EQUAL(config[ic].value,
1061  ::std::string(ch));
1062  }
1063  }
1064  }
1065  }
1066  delete pman;
1067  }
1068 
1076  {
1077 
1078  ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
1079 
1080  try
1081  {
1083  retcode = pman->shutdown();
1084  CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, retcode);
1085  ::coil::sleep(3);
1086  delete pman;
1087  }
1088  catch(...)
1089  {
1090  CPPUNIT_FAIL("Exception thrown.");
1091  }
1092  delete pman;
1093  }
1101  {
1102  ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
1103 
1104  //ロード可能なモジュールリストを取得する ::RTC::ReturnCode_t ret; // ret = pman->set_configuration("manager.modules.load_path", "./.libs"); // rtc.conf に入れないと有効にならないね! try { ret = pman->load_module(".libs/DummyModule1.so","DummyModule1Init"); CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret); CPPUNIT_ASSERT(isFound(pman->get_loadable_modules(), "DummyModule1")); } catch(...) { CPPUNIT_FAIL("Exception thrown."); } // try { ret = pman->load_module(".libs/DummyModule2.so","DummyModule2Init"); CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret); CPPUNIT_ASSERT(isFound(pman->get_loadable_modules(), "DummyModule2")); } catch(...) { CPPUNIT_FAIL("Exception thrown."); } //Execute the function ::RTM::ModuleProfileList* list; list = pman->get_loadable_modules(); ::RTM::ModuleProfileList modlist(*list); delete list; //Check returns(ModuleProfileList). CPPUNIT_ASSERT_EQUAL((::CORBA::ULong)2, modlist.length()); CORBA::Long long_ret = NVUtil::find_index(modlist[0].properties,"module_file_name"); CPPUNIT_ASSERT(long_ret!=-1); const char* ch; if( modlist[0].properties[long_ret].value >>= ch ) { CPPUNIT_ASSERT_EQUAL(::std::string("DummyModule2.so"), ::std::string(ch)); } else { CPPUNIT_FAIL( "ModuleProfileList is illegal." ); } long_ret = NVUtil::find_index(modlist[1].properties,"module_file_name"); CPPUNIT_ASSERT(long_ret!=-1); if( modlist[1].properties[long_ret].value >>= ch ) { CPPUNIT_ASSERT_EQUAL(::std::string("DummyModule1.so"), ::std::string(ch)); } else { CPPUNIT_FAIL( "ModuleProfileList is illegal." ); } delete pman; } /*! * @brief tests for fork() * * * */ void test_fork() { ::RTM::ManagerServant *pman = new ::RTM::ManagerServant(); CPPUNIT_ASSERT(pman->fork() == ::RTC::RTC_OK); delete pman; } /*! * @brief tests for restart() * * * */ void test_restart() { ::RTM::ManagerServant *pman = new ::RTM::ManagerServant(); CPPUNIT_ASSERT(pman->restart() == ::RTC::RTC_OK); delete pman; } /*! * @brief tests for get_service() * * * */ void test_get_service() { std::string name("service0"); ::RTM::ManagerServant *pman = new ::RTM::ManagerServant(); CPPUNIT_ASSERT(CORBA::is_nil(pman->get_service(name.c_str()))); delete pman; } /*! * @brief tests for getObjRef() * * * */ void test_getObjRef() { ::RTM::ManagerServant *pman = new ::RTM::ManagerServant(); m_objref = pman->getObjRef(); //CPPUNIT_ASSERT(! CORBA::is_nil(m_objref)); delete pman; } }; }; // namespace ManagerServant /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(ManagerServant::ManagerServantTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { CppUnit::TextUi::TestRunner runner; runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); CppUnit::Outputter* outputter = new CppUnit::TextOutputter(&runner.result(), std::cout); runner.setOutputter(outputter); bool retcode = runner.run(); return !retcode; } #endif // MAIN #endif // ManagerServant_cpp
1106 // ret = pman->set_configuration("manager.modules.load_path", "./.libs");
1107 // rtc.conf に入れないと有効にならないね!
1108 
1109  try
1110  {
1111  ret = pman->load_module(".libs/DummyModule1.so","DummyModule1Init");
1112  CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
1113  CPPUNIT_ASSERT(isFound(pman->get_loadable_modules(),
1114  "DummyModule1"));
1115  }
1116  catch(...)
1117  {
1118  CPPUNIT_FAIL("Exception thrown.");
1119  }
1120 
1121  //
1122  try
1123  {
1124  ret = pman->load_module(".libs/DummyModule2.so","DummyModule2Init");
1125  CPPUNIT_ASSERT_EQUAL(::RTC::RTC_OK, ret);
1126  CPPUNIT_ASSERT(isFound(pman->get_loadable_modules(),
1127  "DummyModule2"));
1128  }
1129  catch(...)
1130  {
1131  CPPUNIT_FAIL("Exception thrown.");
1132  }
1133 
1134  //Execute the function
1135  ::RTM::ModuleProfileList* list;
1136  list = pman->get_loadable_modules();
1137  ::RTM::ModuleProfileList modlist(*list);
1138  delete list;
1139 
1140  //Check returns(ModuleProfileList).
1141  CPPUNIT_ASSERT_EQUAL((::CORBA::ULong)2, modlist.length());
1142 
1143  CORBA::Long long_ret = NVUtil::find_index(modlist[0].properties,"module_file_name");
1144  CPPUNIT_ASSERT(long_ret!=-1);
1145 
1146  const char* ch;
1147  if( modlist[0].properties[long_ret].value >>= ch )
1148  {
1149  CPPUNIT_ASSERT_EQUAL(::std::string("DummyModule2.so"),
1150  ::std::string(ch));
1151  }
1152  else
1153  {
1154  CPPUNIT_FAIL( "ModuleProfileList is illegal." );
1155  }
1156 
1157  long_ret = NVUtil::find_index(modlist[1].properties,"module_file_name");
1158  CPPUNIT_ASSERT(long_ret!=-1);
1159 
1160  if( modlist[1].properties[long_ret].value >>= ch )
1161  {
1162  CPPUNIT_ASSERT_EQUAL(::std::string("DummyModule1.so"),
1163  ::std::string(ch));
1164  }
1165  else
1166  {
1167  CPPUNIT_FAIL( "ModuleProfileList is illegal." );
1168  }
1169  delete pman;
1170  }
1171 
1172 
1179  void test_fork()
1180  {
1181  ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
1182  CPPUNIT_ASSERT(pman->fork() == ::RTC::RTC_OK);
1183  delete pman;
1184  }
1185 
1193  {
1194  ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
1195  CPPUNIT_ASSERT(pman->restart() == ::RTC::RTC_OK);
1196  delete pman;
1197  }
1198 
1206  {
1207  std::string name("service0");
1208  ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
1209  CPPUNIT_ASSERT(CORBA::is_nil(pman->get_service(name.c_str())));
1210  delete pman;
1211  }
1212 
1220  {
1221  ::RTM::ManagerServant *pman = new ::RTM::ManagerServant();
1222  m_objref = pman->getObjRef();
1223  //CPPUNIT_ASSERT(! CORBA::is_nil(m_objref));
1224  delete pman;
1225  }
1226 
1227  };
1228 }; // namespace ManagerServant
1229 
1230 /*
1231  * Register test suite
1232  */
1234 
1235 #ifdef LOCAL_MAIN
1236 int main(int argc, char* argv[])
1237 {
1238  CppUnit::TextUi::TestRunner runner;
1239  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
1240  CppUnit::Outputter* outputter =
1241  new CppUnit::TextOutputter(&runner.result(), std::cout);
1242  runner.setOutputter(outputter);
1243  bool retcode = runner.run();
1244  return !retcode;
1245 }
1246 #endif // MAIN
1247 #endif // ManagerServant_cpp
void test_set_configuration()
tests for set_configuration()
int main(int argc, char **argv)
int countLog(const std::string &msg)
void test_delete_component()
tests for delete_components()
RTM::ManagerList * get_slave_managers()
Getting slave managers.
static const char * consoleout_spec[]
CPPUNIT_TEST_SUITE_REGISTRATION(ManagerServant::ManagerServantTests)
unsigned int sleep(unsigned int seconds)
Stop a processing at specified second time.
Definition: ace/coil/Time.h:40
bool createINSManager()
Generate INSManager.
ReturnCode_t
Definition: doil.h:53
std::vector< std::pair< std::string, std::string > > NVList
Definition: IRTC.h:67
bool isFound(const ::RTM::ModuleProfileList *list, const std::string &mod)
Manager CORBA class.
virtual void setUp()
Test initialization.
void test_get_profile()
tests for get_profile()
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
CORBA::Object_ptr get_service(const char *name)
Get the reference of RTC.
RTC::ReturnCode_t shutdown()
This method shutdowns RTC.
void test_get_factory_profiles()
tests for get_factory_profiles()
RTM::NVList * get_configuration()
Getting this manager&#39;s configuration.
std::vector< std::string > m_log
RTC::RTObject_ptr create_component(const char *module_name)
Creating an RT-Component.
void test_add_slave_manager()
tests for add_slave_manager(), get_slave_managers(), remove_slave_manager()
void test_get_service()
tests for get_service()
virtual void tearDown()
Test finalization.
RTM::ManagerList * get_master_managers()
Getting master managers.
def description()
Definition: cxx_gen.py:27
void log(const std::string &msg)
RTM::Manager_ptr findManager(const char *host_port)
Find the reference of Manager.
const CORBA::Long find_index(const SDOPackage::NVList &nv, const char *name)
Return the index of element specified by name from NVList.
Definition: NVUtil.cpp:227
RTC::ReturnCode_t remove_slave_manager(RTM::Manager_ptr mgr)
Removing a slave manager.
RTC::ReturnCode_t set_configuration(const char *name, const char *value)
Setting manager&#39;s configuration.
RTC::ReturnCode_t delete_component(const char *instance_name)
Deleting an RT-Component.
RTC::ReturnCode_t load_module(const char *pathname, const char *initfunc)
Loading a module.
RTC::ReturnCode_t remove_master_manager(RTM::Manager_ptr mgr)
Removing a master manager.
void test_unload_modules()
tests for unload_modules()
void test_get_configuration()
tests for get_configuration()
void test_add_master_manager()
tests for is_master(), createINSManager(), findManager(), add_master_manager(), get_master_managers()...
RTComponent manager servant implementation class.
static const char * consolein_spec[]
NameValue and NVList utility functions.
void test_shutdown()
tests for shutdown()
RTC::ReturnCode_t restart()
This method restarts RTC.
void test_get_loadable_modules()
tests for get_loadable_modules()
RTM::ModuleProfileList * get_loaded_modules()
Getting loaded module profiles.
RTC::ReturnCode_t unload_module(const char *pathname)
Unloading a module.
RTC::ReturnCode_t add_master_manager(RTM::Manager_ptr mgr)
Getting a master manager.
void test_get_component_profiles()
tests for get_component_profiles()
void test_get_loaded_modules()
tests for get_loaded_modules()
RTM::ManagerProfile * get_profile()
Getting this manager&#39;s profile.
::CORBA::Boolean is_master()
Whether this manager is master or not.
void test_getObjRef()
tests for getObjRef()
void test_get_components()
tests for get_components()
RTM::Manager_ptr getObjRef() const
Get the reference of Manager.
RTM::ModuleProfileList * get_factory_profiles()
Getting component factory profiles.
bret
7 送受信データ比較
Definition: ConnectTest.py:377
RTC::RTCList * get_components()
Getting RT-Component list running on this manager.
std::vector< IRTObject * > RTCList
RTC::ComponentProfileList * get_component_profiles()
Getting RT-Component&#39;s profile list running on this manager.
void test_load_module()
tests for load_module()
RTM::ModuleProfileList * get_loadable_modules()
Getting loadable module profiles.
RTC::ReturnCode_t add_slave_manager(RTM::Manager_ptr mgr)
Getting a slave manager.
RTC::ReturnCode_t fork()
The copy of the process is generated.


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