CORBA_IORUtilTests.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00012 /*
00013  * $Log: CORBA_IORUtilTests.cpp,v $
00014  */
00015 
00016 #ifndef CORBA_IORUtil_cpp
00017 #define CORBA_IORUtil_cpp
00018 
00019 #include <iostream>
00020 
00021 #include <cppunit/ui/text/TestRunner.h>
00022 #include <cppunit/TextOutputter.h>
00023 #include <cppunit/extensions/TestFactoryRegistry.h>
00024 #include <cppunit/extensions/HelperMacros.h>
00025 #include <cppunit/TestAssert.h>
00026 
00027 #include <rtm/CORBA_IORUtil.h>
00028 
00029 
00035 namespace CORBA_IORUtil
00036 {
00037 
00038   class CORBA_IORUtilTests
00039    : public CppUnit::TestFixture
00040   {
00041     CPPUNIT_TEST_SUITE(CORBA_IORUtilTests);
00042 
00043     CPPUNIT_TEST(test_case0);
00044 
00045     CPPUNIT_TEST_SUITE_END();
00046   
00047   private:
00048 
00049   public:
00050   
00054     CORBA_IORUtilTests()
00055     {
00056     }
00057     
00061     ~CORBA_IORUtilTests()
00062     {
00063     }
00064   
00068     virtual void setUp()
00069     {
00070     }
00071     
00075     virtual void tearDown()
00076     { 
00077     }
00078   
00082     void test_case0()
00083     {
00084       bool bret;
00085       IOP::IOR ior;
00086       std::string str_ior("IOR:010000001400000049444c3a52544d2f4d616e616765723a312e300001000000000000006000000001010200100000003139322e3136382e3130302e323430007acf0000070000006d616e61676572000200000000000000080000000100000000545441010000001c00000001000000010001000100000001000105090101000100000009010100");
00087 
00088       std::string str_ior2;
00089       char* str_ior3 = 0;
00090       std::string str_ior_ret;
00091 
00092       // toIOR(), return false check
00093       bret = CORBA_IORUtil::toIOR(str_ior3, ior);
00094       CPPUNIT_ASSERT( !bret );
00095 
00096       // toIOR(), return false check
00097       bret = CORBA_IORUtil::toIOR("IOR", ior);
00098       CPPUNIT_ASSERT( !bret );
00099 
00100       // toIOR(), return false check
00101       bret = CORBA_IORUtil::toIOR("ior:", ior);
00102       CPPUNIT_ASSERT( !bret );
00103 
00104       // toIOR(), return true check
00105       bret = CORBA_IORUtil::toIOR(str_ior.c_str(), ior);
00106       CPPUNIT_ASSERT( bret );
00107 
00108       // toString()
00109       bret = CORBA_IORUtil::toString(ior, str_ior2);
00110       CPPUNIT_ASSERT( bret );
00111       CPPUNIT_ASSERT_EQUAL(str_ior, str_ior2);
00112 
00113       // replaceEndpoint()
00114       bret = CORBA_IORUtil::replaceEndpoint(str_ior, "127.0.0.1");
00115       CPPUNIT_ASSERT( bret );
00116 
00117       // formatIORinfo()
00118       str_ior_ret = CORBA_IORUtil::formatIORinfo(str_ior3);
00119       CPPUNIT_ASSERT( str_ior_ret.size() > 0 );
00120     }
00121 
00122   };
00123 }; // namespace CORBA_IORUtil
00124 
00125 /*
00126  * Register test suite
00127  */
00128 CPPUNIT_TEST_SUITE_REGISTRATION(CORBA_IORUtil::CORBA_IORUtilTests);
00129 
00130 #ifdef LOCAL_MAIN
00131 int main(int argc, char* argv[])
00132 {
00133 
00134   FORMAT format = TEXT_OUT;
00135   int target = 0;
00136   std::string xsl;
00137   std::string ns;
00138   std::string fname;
00139   std::ofstream ofs;
00140 
00141   int i(1);
00142   while (i < argc)
00143     {
00144       std::string arg(argv[i]);
00145       std::string next_arg;
00146       if (i + 1 < argc) next_arg = argv[i + 1];
00147       else              next_arg = "";
00148 
00149       if (arg == "--text") { format = TEXT_OUT; break; }
00150       if (arg == "--xml")
00151         {
00152           if (next_arg == "")
00153             {
00154               fname = argv[0];
00155               fname += ".xml";
00156             }
00157           else
00158             {
00159               fname = next_arg;
00160             }
00161           format = XML_OUT;
00162           ofs.open(fname.c_str());
00163         }
00164       if ( arg == "--compiler"  ) { format = COMPILER_OUT; break; }
00165       if ( arg == "--cerr"      ) { target = 1; break; }
00166       if ( arg == "--xsl"       )
00167         {
00168           if (next_arg == "") xsl = "default.xsl"; 
00169           else                xsl = next_arg;
00170         }
00171       if ( arg == "--namespace" )
00172         {
00173           if (next_arg == "")
00174             {
00175               std::cerr << "no namespace specified" << std::endl;
00176               exit(1); 
00177             }
00178           else
00179             {
00180               xsl = next_arg;
00181             }
00182         }
00183       ++i;
00184     }
00185   CppUnit::TextUi::TestRunner runner;
00186   if ( ns.empty() )
00187     runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
00188   else
00189     runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
00190   CppUnit::Outputter* outputter = 0;
00191   std::ostream* stream = target ? &std::cerr : &std::cout;
00192   switch ( format )
00193     {
00194     case TEXT_OUT :
00195       outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
00196       break;
00197     case XML_OUT :
00198       std::cout << "XML_OUT" << std::endl;
00199       outputter = new CppUnit::XmlOutputter(&runner.result(),
00200                                             ofs, "shift_jis");
00201       static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
00202       break;
00203     case COMPILER_OUT :
00204       outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
00205       break;
00206     }
00207   runner.setOutputter(outputter);
00208   runner.run();
00209   return 0; // runner.run() ? 0 : 1;
00210 }
00211 #endif // MAIN
00212 #endif // CORBA_IORUtil_cpp


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