51 #include <cppunit/ui/text/TestRunner.h> 52 #include <cppunit/TextOutputter.h> 53 #include <cppunit/extensions/TestFactoryRegistry.h> 54 #include <cppunit/extensions/HelperMacros.h> 55 #include <cppunit/TestAssert.h> 79 void log(
const std::string& msg)
87 for (
int i = 0; i < (int)
m_log.size(); ++i)
89 if (
m_log[i] == msg) ++count;
123 if (m_logger != NULL)
125 m_logger->log(
"PortMock::activateInterfaces");
130 if (m_logger != NULL)
132 m_logger->log(
"PortMock::deactivateInterfaces");
154 :
public CppUnit::TestFixture
157 CPPUNIT_TEST(test_getPortList);
158 CPPUNIT_TEST(test_getPortRef);
159 CPPUNIT_TEST(test_getPort);
160 CPPUNIT_TEST(test_addPort);
161 CPPUNIT_TEST(test_registerPort);
162 CPPUNIT_TEST(test_removePort);
163 CPPUNIT_TEST(test_deletePortByName);
164 CPPUNIT_TEST(test_finalizePorts);
165 CPPUNIT_TEST(test_activatePorts);
166 CPPUNIT_TEST(test_deactivatePorts);
167 CPPUNIT_TEST_SUITE_END();
177 for (
int i = 0; i <
g_argc; i++) {
178 argv[i] = (
char *)g_argv[i].c_str();
181 m_orb = CORBA::ORB_init(g_argc, argv);
182 CORBA::Object_var obj = m_orb->resolve_initial_references(
"RootPOA");
183 m_poa = PortableServer::POA::_narrow(obj);
184 PortableServer::POAManager_var pman = m_poa->the_POAManager();
213 CPPUNIT_ASSERT_EQUAL(
true, portAdmin.
addPort(*port0));
216 port1->setName(
"port1");
217 CPPUNIT_ASSERT_EQUAL(
true, portAdmin.
addPort(*port1));
223 RTC::PortProfile* portProf0 = (*portList)[0]->get_port_profile();
224 CPPUNIT_ASSERT(portProf0 != NULL);
225 CPPUNIT_ASSERT_EQUAL(std::string(
"port0"), std::string(portProf0->name));
227 RTC::PortProfile* portProf1 = (*portList)[1]->get_port_profile();
228 CPPUNIT_ASSERT(portProf1 != NULL);
229 CPPUNIT_ASSERT_EQUAL(std::string(
"port1"), std::string(portProf1->name));
249 CPPUNIT_ASSERT_EQUAL(
true, portAdmin.
addPort(*port0));
252 port1->setName(
"port1");
253 CPPUNIT_ASSERT_EQUAL(
true, portAdmin.
addPort(*port1));
256 RTC::PortService_var portRef0 = portAdmin.
getPortRef(
"port0");
257 CPPUNIT_ASSERT(! CORBA::is_nil(portRef0));
258 RTC::PortProfile* portProf0 = portRef0->get_port_profile();
259 CPPUNIT_ASSERT_EQUAL(std::string(
"port0"), std::string(portProf0->name));
261 RTC::PortService_var portRef1 = portAdmin.
getPortRef(
"port1");
262 CPPUNIT_ASSERT(! CORBA::is_nil(portRef1));
263 RTC::PortProfile* portProf1 = portRef1->get_port_profile();
264 CPPUNIT_ASSERT_EQUAL(std::string(
"port1"), std::string(portProf1->name));
267 CPPUNIT_ASSERT(CORBA::is_nil(portAdmin.
getPortRef(
"inexist")));
284 CPPUNIT_ASSERT_EQUAL(
true, portAdmin.
addPort(*port0));
287 port1->setName(
"port1");
288 CPPUNIT_ASSERT_EQUAL(
true, portAdmin.
addPort(*port1));
293 CPPUNIT_ASSERT_EQUAL(std::string(
"port0"), std::string(portProf0->name));
297 CPPUNIT_ASSERT_EQUAL(std::string(
"port1"), std::string(portProf1->name));
313 CPPUNIT_ASSERT_EQUAL(
true, portAdmin.
addPort(*port0));
314 CPPUNIT_ASSERT_EQUAL(
false, portAdmin.
addPort(*port0));
317 port1->setName(
"port1");
319 CPPUNIT_ASSERT_EQUAL(
true, portAdmin.
addPort(port1->getPortRef()));
320 CPPUNIT_ASSERT_EQUAL(
false, portAdmin.
addPort(port1->getPortRef()));
350 CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), portList->length());
351 RTC::PortProfile* portProf1 = (*portList)[0]->get_port_profile();
352 CPPUNIT_ASSERT_EQUAL(std::string(
"port1"), std::string(portProf1->name));
355 const RTC::PortProfile& portProf0 = port0->
getProfile();
356 CPPUNIT_ASSERT(CORBA::is_nil(portProf0.port_ref));
382 CPPUNIT_ASSERT_EQUAL(
true, portAdmin.
removePort(*port0));
383 CPPUNIT_ASSERT_EQUAL(
false, portAdmin.
removePort(*port0));
389 CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), portList->length());
390 RTC::PortProfile* portProf1 = (*portList)[0]->get_port_profile();
391 CPPUNIT_ASSERT_EQUAL(std::string(
"port1"), std::string(portProf1->name));
394 const RTC::PortProfile& portProf0 = port0->
getProfile();
395 CPPUNIT_ASSERT(CORBA::is_nil(portProf0.port_ref));
426 CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), portList->length());
427 RTC::PortProfile* portProf1 = (*portList)[0]->get_port_profile();
428 CPPUNIT_ASSERT_EQUAL(std::string(
"port1"), std::string(portProf1->name));
431 const RTC::PortProfile& portProf0 = port0->
getProfile();
432 CPPUNIT_ASSERT(CORBA::is_nil(portProf0.port_ref));
463 CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), portList->length());
466 const RTC::PortProfile& portProf0 = port0->
getProfile();
467 CPPUNIT_ASSERT(CORBA::is_nil(portProf0.port_ref));
468 const RTC::PortProfile& portProf1 = port1->
getProfile();
469 CPPUNIT_ASSERT(CORBA::is_nil(portProf1.port_ref));
495 CPPUNIT_ASSERT_EQUAL(0,logger.
countLog(
"PortMock::activateInterfaces"));
497 CPPUNIT_ASSERT_EQUAL(2,logger.
countLog(
"PortMock::activateInterfaces"));
499 CPPUNIT_ASSERT_EQUAL(0,logger.
countLog(
"PortMock::deactivateInterfaces"));
501 CPPUNIT_ASSERT_EQUAL(2,logger.
countLog(
"PortMock::deactivateInterfaces"));
503 m_poa->deactivate_object(*m_poa->servant_to_id(port0));
504 m_poa->deactivate_object(*m_poa->servant_to_id(port1));
526 int main(
int argc,
char* argv[])
539 std::string arg(argv[i]);
540 std::string next_arg;
541 if (i + 1 < argc) next_arg = argv[i + 1];
544 if (arg ==
"--text") { format =
TEXT_OUT;
break; }
557 ofs.open(fname.c_str());
559 if ( arg ==
"--compiler" ) { format =
COMPILER_OUT;
break; }
560 if ( arg ==
"--cerr" ) { target = 1;
break; }
561 if ( arg ==
"--xsl" )
563 if (next_arg ==
"") xsl =
"default.xsl";
566 if ( arg ==
"--namespace" )
570 std::cerr <<
"no namespace specified" << std::endl;
580 CppUnit::TextUi::TestRunner runner;
582 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
584 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
585 CppUnit::Outputter* outputter = 0;
586 std::ostream* stream = target ? &std::cerr : &std::cout;
590 outputter =
new CppUnit::TextOutputter(&runner.result(),*stream);
593 std::cout <<
"XML_OUT" << std::endl;
594 outputter =
new CppUnit::XmlOutputter(&runner.result(),
596 static_cast<CppUnit::XmlOutputter*
>(outputter)->setStyleSheet(xsl);
599 outputter =
new CppUnit::CompilerOutputter(&runner.result(),*stream);
602 runner.setOutputter(outputter);
607 #endif // PortAdmin_cpp
int main(int argc, char **argv)
PortService_ptr getPortRef(const char *port_name) const
Get the reference to Port object.
std::vector< std::string > m_log
void finalizePorts()
Deactivate all Ports and unregister them.
void test_getPort()
getPort()メソッドのテスト
unsigned int sleep(unsigned int seconds)
Stop a processing at specified second time.
void test_deletePortByName()
deletePortByName()メソッドのテスト
const PortProfile & getProfile() const
Get the PortProfile of the Port.
PortService_ptr getPortRef()
Get the object reference of this Port.
PortBase * getPort(const char *port_name) const
Get pointer to the Port's servant.
PortableServer::POA_ptr m_poa
CPPUNIT_TEST_SUITE_REGISTRATION(PortAdmin::PortAdminTests)
void test_getPortList()
getPortList()メソッドのテスト
void test_getPortRef()
getPortRef()メソッドのテスト
void log(const std::string &msg)
void test_deactivatePorts(void)
void activatePorts()
Activate all Port interfaces.
virtual RTC::ReturnCode_t publishInterfaces(RTC::ConnectorProfile &)
PortServiceList * getPortServiceList() const
Get PortServiceList.
void test_addPort()
addPort()メソッドのテスト
void registerPort(PortBase &port)
Regsiter the Port.
void test_removePort()
removePort()のテスト
virtual PortProfile * get_port_profile()
[CORBA interface] Get the PortProfile of the Port
void deactivatePorts()
Deactivate all Port interfaces.
bool removePort(PortBase &port)
Unregister the Port registration.
void test_registerPort()
registerPort(),deletePort()メソッドのテスト
int countLog(const std::string &msg)
std::vector< IPortService * > PortServiceList
void deletePortByName(const char *port_name)
Unregister the Port's registration by its name.
void test_finalizePorts()
finalizePorts()メソッドのテスト
virtual RTC::ReturnCode_t subscribeInterfaces(const RTC::ConnectorProfile &)
void setLogger(Logger *logger)
bool addPort(PortBase &port)
Regsiter the Port.
::OutPortBase::Logger logger
void deletePort(PortBase &port)
Unregister the Port registration.
virtual void unsubscribeInterfaces(const RTC::ConnectorProfile &)
std::vector< std::string > g_argv
void setName(const char *name)
Set the name of this Port.
RTC's Port administration class.
void test_activatePorts(void)
virtual void deactivateInterfaces()
Deactivate all Port interfaces.
virtual void activateInterfaces()
Activate all Port interfaces.