DataInOutPortTests.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
12 /*
13  * $Log: DataInOutPortTests.cpp,v $
14  * Revision 1.2 2008/07/18 04:32:00 arafune
15  * *** empty log message ***
16  *
17  * Revision 1.1 2007/12/20 07:50:18 arafune
18  * *** empty log message ***
19  *
20  * Revision 1.1 2007/01/06 18:04:51 n-ando
21  * The first commitment.
22  *
23  *
24  */
25 
26 #ifndef DataInOutPort_cpp
27 #define DataInOutPort_cpp
28 
29 #include <iostream>
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 
37 #include <rtm/idl/BasicDataTypeSkel.h>
38 #include <rtm/idl/RTCSkel.h>
39 #include <rtm/DataOutPort.h>
40 #include <rtm/OutPort.h>
41 #include <rtm/DataInPort.h>
42 #include <rtm/InPort.h>
43 #include <coil/Properties.h>
44 
49 namespace DataInOutPort
50 {
51  template <class DataType>
52  struct HogeCovnert : public RTC::OnReadConvert<DataType>
53  {
54  DataType operator()(const DataType& value)
55  {
56  DataType d(value);
57  d.data = value.data * value.data;
58  return d;
59  }
60  };
61 
63  : public CppUnit::TestFixture
64  {
65  CPPUNIT_TEST_SUITE(DataInOutPortTests);
66  CPPUNIT_TEST(test_connect);
67  CPPUNIT_TEST_SUITE_END();
68 
69  private:
71  RTC::TimedFloat m_ofloat;
72  RTC::PortService_var m_oportref;
73 
75  RTC::TimedFloat m_ifloat;
76  RTC::PortService_var m_iportref;
77 
79  CORBA::ORB_ptr m_pORB;
80  PortableServer::POA_ptr m_pPOA;
81  public:
82 
87  : m_outport("fout", m_ofloat),
88  m_inport("fin", m_ifloat)
89  {
90  m_conv = new HogeCovnert<RTC::TimedFloat>();
91 
92  int argc(0);
93  char** argv(NULL);
94  m_pORB = CORBA::ORB_init(argc, argv);
95  m_pPOA = PortableServer::POA::_narrow(
96  m_pORB->resolve_initial_references("RootPOA"));
97  m_pPOA->the_POAManager()->activate();
98 
99  coil::Properties dummy;
100  m_inport.init(dummy);
101  m_outport.init(dummy);
102  m_oportref = m_outport.get_port_profile()->port_ref;
103  m_iportref = m_inport.get_port_profile()->port_ref;
104 
105  }
106 
111  {
112  delete m_conv;
113  }
114 
118  virtual void setUp()
119  {
120  }
121 
125  virtual void tearDown()
126  {
127  }
128 
129  /* test case */
131  {
132  RTC::ConnectorProfile prof;
133  prof.connector_id = "";
134  prof.name = CORBA::string_dup("connector0");
135  prof.ports.length(2);
136  prof.ports[0] = m_oportref;
137  prof.ports[1] = m_iportref;
138 
139  CORBA_SeqUtil::push_back(prof.properties,
140  NVUtil::newNV("dataport.interface_type",
141  "corba_cdr"));
142 
143  CORBA_SeqUtil::push_back(prof.properties,
144  NVUtil::newNV("dataport.dataflow_type",
145  "push"));
146  CORBA_SeqUtil::push_back(prof.properties,
147  NVUtil::newNV("dataport.subscription_type",
148  "flush"));
149  RTC::ReturnCode_t ret= m_inport.connect(prof);
150  CPPUNIT_ASSERT(ret == RTC::RTC_OK);
151 
153  iprof = m_inport.get_connector_profiles();
154 
156  oprof = m_outport.get_connector_profiles();
157 
158 #ifdef DEBUG
159  std::cout << "Returned connector ID"
160  << prof.connector_id << std::endl;
161  std::cout << "InPort's connector ID"
162  << (*iprof)[0].connector_id << std::endl;
163  std::cout << "OutPort's connector ID"
164  << (*oprof)[0].connector_id << std::endl;
165 #endif
166  std::string c_id, i_id, o_id;
167  c_id = prof.connector_id;
168  i_id = (*iprof)[0].connector_id;
169  o_id = (*oprof)[0].connector_id;
170 
171  CPPUNIT_ASSERT(c_id == o_id);
172  CPPUNIT_ASSERT(c_id == i_id);
173  CPPUNIT_ASSERT(o_id == i_id);
174 
175  for (int i = 0; i < 100; ++i)
176  {
177  m_ofloat.data = 1.234567 * i;
178  m_outport.write();
179 
180  m_inport.read();
181 #ifdef DEBUG
182  sleep(1);
183  std::cout << m_ofloat.data << " <=> " << m_ifloat.data << std::endl;
184 #endif
185  CPPUNIT_ASSERT(m_ofloat.data == m_ifloat.data);
186  }
187 
188  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(&m_inport));
189  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(&m_outport));
190 
191  }
192  };
193 }; // namespace DataInOutPort
194 
195 /*
196  * Register test suite
197  */
199 
200 #ifdef LOCAL_MAIN
201 int main(int argc, char* argv[])
202 {
203 
204  FORMAT format = TEXT_OUT;
205  int target = 0;
206  std::string xsl;
207  std::string ns;
208  std::string fname;
209  std::ofstream ofs;
210 
211  int i(1);
212  while (i < argc)
213  {
214  std::string arg(argv[i]);
215  std::string next_arg;
216  if (i + 1 < argc) next_arg = argv[i + 1];
217  else next_arg = "";
218 
219  if (arg == "--text") { format = TEXT_OUT; break; }
220  if (arg == "--xml")
221  {
222  if (next_arg == "")
223  {
224  fname = argv[0];
225  fname += ".xml";
226  }
227  else
228  {
229  fname = next_arg;
230  }
231  format = XML_OUT;
232  ofs.open(fname.c_str());
233  }
234  if ( arg == "--compiler" ) { format = COMPILER_OUT; break; }
235  if ( arg == "--cerr" ) { target = 1; break; }
236  if ( arg == "--xsl" )
237  {
238  if (next_arg == "") xsl = "default.xsl";
239  else xsl = next_arg;
240  }
241  if ( arg == "--namespace" )
242  {
243  if (next_arg == "")
244  {
245  std::cerr << "no namespace specified" << std::endl;
246  exit(1);
247  }
248  else
249  {
250  xsl = next_arg;
251  }
252  }
253  ++i;
254  }
255  CppUnit::TextUi::TestRunner runner;
256  if ( ns.empty() )
257  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
258  else
259  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
260  CppUnit::Outputter* outputter = 0;
261  std::ostream* stream = target ? &std::cerr : &std::cout;
262  switch ( format )
263  {
264  case TEXT_OUT :
265  outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
266  break;
267  case XML_OUT :
268  std::cout << "XML_OUT" << std::endl;
269  outputter = new CppUnit::XmlOutputter(&runner.result(),
270  ofs, "shift_jis");
271  static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
272  break;
273  case COMPILER_OUT :
274  outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
275  break;
276  }
277  runner.setOutputter(outputter);
278  runner.run();
279  return 0; // runner.run() ? 0 : 1;
280 }
281 #endif // MAIN
282 #endif // DataInOutPort_cpp
SDOPackage::NameValue newNV(const char *name, Value value)
Create NameValue.
Definition: NVUtil.h:79
virtual void tearDown()
Test finalization.
int main(int argc, char **argv)
virtual ConnectorProfileList * get_connector_profiles()
[CORBA interface] Get the ConnectorProfileList of the Port
Definition: PortBase.cpp:133
InPort template class.
HogeCovnert< RTC::TimedFloat > * m_conv
virtual ReturnCode_t connect(ConnectorProfile &connector_profile)
[CORBA interface] Connect the Port
Definition: InPortBase.cpp:443
unsigned int sleep(unsigned int seconds)
Stop a processing at specified second time.
Definition: ace/coil/Time.h:40
ReturnCode_t
Definition: doil.h:53
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
OutPort class.
Base class of OutPort.
RTC::InPort< RTC::TimedFloat > m_inport
Data convert callback abstract class on read()
Definition: PortCallback.h:385
std::vector< ConnectorProfile * > ConnectorProfileList
Definition: IPortService.h:50
CPPUNIT_TEST_SUITE_REGISTRATION(DataInOutPort::DataInOutPortTests)
DataType operator()(const DataType &value)
Callback method.
Base class of InPort.
void init(coil::Properties &prop)
Initializing properties.
virtual PortProfile * get_port_profile()
[CORBA interface] Get the PortProfile of the Port
Definition: PortBase.cpp:100
Class represents a set of properties.
Definition: Properties.h:101
RTC::OutPort< RTC::TimedFloat > m_outport
virtual bool write(DataType &value)
Write data.
Definition: OutPort.h:209
virtual void setUp()
Test initialization.
void push_back(CorbaSequence &seq, SequenceElement elem)
Push the new element back to the CORBA sequence.
void init(coil::Properties &prop)
Initializing properties.
Definition: InPortBase.cpp:96
bool read()
Readout the value from DataPort.
Definition: InPort.h:379


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