ManagerConfigTests.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
12 /*
13  * $Log: ManagerConfigTests.cpp,v $
14  * Revision 1.3 2008/05/01 08:01:03 arafune
15  * Modified some tests.
16  *
17  * Revision 1.2 2008/05/01 07:52:46 arafune
18  * Modified some tests.
19  *
20  *
21  * Revision 1.1 2006/11/27 08:25:57 n-ando
22  * TestSuites are devided into each directory.
23  *
24  *
25  */
26 
27 #ifndef ManagerConfig_cpp
28 #define ManagerConfig_cpp
29 
30 #include <cppunit/ui/text/TestRunner.h>
31 #include <cppunit/TextOutputter.h>
32 #include <cppunit/extensions/TestFactoryRegistry.h>
33 #include <cppunit/extensions/HelperMacros.h>
34 #include <cppunit/TestAssert.h>
35 
36 #include <fstream>
37 #include <vector>
38 #include <string>
39 
40 #include <rtm/ManagerConfig.h>
41 
46 namespace ManagerConfig
47 {
48  int g_argc;
49  //char* g_argv[10];
50  std::vector<std::string> g_argv;
51 
53  {
54  public:
55  void parseArgs(int argc, char** argv)
56  {
57  ManagerConfig::parseArgs(argc, argv);
58  }
59 
61  {
62  return ManagerConfig::findConfigFile();
63  }
64 
66  {
67  ManagerConfig::setSystemInformation(prop);
68  }
69 
70  bool fileExist(const std::string& filename)
71  {
72  return ManagerConfig::fileExist(filename);
73  }
74 
75  public:
76  std::string& configFile()
77  {
78  return m_configFile;
79  }
80  bool m_isMaster;
81  };
82 
84  : public CppUnit::TestFixture
85  {
86  CPPUNIT_TEST_SUITE(ManagerConfigTests);
87  CPPUNIT_TEST(test_init_and_configure);
88  CPPUNIT_TEST(test_init_default);
89  CPPUNIT_TEST_SUITE_END();
90 
91  public:
96  {
97  }
98 
103  {
104  }
105 
109  virtual void setUp()
110  {
111  }
112 
116  virtual void tearDown()
117  {
118  }
119 
128  {
129  ManagerConfigMock mgrCfg;
130  CPPUNIT_ASSERT(mgrCfg.fileExist("./rtc.conf"));
131 
132  // コマンド引数の-fオプションで指定したファイルで正しく初期化できるか?
133 // char* argv[] = { "command", "-f", "./rtc.conf" };
134  char* argv[] = { "command", "-d", "./rtc.conf" };
135  int argc = sizeof(argv) / sizeof(char*);
136  mgrCfg.init(argc, argv);
137 
138  // 設定されている内容を正しく取得できるか?
139  coil::Properties properties;
140  mgrCfg.configure(properties);
141 
142  CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.COMPONENT.CONF.PATH"),
143  properties.getProperty("rtc.component.conf.path"));
144  CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.ARCH"),
145  properties.getProperty("rtc.manager.arch"));
146  CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.DEBUG.LEVEL"),
147  properties.getProperty("rtc.manager.debug.level"));
148  CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.LANGUAGE"),
149  properties.getProperty("rtc.manager.language"));
150  CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.NAMESERVER"),
151  properties.getProperty("rtc.manager.nameserver"));
152  CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.OPENING_MESSAGE"),
153  properties.getProperty("rtc.manager.opening_message"));
154  CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.ORB"),
155  properties.getProperty("rtc.manager.orb"));
156  CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.ORB.OPTIONS"),
157  properties.getProperty("rtc.manager.orb.options"));
158  CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.OS"),
159  properties.getProperty("rtc.manager.os"));
160  CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.OS.RELEASE"),
161  properties.getProperty("rtc.manager.os.release"));
162  CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.SUBSYSTEMS"),
163  properties.getProperty("rtc.manager.subsystems"));
164  CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.OPENRTM.AUTHOR"),
165  properties.getProperty("rtc.openrtm.author"));
166  CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.OPENRTM.RELEASE"),
167  properties.getProperty("rtc.openrtm.release"));
168  CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.OPENRTM.VENDOR"),
169  properties.getProperty("rtc.openrtm.vendor"));
170  CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.OPENRTM.VERSION"),
171  properties.getProperty("rtc.openrtm.version"));
172 
173  // システム情報のプロパティが、取得内容に含まれているか?
174  // (システム情報は動作環境に依存するので、プロパティが取得できていることだけを確認する) CPPUNIT_ASSERT(std::string("") != properties.getProperty("manager.os.name")); CPPUNIT_ASSERT(std::string("") != properties.getProperty("manager.os.release")); CPPUNIT_ASSERT(std::string("") != properties.getProperty("manager.os.version")); CPPUNIT_ASSERT(std::string("") != properties.getProperty("manager.os.arch")); CPPUNIT_ASSERT(std::string("") != properties.getProperty("manager.os.hostname")); CPPUNIT_ASSERT(std::string("") != properties.getProperty("manager.pid")); CPPUNIT_ASSERT(std::string("YES") == properties.getProperty("manager.is_master")); // コマンド引数の-aオプション指定が正しく反映されるか? // corba.corba_servant 指定の確認 argv[1] = "-a"; argc = sizeof(argv) / sizeof(char*); mgrCfg.init(argc, argv); mgrCfg.configure(properties); CPPUNIT_ASSERT_EQUAL(std::string("NO"), properties.getProperty("manager.corba_servant")); // コマンド引数の-oオプション指定が正しく反映されるか? // configuration 上書き指定の確認 argv[1] = "-omanager.is_master:NO"; argc = sizeof(argv) / sizeof(char*); mgrCfg.init(argc, argv); mgrCfg.configure(properties); CPPUNIT_ASSERT_EQUAL(std::string("NO"), properties.getProperty("manager.is_master")); // コマンド引数の-pオプション指定が正しく反映されるか? // corba.endpoints ポート番号指定の確認 argv[1] = "-p9876"; argc = sizeof(argv) / sizeof(char*); mgrCfg.init(argc, argv); mgrCfg.configure(properties); CPPUNIT_ASSERT_EQUAL(std::string(":9876"), properties.getProperty("corba.endpoints")); } /*! * @brief init()メソッドのテスト * * - コンフィグファイルの指定オプションなしで初期化した場合、デフォルトのコンフィグレーションファイルの内容で初期化されるか? */ void test_init_default() { ManagerConfigMock mgrCfg; // オプション指定なしで初期化する mgrCfg.init(0, NULL); // 設定されている内容を正しく取得できるか? coil::Properties properties; mgrCfg.configure(properties); CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.COMPONENT.CONF.PATH"), properties.getProperty("rtc.component.conf.path")); CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.ARCH"), properties.getProperty("rtc.manager.arch")); CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.DEBUG.LEVEL"), properties.getProperty("rtc.manager.debug.level")); CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.LANGUAGE"), properties.getProperty("rtc.manager.language")); CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.NAMESERVER"), properties.getProperty("rtc.manager.nameserver")); CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.OPENING_MESSAGE"), properties.getProperty("rtc.manager.opening_message")); CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.ORB"), properties.getProperty("rtc.manager.orb")); CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.ORB.OPTIONS"), properties.getProperty("rtc.manager.orb.options")); CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.OS"), properties.getProperty("rtc.manager.os")); CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.OS.RELEASE"), properties.getProperty("rtc.manager.os.release")); CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.SUBSYSTEMS"), properties.getProperty("rtc.manager.subsystems")); CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.OPENRTM.AUTHOR"), properties.getProperty("rtc.openrtm.author")); CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.OPENRTM.RELEASE"), properties.getProperty("rtc.openrtm.release")); CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.OPENRTM.VENDOR"), properties.getProperty("rtc.openrtm.vendor")); CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.OPENRTM.VERSION"), properties.getProperty("rtc.openrtm.version")); // システム情報のプロパティが、取得内容に含まれているか? // (システム情報は動作環境に依存するので、プロパティが取得できていることだけを確認する) CPPUNIT_ASSERT(std::string("") != properties.getProperty("manager.os.name")); CPPUNIT_ASSERT(std::string("") != properties.getProperty("manager.os.release")); CPPUNIT_ASSERT(std::string("") != properties.getProperty("manager.os.version")); CPPUNIT_ASSERT(std::string("") != properties.getProperty("manager.os.arch")); CPPUNIT_ASSERT(std::string("") != properties.getProperty("manager.os.hostname")); CPPUNIT_ASSERT(std::string("") != properties.getProperty("manager.pid")); CPPUNIT_ASSERT(std::string("") != properties.getProperty("manager.is_master")); } }; }; // namespace ManagerConfig /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(ManagerConfig::ManagerConfigTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // ManagerConfig_cpp
175  CPPUNIT_ASSERT(std::string("")
176  != properties.getProperty("manager.os.name"));
177  CPPUNIT_ASSERT(std::string("")
178  != properties.getProperty("manager.os.release"));
179  CPPUNIT_ASSERT(std::string("")
180  != properties.getProperty("manager.os.version"));
181  CPPUNIT_ASSERT(std::string("")
182  != properties.getProperty("manager.os.arch"));
183  CPPUNIT_ASSERT(std::string("")
184  != properties.getProperty("manager.os.hostname"));
185  CPPUNIT_ASSERT(std::string("")
186  != properties.getProperty("manager.pid"));
187  CPPUNIT_ASSERT(std::string("YES")
188  == properties.getProperty("manager.is_master"));
189 
190  // コマンド引数の-aオプション指定が正しく反映されるか?
191  // corba.corba_servant 指定の確認
192  argv[1] = "-a";
193  argc = sizeof(argv) / sizeof(char*);
194  mgrCfg.init(argc, argv);
195  mgrCfg.configure(properties);
196  CPPUNIT_ASSERT_EQUAL(std::string("NO"),
197  properties.getProperty("manager.corba_servant"));
198 
199  // コマンド引数の-oオプション指定が正しく反映されるか?
200  // configuration 上書き指定の確認
201  argv[1] = "-omanager.is_master:NO";
202  argc = sizeof(argv) / sizeof(char*);
203  mgrCfg.init(argc, argv);
204  mgrCfg.configure(properties);
205  CPPUNIT_ASSERT_EQUAL(std::string("NO"),
206  properties.getProperty("manager.is_master"));
207 
208  // コマンド引数の-pオプション指定が正しく反映されるか?
209  // corba.endpoints ポート番号指定の確認
210  argv[1] = "-p9876";
211  argc = sizeof(argv) / sizeof(char*);
212  mgrCfg.init(argc, argv);
213  mgrCfg.configure(properties);
214  CPPUNIT_ASSERT_EQUAL(std::string(":9876"),
215  properties.getProperty("corba.endpoints"));
216  }
217 
224  {
225 
226  ManagerConfigMock mgrCfg;
227 
228  // オプション指定なしで初期化する mgrCfg.init(0, NULL); // 設定されている内容を正しく取得できるか? coil::Properties properties; mgrCfg.configure(properties); CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.COMPONENT.CONF.PATH"), properties.getProperty("rtc.component.conf.path")); CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.ARCH"), properties.getProperty("rtc.manager.arch")); CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.DEBUG.LEVEL"), properties.getProperty("rtc.manager.debug.level")); CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.LANGUAGE"), properties.getProperty("rtc.manager.language")); CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.NAMESERVER"), properties.getProperty("rtc.manager.nameserver")); CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.OPENING_MESSAGE"), properties.getProperty("rtc.manager.opening_message")); CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.ORB"), properties.getProperty("rtc.manager.orb")); CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.ORB.OPTIONS"), properties.getProperty("rtc.manager.orb.options")); CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.OS"), properties.getProperty("rtc.manager.os")); CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.OS.RELEASE"), properties.getProperty("rtc.manager.os.release")); CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.SUBSYSTEMS"), properties.getProperty("rtc.manager.subsystems")); CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.OPENRTM.AUTHOR"), properties.getProperty("rtc.openrtm.author")); CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.OPENRTM.RELEASE"), properties.getProperty("rtc.openrtm.release")); CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.OPENRTM.VENDOR"), properties.getProperty("rtc.openrtm.vendor")); CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.OPENRTM.VERSION"), properties.getProperty("rtc.openrtm.version")); // システム情報のプロパティが、取得内容に含まれているか? // (システム情報は動作環境に依存するので、プロパティが取得できていることだけを確認する) CPPUNIT_ASSERT(std::string("") != properties.getProperty("manager.os.name")); CPPUNIT_ASSERT(std::string("") != properties.getProperty("manager.os.release")); CPPUNIT_ASSERT(std::string("") != properties.getProperty("manager.os.version")); CPPUNIT_ASSERT(std::string("") != properties.getProperty("manager.os.arch")); CPPUNIT_ASSERT(std::string("") != properties.getProperty("manager.os.hostname")); CPPUNIT_ASSERT(std::string("") != properties.getProperty("manager.pid")); CPPUNIT_ASSERT(std::string("") != properties.getProperty("manager.is_master")); } }; }; // namespace ManagerConfig /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(ManagerConfig::ManagerConfigTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // ManagerConfig_cpp
229  mgrCfg.init(0, NULL);
230 
231  // 設定されている内容を正しく取得できるか?
232  coil::Properties properties;
233  mgrCfg.configure(properties);
234 
235  CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.COMPONENT.CONF.PATH"),
236  properties.getProperty("rtc.component.conf.path"));
237  CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.ARCH"),
238  properties.getProperty("rtc.manager.arch"));
239  CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.DEBUG.LEVEL"),
240  properties.getProperty("rtc.manager.debug.level"));
241  CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.LANGUAGE"),
242  properties.getProperty("rtc.manager.language"));
243  CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.NAMESERVER"),
244  properties.getProperty("rtc.manager.nameserver"));
245  CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.OPENING_MESSAGE"),
246  properties.getProperty("rtc.manager.opening_message"));
247  CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.ORB"),
248  properties.getProperty("rtc.manager.orb"));
249  CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.ORB.OPTIONS"),
250  properties.getProperty("rtc.manager.orb.options"));
251  CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.OS"),
252  properties.getProperty("rtc.manager.os"));
253  CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.OS.RELEASE"),
254  properties.getProperty("rtc.manager.os.release"));
255  CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.MANAGER.SUBSYSTEMS"),
256  properties.getProperty("rtc.manager.subsystems"));
257  CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.OPENRTM.AUTHOR"),
258  properties.getProperty("rtc.openrtm.author"));
259  CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.OPENRTM.RELEASE"),
260  properties.getProperty("rtc.openrtm.release"));
261  CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.OPENRTM.VENDOR"),
262  properties.getProperty("rtc.openrtm.vendor"));
263  CPPUNIT_ASSERT_EQUAL(std::string("DEFAULT.RTC.OPENRTM.VERSION"),
264  properties.getProperty("rtc.openrtm.version"));
265 
266  // システム情報のプロパティが、取得内容に含まれているか?
267  // (システム情報は動作環境に依存するので、プロパティが取得できていることだけを確認する) CPPUNIT_ASSERT(std::string("") != properties.getProperty("manager.os.name")); CPPUNIT_ASSERT(std::string("") != properties.getProperty("manager.os.release")); CPPUNIT_ASSERT(std::string("") != properties.getProperty("manager.os.version")); CPPUNIT_ASSERT(std::string("") != properties.getProperty("manager.os.arch")); CPPUNIT_ASSERT(std::string("") != properties.getProperty("manager.os.hostname")); CPPUNIT_ASSERT(std::string("") != properties.getProperty("manager.pid")); CPPUNIT_ASSERT(std::string("") != properties.getProperty("manager.is_master")); } }; }; // namespace ManagerConfig /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(ManagerConfig::ManagerConfigTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // ManagerConfig_cpp
268  CPPUNIT_ASSERT(std::string("")
269  != properties.getProperty("manager.os.name"));
270  CPPUNIT_ASSERT(std::string("")
271  != properties.getProperty("manager.os.release"));
272  CPPUNIT_ASSERT(std::string("")
273  != properties.getProperty("manager.os.version"));
274  CPPUNIT_ASSERT(std::string("")
275  != properties.getProperty("manager.os.arch"));
276  CPPUNIT_ASSERT(std::string("")
277  != properties.getProperty("manager.os.hostname"));
278  CPPUNIT_ASSERT(std::string("")
279  != properties.getProperty("manager.pid"));
280  CPPUNIT_ASSERT(std::string("")
281  != properties.getProperty("manager.is_master"));
282  }
283 
284  };
285 }; // namespace ManagerConfig
286 
287 /*
288  * Register test suite
289  */
291 
292 #ifdef LOCAL_MAIN
293 int main(int argc, char* argv[])
294 {
295 
296  FORMAT format = TEXT_OUT;
297  int target = 0;
298  std::string xsl;
299  std::string ns;
300  std::string fname;
301  std::ofstream ofs;
302 
303  int i(1);
304  while (i < argc)
305  {
306  std::string arg(argv[i]);
307  std::string next_arg;
308  if (i + 1 < argc) next_arg = argv[i + 1];
309  else next_arg = "";
310 
311  if (arg == "--text") { format = TEXT_OUT; break; }
312  if (arg == "--xml")
313  {
314  if (next_arg == "")
315  {
316  fname = argv[0];
317  fname += ".xml";
318  }
319  else
320  {
321  fname = next_arg;
322  }
323  format = XML_OUT;
324  ofs.open(fname.c_str());
325  }
326  if ( arg == "--compiler" ) { format = COMPILER_OUT; break; }
327  if ( arg == "--cerr" ) { target = 1; break; }
328  if ( arg == "--xsl" )
329  {
330  if (next_arg == "") xsl = "default.xsl";
331  else xsl = next_arg;
332  }
333  if ( arg == "--namespace" )
334  {
335  if (next_arg == "")
336  {
337  std::cerr << "no namespace specified" << std::endl;
338  exit(1);
339  }
340  else
341  {
342  xsl = next_arg;
343  }
344  }
345  ++i;
346  }
347  CppUnit::TextUi::TestRunner runner;
348  if ( ns.empty() )
349  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
350  else
351  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
352  CppUnit::Outputter* outputter = 0;
353  std::ostream* stream = target ? &std::cerr : &std::cout;
354  switch ( format )
355  {
356  case TEXT_OUT :
357  outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
358  break;
359  case XML_OUT :
360  std::cout << "XML_OUT" << std::endl;
361  outputter = new CppUnit::XmlOutputter(&runner.result(),
362  ofs, "shift_jis");
363  static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
364  break;
365  case COMPILER_OUT :
366  outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
367  break;
368  }
369  runner.setOutputter(outputter);
370  runner.run();
371  return 0; // runner.run() ? 0 : 1;
372 }
373 #endif // MAIN
374 #endif // ManagerConfig_cpp
int main(int argc, char **argv)
void parseArgs(int argc, char **argv)
Manager configuration class.
Definition: ManagerConfig.h:84
void setSystemInformation(coil::Properties &prop)
std::string m_configFile
Manager&#39;s configuration file path.
virtual void tearDown()
Test finalization.
RTC manager configuration.
std::vector< std::string > g_argv
void configure(coil::Properties &prop)
Specify the configuration information to the Property.
void test_init_and_configure()
init()メソッドとconfigure()メソッドのテスト
void init(int argc, char **argv)
Initialization.
virtual void setUp()
Test initialization.
void test_init_default()
init()メソッドのテスト
CPPUNIT_TEST_SUITE_REGISTRATION(ManagerConfig::ManagerConfigTests)
prop
Organization::get_organization_property ();.
bool fileExist(const std::string &filename)
Class represents a set of properties.
Definition: Properties.h:101
const std::string & getProperty(const std::string &key) const
Search for the property with the specified key in this property.
Definition: Properties.cpp:156


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Jun 10 2019 14:07:53