ORBManagerTests.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00012 /*
00013  * $Log$
00014  *
00015  */
00016 
00017 #ifndef ORBManager_cpp
00018 #define ORBManager_cpp
00019 
00020 #include <cppunit/ui/text/TestRunner.h>
00021 #include <cppunit/TextOutputter.h>
00022 #include <cppunit/extensions/TestFactoryRegistry.h>
00023 #include <cppunit/extensions/HelperMacros.h>
00024 #include <cppunit/TestAssert.h>
00025 #include <coil/DynamicLib.h>
00026 #include <doil/ORBManager.h>
00027 #include "EchoImpl.h"
00028 #include "IEcho.h"
00029 #include "EchoCORBASkel.h"
00030 #include "EchoIceSkel.h"
00031 #include <doil/corba/CORBAManager.h>
00032 #include <doil/ice/IceManager.h>
00037 typedef void (*ModuleInitFunc)(coil::Properties&);
00038 
00039 namespace ORBManager
00040 {
00041   class ORBManagerTests
00042    : public CppUnit::TestFixture
00043   {
00044     CPPUNIT_TEST_SUITE(ORBManagerTests);
00045     CPPUNIT_TEST(test_init);
00046     CPPUNIT_TEST(test_instance);
00047     CPPUNIT_TEST(test_load_and_add);
00048     CPPUNIT_TEST_SUITE_END();
00049   
00050   private:
00051   
00052   public:
00053   
00057     ORBManagerTests()
00058     {
00059     }
00060     
00064     ~ORBManagerTests()
00065     {
00066     }
00067   
00071     virtual void setUp()
00072     {
00073     }
00074     
00078     virtual void tearDown()
00079     { 
00080     }
00081   
00082     /* test case */
00083     void test_init()
00084     {
00085       coil::Properties prop;
00086       doil::ORBManager* mgr = doil::ORBManager::init(prop);
00087       for (int i(0); i < 100; ++i)
00088         {
00089           doil::ORBManager* tmp;
00090           tmp = doil::ORBManager::init(prop);
00091           CPPUNIT_ASSERT_MESSAGE("ORBManager's pointer should always be same",
00092                                  mgr == tmp);
00093           
00094         }
00095     }
00096     /* test case */
00097     void test_instance()
00098     {
00099       coil::Properties prop;
00100       doil::ORBManager* mgr = &doil::ORBManager::instance();
00101       for (int i(0); i < 100; ++i)
00102         {
00103           doil::ORBManager* tmp;
00104           tmp = &doil::ORBManager::instance();
00105           CPPUNIT_ASSERT_MESSAGE("ORBManager's pointer should always be same",
00106                                  mgr == tmp);
00107         }
00108     }
00109     /* test case */
00110     void test_load_and_add()
00111     {
00112       doil::ORBManager::init(coil::Properties());
00113       coil::Properties* prop = new coil::Properties();
00114 
00115       // CORBA
00116       coil::DynamicLib dll0;
00117       if (dll0.open("../../corba/.libs/libdoilcorba.so",
00118                     RTLD_LAZY | RTLD_GLOBAL) < 0)
00119         {
00120           std::cout << dll0.error() << std::endl;
00121           CPPUNIT_ASSERT_MESSAGE("doilcorba load faild", false);
00122         }
00123 
00124       void* func0;
00125       func0 = dll0.symbol("DoilCORBAInit");
00126       CPPUNIT_ASSERT_MESSAGE("invalid symbol for corba init", func0 != NULL);
00127       ModuleInitFunc init_func0;
00128       init_func0 = (ModuleInitFunc)(func0);
00129       init_func0(*prop);
00130 
00131       std::vector<doil::IORB*> orbs;
00132       orbs = doil::ORBManager::instance().getORBs();
00133       std::cout << "number of ORB: " << orbs.size() << std::endl;
00134       for (int i(0), len(orbs.size()); i < len; ++i)
00135         {
00136           std::cout << "ORB name: " << orbs[i]->name() << std::endl;
00137         }
00138 
00139       // Ice
00140       coil::DynamicLib dll1;
00141       if (dll1.open("../../ice/.libs/libdoilice.so",
00142                     RTLD_LAZY | RTLD_GLOBAL) < 0)
00143         {
00144           std::cout << dll1.error() << std::endl;
00145           CPPUNIT_ASSERT_MESSAGE("doilice load faild", false);
00146         }
00147 
00148       void* func1;
00149       func1 = dll1.symbol("DoilIceInit");
00150       CPPUNIT_ASSERT_MESSAGE("invalid symbol for ice init", func0 != NULL);
00151       ModuleInitFunc init_func1;
00152       init_func1 = (ModuleInitFunc)(func1);
00153       init_func1(*prop);
00154 
00155       orbs = doil::ORBManager::instance().getORBs();
00156       std::cout << "number of ORB: " << orbs.size() << std::endl;
00157       for (int i(0), len(orbs.size()); i < len; ++i)
00158         {
00159           std::cout << "ORB name: " << orbs[i]->name() << std::endl;
00160         }
00161 
00162       // libEchoCORBA.so
00163       coil::DynamicLib dll2;
00164       if (dll2.open(".libs/libEchoCORBA.so", RTLD_LAZY | RTLD_GLOBAL) < 0)
00165         {
00166           std::cout << dll2.error() << std::endl;
00167           CPPUNIT_ASSERT_MESSAGE("libEchoCORBA load faild", false);
00168         }
00169       ModuleInitFunc init_func2;
00170       init_func2 = (ModuleInitFunc)dll2.symbol("EchoCORBAInit");
00171       if (init_func2 == NULL)
00172         {
00173           std::cout << dll2.error() << std::endl;
00174           CPPUNIT_ASSERT_MESSAGE("symbol not found: EchoCORBAInit", false);
00175         }
00176       init_func2(*prop);
00177 
00178 
00179       // libEchoIce.so
00180       coil::DynamicLib dll3;
00181       if (dll3.open(".libs/libEchoIce.so", RTLD_LAZY | RTLD_GLOBAL) < 0)
00182         {
00183           std::cout << dll3.error() << std::endl;
00184           CPPUNIT_ASSERT_MESSAGE("libEchoIce load faild", false);
00185         }
00186       ModuleInitFunc init_func3;
00187       init_func3 = (ModuleInitFunc)dll3.symbol("EchoIceInit");
00188       if (init_func3 == NULL)
00189         {
00190           std::cout << dll3.error() << std::endl;
00191           CPPUNIT_ASSERT_MESSAGE("symbol not found: EchoIceInit", false);
00192         }
00193       init_func3(*prop);
00194 
00195       EchoImpl* ie0 = new EchoImpl();
00196       if (ie0 == NULL) throw "ErrorE";
00197       doil::ReturnCodes ret = doil::ORBManager::instance().activateObject(ie0);
00198 
00199       for (int i(0), l(ret.retcodes_.size()); i < l; ++i)
00200         {
00201           std::cout << i << ": " << ret.retcodes_[i].key_ << ": ";
00202           std::cout << doil::return_codes[ret.retcodes_[i].ret_] << std::endl;
00203         }
00204 
00205       // access corba object
00206       doil::CORBA::CORBAManager* corba(NULL);
00207       doil::Ice::IceManager* ice(NULL);
00208       for (int i(0), l(orbs.size()); i < l; ++i)
00209         {
00210           if (strcmp(orbs[i]->name(), "corba") == 0)
00211             corba = dynamic_cast<doil::CORBA::CORBAManager*>(orbs[i]);
00212           if (strcmp(orbs[i]->name(), "ice") == 0)
00213             ice = dynamic_cast<doil::Ice::IceManager*>(orbs[i]);
00214         }
00215 
00216       CORBA::Object_var obj = corba->toReference(ie0);
00217       EchoCORBA::EchoSample_var ec0 = EchoCORBA::EchoSample::_narrow(obj);
00218       if (CORBA::is_nil(ec0)) throw "Objectref is nil";
00219       ec0->echo("this is corba object");
00220 
00221       Ice::ObjectPrx base = ice->toReference(ie0);
00222       Demo::EchoSamplePrx eobj = Demo::EchoSamplePrx::checkedCast(base);
00223       eobj->echo("This is Ice object");
00224 
00225       ie0->echo("hogehoge");
00226       //      std::cout << "hoge" << std::endl;
00227     }
00228   };
00229 }; // namespace ORBManager
00230 
00231 /*
00232  * Register test suite
00233  */
00234 CPPUNIT_TEST_SUITE_REGISTRATION(ORBManager::ORBManagerTests);
00235 
00236 #ifdef LOCAL_MAIN
00237 int main(int argc, char* argv[])
00238 {
00239     CppUnit::TextUi::TestRunner runner;
00240     runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
00241     CppUnit::Outputter* outputter = 
00242       new CppUnit::TextOutputter(&runner.result(), std::cout);
00243     runner.setOutputter(outputter);
00244     bool retcode = runner.run();
00245     return !retcode;
00246 }
00247 #endif // MAIN
00248 #endif // ORBManager_cpp


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sun Mar 26 2017 03:37:16