os/ossrv/genericopenlibs/cppstdlib/stl/test/unit/cppunit/test_main.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
 * Copyright (c) 2003, 2004
sl@0
     3
 * Zdenek Nemec
sl@0
     4
 *
sl@0
     5
 * This material is provided "as is", with absolutely no warranty expressed
sl@0
     6
 * or implied. Any use is at your own risk.
sl@0
     7
 *
sl@0
     8
 * Permission to use or copy this software for any purpose is hereby granted
sl@0
     9
 * without fee, provided the above notices are retained on all copies.
sl@0
    10
 * Permission to modify the code and to distribute modified code is granted,
sl@0
    11
 * provided the above notices are retained, and a notice that the code was
sl@0
    12
 * modified is included with the above copyright notice.
sl@0
    13
 *
sl@0
    14
 */
sl@0
    15
sl@0
    16
#include "cppunit_proxy.h"
sl@0
    17
#include "file_reporter.h"
sl@0
    18
#include "cppunit_timer.h"
sl@0
    19
sl@0
    20
namespace CPPUNIT_NS
sl@0
    21
{
sl@0
    22
  int CPPUNIT_NS::TestCase::m_numErrors = 0;
sl@0
    23
  int CPPUNIT_NS::TestCase::m_numTests = 0;
sl@0
    24
sl@0
    25
  CPPUNIT_NS::TestCase *CPPUNIT_NS::TestCase::m_root = 0;
sl@0
    26
  CPPUNIT_NS::Reporter *CPPUNIT_NS::TestCase::m_reporter = 0;
sl@0
    27
sl@0
    28
  void CPPUNIT_NS::TestCase::registerTestCase(TestCase *in_testCase) {
sl@0
    29
    in_testCase->m_next = m_root;
sl@0
    30
    m_root = in_testCase;
sl@0
    31
  }
sl@0
    32
sl@0
    33
  int CPPUNIT_NS::TestCase::run(Reporter *in_reporter, const char *in_testName, bool invert) {
sl@0
    34
    TestCase::m_reporter = in_reporter;
sl@0
    35
sl@0
    36
    m_numErrors = 0;
sl@0
    37
    m_numTests = 0;
sl@0
    38
sl@0
    39
    TestCase *tmp = m_root;
sl@0
    40
    while (tmp != 0) {
sl@0
    41
      in_reporter->setFirstStep(true);
sl@0
    42
      tmp->myRun(in_testName, invert);
sl@0
    43
      tmp = tmp->m_next;
sl@0
    44
    }
sl@0
    45
    return m_numErrors;
sl@0
    46
  }
sl@0
    47
}
sl@0
    48
sl@0
    49
int main(int argc, char** argv) {
sl@0
    50
sl@0
    51
  // CppUnit(mini) test launcher
sl@0
    52
  // command line option syntax:
sl@0
    53
  // test [OPTIONS]
sl@0
    54
  // where OPTIONS are
sl@0
    55
  //  -t=CLASS[::TEST]    run the test class CLASS or member test CLASS::TEST
sl@0
    56
  //  -x=CLASS[::TEST]    run all except the test class CLASS or member test CLASS::TEST
sl@0
    57
  //  -f=FILE             save output in file FILE instead of stdout
sl@0
    58
  //  -m                  monitor test(s) execution
sl@0
    59
  char *fileName = 0;
sl@0
    60
  char *testName = "";
sl@0
    61
  char *xtestName = "";
sl@0
    62
  bool doMonitoring = false;
sl@0
    63
sl@0
    64
  for (int i = 1; i < argc; ++i) {
sl@0
    65
    if (argv[i][0] != '-')
sl@0
    66
      break;
sl@0
    67
    if (!strncmp(argv[i], "-t=", 3)) {
sl@0
    68
      testName = argv[i]+3;
sl@0
    69
    }
sl@0
    70
    else if (!strncmp(argv[i], "-f=", 3)) {
sl@0
    71
      fileName = argv[i]+3;
sl@0
    72
    }
sl@0
    73
    else if (!strncmp(argv[i], "-x=", 3)) {
sl@0
    74
      xtestName = argv[i]+3;
sl@0
    75
    }
sl@0
    76
    else if (Timer::supported() && !strncmp(argv[i], "-m", 2)) {
sl@0
    77
      doMonitoring = true;
sl@0
    78
    }
sl@0
    79
  }
sl@0
    80
sl@0
    81
  CPPUNIT_NS::Reporter* reporter;
sl@0
    82
  if (fileName != 0)
sl@0
    83
    reporter = new FileReporter(fileName, doMonitoring);
sl@0
    84
  else
sl@0
    85
    reporter = new FileReporter(stdout, doMonitoring);
sl@0
    86
sl@0
    87
  int num_errors;
sl@0
    88
  if (xtestName[0] != 0) {
sl@0
    89
    num_errors = CPPUNIT_NS::TestCase::run(reporter, xtestName, true);
sl@0
    90
  } else {
sl@0
    91
    num_errors = CPPUNIT_NS::TestCase::run(reporter, testName);
sl@0
    92
  }
sl@0
    93
sl@0
    94
  reporter->printSummary();
sl@0
    95
  delete reporter;
sl@0
    96
sl@0
    97
  return num_errors;
sl@0
    98
}
sl@0
    99
sl@0
   100
// See doc/README.intel for explanation about this code
sl@0
   101
#if defined (STLPORT) && defined (__ICL) && (__ICL >= 900) && \
sl@0
   102
            (_STLP_MSVC_LIB < 1300) && defined (_STLP_USE_DYNAMIC_LIB)
sl@0
   103
#  include <exception>
sl@0
   104
sl@0
   105
#  undef std
sl@0
   106
namespace std
sl@0
   107
{
sl@0
   108
  void _STLP_CALL unexpected() {
sl@0
   109
    unexpected_handler hdl;
sl@0
   110
    set_unexpected(hdl = set_unexpected((unexpected_handler)0));
sl@0
   111
    hdl();
sl@0
   112
  }
sl@0
   113
}
sl@0
   114
#endif