CORBA_IORUtilTests.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
12 /*
13  * $Log: CORBA_IORUtilTests.cpp,v $
14  */
15 
16 #ifndef CORBA_IORUtil_cpp
17 #define CORBA_IORUtil_cpp
18 
19 #include <iostream>
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/CORBA_IORUtil.h>
28 
29 
35 namespace CORBA_IORUtil
36 {
37 
39  : public CppUnit::TestFixture
40  {
42 
44 
46 
47  private:
48 
49  public:
50 
55  {
56  }
57 
62  {
63  }
64 
68  virtual void setUp()
69  {
70  }
71 
75  virtual void tearDown()
76  {
77  }
78 
82  void test_case0()
83  {
84  bool bret;
85  IOP::IOR ior;
86  std::string str_ior("IOR:010000001400000049444c3a52544d2f4d616e616765723a312e300001000000000000006000000001010200100000003139322e3136382e3130302e323430007acf0000070000006d616e61676572000200000000000000080000000100000000545441010000001c00000001000000010001000100000001000105090101000100000009010100");
87 
88  std::string str_ior2;
89  char* str_ior3 = 0;
90  std::string str_ior_ret;
91 
92  // toIOR(), return false check
93  bret = CORBA_IORUtil::toIOR(str_ior3, ior);
94  CPPUNIT_ASSERT( !bret );
95 
96  // toIOR(), return false check
97  bret = CORBA_IORUtil::toIOR("IOR", ior);
98  CPPUNIT_ASSERT( !bret );
99 
100  // toIOR(), return false check
101  bret = CORBA_IORUtil::toIOR("ior:", ior);
102  CPPUNIT_ASSERT( !bret );
103 
104  // toIOR(), return true check
105  bret = CORBA_IORUtil::toIOR(str_ior.c_str(), ior);
106  CPPUNIT_ASSERT( bret );
107 
108  // toString()
109  bret = CORBA_IORUtil::toString(ior, str_ior2);
110  CPPUNIT_ASSERT( bret );
111  CPPUNIT_ASSERT_EQUAL(str_ior, str_ior2);
112 
113  // replaceEndpoint()
114  bret = CORBA_IORUtil::replaceEndpoint(str_ior, "127.0.0.1");
115  CPPUNIT_ASSERT( bret );
116 
117  // formatIORinfo()
118  str_ior_ret = CORBA_IORUtil::formatIORinfo(str_ior3);
119  CPPUNIT_ASSERT( str_ior_ret.size() > 0 );
120  }
121 
122  };
123 }; // namespace CORBA_IORUtil
124 
125 /*
126  * Register test suite
127  */
129 
130 #ifdef LOCAL_MAIN
131 int main(int argc, char* argv[])
132 {
133 
134  FORMAT format = TEXT_OUT;
135  int target = 0;
136  std::string xsl;
137  std::string ns;
138  std::string fname;
139  std::ofstream ofs;
140 
141  int i(1);
142  while (i < argc)
143  {
144  std::string arg(argv[i]);
145  std::string next_arg;
146  if (i + 1 < argc) next_arg = argv[i + 1];
147  else next_arg = "";
148 
149  if (arg == "--text") { format = TEXT_OUT; break; }
150  if (arg == "--xml")
151  {
152  if (next_arg == "")
153  {
154  fname = argv[0];
155  fname += ".xml";
156  }
157  else
158  {
159  fname = next_arg;
160  }
161  format = XML_OUT;
162  ofs.open(fname.c_str());
163  }
164  if ( arg == "--compiler" ) { format = COMPILER_OUT; break; }
165  if ( arg == "--cerr" ) { target = 1; break; }
166  if ( arg == "--xsl" )
167  {
168  if (next_arg == "") xsl = "default.xsl";
169  else xsl = next_arg;
170  }
171  if ( arg == "--namespace" )
172  {
173  if (next_arg == "")
174  {
175  std::cerr << "no namespace specified" << std::endl;
176  exit(1);
177  }
178  else
179  {
180  xsl = next_arg;
181  }
182  }
183  ++i;
184  }
185  CppUnit::TextUi::TestRunner runner;
186  if ( ns.empty() )
187  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
188  else
189  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
190  CppUnit::Outputter* outputter = 0;
191  std::ostream* stream = target ? &std::cerr : &std::cout;
192  switch ( format )
193  {
194  case TEXT_OUT :
195  outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
196  break;
197  case XML_OUT :
198  std::cout << "XML_OUT" << std::endl;
199  outputter = new CppUnit::XmlOutputter(&runner.result(),
200  ofs, "shift_jis");
201  static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
202  break;
203  case COMPILER_OUT :
204  outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
205  break;
206  }
207  runner.setOutputter(outputter);
208  runner.run();
209  return 0; // runner.run() ? 0 : 1;
210 }
211 #endif // MAIN
212 #endif // CORBA_IORUtil_cpp
int main(int argc, char **argv)
virtual void setUp()
Test initialization.
bool toString(IOP::IOR &ior, std::string &iorstr)
Convert from IOR structure to IOR string.
bool replaceEndpoint(std::string &iorstr, const std::string &endpoint)
Replace endpoint address in IOR entry.
std::string formatIORinfo(const char *iorstr)
Extracts information from IOR string and returns formatted string.
CPPUNIT_TEST_SUITE(CORBA_IORUtilTests)
virtual void tearDown()
Test finalization.
void test_case0()
toIOR(), toString(), replaceEndpoint(), formatIORinfo() メソッドテスト
bool toIOR(const char *iorstr, IOP::IOR &ior)
Convert from IOR string to IOR structure.
CORBA IOR manipulation utility functions.
CPPUNIT_TEST_SUITE_REGISTRATION(CORBA_IORUtil::CORBA_IORUtilTests)
bret
7 送受信データ比較
Definition: ConnectTest.py:377


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Jun 10 2019 14:07:51