OutPortCorbaCdrProviderTests.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
12 /*
13  * $Log: OutPortCorbaCdrProviderTests.cpp,v $
14  *
15  *
16  */
17 
18 #ifndef OutPortCorbaCdrProvider_cpp
19 #define OutPortCorbaCdrProvider_cpp
20 
21 #include <cppunit/ui/text/TestRunner.h>
22 #include <cppunit/TextOutputter.h>
23 #include <cppunit/extensions/TestFactoryRegistry.h>
24 #include <cppunit/extensions/HelperMacros.h>
25 #include <cppunit/TestAssert.h>
26 
27 #include <rtm/idl/BasicDataTypeSkel.h>
28 #include <rtm/idl/DataPortSkel.h>
29 #include <rtm/RTC.h>
30 #include <rtm/Typename.h>
33 #include <rtm/CdrBufferBase.h>
34 #include <rtm/PortAdmin.h>
35 #include <rtm/CORBA_SeqUtil.h>
36 #include <rtm/NVUtil.h>
37 #include <rtm/DataPortStatus.h>
38 #include <rtm/ConnectorListener.h>
40 
46 {
47 
49  : public RTC::ConnectorDataListenerT<RTC::TimedLong>
50  {
51  public:
52  DataListener(const char* name) : m_name(name) {}
53  virtual ~DataListener()
54  {
55  //std::cout << "dtor of " << m_name << std::endl;
56  }
57 
58  virtual void operator()(const RTC::ConnectorInfo& info,
59  const RTC::TimedLong& data)
60  {
61  std::cout << "------------------------------" << std::endl;
62  std::cout << "Data Listener: " << m_name << std::endl;
63  std::cout << "Profile::name: " << info.name << std::endl;
64  std::cout << "------------------------------" << std::endl;
65  };
66  std::string m_name;
67  };
68 
69 
71  : public RTC::ConnectorListener
72  {
73  public:
74  ConnListener(const char* name) : m_name(name) {}
75  virtual ~ConnListener()
76  {
77  //std::cout << "dtor of " << m_name << std::endl;
78  }
79 
80  virtual void operator()(const RTC::ConnectorInfo& info)
81  {
82  std::cout << "------------------------------" << std::endl;
83  std::cout << "Connector Listener: " << m_name << std::endl;
84  std::cout << "Profile::name: " << info.name << std::endl;
85  std::cout << "------------------------------" << std::endl;
86  };
87  std::string m_name;
88  };
89 
96  {
97  public:
103  {
104  }
110  {
111  }
117  {
118  return m_properties;
119  }
120  };
122  : public CppUnit::TestFixture
123  {
124  CPPUNIT_TEST_SUITE(OutPortCorbaCdrProviderTests);
125 
126  CPPUNIT_TEST(test_case0);
127  CPPUNIT_TEST_SUITE_END();
128 
129  private:
130  CORBA::ORB_ptr m_pORB;
131  PortableServer::POA_ptr m_pPOA;
132 
133  public:
135 
140  {
141  int argc(0);
142  char** argv(NULL);
143  m_pORB = CORBA::ORB_init(argc, argv);
144  m_pPOA = PortableServer::POA::_narrow(
145  m_pORB->resolve_initial_references("RootPOA"));
146  m_pPOA->the_POAManager()->activate();
147  }
148 
153  {
154  }
155 
159  virtual void setUp()
160  {
161  }
162 
166  virtual void tearDown()
167  {
168  }
169 
174  void test_case0()
175  {
176  //
177  //
178  //
181 
182  //ConnectorInfo
184  coil::vstring ports;
185  RTC::ConnectorInfo info("name", "id", ports, prop);
186 
187  //ConnectorDataListeners
189  new DataListener("ON_BUFFER_WRITE"), true);
191  new DataListener("ON_BUFFER_FULL"), true);
193  new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true);
195  new DataListener("ON_BUFFER_OVERWRITE"), true);
197  new DataListener("ON_BUFFER_READ"), true);
199  new DataListener("ON_SEND"), true);
201  new DataListener("ON_RECEIVED"), true);
203  new DataListener("ON_RECEIVER_FULL"), true);
205  new DataListener("ON_RECEIVER_TIMEOUT"), true);
207  new DataListener("ON_RECEIVER_ERROR"), true);
208 
209  //ConnectorListeners
211  new ConnListener("ON_BUFFER_EMPTY"), true);
213  new ConnListener("ON_BUFFER_READ_TIMEOUT"), true);
215  new ConnListener("ON_SENDER_EMPTY"), true);
217  new ConnListener("ON_SENDER_TIMEOUT"), true);
219  new ConnListener("ON_SENDER_ERROR"), true);
221  new ConnListener("ON_CONNECT"), true);
223  new ConnListener("ON_DISCONNECT"), true);
224 
225  provider->setListener(info, &m_listeners);
226 
227  int index;
228  //IOR をプロぺティに追加することを確認
229  index = NVUtil::find_index(provider->get_m_properties(),
230  "dataport.corba_cdr.outport_ior");
231  CPPUNIT_ASSERT(0<=index);
232 
233  //ref をプロぺティに追加することを確認
234  index = NVUtil::find_index(provider->get_m_properties(),
235  "dataport.corba_cdr.outport_ref");
236  CPPUNIT_ASSERT(0<=index);
237 
238  provider->init(prop);
239 
240  RTC::CdrBufferBase* buffer;
241  buffer = RTC::CdrBufferFactory::instance().createObject("ring_buffer");
242 
243  ::OpenRTM::PortStatus retcode;
244 
245  ::OpenRTM::CdrData_var cdr_data;
246 
247  // buffer がない状態でコール(unkown error)
248  retcode = provider->get(cdr_data.out());
249  CPPUNIT_ASSERT_EQUAL((::OpenRTM::PortStatus)5, retcode);
250 
251  provider->setBuffer(buffer);
252 
253  RTC::OutPortConnector* connector;
254  connector = new RTC::OutPortPullConnector(info,
255  provider,
256  m_listeners,
257  buffer);
258  if (connector == 0)
259  {
260  std::cout << "ERROR: Connector creation failed." << std::endl;
261  }
262  provider->setConnector(connector);
263 
264  //データなしの状態でコール(empty)
265  retcode = provider->get(cdr_data);
266  CPPUNIT_ASSERT_EQUAL((::OpenRTM::PortStatus)3, retcode);
267 
268  int testdata[8] = { 12,34,56,78,90,23,45,99 };
269  cdrMemoryStream cdr;
270  RTC::TimedLong td;
271  for(int ic(0);ic<8;++ic)
272  {
273  td.data = testdata[ic];
274  td >>= cdr;
275  buffer->write(cdr);
276 
277  }
278 
279  retcode = provider->get(cdr_data);
280  CPPUNIT_ASSERT_EQUAL((::OpenRTM::PortStatus)0, retcode);
281 
282 
283  SDOPackage::NVList list = provider->get_m_properties();
284  index = NVUtil::find_index(list,
285  "dataport.corba_cdr.outport_ior");
286 
287  const char* ior;
288  if (list[index].value >>= ior)
289  {
290  CORBA::Object_ptr var = m_pORB->string_to_object(ior);
291  PortableServer::Servant ser = m_pPOA->reference_to_servant(var);
292  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ser));
293  }
294 
295 
296  delete connector;
297  }
298  };
299 }; // namespace OutPortCorbaCdrProvider
300 
301 /*
302  * Register test suite
303  */
305 
306 #ifdef LOCAL_MAIN
307 int main(int argc, char* argv[])
308 {
309 
310  FORMAT format = TEXT_OUT;
311  int target = 0;
312  std::string xsl;
313  std::string ns;
314  std::string fname;
315  std::ofstream ofs;
316 
317  int i(1);
318  while (i < argc)
319  {
320  std::string arg(argv[i]);
321  std::string next_arg;
322  if (i + 1 < argc) next_arg = argv[i + 1];
323  else next_arg = "";
324 
325  if (arg == "--text") { format = TEXT_OUT; break; }
326  if (arg == "--xml")
327  {
328  if (next_arg == "")
329  {
330  fname = argv[0];
331  fname += ".xml";
332  }
333  else
334  {
335  fname = next_arg;
336  }
337  format = XML_OUT;
338  ofs.open(fname.c_str());
339  }
340  if ( arg == "--compiler" ) { format = COMPILER_OUT; break; }
341  if ( arg == "--cerr" ) { target = 1; break; }
342  if ( arg == "--xsl" )
343  {
344  if (next_arg == "") xsl = "default.xsl";
345  else xsl = next_arg;
346  }
347  if ( arg == "--namespace" )
348  {
349  if (next_arg == "")
350  {
351  std::cerr << "no namespace specified" << std::endl;
352  exit(1);
353  }
354  else
355  {
356  xsl = next_arg;
357  }
358  }
359  ++i;
360  }
361  CppUnit::TextUi::TestRunner runner;
362  if ( ns.empty() )
363  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
364  else
365  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
366  CppUnit::Outputter* outputter = 0;
367  std::ostream* stream = target ? &std::cerr : &std::cout;
368  switch ( format )
369  {
370  case TEXT_OUT :
371  outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
372  break;
373  case XML_OUT :
374  std::cout << "XML_OUT" << std::endl;
375  outputter = new CppUnit::XmlOutputter(&runner.result(),
376  ofs, "shift_jis");
377  static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
378  break;
379  case COMPILER_OUT :
380  outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
381  break;
382  }
383  runner.setOutputter(outputter);
384  runner.run();
385  return 0; // runner.run() ? 0 : 1;
386 }
387 #endif // MAIN
388 #endif // OutPortCorbaCdrProvider_cpp
ConnectorListeners class.
int main(int argc, char **argv)
virtual void setConnector(OutPortConnector *connector)
set Connector
OutPortConnector base class.
DataPortStatus class.
ConnectorListener class.
void addListener(ConnectorDataListener *listener, bool autoclean)
Add the listener.
std::vector< std::pair< std::string, std::string > > NVList
Definition: IRTC.h:67
ConnectorListenerHolder connector_[CONNECTOR_LISTENER_NUM]
ConnectorListenerType listener array The ConnectorListenerType listener is stored.
CPPUNIT_TEST_SUITE_REGISTRATION(OutPortCorbaCdrProvider::OutPortCorbaCdrProviderTests)
Typename function.
void addListener(ConnectorListener *listener, bool autoclean)
Add the listener.
static GlobalFactory< AbstractClass, Identifier, Compare, Creator, Destructor > & instance()
Create instance.
Definition: Singleton.h:131
virtual ::OpenRTM::PortStatus get(::OpenRTM::CdrData_out data)
[CORBA interface] Get data from the buffer
OutPortCorbaCdrConsumer class.
std::vector< std::string > vstring
Definition: stringutil.h:37
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
virtual void init(coil::Properties &prop)
Initializing configuration.
ConnectorDataListenerHolder connectorData_[CONNECTOR_DATA_LISTENER_NUM]
ConnectorDataListenerType listener array The ConnectorDataListenerType listener is stored...
virtual void operator()(const RTC::ConnectorInfo &info, const RTC::TimedLong &data)
Virtual Callback method.
ConnectorDataListenerT class.
list index
Definition: rtimages.py:10
NameValue and NVList utility functions.
CORBA sequence utility template functions.
std::string name
Connection name.
virtual void setListener(ConnectorInfo &info, ConnectorListeners *listeners)
Set the listener.
prop
Organization::get_organization_property ();.
virtual void setBuffer(CdrBufferBase *buffer)
Setting outside buffer&#39;s pointer.
Class represents a set of properties.
Definition: Properties.h:101
OutPortPull type connector class.
RTComponent header.
OutPortPullConnector class.
virtual ReturnCode write(const DataType &value, long int sec=-1, long int nsec=-1)=0
Write data into the buffer.
virtual void operator()(const RTC::ConnectorInfo &info)
Virtual Callback method.
OutPortCorbaCdrProvider class.
BufferBase abstract class.
Definition: BufferBase.h:104
connector listener class
RTC&#39;s Port administration class.
OutPortCorbaCdrProvider class.


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Feb 28 2022 23:00:44