OutPortProviderTests.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
21 /*
22  * $Log: OutPortProviderTests.cpp,v $
23  * Revision 1.1 2008/02/21 12:51:22 arafune
24  * The first commitment.
25  *
26  */
27 
28 #ifndef OutPortProvider_cpp
29 #define OutPortProvider_cpp
30 
31 #include <cppunit/ui/text/TestRunner.h>
32 #include <cppunit/TextOutputter.h>
33 #include <cppunit/extensions/TestFactoryRegistry.h>
34 #include <cppunit/extensions/HelperMacros.h>
35 #include <cppunit/TestAssert.h>
36 #include <rtm/OutPortProvider.h>
37 
42 /*
43  *
44  *
45  * Mock RTC
46  *
47  *
48  */
49 namespace RTC
50 {
59  const char* Logger::m_levelString[] =
60  {
61  " SILENT: ",
62  " FATAL: ",
63  " ERROR: ",
64  " WARNING: ",
65  " INFO: ",
66  " DEBUG: ",
67  " TRACE: ",
68  " VERBOSE: ",
69  " PARANOID: "
70  };
71 
72  Logger::Logger(const char* name)
73  : ::coil::LogStream(&m_logStreamBuf, 0, 8, 0)
74  {
75  }
76 
77  Logger::Logger(LogStreamBuf* streambuf)
78  : ::coil::LogStream(&m_logStreamBuf, 0, 8, 0)
79  {
80  }
81 
82  Logger::~Logger(void)
83  {
84  }
85 
88  bool Logger::setLevel(const char* level)
89  {
90  return true;
91  }
92 
95  void Logger::setDateFormat(const char* format)
96  {
97  }
98 
101  void Logger::setName(const char* name)
102  {
103  }
104 
107  void Logger::header(int level)
108  {
109  }
110 
113  std::string Logger::getDate(void)
114  {
115  const int maxsize = 256;
116  char buf[maxsize];
117 
118  return std::string(buf);
119  }
120 
123  int Logger::strToLevel(const char* level)
124  {
125  return 0;
126  }
127 };
128 /*
129  *
130  *
131  *
132  *
133  *
134  */
136 {
138  : public RTC::OutPortProvider
139  {
140  public:
142  const std::string& portType,
143  const std::string& dataType,
144  const std::string& interfaceType,
145  const std::string& dataFlowType,
146  const std::string& subscriptionType)
147  {
148  setPortType(portType.c_str());
149  setDataType(dataType.c_str());
150  setInterfaceType(interfaceType.c_str());
151  setDataFlowType(dataFlowType.c_str());
152  setSubscriptionType(subscriptionType.c_str());
153 
154  }
155 
157  {
158  NVUtil::appendStringValue(m_properties, "PROPERTY_NAME1", "PROPERTY_VALUE1");
159  NVUtil::appendStringValue(m_properties, "PROPERTY_NAME2", "PROPERTY_VALUE2");
160  }
161 
163  {
164  }
165 
167  {
168  }
170  {
171  }
172 
173  };
174 
175  int g_argc;
176  std::vector<std::string> g_argv;
177 
179  : public CppUnit::TestFixture
180  {
181  CPPUNIT_TEST_SUITE(OutPortProviderTests);
182  CPPUNIT_TEST(test_publishInterfaceProfile);
183  CPPUNIT_TEST(test_publishInterfaceProfile2);
184  CPPUNIT_TEST(test_publishInterface);
185  CPPUNIT_TEST_SUITE_END();
186 
187  public:
188 
193  {
194  char* argv[g_argc];
195  for (int i = 0; i < g_argc; i++) {
196  argv[i] = (char *)g_argv[i].c_str();
197  }
198 
199  CORBA::ORB_var orb = CORBA::ORB_init(g_argc, argv);
200  }
201 
206  {
207  }
208 
212  virtual void setUp()
213  {
214  }
215 
219  virtual void tearDown()
220  {
221  }
222 
232  {
233  std::auto_ptr<RTC::OutPortProvider> provider(
234  new OutPortProviderMock("PORT_TYPE", "DATA_TYPE", "INTERFACE_TYPE",
235  "DATA_FLOW_TYPE", "SUBSCRIPTION_TYPE"));
236 
238  provider->publishInterfaceProfile(prop);
239 
240  // dataport.data_typeプロパティは空か?
241  {
242  const char* value;
243  try {
244  NVUtil::find(prop, "dataport.data_type") >>= value;
245  CPPUNIT_FAIL("dataport.data_type fialure.");
246  }
247  catch(std::string ex) {
248  }
249  catch(...) {
250  CPPUNIT_FAIL("dataport.data_type failure.");
251  }
252  }
253 
254  // dataport.interface_typeプロパティを正しく取得できるか?
255  {
256  const char* value;
257  NVUtil::find(prop, "dataport.interface_type") >>= value;
258  CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE"), std::string(value));
259  }
260 
261  // dataport.dataflow_typeプロパティは空か?
262  {
263  const char* value;
264  try {
265  NVUtil::find(prop, "dataport.dataflow_type") >>= value;
266  CPPUNIT_FAIL("dataport.dataflow_type failure.");
267  }
268  catch(std::string ex) {
269  }
270  catch(...) {
271  CPPUNIT_FAIL("dataport.dataflow_type failure.");
272  }
273  }
274 
275  // dataport.subscription_typeプロパティは空か?
276  {
277  const char* value;
278  try {
279  NVUtil::find(prop, "dataport.subscription_type") >>= value;
280  CPPUNIT_FAIL("dataport.subscription_type failure.");
281  }
282  catch(std::string ex) {
283  }
284  catch(...) {
285  CPPUNIT_FAIL("dataport.subscription_type failure.");
286  }
287  }
288  }
289 
299  {
300  std::auto_ptr<OutPortProviderMock> provider(
301  new OutPortProviderMock("PORT_TYPE", "DATA_TYPE", "INTERFACE_TYPE",
302  "DATA_FLOW_TYPE", "SUBSCRIPTION_TYPE"));
303 
305  provider->publishInterfaceProfile(prop);
306 
307  // (1) インタフェースタイプが不一致の場合:
308  SDOPackage::NVList prop_dummy = prop;
309  for (CORBA::ULong i(0); i < prop_dummy.length(); ++i)
310  {
311  if (std::string(prop_dummy[i].name) == std::string("dataport.interface_type"))
312  {
313  // インタフェースタイプが一致しないように、書き換える prop_dummy[i].value <<= "DUMMY"; } } //m_propertiesへ"PROPERTY_NAME1",”PROPERTY_NAME2”を設定 provider->setDummydataInProperties(); provider->publishInterface(prop_dummy); // インタフェース情報が取得されないことを確認する CPPUNIT_ASSERT_EQUAL(CORBA::Long(-1), NVUtil::find_index(prop_dummy, "PROPERTY_NAME1")); CPPUNIT_ASSERT_EQUAL(CORBA::Long(-1), NVUtil::find_index(prop_dummy, "PROPERTY_NAME2")); // (2) インタフェースタイプ一致の場合: provider->publishInterface(prop); // インタフェース情報が取得されることを確認する CORBA::Long index1 = NVUtil::find_index(prop, "PROPERTY_NAME1"); CORBA::Long index2 = NVUtil::find_index(prop, "PROPERTY_NAME2"); CPPUNIT_ASSERT(CORBA::Long(-1) != index1); CPPUNIT_ASSERT(CORBA::Long(-1) != index2); const char* value1; prop[index1].value >>= value1; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTY_VALUE1"), std::string(value1)); const char* value2; prop[index2].value >>= value2; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTY_VALUE2"), std::string(value2)); } /*! * @brief publishInterfaceProfile()メソッドのテスト * * - publishInterfaceProfileメソッドでm_propertiesを読み込んでいることを確認する。 */ void test_publishInterfaceProfile2() { std::auto_ptr<OutPortProviderMock> provider( new OutPortProviderMock("PORT_TYPE", "DATA_TYPE", "INTERFACE_TYPE", "DATA_FLOW_TYPE", "SUBSCRIPTION_TYPE")); //m_propertiesへ"PROPERTY_NAME1",”PROPERTY_NAME2”を設定 provider->setDummydataInProperties(); SDOPackage::NVList prop; provider->publishInterfaceProfile(prop); // インタフェース情報が取得されることを確認する CORBA::Long index1 = NVUtil::find_index(prop, "PROPERTY_NAME1"); CORBA::Long index2 = NVUtil::find_index(prop, "PROPERTY_NAME2"); CPPUNIT_ASSERT(CORBA::Long(-1) != index1); CPPUNIT_ASSERT(CORBA::Long(-1) != index2); const char* value1; prop[index1].value >>= value1; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTY_VALUE1"), std::string(value1)); const char* value2; prop[index2].value >>= value2; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTY_VALUE2"), std::string(value2)); } }; }; // namespace OutPortProvider /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(OutPortProvider::OutPortProviderTests); #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 // OutPortProvider_cpp
314  prop_dummy[i].value <<= "DUMMY";
315  }
316  }
317 
318  //m_propertiesへ"PROPERTY_NAME1",”PROPERTY_NAME2”を設定 provider->setDummydataInProperties(); provider->publishInterface(prop_dummy); // インタフェース情報が取得されないことを確認する CPPUNIT_ASSERT_EQUAL(CORBA::Long(-1), NVUtil::find_index(prop_dummy, "PROPERTY_NAME1")); CPPUNIT_ASSERT_EQUAL(CORBA::Long(-1), NVUtil::find_index(prop_dummy, "PROPERTY_NAME2")); // (2) インタフェースタイプ一致の場合: provider->publishInterface(prop); // インタフェース情報が取得されることを確認する CORBA::Long index1 = NVUtil::find_index(prop, "PROPERTY_NAME1"); CORBA::Long index2 = NVUtil::find_index(prop, "PROPERTY_NAME2"); CPPUNIT_ASSERT(CORBA::Long(-1) != index1); CPPUNIT_ASSERT(CORBA::Long(-1) != index2); const char* value1; prop[index1].value >>= value1; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTY_VALUE1"), std::string(value1)); const char* value2; prop[index2].value >>= value2; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTY_VALUE2"), std::string(value2)); } /*! * @brief publishInterfaceProfile()メソッドのテスト * * - publishInterfaceProfileメソッドでm_propertiesを読み込んでいることを確認する。 */ void test_publishInterfaceProfile2() { std::auto_ptr<OutPortProviderMock> provider( new OutPortProviderMock("PORT_TYPE", "DATA_TYPE", "INTERFACE_TYPE", "DATA_FLOW_TYPE", "SUBSCRIPTION_TYPE")); //m_propertiesへ"PROPERTY_NAME1",”PROPERTY_NAME2”を設定 provider->setDummydataInProperties(); SDOPackage::NVList prop; provider->publishInterfaceProfile(prop); // インタフェース情報が取得されることを確認する CORBA::Long index1 = NVUtil::find_index(prop, "PROPERTY_NAME1"); CORBA::Long index2 = NVUtil::find_index(prop, "PROPERTY_NAME2"); CPPUNIT_ASSERT(CORBA::Long(-1) != index1); CPPUNIT_ASSERT(CORBA::Long(-1) != index2); const char* value1; prop[index1].value >>= value1; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTY_VALUE1"), std::string(value1)); const char* value2; prop[index2].value >>= value2; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTY_VALUE2"), std::string(value2)); } }; }; // namespace OutPortProvider /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(OutPortProvider::OutPortProviderTests); #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 // OutPortProvider_cpp
319  provider->setDummydataInProperties();
320 
321  provider->publishInterface(prop_dummy);
322 
323  // インタフェース情報が取得されないことを確認する CPPUNIT_ASSERT_EQUAL(CORBA::Long(-1), NVUtil::find_index(prop_dummy, "PROPERTY_NAME1")); CPPUNIT_ASSERT_EQUAL(CORBA::Long(-1), NVUtil::find_index(prop_dummy, "PROPERTY_NAME2")); // (2) インタフェースタイプ一致の場合: provider->publishInterface(prop); // インタフェース情報が取得されることを確認する CORBA::Long index1 = NVUtil::find_index(prop, "PROPERTY_NAME1"); CORBA::Long index2 = NVUtil::find_index(prop, "PROPERTY_NAME2"); CPPUNIT_ASSERT(CORBA::Long(-1) != index1); CPPUNIT_ASSERT(CORBA::Long(-1) != index2); const char* value1; prop[index1].value >>= value1; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTY_VALUE1"), std::string(value1)); const char* value2; prop[index2].value >>= value2; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTY_VALUE2"), std::string(value2)); } /*! * @brief publishInterfaceProfile()メソッドのテスト * * - publishInterfaceProfileメソッドでm_propertiesを読み込んでいることを確認する。 */ void test_publishInterfaceProfile2() { std::auto_ptr<OutPortProviderMock> provider( new OutPortProviderMock("PORT_TYPE", "DATA_TYPE", "INTERFACE_TYPE", "DATA_FLOW_TYPE", "SUBSCRIPTION_TYPE")); //m_propertiesへ"PROPERTY_NAME1",”PROPERTY_NAME2”を設定 provider->setDummydataInProperties(); SDOPackage::NVList prop; provider->publishInterfaceProfile(prop); // インタフェース情報が取得されることを確認する CORBA::Long index1 = NVUtil::find_index(prop, "PROPERTY_NAME1"); CORBA::Long index2 = NVUtil::find_index(prop, "PROPERTY_NAME2"); CPPUNIT_ASSERT(CORBA::Long(-1) != index1); CPPUNIT_ASSERT(CORBA::Long(-1) != index2); const char* value1; prop[index1].value >>= value1; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTY_VALUE1"), std::string(value1)); const char* value2; prop[index2].value >>= value2; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTY_VALUE2"), std::string(value2)); } }; }; // namespace OutPortProvider /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(OutPortProvider::OutPortProviderTests); #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 // OutPortProvider_cpp
324  CPPUNIT_ASSERT_EQUAL(CORBA::Long(-1), NVUtil::find_index(prop_dummy, "PROPERTY_NAME1"));
325  CPPUNIT_ASSERT_EQUAL(CORBA::Long(-1), NVUtil::find_index(prop_dummy, "PROPERTY_NAME2"));
326 
327  // (2) インタフェースタイプ一致の場合:
328  provider->publishInterface(prop);
329 
330  // インタフェース情報が取得されることを確認する CORBA::Long index1 = NVUtil::find_index(prop, "PROPERTY_NAME1"); CORBA::Long index2 = NVUtil::find_index(prop, "PROPERTY_NAME2"); CPPUNIT_ASSERT(CORBA::Long(-1) != index1); CPPUNIT_ASSERT(CORBA::Long(-1) != index2); const char* value1; prop[index1].value >>= value1; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTY_VALUE1"), std::string(value1)); const char* value2; prop[index2].value >>= value2; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTY_VALUE2"), std::string(value2)); } /*! * @brief publishInterfaceProfile()メソッドのテスト * * - publishInterfaceProfileメソッドでm_propertiesを読み込んでいることを確認する。 */ void test_publishInterfaceProfile2() { std::auto_ptr<OutPortProviderMock> provider( new OutPortProviderMock("PORT_TYPE", "DATA_TYPE", "INTERFACE_TYPE", "DATA_FLOW_TYPE", "SUBSCRIPTION_TYPE")); //m_propertiesへ"PROPERTY_NAME1",”PROPERTY_NAME2”を設定 provider->setDummydataInProperties(); SDOPackage::NVList prop; provider->publishInterfaceProfile(prop); // インタフェース情報が取得されることを確認する CORBA::Long index1 = NVUtil::find_index(prop, "PROPERTY_NAME1"); CORBA::Long index2 = NVUtil::find_index(prop, "PROPERTY_NAME2"); CPPUNIT_ASSERT(CORBA::Long(-1) != index1); CPPUNIT_ASSERT(CORBA::Long(-1) != index2); const char* value1; prop[index1].value >>= value1; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTY_VALUE1"), std::string(value1)); const char* value2; prop[index2].value >>= value2; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTY_VALUE2"), std::string(value2)); } }; }; // namespace OutPortProvider /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(OutPortProvider::OutPortProviderTests); #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 // OutPortProvider_cpp
331  CORBA::Long index1 = NVUtil::find_index(prop, "PROPERTY_NAME1");
332  CORBA::Long index2 = NVUtil::find_index(prop, "PROPERTY_NAME2");
333  CPPUNIT_ASSERT(CORBA::Long(-1) != index1);
334  CPPUNIT_ASSERT(CORBA::Long(-1) != index2);
335 
336  const char* value1;
337  prop[index1].value >>= value1;
338  CPPUNIT_ASSERT_EQUAL(std::string("PROPERTY_VALUE1"), std::string(value1));
339 
340  const char* value2;
341  prop[index2].value >>= value2;
342  CPPUNIT_ASSERT_EQUAL(std::string("PROPERTY_VALUE2"), std::string(value2));
343  }
350  {
351  std::auto_ptr<OutPortProviderMock> provider(
352  new OutPortProviderMock("PORT_TYPE", "DATA_TYPE", "INTERFACE_TYPE",
353  "DATA_FLOW_TYPE", "SUBSCRIPTION_TYPE"));
354 
355 
356  //m_propertiesへ"PROPERTY_NAME1",”PROPERTY_NAME2”を設定 provider->setDummydataInProperties(); SDOPackage::NVList prop; provider->publishInterfaceProfile(prop); // インタフェース情報が取得されることを確認する CORBA::Long index1 = NVUtil::find_index(prop, "PROPERTY_NAME1"); CORBA::Long index2 = NVUtil::find_index(prop, "PROPERTY_NAME2"); CPPUNIT_ASSERT(CORBA::Long(-1) != index1); CPPUNIT_ASSERT(CORBA::Long(-1) != index2); const char* value1; prop[index1].value >>= value1; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTY_VALUE1"), std::string(value1)); const char* value2; prop[index2].value >>= value2; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTY_VALUE2"), std::string(value2)); } }; }; // namespace OutPortProvider /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(OutPortProvider::OutPortProviderTests); #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 // OutPortProvider_cpp
357  provider->setDummydataInProperties();
358 
360  provider->publishInterfaceProfile(prop);
361  // インタフェース情報が取得されることを確認する CORBA::Long index1 = NVUtil::find_index(prop, "PROPERTY_NAME1"); CORBA::Long index2 = NVUtil::find_index(prop, "PROPERTY_NAME2"); CPPUNIT_ASSERT(CORBA::Long(-1) != index1); CPPUNIT_ASSERT(CORBA::Long(-1) != index2); const char* value1; prop[index1].value >>= value1; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTY_VALUE1"), std::string(value1)); const char* value2; prop[index2].value >>= value2; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTY_VALUE2"), std::string(value2)); } }; }; // namespace OutPortProvider /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(OutPortProvider::OutPortProviderTests); #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 // OutPortProvider_cpp
362  CORBA::Long index1 = NVUtil::find_index(prop, "PROPERTY_NAME1");
363  CORBA::Long index2 = NVUtil::find_index(prop, "PROPERTY_NAME2");
364  CPPUNIT_ASSERT(CORBA::Long(-1) != index1);
365  CPPUNIT_ASSERT(CORBA::Long(-1) != index2);
366 
367  const char* value1;
368  prop[index1].value >>= value1;
369  CPPUNIT_ASSERT_EQUAL(std::string("PROPERTY_VALUE1"), std::string(value1));
370 
371  const char* value2;
372  prop[index2].value >>= value2;
373  CPPUNIT_ASSERT_EQUAL(std::string("PROPERTY_VALUE2"), std::string(value2));
374 
375  }
376 
377  };
378 }; // namespace OutPortProvider
379 
380 /*
381  * Register test suite
382  */
384 
385 #ifdef LOCAL_MAIN
386 int main(int argc, char* argv[])
387 {
388 
389  FORMAT format = TEXT_OUT;
390  int target = 0;
391  std::string xsl;
392  std::string ns;
393  std::string fname;
394  std::ofstream ofs;
395 
396  int i(1);
397  while (i < argc)
398  {
399  std::string arg(argv[i]);
400  std::string next_arg;
401  if (i + 1 < argc) next_arg = argv[i + 1];
402  else next_arg = "";
403 
404  if (arg == "--text") { format = TEXT_OUT; break; }
405  if (arg == "--xml")
406  {
407  if (next_arg == "")
408  {
409  fname = argv[0];
410  fname += ".xml";
411  }
412  else
413  {
414  fname = next_arg;
415  }
416  format = XML_OUT;
417  ofs.open(fname.c_str());
418  }
419  if ( arg == "--compiler" ) { format = COMPILER_OUT; break; }
420  if ( arg == "--cerr" ) { target = 1; break; }
421  if ( arg == "--xsl" )
422  {
423  if (next_arg == "") xsl = "default.xsl";
424  else xsl = next_arg;
425  }
426  if ( arg == "--namespace" )
427  {
428  if (next_arg == "")
429  {
430  std::cerr << "no namespace specified" << std::endl;
431  exit(1);
432  }
433  else
434  {
435  xsl = next_arg;
436  }
437  }
438  ++i;
439  }
440  CppUnit::TextUi::TestRunner runner;
441  if ( ns.empty() )
442  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
443  else
444  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
445  CppUnit::Outputter* outputter = 0;
446  std::ostream* stream = target ? &std::cerr : &std::cout;
447  switch ( format )
448  {
449  case TEXT_OUT :
450  outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
451  break;
452  case XML_OUT :
453  std::cout << "XML_OUT" << std::endl;
454  outputter = new CppUnit::XmlOutputter(&runner.result(),
455  ofs, "shift_jis");
456  static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
457  break;
458  case COMPILER_OUT :
459  outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
460  break;
461  }
462  runner.setOutputter(outputter);
463  runner.run();
464  return 0; // runner.run() ? 0 : 1;
465 }
466 #endif // MAIN
467 #endif // OutPortProvider_cpp
void setDateFormat(const char *format)
Set date/time format for adding the header.
ConnectorListeners class.
virtual ~Logger(void)
Virtual destructor.
int main(int argc, char **argv)
virtual void header(int level)
Message prefix appender function.
void test_publishInterface()
publishInterface()メソッドのテスト
OutPortConnector base class.
RT-Component.
LogStreamBuf m_logStreamBuf
virtual void setUp()
Test initialization.
virtual void tearDown()
Test finalization.
void setConnector(RTC::OutPortConnector *connector)
set Connector
::coil::LogStreamBuffer LogStreamBuf
Definition: SystemLogger.h:34
bool appendStringValue(SDOPackage::NVList &nv, const char *name, const char *value)
Append the specified string to element of NVList.
Definition: NVUtil.cpp:313
std::vector< std::pair< std::string, std::string > > NVList
Definition: IRTC.h:67
void setName(const char *name)
Set suffix of date/time string of header.
log_stream< char > LogStream
CPPUNIT_TEST_SUITE_REGISTRATION(OutPortProvider::OutPortProviderTests)
void setBuffer(RTC::CdrBufferBase *buffer)
Setting outside buffer&#39;s pointer.
const CORBA::Long find_index(const SDOPackage::NVList &nv, const char *name)
Return the index of element specified by name from NVList.
Definition: NVUtil.cpp:227
void test_publishInterfaceProfile2()
publishInterfaceProfile()メソッドのテスト
const CORBA::Any & find(const SDOPackage::NVList &nv, const char *name)
Return the value specified by name from NVList.
Definition: NVUtil.cpp:212
OutPortProviderMock(const std::string &portType, const std::string &dataType, const std::string &interfaceType, const std::string &dataFlowType, const std::string &subscriptionType)
OutPortProvider class.
OutPortProvider.
bool setLevel(const char *level)
Set log level by string.
prop
Organization::get_organization_property ();.
ostream_type & level(int level)
Acquire log stream.
std::vector< std::string > g_argv
void test_publishInterfaceProfile()
publishInterfaceProfile()メソッドのテスト。
void setListener(RTC::ConnectorInfo &info, RTC::ConnectorListeners *listeners)
Set the listener.
Logger(const char *name="")
Constructor.
int strToLevel(const char *level)
Set the log level Set the log level corresponding to the given string.
static const char * m_levelString[]
Definition: SystemLogger.h:342
BufferBase abstract class.
Definition: BufferBase.h:104
std::string getDate(void)
Get the current formatted date/time string Get the current datetime described by specified format...


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