InPortConnectorTests.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00022 #ifndef InPortConnector_cpp
00023 #define InPortConnector_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/InPortConnector.h>
00034 #include <rtm/CdrBufferBase.h>
00035 #include <rtm/CORBA_SeqUtil.h>
00036 #include <rtm/NVUtil.h>
00037 #include <rtm/ConnectorBase.h>
00038 #include <rtm/DataPortStatus.h>
00039 
00044 namespace InPortConnector
00045 {
00046   class InPortConnectorMock
00047     : public RTC::InPortConnector
00048   {
00049   public:
00050       InPortConnectorMock(RTC::ConnectorInfo& info,
00051                           RTC::CdrBufferBase* buffer)
00052         : RTC::InPortConnector(info, buffer)
00053       {
00054       }
00055       virtual ~InPortConnectorMock()
00056       {
00057       }
00058       virtual ReturnCode disconnect()
00059       {
00060           return ::RTC::DataPortStatus::PORT_OK;
00061       }
00062       virtual ReturnCode read(cdrMemoryStream& data)
00063       {
00064           return ::RTC::DataPortStatus::PORT_OK;
00065       }
00066       virtual void activate()
00067       {
00068       }
00069       virtual void deactivate()
00070       {
00071       }
00072   };
00073 
00074   class InPortConnectorTests
00075     : public CppUnit::TestFixture
00076   {
00077     CPPUNIT_TEST_SUITE(InPortConnectorTests);
00078 
00079     CPPUNIT_TEST(test_case0);
00080 
00081     CPPUNIT_TEST_SUITE_END();
00082                 
00083   private:
00084 
00085   public:
00086         
00090     InPortConnectorTests()
00091     {
00092         int argc(0);
00093         char** argv(NULL);
00094         CORBA::ORB_ptr m_pORB = CORBA::ORB_init(argc, argv);
00095         PortableServer::POA_ptr m_pPOA = PortableServer::POA::_narrow(
00096                     m_pORB->resolve_initial_references("RootPOA"));
00097         m_pPOA->the_POAManager()->activate();
00098     }
00099                 
00103     ~InPortConnectorTests()
00104     {
00105     }
00106     
00110     virtual void setUp()
00111     {
00112     }
00113                 
00117     virtual void tearDown()
00118     {
00119     }
00120                 
00125     void test_case0()
00126     {
00127 
00128         RTC::ConnectorProfile cprof;
00129         cprof.connector_id = "id";
00130         cprof.name = CORBA::string_dup("InPortConnectorTest");
00131 
00132         CORBA_SeqUtil::push_back(cprof.properties,
00133                                  NVUtil::newNV("dataport.interface_type",
00134                                                "corba_cdr"));
00135         CORBA_SeqUtil::push_back(cprof.properties,
00136                                  NVUtil::newNV("dataport.dataflow_type",
00137                                                "push"));
00138         CORBA_SeqUtil::push_back(cprof.properties,
00139                                  NVUtil::newNV("dataport.subscription_type",
00140                                                "new"));
00141 
00142 
00143         coil::Properties prop;
00144         NVUtil::copyToProperties(prop, cprof.properties);
00145         RTC::ConnectorInfo info(cprof.name,
00146                                 cprof.connector_id,
00147                                 CORBA_SeqUtil::refToVstring(cprof.ports),
00148                                 prop); 
00149         RTC::CdrBufferBase* m_thebuffer;
00150         m_thebuffer = RTC::CdrBufferFactory::instance().createObject("ring_buffer");
00151 
00152         InPortConnector::InPortConnectorMock connector(info, m_thebuffer);
00153         CPPUNIT_ASSERT_EQUAL(std::string(cprof.connector_id), std::string(connector.id()));
00154         CPPUNIT_ASSERT_EQUAL(std::string(cprof.name), std::string(connector.name()));
00155         CPPUNIT_ASSERT_EQUAL(m_thebuffer, connector.getBuffer());
00156 
00157         connector.setEndian(false);
00158         CPPUNIT_ASSERT(!connector.isLittleEndian());
00159         connector.setEndian(true);
00160         CPPUNIT_ASSERT(connector.isLittleEndian());
00161 
00162         RTC::ConnectorInfo info2 = connector.profile();
00163         CPPUNIT_ASSERT_EQUAL(info.name, info2.name);
00164         CPPUNIT_ASSERT_EQUAL(info.id, info2.id);
00165     }
00166 
00167   };
00168 }; // namespace InPortConnector
00169 
00170 /*
00171  * Register test suite
00172  */
00173 CPPUNIT_TEST_SUITE_REGISTRATION(InPortConnector::InPortConnectorTests);
00174 
00175 #ifdef LOCAL_MAIN
00176 int main(int argc, char* argv[])
00177 {
00178 
00179   FORMAT format = TEXT_OUT;
00180   int target = 0;
00181   std::string xsl;
00182   std::string ns;
00183   std::string fname;
00184   std::ofstream ofs;
00185 
00186   int i(1);
00187   while (i < argc)
00188     {
00189       std::string arg(argv[i]);
00190       std::string next_arg;
00191       if (i + 1 < argc) next_arg = argv[i + 1];
00192       else              next_arg = "";
00193 
00194       if (arg == "--text") { format = TEXT_OUT; break; }
00195       if (arg == "--xml")
00196         {
00197           if (next_arg == "")
00198             {
00199               fname = argv[0];
00200               fname += ".xml";
00201             }
00202           else
00203             {
00204               fname = next_arg;
00205             }
00206           format = XML_OUT;
00207           ofs.open(fname.c_str());
00208         }
00209       if ( arg == "--compiler"  ) { format = COMPILER_OUT; break; }
00210       if ( arg == "--cerr"      ) { target = 1; break; }
00211       if ( arg == "--xsl"       )
00212         {
00213           if (next_arg == "") xsl = "default.xsl"; 
00214           else                xsl = next_arg;
00215         }
00216       if ( arg == "--namespace" )
00217         {
00218           if (next_arg == "")
00219             {
00220               std::cerr << "no namespace specified" << std::endl;
00221               exit(1); 
00222             }
00223           else
00224             {
00225               xsl = next_arg;
00226             }
00227         }
00228       ++i;
00229     }
00230   CppUnit::TextUi::TestRunner runner;
00231   if ( ns.empty() )
00232     runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
00233   else
00234     runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
00235   CppUnit::Outputter* outputter = 0;
00236   std::ostream* stream = target ? &std::cerr : &std::cout;
00237   switch ( format )
00238     {
00239     case TEXT_OUT :
00240       outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
00241       break;
00242     case XML_OUT :
00243       std::cout << "XML_OUT" << std::endl;
00244       outputter = new CppUnit::XmlOutputter(&runner.result(),
00245                                             ofs, "shift_jis");
00246       static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
00247       break;
00248     case COMPILER_OUT :
00249       outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
00250       break;
00251     }
00252   runner.setOutputter(outputter);
00253   runner.run();
00254   return 0; // runner.run() ? 0 : 1;
00255 }
00256 #endif // MAIN
00257 #endif // InPortConnector_cpp


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