19 #ifndef NamingManager_cpp 20 #define NamingManager_cpp 22 #include <cppunit/ui/text/TestRunner.h> 23 #include <cppunit/TextOutputter.h> 24 #include <cppunit/extensions/TestFactoryRegistry.h> 25 #include <cppunit/extensions/HelperMacros.h> 26 #include <cppunit/TestAssert.h> 35 class CorbaObjectManager
43 void activate(::PortableServer::ServantBase* servant)
47 m_poa->activate_object(servant);
49 catch(const ::PortableServer::POA::ServantAlreadyActive &)
56 ::PortableServer::ObjectId_var
id;
57 id =
m_poa->servant_to_id(servant);
58 m_poa->deactivate_object(
id);
61 ::CORBA::ORB_ptr
m_orb;
62 ::PortableServer::POA_ptr
m_poa;
105 :
public CppUnit::TestFixture
109 CPPUNIT_TEST(test_bindObject_and_unbindObject);
110 CPPUNIT_TEST(test_bindObject_and_unbindObject3);
112 CPPUNIT_TEST_SUITE_END();
122 = std::string(
"corbaloc::")
124 + std::string(
"/NameService");
126 CORBA::Object_var obj = m_pORB->string_to_object(nsName.c_str());
127 CosNaming::NamingContext_var rootContext = CosNaming::NamingContext::_narrow(obj);
128 if (CORBA::is_nil(rootContext))
130 throw std::bad_alloc();
159 m_pORB = CORBA::ORB_init(argc, argv);
160 m_pPOA = PortableServer::POA::_narrow(
161 m_pORB->resolve_initial_references(
"RootPOA"));
162 m_pPOA->the_POAManager()->activate();
181 const char* name_server =
"localhost:2809";
188 CPPUNIT_ASSERT(! CORBA::is_nil(rto->
getObjRef()));
194 CosNaming::NamingContext_var nc = getRootContext(name_server);
195 CosNaming::Name name;
198 name[0].kind =
"kind";
199 CORBA::Object_ptr obj = nc->resolve(name);
200 CPPUNIT_ASSERT(! CORBA::is_nil(obj));
209 CPPUNIT_FAIL(
"Exception not thrown.");
211 catch (CosNaming::NamingContext::NotFound expected) {}
227 const char* name_server =
"localhost:2809";
240 CosNaming::NamingContext_var nc = getRootContext(name_server);
241 CosNaming::Name name;
244 name[0].kind =
"kind";
245 CORBA::Object_ptr obj = nc->resolve(name);
255 CPPUNIT_FAIL(
"Exception not thrown.");
257 catch (CosNaming::NamingContext::NotFound expected) {}
266 :
public CppUnit::TestFixture
270 CPPUNIT_TEST(test_registerMgrName_and_unregisterMgrName);
271 CPPUNIT_TEST(test_bindObject_and_unbindObject2);
272 CPPUNIT_TEST(test_bindObject_and_unbindObject);
273 CPPUNIT_TEST(test_unbindAll);
274 CPPUNIT_TEST(test_getObjects);
275 CPPUNIT_TEST(test_update);
277 CPPUNIT_TEST_SUITE_END();
288 = std::string(
"corbaloc::")
290 + std::string(
"/NameService");
292 CORBA::Object_var obj = m_mgr->
getORB()->string_to_object(nsName.c_str());
293 CosNaming::NamingContext_var rootContext = CosNaming::NamingContext::_narrow(obj);
294 if (CORBA::is_nil(rootContext))
296 throw std::bad_alloc();
302 bool canResolve(
const char* name_server,
const char*
id,
const char* kind)
304 CosNaming::NamingContext_var nc = getRootContext(name_server);
306 CosNaming::Name name;
311 CORBA::Object_ptr obj;
314 obj = nc->resolve(name);
316 catch (CosNaming::NamingContext::NotFound e)
321 return !CORBA::is_nil(obj);
377 CPPUNIT_ASSERT(! CORBA::is_nil(rto->
getObjRef()));
382 const char* name_server =
"localhost:2809";
387 CPPUNIT_ASSERT(canResolve(name_server,
"id",
"kind"));
393 CPPUNIT_ASSERT(! canResolve(name_server,
"id",
"kind"));
412 CPPUNIT_ASSERT(! CORBA::is_nil(rto1->
getObjRef()));
416 CPPUNIT_ASSERT(! CORBA::is_nil(rto2->
getObjRef()));
421 const char* name_server =
"localhost:2809";
426 CPPUNIT_ASSERT(canResolve(name_server,
"id1",
"kind1"));
429 CPPUNIT_ASSERT(canResolve(name_server,
"id2",
"kind2"));
435 CPPUNIT_ASSERT(! canResolve(name_server,
"id1",
"kind1"));
436 CPPUNIT_ASSERT(! canResolve(name_server,
"id2",
"kind2"));
458 CPPUNIT_ASSERT(! CORBA::is_nil(rto1->
getObjRef()));
462 CPPUNIT_ASSERT(! CORBA::is_nil(rto2->
getObjRef()));
467 const char* name_server =
"localhost:2809";
472 CPPUNIT_ASSERT(canResolve(name_server,
"id1",
"kind1"));
475 CPPUNIT_ASSERT(canResolve(name_server,
"id2",
"kind2"));
478 std::vector<RTC::RTObject_impl*> objs = nmgr.
getObjects();
479 CPPUNIT_ASSERT_EQUAL(2, (
int) objs.size());
482 CPPUNIT_ASSERT(objs.end() !=
std::find(objs.begin(), objs.end(), rto1));
483 CPPUNIT_ASSERT(objs.end() !=
std::find(objs.begin(), objs.end(), rto2));
502 const char* name_server =
"localhost:2809";
510 CPPUNIT_ASSERT(! CORBA::is_nil(rto->
getObjRef()));
516 CPPUNIT_ASSERT(! canResolve(name_server,
"id",
"kind"));
522 CPPUNIT_ASSERT(! canResolve(name_server,
"id",
"kind"));
526 m_mgr->
getConfig()[
"naming.update.rebind"] =
"NO";
528 CPPUNIT_ASSERT(! canResolve(name_server,
"id",
"kind"));
530 m_mgr->
getConfig()[
"naming.update.rebind"] =
"YES";
532 CPPUNIT_ASSERT(canResolve(name_server,
"id",
"kind"));
561 for (
int i(0), len(nmm.
mgrNames.size()); i < len; ++i)
563 if (nmm.
mgrNames[i]->name ==
"id.kind")
571 CPPUNIT_ASSERT(bret);
577 for (
int i(0), len(nmm.
mgrNames.size()); i < len; ++i)
579 if (nmm.
mgrNames[i]->name ==
"id.kind")
587 CPPUNIT_ASSERT(bret);
593 for (
int i(0), len(nmm.
mgrNames.size()); i < len; ++i)
595 if (nmm.
mgrNames[i]->name ==
"id2.kind2")
603 CPPUNIT_ASSERT(bret);
610 for (
int i(0), len(nmm.
mgrNames.size()); i < len; ++i)
612 if (nmm.
mgrNames[i]->name ==
"id2.kind2")
617 CPPUNIT_ASSERT(!bret);
621 for (
int i(0), len(nmm.
mgrNames.size()); i < len; ++i)
628 CPPUNIT_ASSERT(!bret);
635 for (
int i(0), len(nmm.
mgrNames.size()); i < len; ++i)
637 if (nmm.
mgrNames[i]->name ==
"id.kind")
642 CPPUNIT_ASSERT(!bret);
646 for (
int i(0), len(nmm.
mgrNames.size()); i < len; ++i)
653 CPPUNIT_ASSERT(!bret);
681 const char* name_server =
"localhost:2809";
692 CPPUNIT_ASSERT(! canResolve(name_server,
"id",
"kind"));
708 int main(
int argc,
char* argv[])
721 std::string arg(argv[i]);
722 std::string next_arg;
723 if (i + 1 < argc) next_arg = argv[i + 1];
726 if (arg ==
"--text") { format =
TEXT_OUT;
break; }
739 ofs.open(fname.c_str());
741 if ( arg ==
"--compiler" ) { format =
COMPILER_OUT;
break; }
742 if ( arg ==
"--cerr" ) { target = 1;
break; }
743 if ( arg ==
"--xsl" )
745 if (next_arg ==
"") xsl =
"default.xsl";
748 if ( arg ==
"--namespace" )
752 std::cerr <<
"no namespace specified" << std::endl;
762 CppUnit::TextUi::TestRunner runner;
764 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
766 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
767 CppUnit::Outputter* outputter = 0;
768 std::ostream* stream = target ? &std::cerr : &std::cout;
772 outputter =
new CppUnit::TextOutputter(&runner.result(),*stream);
775 std::cout <<
"XML_OUT" << std::endl;
776 outputter =
new CppUnit::XmlOutputter(&runner.result(),
778 static_cast<CppUnit::XmlOutputter*
>(outputter)->setStyleSheet(xsl);
781 outputter =
new CppUnit::CompilerOutputter(&runner.result(),*stream);
784 runner.setOutputter(outputter);
789 #endif // NamingManager_cpp
CosNaming::NamingContext_var getRootContext(const std::string &name_server)
int main(int argc, char **argv)
void test_bindObject_and_unbindObject3()
bindObject()メソッドとunbindObject()メソッドのテスト
void deactivate(::PortableServer::ServantBase *servant)
NamingManagerMock(RTC::Manager *manager)
CPPUNIT_TEST_SUITE_REGISTRATION(NamingManager::NamingOnCorbaTests)
std::vector< Mgr * > m_mgrNames
ManagerServant list.
virtual void tearDown()
Test finalization.
PortableServer::POA_ptr getPOA()
Get a pointer to RootPOA held by Manager.
virtual ~NamingManagerMock(void)
CorbaObjectManager(::CORBA::ORB_ptr orb, ::PortableServer::POA_ptr poa)
void test_bindObject_and_unbindObject2()
bindObject()メソッドとunbindObject()メソッドのテスト
std::vector< RTObject_impl * > getObjects()
Get all bound objects.
void test_bindObject_and_unbindObject()
bindObject()メソッドとunbindObject()メソッドのテスト
void bindObject(const char *name, const RTObject_impl *rtobj)
Bind the specified objects to NamingService.
void registerNameServer(const char *method, const char *name_server)
Regster the NameServer.
CORBA::ORB_ptr getORB()
Get the pointer to ORB.
virtual void bindObject(const char *name, const RTObject_impl *rtobj)
Bind the specified CORBA objects to NamingService.
PortableServer::POA_ptr m_pPOA
void test_getObjects()
getObjects()メソッドのテスト
void unregisterMgrName(const char *name)
Unregister the ManagerServants that will be registered to NameServer.
void registerMgrName(const char *name, const RTM::ManagerServant *mgr)
Configure the ManagerServants that will be registered to NameServer.
RTComponent manager class.
std::vector< RTC::NamingManager::Mgr * > mgrNames
virtual ReturnCode_t finalize()
[CORBA interface] Finalize the RTC for destruction
::PortableServer::POA_ptr m_poa
void test_update()
update()メソッドのテスト
coil::Properties & getConfig()
Get the manager configuration.
void unregisterMgrName(const char *name)
NamingOnCorbaTests()
Constructor.
CORBA::Long find(const CorbaSequence &seq, Functor f)
Return the index of CORBA sequence element that functor matches.
static Manager * init(int argc, char **argv)
Initialize manager.
virtual void tearDown()
Test finalization.
void test_bindObject_and_unbindObject()
bindObject()メソッドおよびunbindObject()メソッドのテスト
void test_registerNameServer()
registerNameServer()メソッドのテスト
RTObject_ptr getObjRef() const
[local interface] Get the object reference
void test_unbindAll()
unbindAll()メソッドのテスト
bool canResolve(const char *name_server, const char *id, const char *kind)
naming Service helper class
void update()
Update information of NamingServer.
virtual void unbindObject(const char *name)
Unbind the specified CORBA objects from NamingService.
PortableServer::POA_ptr m_pPOA
virtual ~NamingManagerTests()
Destructor.
NamingServer management class for CORBA.
void test_registerMgrName_and_unregisterMgrName()
registerMgrName()メソッドとunregisterMgrName()メソッドのテスト
void registerMgrName(const char *name, const RTM::ManagerServant *mgr)
virtual void setUp()
Test initialization.
void activate(::PortableServer::ServantBase *servant)
virtual void setUp()
Test initialization.
NamingServer management class.
void unbindObject(const char *name)
Unbind the specified objects from NamingService.
NamingManagerTests()
Constructor.
virtual ~NamingOnCorbaTests()
Destructor.
CosNaming::NamingContext_var getRootContext(const std::string &name_server)
void unbindAll()
Unbind all objects from NamingService.