NumberingPolicyTests.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
11 /*
12  * $Log: NumberingPolicyTests.cpp,v $
13  * Revision 1.1 2008/05/02 13:44:01 arafune
14  * The first commitment.
15  *
16  *
17  */
18 
19 #ifndef NumberingPolicy_cpp
20 #define NumberingPolicy_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 
28 #include <rtm/NumberingPolicy.h>
29 
30 namespace Tests
31 {
33  : public CppUnit::TestFixture
34  {
38 
39  private:
40 
41  public:
46  {
47  }
48 
53  {
54  }
55 
59  virtual void setUp()
60  {
61  }
62 
66  virtual void tearDown()
67  {
68  }
69 
78  {
79 
80  std::string object1 = "apple";
81  std::string object2 = "orange";
82  std::string object3 = "banana";
83 
84  std::auto_ptr<NumberingPolicy> policy(new DefaultNumberingPolicy());
85 
86  // onCreate()は意図どおりに名称を生成して返すか?
87  CPPUNIT_ASSERT_EQUAL(std::string("0"), policy->onCreate(&object1));
88  CPPUNIT_ASSERT_EQUAL(std::string("1"), policy->onCreate(&object2));
89  CPPUNIT_ASSERT_EQUAL(std::string("2"), policy->onCreate(&object3));
90 
91  // onDeleteで、いったん登録解除する policy->onDelete(&object1); policy->onDelete(&object2); // 登録順を入れ換えて再度onCreateを呼び出した場合、意図どおりの名称がアサインされるか? // (登録解除後に、onCreate()で登録した場合、解除されたオブジェクトの番号が再利用されるか?) CPPUNIT_ASSERT_EQUAL(std::string("0"), policy->onCreate(&object2)); CPPUNIT_ASSERT_EQUAL(std::string("1"), policy->onCreate(&object1)); } }; }; // namespace NumberingPolicy /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(Tests::NumberingPolicyTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // NumberingPolicy_cpp
92  policy->onDelete(&object1);
93  policy->onDelete(&object2);
94 
95  // 登録順を入れ換えて再度onCreateを呼び出した場合、意図どおりの名称がアサインされるか?
96  // (登録解除後に、onCreate()で登録した場合、解除されたオブジェクトの番号が再利用されるか?) CPPUNIT_ASSERT_EQUAL(std::string("0"), policy->onCreate(&object2)); CPPUNIT_ASSERT_EQUAL(std::string("1"), policy->onCreate(&object1)); } }; }; // namespace NumberingPolicy /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(Tests::NumberingPolicyTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // NumberingPolicy_cpp
97  CPPUNIT_ASSERT_EQUAL(std::string("0"), policy->onCreate(&object2));
98  CPPUNIT_ASSERT_EQUAL(std::string("1"), policy->onCreate(&object1));
99  }
100 
101  };
102 }; // namespace NumberingPolicy
103 
104 /*
105  * Register test suite
106  */
108 
109 #ifdef LOCAL_MAIN
110 int main(int argc, char* argv[])
111 {
112 
113  FORMAT format = TEXT_OUT;
114  int target = 0;
115  std::string xsl;
116  std::string ns;
117  std::string fname;
118  std::ofstream ofs;
119 
120  int i(1);
121  while (i < argc)
122  {
123  std::string arg(argv[i]);
124  std::string next_arg;
125  if (i + 1 < argc) next_arg = argv[i + 1];
126  else next_arg = "";
127 
128  if (arg == "--text") { format = TEXT_OUT; break; }
129  if (arg == "--xml")
130  {
131  if (next_arg == "")
132  {
133  fname = argv[0];
134  fname += ".xml";
135  }
136  else
137  {
138  fname = next_arg;
139  }
140  format = XML_OUT;
141  ofs.open(fname.c_str());
142  }
143  if ( arg == "--compiler" ) { format = COMPILER_OUT; break; }
144  if ( arg == "--cerr" ) { target = 1; break; }
145  if ( arg == "--xsl" )
146  {
147  if (next_arg == "") xsl = "default.xsl";
148  else xsl = next_arg;
149  }
150  if ( arg == "--namespace" )
151  {
152  if (next_arg == "")
153  {
154  std::cerr << "no namespace specified" << std::endl;
155  exit(1);
156  }
157  else
158  {
159  xsl = next_arg;
160  }
161  }
162  ++i;
163  }
164  CppUnit::TextUi::TestRunner runner;
165  if ( ns.empty() )
166  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
167  else
168  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
169  CppUnit::Outputter* outputter = 0;
170  std::ostream* stream = target ? &std::cerr : &std::cout;
171  switch ( format )
172  {
173  case TEXT_OUT :
174  outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
175  break;
176  case XML_OUT :
177  std::cout << "XML_OUT" << std::endl;
178  outputter = new CppUnit::XmlOutputter(&runner.result(),
179  ofs, "shift_jis");
180  static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
181  break;
182  case COMPILER_OUT :
183  outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
184  break;
185  }
186  runner.setOutputter(outputter);
187  runner.run();
188  return 0; // runner.run() ? 0 : 1;
189 }
190 #endif // MAIN
191 #endif // NumberingPolicy_cpp
int main(int argc, char **argv)
virtual void setUp()
Test initialization.
void test_onCreate_and_onDelete()
DefaultNumberingPolicy::onCreate()とDefaultNumberingPolicy::onDelete()のテスト
CPPUNIT_TEST_SUITE(NumberingPolicyTests)
CPPUNIT_TEST(test_onCreate_and_onDelete)
Object numbering policy class.
CPPUNIT_TEST_SUITE_REGISTRATION(Tests::NumberingPolicyTests)
Class for naming policy management when creating objects.
virtual void tearDown()
Test finalization.


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