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 <cstdlib>
00032 #include <fstream>
00033 #include <cppunit/ui/text/TestRunner.h>
00034 #include <cppunit/XmlOutputter.h>
00035 #include <cppunit/TextOutputter.h>
00036 #include <cppunit/CompilerOutputter.h>
00037 #include <cppunit/extensions/TestFactoryRegistry.h>
00038 
00039 enum FORMAT
00040   {
00041     TEXT_OUT,
00042     XML_OUT,
00043     COMPILER_OUT,
00044   };
00045 
00046 int main(int argc, char* argv[])
00047 {
00048 
00049   FORMAT format = TEXT_OUT;
00050   int target = 0;
00051   std::string xsl;
00052   std::string ns;
00053   std::string fname;
00054   std::ofstream ofs;
00055 
00056   int i(1);
00057   while (i < argc)
00058     {
00059       std::string arg(argv[i]);
00060       std::string next_arg;
00061       if (i + 1 < argc) next_arg = argv[i + 1];
00062       else              next_arg = "";
00063 
00064       if (arg == "--text") { format = TEXT_OUT; break; }
00065       if (arg == "--xml")
00066         {
00067           if (next_arg == "")
00068             {
00069               fname = argv[0];
00070               fname += ".xml";
00071             }
00072           else
00073             {
00074               fname = next_arg;
00075             }
00076           format = XML_OUT;
00077           ofs.open(fname.c_str());
00078         }
00079       if ( arg == "--compiler"  ) { format = COMPILER_OUT; break; }
00080       if ( arg == "--cerr"      ) { target = 1; break; }
00081       if ( arg == "--xsl"       )
00082         {
00083           if (next_arg == "") xsl = "default.xsl"; 
00084           else                xsl = next_arg;
00085         }
00086       if ( arg == "--namespace" )
00087         {
00088           if (next_arg == "")
00089             {
00090               std::cerr << "no namespace specified" << std::endl;
00091               exit(1); 
00092             }
00093           else
00094             {
00095               xsl = next_arg;
00096             }
00097         }
00098       ++i;
00099     }
00100   CppUnit::TextUi::TestRunner runner;
00101   if ( ns.empty() )
00102     runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
00103   else
00104     runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
00105   CppUnit::Outputter* outputter = 0;
00106   std::ostream* stream = target ? &std::cerr : &std::cout;
00107   switch ( format )
00108     {
00109     case TEXT_OUT :
00110       outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
00111       break;
00112     case XML_OUT :
00113       std::cout << "XML_OUT" << std::endl;
00114       outputter = new CppUnit::XmlOutputter(&runner.result(),
00115                                             ofs, "shift_jis");
00116       static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
00117       break;
00118     case COMPILER_OUT :
00119       outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
00120       break;
00121     }
00122   runner.setOutputter(outputter);
00123   return runner.run() ? 0 : 1;
00124 //  return 0; // runner.run() ? 0 : 1;
00125 }


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sun Mar 26 2017 03:37:17