test_main.cpp
Go to the documentation of this file.
00001 // 
00002 // Copyright (c) 2006, Benjamin Kaufmann
00003 // 
00004 // This file is part of Clasp. See http://www.cs.uni-potsdam.de/clasp/ 
00005 // 
00006 // Clasp is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License as published by
00008 // the Free Software Foundation; either version 2 of the License, or
00009 // (at your option) any later version.
00010 // 
00011 // Clasp is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 // 
00016 // You should have received a copy of the GNU General Public License
00017 // along with Clasp; if not, write to the Free Software
00018 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
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 // #define CHECK_HEAP 1;
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) { // run all tests
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         // Change the default outputter to a compiler error format outputter.
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         // Add all registered tests.
00078         runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() );
00079         // Run selected tests.
00080         return 1 - int(runner.run("Clasp::Test::", argv + 1, argc - 1));
00081 }


clasp
Author(s): Benjamin Kaufmann
autogenerated on Thu Aug 27 2015 12:41:40