os/ossrv/genericopenlibs/cppstdlib/stl/test/unit/cppunit/test_main.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 namespace CPPUNIT_NS
    21 {
    22   int CPPUNIT_NS::TestCase::m_numErrors = 0;
    23   int CPPUNIT_NS::TestCase::m_numTests = 0;
    24 
    25   CPPUNIT_NS::TestCase *CPPUNIT_NS::TestCase::m_root = 0;
    26   CPPUNIT_NS::Reporter *CPPUNIT_NS::TestCase::m_reporter = 0;
    27 
    28   void CPPUNIT_NS::TestCase::registerTestCase(TestCase *in_testCase) {
    29     in_testCase->m_next = m_root;
    30     m_root = in_testCase;
    31   }
    32 
    33   int CPPUNIT_NS::TestCase::run(Reporter *in_reporter, const char *in_testName, bool invert) {
    34     TestCase::m_reporter = in_reporter;
    35 
    36     m_numErrors = 0;
    37     m_numTests = 0;
    38 
    39     TestCase *tmp = m_root;
    40     while (tmp != 0) {
    41       in_reporter->setFirstStep(true);
    42       tmp->myRun(in_testName, invert);
    43       tmp = tmp->m_next;
    44     }
    45     return m_numErrors;
    46   }
    47 }
    48 
    49 int main(int argc, char** argv) {
    50 
    51   // CppUnit(mini) test launcher
    52   // command line option syntax:
    53   // test [OPTIONS]
    54   // where OPTIONS are
    55   //  -t=CLASS[::TEST]    run the test class CLASS or member test CLASS::TEST
    56   //  -x=CLASS[::TEST]    run all except the test class CLASS or member test CLASS::TEST
    57   //  -f=FILE             save output in file FILE instead of stdout
    58   //  -m                  monitor test(s) execution
    59   char *fileName = 0;
    60   char *testName = "";
    61   char *xtestName = "";
    62   bool doMonitoring = false;
    63 
    64   for (int i = 1; i < argc; ++i) {
    65     if (argv[i][0] != '-')
    66       break;
    67     if (!strncmp(argv[i], "-t=", 3)) {
    68       testName = argv[i]+3;
    69     }
    70     else if (!strncmp(argv[i], "-f=", 3)) {
    71       fileName = argv[i]+3;
    72     }
    73     else if (!strncmp(argv[i], "-x=", 3)) {
    74       xtestName = argv[i]+3;
    75     }
    76     else if (Timer::supported() && !strncmp(argv[i], "-m", 2)) {
    77       doMonitoring = true;
    78     }
    79   }
    80 
    81   CPPUNIT_NS::Reporter* reporter;
    82   if (fileName != 0)
    83     reporter = new FileReporter(fileName, doMonitoring);
    84   else
    85     reporter = new FileReporter(stdout, doMonitoring);
    86 
    87   int num_errors;
    88   if (xtestName[0] != 0) {
    89     num_errors = CPPUNIT_NS::TestCase::run(reporter, xtestName, true);
    90   } else {
    91     num_errors = CPPUNIT_NS::TestCase::run(reporter, testName);
    92   }
    93 
    94   reporter->printSummary();
    95   delete reporter;
    96 
    97   return num_errors;
    98 }
    99 
   100 // See doc/README.intel for explanation about this code
   101 #if defined (STLPORT) && defined (__ICL) && (__ICL >= 900) && \
   102             (_STLP_MSVC_LIB < 1300) && defined (_STLP_USE_DYNAMIC_LIB)
   103 #  include <exception>
   104 
   105 #  undef std
   106 namespace std
   107 {
   108   void _STLP_CALL unexpected() {
   109     unexpected_handler hdl;
   110     set_unexpected(hdl = set_unexpected((unexpected_handler)0));
   111     hdl();
   112   }
   113 }
   114 #endif