ManagerConfigTests.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00012 /*
00013  * $Log: ManagerConfigTests.cpp,v $
00014  * Revision 1.3  2008/05/01 08:01:03  arafune
00015  * Modified some tests.
00016  *
00017  * Revision 1.2  2008/05/01 07:52:46  arafune
00018  * Modified some tests.
00019  *
00020  *
00021  * Revision 1.1  2006/11/27 08:25:57  n-ando
00022  * TestSuites are devided into each directory.
00023  *
00024  *
00025  */
00026 
00027 #ifndef ManagerConfig_cpp
00028 #define ManagerConfig_cpp
00029 
00030 #include <cppunit/ui/text/TestRunner.h>
00031 #include <cppunit/TextOutputter.h>
00032 #include <cppunit/extensions/TestFactoryRegistry.h>
00033 #include <cppunit/extensions/HelperMacros.h>
00034 #include <cppunit/TestAssert.h>
00035 
00036 #include <fstream>
00037 #include <vector>
00038 #include <string>
00039 
00040 #include <rtm/ManagerConfig.h>
00041 
00046 namespace ManagerConfig
00047 {
00048   int g_argc;
00049   //char* g_argv[10];
00050   std::vector<std::string> g_argv;
00051         
00052   class ManagerConfigMock : public RTC::ManagerConfig
00053   {
00054   public:
00055     void parseArgs(int argc, char** argv)
00056     {
00057       ManagerConfig::parseArgs(argc, argv);
00058     }
00059                 
00060     bool findConfigFile()
00061     {
00062       return ManagerConfig::findConfigFile();
00063     }
00064                 
00065     void setSystemInformation(coil::Properties& prop)
00066     {
00067       ManagerConfig::setSystemInformation(prop);
00068     }
00069                 
00070     bool fileExist(const std::string& filename)
00071     {
00072       return ManagerConfig::fileExist(filename);
00073     }
00074                 
00075   public:
00076     std::string& configFile()
00077     {
00078       return m_configFile;
00079     }
00080   bool m_isMaster;
00081   };
00082         
00083   class ManagerConfigTests
00084     : public CppUnit::TestFixture
00085   {
00086     CPPUNIT_TEST_SUITE(ManagerConfigTests);
00087     CPPUNIT_TEST(test_init_and_configure);
00088     CPPUNIT_TEST(test_init_default);
00089     CPPUNIT_TEST_SUITE_END();
00090             
00091   public:
00095     ManagerConfigTests()
00096     {
00097     }
00098                 
00102     ~ManagerConfigTests()
00103     {
00104     }
00105                 
00109     virtual void setUp()
00110     {
00111     }
00112                 
00116     virtual void tearDown()
00117     { 
00118     }
00119                 
00127     void test_init_and_configure()
00128     {
00129       ManagerConfigMock mgrCfg;
00130       CPPUNIT_ASSERT(mgrCfg.fileExist("./rtc.conf"));
00131 
00132       // コマンド引数の-fオプションで指定したファイルで正しく初期化できるか?
00133 //      char* argv[] = { "command", "-f", "./rtc.conf" };
00134       char* argv[] = { "command", "-d", "./rtc.conf" };
00135       int argc = sizeof(argv) / sizeof(char*);
00136       mgrCfg.init(argc, argv);
00137                         
00138       // 設定されている内容を正しく取得できるか?
00139       coil::Properties properties;
00140       mgrCfg.configure(properties);
00141 
00142       CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.COMPONENT.CONF.PATH"),
00143                            properties.getProperty("rtc.component.conf.path"));
00144       CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.ARCH"),
00145                            properties.getProperty("rtc.manager.arch"));
00146       CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.DEBUG.LEVEL"),
00147                            properties.getProperty("rtc.manager.debug.level"));
00148       CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.LANGUAGE"),
00149                            properties.getProperty("rtc.manager.language"));
00150       CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.NAMESERVER"),
00151                            properties.getProperty("rtc.manager.nameserver"));
00152       CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.OPENING_MESSAGE"),
00153                            properties.getProperty("rtc.manager.opening_message"));
00154       CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.ORB"),
00155                            properties.getProperty("rtc.manager.orb"));
00156       CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.ORB.OPTIONS"),
00157                            properties.getProperty("rtc.manager.orb.options"));
00158       CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.OS"),
00159                            properties.getProperty("rtc.manager.os"));
00160       CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.OS.RELEASE"),
00161                            properties.getProperty("rtc.manager.os.release"));
00162       CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.SUBSYSTEMS"),
00163                            properties.getProperty("rtc.manager.subsystems"));
00164       CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.OPENRTM.AUTHOR"),
00165                            properties.getProperty("rtc.openrtm.author"));
00166       CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.OPENRTM.RELEASE"),
00167                            properties.getProperty("rtc.openrtm.release"));
00168       CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.OPENRTM.VENDOR"),
00169                            properties.getProperty("rtc.openrtm.vendor"));
00170       CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.OPENRTM.VERSION"),
00171                            properties.getProperty("rtc.openrtm.version"));
00172                         
00173       // システム情報のプロパティが、取得内容に含まれているか?
00174       // (システム情報は動作環境に依存するので、プロパティが取得できていることだけを確認する)
00175       CPPUNIT_ASSERT(std::string("")
00176                      != properties.getProperty("manager.os.name"));
00177       CPPUNIT_ASSERT(std::string("")
00178                      != properties.getProperty("manager.os.release"));
00179       CPPUNIT_ASSERT(std::string("")
00180                      != properties.getProperty("manager.os.version"));
00181       CPPUNIT_ASSERT(std::string("")
00182                      != properties.getProperty("manager.os.arch"));
00183       CPPUNIT_ASSERT(std::string("")
00184                      != properties.getProperty("manager.os.hostname"));
00185       CPPUNIT_ASSERT(std::string("")
00186                      != properties.getProperty("manager.pid"));
00187       CPPUNIT_ASSERT(std::string("YES")
00188                      == properties.getProperty("manager.is_master"));
00189 
00190       // コマンド引数の-aオプション指定が正しく反映されるか?
00191       // corba.corba_servant 指定の確認
00192       argv[1] = "-a";
00193       argc = sizeof(argv) / sizeof(char*);
00194       mgrCfg.init(argc, argv);
00195       mgrCfg.configure(properties);
00196       CPPUNIT_ASSERT_EQUAL(std::string("NO"),
00197                            properties.getProperty("manager.corba_servant"));
00198 
00199       // コマンド引数の-oオプション指定が正しく反映されるか?
00200       // configuration 上書き指定の確認
00201       argv[1] = "-omanager.is_master:NO";
00202       argc = sizeof(argv) / sizeof(char*);
00203       mgrCfg.init(argc, argv);
00204       mgrCfg.configure(properties);
00205       CPPUNIT_ASSERT_EQUAL(std::string("NO"),
00206                            properties.getProperty("manager.is_master"));
00207 
00208       // コマンド引数の-pオプション指定が正しく反映されるか?
00209       // corba.endpoints ポート番号指定の確認
00210       argv[1] = "-p9876";
00211       argc = sizeof(argv) / sizeof(char*);
00212       mgrCfg.init(argc, argv);
00213       mgrCfg.configure(properties);
00214       CPPUNIT_ASSERT_EQUAL(std::string(":9876"),
00215                            properties.getProperty("corba.endpoints"));
00216     }
00217                 
00223     void test_init_default()
00224     {
00225 
00226       ManagerConfigMock mgrCfg;
00227 
00228       // オプション指定なしで初期化する
00229       mgrCfg.init(0, NULL);
00230                         
00231       // 設定されている内容を正しく取得できるか?
00232       coil::Properties properties;
00233       mgrCfg.configure(properties);
00234 
00235       CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.COMPONENT.CONF.PATH"),
00236                            properties.getProperty("rtc.component.conf.path"));
00237       CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.ARCH"),
00238                            properties.getProperty("rtc.manager.arch"));
00239       CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.DEBUG.LEVEL"),
00240                            properties.getProperty("rtc.manager.debug.level"));
00241       CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.LANGUAGE"),
00242                            properties.getProperty("rtc.manager.language"));
00243       CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.NAMESERVER"),
00244                            properties.getProperty("rtc.manager.nameserver"));
00245       CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.OPENING_MESSAGE"),
00246                            properties.getProperty("rtc.manager.opening_message"));
00247       CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.ORB"),
00248                            properties.getProperty("rtc.manager.orb"));
00249       CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.ORB.OPTIONS"),
00250                            properties.getProperty("rtc.manager.orb.options"));
00251       CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.OS"),
00252                            properties.getProperty("rtc.manager.os"));
00253       CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.OS.RELEASE"),
00254                            properties.getProperty("rtc.manager.os.release"));
00255       CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.SUBSYSTEMS"),
00256                            properties.getProperty("rtc.manager.subsystems"));
00257       CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.OPENRTM.AUTHOR"),
00258                            properties.getProperty("rtc.openrtm.author"));
00259       CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.OPENRTM.RELEASE"),
00260                            properties.getProperty("rtc.openrtm.release"));
00261       CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.OPENRTM.VENDOR"),
00262                            properties.getProperty("rtc.openrtm.vendor"));
00263       CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.OPENRTM.VERSION"),
00264                            properties.getProperty("rtc.openrtm.version"));
00265                         
00266       // システム情報のプロパティが、取得内容に含まれているか?
00267       // (システム情報は動作環境に依存するので、プロパティが取得できていることだけを確認する)
00268       CPPUNIT_ASSERT(std::string("")
00269                      != properties.getProperty("manager.os.name"));
00270       CPPUNIT_ASSERT(std::string("")
00271                      != properties.getProperty("manager.os.release"));
00272       CPPUNIT_ASSERT(std::string("")
00273                      != properties.getProperty("manager.os.version"));
00274       CPPUNIT_ASSERT(std::string("")
00275                      != properties.getProperty("manager.os.arch"));
00276       CPPUNIT_ASSERT(std::string("")
00277                      != properties.getProperty("manager.os.hostname"));
00278       CPPUNIT_ASSERT(std::string("")
00279                      != properties.getProperty("manager.pid"));
00280       CPPUNIT_ASSERT(std::string("")
00281                      != properties.getProperty("manager.is_master"));
00282     }
00283                 
00284   };
00285 }; // namespace ManagerConfig
00286 
00287 /*
00288  * Register test suite
00289  */
00290 CPPUNIT_TEST_SUITE_REGISTRATION(ManagerConfig::ManagerConfigTests);
00291 
00292 #ifdef LOCAL_MAIN
00293 int main(int argc, char* argv[])
00294 {
00295 
00296   FORMAT format = TEXT_OUT;
00297   int target = 0;
00298   std::string xsl;
00299   std::string ns;
00300   std::string fname;
00301   std::ofstream ofs;
00302 
00303   int i(1);
00304   while (i < argc)
00305     {
00306       std::string arg(argv[i]);
00307       std::string next_arg;
00308       if (i + 1 < argc) next_arg = argv[i + 1];
00309       else              next_arg = "";
00310 
00311       if (arg == "--text") { format = TEXT_OUT; break; }
00312       if (arg == "--xml")
00313         {
00314           if (next_arg == "")
00315             {
00316               fname = argv[0];
00317               fname += ".xml";
00318             }
00319           else
00320             {
00321               fname = next_arg;
00322             }
00323           format = XML_OUT;
00324           ofs.open(fname.c_str());
00325         }
00326       if ( arg == "--compiler"  ) { format = COMPILER_OUT; break; }
00327       if ( arg == "--cerr"      ) { target = 1; break; }
00328       if ( arg == "--xsl"       )
00329         {
00330           if (next_arg == "") xsl = "default.xsl"; 
00331           else                xsl = next_arg;
00332         }
00333       if ( arg == "--namespace" )
00334         {
00335           if (next_arg == "")
00336             {
00337               std::cerr << "no namespace specified" << std::endl;
00338               exit(1); 
00339             }
00340           else
00341             {
00342               xsl = next_arg;
00343             }
00344         }
00345       ++i;
00346     }
00347   CppUnit::TextUi::TestRunner runner;
00348   if ( ns.empty() )
00349     runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
00350   else
00351     runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
00352   CppUnit::Outputter* outputter = 0;
00353   std::ostream* stream = target ? &std::cerr : &std::cout;
00354   switch ( format )
00355     {
00356     case TEXT_OUT :
00357       outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
00358       break;
00359     case XML_OUT :
00360       std::cout << "XML_OUT" << std::endl;
00361       outputter = new CppUnit::XmlOutputter(&runner.result(),
00362                                             ofs, "shift_jis");
00363       static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
00364       break;
00365     case COMPILER_OUT :
00366       outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
00367       break;
00368     }
00369   runner.setOutputter(outputter);
00370   runner.run();
00371   return 0; // runner.run() ? 0 : 1;
00372 }
00373 #endif // MAIN
00374 #endif // ManagerConfig_cpp


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