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 #ifdef __QNX__
40 using std::exit;
41 #endif
42 
43 enum FORMAT
44  {
48  };
49 
50 int main(int argc, char* argv[])
51 {
52 
53  FORMAT format = TEXT_OUT;
54  int target = 0;
55  std::string xsl;
56  std::string ns;
57  std::string fname;
58  std::ofstream ofs;
59 
60  int i(1);
61  while (i < argc)
62  {
63  std::string arg(argv[i]);
64  std::string next_arg;
65  if (i + 1 < argc) next_arg = argv[i + 1];
66  else next_arg = "";
67 
68  if (arg == "--text") { format = TEXT_OUT; break; }
69  if (arg == "--xml")
70  {
71  if (next_arg == "")
72  {
73  fname = argv[0];
74  fname += ".xml";
75  }
76  else
77  {
78  fname = next_arg;
79  }
80  format = XML_OUT;
81  ofs.open(fname.c_str());
82  }
83  if ( arg == "--compiler" ) { format = COMPILER_OUT; break; }
84  if ( arg == "--cerr" ) { target = 1; break; }
85  if ( arg == "--xsl" )
86  {
87  if (next_arg == "") xsl = "default.xsl";
88  else xsl = next_arg;
89  }
90  if ( arg == "--namespace" )
91  {
92  if (next_arg == "")
93  {
94  std::cerr << "no namespace specified" << std::endl;
95  exit(1);
96  }
97  else
98  {
99  xsl = next_arg;
100  }
101  }
102  ++i;
103  }
104  CppUnit::TextUi::TestRunner runner;
105  if ( ns.empty() )
106  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
107  else
108  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
109  CppUnit::Outputter* outputter = 0;
110  std::ostream* stream = target ? &std::cerr : &std::cout;
111  switch ( format )
112  {
113  case TEXT_OUT :
114  outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
115  break;
116  case XML_OUT :
117  std::cout << "XML_OUT" << std::endl;
118  outputter = new CppUnit::XmlOutputter(&runner.result(),
119  ofs, "shift_jis");
120  static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
121  break;
122  case COMPILER_OUT :
123  outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
124  break;
125  }
126  runner.setOutputter(outputter);
127  return runner.run() ? 0 : 1;
128 // return 0; // runner.run() ? 0 : 1;
129 }
int main(int argc, char *argv[])


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Feb 28 2022 23:00:45