aboutsummaryrefslogtreecommitdiff
path: root/test/unit/cppunit/test_main.cpp
blob: 8519d4fe6ebdb254cfa5c71fdc2fd638b75b91eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
 * Copyright (c) 2003, 2004
 * Zdenek Nemec
 *
 * This material is provided "as is", with absolutely no warranty expressed
 * or implied. Any use is at your own risk.
 *
 * Permission to use or copy this software for any purpose is hereby granted
 * without fee, provided the above notices are retained on all copies.
 * Permission to modify the code and to distribute modified code is granted,
 * provided the above notices are retained, and a notice that the code was
 * modified is included with the above copyright notice.
 *
 */

#include "cppunit_proxy.h"
#include "file_reporter.h"
#include "cppunit_timer.h"

#include "stdio.h"

#if 0
namespace CPPUNIT_NS
{
#endif
  int TestCase::m_numErrors = 0;
  int TestCase::m_numTests = 0;

  TestCase *TestCase::m_root = 0;
  Reporter *TestCase::m_reporter = 0;

  void TestCase::registerTestCase(TestCase *in_testCase) {
    in_testCase->m_next = m_root;
    m_root = in_testCase;
  }

  int TestCase::run(Reporter *in_reporter, const char *in_testName, bool invert) {
    TestCase::m_reporter = in_reporter;

    m_numErrors = 0;
    m_numTests = 0;

    TestCase *tmp = m_root;
    while (tmp != 0) {
      tmp->myRun(in_testName, invert);
      tmp = tmp->m_next;
    }
    return m_numErrors;
  }
#if 0
}
#endif

static void usage(const char* name)
{
  printf("Usage : %s [-t=<class>[::<test>]] [-x=<class>[::<test>]] [-f=<file>]%s\n",
         name, Timer::supported() ? " [-m]": "");
  printf("\t[-t=<class>[::<test>]] : test class or class::test to execute;\n");
  printf("\t[-x=<class>[::<test>]] : test class or class::test to exclude from execution;\n");
  printf("\t[-f=<file>] : output file");
  if (Timer::supported())
    printf(";\n\t[-m] : monitor test execution, display time duration for each test\n");
  else
    printf("\n");
}

int main(int argc, char** argv) {

  // CppUnit(mini) test launcher
  // command line option syntax:
  // test [OPTIONS]
  // where OPTIONS are
  //  -t=CLASS[::TEST]    run the test class CLASS or member test CLASS::TEST
  //  -x=CLASS[::TEST]    run all except the test class CLASS or member test CLASS::TEST
  //  -f=FILE             save output in file FILE instead of stdout
  //  -m                  monitor test(s) execution
  const char *fileName = 0;
  const char *testName = "";
  const char *xtestName = "";
  bool doMonitoring = false;

  for (int i = 1; i < argc; ++i) {
    if (argv[i][0] == '-') {
      if (!strncmp(argv[i], "-t=", 3)) {
        testName = argv[i]+3;
        continue;
      }
      else if (!strncmp(argv[i], "-f=", 3)) {
        fileName = argv[i]+3;
        continue;
      }
      else if (!strncmp(argv[i], "-x=", 3)) {
        xtestName = argv[i]+3;
        continue;
      }
      else if (Timer::supported() && !strncmp(argv[i], "-m", 2)) {
        doMonitoring = true;
        continue;
      }
    }

		// invalid option, we display normal usage.
    usage(argv[0]);
    return 1;
  }

  CPPUNIT_NS::Reporter* reporter;
  if (fileName != 0)
    reporter = new FileReporter(fileName, doMonitoring);
  else
    reporter = new FileReporter(stdout, doMonitoring);

  int num_errors;
  if (xtestName[0] != 0) {
    num_errors = CPPUNIT_NS::TestCase::run(reporter, xtestName, true);
  } else {
    num_errors = CPPUNIT_NS::TestCase::run(reporter, testName);
  }

  reporter->printSummary();
  delete reporter;

  return num_errors;
}

// See doc/README.intel for explanation about this code
#if defined (STLPORT) && defined (__ICL) && (__ICL >= 900) && \
            (_STLP_MSVC_LIB < 1300) && defined (_STLP_USE_DYNAMIC_LIB)
#  include <exception>

#  undef std
namespace std
{
  void _STLP_CALL unexpected() {
    unexpected_handler hdl;
    set_unexpected(hdl = set_unexpected((unexpected_handler)0));
    hdl();
  }
}
#endif