17 #ifndef PortServiceProxy_cpp 18 #define PortServiceProxy_cpp 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> 28 #include <idl/RTCSkel.h> 29 #include <PortServiceProxy.h> 30 #include <PortServiceServant.h> 48 void log(
const std::string& msg)
56 for (
int i = 0; i < (int)
m_log.size(); ++i)
58 if (
m_log[i] == msg) ++count;
73 :
public virtual ::POA_RTC::PortService,
78 : ::
doil::CORBA::CORBAServantBase(impl), m_impl(NULL)
86 ::RTC::PortProfile* corba_ret = new ::RTC::PortProfile ();
96 const char* connector_id)
98 ::RTC::ConnectorProfile* corba_ret = new ::RTC::ConnectorProfile ();
102 ::RTC::ConnectorProfile& connector_profile)
115 ::RTC::ConnectorProfile& connector_profile)
140 const char*
id() {
return "IPortServiceMock";}
141 const char*
name() {
return "IPortServiceMock";}
165 const ::std::string& connector_id)
181 const ::std::string& connector_id)
201 const ::std::string& connector_id)
217 :
public virtual ::POA_RTC::PortService {
233 throw (CORBA::SystemException)
235 if (m_logger != NULL)
237 m_logger->log(
"get_port_profile");
239 ::RTC::PortProfile_var prof;
240 m_profile.name =
"name of port";
241 m_profile.interfaces.length(1);
242 m_profile.interfaces[0].instance_name =
"MyService (provided)";
243 m_profile.interfaces[0].type_name =
"Generic (provided)";
245 prof = new ::RTC::PortProfile(m_profile);
252 throw (CORBA::SystemException)
254 if (m_logger != NULL)
256 m_logger->log(
"get_connector_profiles");
258 m_profile.connector_profiles.length(1);
259 m_profile.connector_profiles[0].name =
"ConnectorProfile-name";
260 m_profile.connector_profiles[0].connector_id =
"connect_id0";
261 m_profile.connector_profiles[0].properties.length(1);
262 m_profile.connector_profiles[0].properties[0].name
263 =
"ConnectorProfile-properties0-name";
264 m_profile.connector_profiles[0].properties[0].value
265 <<= (::CORBA::Float)1.1;
266 m_profile.connector_profiles[0].ports.length(1);
270 ::RTC::ConnectorProfileList_var conn_prof;
273 return conn_prof._retn();
279 throw (CORBA::SystemException)
281 if (m_logger != NULL)
283 m_logger->log(
"get_connector_profile");
284 m_logger->log(connector_id);
286 m_profile.connector_profiles.length(1);
287 m_profile.connector_profiles[0].name =
"ConnectorProfile-name";
288 m_profile.connector_profiles[0].connector_id =
"connect_id0";
289 m_profile.connector_profiles[0].properties.length(1);
290 m_profile.connector_profiles[0].properties[0].name
291 =
"ConnectorProfile-properties0-name";
292 m_profile.connector_profiles[0].properties[0].value
293 <<= (::CORBA::Float)1.1;
294 m_profile.connector_profiles[0].ports.length(1);
295 ::RTC::ConnectorProfile_var conn_prof;
298 conn_prof = new ::RTC::ConnectorProfile(
299 m_profile.connector_profiles[0]);
300 return conn_prof._retn();
306 throw (CORBA::SystemException)
308 if (m_logger != NULL)
311 m_logger->log(
"connect");
312 m_logger->log(::std::string(connector_profile.name));
313 m_logger->log(::std::string(connector_profile.connector_id));
315 ::std::string(connector_profile.properties[0].name));
317 ::CORBA::ULong ul = 3;
318 ::CORBA::Any::to_string to_str(ch, ul);
319 connector_profile.properties[0].value >>= to_str;
320 m_logger->log(to_str.val);
322 connector_profile.name =
"ConnectorProfile-name";
323 connector_profile.connector_id =
"connect_id0";
324 connector_profile.properties.length(1);
325 connector_profile.properties[0].name
326 =
"ConnectorProfile-properties0-name";
327 connector_profile.properties[0].value
328 <<= (::CORBA::Float)1.1;
329 connector_profile.ports.length(1);
338 throw (CORBA::SystemException)
340 if (m_logger != NULL)
342 m_logger->log(
"notify_connect");
343 m_logger->log(::std::string(connector_profile.name));
344 m_logger->log(::std::string(connector_profile.connector_id));
346 ::std::string(connector_profile.properties[0].name));
348 ::CORBA::ULong ul = 3;
349 ::CORBA::Any::to_string to_str(ch, ul);
350 connector_profile.properties[0].value >>= to_str;
351 m_logger->log(to_str.val);
353 connector_profile.name =
"ConnectorProfile-name";
354 connector_profile.connector_id =
"connect_id0";
355 connector_profile.properties.length(1);
356 connector_profile.properties[0].name
357 =
"ConnectorProfile-properties0-name";
358 connector_profile.properties[0].value
359 <<= (::CORBA::Float)1.1;
360 connector_profile.ports.length(1);
369 throw (CORBA::SystemException)
371 if (m_logger != NULL)
373 m_logger->log(
"disconnect");
374 m_logger->log(connector_id);
382 throw (CORBA::SystemException)
384 if (m_logger != NULL)
386 m_logger->log(
"notify_disconnect");
387 m_logger->log(connector_id);
395 throw (CORBA::SystemException)
397 if (m_logger != NULL)
399 m_logger->log(
"disconnect_all");
410 :
public CppUnit::TestFixture
413 CPPUNIT_TEST(test_get_port_profile);
414 CPPUNIT_TEST(test_get_connector_profiles);
415 CPPUNIT_TEST(test_get_connector_profile);
416 CPPUNIT_TEST(test_connect);
417 CPPUNIT_TEST(test_disconnect);
418 CPPUNIT_TEST(test_disconnect_all);
419 CPPUNIT_TEST(test_notify_connect);
420 CPPUNIT_TEST(test_notify_disconnect);
421 CPPUNIT_TEST_SUITE_END();
436 m_pORB = CORBA::ORB_init(argc, argv);
437 m_pPOA = PortableServer::POA::_narrow(
438 m_pORB->resolve_initial_references(
"RootPOA"));
439 m_pPOA->the_POAManager()->activate();
471 ::CORBA::Object_ptr ref = obj->_this();
472 if(::CORBA::is_nil(ref))
474 std::cout<<
"ref is nil.Abort test."<<std::endl;
477 ::RTC::CORBA::PortServiceProxy* ap
478 = new ::RTC::CORBA::PortServiceProxy(ref);
483 CPPUNIT_ASSERT_EQUAL(0, logger.
countLog(
"get_port_profile"));
485 prof = ap->get_port_profile();
486 CPPUNIT_ASSERT_EQUAL(1, logger.
countLog(
"get_port_profile"));
487 CPPUNIT_ASSERT_EQUAL(::std::string(
"name of port"),
489 CPPUNIT_ASSERT_EQUAL((::std::string::size_type)1,
490 prof.interfaces.size());
491 CPPUNIT_ASSERT_EQUAL(::std::string(
"MyService (provided)"),
492 prof.interfaces[0].instance_name);
494 prof.interfaces[0].polarity);
509 ::CORBA::Object_ptr ref = obj->_this();
510 if(::CORBA::is_nil(ref))
512 std::cout<<
"ref is nil.Abort test."<<std::endl;
515 ::RTC::CORBA::PortServiceProxy* ap
516 = new ::RTC::CORBA::PortServiceProxy(ref);
521 CPPUNIT_ASSERT_EQUAL(0, logger.
countLog(
"get_connector_profiles"));
523 proflist = ap->get_connector_profiles();
524 CPPUNIT_ASSERT_EQUAL(1, logger.
countLog(
"get_connector_profiles"));
526 CPPUNIT_ASSERT_EQUAL((::std::string::size_type)1,
529 CPPUNIT_ASSERT_EQUAL(::std::string(
"ConnectorProfile-name"),
532 CPPUNIT_ASSERT_EQUAL(::std::string(
"connect_id0"),
533 proflist[0].connector_id);
535 ::std::cout<<proflist[0].properties.size()<<::std::endl;
536 CPPUNIT_ASSERT_EQUAL((::std::string::size_type)1,
537 proflist[0].properties.size());
538 CPPUNIT_ASSERT_EQUAL(::std::string(
539 "ConnectorProfile-properties0-name"),
540 proflist[0].properties[0].name);
541 CPPUNIT_ASSERT_EQUAL(::std::string(
"1.1"),
542 proflist[0].properties[0].value);
543 CPPUNIT_ASSERT_EQUAL((::std::string::size_type)1,
544 proflist[0].ports.size());
559 ::CORBA::Object_ptr ref = obj->_this();
560 if(::CORBA::is_nil(ref))
562 std::cout<<
"ref is nil.Abort test."<<std::endl;
565 ::RTC::CORBA::PortServiceProxy* ap
566 = new ::RTC::CORBA::PortServiceProxy(ref);
571 ::std::string str =
"test_get_connector_profile";
572 CPPUNIT_ASSERT_EQUAL(0, logger.
countLog(
"get_connector_profile"));
573 CPPUNIT_ASSERT_EQUAL(0, logger.
countLog(str));
575 prof = ap->get_connector_profile(str);
576 CPPUNIT_ASSERT_EQUAL(1, logger.
countLog(
"get_connector_profile"));
577 CPPUNIT_ASSERT_EQUAL(1, logger.
countLog(str));
579 CPPUNIT_ASSERT_EQUAL(::std::string(
"ConnectorProfile-name"),
582 CPPUNIT_ASSERT_EQUAL(::std::string(
"connect_id0"),
585 CPPUNIT_ASSERT_EQUAL((::std::string::size_type)1,
586 prof.properties.size());
587 CPPUNIT_ASSERT_EQUAL(::std::string(
588 "ConnectorProfile-properties0-name"),
589 prof.properties[0].name);
590 CPPUNIT_ASSERT_EQUAL(::std::string(
"1.1"),
591 prof.properties[0].value);
592 CPPUNIT_ASSERT_EQUAL((::std::string::size_type)1,
610 std::cout <<
"Manager Name==>"<< mgr.
name() << std::endl;
613 ::CORBA::Object_ptr ref = obj->_this();
614 if(::CORBA::is_nil(ref))
616 std::cout<<
"ref is nil.Abort test."<<std::endl;
619 ::RTC::CORBA::PortServiceProxy* ap
620 = new ::RTC::CORBA::PortServiceProxy(ref);
626 ::std::string str1 =
"in_ConnectorProfile-name";
627 ::std::string str2 =
"in_connect_id0";
628 ::std::string str3 =
"in_ConnectorProfile-properties0-name";
629 ::std::string str4 =
"2.2";
632 ::SDOPackage::Local::NameValue
nv;
639 doil::New<PortServiceServantMock>,
640 doil::Delete<PortServiceServantMock>);
642 prof.
ports.push_back(&portservice);
645 CPPUNIT_ASSERT_EQUAL(0, logger.
countLog(
"connect"));
646 CPPUNIT_ASSERT_EQUAL(0, logger.
countLog(str1));
647 CPPUNIT_ASSERT_EQUAL(0, logger.
countLog(str2));
648 CPPUNIT_ASSERT_EQUAL(0, logger.
countLog(str3));
649 CPPUNIT_ASSERT_EQUAL(0, logger.
countLog(str4));
651 ret = ap->connect(prof);
653 CPPUNIT_ASSERT_EQUAL(1, logger.
countLog(
"connect"));
654 CPPUNIT_ASSERT_EQUAL(1, logger.
countLog(str1));
655 CPPUNIT_ASSERT_EQUAL(1, logger.
countLog(str2));
656 CPPUNIT_ASSERT_EQUAL(1, logger.
countLog(str3));
657 CPPUNIT_ASSERT_EQUAL(1, logger.
countLog(str4));
659 CPPUNIT_ASSERT_EQUAL(::std::string(
"ConnectorProfile-name"),
662 CPPUNIT_ASSERT_EQUAL(::std::string(
"connect_id0"),
665 CPPUNIT_ASSERT_EQUAL((::std::string::size_type)1,
667 CPPUNIT_ASSERT_EQUAL(::std::string(
668 "ConnectorProfile-properties0-name"),
670 CPPUNIT_ASSERT_EQUAL(::std::string(
"1.1"),
672 CPPUNIT_ASSERT_EQUAL((::std::string::size_type)1,
689 ::CORBA::Object_ptr ref = obj->_this();
690 if(::CORBA::is_nil(ref))
692 std::cout<<
"ref is nil.Abort test."<<std::endl;
695 ::RTC::CORBA::PortServiceProxy* ap
696 = new ::RTC::CORBA::PortServiceProxy(ref);
701 ::std::string str =
"test_disconnect";
702 CPPUNIT_ASSERT_EQUAL(0, logger.
countLog(
"disconnect"));
703 CPPUNIT_ASSERT_EQUAL(0, logger.
countLog(str));
705 ret = ap->disconnect(str);
706 CPPUNIT_ASSERT_EQUAL(1, logger.
countLog(
"disconnect"));
707 CPPUNIT_ASSERT_EQUAL(1, logger.
countLog(str));
723 ::CORBA::Object_ptr ref = obj->_this();
724 if(::CORBA::is_nil(ref))
726 std::cout<<
"ref is nil.Abort test."<<std::endl;
729 ::RTC::CORBA::PortServiceProxy* ap
730 = new ::RTC::CORBA::PortServiceProxy(ref);
735 CPPUNIT_ASSERT_EQUAL(0, logger.
countLog(
"disconnect_all"));
737 ret = ap->disconnect_all();
738 CPPUNIT_ASSERT_EQUAL(1, logger.
countLog(
"disconnect_all"));
756 std::cout <<
"Manager Name==>"<< mgr.
name() << std::endl;
758 ::CORBA::Object_ptr ref = obj->_this();
759 if(::CORBA::is_nil(ref))
761 std::cout<<
"ref is nil.Abort test."<<std::endl;
764 ::RTC::CORBA::PortServiceProxy* ap
765 = new ::RTC::CORBA::PortServiceProxy(ref);
771 ::std::string str1 =
"in_ConnectorProfile-name";
772 ::std::string str2 =
"in_connect_id0";
773 ::std::string str3 =
"in_ConnectorProfile-properties0-name";
774 ::std::string str4 =
"2.2";
777 ::SDOPackage::Local::NameValue
nv;
784 doil::New<PortServiceServantMock>,
785 doil::Delete<PortServiceServantMock>);
787 prof.
ports.push_back(&portservice);
788 CPPUNIT_ASSERT_EQUAL(0, logger.
countLog(
"notify_connect"));
789 CPPUNIT_ASSERT_EQUAL(0, logger.
countLog(str1));
790 CPPUNIT_ASSERT_EQUAL(0, logger.
countLog(str2));
791 CPPUNIT_ASSERT_EQUAL(0, logger.
countLog(str3));
792 CPPUNIT_ASSERT_EQUAL(0, logger.
countLog(str4));
794 ret = ap->notify_connect(prof);
796 CPPUNIT_ASSERT_EQUAL(1, logger.
countLog(
"notify_connect"));
797 CPPUNIT_ASSERT_EQUAL(1, logger.
countLog(str1));
798 CPPUNIT_ASSERT_EQUAL(1, logger.
countLog(str2));
799 CPPUNIT_ASSERT_EQUAL(1, logger.
countLog(str3));
800 CPPUNIT_ASSERT_EQUAL(1, logger.
countLog(str4));
802 CPPUNIT_ASSERT_EQUAL(::std::string(
"ConnectorProfile-name"),
805 CPPUNIT_ASSERT_EQUAL(::std::string(
"connect_id0"),
808 CPPUNIT_ASSERT_EQUAL((::std::string::size_type)1,
810 CPPUNIT_ASSERT_EQUAL(::std::string(
811 "ConnectorProfile-properties0-name"),
813 CPPUNIT_ASSERT_EQUAL(::std::string(
"1.1"),
815 CPPUNIT_ASSERT_EQUAL((::std::string::size_type)1,
834 ::CORBA::Object_ptr ref = obj->_this();
835 if(::CORBA::is_nil(ref))
837 std::cout<<
"ref is nil.Abort test."<<std::endl;
840 ::RTC::CORBA::PortServiceProxy* ap
841 = new ::RTC::CORBA::PortServiceProxy(ref);
846 ::std::string str =
"test_notify_disconnect";
847 CPPUNIT_ASSERT_EQUAL(0, logger.
countLog(
"notify_disconnect"));
848 CPPUNIT_ASSERT_EQUAL(0, logger.
countLog(str));
850 ret = ap->notify_disconnect(str);
851 CPPUNIT_ASSERT_EQUAL(1, logger.
countLog(
"notify_disconnect"));
852 CPPUNIT_ASSERT_EQUAL(1, logger.
countLog(str));
875 int main(
int argc,
char* argv[])
877 CppUnit::TextUi::TestRunner runner;
878 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
879 CppUnit::Outputter* outputter =
880 new CppUnit::TextOutputter(&runner.result(), std::cout);
881 runner.setOutputter(outputter);
886 #endif // PortServiceProxy_cpp
int countLog(const std::string &msg)
virtual ::RTC::Local::ReturnCode_t disconnect(const ::std::string &connector_id)
int main(int argc, char **argv)
virtual const char * name()
Getting ORB's name.
virtual ::RTC::ReturnCode_t disconnect(const char *connector_id)
::RTC::PortProfile m_profile
~PortServiceProxyTests()
Destructor.
virtual ::RTC::ReturnCode_t notify_disconnect(const char *connector_id)
::RTC::ReturnCode_t notify_disconnect(const char *connector_id)
void test_notify_disconnect()
IPortService interface class.
virtual ::RTC::Local::ReturnCode_t connect(::RTC::Local::ConnectorProfile &connector_profile)
virtual ReturnCode_t registerFactory(const char *id, doil::ServantNewFunc new_func, doil::ServantDeleteFunc delete_func)
Register servant's factory.
virtual ::RTC::ConnectorProfile * get_connector_profile(const char *connector_id)
::RTC::ReturnCode_t disconnect(const char *connector_id)
static CORBAManager & instance()
getting instance
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
virtual ~PortServiceServantMock()
virtual void setUp()
Test initialization.
UniqueIdentifier connector_id
virtual ::RTC::ReturnCode_t connect(::RTC::ConnectorProfile &connector_profile)
virtual ::RTC::PortProfile * get_port_profile()
virtual ::RTC::Local::ReturnCode_t disconnect_all()
IPortService itnerface class.
::RTC::PortProfile * get_port_profile()
::RTC::ReturnCode_t disconnect_all()
virtual ::RTC::Local::PortProfile get_port_profile()
std::vector< ConnectorProfile * > ConnectorProfileList
void setLogger(Logger *logger)
virtual ::RTC::ConnectorProfileList * get_connector_profiles()
virtual ::RTC::ReturnCode_t disconnect_all()
PortServiceServantMock(doil::ImplBase *impl)
void test_disconnect_all()
virtual ::RTC::Local::ConnectorProfileList get_connector_profiles()
virtual ~IPortServiceMock()
CPPUNIT_TEST_SUITE_REGISTRATION(PortServiceProxy::PortServiceProxyTests)
PortableServer::POA_ptr m_pPOA
PortServiceProxyTests()
Constructor.
void test_notify_connect()
::RTC::ConnectorProfile * get_connector_profile(const char *connector_id)
void test_get_port_profile()
::RTC::ConnectorProfileList * get_connector_profiles()
::OutPortBase::Logger logger
virtual ::RTC::Local::ReturnCode_t notify_disconnect(const ::std::string &connector_id)
virtual ReturnCode_t deactivateObject(doil::ImplBase *impl)
Deactivate object.
std::vector< std::string > m_log
void test_get_connector_profile()
void log(const std::string &msg)
::RTC::ReturnCode_t notify_connect(::RTC::ConnectorProfile &connector_profile)
virtual ::RTC::ReturnCode_t notify_connect(::RTC::ConnectorProfile &connector_profile)
void test_get_connector_profiles()
std::vector< std::string > m_log
virtual ReturnCode_t activateObject(doil::ImplBase *impl)
Activate object.
::RTC::ReturnCode_t connect(::RTC::ConnectorProfile &connector_profile)
virtual void tearDown()
Test finalization.
::RTC::Local::IPortService * m_impl
virtual ~PortServiceRtmMock()
virtual ::RTC::Local::ReturnCode_t notify_connect(::RTC::Local::ConnectorProfile &connector_profile)
virtual ::RTC::Local::ConnectorProfile get_connector_profile(const ::std::string &connector_id)