InPortProviderTests.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
21 /*
22  * $Log: InPortProviderTests.cpp,v $
23  * Revision 1.1 2008/03/10 11:28:31 arafune
24  * The first commitment.
25  *
26  * Revision 1.1 2008/02/21 12:51:22 arafune
27  * The first commitment.
28  *
29  */
30 
31 #ifndef InPortProvider_cpp
32 #define InPortProvider_cpp
33 
34 #include <cppunit/ui/text/TestRunner.h>
35 #include <cppunit/TextOutputter.h>
36 #include <cppunit/extensions/TestFactoryRegistry.h>
37 #include <cppunit/extensions/HelperMacros.h>
38 #include <cppunit/TestAssert.h>
39 #include <rtm/InPortProvider.h>
40 #include <rtm/BufferBase.h>
41 
46 namespace InPortProvider
47 {
49  : public RTC::InPortProvider
50  {
51  public:
53  const std::string& interfaceType,
54  const std::string& dataFlowType,
55  const std::string& subscriptionType)
56  {
57  setInterfaceType(interfaceType.c_str());
58  setDataFlowType(dataFlowType.c_str());
59  setSubscriptionType(subscriptionType.c_str());
60  }
62  {
63  NVUtil::appendStringValue(m_properties, "KEY1", "VALUE1");
64  NVUtil::appendStringValue(m_properties, "KEY2", "VALUE2");
65  }
67  {
68  }
70  {
71  }
73  RTC::ConnectorListeners* listeners)
74  {
75  }
77  {
78  }
79  };
80 
81  int g_argc;
82  std::vector<std::string> g_argv;
83 
85  : public CppUnit::TestFixture
86  {
87  CPPUNIT_TEST_SUITE(InPortProviderTests);
88  CPPUNIT_TEST(test_publishInterfaceProfile);
89  CPPUNIT_TEST(test_publishInterface_with_interfaceType_matched);
90  CPPUNIT_TEST(test_publishInterface_with_interfaceType_unmatched);
91  CPPUNIT_TEST_SUITE_END();
92 
93  public:
94 
99  {
100  char* argv[g_argc];
101  for (int i = 0; i < g_argc; i++) {
102  argv[i] = (char *)g_argv[i].c_str();
103  }
104 
105  CORBA::ORB_var orb = CORBA::ORB_init(g_argc, argv);
106  }
107 
112  {
113  }
114 
118  virtual void setUp()
119  {
120  }
121 
125  virtual void tearDown()
126  {
127  }
128 
137  {
138  std::auto_ptr<InPortProviderMock> provider(
139  new InPortProviderMock("INTERFACE_TYPE", "DATA_FLOW_TYPE", "SUBSCRIPTION_TYPE"));
140 
141  //m_propertiesへ設定 provider->setDummydataInProperties(); SDOPackage::NVList prop; provider->publishInterfaceProfile(prop); // "dataport.interface_type" CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE"), NVUtil::toString(prop, "dataport.interface_type")); // CPPUNIT_ASSERT_EQUAL(std::string("VALUE1"), NVUtil::toString(prop, "KEY1")); CPPUNIT_ASSERT_EQUAL(std::string("VALUE2"), NVUtil::toString(prop, "KEY2")); } /*! * @brief publishInterface() * * - */ void test_publishInterface_with_interfaceType_matched() { std::auto_ptr<InPortProviderMock> provider( new InPortProviderMock("INTERFACE_TYPE", "DATA_FLOW_TYPE", "SUBSCRIPTION_TYPE")); //m_propertiesへ設定 provider->setDummydataInProperties(); SDOPackage::NVList props; NVUtil::appendStringValue(props, "dataport.interface_type", "INTERFACE_TYPE"); CPPUNIT_ASSERT_EQUAL(true, provider->publishInterface(props)); // CPPUNIT_ASSERT_EQUAL(std::string("VALUE1"), NVUtil::toString(props, "KEY1")); CPPUNIT_ASSERT_EQUAL(std::string("VALUE2"), NVUtil::toString(props, "KEY2")); } /*! * @brief publishInterface() * * - */ void test_publishInterface_with_interfaceType_unmatched() { std::auto_ptr<InPortProviderMock> provider( new InPortProviderMock("INTERFACE_TYPE", "DATA_FLOW_TYPE", "SUBSCRIPTION_TYPE")); //m_propertiesへ設定 provider->setDummydataInProperties(); SDOPackage::NVList props; NVUtil::appendStringValue(props, "dataport.interface_type", "UNMATCHED_INTERFACE_TYPE"); CPPUNIT_ASSERT_EQUAL(false, provider->publishInterface(props)); // CPPUNIT_ASSERT_EQUAL(std::string(""), NVUtil::toString(props, "KEY1")); CPPUNIT_ASSERT_EQUAL(std::string(""), NVUtil::toString(props, "KEY2")); } }; }; // namespace InPortProvider /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(InPortProvider::InPortProviderTests); #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 // InPortProvider_cpp
142  provider->setDummydataInProperties();
143 
145  provider->publishInterfaceProfile(prop);
146 
147  // "dataport.interface_type"
148  CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE"),
149  NVUtil::toString(prop, "dataport.interface_type"));
150 
151  //
152  CPPUNIT_ASSERT_EQUAL(std::string("VALUE1"), NVUtil::toString(prop, "KEY1"));
153  CPPUNIT_ASSERT_EQUAL(std::string("VALUE2"), NVUtil::toString(prop, "KEY2"));
154  }
155 
162  {
163  std::auto_ptr<InPortProviderMock> provider(
164  new InPortProviderMock("INTERFACE_TYPE", "DATA_FLOW_TYPE", "SUBSCRIPTION_TYPE"));
165 
166  //m_propertiesへ設定 provider->setDummydataInProperties(); SDOPackage::NVList props; NVUtil::appendStringValue(props, "dataport.interface_type", "INTERFACE_TYPE"); CPPUNIT_ASSERT_EQUAL(true, provider->publishInterface(props)); // CPPUNIT_ASSERT_EQUAL(std::string("VALUE1"), NVUtil::toString(props, "KEY1")); CPPUNIT_ASSERT_EQUAL(std::string("VALUE2"), NVUtil::toString(props, "KEY2")); } /*! * @brief publishInterface() * * - */ void test_publishInterface_with_interfaceType_unmatched() { std::auto_ptr<InPortProviderMock> provider( new InPortProviderMock("INTERFACE_TYPE", "DATA_FLOW_TYPE", "SUBSCRIPTION_TYPE")); //m_propertiesへ設定 provider->setDummydataInProperties(); SDOPackage::NVList props; NVUtil::appendStringValue(props, "dataport.interface_type", "UNMATCHED_INTERFACE_TYPE"); CPPUNIT_ASSERT_EQUAL(false, provider->publishInterface(props)); // CPPUNIT_ASSERT_EQUAL(std::string(""), NVUtil::toString(props, "KEY1")); CPPUNIT_ASSERT_EQUAL(std::string(""), NVUtil::toString(props, "KEY2")); } }; }; // namespace InPortProvider /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(InPortProvider::InPortProviderTests); #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 // InPortProvider_cpp
167  provider->setDummydataInProperties();
168 
169  SDOPackage::NVList props;
170  NVUtil::appendStringValue(props, "dataport.interface_type", "INTERFACE_TYPE");
171  CPPUNIT_ASSERT_EQUAL(true, provider->publishInterface(props));
172 
173  //
174  CPPUNIT_ASSERT_EQUAL(std::string("VALUE1"), NVUtil::toString(props, "KEY1"));
175  CPPUNIT_ASSERT_EQUAL(std::string("VALUE2"), NVUtil::toString(props, "KEY2"));
176  }
177 
184  {
185  std::auto_ptr<InPortProviderMock> provider(
186  new InPortProviderMock("INTERFACE_TYPE", "DATA_FLOW_TYPE", "SUBSCRIPTION_TYPE"));
187 
188  //m_propertiesへ設定 provider->setDummydataInProperties(); SDOPackage::NVList props; NVUtil::appendStringValue(props, "dataport.interface_type", "UNMATCHED_INTERFACE_TYPE"); CPPUNIT_ASSERT_EQUAL(false, provider->publishInterface(props)); // CPPUNIT_ASSERT_EQUAL(std::string(""), NVUtil::toString(props, "KEY1")); CPPUNIT_ASSERT_EQUAL(std::string(""), NVUtil::toString(props, "KEY2")); } }; }; // namespace InPortProvider /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(InPortProvider::InPortProviderTests); #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 // InPortProvider_cpp
189  provider->setDummydataInProperties();
190 
191  SDOPackage::NVList props;
192  NVUtil::appendStringValue(props, "dataport.interface_type", "UNMATCHED_INTERFACE_TYPE");
193  CPPUNIT_ASSERT_EQUAL(false, provider->publishInterface(props));
194 
195  //
196  CPPUNIT_ASSERT_EQUAL(std::string(""), NVUtil::toString(props, "KEY1"));
197  CPPUNIT_ASSERT_EQUAL(std::string(""), NVUtil::toString(props, "KEY2"));
198  }
199 
200  };
201 }; // namespace InPortProvider
202 
203 /*
204  * Register test suite
205  */
207 
208 #ifdef LOCAL_MAIN
209 int main(int argc, char* argv[])
210 {
211 
212  FORMAT format = TEXT_OUT;
213  int target = 0;
214  std::string xsl;
215  std::string ns;
216  std::string fname;
217  std::ofstream ofs;
218 
219  int i(1);
220  while (i < argc)
221  {
222  std::string arg(argv[i]);
223  std::string next_arg;
224  if (i + 1 < argc) next_arg = argv[i + 1];
225  else next_arg = "";
226 
227  if (arg == "--text") { format = TEXT_OUT; break; }
228  if (arg == "--xml")
229  {
230  if (next_arg == "")
231  {
232  fname = argv[0];
233  fname += ".xml";
234  }
235  else
236  {
237  fname = next_arg;
238  }
239  format = XML_OUT;
240  ofs.open(fname.c_str());
241  }
242  if ( arg == "--compiler" ) { format = COMPILER_OUT; break; }
243  if ( arg == "--cerr" ) { target = 1; break; }
244  if ( arg == "--xsl" )
245  {
246  if (next_arg == "") xsl = "default.xsl";
247  else xsl = next_arg;
248  }
249  if ( arg == "--namespace" )
250  {
251  if (next_arg == "")
252  {
253  std::cerr << "no namespace specified" << std::endl;
254  exit(1);
255  }
256  else
257  {
258  xsl = next_arg;
259  }
260  }
261  ++i;
262  }
263  CppUnit::TextUi::TestRunner runner;
264  if ( ns.empty() )
265  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
266  else
267  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
268  CppUnit::Outputter* outputter = 0;
269  std::ostream* stream = target ? &std::cerr : &std::cout;
270  switch ( format )
271  {
272  case TEXT_OUT :
273  outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
274  break;
275  case XML_OUT :
276  std::cout << "XML_OUT" << std::endl;
277  outputter = new CppUnit::XmlOutputter(&runner.result(),
278  ofs, "shift_jis");
279  static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
280  break;
281  case COMPILER_OUT :
282  outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
283  break;
284  }
285  runner.setOutputter(outputter);
286  runner.run();
287  return 0; // runner.run() ? 0 : 1;
288 }
289 #endif // MAIN
290 #endif // InPortProvider_cpp
ConnectorListeners class.
void setBuffer(RTC::BufferBase< cdrMemoryStream > *buffer)
Setting outside buffer&#39;s pointer.
int main(int argc, char **argv)
void test_publishInterface_with_interfaceType_matched()
publishInterface()
InPortConnector base class.
virtual void tearDown()
Test finalization.
InPortProvider class.
CPPUNIT_TEST_SUITE_REGISTRATION(InPortProvider::InPortProviderTests)
SDOPackage::NVList m_properties
Properties to hold port profile.
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
InPortProviderMock(const std::string &interfaceType, const std::string &dataFlowType, const std::string &subscriptionType)
virtual void setUp()
Test initialization.
void test_publishInterface_with_interfaceType_unmatched()
publishInterface()
InPortProvider.
std::string toString(const SDOPackage::NVList &nv, const char *name)
Get NVList of specifid name as string.
Definition: NVUtil.cpp:282
Buffer abstract class.
void setDataFlowType(const char *dataflow_type)
Set the dataflow type.
void setListener(RTC::ConnectorInfo &info, RTC::ConnectorListeners *listeners)
Set the listener.
prop
Organization::get_organization_property ();.
void setInterfaceType(const char *interface_type)
Set the interface type.
Class represents a set of properties.
Definition: Properties.h:101
void init(coil::Properties &prop)
Initializing configuration.
void test_publishInterfaceProfile()
publishInterfaceProfile()
std::vector< std::string > g_argv
void setConnector(RTC::InPortConnector *connector)
set Connector
BufferBase abstract class.
Definition: BufferBase.h:104
void setSubscriptionType(const char *subs_type)
Set the subscription type.


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Jun 6 2019 19:25:58