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


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