coil/tests/TestRunner.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
20 /*
21  * $Log: TestRunner.cpp,v $
22  * Revision 1.1 2007/12/20 07:50:17 arafune
23  * *** empty log message ***
24  *
25  * Revision 1.1 2006/11/27 07:31:50 n-ando
26  * CppUnit tests runner.
27  *
28  */
29 
30 #include <string>
31 #include <cstdlib>
32 #include <fstream>
33 #include <cppunit/ui/text/TestRunner.h>
34 #include <cppunit/XmlOutputter.h>
35 #include <cppunit/TextOutputter.h>
36 #include <cppunit/CompilerOutputter.h>
37 #include <cppunit/extensions/TestFactoryRegistry.h>
38 
39 enum FORMAT
40  {
44  };
45 
46 int main(int argc, char* argv[])
47 {
48 
49  FORMAT format = TEXT_OUT;
50  int target = 0;
51  std::string xsl;
52  std::string ns;
53  std::string fname;
54  std::ofstream ofs;
55 
56  int i(1);
57  while (i < argc)
58  {
59  std::string arg(argv[i]);
60  std::string next_arg;
61  if (i + 1 < argc) next_arg = argv[i + 1];
62  else next_arg = "";
63 
64  if (arg == "--text") { format = TEXT_OUT; break; }
65  if (arg == "--xml")
66  {
67  if (next_arg == "")
68  {
69  fname = argv[0];
70  fname += ".xml";
71  }
72  else
73  {
74  fname = next_arg;
75  }
76  format = XML_OUT;
77  ofs.open(fname.c_str());
78  }
79  if ( arg == "--compiler" ) { format = COMPILER_OUT; break; }
80  if ( arg == "--cerr" ) { target = 1; break; }
81  if ( arg == "--xsl" )
82  {
83  if (next_arg == "") xsl = "default.xsl";
84  else xsl = next_arg;
85  }
86  if ( arg == "--namespace" )
87  {
88  if (next_arg == "")
89  {
90  std::cerr << "no namespace specified" << std::endl;
91  exit(1);
92  }
93  else
94  {
95  xsl = next_arg;
96  }
97  }
98  ++i;
99  }
100  CppUnit::TextUi::TestRunner runner;
101  if ( ns.empty() )
102  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
103  else
104  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
105  CppUnit::Outputter* outputter = 0;
106  std::ostream* stream = target ? &std::cerr : &std::cout;
107  switch ( format )
108  {
109  case TEXT_OUT :
110  outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
111  break;
112  case XML_OUT :
113  std::cout << "XML_OUT" << std::endl;
114  outputter = new CppUnit::XmlOutputter(&runner.result(),
115  ofs, "shift_jis");
116  static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
117  break;
118  case COMPILER_OUT :
119  outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
120  break;
121  }
122  runner.setOutputter(outputter);
123  return runner.run() ? 0 : 1;
124 // return 0; // runner.run() ? 0 : 1;
125 }
int main(int argc, char *argv[])


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