OutPortBaseTests.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00012 /*
00013  * $Log: OutPortBaseTests.cpp,v $
00014  * Revision 1.2  2008/02/21 07:36:39  arafune
00015  * Some tests were added.
00016  *
00017  * Revision 1.1  2007/12/20 07:50:17  arafune
00018  * *** empty log message ***
00019  *
00020  * Revision 1.1  2006/12/02 18:55:54  n-ando
00021  * *** empty log message ***
00022  *
00023  *
00024  */
00025 
00026 #ifndef OutPortBase_cpp
00027 #define OutPortBase_cpp
00028 
00029 #include <cppunit/ui/text/TestRunner.h>
00030 #include <cppunit/TextOutputter.h>
00031 #include <cppunit/extensions/TestFactoryRegistry.h>
00032 #include <cppunit/extensions/HelperMacros.h>
00033 #include <cppunit/TestAssert.h>
00034 
00035 #include <rtm/idl/BasicDataTypeSkel.h>
00036 #include <rtm/idl/DataPortSkel.h>
00037 #include <rtm/Typename.h>
00038 #include <rtm/PublisherBase.h>
00039 #include <rtm/OutPortBase.h>
00040 #include <rtm/InPort.h>
00041 #include <rtm/CorbaConsumer.h>
00042 #include <rtm/InPortConsumer.h>
00043 #include <rtm/OutPort.h>
00044 #include <rtm/OutPortConnector.h>
00045 #include <rtm/PortAdmin.h>
00046 #include <rtm/PublisherBase.h>
00047 #include <rtm/PublisherFlush.h>
00048 #include <rtm/PublisherNew.h>
00049 #include <rtm/PublisherPeriodic.h>
00050 #include <rtm/SystemLogger.h>
00051 #include <rtm/OutPortPushConnector.h>
00052 #include <rtm/OutPortProvider.h>
00053 #include <rtm/OutPortPullConnector.h>
00054 #include <rtm/ConnectorListener.h>
00055 
00056 // ConnectorDataListenerType count
00057 #define cdl_len 10
00058 // ConnectorListenerType count
00059 #define cl_len 7
00060 
00065 namespace OutPortBase
00066 {
00067 
00068   // ConnectorDataListenerType
00069   static const char* str_cdl[] =
00070   {
00071     "ON_BUFFER_WRITE",
00072     "ON_BUFFER_FULL",
00073     "ON_BUFFER_WRITE_TIMEOUT",
00074     "ON_BUFFER_OVERWRITE",
00075     "ON_BUFFER_READ", 
00076     "ON_SEND", 
00077     "ON_RECEIVED",
00078     "ON_RECEIVER_FULL", 
00079     "ON_RECEIVER_TIMEOUT", 
00080     "ON_RECEIVER_ERROR"
00081   };
00082 
00083   // ConnectorListenerType
00084   static const char* str_cl[] =
00085   {
00086     "ON_BUFFER_EMPTY",
00087     "ON_BUFFER_READ_TIMEOUT",
00088     "ON_SENDER_EMPTY", 
00089     "ON_SENDER_TIMEOUT", 
00090     "ON_SENDER_ERROR", 
00091     "ON_CONNECT",
00092     "ON_DISCONNECT"
00093   };
00094 
00095   static int cdl_count;
00096   static int cl_count;
00097 
00098   class DataListener
00099     : public RTC::ConnectorDataListenerT<RTC::TimedLong>
00100   {
00101   public:
00102     DataListener(const char* name) : m_name(name)
00103     {
00104       ++cdl_count;
00105     }
00106     virtual ~DataListener()
00107     {
00108       --cdl_count;
00109     }
00110 
00111     virtual void operator()(const RTC::ConnectorInfo& info,
00112                             const RTC::TimedLong& data)
00113     {
00114       std::cout << "------------------------------"   << std::endl;
00115       std::cout << "Data Listener: " << m_name       << std::endl;
00116       std::cout << "Profile::name: " << info.name    << std::endl;
00117       std::cout << "------------------------------"   << std::endl;
00118     };
00119     std::string m_name;
00120   };
00121 
00122 
00123   class ConnListener
00124     : public RTC::ConnectorListener
00125   {
00126   public:
00127     ConnListener(const char* name) : m_name(name)
00128     {
00129       ++cl_count;
00130     }
00131     virtual ~ConnListener()
00132     {
00133       --cl_count;
00134     }
00135 
00136     virtual void operator()(const RTC::ConnectorInfo& info)
00137     {
00138       std::cout << "------------------------------"   << std::endl;
00139       std::cout << "Connector Listener: " << m_name       << std::endl;
00140       std::cout << "Profile::name:      " << info.name    << std::endl;
00141       std::cout << "------------------------------"   << std::endl;
00142     };
00143     std::string m_name;
00144   };
00145 
00151   class PublisherA
00152     : public RTC::PublisherBase
00153   {
00154   public:
00155     PublisherA(std::string& footPrints) : m_footPrints(footPrints) {};
00156     virtual ~PublisherA() { 
00157       m_footPrints += "a"; 
00158     }
00159 
00160     void update() { m_footPrints += "A"; }
00161           
00162     std::string& m_footPrints;
00163     // std::string m_footPrints;
00164   };
00170   class PublisherB
00171     : public RTC::PublisherBase
00172   {
00173   public:
00174     std::string& m_footPrints;
00175     // std::string m_footPrints;
00176     PublisherB(std::string& footPrints) : m_footPrints(footPrints) {};
00177     virtual ~PublisherB() { 
00178       m_footPrints += "b"; 
00179     }
00180     void update() { m_footPrints += "B"; }
00181   };
00187   class PublisherC
00188     : public RTC::PublisherBase
00189   {
00190   public:
00191     std::string& m_footPrints;
00192     //    std::string m_footPrints;
00193     PublisherC(std::string& footPrints) : m_footPrints(footPrints) {};
00194     virtual ~PublisherC() {
00195       m_footPrints += "c";
00196     }
00197     void update() { m_footPrints += "C"; }
00198   };
00204   class PublisherD
00205     : public RTC::PublisherBase
00206   {
00207   public:
00208     std::string& m_footPrints;
00209     // std::string m_footPrints;
00210     PublisherD(std::string& footPrints) : m_footPrints(footPrints) {};
00211     virtual ~PublisherD() {
00212       m_footPrints += "d";
00213     }
00214     void update() { m_footPrints += "D"; }
00215   };
00221   class Logger
00222   {
00223   public:
00224     void log(const std::string& msg)
00225     {
00226       m_log.push_back(msg);
00227     }
00228 
00229     int countLog(const std::string& msg)
00230     {
00231       int count = 0;
00232       for (int i = 0; i < (int) m_log.size(); ++i)
00233         {
00234           if (m_log[i] == msg) ++count;
00235         }
00236       return count;
00237     }
00238                 
00239     void clearLog(void)
00240     {
00241         m_log.clear();
00242     }
00243   private:
00244     std::vector<std::string> m_log;
00245   };
00251   template <class DataType>
00252   class RingBufferMock
00253     : public RTC::BufferBase<DataType>
00254   {
00255   public:
00256     BUFFERSTATUS_ENUM
00257       RingBufferMock(long int length = 8)
00258       {
00259           m_logger = NULL;
00260           logger.log("RingBufferMock::Constructor");
00261           m_read_return_value = BUFFER_OK;
00262       }
00263       virtual ~RingBufferMock(void)
00264       {
00265       }
00266   
00267     
00272       void set_read_return_value(::RTC::BufferStatus::Enum value)
00273       {
00274           m_read_return_value = value;
00275       }
00280       virtual void init(const coil::Properties& prop)
00281       {
00282       }
00287       virtual size_t length(void) const
00288       {
00289           return 0;
00290       }
00295       virtual ReturnCode length(size_t n)
00296       {
00297           return ::RTC::BufferStatus::BUFFER_OK; //BUFFER_OK;
00298       }
00303       virtual ReturnCode reset()
00304       {
00305           return ::RTC::BufferStatus::BUFFER_OK; //BUFFER_OK;
00306       }
00311       virtual DataType* wptr(long int n = 0)
00312       {
00313           return &m_data;
00314       }
00319       virtual ReturnCode advanceWptr(long int n = 1)
00320       {
00321           return ::RTC::BufferStatus::BUFFER_OK; //BUFFER_OK;
00322       }
00327       virtual ReturnCode put(const DataType& value)
00328       {
00329           return ::RTC::BufferStatus::BUFFER_OK; //BUFFER_OK;
00330       }
00335       virtual ReturnCode write(const DataType& value,
00336                                long int sec = -1, long int nsec = -1)
00337       {
00338           return ::RTC::BufferStatus::BUFFER_OK; //BUFFER_OK;
00339       }
00344       virtual size_t writable() const
00345       {
00346           return 0;
00347       }
00352       virtual bool full(void) const
00353       {
00354           return true;
00355       }
00360       virtual DataType* rptr(long int n = 0)
00361       {
00362           return &m_data;
00363       }
00368       virtual ReturnCode advanceRptr(long int n = 1)
00369       {
00370           return ::RTC::BufferStatus::BUFFER_OK; //BUFFER_OK;
00371       }
00376       virtual ReturnCode get(DataType& value)
00377       {
00378           return ::RTC::BufferStatus::BUFFER_OK; //BUFFER_OK;
00379       }
00384       virtual DataType&  get()
00385       {
00386           return m_data;
00387       }
00392       virtual ReturnCode read(DataType& value,
00393                               long int sec = -1, long int nsec = -1)
00394       {
00395           if (m_logger != NULL)
00396           {
00397               m_logger->log("RingBufferMock::read");
00398           }
00399           logger.log("RingBufferMock::read");
00400           return m_read_return_value; //BUFFER_OK;
00401       }
00406       virtual size_t readable() const
00407       {
00408           return 0;
00409       }
00414       virtual bool empty(void) const
00415       {
00416           return true;
00417       }
00422       void setLogger(Logger* logger)
00423       {
00424           m_logger = logger;
00425       }
00426 
00427       static Logger logger;
00428   private:
00429       DataType m_data;
00430       std::vector<DataType> m_buffer;
00431       Logger* m_logger;
00432       ::RTC::BufferStatus::Enum m_read_return_value;
00433   };
00434   template <class DataType>
00435   Logger RingBufferMock<DataType>::logger;
00436   typedef RingBufferMock<cdrMemoryStream> CdrRingBufferMock;
00442   class OutPortBaseMock
00443     : public RTC::OutPortBase
00444   {
00445   public:
00450       OutPortBaseMock(const char* name, const char* data_type)
00451         : RTC::OutPortBase(name , data_type)
00452       {
00453       }
00457       coil::Properties get_m_properties()
00458       {
00459           return m_properties;
00460       }
00464       RTC::OutPortProvider* createProvider_public(RTC::ConnectorProfile& cprof,
00465                                       coil::Properties& prop)
00466       {
00467           return createProvider(cprof, prop);
00468       }
00472       RTC::InPortConsumer* createCondumer_public(RTC::ConnectorProfile& cprof,
00473                                       coil::Properties& prop)
00474       {
00475           return createConsumer(cprof, prop);
00476       }
00480       RTC::OutPortConnector* createConnector_public(const RTC::ConnectorProfile& cprof,
00481                                       coil::Properties& prop,
00482                                       RTC::OutPortProvider* provider)
00483       {
00484           return createConnector(cprof,prop,provider);
00485       }
00489       virtual RTC::ReturnCode_t
00490       publishInterfaces_public(RTC::ConnectorProfile& connector_profile)
00491        {
00492           return publishInterfaces(connector_profile);
00493        } 
00497       virtual RTC::ReturnCode_t
00498       subscribeInterfaces_public(RTC::ConnectorProfile& connector_profile)
00499        {
00500           return subscribeInterfaces(connector_profile);
00501        } 
00506       coil::vstring get_m_consumerTypes()
00507       {
00508           return m_consumerTypes;
00509       }
00514       coil::vstring get_m_providerTypes()
00515       {
00516           return m_providerTypes;
00517       }
00521       void initConsumers_public(void)
00522       {
00523           initConsumers();
00524       }
00528       void initProviders_public(void)
00529       {
00530           initProviders();
00531       }
00536       ConnectorList get_m_connectors()
00537       {
00538           return m_connectors;
00539       }
00545       bool write()
00546       {
00547           return true;
00548       }
00549 
00550      
00551   };
00557   template <class DataType>
00558   class InPortMock
00559     : public RTC::InPortBase
00560   {
00561   public:
00562     InPortMock(const char* name, DataType& value) 
00563      : InPortBase(name,toTypename<DataType>()) {}
00567     virtual RTC::ReturnCode_t
00568     publishInterfaces_public(RTC::ConnectorProfile& connector_profile)
00569      {
00570         return publishInterfaces(connector_profile);
00571      } 
00575     virtual RTC::ReturnCode_t
00576     subscribeInterfaces_public(RTC::ConnectorProfile& connector_profile)
00577      {
00578         return subscribeInterfaces(connector_profile);
00579      } 
00583      bool read()
00584      {
00585         return true;
00586      }
00587 
00588   };
00589 
00595   class InPortCorbaCdrConsumerMock
00596     : public RTC::InPortConsumer,
00597       public RTC::CorbaConsumer< ::OpenRTM::InPortCdr >
00598   {
00599 
00600   public:
00601       InPortCorbaCdrConsumerMock(void)
00602        {
00603           m_logger = NULL;
00604        }
00605       virtual ~InPortCorbaCdrConsumerMock(void)
00606       {
00607       }
00612       void init(coil::Properties& prop)
00613       {
00614           if (m_logger != NULL)
00615           {
00616               m_logger->log("InPortCorbaCdrConsumerMock::init");
00617           }
00618       }
00623       RTC::InPortConsumer::ReturnCode put(const cdrMemoryStream& data)
00624       {
00625           return PORT_OK;
00626       }
00631       void publishInterfaceProfile(SDOPackage::NVList& properties)
00632       {
00633           return;
00634       }
00635 
00640       bool subscribeInterface(const SDOPackage::NVList& properties)
00641       {
00642     
00643           return true;;
00644       }
00645   
00650       void unsubscribeInterface(const SDOPackage::NVList& properties)
00651       {
00652       }
00653   
00654       bool subscribeFromIor(const SDOPackage::NVList& properties)
00655       {
00656     
00657           return true;;
00658       }
00659       bool subscribeFromRef(const SDOPackage::NVList& properties)
00660       {
00661     
00662           return true;;
00663       }
00664       bool unsubscribeFromIor(const SDOPackage::NVList& properties)
00665       {
00666     
00667           return true;;
00668       }
00669       bool unsubscribeFromRef(const SDOPackage::NVList& properties)
00670       {
00671     
00672           return true;;
00673       }
00674     
00679       void setLogger(Logger* logger)
00680       {
00681           m_logger = logger;
00682       }
00683   private:
00684     Logger* m_logger;
00685 
00686   };
00692   class OutPortCorbaCdrProviderMock
00693     : public RTC::OutPortProvider,
00694       public virtual ::POA_OpenRTM::OutPortCdr,
00695       public virtual PortableServer::RefCountServantBase
00696   {
00697 
00698   public:
00699       OutPortCorbaCdrProviderMock(void)
00700        {
00701           setInterfaceType("corba_cdr");
00702           m_logger = NULL;
00703        }
00704       virtual ~OutPortCorbaCdrProviderMock(void)
00705       {
00706       }
00711       void init(coil::Properties& prop)
00712       {
00713           if (m_logger != NULL)
00714           {
00715               m_logger->log("OutPortCorbaCdrProviderMock::init");
00716           }
00717       }
00718 
00723       void setBuffer(RTC::CdrBufferBase* buffer)
00724       {
00725         if (m_logger != NULL)
00726         {
00727           m_logger->log("OutPortCorbaCdrProviderMock::setBuffer");
00728         }
00729       }
00730   
00731       void setListener(RTC::ConnectorInfo& info,
00732                      RTC::ConnectorListeners* listeners)
00733       {
00734         // m_profile = info;
00735         // m_listeners = listeners;
00736       }
00737       void setConnector(RTC::OutPortConnector* connector)
00738       {
00739         // m_connector = connector;
00740       }
00741 
00746       virtual ::OpenRTM::PortStatus get(::OpenRTM::CdrData_out data)
00747       {
00748           return ::OpenRTM::PORT_OK;
00749       }
00754       RTC::InPortConsumer::ReturnCode put(const cdrMemoryStream& data)
00755       {
00756           return PORT_OK;
00757       }
00762       void publishInterfaceProfile(SDOPackage::NVList& properties)
00763       {
00764           return;
00765       }
00766 
00771       bool subscribeInterface(const SDOPackage::NVList& properties)
00772       {
00773     
00774           return true;;
00775       }
00776   
00781       void unsubscribeInterface(const SDOPackage::NVList& properties)
00782       {
00783       }
00788       bool publishInterface(SDOPackage::NVList& prop)
00789       {
00790           return true;
00791       }
00792   
00797       void setLogger(Logger* logger)
00798       {
00799           m_logger = logger;
00800       }
00801   private:
00802     Logger* m_logger;
00803 
00804   };
00805 };
00806 namespace RTC 
00807 {
00813   ::OutPortBase::Logger logger;
00814 };
00815 namespace OutPortBase
00816 {
00822   class OutPortBaseTests
00823     : public CppUnit::TestFixture
00824   {
00825     CPPUNIT_TEST_SUITE(OutPortBaseTests);
00826 
00827     CPPUNIT_TEST(test_constructor);
00828     CPPUNIT_TEST(test_initConsumers);
00829     CPPUNIT_TEST(test_initConsumers2);//Consumers are not registered in Factory.
00830     CPPUNIT_TEST(test_initProviders);
00831     CPPUNIT_TEST(test_initProviders2);//Providers are not registered in Factory.
00832     CPPUNIT_TEST(test_init_properties);
00833     CPPUNIT_TEST(test_name);
00834     CPPUNIT_TEST(test_connectors_getConnectorXX);
00835     CPPUNIT_TEST(test_activateInterfaces_deactivateInterfaces);
00836     CPPUNIT_TEST(test_publishInterfaces);
00837     CPPUNIT_TEST(test_publishInterfaces2);//dataport.dataflow_type is "push" 
00838     CPPUNIT_TEST(test_publishInterfaces3);//dataport.dataflow_type is "else" 
00839     CPPUNIT_TEST(test_publishInterfaces4);//Provider is deleted.  
00840     CPPUNIT_TEST(test_publishInterfaces5);
00841     CPPUNIT_TEST(test_subscribeInterfaces);
00842     CPPUNIT_TEST(test_subscribeInterfaces2);//dataport.dataflow_type is "pull"
00843     CPPUNIT_TEST(test_subscribeInterfaces3);//dataport.dataflow_type is "else"
00844     CPPUNIT_TEST(test_subscribeInterfaces4);//Consumer is deleted.
00845     CPPUNIT_TEST(test_subscribeInterfaces5);
00846     CPPUNIT_TEST(test_ConnectorListener);
00847 
00848     CPPUNIT_TEST_SUITE_END();
00849         
00850   private:
00851     CORBA::ORB_ptr m_pORB;
00852     PortableServer::POA_ptr m_pPOA;
00853     RTC::ConnectorListeners m_listeners;
00854     DataListener *m_datalisteners[cdl_len];
00855     ConnListener *m_connlisteners[cl_len];
00856 
00857   public:
00858     RTC::Logger rtclog;
00859         
00863     OutPortBaseTests()
00864     : rtclog("The unit test for OutPortBase")
00865     {
00866         int argc(0);
00867         char** argv(NULL);
00868         m_pORB = CORBA::ORB_init(argc, argv);
00869         m_pPOA = PortableServer::POA::_narrow(
00870                     m_pORB->resolve_initial_references("RootPOA"));
00871         m_pPOA->the_POAManager()->activate();
00872         rtclog.setLevel("PARANOID");
00873     }
00874                 
00878     ~OutPortBaseTests()
00879     {
00880     }
00881                 
00885     virtual void setUp()
00886     {
00887         //既に "corba_cdr" で登録されている場合は削除する。
00888         if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") )
00889         {
00890             RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr");
00891         }
00892         //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。
00893         RTC::InPortConsumerFactory::instance().
00894         addFactory("corba_cdr",
00895                    ::coil::Creator< ::RTC::InPortConsumer, 
00896                                     InPortCorbaCdrConsumerMock>,
00897                    ::coil::Destructor< ::RTC::InPortConsumer, 
00898                                        InPortCorbaCdrConsumerMock>);
00899 
00900         //既に "corba_cdr" で登録されている場合は削除する。
00901         if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") )
00902         {
00903             RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr");
00904         }
00905         //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。
00906         RTC::OutPortProviderFactory::instance().
00907         addFactory("corba_cdr",
00908                    ::coil::Creator< ::RTC::OutPortProvider, 
00909                                     OutPortCorbaCdrProviderMock>,
00910                    ::coil::Destructor< ::RTC::OutPortProvider, 
00911                                        OutPortCorbaCdrProviderMock>);
00912 
00913 
00914         //既に "subscription_type" 登録されている場合は削除する。
00915         if( RTC::PublisherFactory::instance().hasFactory("new") )
00916         {
00917             RTC::PublisherFactory::instance().removeFactory("new");
00918         }
00919         ::RTC::PublisherFactory::
00920         instance().addFactory("new",
00921                               ::coil::Creator< ::RTC::PublisherBase,
00922                                                ::RTC::PublisherNew>,
00923                               ::coil::Destructor< ::RTC::PublisherBase,
00924                                                   ::RTC::PublisherNew>);
00925 
00926         if( RTC::PublisherFactory::instance().hasFactory("periodic") )
00927         {
00928             RTC::PublisherFactory::instance().removeFactory("periodic");
00929         }
00930         ::RTC::PublisherFactory::
00931         instance().addFactory("periodic",
00932                               ::coil::Creator< ::RTC::PublisherBase,
00933                                                ::RTC::PublisherPeriodic>,
00934                               ::coil::Destructor< ::RTC::PublisherBase,
00935                                                   ::RTC::PublisherPeriodic>);
00936 
00937         if( RTC::PublisherFactory::instance().hasFactory("flush") )
00938         {
00939             RTC::PublisherFactory::instance().removeFactory("flush");
00940         }
00941         ::RTC::PublisherFactory::
00942         instance().addFactory("flush",
00943                               ::coil::Creator< ::RTC::PublisherBase,
00944                                                ::RTC::PublisherFlush>,
00945                               ::coil::Destructor< ::RTC::PublisherBase,
00946                                                   ::RTC::PublisherFlush>);
00947     }
00948                 
00952     virtual void tearDown()
00953     { 
00954     }
00955                 
00960     void test_constructor()
00961     {
00962         //既に "corba_cdr" で登録されている場合は削除する。
00963         if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") )
00964         {
00965             RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr");
00966         }
00967         //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。
00968         RTC::InPortConsumerFactory::instance().
00969         addFactory("corba_cdr",
00970                    ::coil::Creator< ::RTC::InPortConsumer, 
00971                                     InPortCorbaCdrConsumerMock>,
00972                    ::coil::Destructor< ::RTC::InPortConsumer, 
00973                                        InPortCorbaCdrConsumerMock>);
00974 
00975         //既に "corba_cdr" で登録されている場合は削除する。
00976         if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") )
00977         {
00978             RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr");
00979         }
00980         //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。
00981         RTC::OutPortProviderFactory::instance().
00982         addFactory("corba_cdr",
00983                    ::coil::Creator< ::RTC::OutPortProvider, 
00984                                     OutPortCorbaCdrProviderMock>,
00985                    ::coil::Destructor< ::RTC::OutPortProvider, 
00986                                        OutPortCorbaCdrProviderMock>);
00987 
00988 
00989         //既に "subscription_type" 登録されている場合は削除する。
00990         if( RTC::PublisherFactory::instance().hasFactory("new") )
00991         {
00992             RTC::PublisherFactory::instance().removeFactory("new");
00993         }
00994         if( RTC::PublisherFactory::instance().hasFactory("periodic") )
00995         {
00996             RTC::PublisherFactory::instance().removeFactory("periodic");
00997         }
00998         if( RTC::PublisherFactory::instance().hasFactory("flush") )
00999         {
01000             RTC::PublisherFactory::instance().removeFactory("flush");
01001         }
01002 
01003         {
01004             OutPortBaseMock outPort("OutPortBaseTest", 
01005                                     toTypename<RTC::TimedFloat>());
01006 
01007             RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
01008             portAdmin.registerPort(outPort); 
01009         
01010             RTC::PortProfile profile = outPort.getPortProfile();
01011             coil::Properties prop = NVUtil::toProperties(profile.properties);
01012             CPPUNIT_ASSERT_EQUAL(std::string("DataOutPort"), 
01013                                  prop["port.port_type"] );
01014             CPPUNIT_ASSERT_EQUAL(std::string(toTypename<RTC::TimedFloat>()),
01015                                  prop["dataport.data_type"] );
01016             CPPUNIT_ASSERT_EQUAL(std::string(""),
01017                                  prop["dataport.subscription_type"]);
01018 
01019             portAdmin.deletePort(outPort);
01020         }
01021         ::RTC::PublisherFactory::
01022         instance().addFactory("flush",
01023                               ::coil::Creator< ::RTC::PublisherBase,
01024                                                ::RTC::PublisherFlush>,
01025                               ::coil::Destructor< ::RTC::PublisherBase,
01026                                                   ::RTC::PublisherFlush>);
01027         {
01028             OutPortBaseMock outPort("OutPortBaseTest", 
01029                                     toTypename<RTC::TimedFloat>());
01030 
01031             RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
01032             portAdmin.registerPort(outPort); 
01033         
01034             RTC::PortProfile profile = outPort.getPortProfile();
01035             coil::Properties prop = NVUtil::toProperties(profile.properties);
01036             CPPUNIT_ASSERT_EQUAL(std::string("DataOutPort"), 
01037                                  prop["port.port_type"] );
01038             CPPUNIT_ASSERT_EQUAL(std::string(toTypename<RTC::TimedFloat>()),
01039                                  prop["dataport.data_type"] );
01040             CPPUNIT_ASSERT_EQUAL(std::string("flush"),
01041                                  prop["dataport.subscription_type"]);
01042 
01043             portAdmin.deletePort(outPort);
01044         }
01045 
01046         ::RTC::PublisherFactory::
01047         instance().addFactory("new",
01048                               ::coil::Creator< ::RTC::PublisherBase,
01049                                                ::RTC::PublisherNew>,
01050                               ::coil::Destructor< ::RTC::PublisherBase,
01051                                                   ::RTC::PublisherNew>);
01052         {
01053             OutPortBaseMock outPort("OutPortBaseTest", 
01054                                     toTypename<RTC::TimedFloat>());
01055 
01056             RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
01057             portAdmin.registerPort(outPort); 
01058         
01059             RTC::PortProfile profile = outPort.getPortProfile();
01060             coil::Properties prop = NVUtil::toProperties(profile.properties);
01061             CPPUNIT_ASSERT_EQUAL(std::string("DataOutPort"), 
01062                                  prop["port.port_type"] );
01063             CPPUNIT_ASSERT_EQUAL(std::string(toTypename<RTC::TimedFloat>()),
01064                                  prop["dataport.data_type"] );
01065             CPPUNIT_ASSERT_EQUAL(std::string("flush,new"),
01066                                  prop["dataport.subscription_type"]);
01067 
01068             portAdmin.deletePort(outPort);
01069         }
01070         ::RTC::PublisherFactory::
01071         instance().addFactory("periodic",
01072                               ::coil::Creator< ::RTC::PublisherBase,
01073                                                ::RTC::PublisherPeriodic>,
01074                               ::coil::Destructor< ::RTC::PublisherBase,
01075                                                   ::RTC::PublisherPeriodic>);
01076         {
01077             OutPortBaseMock outPort("OutPortBaseTest", 
01078                                     toTypename<RTC::TimedFloat>());
01079 
01080             RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
01081             portAdmin.registerPort(outPort); 
01082         
01083             RTC::PortProfile profile = outPort.getPortProfile();
01084             coil::Properties prop = NVUtil::toProperties(profile.properties);
01085             CPPUNIT_ASSERT_EQUAL(std::string("DataOutPort"), 
01086                                  prop["port.port_type"] );
01087             CPPUNIT_ASSERT_EQUAL(std::string(toTypename<RTC::TimedFloat>()),
01088                                  prop["dataport.data_type"] );
01089             CPPUNIT_ASSERT_EQUAL(std::string("flush,new,periodic"),
01090                                  prop["dataport.subscription_type"]);
01091 
01092             portAdmin.deletePort(outPort);
01093         }
01094     }
01099     void test_initConsumers()
01100     {
01101         //既に "corba_cdr" で登録されている場合は削除する。
01102         if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") )
01103         {
01104             RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr");
01105         }
01106 
01107         //既に "corba_cdr" で登録されている場合は削除する。
01108         if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") )
01109         {
01110             RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr");
01111         }
01112 
01113         OutPortBaseMock outPort("OutPortBaseTest", 
01114                                 toTypename<RTC::TimedFloat>());
01115 
01116         RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
01117         portAdmin.registerPort(outPort); 
01118 
01119         //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。
01120         RTC::InPortConsumerFactory::instance().
01121         addFactory("corba_cdr",
01122                    ::coil::Creator< ::RTC::InPortConsumer, 
01123                                     InPortCorbaCdrConsumerMock>,
01124                    ::coil::Destructor< ::RTC::InPortConsumer, 
01125                                        InPortCorbaCdrConsumerMock>);
01126         //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。
01127         RTC::OutPortProviderFactory::instance().
01128         addFactory("corba_cdr",
01129                    ::coil::Creator< ::RTC::OutPortProvider, 
01130                                     OutPortCorbaCdrProviderMock>,
01131                    ::coil::Destructor< ::RTC::OutPortProvider, 
01132                                        OutPortCorbaCdrProviderMock>);
01133 
01134         RTC::PortProfile profile = outPort.getPortProfile();
01135         coil::Properties prop = NVUtil::toProperties(profile.properties);
01136         CPPUNIT_ASSERT_EQUAL(std::string(""),
01137                              prop["dataport.dataflow_type"]);
01138         CPPUNIT_ASSERT_EQUAL(std::string(""),
01139                              prop["dataport.interface_type"]);
01140 
01141         coil::vstring cstr = outPort.get_m_consumerTypes();
01142         CPPUNIT_ASSERT_EQUAL((size_t)0, cstr.size());
01143 
01144         outPort.initConsumers_public();
01145 
01146         profile = outPort.getPortProfile();
01147         prop = NVUtil::toProperties(profile.properties);
01148 
01149         //getPortProfileのpropertiesに以下が追加される
01150         CPPUNIT_ASSERT_EQUAL(std::string("push"),
01151                              prop["dataport.dataflow_type"]);
01152         CPPUNIT_ASSERT_EQUAL(std::string("corba_cdr"),
01153                              prop["dataport.interface_type"]);
01154  
01155         //ProviderTypes,ConsumerTypesが取得される
01156         cstr = outPort.get_m_consumerTypes();
01157         CPPUNIT_ASSERT((size_t)0!= cstr.size());
01158         CPPUNIT_ASSERT_EQUAL(std::string("corba_cdr"),
01159                              cstr[0]);
01160 
01161         portAdmin.deletePort(outPort);
01162     }
01167     void test_initConsumers2()
01168     {
01169         //既に "corba_cdr" で登録されている場合は削除する。
01170         if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") )
01171         {
01172             RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr");
01173         }
01174 
01175         //既に "corba_cdr" で登録されている場合は削除する。
01176         if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") )
01177         {
01178             RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr");
01179         }
01180 
01181         OutPortBaseMock outPort("OutPortBaseTest", 
01182                                 toTypename<RTC::TimedFloat>());
01183 
01184         RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
01185         portAdmin.registerPort(outPort); 
01186 
01187         //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。
01188         RTC::OutPortProviderFactory::instance().
01189         addFactory("corba_cdr",
01190                    ::coil::Creator< ::RTC::OutPortProvider, 
01191                                     OutPortCorbaCdrProviderMock>,
01192                    ::coil::Destructor< ::RTC::OutPortProvider, 
01193                                        OutPortCorbaCdrProviderMock>);
01194 
01195         RTC::PortProfile profile = outPort.getPortProfile();
01196         coil::Properties prop = NVUtil::toProperties(profile.properties);
01197         CPPUNIT_ASSERT_EQUAL(std::string(""),
01198                              prop["dataport.dataflow_type"]);
01199         CPPUNIT_ASSERT_EQUAL(std::string(""),
01200                              prop["dataport.interface_type"]);
01201 
01202         coil::vstring cstr = outPort.get_m_consumerTypes();
01203         CPPUNIT_ASSERT_EQUAL((size_t)0, cstr.size());
01204 
01205         outPort.initConsumers_public();
01206 
01207         profile = outPort.getPortProfile();
01208         prop = NVUtil::toProperties(profile.properties);
01209 
01210         //getPortProfileのpropertiesに以下が追加される
01211         CPPUNIT_ASSERT_EQUAL(std::string(""),
01212                              prop["dataport.dataflow_type"]);
01213         CPPUNIT_ASSERT_EQUAL(std::string(""),
01214                              prop["dataport.interface_type"]);
01215  
01216         //ProviderTypes,ConsumerTypesが取得される
01217         cstr = outPort.get_m_consumerTypes();
01218         CPPUNIT_ASSERT((size_t)0== cstr.size());
01219 
01220         portAdmin.deletePort(outPort);
01221     }
01226     void test_initProviders()
01227     {
01228         //既に "corba_cdr" で登録されている場合は削除する。
01229         if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") )
01230         {
01231             RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr");
01232         }
01233 
01234         //既に "corba_cdr" で登録されている場合は削除する。
01235         if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") )
01236         {
01237             RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr");
01238         }
01239 
01240         OutPortBaseMock outPort("OutPortBaseTest", 
01241                                 toTypename<RTC::TimedFloat>());
01242 
01243         RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
01244         portAdmin.registerPort(outPort); 
01245 
01246         //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。
01247         RTC::InPortConsumerFactory::instance().
01248         addFactory("corba_cdr",
01249                    ::coil::Creator< ::RTC::InPortConsumer, 
01250                                     InPortCorbaCdrConsumerMock>,
01251                    ::coil::Destructor< ::RTC::InPortConsumer, 
01252                                        InPortCorbaCdrConsumerMock>);
01253         //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。
01254         RTC::OutPortProviderFactory::instance().
01255         addFactory("corba_cdr",
01256                    ::coil::Creator< ::RTC::OutPortProvider, 
01257                                     OutPortCorbaCdrProviderMock>,
01258                    ::coil::Destructor< ::RTC::OutPortProvider, 
01259                                        OutPortCorbaCdrProviderMock>);
01260 
01261         RTC::PortProfile profile = outPort.getPortProfile();
01262         coil::Properties prop = NVUtil::toProperties(profile.properties);
01263         CPPUNIT_ASSERT_EQUAL(std::string(""),
01264                              prop["dataport.dataflow_type"]);
01265         CPPUNIT_ASSERT_EQUAL(std::string(""),
01266                              prop["dataport.interface_type"]);
01267 
01268         coil::vstring cstr = outPort.get_m_providerTypes();
01269         CPPUNIT_ASSERT_EQUAL((size_t)0, cstr.size());
01270 
01271         outPort.initProviders_public();
01272 
01273         profile = outPort.getPortProfile();
01274         prop = NVUtil::toProperties(profile.properties);
01275 
01276         //getPortProfileのpropertiesに以下が追加される
01277         CPPUNIT_ASSERT_EQUAL(std::string("pull"),
01278                              prop["dataport.dataflow_type"]);
01279         CPPUNIT_ASSERT_EQUAL(std::string("corba_cdr"),
01280                              prop["dataport.interface_type"]);
01281  
01282         //ProviderTypes,ConsumerTypesが取得される
01283         cstr = outPort.get_m_providerTypes();
01284         CPPUNIT_ASSERT((size_t)0!= cstr.size());
01285         CPPUNIT_ASSERT_EQUAL(std::string("corba_cdr"),
01286                              cstr[0]);
01287 
01288         portAdmin.deletePort(outPort);
01289     }
01294     void test_initProviders2()
01295     {
01296         //既に "corba_cdr" で登録されている場合は削除する。
01297         if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") )
01298         {
01299             RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr");
01300         }
01301 
01302         //既に "corba_cdr" で登録されている場合は削除する。
01303         if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") )
01304         {
01305             RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr");
01306         }
01307 
01308         OutPortBaseMock outPort("OutPortBaseTest", 
01309                                 toTypename<RTC::TimedFloat>());
01310 
01311         RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
01312         portAdmin.registerPort(outPort); 
01313 
01314         //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。
01315         RTC::InPortConsumerFactory::instance().
01316         addFactory("corba_cdr",
01317                    ::coil::Creator< ::RTC::InPortConsumer, 
01318                                     InPortCorbaCdrConsumerMock>,
01319                    ::coil::Destructor< ::RTC::InPortConsumer, 
01320                                        InPortCorbaCdrConsumerMock>);
01321 
01322         RTC::PortProfile profile = outPort.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 cstr = outPort.get_m_providerTypes();
01330         CPPUNIT_ASSERT_EQUAL((size_t)0, cstr.size());
01331 
01332         outPort.initProviders_public();
01333 
01334         profile = outPort.getPortProfile();
01335         prop = NVUtil::toProperties(profile.properties);
01336 
01337         //getPortProfileのpropertiesに以下が追加される
01338         CPPUNIT_ASSERT_EQUAL(std::string(""),
01339                              prop["dataport.dataflow_type"]);
01340         CPPUNIT_ASSERT_EQUAL(std::string(""),
01341                              prop["dataport.interface_type"]);
01342  
01343         //ProviderTypes,ConsumerTypesが取得される
01344         cstr = outPort.get_m_providerTypes();
01345         CPPUNIT_ASSERT((size_t)0== cstr.size());
01346 
01347         portAdmin.deletePort(outPort);
01348     }
01353     void test_init_properties()
01354     {
01355         OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedDouble>());
01356 
01357         coil::Properties prop;
01358         prop["dataport.interface_type"] = "corba_cdr";
01359         prop["dataport.dataflow_type"] = "pull";
01360         prop["dataport.subscription_type"] = "new";
01361 
01362         RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
01363         portAdmin.registerPort(outPort); 
01364 
01365         outPort.init(prop);
01366 
01367         coil::Properties prop2 = outPort.get_m_properties();
01368         CPPUNIT_ASSERT_EQUAL(prop.size(), prop2.size());
01369           
01370         CPPUNIT_ASSERT_EQUAL(prop["dataport.interface_type"],
01371                              prop2["dataport.interface_type"]);
01372         CPPUNIT_ASSERT_EQUAL(prop["dataport.dataflow_type"],
01373                              prop2["dataport.dataflow_type"]);
01374         CPPUNIT_ASSERT_EQUAL(prop["dataport.subscription_type"],
01375                              prop2["dataport.subscription_type"]);
01376 
01377         prop2 = outPort.properties();
01378         CPPUNIT_ASSERT_EQUAL(prop.size(), prop2.size());
01379           
01380         CPPUNIT_ASSERT_EQUAL(prop["dataport.interface_type"],
01381                              prop2["dataport.interface_type"]);
01382         CPPUNIT_ASSERT_EQUAL(prop["dataport.dataflow_type"],
01383                              prop2["dataport.dataflow_type"]);
01384         CPPUNIT_ASSERT_EQUAL(prop["dataport.subscription_type"],
01385                              prop2["dataport.subscription_type"]);
01386 
01387         portAdmin.deletePort(outPort);
01388     }
01394     void test_name()
01395     {
01396         OutPortBaseMock outPort("Hello, World!", toTypename<RTC::TimedDouble>());
01397 
01398         RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
01399         portAdmin.registerPort(outPort); 
01400 
01401         CPPUNIT_ASSERT_EQUAL(std::string("unknown.Hello, World!"), std::string(outPort.getName()));
01402         portAdmin.deletePort(outPort);
01403     }
01404                 
01409     void test_connectors_getConnectorXX(void)
01410     {
01411         RTC::TimedDouble inbindValue;
01412         InPortMock<RTC::TimedDouble> inPort("in:OutPortBaseTest",inbindValue);
01413 
01414         OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedDouble>());
01415 
01416         RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
01417         portAdmin.registerPort(outPort); 
01418         portAdmin.registerPort(inPort); 
01419 
01420         RTC::ConnectorProfile inprof;
01421         inprof.ports.length(1);
01422         inprof.ports[0] = outPort.get_port_profile()->port_ref;
01423         CORBA_SeqUtil::push_back(inprof.properties,
01424                                  NVUtil::newNV("dataport.interface_type",
01425                                  "corba_cdr"));
01426         CORBA_SeqUtil::push_back(inprof.properties,
01427                                  NVUtil::newNV("dataport.dataflow_type",
01428                                  "push"));
01429         CORBA_SeqUtil::push_back(inprof.properties,
01430                                  NVUtil::newNV("dataport.subscription_type",
01431                                  "flush"));
01432         inprof.connector_id = "id0";
01433         inprof.name = CORBA::string_dup("bar");
01434 
01435         coil::Properties dummy;
01436         inPort.init(dummy);
01437         outPort.init(dummy);
01438 
01439         inPort.publishInterfaces_public(inprof);
01440 
01441         std::string vstrid[10] = {"id0","id1","id2","id3","id4",
01442                                   "id5","id6","id7","id8","id9"};
01443         std::string vstrname[10] = {"foo0","foo1","foo2","foo3","foo4",
01444                                     "foo5","foo6","foo7","foo8","foo9"};
01445 
01446         std::string vstrinterface[10] = {"corba_cdr","corba_cdr","corba_cdr",
01447                                          "corba_cdr","corba_cdr","corba_cdr",
01448                                          "corba_cdr","corba_cdr","corba_cdr",
01449                                          "corba_cdr"};
01450         std::string vstrdataflow[10] = {"push","push","push",
01451                                          "push","push","push",
01452                                          "pull","pull","pull","pull"};
01453 
01454         std::string vstrsubscription[10] = {"flush","flush","flush",
01455                                             "flush","flush","flush",
01456                                             "flush","flush","flush","flush"};
01457         
01458         //
01459         //connectors()
01460         //
01461         for(int ic(0);ic<10;++ic)
01462         {
01463             RTC::ConnectorProfile prof;
01464             prof.ports.length(1);
01465             prof.ports[0] = outPort.get_port_profile()->port_ref;
01466             CORBA_SeqUtil::push_back(prof.properties,
01467                                      NVUtil::newNV("dataport.interface_type",
01468                                                    vstrinterface[ic].c_str()));
01469             CORBA_SeqUtil::push_back(prof.properties,
01470                                      NVUtil::newNV("dataport.dataflow_type",
01471                                                    vstrdataflow[ic].c_str()));
01472             CORBA_SeqUtil::push_back(prof.properties,
01473                                      NVUtil::newNV("dataport.subscription_type",
01474                                                    vstrsubscription[ic].c_str()));
01475             CORBA_SeqUtil::push_back(prof.properties,
01476                                      NVUtil::newNV("dataport.corba_cdr.inport_ior",
01477                                      NVUtil::toString(inprof.properties,"dataport.corba_cdr.inport_ior").c_str()));
01478             prof.connector_id = vstrid[ic].c_str();
01479             prof.name = CORBA::string_dup(vstrname[ic].c_str());
01480 
01481 
01482             coil::Properties prop(outPort.properties());
01483             coil::Properties conn_prop;
01484             NVUtil::copyToProperties(conn_prop, prof.properties);
01485             prop << conn_prop.getNode("dataport"); // marge ConnectorProfile
01486             RTC::OutPortProvider* provider(outPort.createProvider_public(prof, prop));
01487             outPort.createConnector_public(prof,prop,provider);
01488 
01489             std::vector<RTC::OutPortConnector*> objs = outPort.connectors();
01490 
01491             CPPUNIT_ASSERT_EQUAL((size_t)(ic+1), objs.size());
01492             CPPUNIT_ASSERT_EQUAL(vstrid[ic], std::string(objs[ic]->id()));
01493             CPPUNIT_ASSERT_EQUAL(vstrname[ic], std::string(objs[ic]->name()));
01494         }
01495 
01496         //
01497         //getConnectorProfiles()
01498         //
01499         RTC::ConnectorInfoList list = outPort.getConnectorProfiles();
01500         CPPUNIT_ASSERT_EQUAL((size_t)10, list.size());
01501         for(int ic(0);ic<10;++ic)
01502         {
01503             CPPUNIT_ASSERT_EQUAL(vstrid[ic], std::string(list[ic].id));
01504             CPPUNIT_ASSERT_EQUAL(vstrname[ic], std::string(list[ic].name));
01505             CPPUNIT_ASSERT_EQUAL((size_t)1, list[ic].ports.size());
01506             
01507             CPPUNIT_ASSERT_EQUAL(vstrinterface[ic],
01508                                  list[ic].properties["interface_type"]);
01509             CPPUNIT_ASSERT_EQUAL(vstrdataflow[ic],
01510                                  list[ic].properties["dataflow_type"]);
01511             CPPUNIT_ASSERT_EQUAL(vstrsubscription[ic],
01512                                  list[ic].properties["subscription_type"]);
01513 
01514         }
01515 
01516         //
01517         //getConnectorIds()
01518         //
01519         coil::vstring ids = outPort.getConnectorIds();
01520         CPPUNIT_ASSERT_EQUAL((size_t)10, ids.size());
01521         for(int ic(0);ic<10;++ic)
01522         {
01523             CPPUNIT_ASSERT_EQUAL(vstrid[ic], ids[ic]);
01524         }
01525 
01526         //
01527         //getConnectorNames()
01528         //
01529         coil::vstring names = outPort.getConnectorNames();
01530         CPPUNIT_ASSERT_EQUAL((size_t)10, names.size());
01531         for(int ic(0);ic<10;++ic)
01532         {
01533             CPPUNIT_ASSERT_EQUAL(vstrname[ic], names[ic]);
01534         }
01535 
01536         //
01537         // getConnectorById()
01538         //
01539         RTC::OutPortConnector* oc = outPort.getConnectorById("unknown");
01540         CPPUNIT_ASSERT(oc == 0);
01541         oc = outPort.getConnectorById("id0");
01542         CPPUNIT_ASSERT(oc != 0);
01543         oc = outPort.getConnectorById("id1");
01544         CPPUNIT_ASSERT(oc != 0);
01545 
01546         //
01547         // getConnectorByName()
01548         //
01549         oc = outPort.getConnectorByName("unknown");
01550         CPPUNIT_ASSERT(oc == 0);
01551         oc = outPort.getConnectorByName("foo0");
01552         CPPUNIT_ASSERT(oc != 0);
01553         oc = outPort.getConnectorByName("foo1");
01554         CPPUNIT_ASSERT(oc != 0);
01555 
01556         //
01557         //getConnectorProfileById()
01558         //
01559         for(int ic(0);ic<10;++ic)
01560         {
01561 
01562             RTC::ConnectorInfo prof;
01563             bool ret = outPort.getConnectorProfileById(vstrid[ic].c_str(),prof);
01564             CPPUNIT_ASSERT(ret);
01565             CPPUNIT_ASSERT_EQUAL(vstrinterface[ic],
01566                                  prof.properties["interface_type"]);
01567             CPPUNIT_ASSERT_EQUAL(vstrdataflow[ic],
01568                                  prof.properties["dataflow_type"]);
01569             CPPUNIT_ASSERT_EQUAL(vstrsubscription[ic],
01570                                  prof.properties["subscription_type"]);
01571         }
01572         {
01573             RTC::ConnectorInfo prof;
01574             bool ret = outPort.getConnectorProfileById("foo",prof);
01575             CPPUNIT_ASSERT(!ret);
01576             ret = outPort.getConnectorProfileById("bar",prof);
01577             CPPUNIT_ASSERT(!ret);
01578         }
01579 
01580         //
01581         //getConnectorProfileByName()
01582         //
01583         for(int ic(0);ic<10;++ic)
01584         {
01585             RTC::ConnectorInfo prof;
01586             bool ret = outPort.getConnectorProfileByName(vstrname[ic].c_str(),
01587                                                          prof);
01588             CPPUNIT_ASSERT(ret);
01589             CPPUNIT_ASSERT_EQUAL(vstrinterface[ic],
01590                                  prof.properties["interface_type"]);
01591             CPPUNIT_ASSERT_EQUAL(vstrdataflow[ic],
01592                                  prof.properties["dataflow_type"]);
01593             CPPUNIT_ASSERT_EQUAL(vstrsubscription[ic],
01594                                  prof.properties["subscription_type"]);
01595         }
01596         {
01597             RTC::ConnectorInfo prof;
01598             bool ret = outPort.getConnectorProfileByName("foo",prof);
01599             CPPUNIT_ASSERT(!ret);
01600             ret = outPort.getConnectorProfileByName("bar",prof);
01601             CPPUNIT_ASSERT(!ret);
01602         }
01603 
01604         //
01605         //publishInterfaces()
01606         //
01607         {
01608             RTC::ConnectorProfile outprof;
01609             bool ret = outPort.publishInterfaces_public(outprof);
01610             CPPUNIT_ASSERT(ret);
01611             {
01612                 const char* value;
01613                 try {
01614                     NVUtil::find(outprof.properties, "dataport.data_type") >>= value;
01615                     CPPUNIT_FAIL("dataport.data_type fialure.");
01616                 }
01617                 catch(std::string ex) {
01618                 }
01619                 catch(...) {
01620                     CPPUNIT_FAIL("dataport.data_type failure.");
01621                 }
01622             }
01623         }
01624         portAdmin.deletePort(outPort);
01625         portAdmin.deletePort(inPort);
01626     }
01627 
01632     void test_activateInterfaces_deactivateInterfaces(void)
01633     {
01634         RTC::TimedDouble inbindValue;
01635         InPortMock<RTC::TimedDouble> inPort("in:OutPortBaseTest",inbindValue);
01636 
01637         OutPortBaseMock outPort("out:OutPortBaseTest", toTypename<RTC::TimedDouble>());
01638 
01639         RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
01640         portAdmin.registerPort(outPort); 
01641         portAdmin.registerPort(inPort); 
01642 
01643         RTC::ConnectorProfile inprof;
01644         inprof.ports.length(1);
01645         inprof.ports[0] = outPort.get_port_profile()->port_ref;
01646         CORBA_SeqUtil::push_back(inprof.properties,
01647                                  NVUtil::newNV("dataport.interface_type",
01648                                  "corba_cdr"));
01649         CORBA_SeqUtil::push_back(inprof.properties,
01650                                  NVUtil::newNV("dataport.dataflow_type",
01651                                  "push"));
01652         CORBA_SeqUtil::push_back(inprof.properties,
01653                                  NVUtil::newNV("dataport.subscription_type",
01654                                  "flush"));
01655         inprof.connector_id = "id0";
01656         inprof.name = CORBA::string_dup("bar");
01657         coil::Properties dummy;
01658         inPort.init(dummy);
01659         outPort.init(dummy);
01660         inPort.publishInterfaces_public(inprof);
01661         //std::cout<<NVUtil::toString(inprof.properties)<<std::endl;
01662 
01663         std::string vstrid[10] = {"id0","id1","id2","id3","id4",
01664                                   "id5","id6","id7","id8","id9"};
01665         std::string vstrname[10] = {"foo0","foo1","foo2","foo3","foo4",
01666                                     "foo5","foo6","foo7","foo8","foo9"};
01667 
01668         std::string vstrinterface[10] = {"corba_cdr","corba_cdr","corba_cdr",
01669                                          "corba_cdr","corba_cdr","corba_cdr",
01670                                          "corba_cdr","corba_cdr","corba_cdr",
01671                                          "corba_cdr"};
01672         std::string vstrdataflow[10] = {"push","push","push",
01673                                          "push","push","push",
01674                                          "push","push","push","push"};
01675 
01676         std::string vstrsubscription[10] = {"flush","flush","flush",
01677                                             "flush","flush","flush",
01678                                             "flush","flush","flush","flush"};
01679         //
01680         //
01681         for(int ic(0);ic<10;++ic)
01682         {
01683             RTC::ConnectorProfile prof;
01684             prof.ports.length(1);
01685             prof.ports[0] = outPort.get_port_profile()->port_ref;
01686             CORBA_SeqUtil::push_back(prof.properties,
01687                                      NVUtil::newNV("dataport.interface_type",
01688                                                    vstrinterface[ic].c_str()));
01689             CORBA_SeqUtil::push_back(prof.properties,
01690                                      NVUtil::newNV("dataport.dataflow_type",
01691                                                    vstrdataflow[ic].c_str()));
01692             CORBA_SeqUtil::push_back(prof.properties,
01693                                      NVUtil::newNV("dataport.subscription_type",
01694                                                    vstrsubscription[ic].c_str()));
01695             CORBA_SeqUtil::push_back(prof.properties,
01696                                      NVUtil::newNV("dataport.corba_cdr.inport_ior",
01697                                      NVUtil::toString(inprof.properties,"dataport.corba_cdr.inport_ior").c_str()));
01698             prof.connector_id = vstrid[ic].c_str();
01699             prof.name = CORBA::string_dup(vstrname[ic].c_str());
01700 
01701 
01702             outPort.subscribeInterfaces_public(prof);
01703 
01704         }
01705         int logcnt;
01706         logcnt = ::RTC::logger.countLog("OutPortPushConnector::activate"); 
01707         outPort.activateInterfaces();
01708         CPPUNIT_ASSERT_EQUAL(logcnt+10,
01709                   ::RTC::logger.countLog("OutPortPushConnector::activate"));
01710 
01711 
01712         logcnt = ::RTC::logger.countLog("OutPortPushConnector::deactivate"); 
01713         outPort.deactivateInterfaces();
01714         CPPUNIT_ASSERT_EQUAL(logcnt+10,
01715                   ::RTC::logger.countLog("OutPortPushConnector::deactivate"));
01716 
01717         portAdmin.deletePort(outPort);
01718         portAdmin.deletePort(inPort);
01719 
01720     }
01725     void test_publishInterfaces(void)
01726     {
01727         //既に "corba_cdr" で登録されている場合は削除する。
01728         if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") )
01729         {
01730             RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr");
01731         }
01732         //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。
01733         RTC::OutPortProviderFactory::instance().
01734         addFactory("corba_cdr",
01735                    ::coil::Creator< ::RTC::OutPortProvider, 
01736                                     OutPortCorbaCdrProviderMock>,
01737                    ::coil::Destructor< ::RTC::OutPortProvider, 
01738                                        OutPortCorbaCdrProviderMock>);
01739 
01740         //既に "corba_cdr" で登録されている場合は削除する。
01741         if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") )
01742         {
01743             RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr");
01744         }
01745         //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。
01746         RTC::InPortConsumerFactory::instance().
01747         addFactory("corba_cdr",
01748                    ::coil::Creator< ::RTC::InPortConsumer, 
01749                                     InPortCorbaCdrConsumerMock>,
01750                    ::coil::Destructor< ::RTC::InPortConsumer, 
01751                                        InPortCorbaCdrConsumerMock>);
01752 
01753 
01754         OutPortBaseMock outPort("OutPortBaseTest", 
01755                                 toTypename<RTC::TimedFloat>());
01756 
01757         RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
01758         portAdmin.registerPort(outPort); 
01759         RTC::ConnectorProfile prof;
01760         prof.connector_id = "id0";
01761         prof.name = CORBA::string_dup("OutPortBaseTest0");
01762         prof.ports.length(1);
01763         prof.ports[0] = outPort.get_port_profile()->port_ref;
01764         CORBA_SeqUtil::push_back(prof.properties,
01765                                  NVUtil::newNV("dataport.interface_type",
01766                                  "corba_cdr"));
01767         CORBA_SeqUtil::push_back(prof.properties,
01768                                  NVUtil::newNV("dataport.dataflow_type",
01769                                  "pull"));
01770         CORBA_SeqUtil::push_back(prof.properties,
01771                                  NVUtil::newNV("dataport.subscription_type",
01772                                  "new"));
01773         coil::Properties dummy;
01774         outPort.init(dummy);
01775 
01776         RTC::ReturnCode_t retcode;
01777         CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size());
01778         retcode = outPort.publishInterfaces_public(prof);
01779         CPPUNIT_ASSERT_EQUAL(1,(int)outPort.get_m_connectors().size());
01780         CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode);
01781 
01782         prof.connector_id = "id1";
01783         prof.name = CORBA::string_dup("OutPortBaseTest1");
01784         retcode = outPort.publishInterfaces_public(prof);
01785         CPPUNIT_ASSERT_EQUAL(2,(int)outPort.get_m_connectors().size());
01786         CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode);
01787 
01788         portAdmin.deletePort(outPort);
01789     }
01794     void test_publishInterfaces2(void)
01795     {
01796         //
01797         //dataport.dataflow_typeがpushでpublisherInterfaceをコール
01798         //
01799 
01800         //既に "corba_cdr" で登録されている場合は削除する。
01801         if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") )
01802         {
01803             RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr");
01804         }
01805         //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。
01806         RTC::OutPortProviderFactory::instance().
01807         addFactory("corba_cdr",
01808                    ::coil::Creator< ::RTC::OutPortProvider, 
01809                                     OutPortCorbaCdrProviderMock>,
01810                    ::coil::Destructor< ::RTC::OutPortProvider, 
01811                                        OutPortCorbaCdrProviderMock>);
01812 
01813         //既に "corba_cdr" で登録されている場合は削除する。
01814         if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") )
01815         {
01816             RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr");
01817         }
01818         //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。
01819         RTC::InPortConsumerFactory::instance().
01820         addFactory("corba_cdr",
01821                    ::coil::Creator< ::RTC::InPortConsumer, 
01822                                     InPortCorbaCdrConsumerMock>,
01823                    ::coil::Destructor< ::RTC::InPortConsumer, 
01824                                        InPortCorbaCdrConsumerMock>);
01825 
01826 
01827         OutPortBaseMock outPort("OutPortBaseTest", 
01828                                 toTypename<RTC::TimedFloat>());
01829 
01830         RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
01831         portAdmin.registerPort(outPort); 
01832         RTC::ConnectorProfile prof;
01833         prof.connector_id = "id0";
01834         prof.name = CORBA::string_dup("OutPortBaseTest0");
01835         prof.ports.length(1);
01836         prof.ports[0] = outPort.get_port_profile()->port_ref;
01837         CORBA_SeqUtil::push_back(prof.properties,
01838                                  NVUtil::newNV("dataport.interface_type",
01839                                  "corba_cdr"));
01840         CORBA_SeqUtil::push_back(prof.properties,
01841                                  NVUtil::newNV("dataport.dataflow_type",
01842                                  "push"));
01843         CORBA_SeqUtil::push_back(prof.properties,
01844                                  NVUtil::newNV("dataport.subscription_type",
01845                                  "new"));
01846         coil::Properties dummy;
01847         outPort.init(dummy);
01848 
01849         RTC::ReturnCode_t retcode;
01850         CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size());
01851         retcode = outPort.publishInterfaces_public(prof);
01852         CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size());
01853         CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode);
01854 
01855         portAdmin.deletePort(outPort);
01856     }
01861     void test_publishInterfaces3(void)
01862     {
01863         //
01864         //dataport.dataflow_typeがelseでpublisherInterfaceをコール
01865         //
01866 
01867         //既に "corba_cdr" で登録されている場合は削除する。
01868         if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") )
01869         {
01870             RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr");
01871         }
01872         //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。
01873         RTC::OutPortProviderFactory::instance().
01874         addFactory("corba_cdr",
01875                    ::coil::Creator< ::RTC::OutPortProvider, 
01876                                     OutPortCorbaCdrProviderMock>,
01877                    ::coil::Destructor< ::RTC::OutPortProvider, 
01878                                        OutPortCorbaCdrProviderMock>);
01879 
01880         //既に "corba_cdr" で登録されている場合は削除する。
01881         if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") )
01882         {
01883             RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr");
01884         }
01885         //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。
01886         RTC::InPortConsumerFactory::instance().
01887         addFactory("corba_cdr",
01888                    ::coil::Creator< ::RTC::InPortConsumer, 
01889                                     InPortCorbaCdrConsumerMock>,
01890                    ::coil::Destructor< ::RTC::InPortConsumer, 
01891                                        InPortCorbaCdrConsumerMock>);
01892 
01893 
01894         OutPortBaseMock outPort("OutPortBaseTest", 
01895                                 toTypename<RTC::TimedFloat>());
01896 
01897         RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
01898         portAdmin.registerPort(outPort); 
01899         RTC::ConnectorProfile prof;
01900         prof.connector_id = "id0";
01901         prof.name = CORBA::string_dup("OutPortBaseTest0");
01902         prof.ports.length(1);
01903         prof.ports[0] = outPort.get_port_profile()->port_ref;
01904         CORBA_SeqUtil::push_back(prof.properties,
01905                                  NVUtil::newNV("dataport.interface_type",
01906                                  "corba_cdr"));
01907         CORBA_SeqUtil::push_back(prof.properties,
01908                                  NVUtil::newNV("dataport.dataflow_type",
01909                                  "else"));
01910         CORBA_SeqUtil::push_back(prof.properties,
01911                                  NVUtil::newNV("dataport.subscription_type",
01912                                  "new"));
01913         coil::Properties dummy;
01914         outPort.init(dummy);
01915 
01916         RTC::ReturnCode_t retcode;
01917         CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size());
01918         retcode = outPort.publishInterfaces_public(prof);
01919         CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size());
01920         CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode);
01921 
01922         portAdmin.deletePort(outPort);
01923     }
01928     void test_publishInterfaces4(void)
01929     {
01930         //
01931         //ProviderなしでpublisherInterfaceをコール
01932         //
01933 
01934         //既に "corba_cdr" で登録されている場合は削除する。
01935         if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") )
01936         {
01937             RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr");
01938         }
01939 
01940         //既に "corba_cdr" で登録されている場合は削除する。
01941         if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") )
01942         {
01943             RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr");
01944         }
01945         //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。
01946         RTC::InPortConsumerFactory::instance().
01947         addFactory("corba_cdr",
01948                    ::coil::Creator< ::RTC::InPortConsumer, 
01949                                     InPortCorbaCdrConsumerMock>,
01950                    ::coil::Destructor< ::RTC::InPortConsumer, 
01951                                        InPortCorbaCdrConsumerMock>);
01952 
01953 
01954         OutPortBaseMock outPort("OutPortBaseTest", 
01955                                 toTypename<RTC::TimedFloat>());
01956 
01957         RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
01958         portAdmin.registerPort(outPort); 
01959         RTC::ConnectorProfile prof;
01960         prof.connector_id = "id0";
01961         prof.name = CORBA::string_dup("OutPortBaseTest0");
01962         prof.ports.length(1);
01963         prof.ports[0] = outPort.get_port_profile()->port_ref;
01964         CORBA_SeqUtil::push_back(prof.properties,
01965                                  NVUtil::newNV("dataport.interface_type",
01966                                  "corba_cdr"));
01967         CORBA_SeqUtil::push_back(prof.properties,
01968                                  NVUtil::newNV("dataport.dataflow_type",
01969                                  "pull"));
01970         CORBA_SeqUtil::push_back(prof.properties,
01971                                  NVUtil::newNV("dataport.subscription_type",
01972                                  "new"));
01973         coil::Properties dummy;
01974         outPort.init(dummy);
01975 
01976         RTC::ReturnCode_t retcode;
01977         CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size());
01978         retcode = outPort.publishInterfaces_public(prof);
01979         CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size());
01980         CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode);
01981 
01982 
01983         portAdmin.deletePort(outPort);
01984     }
01989     void test_publishInterfaces5(void)
01990     {
01991         //既に "corba_cdr" で登録されている場合は削除する。
01992         if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") )
01993         {
01994             RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr");
01995         }
01996         //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。
01997         RTC::OutPortProviderFactory::instance().
01998         addFactory("corba_cdr",
01999                    ::coil::Creator< ::RTC::OutPortProvider, 
02000                                     OutPortCorbaCdrProviderMock>,
02001                    ::coil::Destructor< ::RTC::OutPortProvider, 
02002                                        OutPortCorbaCdrProviderMock>);
02003 
02004         //既に "corba_cdr" で登録されている場合は削除する。
02005         if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") )
02006         {
02007             RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr");
02008         }
02009         //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。
02010         RTC::InPortConsumerFactory::instance().
02011         addFactory("corba_cdr",
02012                    ::coil::Creator< ::RTC::InPortConsumer, 
02013                                     InPortCorbaCdrConsumerMock>,
02014                    ::coil::Destructor< ::RTC::InPortConsumer, 
02015                                        InPortCorbaCdrConsumerMock>);
02016 
02017 
02018         OutPortBaseMock outPort("OutPortBaseTest", 
02019                                 toTypename<RTC::TimedFloat>());
02020 
02021         RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
02022         portAdmin.registerPort(outPort); 
02023         RTC::ConnectorProfile prof;
02024         prof.connector_id = "id0";
02025         prof.name = CORBA::string_dup("OutPortBaseTest0");
02026         prof.ports.length(1);
02027         prof.ports[0] = outPort.get_port_profile()->port_ref;
02028         CORBA_SeqUtil::push_back(prof.properties,
02029                                  NVUtil::newNV("dataport.interface_type",
02030                                  "corba_cdr"));
02031         CORBA_SeqUtil::push_back(prof.properties,
02032                                  NVUtil::newNV("dataport.dataflow_type",
02033                                  "pull"));
02034         CORBA_SeqUtil::push_back(prof.properties,
02035                                  NVUtil::newNV("dataport.subscription_type",
02036                                  "new"));
02037         CORBA_SeqUtil::push_back(prof.properties,
02038                                  NVUtil::newNV("dataport.OutPortBaseTests",
02039                                  "bad_alloc"));
02040         coil::Properties dummy;
02041         outPort.init(dummy);
02042 
02043         RTC::ReturnCode_t retcode;
02044         CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size());
02045         retcode = outPort.publishInterfaces_public(prof);
02046         CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size());
02047         CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode);
02048 
02049         portAdmin.deletePort(outPort);
02050     }
02055     void test_subscribeInterfaces(void)
02056     {
02057         //既に "corba_cdr" で登録されている場合は削除する。
02058         if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") )
02059         {
02060             RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr");
02061         }
02062         //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。
02063         RTC::OutPortProviderFactory::instance().
02064         addFactory("corba_cdr",
02065                    ::coil::Creator< ::RTC::OutPortProvider, 
02066                                     OutPortCorbaCdrProviderMock>,
02067                    ::coil::Destructor< ::RTC::OutPortProvider, 
02068                                        OutPortCorbaCdrProviderMock>);
02069 
02070         //既に "corba_cdr" で登録されている場合は削除する。
02071         if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") )
02072         {
02073             RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr");
02074         }
02075         //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。
02076         RTC::InPortConsumerFactory::instance().
02077         addFactory("corba_cdr",
02078                    ::coil::Creator< ::RTC::InPortConsumer, 
02079                                     InPortCorbaCdrConsumerMock>,
02080                    ::coil::Destructor< ::RTC::InPortConsumer, 
02081                                        InPortCorbaCdrConsumerMock>);
02082 
02083 
02084         OutPortBaseMock outPort("OutPortBaseTest", 
02085                                 toTypename<RTC::TimedFloat>());
02086 
02087         RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
02088         portAdmin.registerPort(outPort); 
02089 
02090         RTC::ConnectorProfile prof;
02091         prof.connector_id = "id0";
02092         prof.name = CORBA::string_dup("OutPortBaseTest0");
02093         prof.ports.length(1);
02094         prof.ports[0] = outPort.get_port_profile()->port_ref;
02095         CORBA_SeqUtil::push_back(prof.properties,
02096                                  NVUtil::newNV("dataport.interface_type",
02097                                  "corba_cdr"));
02098         CORBA_SeqUtil::push_back(prof.properties,
02099                                  NVUtil::newNV("dataport.dataflow_type",
02100                                  "push"));
02101         CORBA_SeqUtil::push_back(prof.properties,
02102                                  NVUtil::newNV("dataport.subscription_type",
02103                                  "new"));
02104         coil::Properties dummy;
02105         outPort.init(dummy);
02106 
02107         RTC::ReturnCode_t retcode;
02108         CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size());
02109         retcode = outPort.subscribeInterfaces_public(prof);
02110         CPPUNIT_ASSERT_EQUAL(1,(int)outPort.get_m_connectors().size());
02111         CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode);
02112 
02113         prof.connector_id = "id1";
02114         prof.name = CORBA::string_dup("OutPortBaseTest1");
02115         retcode = outPort.subscribeInterfaces_public(prof);
02116         CPPUNIT_ASSERT_EQUAL(2,(int)outPort.get_m_connectors().size());
02117         CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode);
02118 
02119         portAdmin.deletePort(outPort);
02120     }
02125     void test_subscribeInterfaces2(void)
02126     {
02127         //既に "corba_cdr" で登録されている場合は削除する。
02128         if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") )
02129         {
02130             RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr");
02131         }
02132         //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。
02133         RTC::OutPortProviderFactory::instance().
02134         addFactory("corba_cdr",
02135                    ::coil::Creator< ::RTC::OutPortProvider, 
02136                                     OutPortCorbaCdrProviderMock>,
02137                    ::coil::Destructor< ::RTC::OutPortProvider, 
02138                                        OutPortCorbaCdrProviderMock>);
02139 
02140         //既に "corba_cdr" で登録されている場合は削除する。
02141         if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") )
02142         {
02143             RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr");
02144         }
02145         //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。
02146         RTC::InPortConsumerFactory::instance().
02147         addFactory("corba_cdr",
02148                    ::coil::Creator< ::RTC::InPortConsumer, 
02149                                     InPortCorbaCdrConsumerMock>,
02150                    ::coil::Destructor< ::RTC::InPortConsumer, 
02151                                        InPortCorbaCdrConsumerMock>);
02152 
02153 
02154         OutPortBaseMock outPort("OutPortBaseTest", 
02155                                 toTypename<RTC::TimedFloat>());
02156 
02157         RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
02158         portAdmin.registerPort(outPort); 
02159 
02160         RTC::ConnectorProfile prof;
02161         prof.connector_id = "id0";
02162         prof.name = CORBA::string_dup("OutPortBaseTest0");
02163         prof.ports.length(1);
02164         prof.ports[0] = outPort.get_port_profile()->port_ref;
02165         CORBA_SeqUtil::push_back(prof.properties,
02166                                  NVUtil::newNV("dataport.interface_type",
02167                                  "corba_cdr"));
02168         CORBA_SeqUtil::push_back(prof.properties,
02169                                  NVUtil::newNV("dataport.dataflow_type",
02170                                  "pull"));
02171         CORBA_SeqUtil::push_back(prof.properties,
02172                                  NVUtil::newNV("dataport.subscription_type",
02173                                  "new"));
02174         RTC::ReturnCode_t retcode;
02175         CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size());
02176         retcode = outPort.subscribeInterfaces_public(prof);
02177         CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size());
02178         CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode);
02179 
02180         portAdmin.deletePort(outPort);
02181     }
02186     void test_subscribeInterfaces3(void)
02187     {
02188         //既に "corba_cdr" で登録されている場合は削除する。
02189         if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") )
02190         {
02191             RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr");
02192         }
02193         //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。
02194         RTC::OutPortProviderFactory::instance().
02195         addFactory("corba_cdr",
02196                    ::coil::Creator< ::RTC::OutPortProvider, 
02197                                     OutPortCorbaCdrProviderMock>,
02198                    ::coil::Destructor< ::RTC::OutPortProvider, 
02199                                        OutPortCorbaCdrProviderMock>);
02200 
02201         //既に "corba_cdr" で登録されている場合は削除する。
02202         if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") )
02203         {
02204             RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr");
02205         }
02206         //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。
02207         RTC::InPortConsumerFactory::instance().
02208         addFactory("corba_cdr",
02209                    ::coil::Creator< ::RTC::InPortConsumer, 
02210                                     InPortCorbaCdrConsumerMock>,
02211                    ::coil::Destructor< ::RTC::InPortConsumer, 
02212                                        InPortCorbaCdrConsumerMock>);
02213 
02214 
02215         OutPortBaseMock outPort("OutPortBaseTest", 
02216                                 toTypename<RTC::TimedFloat>());
02217 
02218         RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
02219         portAdmin.registerPort(outPort); 
02220 
02221         RTC::ConnectorProfile prof;
02222         prof.connector_id = "id0";
02223         prof.name = CORBA::string_dup("OutPortBaseTest0");
02224         prof.ports.length(1);
02225         prof.ports[0] = outPort.get_port_profile()->port_ref;
02226         CORBA_SeqUtil::push_back(prof.properties,
02227                                  NVUtil::newNV("dataport.interface_type",
02228                                  "corba_cdr"));
02229         CORBA_SeqUtil::push_back(prof.properties,
02230                                  NVUtil::newNV("dataport.dataflow_type",
02231                                  "else"));
02232         CORBA_SeqUtil::push_back(prof.properties,
02233                                  NVUtil::newNV("dataport.subscription_type",
02234                                  "new"));
02235         RTC::ReturnCode_t retcode;
02236         CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size());
02237         retcode = outPort.subscribeInterfaces_public(prof);
02238         CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size());
02239         CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode);
02240 
02241         portAdmin.deletePort(outPort);
02242     }
02247     void test_subscribeInterfaces4(void)
02248     {
02249         //既に "corba_cdr" で登録されている場合は削除する。
02250         if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") )
02251         {
02252             RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr");
02253         }
02254         //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。
02255         RTC::OutPortProviderFactory::instance().
02256         addFactory("corba_cdr",
02257                    ::coil::Creator< ::RTC::OutPortProvider, 
02258                                     OutPortCorbaCdrProviderMock>,
02259                    ::coil::Destructor< ::RTC::OutPortProvider, 
02260                                        OutPortCorbaCdrProviderMock>);
02261 
02262         //既に "corba_cdr" で登録されている場合は削除する。
02263         if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") )
02264         {
02265             RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr");
02266         }
02267 
02268 
02269         OutPortBaseMock outPort("OutPortBaseTest", 
02270                                 toTypename<RTC::TimedFloat>());
02271 
02272         RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
02273         portAdmin.registerPort(outPort); 
02274 
02275         RTC::ConnectorProfile prof;
02276         prof.connector_id = "id0";
02277         prof.name = CORBA::string_dup("OutPortBaseTest0");
02278         prof.ports.length(1);
02279         prof.ports[0] = outPort.get_port_profile()->port_ref;
02280         CORBA_SeqUtil::push_back(prof.properties,
02281                                  NVUtil::newNV("dataport.interface_type",
02282                                  "corba_cdr"));
02283         CORBA_SeqUtil::push_back(prof.properties,
02284                                  NVUtil::newNV("dataport.dataflow_type",
02285                                  "push"));
02286         CORBA_SeqUtil::push_back(prof.properties,
02287                                  NVUtil::newNV("dataport.subscription_type",
02288                                  "new"));
02289         RTC::ReturnCode_t retcode;
02290         CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size());
02291         retcode = outPort.subscribeInterfaces_public(prof);
02292         CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size());
02293         CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode);
02294 
02295         portAdmin.deletePort(outPort);
02296     }
02301     void test_subscribeInterfaces5(void)
02302     {
02303         //既に "corba_cdr" で登録されている場合は削除する。
02304         if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") )
02305         {
02306             RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr");
02307         }
02308         //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。
02309         RTC::OutPortProviderFactory::instance().
02310         addFactory("corba_cdr",
02311                    ::coil::Creator< ::RTC::OutPortProvider, 
02312                                     OutPortCorbaCdrProviderMock>,
02313                    ::coil::Destructor< ::RTC::OutPortProvider, 
02314                                        OutPortCorbaCdrProviderMock>);
02315 
02316         //既に "corba_cdr" で登録されている場合は削除する。
02317         if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") )
02318         {
02319             RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr");
02320         }
02321         //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。
02322         RTC::InPortConsumerFactory::instance().
02323         addFactory("corba_cdr",
02324                    ::coil::Creator< ::RTC::InPortConsumer, 
02325                                     InPortCorbaCdrConsumerMock>,
02326                    ::coil::Destructor< ::RTC::InPortConsumer, 
02327                                        InPortCorbaCdrConsumerMock>);
02328 
02329 
02330         OutPortBaseMock outPort("OutPortBaseTest", 
02331                                 toTypename<RTC::TimedFloat>());
02332 
02333         RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
02334         portAdmin.registerPort(outPort); 
02335 
02336         RTC::ConnectorProfile prof;
02337         prof.connector_id = "id0";
02338         prof.name = CORBA::string_dup("OutPortBaseTest0");
02339         prof.ports.length(1);
02340         prof.ports[0] = outPort.get_port_profile()->port_ref;
02341         CORBA_SeqUtil::push_back(prof.properties,
02342                                  NVUtil::newNV("dataport.interface_type",
02343                                  "corba_cdr"));
02344         CORBA_SeqUtil::push_back(prof.properties,
02345                                  NVUtil::newNV("dataport.dataflow_type",
02346                                  "push"));
02347         CORBA_SeqUtil::push_back(prof.properties,
02348                                  NVUtil::newNV("dataport.subscription_type",
02349                                  "new"));
02350         CORBA_SeqUtil::push_back(prof.properties,
02351                                  NVUtil::newNV("dataport.OutPortBaseTests",
02352                                  "bad_alloc"));
02353         coil::Properties dummy;
02354         outPort.init(dummy);
02355 
02356         RTC::ReturnCode_t retcode;
02357         CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size());
02358         retcode = outPort.subscribeInterfaces_public(prof);
02359         CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size());
02360         CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode);
02361 
02362         portAdmin.deletePort(outPort);
02363     }
02364 
02369     void test_ConnectorListener(void)
02370     {
02371         RTC::TimedLong tdl;
02372         InPortMock<RTC::TimedLong> inPort("InPort", tdl);
02373 
02374         OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedLong>());
02375 
02376         RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
02377         portAdmin.registerPort(outPort); 
02378         portAdmin.registerPort(inPort); 
02379 
02380         RTC::ConnectorProfile prof;
02381         prof.ports.length(2);
02382         prof.ports[0] = inPort.get_port_profile()->port_ref;
02383         prof.ports[1] = outPort.get_port_profile()->port_ref;
02384         CORBA_SeqUtil::push_back(prof.properties,
02385                                  NVUtil::newNV("dataport.interface_type",
02386                                  "corba_cdr"));
02387         CORBA_SeqUtil::push_back(prof.properties,
02388                                  NVUtil::newNV("dataport.dataflow_type",
02389                                  "push"));
02390         CORBA_SeqUtil::push_back(prof.properties,
02391                                  NVUtil::newNV("dataport.subscription_type",
02392                                  "flush"));
02393         prof.connector_id = "id0";
02394         prof.name = CORBA::string_dup("test");
02395         coil::Properties dummy;
02396         inPort.init(dummy);
02397         outPort.init(dummy);
02398 
02399         //ConnectorDataListeners settting
02400         for (int i(0); i<cdl_len; ++i)
02401           {
02402             m_datalisteners[i] = new DataListener(str_cdl[i]);
02403           }
02404 
02405         //ConnectorListeners settting
02406         for (int i(0); i<cl_len; ++i)
02407           {
02408             m_connlisteners[i] = new ConnListener(str_cl[i]);
02409           }
02410 
02411         // addConnectorDataListener()
02412         for (int i(0); i<cdl_len; ++i)
02413           {
02414             outPort.addConnectorDataListener((RTC::ConnectorDataListenerType)i, 
02415                                              m_datalisteners[i], true);
02416           }
02417 
02418         // addConnectorListener()
02419         for (int i(0); i<cl_len; ++i)
02420           {
02421             outPort.addConnectorListener((RTC::ConnectorListenerType)i, 
02422                                          m_connlisteners[i], true);
02423           }
02424 
02425         // Listener add count check
02426         CPPUNIT_ASSERT_EQUAL(10, cdl_count);
02427         CPPUNIT_ASSERT_EQUAL(7, cl_count);
02428 
02429         inPort.publishInterfaces_public(prof);
02430         outPort.subscribeInterfaces_public(prof);
02431 
02432         // connect()
02433         RTC::ReturnCode_t ret;
02434         ret = outPort.connect(prof);
02435         CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ret);
02436 
02437         // isLittleEndian()
02438         bool bret = outPort.isLittleEndian();
02439         CPPUNIT_ASSERT( bret );
02440 
02441         outPort.activateInterfaces();
02442         outPort.deactivateInterfaces();
02443 
02444         ret = outPort.disconnect_all();
02445         CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ret);
02446 
02447         portAdmin.deletePort(outPort);
02448         portAdmin.deletePort(inPort);
02449 
02450         // removeConnectorDataListener()
02451         for (int i(0); i<cdl_len; ++i)
02452           {
02453             outPort.removeConnectorDataListener((RTC::ConnectorDataListenerType)i, 
02454                                                 m_datalisteners[i]);
02455           }
02456 
02457         // removeConnectorListener()
02458         for (int i(0); i<cl_len; ++i)
02459           {
02460             outPort.removeConnectorListener((RTC::ConnectorListenerType)i, 
02461                                             m_connlisteners[i]);
02462           }
02463 
02464         // Listener remove count check
02465         CPPUNIT_ASSERT_EQUAL(0, cdl_count);
02466         CPPUNIT_ASSERT_EQUAL(0, cl_count);
02467     }
02468 
02469   };
02470 }; // namespace OutPortBase
02471 
02472 
02476 namespace RTC 
02477 {
02487   OutPortPushConnector::OutPortPushConnector(ConnectorInfo info, 
02488                                              InPortConsumer* consumer,
02489                                              ConnectorListeners& listeners,
02490                                              CdrBufferBase* buffer)
02491     : OutPortConnector(info),
02492       m_consumer(consumer), m_publisher(0), m_listeners(listeners), m_buffer(buffer)
02493   {
02494       if(info.properties["OutPortBaseTests"]=="bad_alloc")
02495       {
02496           throw std::bad_alloc();
02497       }
02498       m_publisher = createPublisher(info);
02499       m_publisher->init(info.properties);
02500       m_publisher->setListener(m_profile, &m_listeners);
02501       onConnect();
02502   }
02507   OutPortPushConnector::~OutPortPushConnector()
02508   {
02509       onDisconnect();
02510       disconnect();
02511   }
02516   ConnectorBase::ReturnCode OutPortPushConnector::disconnect()
02517   {
02518       if (m_publisher != 0)
02519         {
02520           PublisherFactory& pfactory(PublisherFactory::instance());
02521           pfactory.deleteObject(m_publisher);
02522         }
02523       m_publisher = 0;
02524       return PORT_OK;
02525   }
02530   CdrBufferBase* OutPortPushConnector::getBuffer()
02531   {
02532       return new ::OutPortBase::CdrRingBufferMock();
02533   }
02538   void OutPortPushConnector::activate()
02539   {
02540       RTC::logger.log("OutPortPushConnector::activate");
02541   }
02546   void OutPortPushConnector::deactivate()
02547   {
02548       RTC::logger.log("OutPortPushConnector::deactivate");
02549   }
02554   ConnectorBase::ReturnCode
02555   OutPortPushConnector::write(const cdrMemoryStream& data)
02556   {
02557       return PORT_OK;
02558   }
02563   PublisherBase* OutPortPushConnector::createPublisher(ConnectorInfo& info)
02564   {
02565       return new PublisherFlush(); 
02566   }
02571   CdrBufferBase* OutPortPushConnector::createBuffer(ConnectorInfo& info)
02572   {
02573       return new ::OutPortBase::CdrRingBufferMock();
02574 
02575   }
02580   void OutPortPushConnector::onConnect()
02581   {
02582     m_listeners.connector_[ON_CONNECT].notify(m_profile);
02583   }
02588   void OutPortPushConnector::onDisconnect()
02589   {
02590     m_listeners.connector_[ON_DISCONNECT].notify(m_profile);
02591   }
02592 
02602   OutPortPullConnector::OutPortPullConnector(ConnectorInfo info,
02603                                              OutPortProvider* provider,
02604                                              ConnectorListeners& listeners,
02605                                              CdrBufferBase* buffer)
02606     : OutPortConnector(info), m_provider(provider), m_listeners(listeners),
02607       m_buffer(buffer)
02608 
02609   {
02610       if(info.properties["OutPortBaseTests"]=="bad_alloc")
02611       {
02612           throw std::bad_alloc();
02613       }
02614   }
02619   OutPortPullConnector::~OutPortPullConnector()
02620   {
02621   }
02626   ConnectorBase::ReturnCode
02627   OutPortPullConnector::write(const cdrMemoryStream& data)
02628   {
02629       return PORT_OK;
02630   }
02635   CdrBufferBase* OutPortPullConnector::getBuffer()
02636   {
02637       return new ::OutPortBase::CdrRingBufferMock();
02638   }
02643   ConnectorBase::ReturnCode OutPortPullConnector::disconnect()
02644   {
02645       return PORT_OK;
02646   }
02647 };
02648 
02649 
02650 /*
02651  * Register test suite
02652  */
02653 CPPUNIT_TEST_SUITE_REGISTRATION(OutPortBase::OutPortBaseTests);
02654 
02655 #ifdef LOCAL_MAIN
02656 int main(int argc, char* argv[])
02657 {
02658 
02659   FORMAT format = TEXT_OUT;
02660   int target = 0;
02661   std::string xsl;
02662   std::string ns;
02663   std::string fname;
02664   std::ofstream ofs;
02665 
02666   int i(1);
02667   while (i < argc)
02668     {
02669       std::string arg(argv[i]);
02670       std::string next_arg;
02671       if (i + 1 < argc) next_arg = argv[i + 1];
02672       else              next_arg = "";
02673 
02674       if (arg == "--text") { format = TEXT_OUT; break; }
02675       if (arg == "--xml")
02676         {
02677           if (next_arg == "")
02678             {
02679               fname = argv[0];
02680               fname += ".xml";
02681             }
02682           else
02683             {
02684               fname = next_arg;
02685             }
02686           format = XML_OUT;
02687           ofs.open(fname.c_str());
02688         }
02689       if ( arg == "--compiler"  ) { format = COMPILER_OUT; break; }
02690       if ( arg == "--cerr"      ) { target = 1; break; }
02691       if ( arg == "--xsl"       )
02692         {
02693           if (next_arg == "") xsl = "default.xsl"; 
02694           else                xsl = next_arg;
02695         }
02696       if ( arg == "--namespace" )
02697         {
02698           if (next_arg == "")
02699             {
02700               std::cerr << "no namespace specified" << std::endl;
02701               exit(1); 
02702             }
02703           else
02704             {
02705               xsl = next_arg;
02706             }
02707         }
02708       ++i;
02709     }
02710   CppUnit::TextUi::TestRunner runner;
02711   if ( ns.empty() )
02712     runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
02713   else
02714     runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
02715   CppUnit::Outputter* outputter = 0;
02716   std::ostream* stream = target ? &std::cerr : &std::cout;
02717   switch ( format )
02718     {
02719     case TEXT_OUT :
02720       outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
02721       break;
02722     case XML_OUT :
02723       std::cout << "XML_OUT" << std::endl;
02724       outputter = new CppUnit::XmlOutputter(&runner.result(),
02725                                             ofs, "shift_jis");
02726       static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
02727       break;
02728     case COMPILER_OUT :
02729       outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
02730       break;
02731     }
02732   runner.setOutputter(outputter);
02733   runner.run();
02734   return 0; // runner.run() ? 0 : 1;
02735 }
02736 #endif // MAIN
02737 #endif // OutPortBase_cpp


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sun Mar 26 2017 03:37:16