00001
00012
00013
00014
00015
00016
00017
00018 #ifndef InPortBase_cpp
00019 #define InPortBase_cpp
00020
00021 #include <cppunit/ui/text/TestRunner.h>
00022 #include <cppunit/TextOutputter.h>
00023 #include <cppunit/extensions/TestFactoryRegistry.h>
00024 #include <cppunit/extensions/HelperMacros.h>
00025 #include <cppunit/TestAssert.h>
00026
00027 #include <rtm/idl/BasicDataTypeSkel.h>
00028 #include <rtm/idl/DataPortSkel.h>
00029 #include <rtm/RTC.h>
00030 #include <rtm/Typename.h>
00031 #include <rtm/InPortBase.h>
00032 #include <rtm/CdrBufferBase.h>
00033 #include <rtm/PortAdmin.h>
00034 #include <rtm/InPortConnector.h>
00035 #include <rtm/InPortProvider.h>
00036 #include <rtm/InPortConsumer.h>
00037 #include <rtm/OutPortProvider.h>
00038 #include <rtm/OutPortConsumer.h>
00039 #include <rtm/CorbaConsumer.h>
00040 #include <rtm/InPortPushConnector.h>
00041 #include <rtm/InPortProvider.h>
00042 #include <rtm/ConnectorListener.h>
00043 #include <rtm/OutPort.h>
00044 #include <rtm/OutPortBase.h>
00045 #include <rtm/InPortCorbaCdrProvider.h>
00046 #include <rtm/OutPortCorbaCdrConsumer.h>
00047
00048
00049 #define cdl_len 10
00050
00051 #define cl_len 7
00052
00053 namespace InPortBase
00054 {
00055
00056
00057 static const char* str_cdl[] =
00058 {
00059 "ON_BUFFER_WRITE",
00060 "ON_BUFFER_FULL",
00061 "ON_BUFFER_WRITE_TIMEOUT",
00062 "ON_BUFFER_OVERWRITE",
00063 "ON_BUFFER_READ",
00064 "ON_SEND",
00065 "ON_RECEIVED",
00066 "ON_RECEIVER_FULL",
00067 "ON_RECEIVER_TIMEOUT",
00068 "ON_RECEIVER_ERROR"
00069 };
00070
00071
00072 static const char* str_cl[] =
00073 {
00074 "ON_BUFFER_EMPTY",
00075 "ON_BUFFER_READ_TIMEOUT",
00076 "ON_SENDER_EMPTY",
00077 "ON_SENDER_TIMEOUT",
00078 "ON_SENDER_ERROR",
00079 "ON_CONNECT",
00080 "ON_DISCONNECT"
00081 };
00082
00083 static int cdl_count;
00084 static int cl_count;
00085
00086 class DataListener
00087 : public RTC::ConnectorDataListenerT<RTC::TimedLong>
00088 {
00089 public:
00090 DataListener(const char* name) : m_name(name)
00091 {
00092 ++cdl_count;
00093 }
00094 virtual ~DataListener()
00095 {
00096 --cdl_count;
00097 }
00098
00099 virtual void operator()(const RTC::ConnectorInfo& info,
00100 const RTC::TimedLong& data)
00101 {
00102 std::cout << "------------------------------" << std::endl;
00103 std::cout << "Data Listener: " << m_name << std::endl;
00104 std::cout << "Profile::name: " << info.name << std::endl;
00105 std::cout << "------------------------------" << std::endl;
00106 };
00107 std::string m_name;
00108 };
00109
00110
00111 class ConnListener
00112 : public RTC::ConnectorListener
00113 {
00114 public:
00115 ConnListener(const char* name) : m_name(name)
00116 {
00117 ++cl_count;
00118 }
00119 virtual ~ConnListener()
00120 {
00121 --cl_count;
00122 }
00123
00124 virtual void operator()(const RTC::ConnectorInfo& info)
00125 {
00126 std::cout << "------------------------------" << std::endl;
00127 std::cout << "Connector Listener: " << m_name << std::endl;
00128 std::cout << "Profile::name: " << info.name << std::endl;
00129 std::cout << "------------------------------" << std::endl;
00130 };
00131 std::string m_name;
00132 };
00133
00139 class Logger
00140 {
00141 public:
00142 void log(const std::string& msg)
00143 {
00144 m_log.push_back(msg);
00145 }
00146
00147 int countLog(const std::string& msg)
00148 {
00149 int count = 0;
00150 for (int i = 0; i < (int) m_log.size(); ++i)
00151 {
00152 if (m_log[i] == msg) ++count;
00153 }
00154 return count;
00155 }
00156
00157 void clearLog(void)
00158 {
00159 m_log.clear();
00160 }
00161 private:
00162 std::vector<std::string> m_log;
00163 };
00164
00170 template <class DataType>
00171 class RingBufferMock
00172 : public RTC::BufferBase<DataType>
00173 {
00174 public:
00175 BUFFERSTATUS_ENUM
00176 RingBufferMock(long int length = 8)
00177 {
00178 m_logger = NULL;
00179 logger.log("RingBufferMock::Constructor");
00180 m_read_return_value = BUFFER_OK;
00181 }
00182 virtual ~RingBufferMock(void)
00183 {
00184 }
00185
00186
00191 void set_read_return_value(::RTC::BufferStatus::Enum value)
00192 {
00193 m_read_return_value = value;
00194 }
00199 virtual void init(const coil::Properties& prop)
00200 {
00201 }
00206 virtual size_t length(void) const
00207 {
00208 return 0;
00209 }
00214 virtual ReturnCode length(size_t n)
00215 {
00216 return ::RTC::BufferStatus::BUFFER_OK;
00217 }
00222 virtual ReturnCode reset()
00223 {
00224 return ::RTC::BufferStatus::BUFFER_OK;
00225 }
00230 virtual DataType* wptr(long int n = 0)
00231 {
00232 return &m_data;
00233 }
00238 virtual ReturnCode advanceWptr(long int n = 1)
00239 {
00240 return ::RTC::BufferStatus::BUFFER_OK;
00241 }
00246 virtual ReturnCode put(const DataType& value)
00247 {
00248 return ::RTC::BufferStatus::BUFFER_OK;
00249 }
00254 virtual ReturnCode write(const DataType& value,
00255 long int sec = -1, long int nsec = -1)
00256 {
00257 return ::RTC::BufferStatus::BUFFER_OK;
00258 }
00263 virtual size_t writable() const
00264 {
00265 return 0;
00266 }
00271 virtual bool full(void) const
00272 {
00273 return true;
00274 }
00279 virtual DataType* rptr(long int n = 0)
00280 {
00281 return &m_data;
00282 }
00287 virtual ReturnCode advanceRptr(long int n = 1)
00288 {
00289 return ::RTC::BufferStatus::BUFFER_OK;
00290 }
00295 virtual ReturnCode get(DataType& value)
00296 {
00297 return ::RTC::BufferStatus::BUFFER_OK;
00298 }
00303 virtual DataType& get()
00304 {
00305 return m_data;
00306 }
00311 virtual ReturnCode read(DataType& value,
00312 long int sec = -1, long int nsec = -1)
00313 {
00314 if (m_logger != NULL)
00315 {
00316 m_logger->log("RingBufferMock::read");
00317 }
00318 logger.log("RingBufferMock::read");
00319 return m_read_return_value;
00320 }
00325 virtual size_t readable() const
00326 {
00327 return 0;
00328 }
00333 virtual bool empty(void) const
00334 {
00335 return true;
00336 }
00341 void setLogger(Logger* logger)
00342 {
00343 m_logger = logger;
00344 }
00345
00346 static Logger logger;
00347 private:
00348 DataType m_data;
00349 std::vector<DataType> m_buffer;
00350 Logger* m_logger;
00351 ::RTC::BufferStatus::Enum m_read_return_value;
00352 };
00353
00354 template <class DataType>
00355 Logger RingBufferMock<DataType>::logger;
00356 typedef RingBufferMock<cdrMemoryStream> CdrRingBufferMock;
00357
00363 class InPortCorbaCdrProviderMock
00364 : public RTC::InPortProvider,
00365 public virtual POA_OpenRTM::InPortCdr,
00366 public virtual PortableServer::RefCountServantBase
00367 {
00368
00369 public:
00370 InPortCorbaCdrProviderMock(void)
00371 {
00372 m_logger = NULL;
00373
00374 setInterfaceType("corba_cdr");
00375
00376
00377 m_objref = this->_this();
00378
00379
00380 CORBA::ORB_ptr orb = ::RTC::Manager::instance().getORB();
00381 CORBA_SeqUtil::
00382 push_back(m_properties,
00383 NVUtil::newNV("dataport.corba_cdr.inport_ior",
00384 orb->object_to_string(m_objref.in())));
00385 CORBA_SeqUtil::
00386 push_back(m_properties,
00387 NVUtil::newNV("dataport.corba_cdr.inport_ref",
00388 m_objref));
00389 }
00390 virtual ~InPortCorbaCdrProviderMock(void)
00391 {
00392 PortableServer::ObjectId_var oid;
00393 oid = _default_POA()->servant_to_id(this);
00394 _default_POA()->deactivate_object(oid);
00395 }
00400 void setBuffer(RTC::BufferBase<cdrMemoryStream>* buffer)
00401 {
00402 if (m_logger != NULL)
00403 {
00404 m_logger->log("InPortCorbaCdrProviderMock::setBuffer");
00405 }
00406 }
00411 ::OpenRTM::PortStatus put(const ::OpenRTM::CdrData& data)
00412 throw (CORBA::SystemException)
00413 {
00414 return ::OpenRTM::PORT_OK;
00415 }
00420 void init(coil::Properties& prop)
00421 {
00422 if (m_logger != NULL)
00423 {
00424 m_logger->log("InPortCorbaCdrProviderMock::init");
00425 }
00426 }
00431 RTC::InPortConsumer::ReturnCode put(const cdrMemoryStream& data)
00432 {
00433 return PORT_OK;
00434 }
00439 void publishInterfaceProfile(SDOPackage::NVList& properties)
00440 {
00441 return;
00442 }
00443
00448 bool subscribeInterface(const SDOPackage::NVList& properties)
00449 {
00450
00451 return true;;
00452 }
00453
00458 void unsubscribeInterface(const SDOPackage::NVList& properties)
00459 {
00460 }
00461
00462
00467
00468
00469
00470
00471
00472
00477 void setLogger(Logger* logger)
00478 {
00479 m_logger = logger;
00480 }
00481
00482 void setListener(RTC::ConnectorInfo& info,
00483 RTC::ConnectorListeners* listeners)
00484 {
00485
00486
00487 }
00488 void setConnector(RTC::InPortConnector* connector)
00489 {
00490
00491 }
00492
00493 private:
00494 Logger* m_logger;
00495 ::OpenRTM::InPortCdr_var m_objref;
00496
00497 };
00498
00504 class OutPortCorbaCdrConsumerMock
00505 : public RTC::OutPortConsumer,
00506 public RTC::CorbaConsumer< ::OpenRTM::OutPortCdr >
00507 {
00508
00509 public:
00510 OutPortCorbaCdrConsumerMock(void)
00511 {
00512 m_logger = NULL;
00513 }
00514 virtual ~OutPortCorbaCdrConsumerMock(void)
00515 {
00516 }
00521 void setBuffer(RTC::BufferBase<cdrMemoryStream>* buffer)
00522 {
00523 if (m_logger != NULL)
00524 {
00525 m_logger->log("OutPortCorbaCdrConsumerMock::setBuffer");
00526 }
00527 }
00532 ::OpenRTM::PortStatus put(const ::OpenRTM::CdrData& data)
00533 throw (CORBA::SystemException)
00534 {
00535 return ::OpenRTM::PORT_OK;
00536 }
00541 void init(coil::Properties& prop)
00542 {
00543 if (m_logger != NULL)
00544 {
00545 m_logger->log("OutPortCorbaCdrConsumerMock::init");
00546 }
00547 }
00552 RTC::OutPortConsumer::ReturnCode put(const cdrMemoryStream& data)
00553 {
00554 return PORT_OK;
00555 }
00560 void publishInterfaceProfile(SDOPackage::NVList& properties)
00561 {
00562 return;
00563 }
00564
00569 bool subscribeInterface(const SDOPackage::NVList& properties)
00570 {
00571
00572 return true;;
00573 }
00574
00579 void unsubscribeInterface(const SDOPackage::NVList& properties)
00580 {
00581 }
00586 virtual ReturnCode get(cdrMemoryStream& data)
00587 {
00588 return PORT_OK;
00589 }
00590
00591 void setListener(RTC::ConnectorInfo& info,
00592 RTC::ConnectorListeners* listeners)
00593 {
00594
00595
00596 }
00597
00602 void setLogger(Logger* logger)
00603 {
00604 m_logger = logger;
00605 }
00606 private:
00607 Logger* m_logger;
00608
00609 };
00610
00615 class InPortBaseMock
00616 : public RTC::InPortBase
00617 {
00618 public:
00623 InPortBaseMock(const char* name, const char* data_type)
00624 : RTC::InPortBase(name , data_type)
00625 {
00626 rtclog.setLevel("PARANOID");
00627 }
00632 virtual ~InPortBaseMock()
00633 {
00634 }
00639 RTC::CdrBufferBase* getThebuffer()
00640 {
00641 return m_thebuffer;
00642 }
00647 coil::vstring getProviderTypes()
00648 {
00649 return m_providerTypes;
00650 }
00655 coil::vstring get_m_consumerTypes()
00656 {
00657 return m_consumerTypes;
00658 }
00663 void initConsumers_public()
00664 {
00665 initConsumers();
00666 }
00671 void initProviders_public()
00672 {
00673 initProviders();
00674 }
00679 void setSinglebuffer()
00680 {
00681 m_singlebuffer = true;
00682 }
00687 void setMultibuffer()
00688 {
00689 m_singlebuffer = false;
00690 }
00695 ConnectorList get_m_connectors()
00696 {
00697 return m_connectors;
00698 }
00703 virtual RTC::ReturnCode_t publishInterfaces_public(RTC::ConnectorProfile& connector_profile)
00704 {
00705 RTC::ReturnCode_t ret = RTC::InPortBase::publishInterfaces(connector_profile);
00706 return ret;
00707 }
00712 virtual RTC::ReturnCode_t subscribeInterfaces_public(RTC::ConnectorProfile& connector_profile)
00713 {
00714 RTC::ReturnCode_t ret = RTC::InPortBase::subscribeInterfaces(connector_profile);
00715 return ret;
00716 }
00721 RTC::InPortConnector*
00722 createConnector_public(RTC::ConnectorProfile& cprof,
00723 coil::Properties& prop,
00724 RTC::InPortProvider* provider)
00725 {
00726 return RTC::InPortBase::createConnector(cprof, prop, provider);
00727 }
00732 RTC::InPortProvider* createProvider_public(RTC::ConnectorProfile& cprof,
00733 coil::Properties& prop)
00734 {
00735 return RTC::InPortBase::createProvider(cprof, prop);
00736 }
00741 coil::Properties get_m_properties()
00742 {
00743 return m_properties;
00744 }
00749 void init(coil::Properties& prop)
00750 {
00751 RTC::InPortBase::init(prop);
00752 }
00756 bool read()
00757 {
00758 return true;
00759 }
00760 };
00761
00762 template <class DataType>
00763 class OutPortMock
00764 : public RTC::OutPort<DataType>
00765 {
00766 public:
00767 OutPortMock(const char* name, DataType& value)
00768 : RTC::OutPort<DataType>(name, value)
00769 {
00770 }
00771
00772 virtual ~OutPortMock()
00773 {
00774 }
00775 };
00776
00777 class InPortBaseTests
00778 : public CppUnit::TestFixture
00779 {
00780 CPPUNIT_TEST_SUITE(InPortBaseTests);
00781
00782 CPPUNIT_TEST(test_constructor);
00783 CPPUNIT_TEST(test_init);
00784 CPPUNIT_TEST(test_init2);
00785 CPPUNIT_TEST(test_init3);
00786 CPPUNIT_TEST(test_initProviders);
00787 CPPUNIT_TEST(test_initProviders2);
00788 CPPUNIT_TEST(test_initConsumers);
00789 CPPUNIT_TEST(test_initConsumers2);
00790 CPPUNIT_TEST(test_activateInterfaces_deactivateInterfaces);
00791 CPPUNIT_TEST(test_publishInterfaces);
00792 CPPUNIT_TEST(test_publishInterfaces2);
00793 CPPUNIT_TEST(test_publishInterfaces3);
00794 CPPUNIT_TEST(test_publishInterfaces4);
00795 CPPUNIT_TEST(test_publishInterfaces5);
00796 CPPUNIT_TEST(test_subscribeInterfaces);
00797 CPPUNIT_TEST(test_subscribeInterfaces2);
00798 CPPUNIT_TEST(test_subscribeInterfaces3);
00799 CPPUNIT_TEST(test_subscribeInterfaces4);
00800 CPPUNIT_TEST(test_subscribeInterfaces5);
00801 CPPUNIT_TEST(test_createConnector);
00802 CPPUNIT_TEST(test_createConnector2);
00803 CPPUNIT_TEST(test_ConnectorListener);
00804
00805 CPPUNIT_TEST_SUITE_END();
00806
00807 private:
00808 CORBA::ORB_ptr m_pORB;
00809 PortableServer::POA_ptr m_pPOA;
00810 RTC::ConnectorListeners m_listeners;
00811 DataListener *m_datalisteners[cdl_len];
00812 ConnListener *m_connlisteners[cl_len];
00813
00814 public:
00815
00819 InPortBaseTests()
00820 {
00821 int argc(0);
00822 char** argv(NULL);
00823 m_pORB = CORBA::ORB_init(argc, argv);
00824 m_pPOA = PortableServer::POA::_narrow(
00825 m_pORB->resolve_initial_references("RootPOA"));
00826 m_pPOA->the_POAManager()->activate();
00827 }
00828
00832 ~InPortBaseTests()
00833 {
00834 }
00835
00839 virtual void setUp()
00840 {
00841
00842 if( RTC::InPortProviderFactory::instance().hasFactory("corba_cdr") )
00843 {
00844 RTC::InPortProviderFactory::instance().removeFactory("corba_cdr");
00845 }
00846
00847 RTC::InPortProviderFactory::instance().
00848 addFactory("corba_cdr",
00849 ::coil::Creator< ::RTC::InPortProvider,
00850 InPortCorbaCdrProviderMock>,
00851 ::coil::Destructor< ::RTC::InPortProvider,
00852 InPortCorbaCdrProviderMock>);
00853
00854
00855 if( RTC::OutPortConsumerFactory::instance().hasFactory("corba_cdr") )
00856 {
00857 RTC::OutPortConsumerFactory::instance().removeFactory("corba_cdr");
00858 }
00859
00860 RTC::OutPortConsumerFactory::instance().
00861 addFactory("corba_cdr",
00862 ::coil::Creator< ::RTC::OutPortConsumer,
00863 OutPortCorbaCdrConsumerMock>,
00864 ::coil::Destructor< ::RTC::OutPortConsumer,
00865 OutPortCorbaCdrConsumerMock>);
00866
00867
00868 if( RTC::CdrBufferFactory::instance().hasFactory("ring_buffer") )
00869 {
00870 RTC::CdrBufferFactory::instance().removeFactory("ring_buffer");
00871 }
00872
00873 RTC::CdrBufferFactory::instance().
00874 addFactory("ring_buffer",
00875 coil::Creator<RTC::CdrBufferBase, CdrRingBufferMock>,
00876 coil::Destructor<RTC::CdrBufferBase, CdrRingBufferMock>);
00877 }
00878
00882 virtual void tearDown()
00883 {
00884 }
00885
00890 void test_constructor()
00891 {
00892 InPortBaseMock inport("InPortBaseTest", toTypename<RTC::TimedFloat>());
00893
00894 RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
00895 portAdmin.registerPort(inport);
00896
00897 RTC::PortProfile profile = inport.getPortProfile();
00898 coil::Properties prop = NVUtil::toProperties(profile.properties);
00899 CPPUNIT_ASSERT_EQUAL(std::string("DataInPort"), prop["port.port_type"] );
00900 CPPUNIT_ASSERT_EQUAL(std::string(toTypename<RTC::TimedFloat>()),
00901 prop["dataport.data_type"] );
00902 CPPUNIT_ASSERT_EQUAL(std::string("Any"),
00903 prop["dataport.subscription_type"]);
00904
00905 portAdmin.deletePort(inport);
00906
00907
00908 }
00913 void test_init()
00914 {
00915
00916
00917
00918
00919
00920
00921
00922
00923 if( RTC::InPortProviderFactory::instance().hasFactory("corba_cdr") )
00924 {
00925 RTC::InPortProviderFactory::instance().removeFactory("corba_cdr");
00926 }
00927
00928 RTC::InPortProviderFactory::instance().
00929 addFactory("corba_cdr",
00930 ::coil::Creator< ::RTC::InPortProvider,
00931 InPortCorbaCdrProviderMock>,
00932 ::coil::Destructor< ::RTC::InPortProvider,
00933 InPortCorbaCdrProviderMock>);
00934
00935
00936 if( RTC::OutPortConsumerFactory::instance().hasFactory("corba_cdr") )
00937 {
00938 RTC::OutPortConsumerFactory::instance().removeFactory("corba_cdr");
00939 }
00940
00941 RTC::OutPortConsumerFactory::instance().
00942 addFactory("corba_cdr",
00943 ::coil::Creator< ::RTC::OutPortConsumer,
00944 OutPortCorbaCdrConsumerMock>,
00945 ::coil::Destructor< ::RTC::OutPortConsumer,
00946 OutPortCorbaCdrConsumerMock>);
00947
00948
00949 if( RTC::CdrBufferFactory::instance().hasFactory("ring_buffer") )
00950 {
00951 RTC::CdrBufferFactory::instance().removeFactory("ring_buffer");
00952 }
00953
00954
00955 RTC::CdrBufferFactory::instance().
00956 addFactory("ring_buffer",
00957 coil::Creator<RTC::CdrBufferBase, CdrRingBufferMock>,
00958 coil::Destructor<RTC::CdrBufferBase, CdrRingBufferMock>);
00959
00960
00961 InPortBaseMock inport("InPortBaseTest", toTypename<RTC::TimedFloat>());
00962
00963 RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
00964 portAdmin.registerPort(inport);
00965
00966 CPPUNIT_ASSERT(0==inport.getThebuffer());
00967 RTC::PortProfile profile = inport.getPortProfile();
00968 coil::Properties prop = NVUtil::toProperties(profile.properties);
00969 CPPUNIT_ASSERT_EQUAL(std::string(""),
00970 prop["dataport.dataflow_type"]);
00971 CPPUNIT_ASSERT_EQUAL(std::string(""),
00972 prop["dataport.interface_type"]);
00973
00974 coil::vstring pstr = inport.getProviderTypes();
00975 CPPUNIT_ASSERT_EQUAL((size_t)0, pstr.size());
00976 coil::vstring cstr = inport.get_m_consumerTypes();
00977 CPPUNIT_ASSERT_EQUAL((size_t)0, cstr.size());
00978 CdrRingBufferMock::logger.clearLog();
00979 CPPUNIT_ASSERT_EQUAL(0,
00980 CdrRingBufferMock::logger.countLog("RingBufferMock::Constructor"));
00981
00982 coil::Properties dummy;
00983 inport.init(dummy);
00984
00985
00986 CPPUNIT_ASSERT(0!=inport.getThebuffer());
00987 CPPUNIT_ASSERT_EQUAL(1,
00988 CdrRingBufferMock::logger.countLog("RingBufferMock::Constructor"));
00989
00990 profile = inport.getPortProfile();
00991 prop = NVUtil::toProperties(profile.properties);
00992
00993
00994 CPPUNIT_ASSERT_EQUAL(std::string("push,pull"),
00995 prop["dataport.dataflow_type"]);
00996 CPPUNIT_ASSERT_EQUAL(std::string("corba_cdr"),
00997 prop["dataport.interface_type"]);
00998
00999
01000 pstr = inport.getProviderTypes();
01001 CPPUNIT_ASSERT_EQUAL(std::string("corba_cdr"),
01002 pstr[0]);
01003 cstr = inport.get_m_consumerTypes();
01004 CPPUNIT_ASSERT_EQUAL(std::string("corba_cdr"),
01005 cstr[0]);
01006
01007 portAdmin.deletePort(inport);
01008 }
01013 void test_init2()
01014 {
01015
01016
01017
01018
01019
01020
01021
01022
01023 if( RTC::InPortProviderFactory::instance().hasFactory("corba_cdr") )
01024 {
01025 RTC::InPortProviderFactory::instance().removeFactory("corba_cdr");
01026 }
01027
01028 RTC::InPortProviderFactory::instance().
01029 addFactory("corba_cdr",
01030 ::coil::Creator< ::RTC::InPortProvider,
01031 InPortCorbaCdrProviderMock>,
01032 ::coil::Destructor< ::RTC::InPortProvider,
01033 InPortCorbaCdrProviderMock>);
01034
01035
01036 if( RTC::OutPortConsumerFactory::instance().hasFactory("corba_cdr") )
01037 {
01038 RTC::OutPortConsumerFactory::instance().removeFactory("corba_cdr");
01039 }
01040
01041 RTC::OutPortConsumerFactory::instance().
01042 addFactory("corba_cdr",
01043 ::coil::Creator< ::RTC::OutPortConsumer,
01044 OutPortCorbaCdrConsumerMock>,
01045 ::coil::Destructor< ::RTC::OutPortConsumer,
01046 OutPortCorbaCdrConsumerMock>);
01047
01048
01049 if( RTC::CdrBufferFactory::instance().hasFactory("ring_buffer") )
01050 {
01051 RTC::CdrBufferFactory::instance().removeFactory("ring_buffer");
01052 }
01053
01054 RTC::CdrBufferFactory::instance().
01055 addFactory("ring_buffer",
01056 coil::Creator<RTC::CdrBufferBase, CdrRingBufferMock>,
01057 coil::Destructor<RTC::CdrBufferBase, CdrRingBufferMock>);
01058 InPortBaseMock inport("InPortBaseTest", toTypename<RTC::TimedFloat>());
01059
01060 RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
01061 portAdmin.registerPort(inport);
01062
01063 CPPUNIT_ASSERT(0==inport.getThebuffer());
01064 RTC::PortProfile profile = inport.getPortProfile();
01065 coil::Properties prop = NVUtil::toProperties(profile.properties);
01066 CPPUNIT_ASSERT_EQUAL(std::string(""),
01067 prop["dataport.dataflow_type"]);
01068 CPPUNIT_ASSERT_EQUAL(std::string(""),
01069 prop["dataport.interface_type"]);
01070
01071 coil::vstring pstr = inport.getProviderTypes();
01072 CPPUNIT_ASSERT_EQUAL((size_t)0, pstr.size());
01073 coil::vstring cstr = inport.get_m_consumerTypes();
01074 CPPUNIT_ASSERT_EQUAL((size_t)0, cstr.size());
01075 CdrRingBufferMock::logger.clearLog();
01076 CPPUNIT_ASSERT_EQUAL(0,
01077 CdrRingBufferMock::logger.countLog("RingBufferMock::Constructor"));
01078
01079 inport.setMultibuffer();
01080 coil::Properties dummy;
01081 inport.init(dummy);
01082
01083 CPPUNIT_ASSERT(0==inport.getThebuffer());
01084 CPPUNIT_ASSERT_EQUAL(0,
01085 CdrRingBufferMock::logger.countLog("RingBufferMock::Constructor"));
01086
01087 profile = inport.getPortProfile();
01088 prop = NVUtil::toProperties(profile.properties);
01089
01090
01091 CPPUNIT_ASSERT_EQUAL(std::string("push,pull"),
01092 prop["dataport.dataflow_type"]);
01093 CPPUNIT_ASSERT_EQUAL(std::string("corba_cdr"),
01094 prop["dataport.interface_type"]);
01095
01096
01097 pstr = inport.getProviderTypes();
01098 CPPUNIT_ASSERT_EQUAL(std::string("corba_cdr"),
01099 pstr[0]);
01100 cstr = inport.get_m_consumerTypes();
01101 CPPUNIT_ASSERT_EQUAL(std::string("corba_cdr"),
01102 cstr[0]);
01103
01104 portAdmin.deletePort(inport);
01105 }
01110 void test_init3()
01111 {
01112
01113
01114
01115
01116
01117
01118
01119
01120 if( RTC::InPortProviderFactory::instance().hasFactory("corba_cdr") )
01121 {
01122 RTC::InPortProviderFactory::instance().removeFactory("corba_cdr");
01123 }
01124
01125 RTC::InPortProviderFactory::instance().
01126 addFactory("corba_cdr",
01127 ::coil::Creator< ::RTC::InPortProvider,
01128 InPortCorbaCdrProviderMock>,
01129 ::coil::Destructor< ::RTC::InPortProvider,
01130 InPortCorbaCdrProviderMock>);
01131
01132
01133 if( RTC::OutPortConsumerFactory::instance().hasFactory("corba_cdr") )
01134 {
01135 RTC::OutPortConsumerFactory::instance().removeFactory("corba_cdr");
01136 }
01137
01138 RTC::OutPortConsumerFactory::instance().
01139 addFactory("corba_cdr",
01140 ::coil::Creator< ::RTC::OutPortConsumer,
01141 OutPortCorbaCdrConsumerMock>,
01142 ::coil::Destructor< ::RTC::OutPortConsumer,
01143 OutPortCorbaCdrConsumerMock>);
01144
01145
01146 if( RTC::CdrBufferFactory::instance().hasFactory("ring_buffer") )
01147 {
01148 RTC::CdrBufferFactory::instance().removeFactory("ring_buffer");
01149 }
01150
01151 InPortBaseMock inport("InPortBaseTest", toTypename<RTC::TimedFloat>());
01152
01153 RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
01154 portAdmin.registerPort(inport);
01155
01156 CPPUNIT_ASSERT(0==inport.getThebuffer());
01157 RTC::PortProfile profile = inport.getPortProfile();
01158 coil::Properties prop = NVUtil::toProperties(profile.properties);
01159 CPPUNIT_ASSERT_EQUAL(std::string(""),
01160 prop["dataport.dataflow_type"]);
01161 CPPUNIT_ASSERT_EQUAL(std::string(""),
01162 prop["dataport.interface_type"]);
01163
01164 coil::vstring pstr = inport.getProviderTypes();
01165 CPPUNIT_ASSERT_EQUAL((size_t)0, pstr.size());
01166 coil::vstring cstr = inport.get_m_consumerTypes();
01167 CPPUNIT_ASSERT_EQUAL((size_t)0, cstr.size());
01168 CdrRingBufferMock::logger.clearLog();
01169 CPPUNIT_ASSERT_EQUAL(0,
01170 CdrRingBufferMock::logger.countLog("RingBufferMock::Constructor"));
01171
01172 coil::Properties dummy;
01173 inport.init(dummy);
01174
01175
01176 CPPUNIT_ASSERT(0==inport.getThebuffer());
01177 CPPUNIT_ASSERT_EQUAL(0,
01178 CdrRingBufferMock::logger.countLog("RingBufferMock::Constructor"));
01179
01180 profile = inport.getPortProfile();
01181 prop = NVUtil::toProperties(profile.properties);
01182
01183
01184 CPPUNIT_ASSERT_EQUAL(std::string("push,pull"),
01185 prop["dataport.dataflow_type"]);
01186 CPPUNIT_ASSERT_EQUAL(std::string("corba_cdr"),
01187 prop["dataport.interface_type"]);
01188
01189
01190 pstr = inport.getProviderTypes();
01191 CPPUNIT_ASSERT_EQUAL(std::string("corba_cdr"),
01192 pstr[0]);
01193 cstr = inport.get_m_consumerTypes();
01194 CPPUNIT_ASSERT_EQUAL(std::string("corba_cdr"),
01195 cstr[0]);
01196
01197
01198 portAdmin.deletePort(inport);
01199 }
01204 void test_initProviders()
01205 {
01206
01207 if( RTC::InPortProviderFactory::instance().hasFactory("corba_cdr") )
01208 {
01209 RTC::InPortProviderFactory::instance().removeFactory("corba_cdr");
01210 }
01211
01212 RTC::InPortProviderFactory::instance().
01213 addFactory("corba_cdr",
01214 ::coil::Creator< ::RTC::InPortProvider,
01215 InPortCorbaCdrProviderMock>,
01216 ::coil::Destructor< ::RTC::InPortProvider,
01217 InPortCorbaCdrProviderMock>);
01218
01219
01220 if( RTC::CdrBufferFactory::instance().hasFactory("ring_buffer") )
01221 {
01222 RTC::CdrBufferFactory::instance().removeFactory("ring_buffer");
01223 }
01224
01225
01226 if( RTC::OutPortConsumerFactory::instance().hasFactory("corba_cdr") )
01227 {
01228 RTC::OutPortConsumerFactory::instance().removeFactory("corba_cdr");
01229 }
01230
01231 RTC::OutPortConsumerFactory::instance().
01232 addFactory("corba_cdr",
01233 ::coil::Creator< ::RTC::OutPortConsumer,
01234 OutPortCorbaCdrConsumerMock>,
01235 ::coil::Destructor< ::RTC::OutPortConsumer,
01236 OutPortCorbaCdrConsumerMock>);
01237
01238
01239 RTC::CdrBufferFactory::instance().
01240 addFactory("ring_buffer",
01241 coil::Creator<RTC::CdrBufferBase, CdrRingBufferMock>,
01242 coil::Destructor<RTC::CdrBufferBase, CdrRingBufferMock>);
01243
01244
01245 InPortBaseMock inport("InPortBaseTest", toTypename<RTC::TimedFloat>());
01246
01247 RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
01248 portAdmin.registerPort(inport);
01249
01250 RTC::PortProfile profile = inport.getPortProfile();
01251 coil::Properties prop = NVUtil::toProperties(profile.properties);
01252 CPPUNIT_ASSERT_EQUAL(std::string(""),
01253 prop["dataport.dataflow_type"]);
01254 CPPUNIT_ASSERT_EQUAL(std::string(""),
01255 prop["dataport.interface_type"]);
01256
01257 coil::vstring pstr = inport.getProviderTypes();
01258 CPPUNIT_ASSERT_EQUAL((size_t)0, pstr.size());
01259 inport.initProviders_public();
01260
01261
01262 profile = inport.getPortProfile();
01263 prop = NVUtil::toProperties(profile.properties);
01264
01265
01266 CPPUNIT_ASSERT_EQUAL(std::string("push"),
01267 prop["dataport.dataflow_type"]);
01268 CPPUNIT_ASSERT_EQUAL(std::string("corba_cdr"),
01269 prop["dataport.interface_type"]);
01270
01271
01272 pstr = inport.getProviderTypes();
01273 CPPUNIT_ASSERT((size_t)0!= pstr.size());
01274 CPPUNIT_ASSERT_EQUAL(std::string("corba_cdr"),
01275 pstr[0]);
01276
01277 portAdmin.deletePort(inport);
01278 }
01284 void test_initProviders2()
01285 {
01286
01287 if( RTC::InPortProviderFactory::instance().hasFactory("corba_cdr") )
01288 {
01289 RTC::InPortProviderFactory::instance().removeFactory("corba_cdr");
01290 }
01291
01292
01293 if( RTC::OutPortConsumerFactory::instance().hasFactory("corba_cdr") )
01294 {
01295 RTC::OutPortConsumerFactory::instance().removeFactory("corba_cdr");
01296 }
01297
01298 RTC::OutPortConsumerFactory::instance().
01299 addFactory("corba_cdr",
01300 ::coil::Creator< ::RTC::OutPortConsumer,
01301 OutPortCorbaCdrConsumerMock>,
01302 ::coil::Destructor< ::RTC::OutPortConsumer,
01303 OutPortCorbaCdrConsumerMock>);
01304
01305
01306 if( RTC::CdrBufferFactory::instance().hasFactory("ring_buffer") )
01307 {
01308 RTC::CdrBufferFactory::instance().removeFactory("ring_buffer");
01309 }
01310
01311 RTC::CdrBufferFactory::instance().
01312 addFactory("ring_buffer",
01313 coil::Creator<RTC::CdrBufferBase, CdrRingBufferMock>,
01314 coil::Destructor<RTC::CdrBufferBase, CdrRingBufferMock>);
01315
01316
01317 InPortBaseMock inport("InPortBaseTest", toTypename<RTC::TimedFloat>());
01318
01319 RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
01320 portAdmin.registerPort(inport);
01321
01322 RTC::PortProfile profile = inport.getPortProfile();
01323 coil::Properties prop = NVUtil::toProperties(profile.properties);
01324 CPPUNIT_ASSERT_EQUAL(std::string(""),
01325 prop["dataport.dataflow_type"]);
01326 CPPUNIT_ASSERT_EQUAL(std::string(""),
01327 prop["dataport.interface_type"]);
01328
01329 coil::vstring pstr = inport.getProviderTypes();
01330 CPPUNIT_ASSERT_EQUAL((size_t)0, pstr.size());
01331 inport.initProviders_public();
01332
01333
01334 profile = inport.getPortProfile();
01335 prop = NVUtil::toProperties(profile.properties);
01336
01337
01338 CPPUNIT_ASSERT_EQUAL(std::string(""),
01339 prop["dataport.dataflow_type"]);
01340 CPPUNIT_ASSERT_EQUAL(std::string(""),
01341 prop["dataport.interface_type"]);
01342
01343
01344 pstr = inport.getProviderTypes();
01345 CPPUNIT_ASSERT((size_t)0== pstr.size());
01346
01347 portAdmin.deletePort(inport);
01348 }
01353 void test_initConsumers()
01354 {
01355
01356 if( RTC::InPortProviderFactory::instance().hasFactory("corba_cdr") )
01357 {
01358 RTC::InPortProviderFactory::instance().removeFactory("corba_cdr");
01359 }
01360
01361 RTC::InPortProviderFactory::instance().
01362 addFactory("corba_cdr",
01363 ::coil::Creator< ::RTC::InPortProvider,
01364 InPortCorbaCdrProviderMock>,
01365 ::coil::Destructor< ::RTC::InPortProvider,
01366 InPortCorbaCdrProviderMock>);
01367
01368
01369 if( RTC::OutPortConsumerFactory::instance().hasFactory("corba_cdr") )
01370 {
01371 RTC::OutPortConsumerFactory::instance().removeFactory("corba_cdr");
01372 }
01373
01374 RTC::OutPortConsumerFactory::instance().
01375 addFactory("corba_cdr",
01376 ::coil::Creator< ::RTC::OutPortConsumer,
01377 OutPortCorbaCdrConsumerMock>,
01378 ::coil::Destructor< ::RTC::OutPortConsumer,
01379 OutPortCorbaCdrConsumerMock>);
01380
01381
01382 if( RTC::CdrBufferFactory::instance().hasFactory("ring_buffer") )
01383 {
01384 RTC::CdrBufferFactory::instance().removeFactory("ring_buffer");
01385 }
01386
01387 RTC::CdrBufferFactory::instance().
01388 addFactory("ring_buffer",
01389 coil::Creator<RTC::CdrBufferBase, CdrRingBufferMock>,
01390 coil::Destructor<RTC::CdrBufferBase, CdrRingBufferMock>);
01391
01392 InPortBaseMock inport("InPortBaseTest", toTypename<RTC::TimedFloat>());
01393
01394 RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
01395 portAdmin.registerPort(inport);
01396
01397 RTC::PortProfile profile = inport.getPortProfile();
01398 coil::Properties prop = NVUtil::toProperties(profile.properties);
01399 CPPUNIT_ASSERT_EQUAL(std::string(""),
01400 prop["dataport.dataflow_type"]);
01401 CPPUNIT_ASSERT_EQUAL(std::string(""),
01402 prop["dataport.interface_type"]);
01403
01404 coil::vstring cstr = inport.get_m_consumerTypes();
01405 CPPUNIT_ASSERT_EQUAL((size_t)0, cstr.size());
01406
01407 inport.initConsumers_public();
01408
01409 profile = inport.getPortProfile();
01410 prop = NVUtil::toProperties(profile.properties);
01411
01412
01413 CPPUNIT_ASSERT_EQUAL(std::string("pull"),
01414 prop["dataport.dataflow_type"]);
01415 CPPUNIT_ASSERT_EQUAL(std::string("corba_cdr"),
01416 prop["dataport.interface_type"]);
01417
01418
01419 cstr = inport.get_m_consumerTypes();
01420 CPPUNIT_ASSERT((size_t)0!= cstr.size());
01421 CPPUNIT_ASSERT_EQUAL(std::string("corba_cdr"),
01422 cstr[0]);
01423
01424 portAdmin.deletePort(inport);
01425
01426 }
01431 void test_initConsumers2()
01432 {
01433
01434 if( RTC::InPortProviderFactory::instance().hasFactory("corba_cdr") )
01435 {
01436 RTC::InPortProviderFactory::instance().removeFactory("corba_cdr");
01437 }
01438
01439 RTC::InPortProviderFactory::instance().
01440 addFactory("corba_cdr",
01441 ::coil::Creator< ::RTC::InPortProvider,
01442 InPortCorbaCdrProviderMock>,
01443 ::coil::Destructor< ::RTC::InPortProvider,
01444 InPortCorbaCdrProviderMock>);
01445
01446
01447 if( RTC::OutPortConsumerFactory::instance().hasFactory("corba_cdr") )
01448 {
01449 RTC::OutPortConsumerFactory::instance().removeFactory("corba_cdr");
01450 }
01451
01452
01453 if( RTC::CdrBufferFactory::instance().hasFactory("ring_buffer") )
01454 {
01455 RTC::CdrBufferFactory::instance().removeFactory("ring_buffer");
01456 }
01457
01458 RTC::CdrBufferFactory::instance().
01459 addFactory("ring_buffer",
01460 coil::Creator<RTC::CdrBufferBase, CdrRingBufferMock>,
01461 coil::Destructor<RTC::CdrBufferBase, CdrRingBufferMock>);
01462
01463 InPortBaseMock inport("InPortBaseTest", toTypename<RTC::TimedFloat>());
01464
01465 RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
01466 portAdmin.registerPort(inport);
01467
01468 RTC::PortProfile profile = inport.getPortProfile();
01469 coil::Properties prop = NVUtil::toProperties(profile.properties);
01470 CPPUNIT_ASSERT_EQUAL(std::string(""),
01471 prop["dataport.dataflow_type"]);
01472 CPPUNIT_ASSERT_EQUAL(std::string(""),
01473 prop["dataport.interface_type"]);
01474
01475 coil::vstring cstr = inport.get_m_consumerTypes();
01476 CPPUNIT_ASSERT_EQUAL((size_t)0, cstr.size());
01477
01478 inport.initConsumers_public();
01479
01480 profile = inport.getPortProfile();
01481 prop = NVUtil::toProperties(profile.properties);
01482
01483
01484 CPPUNIT_ASSERT_EQUAL(std::string(""),
01485 prop["dataport.dataflow_type"]);
01486 CPPUNIT_ASSERT_EQUAL(std::string(""),
01487 prop["dataport.interface_type"]);
01488
01489
01490 cstr = inport.get_m_consumerTypes();
01491 CPPUNIT_ASSERT((size_t)0== cstr.size());
01492
01493 portAdmin.deletePort(inport);
01494
01495 }
01500 void test_activateInterfaces_deactivateInterfaces(void)
01501 {
01502
01503 if( RTC::InPortProviderFactory::instance().hasFactory("corba_cdr") )
01504 {
01505 RTC::InPortProviderFactory::instance().removeFactory("corba_cdr");
01506 }
01507
01508 RTC::InPortProviderFactory::instance().
01509 addFactory("corba_cdr",
01510 ::coil::Creator< ::RTC::InPortProvider,
01511 InPortCorbaCdrProviderMock>,
01512 ::coil::Destructor< ::RTC::InPortProvider,
01513 InPortCorbaCdrProviderMock>);
01514
01515
01516 if( RTC::OutPortConsumerFactory::instance().hasFactory("corba_cdr") )
01517 {
01518 RTC::OutPortConsumerFactory::instance().removeFactory("corba_cdr");
01519 }
01520
01521 RTC::OutPortConsumerFactory::instance().
01522 addFactory("corba_cdr",
01523 ::coil::Creator< ::RTC::OutPortConsumer,
01524 OutPortCorbaCdrConsumerMock>,
01525 ::coil::Destructor< ::RTC::OutPortConsumer,
01526 OutPortCorbaCdrConsumerMock>);
01527
01528
01529 if( RTC::CdrBufferFactory::instance().hasFactory("ring_buffer") )
01530 {
01531 RTC::CdrBufferFactory::instance().removeFactory("ring_buffer");
01532 }
01533
01534
01535 RTC::CdrBufferFactory::instance().
01536 addFactory("ring_buffer",
01537 coil::Creator<RTC::CdrBufferBase, CdrRingBufferMock>,
01538 coil::Destructor<RTC::CdrBufferBase, CdrRingBufferMock>);
01539
01540 InPortBaseMock inport("InPortBaseTest", toTypename<RTC::TimedFloat>());
01541 coil::Properties dummy;
01542 inport.init(dummy);
01543
01544 RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
01545 portAdmin.registerPort(inport);
01546 RTC::ConnectorProfile prof;
01547 prof.connector_id = "id0";
01548 prof.name = CORBA::string_dup("InPortBaseTest0");
01549 prof.ports.length(1);
01550 prof.ports[0] = inport.get_port_profile()->port_ref;
01551 CORBA_SeqUtil::push_back(prof.properties,
01552 NVUtil::newNV("dataport.interface_type",
01553 "corba_cdr"));
01554 CORBA_SeqUtil::push_back(prof.properties,
01555 NVUtil::newNV("dataport.dataflow_type",
01556 "push"));
01557 CORBA_SeqUtil::push_back(prof.properties,
01558 NVUtil::newNV("dataport.subscription_type",
01559 "new"));
01560 inport.publishInterfaces_public(prof);
01561 prof.connector_id = "id1";
01562 prof.name = CORBA::string_dup("InPortBaseTest1");
01563 inport.publishInterfaces_public(prof);
01564
01565
01566 RTC::ConnectorInfoList cilist = inport.getConnectorProfiles();
01567 CPPUNIT_ASSERT(cilist.size() == 2);
01568 CPPUNIT_ASSERT_EQUAL(std::string("id0"), std::string(cilist[0].id));
01569 CPPUNIT_ASSERT_EQUAL(std::string("InPortBaseTest0"), std::string(cilist[0].name));
01570 CPPUNIT_ASSERT_EQUAL((size_t)1, cilist[0].ports.size());
01571 CPPUNIT_ASSERT_EQUAL(std::string("id1"), std::string(cilist[1].id));
01572 CPPUNIT_ASSERT_EQUAL(std::string("InPortBaseTest1"), std::string(cilist[1].name));
01573 CPPUNIT_ASSERT_EQUAL((size_t)1, cilist[1].ports.size());
01574
01575
01576 coil::vstring ids = inport.getConnectorIds();
01577 CPPUNIT_ASSERT(ids.size() == 2);
01578 CPPUNIT_ASSERT_EQUAL(std::string("id0"), std::string(ids[0]));
01579 CPPUNIT_ASSERT_EQUAL(std::string("id1"), std::string(ids[1]));
01580
01581
01582 coil::vstring names = inport.getConnectorNames();
01583 CPPUNIT_ASSERT_EQUAL(std::string("InPortBaseTest0"), std::string(names[0]));
01584 CPPUNIT_ASSERT_EQUAL(std::string("InPortBaseTest1"), std::string(names[1]));
01585
01586
01587 RTC::InPortConnector* ic = inport.getConnectorById("unknown");
01588 CPPUNIT_ASSERT(ic == 0);
01589 ic = inport.getConnectorById("id0");
01590 CPPUNIT_ASSERT(ic != 0);
01591 ic = inport.getConnectorById("id1");
01592 CPPUNIT_ASSERT(ic != 0);
01593
01594
01595 ic = inport.getConnectorByName("unknown");
01596 CPPUNIT_ASSERT(ic == 0);
01597 ic = inport.getConnectorByName("InPortBaseTest0");
01598 CPPUNIT_ASSERT(ic != 0);
01599 ic = inport.getConnectorByName("InPortBaseTest1");
01600 CPPUNIT_ASSERT(ic != 0);
01601
01602
01603 RTC::ConnectorInfo info;
01604 bool bret = inport.getConnectorProfileById("unknown", info);
01605 CPPUNIT_ASSERT( !bret );
01606 bret = inport.getConnectorProfileById("id0", info);
01607 CPPUNIT_ASSERT( bret );
01608 bret = inport.getConnectorProfileById("id1", info);
01609 CPPUNIT_ASSERT( bret );
01610
01611
01612 bret = inport.getConnectorProfileByName("unknown", info);
01613 CPPUNIT_ASSERT( !bret );
01614 bret = inport.getConnectorProfileByName("InPortBaseTest0", info);
01615 CPPUNIT_ASSERT( bret );
01616 bret = inport.getConnectorProfileByName("InPortBaseTest1", info);
01617 CPPUNIT_ASSERT( bret );
01618
01619 CPPUNIT_ASSERT_EQUAL(2,(int)inport.get_m_connectors().size());
01620 std::vector<RTC::InPortConnector*> list = inport.get_m_connectors();
01621 inport.activateInterfaces();
01622 inport.deactivateInterfaces();
01623
01624 portAdmin.deletePort(inport);
01625
01626 ic = NULL;
01627 delete ic;
01628 }
01633 void test_publishInterfaces(void)
01634 {
01635
01636 if( RTC::InPortProviderFactory::instance().hasFactory("corba_cdr") )
01637 {
01638 RTC::InPortProviderFactory::instance().removeFactory("corba_cdr");
01639 }
01640
01641 RTC::InPortProviderFactory::instance().
01642 addFactory("corba_cdr",
01643 ::coil::Creator< ::RTC::InPortProvider,
01644 InPortCorbaCdrProviderMock>,
01645 ::coil::Destructor< ::RTC::InPortProvider,
01646 InPortCorbaCdrProviderMock>);
01647
01648
01649 if( RTC::OutPortConsumerFactory::instance().hasFactory("corba_cdr") )
01650 {
01651 RTC::OutPortConsumerFactory::instance().removeFactory("corba_cdr");
01652 }
01653
01654 RTC::OutPortConsumerFactory::instance().
01655 addFactory("corba_cdr",
01656 ::coil::Creator< ::RTC::OutPortConsumer,
01657 OutPortCorbaCdrConsumerMock>,
01658 ::coil::Destructor< ::RTC::OutPortConsumer,
01659 OutPortCorbaCdrConsumerMock>);
01660
01661
01662 if( RTC::CdrBufferFactory::instance().hasFactory("ring_buffer") )
01663 {
01664 RTC::CdrBufferFactory::instance().removeFactory("ring_buffer");
01665 }
01666
01667
01668 RTC::CdrBufferFactory::instance().
01669 addFactory("ring_buffer",
01670 coil::Creator<RTC::CdrBufferBase, CdrRingBufferMock>,
01671 coil::Destructor<RTC::CdrBufferBase, CdrRingBufferMock>);
01672
01673 InPortBaseMock inport("InPortBaseTest", toTypename<RTC::TimedFloat>());
01674 coil::Properties dummy;
01675 inport.init(dummy);
01676
01677 RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
01678 portAdmin.registerPort(inport);
01679 RTC::ConnectorProfile prof;
01680 prof.connector_id = "id0";
01681 prof.name = CORBA::string_dup("InPortBaseTest0");
01682 prof.ports.length(1);
01683 prof.ports[0] = inport.get_port_profile()->port_ref;
01684 CORBA_SeqUtil::push_back(prof.properties,
01685 NVUtil::newNV("dataport.interface_type",
01686 "corba_cdr"));
01687 CORBA_SeqUtil::push_back(prof.properties,
01688 NVUtil::newNV("dataport.dataflow_type",
01689 "push"));
01690 CORBA_SeqUtil::push_back(prof.properties,
01691 NVUtil::newNV("dataport.subscription_type",
01692 "new"));
01693 RTC::ReturnCode_t retcode;
01694 CPPUNIT_ASSERT_EQUAL(0,(int)inport.get_m_connectors().size());
01695 retcode = inport.publishInterfaces_public(prof);
01696 CPPUNIT_ASSERT_EQUAL(1,(int)inport.get_m_connectors().size());
01697 CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode);
01698
01699 prof.connector_id = "id1";
01700 prof.name = CORBA::string_dup("InPortBaseTest1");
01701 retcode = inport.publishInterfaces_public(prof);
01702 CPPUNIT_ASSERT_EQUAL(2,(int)inport.get_m_connectors().size());
01703 CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode);
01704
01705 portAdmin.deletePort(inport);
01706 }
01713 void test_publishInterfaces2(void)
01714 {
01715
01716
01717
01718
01719
01720 if( RTC::InPortProviderFactory::instance().hasFactory("corba_cdr") )
01721 {
01722 RTC::InPortProviderFactory::instance().removeFactory("corba_cdr");
01723 }
01724
01725 RTC::InPortProviderFactory::instance().
01726 addFactory("corba_cdr",
01727 ::coil::Creator< ::RTC::InPortProvider,
01728 InPortCorbaCdrProviderMock>,
01729 ::coil::Destructor< ::RTC::InPortProvider,
01730 InPortCorbaCdrProviderMock>);
01731
01732
01733 if( RTC::OutPortConsumerFactory::instance().hasFactory("corba_cdr") )
01734 {
01735 RTC::OutPortConsumerFactory::instance().removeFactory("corba_cdr");
01736 }
01737
01738 RTC::OutPortConsumerFactory::instance().
01739 addFactory("corba_cdr",
01740 ::coil::Creator< ::RTC::OutPortConsumer,
01741 OutPortCorbaCdrConsumerMock>,
01742 ::coil::Destructor< ::RTC::OutPortConsumer,
01743 OutPortCorbaCdrConsumerMock>);
01744
01745
01746 if( RTC::CdrBufferFactory::instance().hasFactory("ring_buffer") )
01747 {
01748 RTC::CdrBufferFactory::instance().removeFactory("ring_buffer");
01749 }
01750
01751
01752 RTC::CdrBufferFactory::instance().
01753 addFactory("ring_buffer",
01754 coil::Creator<RTC::CdrBufferBase, CdrRingBufferMock>,
01755 coil::Destructor<RTC::CdrBufferBase, CdrRingBufferMock>);
01756
01757 InPortBaseMock inport("InPortBaseTest", toTypename<RTC::TimedFloat>());
01758 coil::Properties dummy;
01759 inport.init(dummy);
01760
01761 RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
01762 portAdmin.registerPort(inport);
01763 RTC::ConnectorProfile prof;
01764 prof.connector_id = "id0";
01765 prof.name = CORBA::string_dup("InPortBaseTest0");
01766 prof.ports.length(1);
01767 prof.ports[0] = inport.get_port_profile()->port_ref;
01768 CORBA_SeqUtil::push_back(prof.properties,
01769 NVUtil::newNV("dataport.interface_type",
01770 "corba_cdr"));
01771 CORBA_SeqUtil::push_back(prof.properties,
01772 NVUtil::newNV("dataport.dataflow_type",
01773 "pull"));
01774 CORBA_SeqUtil::push_back(prof.properties,
01775 NVUtil::newNV("dataport.subscription_type",
01776 "new"));
01777 RTC::ReturnCode_t retcode;
01778 CPPUNIT_ASSERT_EQUAL(0,(int)inport.get_m_connectors().size());
01779 retcode = inport.publishInterfaces_public(prof);
01780 CPPUNIT_ASSERT_EQUAL(0,(int)inport.get_m_connectors().size());
01781 CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode);
01782
01783 prof.connector_id = "id1";
01784 prof.name = CORBA::string_dup("InPortBaseTest1");
01785 retcode = inport.publishInterfaces_public(prof);
01786 CPPUNIT_ASSERT_EQUAL(0,(int)inport.get_m_connectors().size());
01787 CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode);
01788
01789 portAdmin.deletePort(inport);
01790 }
01795 void test_publishInterfaces3(void)
01796 {
01797
01798
01799
01800
01801
01802 if( RTC::InPortProviderFactory::instance().hasFactory("corba_cdr") )
01803 {
01804 RTC::InPortProviderFactory::instance().removeFactory("corba_cdr");
01805 }
01806
01807 RTC::InPortProviderFactory::instance().
01808 addFactory("corba_cdr",
01809 ::coil::Creator< ::RTC::InPortProvider,
01810 InPortCorbaCdrProviderMock>,
01811 ::coil::Destructor< ::RTC::InPortProvider,
01812 InPortCorbaCdrProviderMock>);
01813
01814
01815 if( RTC::OutPortConsumerFactory::instance().hasFactory("corba_cdr") )
01816 {
01817 RTC::OutPortConsumerFactory::instance().removeFactory("corba_cdr");
01818 }
01819
01820 RTC::OutPortConsumerFactory::instance().
01821 addFactory("corba_cdr",
01822 ::coil::Creator< ::RTC::OutPortConsumer,
01823 OutPortCorbaCdrConsumerMock>,
01824 ::coil::Destructor< ::RTC::OutPortConsumer,
01825 OutPortCorbaCdrConsumerMock>);
01826
01827
01828 if( RTC::CdrBufferFactory::instance().hasFactory("ring_buffer") )
01829 {
01830 RTC::CdrBufferFactory::instance().removeFactory("ring_buffer");
01831 }
01832
01833
01834 RTC::CdrBufferFactory::instance().
01835 addFactory("ring_buffer",
01836 coil::Creator<RTC::CdrBufferBase, CdrRingBufferMock>,
01837 coil::Destructor<RTC::CdrBufferBase, CdrRingBufferMock>);
01838
01839 InPortBaseMock inport("InPortBaseTest", toTypename<RTC::TimedFloat>());
01840 coil::Properties dummy;
01841 inport.init(dummy);
01842
01843 RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
01844 portAdmin.registerPort(inport);
01845 RTC::ConnectorProfile prof;
01846 prof.connector_id = "id0";
01847 prof.name = CORBA::string_dup("InPortBaseTest0");
01848 prof.ports.length(1);
01849 prof.ports[0] = inport.get_port_profile()->port_ref;
01850 CORBA_SeqUtil::push_back(prof.properties,
01851 NVUtil::newNV("dataport.interface_type",
01852 "corba_cdr"));
01853 CORBA_SeqUtil::push_back(prof.properties,
01854 NVUtil::newNV("dataport.dataflow_type",
01855 "else"));
01856 CORBA_SeqUtil::push_back(prof.properties,
01857 NVUtil::newNV("dataport.subscription_type",
01858 "new"));
01859 RTC::ReturnCode_t retcode;
01860 CPPUNIT_ASSERT_EQUAL(0,(int)inport.get_m_connectors().size());
01861 retcode = inport.publishInterfaces_public(prof);
01862 CPPUNIT_ASSERT_EQUAL(0,(int)inport.get_m_connectors().size());
01863 CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode);
01864
01865 prof.connector_id = "id1";
01866 prof.name = CORBA::string_dup("InPortBaseTest1");
01867 retcode = inport.publishInterfaces_public(prof);
01868 CPPUNIT_ASSERT_EQUAL(0,(int)inport.get_m_connectors().size());
01869 CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode);
01870
01871 portAdmin.deletePort(inport);
01872 }
01877 void test_publishInterfaces4(void)
01878 {
01879
01880
01881
01882
01883
01884 if( RTC::InPortProviderFactory::instance().hasFactory("corba_cdr") )
01885 {
01886 RTC::InPortProviderFactory::instance().removeFactory("corba_cdr");
01887 }
01888
01889
01890 if( RTC::OutPortConsumerFactory::instance().hasFactory("corba_cdr") )
01891 {
01892 RTC::OutPortConsumerFactory::instance().removeFactory("corba_cdr");
01893 }
01894
01895 RTC::OutPortConsumerFactory::instance().
01896 addFactory("corba_cdr",
01897 ::coil::Creator< ::RTC::OutPortConsumer,
01898 OutPortCorbaCdrConsumerMock>,
01899 ::coil::Destructor< ::RTC::OutPortConsumer,
01900 OutPortCorbaCdrConsumerMock>);
01901
01902
01903 if( RTC::CdrBufferFactory::instance().hasFactory("ring_buffer") )
01904 {
01905 RTC::CdrBufferFactory::instance().removeFactory("ring_buffer");
01906 }
01907
01908
01909 RTC::CdrBufferFactory::instance().
01910 addFactory("ring_buffer",
01911 coil::Creator<RTC::CdrBufferBase, CdrRingBufferMock>,
01912 coil::Destructor<RTC::CdrBufferBase, CdrRingBufferMock>);
01913
01914 InPortBaseMock inport("InPortBaseTest", toTypename<RTC::TimedFloat>());
01915 coil::Properties dummy;
01916 inport.init(dummy);
01917
01918 RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
01919 portAdmin.registerPort(inport);
01920 RTC::ConnectorProfile prof;
01921 prof.connector_id = "id0";
01922 prof.name = CORBA::string_dup("InPortBaseTest0");
01923 prof.ports.length(1);
01924 prof.ports[0] = inport.get_port_profile()->port_ref;
01925 CORBA_SeqUtil::push_back(prof.properties,
01926 NVUtil::newNV("dataport.interface_type",
01927 "corba_cdr"));
01928 CORBA_SeqUtil::push_back(prof.properties,
01929 NVUtil::newNV("dataport.dataflow_type",
01930 "else"));
01931 CORBA_SeqUtil::push_back(prof.properties,
01932 NVUtil::newNV("dataport.subscription_type",
01933 "new"));
01934 RTC::ReturnCode_t retcode;
01935 CPPUNIT_ASSERT_EQUAL(0,(int)inport.get_m_connectors().size());
01936 retcode = inport.publishInterfaces_public(prof);
01937 CPPUNIT_ASSERT_EQUAL(0,(int)inport.get_m_connectors().size());
01938 CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode);
01939
01940 portAdmin.deletePort(inport);
01941 }
01946 void test_publishInterfaces5(void)
01947 {
01948
01949
01950
01951
01952
01953 if( RTC::InPortProviderFactory::instance().hasFactory("corba_cdr") )
01954 {
01955 RTC::InPortProviderFactory::instance().removeFactory("corba_cdr");
01956 }
01957
01958 RTC::InPortProviderFactory::instance().
01959 addFactory("corba_cdr",
01960 ::coil::Creator< ::RTC::InPortProvider,
01961 InPortCorbaCdrProviderMock>,
01962 ::coil::Destructor< ::RTC::InPortProvider,
01963 InPortCorbaCdrProviderMock>);
01964
01965
01966 if( RTC::OutPortConsumerFactory::instance().hasFactory("corba_cdr") )
01967 {
01968 RTC::OutPortConsumerFactory::instance().removeFactory("corba_cdr");
01969 }
01970
01971 RTC::OutPortConsumerFactory::instance().
01972 addFactory("corba_cdr",
01973 ::coil::Creator< ::RTC::OutPortConsumer,
01974 OutPortCorbaCdrConsumerMock>,
01975 ::coil::Destructor< ::RTC::OutPortConsumer,
01976 OutPortCorbaCdrConsumerMock>);
01977
01978
01979 if( RTC::CdrBufferFactory::instance().hasFactory("ring_buffer") )
01980 {
01981 RTC::CdrBufferFactory::instance().removeFactory("ring_buffer");
01982 }
01983
01984
01985 InPortBaseMock inport("InPortBaseTest", toTypename<RTC::TimedFloat>());
01986 coil::Properties dummy;
01987 inport.init(dummy);
01988
01989 RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
01990 portAdmin.registerPort(inport);
01991 RTC::ConnectorProfile prof;
01992 prof.connector_id = "id0";
01993 prof.name = CORBA::string_dup("InPortBaseTest0");
01994 prof.ports.length(1);
01995 prof.ports[0] = inport.get_port_profile()->port_ref;
01996 CORBA_SeqUtil::push_back(prof.properties,
01997 NVUtil::newNV("dataport.interface_type",
01998 "corba_cdr"));
01999 CORBA_SeqUtil::push_back(prof.properties,
02000 NVUtil::newNV("dataport.dataflow_type",
02001 "else"));
02002 CORBA_SeqUtil::push_back(prof.properties,
02003 NVUtil::newNV("dataport.subscription_type",
02004 "new"));
02005 RTC::ReturnCode_t retcode;
02006 CPPUNIT_ASSERT_EQUAL(0,(int)inport.get_m_connectors().size());
02007 retcode = inport.publishInterfaces_public(prof);
02008 CPPUNIT_ASSERT_EQUAL(0,(int)inport.get_m_connectors().size());
02009 CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode);
02010
02011
02012 portAdmin.deletePort(inport);
02013 }
02018 void test_subscribeInterfaces(void)
02019 {
02020
02021 if( RTC::InPortProviderFactory::instance().hasFactory("corba_cdr") )
02022 {
02023 RTC::InPortProviderFactory::instance().removeFactory("corba_cdr");
02024 }
02025
02026 RTC::InPortProviderFactory::instance().
02027 addFactory("corba_cdr",
02028 ::coil::Creator< ::RTC::InPortProvider,
02029 InPortCorbaCdrProviderMock>,
02030 ::coil::Destructor< ::RTC::InPortProvider,
02031 InPortCorbaCdrProviderMock>);
02032
02033
02034 if( RTC::OutPortConsumerFactory::instance().hasFactory("corba_cdr") )
02035 {
02036 RTC::OutPortConsumerFactory::instance().removeFactory("corba_cdr");
02037 }
02038
02039 RTC::OutPortConsumerFactory::instance().
02040 addFactory("corba_cdr",
02041 ::coil::Creator< ::RTC::OutPortConsumer,
02042 OutPortCorbaCdrConsumerMock>,
02043 ::coil::Destructor< ::RTC::OutPortConsumer,
02044 OutPortCorbaCdrConsumerMock>);
02045
02046
02047 if( RTC::CdrBufferFactory::instance().hasFactory("ring_buffer") )
02048 {
02049 RTC::CdrBufferFactory::instance().removeFactory("ring_buffer");
02050 }
02051
02052
02053 RTC::CdrBufferFactory::instance().
02054 addFactory("ring_buffer",
02055 coil::Creator<RTC::CdrBufferBase, CdrRingBufferMock>,
02056 coil::Destructor<RTC::CdrBufferBase, CdrRingBufferMock>);
02057
02058 InPortBaseMock inport("InPortBaseTest", toTypename<RTC::TimedFloat>());
02059 coil::Properties dummy;
02060 inport.init(dummy);
02061
02062 RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
02063 portAdmin.registerPort(inport);
02064 RTC::ConnectorProfile prof;
02065 prof.connector_id = "id0";
02066 prof.name = CORBA::string_dup("InPortBaseTest0");
02067 prof.ports.length(1);
02068 prof.ports[0] = inport.get_port_profile()->port_ref;
02069 CORBA_SeqUtil::push_back(prof.properties,
02070 NVUtil::newNV("dataport.interface_type",
02071 "corba_cdr"));
02072 CORBA_SeqUtil::push_back(prof.properties,
02073 NVUtil::newNV("dataport.dataflow_type",
02074 "pull"));
02075 CORBA_SeqUtil::push_back(prof.properties,
02076 NVUtil::newNV("dataport.subscription_type",
02077 "new"));
02078 RTC::ReturnCode_t retcode;
02079 CPPUNIT_ASSERT_EQUAL(0,(int)inport.get_m_connectors().size());
02080 retcode = inport.subscribeInterfaces_public(prof);
02081 CPPUNIT_ASSERT_EQUAL(1,(int)inport.get_m_connectors().size());
02082 CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode);
02083
02084 prof.connector_id = "id1";
02085 prof.name = CORBA::string_dup("InPortBaseTest1");
02086 retcode = inport.subscribeInterfaces_public(prof);
02087 CPPUNIT_ASSERT_EQUAL(2,(int)inport.get_m_connectors().size());
02088 CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode);
02089
02090 portAdmin.deletePort(inport);
02091 }
02097 void test_subscribeInterfaces2(void)
02098 {
02099
02100
02101
02102
02103
02104 if( RTC::InPortProviderFactory::instance().hasFactory("corba_cdr") )
02105 {
02106 RTC::InPortProviderFactory::instance().removeFactory("corba_cdr");
02107 }
02108
02109 RTC::InPortProviderFactory::instance().
02110 addFactory("corba_cdr",
02111 ::coil::Creator< ::RTC::InPortProvider,
02112 InPortCorbaCdrProviderMock>,
02113 ::coil::Destructor< ::RTC::InPortProvider,
02114 InPortCorbaCdrProviderMock>);
02115
02116
02117 if( RTC::OutPortConsumerFactory::instance().hasFactory("corba_cdr") )
02118 {
02119 RTC::OutPortConsumerFactory::instance().removeFactory("corba_cdr");
02120 }
02121
02122 RTC::OutPortConsumerFactory::instance().
02123 addFactory("corba_cdr",
02124 ::coil::Creator< ::RTC::OutPortConsumer,
02125 OutPortCorbaCdrConsumerMock>,
02126 ::coil::Destructor< ::RTC::OutPortConsumer,
02127 OutPortCorbaCdrConsumerMock>);
02128
02129
02130 if( RTC::CdrBufferFactory::instance().hasFactory("ring_buffer") )
02131 {
02132 RTC::CdrBufferFactory::instance().removeFactory("ring_buffer");
02133 }
02134
02135
02136 RTC::CdrBufferFactory::instance().
02137 addFactory("ring_buffer",
02138 coil::Creator<RTC::CdrBufferBase, CdrRingBufferMock>,
02139 coil::Destructor<RTC::CdrBufferBase, CdrRingBufferMock>);
02140
02141 InPortBaseMock inport("InPortBaseTest", toTypename<RTC::TimedFloat>());
02142 coil::Properties dummy;
02143 inport.init(dummy);
02144
02145 RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
02146 portAdmin.registerPort(inport);
02147 RTC::ConnectorProfile prof;
02148 prof.connector_id = "id0";
02149 prof.name = CORBA::string_dup("InPortBaseTest0");
02150 prof.ports.length(1);
02151 prof.ports[0] = inport.get_port_profile()->port_ref;
02152 CORBA_SeqUtil::push_back(prof.properties,
02153 NVUtil::newNV("dataport.interface_type",
02154 "corba_cdr"));
02155 CORBA_SeqUtil::push_back(prof.properties,
02156 NVUtil::newNV("dataport.dataflow_type",
02157 "push"));
02158 CORBA_SeqUtil::push_back(prof.properties,
02159 NVUtil::newNV("dataport.subscription_type",
02160 "new"));
02161 RTC::ReturnCode_t retcode;
02162 CPPUNIT_ASSERT_EQUAL(0,(int)inport.get_m_connectors().size());
02163 retcode = inport.subscribeInterfaces_public(prof);
02164 CPPUNIT_ASSERT_EQUAL(0,(int)inport.get_m_connectors().size());
02165 CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode);
02166
02167
02168 portAdmin.deletePort(inport);
02169 }
02174 void test_subscribeInterfaces3(void)
02175 {
02176
02177
02178
02179
02180
02181 if( RTC::InPortProviderFactory::instance().hasFactory("corba_cdr") )
02182 {
02183 RTC::InPortProviderFactory::instance().removeFactory("corba_cdr");
02184 }
02185
02186 RTC::InPortProviderFactory::instance().
02187 addFactory("corba_cdr",
02188 ::coil::Creator< ::RTC::InPortProvider,
02189 InPortCorbaCdrProviderMock>,
02190 ::coil::Destructor< ::RTC::InPortProvider,
02191 InPortCorbaCdrProviderMock>);
02192
02193
02194 if( RTC::OutPortConsumerFactory::instance().hasFactory("corba_cdr") )
02195 {
02196 RTC::OutPortConsumerFactory::instance().removeFactory("corba_cdr");
02197 }
02198
02199 RTC::OutPortConsumerFactory::instance().
02200 addFactory("corba_cdr",
02201 ::coil::Creator< ::RTC::OutPortConsumer,
02202 OutPortCorbaCdrConsumerMock>,
02203 ::coil::Destructor< ::RTC::OutPortConsumer,
02204 OutPortCorbaCdrConsumerMock>);
02205
02206
02207 if( RTC::CdrBufferFactory::instance().hasFactory("ring_buffer") )
02208 {
02209 RTC::CdrBufferFactory::instance().removeFactory("ring_buffer");
02210 }
02211
02212
02213 RTC::CdrBufferFactory::instance().
02214 addFactory("ring_buffer",
02215 coil::Creator<RTC::CdrBufferBase, CdrRingBufferMock>,
02216 coil::Destructor<RTC::CdrBufferBase, CdrRingBufferMock>);
02217
02218 InPortBaseMock inport("InPortBaseTest", toTypename<RTC::TimedFloat>());
02219 coil::Properties dummy;
02220 inport.init(dummy);
02221
02222 RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
02223 portAdmin.registerPort(inport);
02224 RTC::ConnectorProfile prof;
02225 prof.connector_id = "id0";
02226 prof.name = CORBA::string_dup("InPortBaseTest0");
02227 prof.ports.length(1);
02228 prof.ports[0] = inport.get_port_profile()->port_ref;
02229 CORBA_SeqUtil::push_back(prof.properties,
02230 NVUtil::newNV("dataport.interface_type",
02231 "corba_cdr"));
02232 CORBA_SeqUtil::push_back(prof.properties,
02233 NVUtil::newNV("dataport.dataflow_type",
02234 "else"));
02235 CORBA_SeqUtil::push_back(prof.properties,
02236 NVUtil::newNV("dataport.subscription_type",
02237 "new"));
02238 RTC::ReturnCode_t retcode;
02239 CPPUNIT_ASSERT_EQUAL(0,(int)inport.get_m_connectors().size());
02240 retcode = inport.subscribeInterfaces_public(prof);
02241 CPPUNIT_ASSERT_EQUAL(0,(int)inport.get_m_connectors().size());
02242 CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode);
02243
02244
02245 portAdmin.deletePort(inport);
02246 }
02251 void test_subscribeInterfaces4(void)
02252 {
02253
02254
02255
02256
02257
02258 if( RTC::InPortProviderFactory::instance().hasFactory("corba_cdr") )
02259 {
02260 RTC::InPortProviderFactory::instance().removeFactory("corba_cdr");
02261 }
02262
02263 RTC::InPortProviderFactory::instance().
02264 addFactory("corba_cdr",
02265 ::coil::Creator< ::RTC::InPortProvider,
02266 InPortCorbaCdrProviderMock>,
02267 ::coil::Destructor< ::RTC::InPortProvider,
02268 InPortCorbaCdrProviderMock>);
02269
02270
02271 if( RTC::OutPortConsumerFactory::instance().hasFactory("corba_cdr") )
02272 {
02273 RTC::OutPortConsumerFactory::instance().removeFactory("corba_cdr");
02274 }
02275
02276
02277 if( RTC::CdrBufferFactory::instance().hasFactory("ring_buffer") )
02278 {
02279 RTC::CdrBufferFactory::instance().removeFactory("ring_buffer");
02280 }
02281
02282
02283 RTC::CdrBufferFactory::instance().
02284 addFactory("ring_buffer",
02285 coil::Creator<RTC::CdrBufferBase, CdrRingBufferMock>,
02286 coil::Destructor<RTC::CdrBufferBase, CdrRingBufferMock>);
02287
02288 InPortBaseMock inport("InPortBaseTest", toTypename<RTC::TimedFloat>());
02289 coil::Properties dummy;
02290 inport.init(dummy);
02291
02292 RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
02293 portAdmin.registerPort(inport);
02294 RTC::ConnectorProfile prof;
02295 prof.connector_id = "id0";
02296 prof.name = CORBA::string_dup("InPortBaseTest0");
02297 prof.ports.length(1);
02298 prof.ports[0] = inport.get_port_profile()->port_ref;
02299 CORBA_SeqUtil::push_back(prof.properties,
02300 NVUtil::newNV("dataport.interface_type",
02301 "corba_cdr"));
02302 CORBA_SeqUtil::push_back(prof.properties,
02303 NVUtil::newNV("dataport.dataflow_type",
02304 "pull"));
02305 CORBA_SeqUtil::push_back(prof.properties,
02306 NVUtil::newNV("dataport.subscription_type",
02307 "new"));
02308 RTC::ReturnCode_t retcode;
02309 CPPUNIT_ASSERT_EQUAL(0,(int)inport.get_m_connectors().size());
02310 retcode = inport.subscribeInterfaces_public(prof);
02311 CPPUNIT_ASSERT_EQUAL(0,(int)inport.get_m_connectors().size());
02312 CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode);
02313
02314 portAdmin.deletePort(inport);
02315 }
02320 void test_subscribeInterfaces5(void)
02321 {
02322
02323
02324
02325
02326
02327 if( RTC::InPortProviderFactory::instance().hasFactory("corba_cdr") )
02328 {
02329 RTC::InPortProviderFactory::instance().removeFactory("corba_cdr");
02330 }
02331
02332 RTC::InPortProviderFactory::instance().
02333 addFactory("corba_cdr",
02334 ::coil::Creator< ::RTC::InPortProvider,
02335 InPortCorbaCdrProviderMock>,
02336 ::coil::Destructor< ::RTC::InPortProvider,
02337 InPortCorbaCdrProviderMock>);
02338
02339
02340 if( RTC::OutPortConsumerFactory::instance().hasFactory("corba_cdr") )
02341 {
02342 RTC::OutPortConsumerFactory::instance().removeFactory("corba_cdr");
02343 }
02344
02345 RTC::OutPortConsumerFactory::instance().
02346 addFactory("corba_cdr",
02347 ::coil::Creator< ::RTC::OutPortConsumer,
02348 OutPortCorbaCdrConsumerMock>,
02349 ::coil::Destructor< ::RTC::OutPortConsumer,
02350 OutPortCorbaCdrConsumerMock>);
02351
02352
02353 if( RTC::CdrBufferFactory::instance().hasFactory("ring_buffer") )
02354 {
02355 RTC::CdrBufferFactory::instance().removeFactory("ring_buffer");
02356 }
02357
02358 InPortBaseMock inport("InPortBaseTest", toTypename<RTC::TimedFloat>());
02359 coil::Properties dummy;
02360 inport.init(dummy);
02361
02362 RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
02363 portAdmin.registerPort(inport);
02364 RTC::ConnectorProfile prof;
02365 prof.connector_id = "id0";
02366 prof.name = CORBA::string_dup("InPortBaseTest0");
02367 prof.ports.length(1);
02368 prof.ports[0] = inport.get_port_profile()->port_ref;
02369 CORBA_SeqUtil::push_back(prof.properties,
02370 NVUtil::newNV("dataport.interface_type",
02371 "corba_cdr"));
02372 CORBA_SeqUtil::push_back(prof.properties,
02373 NVUtil::newNV("dataport.dataflow_type",
02374 "pull"));
02375 CORBA_SeqUtil::push_back(prof.properties,
02376 NVUtil::newNV("dataport.subscription_type",
02377 "new"));
02378 RTC::ReturnCode_t retcode;
02379 CPPUNIT_ASSERT_EQUAL(0,(int)inport.get_m_connectors().size());
02380 retcode = inport.subscribeInterfaces_public(prof);
02381 CPPUNIT_ASSERT_EQUAL(0,(int)inport.get_m_connectors().size());
02382 CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode);
02383
02384 portAdmin.deletePort(inport);
02385 }
02390 void test_createConnector(void)
02391 {
02392 InPortBaseMock inport("InPortBaseTest", toTypename<RTC::TimedDouble>());
02393
02394 RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
02395 portAdmin.registerPort(inport);
02396
02397 RTC::ConnectorProfile prof;
02398
02399 coil::Properties prop(inport.properties());
02400 RTC::InPortProvider* provider = new InPortCorbaCdrProviderMock();
02401 RTC::InPortConnector* connector
02402 = inport.createConnector_public(prof, prop, provider);
02403 CPPUNIT_ASSERT(0!= connector);
02404
02405 portAdmin.deletePort(inport);
02406
02407 }
02412 void test_createConnector2(void)
02413 {
02414 InPortBaseMock inport("InPortBaseTest", toTypename<RTC::TimedDouble>());
02415
02416 RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
02417 portAdmin.registerPort(inport);
02418
02419 RTC::ConnectorProfile prof;
02420
02421 coil::Properties prop(inport.properties());
02422 prop.setProperty("InPortBaseTests","bad_alloc");
02423 RTC::InPortProvider* provider = new InPortCorbaCdrProviderMock();
02424 RTC::InPortConnector* connector
02425 = inport.createConnector_public(prof, prop, provider);
02426 CPPUNIT_ASSERT(0 != connector);
02427
02428 portAdmin.deletePort(inport);
02429
02430 }
02431
02436 void test_ConnectorListener(void)
02437 {
02438 RTC::TimedLong tdl;
02439 OutPortMock<RTC::TimedLong> outport("OutPort", tdl);
02440 coil::Properties dummy;
02441 outport.init(dummy);
02442
02443
02444 if( RTC::InPortProviderFactory::instance().hasFactory("corba_cdr") )
02445 {
02446 RTC::InPortProviderFactory::instance().removeFactory("corba_cdr");
02447 }
02448
02449 RTC::InPortProviderFactory::instance().
02450 addFactory("corba_cdr",
02451 ::coil::Creator< ::RTC::InPortProvider,
02452 ::RTC::InPortCorbaCdrProvider>,
02453 ::coil::Destructor< ::RTC::InPortProvider,
02454 ::RTC::InPortCorbaCdrProvider>);
02455
02456
02457 if( RTC::OutPortConsumerFactory::instance().hasFactory("corba_cdr") )
02458 {
02459 RTC::OutPortConsumerFactory::instance().removeFactory("corba_cdr");
02460 }
02461
02462 RTC::OutPortConsumerFactory::instance().
02463 addFactory("corba_cdr",
02464 ::coil::Creator< ::RTC::OutPortConsumer,
02465 ::RTC::OutPortCorbaCdrConsumer>,
02466 ::coil::Destructor< ::RTC::OutPortConsumer,
02467 ::RTC::OutPortCorbaCdrConsumer>);
02468
02469
02470 if( RTC::CdrBufferFactory::instance().hasFactory("ring_buffer") )
02471 {
02472 RTC::CdrBufferFactory::instance().removeFactory("ring_buffer");
02473 }
02474
02475
02476 RTC::CdrBufferFactory::instance().
02477 addFactory("ring_buffer",
02478 coil::Creator<RTC::CdrBufferBase, CdrRingBufferMock>,
02479 coil::Destructor<RTC::CdrBufferBase, CdrRingBufferMock>);
02480
02481 InPortBaseMock inport("InPortBaseTest", toTypename<RTC::TimedLong>());
02482 inport.init(dummy);
02483
02484 RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
02485 portAdmin.registerPort(inport);
02486 RTC::ConnectorProfile prof;
02487 prof.connector_id = "id0";
02488 prof.name = CORBA::string_dup("connectTest0");
02489 prof.ports.length(2);
02490 prof.ports[0] = inport.get_port_profile()->port_ref;
02491 prof.ports[1] = outport.get_port_profile()->port_ref;
02492 CORBA_SeqUtil::push_back(prof.properties,
02493 NVUtil::newNV("dataport.interface_type",
02494 "corba_cdr"));
02495 CORBA_SeqUtil::push_back(prof.properties,
02496 NVUtil::newNV("dataport.dataflow_type",
02497 "push"));
02498 CORBA_SeqUtil::push_back(prof.properties,
02499 NVUtil::newNV("dataport.subscription_type",
02500 "flush"));
02501
02502
02503 for (int i(0); i<cdl_len; ++i)
02504 {
02505 m_datalisteners[i] = new DataListener(str_cdl[i]);
02506 }
02507
02508
02509 for (int i(0); i<cl_len; ++i)
02510 {
02511 m_connlisteners[i] = new ConnListener(str_cl[i]);
02512 }
02513
02514
02515 for (int i(0); i<cdl_len; ++i)
02516 {
02517 inport.addConnectorDataListener((RTC::ConnectorDataListenerType)i,
02518 m_datalisteners[i], true);
02519 }
02520
02521
02522 for (int i(0); i<cl_len; ++i)
02523 {
02524 inport.addConnectorListener((RTC::ConnectorListenerType)i,
02525 m_connlisteners[i], true);
02526 }
02527
02528
02529 CPPUNIT_ASSERT_EQUAL(10, cdl_count);
02530 CPPUNIT_ASSERT_EQUAL(7, cl_count);
02531
02532 inport.publishInterfaces_public(prof);
02533
02534
02535 RTC::ReturnCode_t ret;
02536 ret = inport.connect(prof);
02537 CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ret);
02538
02539
02540
02541 bool bret = inport.isLittleEndian();
02542 CPPUNIT_ASSERT( bret );
02543
02544 tdl.data = 100;
02545 outport.write(tdl);
02546
02547 inport.activateInterfaces();
02548 inport.deactivateInterfaces();
02549 ret = inport.disconnect_all();
02550 CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ret);
02551
02552 portAdmin.deletePort(inport);
02553
02554 for (int i(0); i<cdl_len; ++i)
02555 {
02556 inport.removeConnectorDataListener((RTC::ConnectorDataListenerType)i,
02557 m_datalisteners[i]);
02558 }
02559
02560
02561 for (int i(0); i<cl_len; ++i)
02562 {
02563 inport.removeConnectorListener((RTC::ConnectorListenerType)i,
02564 m_connlisteners[i]);
02565 }
02566
02567
02568 CPPUNIT_ASSERT_EQUAL(0, cdl_count);
02569 CPPUNIT_ASSERT_EQUAL(0, cl_count);
02570
02571 }
02572
02573 };
02574 };
02575
02576
02577
02578
02579
02580 CPPUNIT_TEST_SUITE_REGISTRATION(InPortBase::InPortBaseTests);
02581
02582 #ifdef LOCAL_MAIN
02583 int main(int argc, char* argv[])
02584 {
02585
02586 FORMAT format = TEXT_OUT;
02587 int target = 0;
02588 std::string xsl;
02589 std::string ns;
02590 std::string fname;
02591 std::ofstream ofs;
02592
02593 int i(1);
02594 while (i < argc)
02595 {
02596 std::string arg(argv[i]);
02597 std::string next_arg;
02598 if (i + 1 < argc) next_arg = argv[i + 1];
02599 else next_arg = "";
02600
02601 if (arg == "--text") { format = TEXT_OUT; break; }
02602 if (arg == "--xml")
02603 {
02604 if (next_arg == "")
02605 {
02606 fname = argv[0];
02607 fname += ".xml";
02608 }
02609 else
02610 {
02611 fname = next_arg;
02612 }
02613 format = XML_OUT;
02614 ofs.open(fname.c_str());
02615 }
02616 if ( arg == "--compiler" ) { format = COMPILER_OUT; break; }
02617 if ( arg == "--cerr" ) { target = 1; break; }
02618 if ( arg == "--xsl" )
02619 {
02620 if (next_arg == "") xsl = "default.xsl";
02621 else xsl = next_arg;
02622 }
02623 if ( arg == "--namespace" )
02624 {
02625 if (next_arg == "")
02626 {
02627 std::cerr << "no namespace specified" << std::endl;
02628 exit(1);
02629 }
02630 else
02631 {
02632 xsl = next_arg;
02633 }
02634 }
02635 ++i;
02636 }
02637 CppUnit::TextUi::TestRunner runner;
02638 if ( ns.empty() )
02639 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
02640 else
02641 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
02642 CppUnit::Outputter* outputter = 0;
02643 std::ostream* stream = target ? &std::cerr : &std::cout;
02644 switch ( format )
02645 {
02646 case TEXT_OUT :
02647 outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
02648 break;
02649 case XML_OUT :
02650 std::cout << "XML_OUT" << std::endl;
02651 outputter = new CppUnit::XmlOutputter(&runner.result(),
02652 ofs, "shift_jis");
02653 static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
02654 break;
02655 case COMPILER_OUT :
02656 outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
02657 break;
02658 }
02659 runner.setOutputter(outputter);
02660 runner.run();
02661 return 0;
02662 }
02663 #endif // MAIN
02664 #endif // OutPortBase_cpp