29 #include <cppunit/ui/text/TestRunner.h> 30 #include <cppunit/TextOutputter.h> 31 #include <cppunit/extensions/TestFactoryRegistry.h> 32 #include <cppunit/extensions/HelperMacros.h> 33 #include <cppunit/TestAssert.h> 38 #include "MyServiceSkel.h" 41 :
public virtual POA_MyService,
42 public virtual PortableServer::RefCountServantBase
70 std::cout <<
m_name <<
": " << msg << std::endl;
110 deactivateInterfaces();
117 activateInterfaces();
127 :
public CppUnit::TestFixture
130 CPPUNIT_TEST(test_get_port_profile);
131 CPPUNIT_TEST(test_connect);
132 CPPUNIT_TEST(test_disconnect);
133 CPPUNIT_TEST(test_registerProvider);
134 CPPUNIT_TEST(test_activateInterfaces_deactivateInterfaces);
135 CPPUNIT_TEST_SUITE_END();
164 m_pORB = CORBA::ORB_init(argc, argv);
165 m_pPOA = PortableServer::POA::_narrow(
166 m_pORB->resolve_initial_references(
"RootPOA"));
167 m_pPOA->the_POAManager()->activate();
206 port->registerProvider(
"MyService (provided)",
"Generic (provided)", *pMyServiceImpl);
207 port->registerConsumer(
"MyService (required)",
"Generic (required)", *pMyServiceConsumer);
209 RTC::PortService_var portRef = port->getPortRef();
210 RTC::PortProfile* profile = portRef->get_port_profile();
213 CPPUNIT_ASSERT_EQUAL(std::string(
"unknown.name of port"), std::string(profile->name));
217 for (CORBA::ULong i = 0; i < profile->interfaces.length(); ++i)
219 if (std::string(profiles[i].instance_name)
220 == std::string(
"MyService (provided)"))
223 CPPUNIT_ASSERT_EQUAL(std::string(
"Generic (provided)"),
224 std::string(profiles[i].type_name));
229 else if (std::string(profiles[i].instance_name)
230 == std::string(
"MyService (required)"))
233 CPPUNIT_ASSERT_EQUAL(std::string(
"Generic (required)"),
234 std::string(profiles[i].type_name));
242 std::string msg(
"Unexpected instance_name:");
243 msg += std::string(profiles[i].instance_name);
249 delete pMyServiceConsumer;
250 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImpl));
251 delete pMyServiceImpl;
269 port0->registerProvider(
"MyServiceA",
"Generic", *pMyServiceImplA);
270 port0->registerConsumer(
"MyServiceB",
"Generic", *pMyServiceConsumerB);
279 port1->registerProvider(
"MyServiceB",
"Generic", *pMyServiceImplB);
280 port1->registerConsumer(
"MyServiceA",
"Generic", *pMyServiceConsumerA);
283 RTC::ConnectorProfile connProfile;
284 connProfile.connector_id =
"";
285 connProfile.name = CORBA::string_dup(
"name of connector profile");
286 connProfile.ports.length(2);
287 connProfile.ports[0] = port0->getPortRef();
288 connProfile.ports[1] = port1->getPortRef();
291 port0->getPortRef()->connect(connProfile);
293 port0->activateInterfaces_public();
294 port1->activateInterfaces_public();
298 (*pMyServiceConsumerA)->hello_world();
303 (*pMyServiceConsumerB)->hello_world();
308 delete pMyServiceConsumerA;
309 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB));
310 delete pMyServiceImplB;
311 delete pMyServiceConsumerB;
312 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA));
313 delete pMyServiceImplA;
330 port0->registerProvider(
"MyServiceA-1",
"Generic", *pMyServiceImplA);
331 port0->registerConsumer(
"MyServiceB-1",
"Generic", *pMyServiceConsumerB);
340 port1->registerProvider(
"MyServiceB-1",
"Generic", *pMyServiceImplB);
341 port1->registerConsumer(
"MyServiceA-1",
"Generic", *pMyServiceConsumerA);
344 RTC::ConnectorProfile connProfile;
345 connProfile.connector_id =
"id1";
346 connProfile.name = CORBA::string_dup(
"name of connector profile-1");
347 connProfile.ports.length(2);
348 connProfile.ports[0] = port0->getPortRef();
349 connProfile.ports[1] = port1->getPortRef();
352 port0->getPortRef()->connect(connProfile);
354 port0->activateInterfaces_public();
355 port1->activateInterfaces_public();
359 (*pMyServiceConsumerA)->hello_world();
363 port0->getPortRef()->disconnect(connProfile.connector_id);
369 (*pMyServiceConsumerB)->hello_world();
371 CPPUNIT_FAIL(
"Couldn't catch no exceptions. Disconnection failed.");
380 delete pMyServiceConsumerA;
381 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB));
382 delete pMyServiceImplB;
383 delete pMyServiceConsumerB;
384 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA));
385 delete pMyServiceImplA;
403 CPPUNIT_ASSERT_EQUAL(
true,ret);
407 CPPUNIT_ASSERT_EQUAL(
false,ret);
411 CPPUNIT_ASSERT_EQUAL(
false,ret);
416 CPPUNIT_ASSERT_EQUAL(
true,ret);
420 CPPUNIT_ASSERT_EQUAL(
true,ret);
425 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pImpl1));
427 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pImpl0));
443 port0->registerProvider(
"MyServiceAA",
"Generic", *pMyServiceImplA);
444 port0->registerConsumer(
"MyServiceBB",
"Generic", *pMyServiceConsumerB);
453 port1->registerProvider(
"MyServiceBB",
"Generic", *pMyServiceImplB);
454 port1->registerConsumer(
"MyServiceAA",
"Generic", *pMyServiceConsumerA);
457 RTC::ConnectorProfile connProfile;
458 connProfile.connector_id =
"";
459 connProfile.name = CORBA::string_dup(
"name of connector profile");
460 connProfile.ports.length(2);
461 connProfile.ports[0] = port0->getPortRef();
462 connProfile.ports[1] = port1->getPortRef();
465 port0->getPortRef()->connect(connProfile);
467 port0->activateInterfaces_public();
468 port1->activateInterfaces_public();
472 (*pMyServiceConsumerA)->hello_world();
476 port0->getPortRef()->disconnect(connProfile.connector_id);
479 port0->deactivateInterfaces_public();
480 port1->deactivateInterfaces_public();
482 port0->getPortRef()->connect(connProfile);
487 (*pMyServiceConsumerA)->hello_world();
488 CPPUNIT_FAIL(
"Couldn't catch no exceptions. Disconnection failed.");
495 port0->getPortRef()->disconnect(connProfile.connector_id);
497 port0->activateInterfaces_public();
498 port1->activateInterfaces_public();
500 port0->getPortRef()->connect(connProfile);
503 (*pMyServiceConsumerA)->hello_world();
506 port0->getPortRef()->disconnect(connProfile.connector_id);
510 delete pMyServiceConsumerA;
511 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB));
512 delete pMyServiceImplB;
513 delete pMyServiceConsumerB;
514 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA));
515 delete pMyServiceImplA;
527 int main(
int argc,
char* argv[])
540 std::string arg(argv[i]);
541 std::string next_arg;
542 if (i + 1 < argc) next_arg = argv[i + 1];
545 if (arg ==
"--text") { format =
TEXT_OUT;
break; }
558 ofs.open(fname.c_str());
560 if ( arg ==
"--compiler" ) { format =
COMPILER_OUT;
break; }
561 if ( arg ==
"--cerr" ) { target = 1;
break; }
562 if ( arg ==
"--xsl" )
564 if (next_arg ==
"") xsl =
"default.xsl";
567 if ( arg ==
"--namespace" )
571 std::cerr <<
"no namespace specified" << std::endl;
581 CppUnit::TextUi::TestRunner runner;
583 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
585 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
586 CppUnit::Outputter* outputter = 0;
587 std::ostream* stream = target ? &std::cerr : &std::cout;
591 outputter =
new CppUnit::TextOutputter(&runner.result(),*stream);
594 std::cout <<
"XML_OUT" << std::endl;
595 outputter =
new CppUnit::XmlOutputter(&runner.result(),
597 static_cast<CppUnit::XmlOutputter*
>(outputter)->setStyleSheet(xsl);
600 outputter =
new CppUnit::CompilerOutputter(&runner.result(),*stream);
603 runner.setOutputter(outputter);
608 #endif // CorbaPort_cpp int main(int argc, char **argv)
void test_activateInterfaces_deactivateInterfaces(void)
registerProvider()メソッドのテスト
void activateInterfaces_public()
virtual void tearDown()
Test finalization.
RT Conponent CORBA service/consumer Port.
void test_registerProvider(void)
registerProvider()メソッドのテスト
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
std::vector< PortInterfaceProfile * > PortInterfaceProfileList
void setName(const char *name)
CorbaPortTests()
Constructor.
void test_disconnect()
disconnect()メソッド、および、そこから呼び出される各protectedメソッドのテスト
void test_get_port_profile()
get_port_profile()メソッドのテスト
bool m_hello_world_called
void print_msg(const char *msg)
Class represents a set of properties.
virtual ~MyService_impl()
~CorbaPortTests()
Destructor.
virtual void setUp()
Test initialization.
PortableServer::POA_ptr m_pPOA
bool is_hello_world_called()
CorbaPortMock(const char *name)
virtual ~CorbaPortMock(void)
void deactivateInterfaces_public()
CPPUNIT_TEST_SUITE_REGISTRATION(CorbaPort::CorbaPortTests)
bool registerProvider(const char *instance_name, const char *type_name, PortableServer::RefCountServantBase &provider)
Register the provider.