OutPortConnectorTests.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
22 #ifndef OutPortConnector_cpp
23 #define OutPortConnector_cpp
24 
25 #include <cppunit/ui/text/TestRunner.h>
26 #include <cppunit/TextOutputter.h>
27 #include <cppunit/extensions/TestFactoryRegistry.h>
28 #include <cppunit/extensions/HelperMacros.h>
29 #include <cppunit/TestAssert.h>
30 
31 #include <coil/Properties.h>
32 
33 #include <rtm/idl/BasicDataTypeSkel.h>
34 #include <rtm/Typename.h>
35 #include <rtm/OutPortConnector.h>
36 #include <rtm/CdrBufferBase.h>
37 #include <rtm/CORBA_SeqUtil.h>
38 #include <rtm/NVUtil.h>
39 #include <rtm/ConnectorBase.h>
40 #include <rtm/DataPortStatus.h>
41 #include <rtm/InPortBase.h>
42 #include <rtm/OutPortBase.h>
43 #include <rtm/PortAdmin.h>
44 
51 {
52  class InPortMock
53  : public RTC::InPortBase
54  {
55  public:
56  InPortMock(const char* name, const char* value)
57  : InPortBase(name, value) {}
61  bool read()
62  {
63  return true;
64  }
65 
66  };
67 
69  : public RTC::OutPortBase
70  {
71  public:
72  OutPortMock(const char* name, const char* value)
73  : OutPortBase(name, value) {}
77  bool write()
78  {
79  return true;
80  }
81 
82  };
83 
85  : public RTC::OutPortConnector
86  {
87  public:
89  : RTC::OutPortConnector(info)
90  {
91  }
93  {
94  }
96  {
97  return ::RTC::DataPortStatus::PORT_OK;
98  }
99  void activate()
100  {
101  }
102  void deactivate()
103  {
104  }
106  {
107  return m_buffer;
108  }
109  ReturnCode write(const cdrMemoryStream& data)
110  {
111  return ::RTC::DataPortStatus::PORT_OK;
112  }
113  private:
115  };
116 
118  : public CppUnit::TestFixture
119  {
120  CPPUNIT_TEST_SUITE(OutPortConnectorTests);
121 
122  CPPUNIT_TEST(test_case0);
123 
124  CPPUNIT_TEST_SUITE_END();
125 
126  private:
127  CORBA::ORB_ptr m_pORB;
128  PortableServer::POA_ptr m_pPOA;
129 
130 
131  public:
132 
137  {
138 
139  int argc(0);
140  char** argv(NULL);
141  m_pORB = CORBA::ORB_init(argc, argv);
142  m_pPOA = PortableServer::POA::_narrow(
143  m_pORB->resolve_initial_references("RootPOA"));
144  m_pPOA->the_POAManager()->activate();
145 
146  }
147 
152  {
153  }
154 
158  virtual void setUp()
159  {
160  }
161 
165  virtual void tearDown()
166  {
167  }
168 
173  void test_case0()
174  {
175 
176  InPortMock inport("OutPortConnectorTest1", toTypename<RTC::TimedFloat>());
177  RTC::PortService_var port_ref1= inport.get_port_profile()->port_ref;
178  OutPortMock outport("OutPortConnectorTest2", toTypename<RTC::TimedFloat>());
179  RTC::PortService_var port_ref2= outport.get_port_profile()->port_ref;
180 
181  RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
182  portAdmin.registerPort(inport);
183  portAdmin.registerPort(outport);
184 
185  RTC::ConnectorProfile cprof;
186  cprof.connector_id = "id";
187  cprof.name = CORBA::string_dup("OutPortConnectorTest");
188 
189  CORBA_SeqUtil::push_back(cprof.properties,
190  NVUtil::newNV("dataport.interface_type",
191  "corba_cdr"));
192  CORBA_SeqUtil::push_back(cprof.properties,
193  NVUtil::newNV("dataport.dataflow_type",
194  "push"));
195  CORBA_SeqUtil::push_back(cprof.properties,
196  NVUtil::newNV("dataport.subscription_type",
197  "new"));
198 
199  cprof.ports.length(2);
200  cprof.ports[0] = port_ref1;
201  cprof.ports[1] = port_ref2;
202 
204  NVUtil::copyToProperties(prop, cprof.properties);
205  RTC::ConnectorInfo info(cprof.name, cprof.connector_id,
206  CORBA_SeqUtil::refToVstring(cprof.ports), prop);
207 
208  OutPortConnectorMock connector(info);
209  CPPUNIT_ASSERT_EQUAL(std::string(cprof.connector_id), std::string(connector.id()));
210  CPPUNIT_ASSERT_EQUAL(std::string(cprof.name), std::string(connector.name()));
211  connector.setEndian(false);
212  CPPUNIT_ASSERT(!connector.isLittleEndian());
213  connector.setEndian(true);
214  CPPUNIT_ASSERT(connector.isLittleEndian());
215 
216  RTC::ConnectorInfo info2 = connector.profile();
217  CPPUNIT_ASSERT_EQUAL(info.name,info2.name);
218  CPPUNIT_ASSERT_EQUAL(info.id,info2.id);
219  CPPUNIT_ASSERT(info.ports==info2.ports);
220  CPPUNIT_ASSERT_EQUAL(info.properties.size(),
221  info2.properties.size());
222  CPPUNIT_ASSERT_EQUAL(info.properties["dataport.interface_type"],
223  info2.properties["dataport.interface_type"]);
224  CPPUNIT_ASSERT_EQUAL(info.properties["dataport.dataflow_type"],
225  info2.properties["dataport.dataflow_type"]);
226  CPPUNIT_ASSERT_EQUAL(info.properties["dataport.subscription_type"],
227  info2.properties["dataport.subscription_type"]);
228  portAdmin.deletePort(inport);
229  portAdmin.deletePort(outport);
230  }
231 
232  };
233 }; // namespace OutPortConnector
234 
235 /*
236  * Register test suite
237  */
239 
240 #ifdef LOCAL_MAIN
241 int main(int argc, char* argv[])
242 {
243 
244  FORMAT format = TEXT_OUT;
245  int target = 0;
246  std::string xsl;
247  std::string ns;
248  std::string fname;
249  std::ofstream ofs;
250 
251  int i(1);
252  while (i < argc)
253  {
254  std::string arg(argv[i]);
255  std::string next_arg;
256  if (i + 1 < argc) next_arg = argv[i + 1];
257  else next_arg = "";
258 
259  if (arg == "--text") { format = TEXT_OUT; break; }
260  if (arg == "--xml")
261  {
262  if (next_arg == "")
263  {
264  fname = argv[0];
265  fname += ".xml";
266  }
267  else
268  {
269  fname = next_arg;
270  }
271  format = XML_OUT;
272  ofs.open(fname.c_str());
273  }
274  if ( arg == "--compiler" ) { format = COMPILER_OUT; break; }
275  if ( arg == "--cerr" ) { target = 1; break; }
276  if ( arg == "--xsl" )
277  {
278  if (next_arg == "") xsl = "default.xsl";
279  else xsl = next_arg;
280  }
281  if ( arg == "--namespace" )
282  {
283  if (next_arg == "")
284  {
285  std::cerr << "no namespace specified" << std::endl;
286  exit(1);
287  }
288  else
289  {
290  xsl = next_arg;
291  }
292  }
293  ++i;
294  }
295  CppUnit::TextUi::TestRunner runner;
296  if ( ns.empty() )
297  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
298  else
299  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
300  CppUnit::Outputter* outputter = 0;
301  std::ostream* stream = target ? &std::cerr : &std::cout;
302  switch ( format )
303  {
304  case TEXT_OUT :
305  outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
306  break;
307  case XML_OUT :
308  std::cout << "XML_OUT" << std::endl;
309  outputter = new CppUnit::XmlOutputter(&runner.result(),
310  ofs, "shift_jis");
311  static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
312  break;
313  case COMPILER_OUT :
314  outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
315  break;
316  }
317  runner.setOutputter(outputter);
318  runner.run();
319  return 0; // runner.run() ? 0 : 1;
320 }
321 #endif // MAIN
322 #endif // OutPortConnector_cpp
SDOPackage::NameValue newNV(const char *name, Value value)
Create NameValue.
Definition: NVUtil.h:79
int main(int argc, char **argv)
OutPortConnector base class.
DataPortStatus class.
coil::Properties properties
Connection properties.
RT-Component.
coil::vstring ports
Connection ports.
OutPortConnector class.
virtual void setEndian(const bool endian_type)
Setting an endian type.
bool read()
It is a virtual method that is called from RTObject_impl::readAll(). This method reads out data from ...
Typename function.
string outport
Definition: README_gen.py:115
Enum
DataPortStatus return codes.
Definition: BufferStatus.h:84
virtual bool isLittleEndian()
return it whether endian setting.
PortAdmin class.
Definition: PortAdmin.h:52
RTC::CdrBufferBase * getBuffer()
Getting Buffer.
void test_case0()
profile(), id(), name(), setEndian(), isLittleEndian() メソッドのテスト
Connector base class.
CPPUNIT_TEST_SUITE_REGISTRATION(OutPortConnector::OutPortConnectorTests)
string inport
Definition: README_gen.py:90
OutPortMock(const char *name, const char *value)
ReturnCode disconnect()
Disconnect connection.
void copyToProperties(coil::Properties &prop, const SDOPackage::NVList &nv)
Copy NVList to the Proeprties.
Definition: NVUtil.cpp:137
InPortMock(const char *name, const char *value)
void registerPort(PortBase &port)
Regsiter the Port.
Definition: PortAdmin.cpp:239
NameValue and NVList utility functions.
Output base class.
Definition: OutPortBase.h:230
CORBA sequence utility template functions.
std::string name
Connection name.
Port for InPort.
Definition: InPortBase.h:67
void deactivate()
Connector deactivation.
prop
Organization::get_organization_property ();.
virtual PortProfile * get_port_profile()
[CORBA interface] Get the PortProfile of the Port
Definition: PortBase.cpp:100
RTC::Port implementation for InPort.
InPortBase base class.
ReturnCode write(const cdrMemoryStream &data)
Destructor.
Class represents a set of properties.
Definition: Properties.h:101
int size(void) const
Get the number of Properties.
Definition: Properties.cpp:432
void push_back(CorbaSequence &seq, SequenceElement elem)
Push the new element back to the CORBA sequence.
virtual void setUp()
Test initialization.
void deletePort(PortBase &port)
Unregister the Port registration.
Definition: PortAdmin.cpp:297
virtual void tearDown()
Test finalization.
coil::vstring refToVstring(const CorbaRefSequence &objlist)
BufferBase abstract class.
Definition: BufferBase.h:104
const char * id()
Getting Connector ID.
std::string id
ConnectionID.
RTC&#39;s Port administration class.
const ConnectorInfo & profile()
Getting Profile.
const char * name()
Getting Connector name.


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