InPortProviderTests.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00021 /*
00022  * $Log: InPortProviderTests.cpp,v $
00023  * Revision 1.1  2008/03/10 11:28:31  arafune
00024  * The first commitment.
00025  *
00026  * Revision 1.1  2008/02/21 12:51:22  arafune
00027  * The first commitment.
00028  *
00029  */
00030 
00031 #ifndef InPortProvider_cpp
00032 #define InPortProvider_cpp
00033 
00034 #include <cppunit/ui/text/TestRunner.h>
00035 #include <cppunit/TextOutputter.h>
00036 #include <cppunit/extensions/TestFactoryRegistry.h>
00037 #include <cppunit/extensions/HelperMacros.h>
00038 #include <cppunit/TestAssert.h>
00039 #include <rtm/InPortProvider.h>
00040 #include <rtm/BufferBase.h>
00041 
00046 namespace InPortProvider
00047 {
00048   class InPortProviderMock
00049     : public RTC::InPortProvider
00050   {
00051   public:
00052     InPortProviderMock(
00053                        const std::string& interfaceType,
00054                        const std::string& dataFlowType,
00055                        const std::string& subscriptionType)
00056     {
00057       setInterfaceType(interfaceType.c_str());
00058       setDataFlowType(dataFlowType.c_str());
00059       setSubscriptionType(subscriptionType.c_str());
00060     }
00061     void setDummydataInProperties(void)
00062     {
00063       NVUtil::appendStringValue(m_properties, "KEY1", "VALUE1");
00064       NVUtil::appendStringValue(m_properties, "KEY2", "VALUE2");
00065     }
00066     void init(coil::Properties& prop)
00067       {
00068       }
00069     void setBuffer(RTC::BufferBase<cdrMemoryStream>* buffer) 
00070       {
00071       }
00072     void setListener(RTC::ConnectorInfo& info,
00073                      RTC::ConnectorListeners* listeners)
00074       {
00075       }
00076     void setConnector(RTC::InPortConnector* connector)
00077       {
00078       }
00079    };
00080         
00081   int g_argc;
00082   std::vector<std::string> g_argv;
00083 
00084   class InPortProviderTests
00085     : public CppUnit::TestFixture
00086   {
00087     CPPUNIT_TEST_SUITE(InPortProviderTests);
00088     CPPUNIT_TEST(test_publishInterfaceProfile);
00089     CPPUNIT_TEST(test_publishInterface_with_interfaceType_matched);
00090     CPPUNIT_TEST(test_publishInterface_with_interfaceType_unmatched);
00091     CPPUNIT_TEST_SUITE_END();
00092                 
00093   public:
00094         
00098     InPortProviderTests()
00099     {
00100       char* argv[g_argc];
00101       for (int i = 0; i < g_argc; i++) {
00102         argv[i] = (char *)g_argv[i].c_str();
00103       }
00104               
00105       CORBA::ORB_var orb = CORBA::ORB_init(g_argc, argv);
00106     }
00107                 
00111     ~InPortProviderTests()
00112     {
00113     }
00114                 
00118     virtual void setUp()
00119     {
00120     }
00121                 
00125     virtual void tearDown()
00126     { 
00127     }
00128                 
00136     void test_publishInterfaceProfile()
00137     {
00138       std::auto_ptr<InPortProviderMock> provider(
00139           new InPortProviderMock("INTERFACE_TYPE", "DATA_FLOW_TYPE", "SUBSCRIPTION_TYPE"));
00140 
00141       //m_propertiesへ設定
00142       provider->setDummydataInProperties();
00143 
00144       SDOPackage::NVList prop;
00145       provider->publishInterfaceProfile(prop);
00146                         
00147       // "dataport.interface_type"
00148       CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE"),
00149                            NVUtil::toString(prop, "dataport.interface_type"));
00150                         
00151       // 
00152       CPPUNIT_ASSERT_EQUAL(std::string("VALUE1"), NVUtil::toString(prop, "KEY1"));
00153       CPPUNIT_ASSERT_EQUAL(std::string("VALUE2"), NVUtil::toString(prop, "KEY2"));
00154     }
00155                 
00161     void test_publishInterface_with_interfaceType_matched()
00162     {
00163       std::auto_ptr<InPortProviderMock> provider(
00164           new InPortProviderMock("INTERFACE_TYPE", "DATA_FLOW_TYPE", "SUBSCRIPTION_TYPE"));
00165 
00166       //m_propertiesへ設定
00167       provider->setDummydataInProperties();
00168 
00169       SDOPackage::NVList props;
00170       NVUtil::appendStringValue(props, "dataport.interface_type", "INTERFACE_TYPE");
00171       CPPUNIT_ASSERT_EQUAL(true, provider->publishInterface(props));
00172 
00173       // 
00174       CPPUNIT_ASSERT_EQUAL(std::string("VALUE1"), NVUtil::toString(props, "KEY1"));
00175       CPPUNIT_ASSERT_EQUAL(std::string("VALUE2"), NVUtil::toString(props, "KEY2"));
00176     }
00177                 
00183     void test_publishInterface_with_interfaceType_unmatched()
00184     {
00185       std::auto_ptr<InPortProviderMock> provider(
00186           new InPortProviderMock("INTERFACE_TYPE", "DATA_FLOW_TYPE", "SUBSCRIPTION_TYPE"));
00187 
00188       //m_propertiesへ設定
00189       provider->setDummydataInProperties();
00190 
00191       SDOPackage::NVList props;
00192       NVUtil::appendStringValue(props, "dataport.interface_type", "UNMATCHED_INTERFACE_TYPE");
00193       CPPUNIT_ASSERT_EQUAL(false, provider->publishInterface(props));
00194 
00195       // 
00196       CPPUNIT_ASSERT_EQUAL(std::string(""), NVUtil::toString(props, "KEY1"));
00197       CPPUNIT_ASSERT_EQUAL(std::string(""), NVUtil::toString(props, "KEY2"));
00198     }
00199                 
00200   };
00201 }; // namespace InPortProvider
00202 
00203 /*
00204  * Register test suite
00205  */
00206 CPPUNIT_TEST_SUITE_REGISTRATION(InPortProvider::InPortProviderTests);
00207 
00208 #ifdef LOCAL_MAIN
00209 int main(int argc, char* argv[])
00210 {
00211 
00212   FORMAT format = TEXT_OUT;
00213   int target = 0;
00214   std::string xsl;
00215   std::string ns;
00216   std::string fname;
00217   std::ofstream ofs;
00218 
00219   int i(1);
00220   while (i < argc)
00221     {
00222       std::string arg(argv[i]);
00223       std::string next_arg;
00224       if (i + 1 < argc) next_arg = argv[i + 1];
00225       else              next_arg = "";
00226 
00227       if (arg == "--text") { format = TEXT_OUT; break; }
00228       if (arg == "--xml")
00229         {
00230           if (next_arg == "")
00231             {
00232               fname = argv[0];
00233               fname += ".xml";
00234             }
00235           else
00236             {
00237               fname = next_arg;
00238             }
00239           format = XML_OUT;
00240           ofs.open(fname.c_str());
00241         }
00242       if ( arg == "--compiler"  ) { format = COMPILER_OUT; break; }
00243       if ( arg == "--cerr"      ) { target = 1; break; }
00244       if ( arg == "--xsl"       )
00245         {
00246           if (next_arg == "") xsl = "default.xsl"; 
00247           else                xsl = next_arg;
00248         }
00249       if ( arg == "--namespace" )
00250         {
00251           if (next_arg == "")
00252             {
00253               std::cerr << "no namespace specified" << std::endl;
00254               exit(1); 
00255             }
00256           else
00257             {
00258               xsl = next_arg;
00259             }
00260         }
00261       ++i;
00262     }
00263   CppUnit::TextUi::TestRunner runner;
00264   if ( ns.empty() )
00265     runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
00266   else
00267     runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
00268   CppUnit::Outputter* outputter = 0;
00269   std::ostream* stream = target ? &std::cerr : &std::cout;
00270   switch ( format )
00271     {
00272     case TEXT_OUT :
00273       outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
00274       break;
00275     case XML_OUT :
00276       std::cout << "XML_OUT" << std::endl;
00277       outputter = new CppUnit::XmlOutputter(&runner.result(),
00278                                             ofs, "shift_jis");
00279       static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
00280       break;
00281     case COMPILER_OUT :
00282       outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
00283       break;
00284     }
00285   runner.setOutputter(outputter);
00286   runner.run();
00287   return 0; // runner.run() ? 0 : 1;
00288 }
00289 #endif // MAIN
00290 #endif // InPortProvider_cpp


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Aug 27 2015 14:16:37