Home | History | Annotate | Download | only in cppunit
      1 /*
      2  * Copyright (c) 2003, 2004
      3  * Zdenek Nemec
      4  *
      5  * This material is provided "as is", with absolutely no warranty expressed
      6  * or implied. Any use is at your own risk.
      7  *
      8  * Permission to use or copy this software for any purpose is hereby granted
      9  * without fee, provided the above notices are retained on all copies.
     10  * Permission to modify the code and to distribute modified code is granted,
     11  * provided the above notices are retained, and a notice that the code was
     12  * modified is included with the above copyright notice.
     13  *
     14  */
     15 
     16 #include "cppunit_proxy.h"
     17 #include "file_reporter.h"
     18 #include "cppunit_timer.h"
     19 
     20 #include "stdio.h"
     21 
     22 #if 0
     23 namespace CPPUNIT_NS
     24 {
     25 #endif
     26   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 
     54 static 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 
     67 int 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
    132 namespace 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