ECFactoryTests.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
11 /*
12  * $Log: ECFactoryTests.cpp,v $
13  * Revision 1.1 2008/04/15 08:38:41 arafune
14  * The first commitment.
15  *
16  *
17  */
18 
19 #ifndef ECFactory_cpp
20 #define ECFactory_cpp
21 
22 #include <cppunit/ui/text/TestRunner.h>
23 #include <cppunit/TextOutputter.h>
24 #include <cppunit/extensions/TestFactoryRegistry.h>
25 #include <cppunit/extensions/HelperMacros.h>
26 #include <cppunit/TestAssert.h>
27 
30 #include <rtm/ECFactory.h>
31 
36 namespace ECFactory
37 {
39  : public CppUnit::TestFixture
40  {
45 
46  private:
47  CORBA::ORB_ptr m_pORB;
48  PortableServer::POA_ptr m_pPOA;
49 
50  public:
55  {
56  int argc(0);
57  char** argv(NULL);
58  m_pORB = CORBA::ORB_init(argc, argv);
59  m_pPOA = PortableServer::POA::_narrow(
60  m_pORB->resolve_initial_references("RootPOA"));
61  m_pPOA->the_POAManager()->activate();
62  }
63 
67  virtual ~ECFactoryTests()
68  {
69  }
70 
74  virtual void setUp()
75  {
76  }
77 
81  virtual void tearDown()
82  {
83  }
84 
90  void test_name()
91  {
92  std::string name = "name of execution context";
93 
94  std::auto_ptr<RTC::ECFactoryBase> factory(
96  name.c_str(),
97  RTC::ECCreate<RTC::PeriodicExecutionContext>,
98  RTC::ECDelete<RTC::PeriodicExecutionContext>));
99 
100  // コンストラクタで指定した名称を、name()メソッドで正しく取得できるか?
101  CPPUNIT_ASSERT_EQUAL(name, std::string(factory->name()));
102  }
103 
111  {
112  std::auto_ptr<RTC::ECFactoryBase> factory(
113  new RTC::ECFactoryCXX(
114  "name of execution context",
115  RTC::ECCreate<RTC::PeriodicExecutionContext>,
116  RTC::ECDelete<RTC::PeriodicExecutionContext>));
117 
118  // create()呼出しにより、所定のExcecutionContextのインスタンスが生成されるか?
119  RTC::ExecutionContextBase* ec = factory->create();
120  CPPUNIT_ASSERT(dynamic_cast<RTC::PeriodicExecutionContext*>(ec) != 0);
121 
122  // destroy()呼出しにより、所定のExecutionContextインスタンスが削除されるか?
123  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
124  factory->destroy(ec);
125  CPPUNIT_ASSERT(dynamic_cast<RTC::PeriodicExecutionContext*>(ec) == 0);
126  }
127 
128  };
129 }; // namespace ECFactory
130 
131 /*
132  * Register test suite
133  */
135 
136 #ifdef LOCAL_MAIN
137 int main(int argc, char* argv[])
138 {
139 
140  FORMAT format = TEXT_OUT;
141  int target = 0;
142  std::string xsl;
143  std::string ns;
144  std::string fname;
145  std::ofstream ofs;
146 
147  int i(1);
148  while (i < argc)
149  {
150  std::string arg(argv[i]);
151  std::string next_arg;
152  if (i + 1 < argc) next_arg = argv[i + 1];
153  else next_arg = "";
154 
155  if (arg == "--text") { format = TEXT_OUT; break; }
156  if (arg == "--xml")
157  {
158  if (next_arg == "")
159  {
160  fname = argv[0];
161  fname += ".xml";
162  }
163  else
164  {
165  fname = next_arg;
166  }
167  format = XML_OUT;
168  ofs.open(fname.c_str());
169  }
170  if ( arg == "--compiler" ) { format = COMPILER_OUT; break; }
171  if ( arg == "--cerr" ) { target = 1; break; }
172  if ( arg == "--xsl" )
173  {
174  if (next_arg == "") xsl = "default.xsl";
175  else xsl = next_arg;
176  }
177  if ( arg == "--namespace" )
178  {
179  if (next_arg == "")
180  {
181  std::cerr << "no namespace specified" << std::endl;
182  exit(1);
183  }
184  else
185  {
186  xsl = next_arg;
187  }
188  }
189  ++i;
190  }
191  CppUnit::TextUi::TestRunner runner;
192  if ( ns.empty() )
193  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
194  else
195  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
196  CppUnit::Outputter* outputter = 0;
197  std::ostream* stream = target ? &std::cerr : &std::cout;
198  switch ( format )
199  {
200  case TEXT_OUT :
201  outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
202  break;
203  case XML_OUT :
204  std::cout << "XML_OUT" << std::endl;
205  outputter = new CppUnit::XmlOutputter(&runner.result(),
206  ofs, "shift_jis");
207  static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
208  break;
209  case COMPILER_OUT :
210  outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
211  break;
212  }
213  runner.setOutputter(outputter);
214  runner.run();
215  return 0; // runner.run() ? 0 : 1;
216 }
217 #endif // MAIN
218 #endif // ECFactory_cpp
ECFactoryCXX class.
Definition: ECFactory.h:221
int main(int argc, char **argv)
virtual ~ECFactoryTests()
Destructor.
A base class for ExecutionContext.
virtual void tearDown()
Test finalization.
PortableServer::POA_ptr m_pPOA
void test_name()
name()メソッドのテスト
CPPUNIT_TEST_SUITE(ECFactoryTests)
ExtTrigExecutionContext class.
void test_create_and_destroy()
create()メソッドとdestroy()メソッドのテスト
CPPUNIT_TEST_SUITE_REGISTRATION(ECFactory::ECFactoryTests)
virtual void setUp()
Test initialization.
ExecutionContext Factory class.
PeriodicExecutionContext class.


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