Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <cppunit/CompilerOutputter.h>
00022 #include <cppunit/extensions/TestFactoryRegistry.h>
00023 #include <cppunit/TextTestProgressListener.h>
00024 #include <cppunit/Exception.h>
00025 #include <cppunit/ui/text/TestRunner.h>
00026 #include <cppunit/TextTestResult.h>
00027 #include <string.h>
00028 #include <stdexcept>
00029 #if defined (_MSC_VER) && _MSC_VER >= 1200
00030 #include <crtdbg.h>
00031 #endif
00032
00033
00034 class CmdLineRunner : public CPPUNIT_NS::TextUi::TestRunner {
00035 public:
00036 using CPPUNIT_NS::TextUi::TestRunner::run;
00037 bool run(const std::string& prefix, char** argv, int num) {
00038 using namespace CPPUNIT_NS;
00039 if (num == 0) {
00040 return TextUi::TestRunner::run();
00041 }
00042 TextTestProgressListener progress;
00043 m_eventManager->addListener( &progress );
00044 for (int i = 0; i != num; ++i) {
00045 std::string path = strncmp(argv[i], prefix.c_str(), prefix.length()) != 0 ? prefix + argv[i] : argv[i];
00046 try { TestRunner::run(*m_eventManager, path); }
00047 catch (const std::invalid_argument& e) {
00048 m_eventManager->addError(m_suite, new Exception(Message(e.what()), CPPUNIT_SOURCELINE()));
00049 }
00050 }
00051 m_eventManager->removeListener( &progress );
00052 printResult( true );
00053 return m_result->wasSuccessful();
00054 }
00055 };
00056
00057 int main(int argc, char** argv) {
00058 #if defined (_MSC_VER) && defined (CHECK_HEAP) && _MSC_VER >= 1200
00059 _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) |
00060 _CRTDBG_LEAK_CHECK_DF | _CRTDBG_ALLOC_MEM_DF |
00061 _CRTDBG_CHECK_ALWAYS_DF);
00062
00063 _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE );
00064 _CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDERR );
00065 _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE );
00066 _CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDERR );
00067 _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE );
00068 _CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDERR );
00069 #endif
00070 CmdLineRunner runner;
00071
00072 #if defined (_MSC_VER)
00073 runner.setOutputter( new CPPUNIT_NS::CompilerOutputter( &runner.result(), std::cout ) );
00074 #else
00075 runner.setOutputter( new CPPUNIT_NS::CompilerOutputter( &runner.result(), std::cout, "%p:%l:" ) );
00076 #endif
00077
00078 runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() );
00079
00080 return 1 - int(runner.run("Clasp::Test::", argv + 1, argc - 1));
00081 }