TestRunner.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00020 /*
00021  * $Log: TestRunner.cpp,v $
00022  * Revision 1.1  2007/12/20 07:50:17  arafune
00023  * *** empty log message ***
00024  *
00025  * Revision 1.1  2006/11/27 07:31:50  n-ando
00026  * CppUnit tests runner.
00027  *
00028  */
00029 
00030 #include <string>
00031 #include <fstream>
00032 #include <cppunit/ui/text/TestRunner.h>
00033 #include <cppunit/XmlOutputter.h>
00034 #include <cppunit/TextOutputter.h>
00035 #include <cppunit/CompilerOutputter.h>
00036 #include <cppunit/extensions/TestFactoryRegistry.h>
00037 
00038 enum FORMAT
00039   {
00040     TEXT_OUT,
00041     XML_OUT,
00042     COMPILER_OUT,
00043   };
00044 
00045 int main(int argc, char* argv[])
00046 {
00047 
00048   FORMAT format = TEXT_OUT;
00049   int target = 0;
00050   std::string xsl;
00051   std::string ns;
00052   std::string fname;
00053   std::ofstream ofs;
00054 
00055   int i(1);
00056   while (i < argc)
00057     {
00058       std::string arg(argv[i]);
00059       std::string next_arg;
00060       if (i + 1 < argc) next_arg = argv[i + 1];
00061       else              next_arg = "";
00062 
00063       if (arg == "--text") { format = TEXT_OUT; break; }
00064       if (arg == "--xml")
00065         {
00066           if (next_arg == "")
00067             {
00068               fname = argv[0];
00069               fname += ".xml";
00070             }
00071           else
00072             {
00073               fname = next_arg;
00074             }
00075           format = XML_OUT;
00076           ofs.open(fname.c_str());
00077         }
00078       if ( arg == "--compiler"  ) { format = COMPILER_OUT; break; }
00079       if ( arg == "--cerr"      ) { target = 1; break; }
00080       if ( arg == "--xsl"       )
00081         {
00082           if (next_arg == "") xsl = "default.xsl"; 
00083           else                xsl = next_arg;
00084         }
00085       if ( arg == "--namespace" )
00086         {
00087           if (next_arg == "")
00088             {
00089               std::cerr << "no namespace specified" << std::endl;
00090               exit(1); 
00091             }
00092           else
00093             {
00094               xsl = next_arg;
00095             }
00096         }
00097       ++i;
00098     }
00099   CppUnit::TextUi::TestRunner runner;
00100   if ( ns.empty() )
00101     runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
00102   else
00103     runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
00104   CppUnit::Outputter* outputter = 0;
00105   std::ostream* stream = target ? &std::cerr : &std::cout;
00106   switch ( format )
00107     {
00108     case TEXT_OUT :
00109       outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
00110       break;
00111     case XML_OUT :
00112       std::cout << "XML_OUT" << std::endl;
00113       outputter = new CppUnit::XmlOutputter(&runner.result(),
00114                                             ofs, "shift_jis");
00115       static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
00116       break;
00117     case COMPILER_OUT :
00118       outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
00119       break;
00120     }
00121   runner.setOutputter(outputter);
00122   runner.run();
00123   return 0; // runner.run() ? 0 : 1;
00124 }


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sat Jun 8 2019 18:49:07