OutPortPushConnectorTests.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00022 #ifndef OutPortPushConnector_cpp
00023 #define OutPortPushConnector_cpp
00024 
00025 #include <cppunit/ui/text/TestRunner.h>
00026 #include <cppunit/TextOutputter.h>
00027 #include <cppunit/extensions/TestFactoryRegistry.h>
00028 #include <cppunit/extensions/HelperMacros.h>
00029 #include <cppunit/TestAssert.h>
00030 
00031 #include <coil/Properties.h>
00032 
00033 #include <rtm/idl/BasicDataTypeSkel.h>
00034 #include <rtm/idl/DataPortSkel.h>
00035 #include <rtm/Typename.h>
00036 #include <rtm/OutPortPushConnector.h>
00037 #include <rtm/CdrBufferBase.h>
00038 #include <rtm/CORBA_SeqUtil.h>
00039 #include <rtm/NVUtil.h>
00040 #include <rtm/ConnectorBase.h>
00041 #include <rtm/DataPortStatus.h>
00042 #include <rtm/InPortBase.h>
00043 #include <rtm/InPortConsumer.h>
00044 #include <rtm/OutPortBase.h>
00045 #include <rtm/PortAdmin.h>
00046 #include <rtm/CorbaConsumer.h>
00047 #include <rtm/PublisherBase.h>
00048 
00053 namespace OutPortPushConnector
00054 {
00055 
00056   class DataListener
00057     : public RTC::ConnectorDataListenerT<RTC::TimedLong>
00058   {
00059   public:
00060     DataListener(const char* name) : m_name(name) {}
00061     virtual ~DataListener()
00062     {
00063       //std::cout << "dtor of " << m_name << std::endl;
00064     }
00065 
00066     virtual void operator()(const RTC::ConnectorInfo& info,
00067                             const RTC::TimedLong& data)
00068     {
00069       //std::cout << "------------------------------"   << std::endl;
00070       //std::cout << "Data Listener: " << m_name       << std::endl;
00071       //std::cout << "Profile::name: " << info.name    << std::endl;
00072       //std::cout << "------------------------------"   << std::endl;
00073     };
00074     std::string m_name;
00075   };
00076 
00077 
00078   class ConnListener
00079     : public RTC::ConnectorListener
00080   {
00081   public:
00082     ConnListener(const char* name) : m_name(name) {}
00083     virtual ~ConnListener()
00084     {
00085       //std::cout << "dtor of " << m_name << std::endl;
00086     }
00087 
00088     virtual void operator()(const RTC::ConnectorInfo& info)
00089     {
00090       std::cout << "------------------------------"   << std::endl;
00091       std::cout << "Connector Listener: " << m_name       << std::endl;
00092       std::cout << "Profile::name:      " << info.name    << std::endl;
00093       std::cout << "------------------------------"   << std::endl;
00094     };
00095     std::string m_name;
00096   };
00097 
00103   class Logger
00104   {
00105   public:
00106     void log(const std::string& msg)
00107     {
00108       m_log.push_back(msg);
00109     }
00110 
00111     int countLog(const std::string& msg)
00112     {
00113       int count = 0;
00114       for (int i = 0; i < (int) m_log.size(); ++i)
00115         {
00116           if (m_log[i] == msg) ++count;
00117         }
00118      return count;
00119     }
00120                 
00121   private:
00122     std::vector<std::string> m_log;
00123   };
00124 
00130   class InPortCorbaCdrConsumerMock
00131     : public RTC::InPortConsumer,
00132       public RTC::CorbaConsumer< ::OpenRTM::InPortCdr >
00133   {
00134 
00135   public:
00136       InPortCorbaCdrConsumerMock(void)
00137        {
00138           m_logger = NULL;
00139        }
00140       virtual ~InPortCorbaCdrConsumerMock(void)
00141       {
00142       }
00147       void init(coil::Properties& prop)
00148       {
00149           if (m_logger != NULL)
00150           {
00151               m_logger->log("InPortCorbaCdrConsumerMock::init");
00152           }
00153       }
00158       RTC::InPortConsumer::ReturnCode put(const cdrMemoryStream& data)
00159       {
00160           return PORT_OK;
00161       }
00166       void publishInterfaceProfile(SDOPackage::NVList& properties)
00167       {
00168           return;
00169       }
00170 
00175       bool subscribeInterface(const SDOPackage::NVList& properties)
00176       {
00177     
00178           return true;;
00179       }
00180   
00185       void unsubscribeInterface(const SDOPackage::NVList& properties)
00186       {
00187       }
00188   
00189   
00194       void setLogger(Logger* logger)
00195       {
00196           m_logger = logger;
00197       }
00198   private:
00199     Logger* m_logger;
00200 
00201   };
00207   class PublisherFlushMock
00208     : public RTC::PublisherBase
00209   {
00210   public:
00211       PublisherFlushMock()
00212       {
00213           m_logger = NULL;
00214       }
00215       ~PublisherFlushMock()
00216       {
00217       }
00222       RTC::PublisherBase::ReturnCode write(const cdrMemoryStream& data,
00223                                            unsigned long sec,
00224                                            unsigned long usec)
00225       {
00226           cdrMemoryStream cdr(data);
00227           CORBA::ULong inlen = cdr.bufSize();
00228 
00229           RTC::TimedLong td;
00230           td <<= cdr;
00231           std::stringstream ss;
00232           ss << td.data;
00233           if (m_logger != NULL)
00234           {
00235               m_logger->log("PublisherFlushMock::write");
00236               m_logger->log(ss.str());
00237           }
00238           logger.log("PublisherFlushMock::write");
00239           logger.log(ss.str());
00240           return PORT_OK;
00241       }
00246       bool isActive()
00247       {
00248           return true;
00249       }
00250 
00255       RTC::PublisherBase::ReturnCode activate()
00256       {
00257           if (m_logger != NULL)
00258           {
00259               m_logger->log("PublisherFlushMock::activate");
00260           }
00261           logger.log("PublisherFlushMock::activate");
00262           return PORT_OK;
00263       }
00264 
00269       RTC::PublisherBase::ReturnCode deactivate()
00270       {
00271           if (m_logger != NULL)
00272           {
00273               m_logger->log("PublisherFlushMock::deactivate");
00274           }
00275           logger.log("PublisherFlushMock::deactivate");
00276           return PORT_OK;
00277       }
00282       RTC::PublisherBase::ReturnCode init(coil::Properties& prop)
00283       {
00284           return PORT_OK;
00285       }
00290       RTC::PublisherBase::ReturnCode setConsumer(RTC::InPortConsumer* consumer)
00291       {
00292           if (m_logger != NULL)
00293           {
00294               m_logger->log("PublisherFlushMock::setConsumer");
00295           }
00296           logger.log("PublisherFlushMock::setConsumer");
00297           return PORT_OK;
00298       }
00299 
00304       RTC::PublisherBase::ReturnCode setBuffer(RTC::CdrBufferBase* buffer)
00305       {
00306           if (m_logger != NULL)
00307           {
00308               m_logger->log("PublisherFlushMock::setBuffer");
00309               if(buffer == NULL)
00310               {
00311                   m_logger->log("buffer NG");
00312               }
00313               else
00314               {
00315                   m_logger->log("buffer OK");
00316               }
00317           }
00318           logger.log("PublisherFlushMock::setBuffer");
00319           if(buffer == NULL)
00320           {
00321               logger.log("buffer NG");
00322           }
00323           else
00324           {
00325               logger.log("buffer OK");
00326           }
00327           return PORT_OK;
00328       }
00329 
00334       RTC::PublisherBase::ReturnCode setListener(RTC::ConnectorInfo& info,
00335                                                  RTC::ConnectorListeners* listeners)
00336       {
00337           if (m_logger != NULL)
00338           {
00339               m_logger->log("PublisherFlushMock::setListener");
00340               if (listeners == 0)
00341               {
00342                   m_logger->log("listeners NG");
00343               }
00344               else
00345               {
00346                   m_logger->log("listeners OK");
00347               }
00348           }
00349           logger.log("PublisherFlushMock::setListener");
00350           if (listeners == 0)
00351           {
00352               logger.log("listeners NG");
00353           }
00354           else
00355           {
00356               logger.log("listeners OK");
00357           }
00358           return PORT_OK;
00359       }
00360 
00365       void setLogger(Logger* logger)
00366       {
00367           m_logger = logger;
00368       }
00369     static Logger logger;
00370   private:
00371     Logger* m_logger;
00372   };
00373 
00374   Logger PublisherFlushMock::logger;
00375 
00381   class PublisherNewMock
00382     : public RTC::PublisherBase
00383   {
00384   public:
00385       PublisherNewMock()
00386       {
00387           m_logger = NULL;
00388       }
00389       ~PublisherNewMock()
00390       {
00391       }
00396       RTC::PublisherBase::ReturnCode write(const cdrMemoryStream& data,
00397                                            unsigned long sec,
00398                                            unsigned long usec)
00399       {
00400           cdrMemoryStream cdr(data);
00401           CORBA::ULong inlen = cdr.bufSize();
00402 
00403           RTC::TimedLong td;
00404           td <<= cdr;
00405           std::stringstream ss;
00406           ss << td.data;
00407 
00408           if (m_logger != NULL)
00409           {
00410               m_logger->log("PublisherNewMock::write");
00411               m_logger->log(ss.str());
00412           }
00413           logger.log("PublisherNewMock::write");
00414           logger.log(ss.str());
00415           return PORT_OK;
00416       }
00421       bool isActive()
00422       {
00423           return true;
00424       }
00425 
00430       RTC::PublisherBase::ReturnCode activate()
00431       {
00432           if (m_logger != NULL)
00433           {
00434               m_logger->log("PublisherNewMock::activate");
00435           }
00436           logger.log("PublisherNewMock::activate");
00437           return PORT_OK;
00438       }
00439 
00444       RTC::PublisherBase::ReturnCode deactivate()
00445       {
00446           if (m_logger != NULL)
00447           {
00448               m_logger->log("PublisherNewMock::deactivate");
00449           }
00450           logger.log("PublisherNewMock::deactivate");
00451           return PORT_OK;
00452       }
00453 
00458       RTC::PublisherBase::ReturnCode init(coil::Properties& prop)
00459       {
00460           return PORT_OK;
00461       }
00462 
00467       RTC::PublisherBase::ReturnCode setConsumer(RTC::InPortConsumer* consumer)
00468       {
00469           if (m_logger != NULL)
00470           {
00471               m_logger->log("PublisherNewMock::setConsumer");
00472           }
00473           logger.log("PublisherNewMock::setConsumer");
00474           return PORT_OK;
00475       }
00476 
00481       PublisherBase::ReturnCode setBuffer(RTC::CdrBufferBase* buffer)
00482       {
00483           if (m_logger != NULL)
00484           {
00485               m_logger->log("PublisherNewMock::setBuffer");
00486               if(buffer == NULL)
00487               {
00488                   m_logger->log("buffer NG");
00489               }
00490               else
00491               {
00492                   m_logger->log("buffer OK");
00493               }
00494           }
00495           logger.log("PublisherNewMock::setBuffer");
00496           if(buffer == NULL)
00497           {
00498               logger.log("buffer NG");
00499           }
00500           else
00501           {
00502               logger.log("buffer OK");
00503           }
00504           return PORT_OK;
00505       }
00506 
00511       RTC::PublisherBase::ReturnCode setListener(RTC::ConnectorInfo& info,
00512                                                  RTC::ConnectorListeners* listeners)
00513       {
00514           if (m_logger != NULL)
00515           {
00516               m_logger->log("PublisherNewMock::setListener");
00517               if (listeners == 0)
00518               {
00519                   m_logger->log("listeners NG");
00520               }
00521               else
00522               {
00523                   m_logger->log("listeners OK");
00524               }
00525           }
00526           logger.log("PublisherNewMock::setListener");
00527           if (listeners == 0)
00528           {
00529               logger.log("listeners NG");
00530           }
00531           else
00532           {
00533               logger.log("listeners OK");
00534           }
00535           return PORT_OK;
00536       }
00537 
00542       void setLogger(Logger* logger)
00543       {
00544           m_logger = logger;
00545       }
00546     static Logger logger;
00547   private:
00548     Logger* m_logger;
00549   };
00550 
00551   Logger PublisherNewMock::logger;
00552 
00553   class OutPortPushConnectorTests
00554     : public CppUnit::TestFixture
00555   {
00556     CPPUNIT_TEST_SUITE(OutPortPushConnectorTests);
00557 
00558     CPPUNIT_TEST(test_OutPortPushConnector);
00559     CPPUNIT_TEST(test_write);
00560     CPPUNIT_TEST(test_disconnect_getBuffer);
00561     CPPUNIT_TEST(test_activate_deactivate);
00562 
00563     CPPUNIT_TEST_SUITE_END();
00564                 
00565   private:
00566     CORBA::ORB_ptr m_pORB;
00567     PortableServer::POA_ptr m_pPOA;
00568 
00569 
00570   public:
00571     RTC::ConnectorListeners m_listeners;
00572         
00576     OutPortPushConnectorTests()
00577     {
00578 
00579         int argc(0);
00580         char** argv(NULL);
00581         m_pORB = CORBA::ORB_init(argc, argv);
00582         m_pPOA = PortableServer::POA::_narrow(
00583                     m_pORB->resolve_initial_references("RootPOA"));
00584         m_pPOA->the_POAManager()->activate();
00585 
00586     }
00587                 
00591     ~OutPortPushConnectorTests()
00592     {
00593     }
00594     
00598     virtual void setUp()
00599     {
00600         //ConnectorDataListeners
00601         m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener(
00602                                    new DataListener("ON_BUFFER_WRITE"), true);
00603         m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener(
00604                                    new DataListener("ON_BUFFER_FULL"), true);
00605         m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener(
00606                                    new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true);
00607         m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener(
00608                                    new DataListener("ON_BUFFER_OVERWRITE"), true);
00609         m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener(
00610                                    new DataListener("ON_BUFFER_READ"), true);
00611         m_listeners.connectorData_[RTC::ON_SEND].addListener(
00612                                    new DataListener("ON_SEND"), true);
00613         m_listeners.connectorData_[RTC::ON_RECEIVED].addListener(
00614                                    new DataListener("ON_RECEIVED"), true);
00615         m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener(
00616                                    new DataListener("ON_RECEIVER_FULL"), true);
00617         m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener(
00618                                    new DataListener("ON_RECEIVER_TIMEOUT"), true);
00619         m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener(
00620                                    new DataListener("ON_RECEIVER_ERROR"), true);
00621 
00622         //ConnectorListeners
00623         m_listeners.connector_[RTC::ON_BUFFER_EMPTY].addListener(
00624                                     new ConnListener("ON_BUFFER_EMPTY"), true);
00625         m_listeners.connector_[RTC::ON_BUFFER_READ_TIMEOUT].addListener(
00626                                     new ConnListener("ON_BUFFER_READ_TIMEOUT"), true);
00627         m_listeners.connector_[RTC::ON_SENDER_EMPTY].addListener(
00628                                     new ConnListener("ON_SENDER_EMPTY"), true);
00629         m_listeners.connector_[RTC::ON_SENDER_TIMEOUT].addListener(
00630                                     new ConnListener("ON_SENDER_TIMEOUT"), true);
00631         m_listeners.connector_[RTC::ON_SENDER_ERROR].addListener(
00632                                     new ConnListener("ON_SENDER_ERROR"), true);
00633         m_listeners.connector_[RTC::ON_CONNECT].addListener(
00634                                     new ConnListener("ON_CONNECT"), true);
00635         m_listeners.connector_[RTC::ON_DISCONNECT].addListener(
00636                                     new ConnListener("ON_DISCONNECT"), true);
00637     }
00638                 
00642     virtual void tearDown()
00643     {
00644     }
00645                 
00650     void test_OutPortPushConnector()
00651     {
00652         ::RTC::PublisherFactory::
00653         instance().addFactory("flush",
00654                               ::coil::Creator< ::RTC::PublisherBase,
00655                                                       PublisherFlushMock>,
00656                               ::coil::Destructor< ::RTC::PublisherBase,
00657                                                          PublisherFlushMock>);
00658         ::RTC::PublisherFactory::
00659         instance().addFactory("new",
00660                               ::coil::Creator< ::RTC::PublisherBase,
00661                                                PublisherNewMock>,
00662                               ::coil::Destructor< ::RTC::PublisherBase,
00663                                                PublisherNewMock>);
00664         RTC::ConnectorProfile prof;
00665         CORBA_SeqUtil::push_back(prof.properties,
00666                                NVUtil::newNV("dataport.interface_type",
00667                                              "corba_cdr"));
00668         CORBA_SeqUtil::push_back(prof.properties,
00669                                NVUtil::newNV("dataport.dataflow_type",
00670                                              "push"));
00671         CORBA_SeqUtil::push_back(prof.properties,
00672                                NVUtil::newNV("dataport.subscription_type",
00673                                              "new"));
00674         coil::Properties prop;
00675         {
00676             coil::Properties conn_prop;
00677             NVUtil::copyToProperties(conn_prop, prof.properties);
00678             prop << conn_prop.getNode("dataport"); // marge ConnectorProfile
00679         }
00680         InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock();
00681         Logger logger;
00682         consumer->setLogger(&logger);
00683         RTC::ConnectorInfo profile_new(prof.name,
00684                                        prof.connector_id,
00685                                        CORBA_SeqUtil::refToVstring(prof.ports),
00686                                        prop); 
00687         RTC::OutPortConnector* connector(0);
00688         CPPUNIT_ASSERT_EQUAL(0, 
00689                            logger.countLog("InPortCorbaCdrConsumerMock::init"));
00690         CPPUNIT_ASSERT_EQUAL(0, 
00691             PublisherNewMock::logger.countLog("PublisherNewMock::setBuffer"));
00692         CPPUNIT_ASSERT_EQUAL(0, 
00693             PublisherNewMock::logger.countLog("buffer OK"));
00694         CPPUNIT_ASSERT_EQUAL(0, 
00695             PublisherNewMock::logger.countLog("PublisherNewMock::setConsumer"));
00696         connector = new RTC::OutPortPushConnector(profile_new, consumer, m_listeners);
00697         CPPUNIT_ASSERT_EQUAL(1, 
00698                            logger.countLog("InPortCorbaCdrConsumerMock::init"));
00699         CPPUNIT_ASSERT_EQUAL(1, 
00700             PublisherNewMock::logger.countLog("PublisherNewMock::setBuffer"));
00701         CPPUNIT_ASSERT_EQUAL(1, 
00702             PublisherNewMock::logger.countLog("buffer OK"));
00703         CPPUNIT_ASSERT_EQUAL(0, 
00704             PublisherNewMock::logger.countLog("buffer NG"));
00705         CPPUNIT_ASSERT_EQUAL(1, 
00706             PublisherNewMock::logger.countLog("PublisherNewMock::setConsumer"));
00707 
00708         delete connector;
00709 
00710         //subscription_type
00711         //Flush
00712         CORBA_SeqUtil::push_back(prof.properties,
00713                                NVUtil::newNV("dataport.subscription_type",
00714                                              ""));
00715         {
00716             coil::Properties conn_prop;
00717             NVUtil::copyToProperties(conn_prop, prof.properties);
00718             prop << conn_prop.getNode("dataport"); // marge ConnectorProfile
00719         }
00720         RTC::ConnectorInfo profile_flush(prof.name,
00721                                          prof.connector_id,
00722                                          CORBA_SeqUtil::refToVstring(prof.ports),
00723                                          prop); 
00724         CPPUNIT_ASSERT_EQUAL(1, 
00725                            logger.countLog("InPortCorbaCdrConsumerMock::init"));
00726         CPPUNIT_ASSERT_EQUAL(0, 
00727         PublisherFlushMock::logger.countLog("PublisherFlushMock::setBuffer"));
00728         CPPUNIT_ASSERT_EQUAL(0, 
00729         PublisherFlushMock::logger.countLog("buffer OK"));
00730         CPPUNIT_ASSERT_EQUAL(0, 
00731         PublisherFlushMock::logger.countLog("PublisherFlushMock::setConsumer"));
00732         connector = new RTC::OutPortPushConnector(profile_flush, consumer, m_listeners);
00733         CPPUNIT_ASSERT_EQUAL(2, 
00734                            logger.countLog("InPortCorbaCdrConsumerMock::init"));
00735         CPPUNIT_ASSERT_EQUAL(1, 
00736         PublisherFlushMock::logger.countLog("PublisherFlushMock::setBuffer"));
00737         CPPUNIT_ASSERT_EQUAL(1, 
00738         PublisherFlushMock::logger.countLog("buffer OK"));
00739         CPPUNIT_ASSERT_EQUAL(1, 
00740         PublisherFlushMock::logger.countLog("PublisherFlushMock::setConsumer"));
00741 
00742         //consumer
00743         delete connector;
00744         
00745 
00746         //consumer
00747         RTC::OutPortConnector* connector_err(0);
00748         try {
00749             RTC::ConnectorProfile prof_err;
00750             {
00751                 coil::Properties conn_prop;
00752                 NVUtil::copyToProperties(conn_prop, prof_err.properties);
00753                 prop << conn_prop.getNode("dataport"); // marge ConnectorProfile
00754             }
00755             RTC::ConnectorInfo profile_err(prof_err.name,
00756                                           prof_err.connector_id,
00757                                           CORBA_SeqUtil::refToVstring(prof_err.ports),
00758                                           prop); 
00759             connector_err = new RTC::OutPortPushConnector(profile_err, NULL, m_listeners);
00760             CPPUNIT_FAIL("The exception was not thrown. ");
00761         }
00762         catch(std::bad_alloc& e)
00763         {
00764         }
00765         catch(...)
00766         {
00767             CPPUNIT_FAIL("The exception not intended was thrown .");
00768         }
00769         delete connector_err;
00770         delete consumer;
00771     }
00776     void test_write()
00777     {
00778         ::RTC::PublisherFactory::
00779         instance().addFactory("new",
00780                               ::coil::Creator< ::RTC::PublisherBase,
00781                                                       PublisherNewMock>,
00782                               ::coil::Destructor< ::RTC::PublisherBase,
00783                                                          PublisherNewMock>);
00784         RTC::ConnectorProfile prof;
00785         CORBA_SeqUtil::push_back(prof.properties,
00786                                NVUtil::newNV("dataport.interface_type",
00787                                              "corba_cdr"));
00788         CORBA_SeqUtil::push_back(prof.properties,
00789                                NVUtil::newNV("dataport.dataflow_type",
00790                                              "push"));
00791         CORBA_SeqUtil::push_back(prof.properties,
00792                                NVUtil::newNV("dataport.subscription_type",
00793                                              "new"));
00794         coil::Properties prop;
00795         {
00796             coil::Properties conn_prop;
00797             NVUtil::copyToProperties(conn_prop, prof.properties);
00798             prop << conn_prop.getNode("dataport"); // marge ConnectorProfile
00799         }
00800         InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock();
00801         Logger logger;
00802         consumer->setLogger(&logger);
00803         RTC::ConnectorInfo profile_new(prof.name,
00804                                        prof.connector_id,
00805                                        CORBA_SeqUtil::refToVstring(prof.ports),
00806                                        prop); 
00807         RTC::OutPortConnector* connector(0);
00808         connector = new RTC::OutPortPushConnector(profile_new, consumer, m_listeners);
00809         CPPUNIT_ASSERT_EQUAL(0, 
00810                PublisherNewMock::logger.countLog("PublisherNewMock::write"));
00811         CPPUNIT_ASSERT_EQUAL(0, 
00812                PublisherNewMock::logger.countLog("12345"));
00813         cdrMemoryStream cdr;
00814         RTC::TimedLong td;
00815         td.data = 12345;
00816         td >>= cdr;
00817 
00818         RTC::ConnectorBase::ReturnCode ret;
00819         ret = connector->write(cdr);
00820         CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, ret);
00821 
00822         CPPUNIT_ASSERT_EQUAL(1, 
00823                PublisherNewMock::logger.countLog("PublisherNewMock::write"));
00824         CPPUNIT_ASSERT_EQUAL(1, 
00825                PublisherNewMock::logger.countLog("12345"));
00826 
00827         delete connector;
00828         delete consumer;
00829     }
00834     void test_disconnect_getBuffer()
00835     {
00836         ::RTC::PublisherFactory::
00837         instance().addFactory("new",
00838                               ::coil::Creator< ::RTC::PublisherBase,
00839                                                       PublisherNewMock>,
00840                               ::coil::Destructor< ::RTC::PublisherBase,
00841                                                          PublisherNewMock>);
00842         RTC::ConnectorProfile prof;
00843         CORBA_SeqUtil::push_back(prof.properties,
00844                                NVUtil::newNV("dataport.interface_type",
00845                                              "corba_cdr"));
00846         CORBA_SeqUtil::push_back(prof.properties,
00847                                NVUtil::newNV("dataport.dataflow_type",
00848                                              "push"));
00849         CORBA_SeqUtil::push_back(prof.properties,
00850                                NVUtil::newNV("dataport.subscription_type",
00851                                              "new"));
00852         coil::Properties prop;
00853         {
00854             coil::Properties conn_prop;
00855             NVUtil::copyToProperties(conn_prop, prof.properties);
00856             prop << conn_prop.getNode("dataport"); // marge ConnectorProfile
00857         }
00858         InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock();
00859         Logger logger;
00860         consumer->setLogger(&logger);
00861         RTC::ConnectorInfo profile_new(prof.name,
00862                                        prof.connector_id,
00863                                        CORBA_SeqUtil::refToVstring(prof.ports),
00864                                        prop); 
00865         RTC::OutPortConnector* connector(0);
00866         connector = new RTC::OutPortPushConnector(profile_new, consumer, m_listeners);
00867         CPPUNIT_ASSERT(connector->getBuffer());
00868 
00869         RTC::ConnectorBase::ReturnCode ret;
00870         ret = connector->disconnect();
00871         CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, ret);
00872 
00873         CPPUNIT_ASSERT(!connector->getBuffer());
00874 
00875         delete connector;
00876         delete consumer;
00877     }
00882     void test_activate_deactivate()
00883     {
00884         ::RTC::PublisherFactory::
00885         instance().addFactory("new",
00886                               ::coil::Creator< ::RTC::PublisherBase,
00887                                                       PublisherNewMock>,
00888                               ::coil::Destructor< ::RTC::PublisherBase,
00889                                                          PublisherNewMock>);
00890         RTC::ConnectorProfile prof;
00891         CORBA_SeqUtil::push_back(prof.properties,
00892                                NVUtil::newNV("dataport.interface_type",
00893                                              "corba_cdr"));
00894         CORBA_SeqUtil::push_back(prof.properties,
00895                                NVUtil::newNV("dataport.dataflow_type",
00896                                              "push"));
00897         CORBA_SeqUtil::push_back(prof.properties,
00898                                NVUtil::newNV("dataport.subscription_type",
00899                                              "new"));
00900         coil::Properties prop;
00901         {
00902             coil::Properties conn_prop;
00903             NVUtil::copyToProperties(conn_prop, prof.properties);
00904             prop << conn_prop.getNode("dataport"); // marge ConnectorProfile
00905         }
00906         InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock();
00907         Logger logger;
00908         consumer->setLogger(&logger);
00909         RTC::ConnectorInfo profile_new(prof.name,
00910                                        prof.connector_id,
00911                                        CORBA_SeqUtil::refToVstring(prof.ports),
00912                                        prop); 
00913         RTC::OutPortConnector* connector(0);
00914         connector = new RTC::OutPortPushConnector(profile_new, consumer, m_listeners);
00915         CPPUNIT_ASSERT_EQUAL(0, 
00916                PublisherNewMock::logger.countLog("PublisherNewMock::activate"));
00917         connector->activate();
00918         CPPUNIT_ASSERT_EQUAL(1, 
00919                PublisherNewMock::logger.countLog("PublisherNewMock::activate"));
00920 
00921         delete connector;
00922         connector = new RTC::OutPortPushConnector(profile_new, consumer, m_listeners);
00923         CPPUNIT_ASSERT_EQUAL(0, 
00924              PublisherNewMock::logger.countLog("PublisherNewMock::deactivate"));
00925 
00926         connector->deactivate();
00927         CPPUNIT_ASSERT_EQUAL(1, 
00928              PublisherNewMock::logger.countLog("PublisherNewMock::deactivate"));
00929 
00930         delete connector;
00931         delete consumer;
00932     }
00933   };
00934 }; // namespace OutPortPushConnector
00935 
00936 /*
00937  * Register test suite
00938  */
00939 CPPUNIT_TEST_SUITE_REGISTRATION(OutPortPushConnector::OutPortPushConnectorTests);
00940 
00941 #ifdef LOCAL_MAIN
00942 int main(int argc, char* argv[])
00943 {
00944 
00945   FORMAT format = TEXT_OUT;
00946   int target = 0;
00947   std::string xsl;
00948   std::string ns;
00949   std::string fname;
00950   std::ofstream ofs;
00951 
00952   int i(1);
00953   while (i < argc)
00954     {
00955       std::string arg(argv[i]);
00956       std::string next_arg;
00957       if (i + 1 < argc) next_arg = argv[i + 1];
00958       else              next_arg = "";
00959 
00960       if (arg == "--text") { format = TEXT_OUT; break; }
00961       if (arg == "--xml")
00962         {
00963           if (next_arg == "")
00964             {
00965               fname = argv[0];
00966               fname += ".xml";
00967             }
00968           else
00969             {
00970               fname = next_arg;
00971             }
00972           format = XML_OUT;
00973           ofs.open(fname.c_str());
00974         }
00975       if ( arg == "--compiler"  ) { format = COMPILER_OUT; break; }
00976       if ( arg == "--cerr"      ) { target = 1; break; }
00977       if ( arg == "--xsl"       )
00978         {
00979           if (next_arg == "") xsl = "default.xsl"; 
00980           else                xsl = next_arg;
00981         }
00982       if ( arg == "--namespace" )
00983         {
00984           if (next_arg == "")
00985             {
00986               std::cerr << "no namespace specified" << std::endl;
00987               exit(1); 
00988             }
00989           else
00990             {
00991               xsl = next_arg;
00992             }
00993         }
00994       ++i;
00995     }
00996   CppUnit::TextUi::TestRunner runner;
00997   if ( ns.empty() )
00998     runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
00999   else
01000     runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
01001   CppUnit::Outputter* outputter = 0;
01002   std::ostream* stream = target ? &std::cerr : &std::cout;
01003   switch ( format )
01004     {
01005     case TEXT_OUT :
01006       outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
01007       break;
01008     case XML_OUT :
01009       std::cout << "XML_OUT" << std::endl;
01010       outputter = new CppUnit::XmlOutputter(&runner.result(),
01011                                             ofs, "shift_jis");
01012       static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
01013       break;
01014     case COMPILER_OUT :
01015       outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
01016       break;
01017     }
01018   runner.setOutputter(outputter);
01019   runner.run();
01020   return 0; // runner.run() ? 0 : 1;
01021 }
01022 #endif // MAIN
01023 #endif // InPort_cpp


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sat Jun 8 2019 18:49:05