ORBManagerTests.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
12 /*
13  * $Log$
14  *
15  */
16 
17 #ifndef ORBManager_cpp
18 #define ORBManager_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 <coil/DynamicLib.h>
26 #include <doil/ORBManager.h>
27 #include "EchoImpl.h"
28 #include "IEcho.h"
29 #include "EchoCORBASkel.h"
30 #include "EchoIceSkel.h"
32 #include <doil/ice/IceManager.h>
37 typedef void (*ModuleInitFunc)(coil::Properties&);
38 
39 namespace ORBManager
40 {
42  : public CppUnit::TestFixture
43  {
49 
50  private:
51 
52  public:
53 
58  {
59  }
60 
65  {
66  }
67 
71  virtual void setUp()
72  {
73  }
74 
78  virtual void tearDown()
79  {
80  }
81 
82  /* test case */
83  void test_init()
84  {
87  for (int i(0); i < 100; ++i)
88  {
89  doil::ORBManager* tmp;
90  tmp = doil::ORBManager::init(prop);
91  CPPUNIT_ASSERT_MESSAGE("ORBManager's pointer should always be same",
92  mgr == tmp);
93 
94  }
95  }
96  /* test case */
98  {
101  for (int i(0); i < 100; ++i)
102  {
103  doil::ORBManager* tmp;
105  CPPUNIT_ASSERT_MESSAGE("ORBManager's pointer should always be same",
106  mgr == tmp);
107  }
108  }
109  /* test case */
111  {
114 
115  // CORBA
116  coil::DynamicLib dll0;
117  if (dll0.open("../../corba/.libs/libdoilcorba.so",
118  RTLD_LAZY | RTLD_GLOBAL) < 0)
119  {
120  std::cout << dll0.error() << std::endl;
121  CPPUNIT_ASSERT_MESSAGE("doilcorba load faild", false);
122  }
123 
124  void* func0;
125  func0 = dll0.symbol("DoilCORBAInit");
126  CPPUNIT_ASSERT_MESSAGE("invalid symbol for corba init", func0 != NULL);
127  ModuleInitFunc init_func0;
128  init_func0 = (ModuleInitFunc)(func0);
129  init_func0(*prop);
130 
131  std::vector<doil::IORB*> orbs;
133  std::cout << "number of ORB: " << orbs.size() << std::endl;
134  for (int i(0), len(orbs.size()); i < len; ++i)
135  {
136  std::cout << "ORB name: " << orbs[i]->name() << std::endl;
137  }
138 
139  // Ice
140  coil::DynamicLib dll1;
141  if (dll1.open("../../ice/.libs/libdoilice.so",
142  RTLD_LAZY | RTLD_GLOBAL) < 0)
143  {
144  std::cout << dll1.error() << std::endl;
145  CPPUNIT_ASSERT_MESSAGE("doilice load faild", false);
146  }
147 
148  void* func1;
149  func1 = dll1.symbol("DoilIceInit");
150  CPPUNIT_ASSERT_MESSAGE("invalid symbol for ice init", func0 != NULL);
151  ModuleInitFunc init_func1;
152  init_func1 = (ModuleInitFunc)(func1);
153  init_func1(*prop);
154 
156  std::cout << "number of ORB: " << orbs.size() << std::endl;
157  for (int i(0), len(orbs.size()); i < len; ++i)
158  {
159  std::cout << "ORB name: " << orbs[i]->name() << std::endl;
160  }
161 
162  // libEchoCORBA.so
163  coil::DynamicLib dll2;
164  if (dll2.open(".libs/libEchoCORBA.so", RTLD_LAZY | RTLD_GLOBAL) < 0)
165  {
166  std::cout << dll2.error() << std::endl;
167  CPPUNIT_ASSERT_MESSAGE("libEchoCORBA load faild", false);
168  }
169  ModuleInitFunc init_func2;
170  init_func2 = (ModuleInitFunc)dll2.symbol("EchoCORBAInit");
171  if (init_func2 == NULL)
172  {
173  std::cout << dll2.error() << std::endl;
174  CPPUNIT_ASSERT_MESSAGE("symbol not found: EchoCORBAInit", false);
175  }
176  init_func2(*prop);
177 
178 
179  // libEchoIce.so
180  coil::DynamicLib dll3;
181  if (dll3.open(".libs/libEchoIce.so", RTLD_LAZY | RTLD_GLOBAL) < 0)
182  {
183  std::cout << dll3.error() << std::endl;
184  CPPUNIT_ASSERT_MESSAGE("libEchoIce load faild", false);
185  }
186  ModuleInitFunc init_func3;
187  init_func3 = (ModuleInitFunc)dll3.symbol("EchoIceInit");
188  if (init_func3 == NULL)
189  {
190  std::cout << dll3.error() << std::endl;
191  CPPUNIT_ASSERT_MESSAGE("symbol not found: EchoIceInit", false);
192  }
193  init_func3(*prop);
194 
195  EchoImpl* ie0 = new EchoImpl();
196  if (ie0 == NULL) throw "ErrorE";
198 
199  for (int i(0), l(ret.retcodes_.size()); i < l; ++i)
200  {
201  std::cout << i << ": " << ret.retcodes_[i].key_ << ": ";
202  std::cout << doil::return_codes[ret.retcodes_[i].ret_] << std::endl;
203  }
204 
205  // access corba object
206  doil::CORBA::CORBAManager* corba(NULL);
207  doil::Ice::IceManager* ice(NULL);
208  for (int i(0), l(orbs.size()); i < l; ++i)
209  {
210  if (strcmp(orbs[i]->name(), "corba") == 0)
211  corba = dynamic_cast<doil::CORBA::CORBAManager*>(orbs[i]);
212  if (strcmp(orbs[i]->name(), "ice") == 0)
213  ice = dynamic_cast<doil::Ice::IceManager*>(orbs[i]);
214  }
215 
216  CORBA::Object_var obj = corba->toReference(ie0);
217  EchoCORBA::EchoSample_var ec0 = EchoCORBA::EchoSample::_narrow(obj);
218  if (CORBA::is_nil(ec0)) throw "Objectref is nil";
219  ec0->echo("this is corba object");
220 
221  Ice::ObjectPrx base = ice->toReference(ie0);
222  Demo::EchoSamplePrx eobj = Demo::EchoSamplePrx::checkedCast(base);
223  eobj->echo("This is Ice object");
224 
225  ie0->echo("hogehoge");
226  // std::cout << "hoge" << std::endl;
227  }
228  };
229 }; // namespace ORBManager
230 
231 /*
232  * Register test suite
233  */
235 
236 #ifdef LOCAL_MAIN
237 int main(int argc, char* argv[])
238 {
239  CppUnit::TextUi::TestRunner runner;
240  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
241  CppUnit::Outputter* outputter =
242  new CppUnit::TextOutputter(&runner.result(), std::cout);
243  runner.setOutputter(outputter);
244  bool retcode = runner.run();
245  return !retcode;
246 }
247 #endif // MAIN
248 #endif // ORBManager_cpp
int main(int argc, char **argv)
Ice manager for doil.
void echo(std::string msg)
void(* ModuleInitFunc)(coil::Properties &)
::IceInternal::ProxyHandle< ::IceProxy::Demo::EchoSample > EchoSamplePrx
Definition: EchoSample.h:87
virtual void setUp()
Test initialization.
CPPUNIT_TEST_SUITE(ORBManagerTests)
void * symbol(const char *symbol_name)
Return an address of the memory where a symbol was loaded.
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
::CORBA::Object_ptr toReference(doil::ImplBase *impl)
Converting Impl object to object reference.
DynamicLib class.
static ORBManager & instance()
getting instance
Definition: ORBManager.cpp:61
coil::Properties Properties
Definition: RTC.h:83
CORBA manager for doil.
static const char * return_codes[]
Definition: doil.h:62
std::vector< NamedReturnCode > retcodes_
Definition: doil.h:109
::Ice::ObjectPrx toReference(doil::ImplBase *impl)
Converting Impl object to object reference.
Definition: IceManager.cpp:360
CPPUNIT_TEST_SUITE_REGISTRATION(ORBManager::ORBManagerTests)
prop
Organization::get_organization_property ();.
Class represents a set of properties.
Definition: Properties.h:101
virtual void tearDown()
Test finalization.
const char * error(void) const
Return the explanation message about the error.
static ORBManager * init(coil::Properties prop)
initializer
Definition: ORBManager.cpp:39
virtual ReturnCodes activateObject(ImplBase *impl, const char *orbname="")
Activate object.
Definition: ORBManager.cpp:212
virtual int open(const char *dll_name, int open_mode=COIL_DEFAULT_DYNLIB_MODE, int close_handle_on_destruction=1)
Load of the Dynamic link library.
const std::vector< IORB * > getORBs()
Get all the ORBs that are registered in this ORBManager.
Definition: ORBManager.cpp:143


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