InPortConnectorTests.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
22 #ifndef InPortConnector_cpp
23 #define InPortConnector_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/InPortConnector.h>
34 #include <rtm/CdrBufferBase.h>
35 #include <rtm/CORBA_SeqUtil.h>
36 #include <rtm/NVUtil.h>
37 #include <rtm/ConnectorBase.h>
38 #include <rtm/DataPortStatus.h>
39 
44 namespace InPortConnector
45 {
47  : public RTC::InPortConnector
48  {
49  public:
51  RTC::CdrBufferBase* buffer)
52  : RTC::InPortConnector(info, buffer)
53  {
54  }
56  {
57  }
59  {
60  return ::RTC::DataPortStatus::PORT_OK;
61  }
62  virtual ReturnCode read(cdrMemoryStream& data)
63  {
64  return ::RTC::DataPortStatus::PORT_OK;
65  }
66  virtual void activate()
67  {
68  }
69  virtual void deactivate()
70  {
71  }
72  };
73 
75  : public CppUnit::TestFixture
76  {
77  CPPUNIT_TEST_SUITE(InPortConnectorTests);
78 
79  CPPUNIT_TEST(test_case0);
80 
81  CPPUNIT_TEST_SUITE_END();
82 
83  private:
84 
85  public:
86 
91  {
92  int argc(0);
93  char** argv(NULL);
94  CORBA::ORB_ptr m_pORB = CORBA::ORB_init(argc, argv);
95  PortableServer::POA_ptr m_pPOA = PortableServer::POA::_narrow(
96  m_pORB->resolve_initial_references("RootPOA"));
97  m_pPOA->the_POAManager()->activate();
98  }
99 
104  {
105  }
106 
110  virtual void setUp()
111  {
112  }
113 
117  virtual void tearDown()
118  {
119  }
120 
125  void test_case0()
126  {
127 
128  RTC::ConnectorProfile cprof;
129  cprof.connector_id = "id";
130  cprof.name = CORBA::string_dup("InPortConnectorTest");
131 
132  CORBA_SeqUtil::push_back(cprof.properties,
133  NVUtil::newNV("dataport.interface_type",
134  "corba_cdr"));
135  CORBA_SeqUtil::push_back(cprof.properties,
136  NVUtil::newNV("dataport.dataflow_type",
137  "push"));
138  CORBA_SeqUtil::push_back(cprof.properties,
139  NVUtil::newNV("dataport.subscription_type",
140  "new"));
141 
142 
144  NVUtil::copyToProperties(prop, cprof.properties);
145  RTC::ConnectorInfo info(cprof.name,
146  cprof.connector_id,
147  CORBA_SeqUtil::refToVstring(cprof.ports),
148  prop);
149  RTC::CdrBufferBase* m_thebuffer;
150  m_thebuffer = RTC::CdrBufferFactory::instance().createObject("ring_buffer");
151 
152  InPortConnector::InPortConnectorMock connector(info, m_thebuffer);
153  CPPUNIT_ASSERT_EQUAL(std::string(cprof.connector_id), std::string(connector.id()));
154  CPPUNIT_ASSERT_EQUAL(std::string(cprof.name), std::string(connector.name()));
155  CPPUNIT_ASSERT_EQUAL(m_thebuffer, connector.getBuffer());
156 
157  connector.setEndian(false);
158  CPPUNIT_ASSERT(!connector.isLittleEndian());
159  connector.setEndian(true);
160  CPPUNIT_ASSERT(connector.isLittleEndian());
161 
162  RTC::ConnectorInfo info2 = connector.profile();
163  CPPUNIT_ASSERT_EQUAL(info.name, info2.name);
164  CPPUNIT_ASSERT_EQUAL(info.id, info2.id);
165  }
166 
167  };
168 }; // namespace InPortConnector
169 
170 /*
171  * Register test suite
172  */
174 
175 #ifdef LOCAL_MAIN
176 int main(int argc, char* argv[])
177 {
178 
179  FORMAT format = TEXT_OUT;
180  int target = 0;
181  std::string xsl;
182  std::string ns;
183  std::string fname;
184  std::ofstream ofs;
185 
186  int i(1);
187  while (i < argc)
188  {
189  std::string arg(argv[i]);
190  std::string next_arg;
191  if (i + 1 < argc) next_arg = argv[i + 1];
192  else next_arg = "";
193 
194  if (arg == "--text") { format = TEXT_OUT; break; }
195  if (arg == "--xml")
196  {
197  if (next_arg == "")
198  {
199  fname = argv[0];
200  fname += ".xml";
201  }
202  else
203  {
204  fname = next_arg;
205  }
206  format = XML_OUT;
207  ofs.open(fname.c_str());
208  }
209  if ( arg == "--compiler" ) { format = COMPILER_OUT; break; }
210  if ( arg == "--cerr" ) { target = 1; break; }
211  if ( arg == "--xsl" )
212  {
213  if (next_arg == "") xsl = "default.xsl";
214  else xsl = next_arg;
215  }
216  if ( arg == "--namespace" )
217  {
218  if (next_arg == "")
219  {
220  std::cerr << "no namespace specified" << std::endl;
221  exit(1);
222  }
223  else
224  {
225  xsl = next_arg;
226  }
227  }
228  ++i;
229  }
230  CppUnit::TextUi::TestRunner runner;
231  if ( ns.empty() )
232  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
233  else
234  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
235  CppUnit::Outputter* outputter = 0;
236  std::ostream* stream = target ? &std::cerr : &std::cout;
237  switch ( format )
238  {
239  case TEXT_OUT :
240  outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
241  break;
242  case XML_OUT :
243  std::cout << "XML_OUT" << std::endl;
244  outputter = new CppUnit::XmlOutputter(&runner.result(),
245  ofs, "shift_jis");
246  static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
247  break;
248  case COMPILER_OUT :
249  outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
250  break;
251  }
252  runner.setOutputter(outputter);
253  runner.run();
254  return 0; // runner.run() ? 0 : 1;
255 }
256 #endif // MAIN
257 #endif // InPortConnector_cpp
SDOPackage::NameValue newNV(const char *name, Value value)
Create NameValue.
Definition: NVUtil.h:79
int main(int argc, char **argv)
InPortConnector base class.
DataPortStatus class.
RT-Component.
virtual void deactivate()
Connector deactivation.
static GlobalFactory< AbstractClass, Identifier, Compare, Creator, Destructor > & instance()
Create instance.
Definition: Singleton.h:131
virtual const ConnectorInfo & profile()
Getting ConnectorInfo.
Enum
DataPortStatus return codes.
Definition: BufferStatus.h:84
Connector base class.
virtual void setUp()
Test initialization.
void copyToProperties(coil::Properties &prop, const SDOPackage::NVList &nv)
Copy NVList to the Proeprties.
Definition: NVUtil.cpp:137
virtual CdrBufferBase * getBuffer()
Getting Buffer.
InPortConnector base class.
NameValue and NVList utility functions.
virtual ReturnCode read(cdrMemoryStream &data)
Destructor.
virtual const char * name()
Getting Connector name.
CORBA sequence utility template functions.
virtual void setEndian(const bool endian_type)
Setting an endian type.
std::string name
Connection name.
void test_case0()
profile(),id(),name(),getBuffer(),setEndian(),isLittleEndian() メソッドのテスト
virtual void tearDown()
Test finalization.
virtual const char * id()
Getting Connector ID.
prop
Organization::get_organization_property ();.
virtual bool isLittleEndian()
Whether this connector&#39;s endian is little.
Class represents a set of properties.
Definition: Properties.h:101
CPPUNIT_TEST_SUITE_REGISTRATION(InPortConnector::InPortConnectorTests)
virtual void activate()
Connector activation.
void push_back(CorbaSequence &seq, SequenceElement elem)
Push the new element back to the CORBA sequence.
virtual ReturnCode disconnect()
Disconnect connection.
coil::vstring refToVstring(const CorbaRefSequence &objlist)
BufferBase abstract class.
Definition: BufferBase.h:104
std::string id
ConnectionID.
InPortConnectorMock(RTC::ConnectorInfo &info, RTC::CdrBufferBase *buffer)


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