test_main.cpp revision e46c9386c4f79aa40185f79a19fc5b2a7ef528b3
103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)/* 203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) * Copyright (c) 2003, 2004 303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) * Zdenek Nemec 403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) * 503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) * This material is provided "as is", with absolutely no warranty expressed 603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) * or implied. Any use is at your own risk. 703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) * 803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) * Permission to use or copy this software for any purpose is hereby granted 903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) * without fee, provided the above notices are retained on all copies. 1003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) * Permission to modify the code and to distribute modified code is granted, 1103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) * provided the above notices are retained, and a notice that the code was 1203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) * modified is included with the above copyright notice. 1303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) * 1403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) */ 1503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 1603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "cppunit_proxy.h" 1703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "file_reporter.h" 1803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "cppunit_timer.h" 1903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 2003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "stdio.h" 2103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 2203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#if 0 2303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)namespace CPPUNIT_NS 2403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles){ 2503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#endif 2603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) int TestCase::m_numErrors = 0; 27 int TestCase::m_numTests = 0; 28 29 TestCase *TestCase::m_root = 0; 30 Reporter *TestCase::m_reporter = 0; 31 32 void TestCase::registerTestCase(TestCase *in_testCase) { 33 in_testCase->m_next = m_root; 34 m_root = in_testCase; 35 } 36 37 int TestCase::run(Reporter *in_reporter, const char *in_testName, bool invert) { 38 TestCase::m_reporter = in_reporter; 39 40 m_numErrors = 0; 41 m_numTests = 0; 42 43 TestCase *tmp = m_root; 44 while (tmp != 0) { 45 tmp->myRun(in_testName, invert); 46 tmp = tmp->m_next; 47 } 48 return m_numErrors; 49 } 50#if 0 51} 52#endif 53 54static void usage(const char* name) 55{ 56 printf("Usage : %s [-t=<class>[::<test>]] [-x=<class>[::<test>]] [-f=<file>]%s\n", 57 name, Timer::supported() ? " [-m]": ""); 58 printf("\t[-t=<class>[::<test>]] : test class or class::test to execute;\n"); 59 printf("\t[-x=<class>[::<test>]] : test class or class::test to exclude from execution;\n"); 60 printf("\t[-f=<file>] : output file"); 61 if (Timer::supported()) 62 printf(";\n\t[-m] : monitor test execution, display time duration for each test\n"); 63 else 64 printf("\n"); 65} 66 67int main(int argc, char** argv) { 68 69 // CppUnit(mini) test launcher 70 // command line option syntax: 71 // test [OPTIONS] 72 // where OPTIONS are 73 // -t=CLASS[::TEST] run the test class CLASS or member test CLASS::TEST 74 // -x=CLASS[::TEST] run all except the test class CLASS or member test CLASS::TEST 75 // -f=FILE save output in file FILE instead of stdout 76 // -m monitor test(s) execution 77 const char *fileName = 0; 78 const char *testName = ""; 79 const char *xtestName = ""; 80 bool doMonitoring = false; 81 82 for (int i = 1; i < argc; ++i) { 83 if (argv[i][0] == '-') { 84 if (!strncmp(argv[i], "-t=", 3)) { 85 testName = argv[i]+3; 86 continue; 87 } 88 else if (!strncmp(argv[i], "-f=", 3)) { 89 fileName = argv[i]+3; 90 continue; 91 } 92 else if (!strncmp(argv[i], "-x=", 3)) { 93 xtestName = argv[i]+3; 94 continue; 95 } 96 else if (Timer::supported() && !strncmp(argv[i], "-m", 2)) { 97 doMonitoring = true; 98 continue; 99 } 100 } 101 102 // invalid option, we display normal usage. 103 usage(argv[0]); 104 return 1; 105 } 106 107 CPPUNIT_NS::Reporter* reporter; 108 if (fileName != 0) 109 reporter = new FileReporter(fileName, doMonitoring); 110 else 111 reporter = new FileReporter(stdout, doMonitoring); 112 113 int num_errors; 114 if (xtestName[0] != 0) { 115 num_errors = CPPUNIT_NS::TestCase::run(reporter, xtestName, true); 116 } else { 117 num_errors = CPPUNIT_NS::TestCase::run(reporter, testName); 118 } 119 120 reporter->printSummary(); 121 delete reporter; 122 123 return num_errors; 124} 125 126// See doc/README.intel for explanation about this code 127#if defined (STLPORT) && defined (__ICL) && (__ICL >= 900) && \ 128 (_STLP_MSVC_LIB < 1300) && defined (_STLP_USE_DYNAMIC_LIB) 129# include <exception> 130 131# undef std 132namespace std 133{ 134 void _STLP_CALL unexpected() { 135 unexpected_handler hdl; 136 set_unexpected(hdl = set_unexpected((unexpected_handler)0)); 137 hdl(); 138 } 139} 140#endif 141