Update contrib.
2 * Copyright (c) 2003, 2004
5 * This material is provided "as is", with absolutely no warranty expressed
6 * or implied. Any use is at your own risk.
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.
16 /* $Id: cppunit_mini.h 2490 2006-06-27 19:49:26Z dums $ */
18 #ifndef _CPPUNITMPFR_H_
19 #define _CPPUNITMPFR_H_
21 #define CPPUNIT_NS CppUnitMini
29 virtual ~Reporter() {}
30 virtual void error(const char * /*macroName*/, const char * /*in_macro*/, const char * /*in_file*/, int /*in_line*/) {}
31 virtual void failure(const char * /*macroName*/, const char * /*in_macro*/, const char * /*in_file*/, int /*in_line*/) {}
32 virtual void message( const char * /*msg*/ ) {}
33 virtual void progress( const char * /*in_className*/, const char * /*in_testName*/, bool /*ignored*/) {}
35 virtual void printSummary() {}
36 void setFirstStep(const bool in_firstStep) {m_firstStep = in_firstStep;}
37 const bool firstStep() { return m_firstStep; }
44 virtual ~TestFixture() {}
46 //! \brief Set up context before running a test.
47 virtual void setUp() {}
49 //! Clean up after the test run.
50 virtual void tearDown() {}
53 class TestCase : public TestFixture {
55 TestCase() { m_failed = false; registerTestCase(this); }
57 static int run(Reporter *in_reporter = 0, const char *in_testName = "", bool invert = false);
58 int numErrors() { return m_numErrors; }
59 static void registerTestCase(TestCase *in_testCase);
61 virtual void myRun(const char * /*in_name*/, bool /*invert*/ = false) {}
63 virtual void failure(const char *in_macroName, const char *in_macro, const char *in_file, int in_line) {
66 m_reporter->failure(in_macroName, in_macro, in_file, in_line);
70 virtual void error(const char *in_macroName, const char *in_macro, const char *in_file, int in_line) {
73 m_reporter->error(in_macroName, in_macro, in_file, in_line);
77 static void message(const char *msg) {
79 m_reporter->message(msg);
83 bool equalDoubles(double in_expected, double in_real, double in_maxErr) {
84 double diff = in_expected - in_real;
88 return diff < in_maxErr;
91 virtual void progress(const char *in_className, const char *in_functionName, bool ignored) {
94 m_reporter->progress(in_className, in_functionName, ignored);
98 bool shouldRunThis(const char *in_desiredTest, const char *in_className, const char *in_functionName, bool invert = false) {
99 if ((in_desiredTest) && (in_desiredTest[0] != '\0')) {
100 const char *ptr = strstr(in_desiredTest, "::");
102 bool decision = (strncmp(in_desiredTest, in_className, strlen(in_className)) == 0) &&
103 (strncmp(ptr + 2, in_functionName, strlen(in_functionName)) == 0);
104 return invert ? !decision : decision;
106 bool decision = strcmp(in_desiredTest, in_className) == 0;
107 return invert ? !decision : decision;
119 static int m_numErrors;
120 static int m_numTests;
123 static TestCase *m_root;
127 static Reporter *m_reporter;
131 #if !defined (CPPUNIT_MINI_HIDE_UNUSED_VARIABLE)
132 # if defined (_MSC_VER)
133 # define CPPUNIT_MINI_HIDE_UNUSED_VARIABLE(v) (v);
135 # define CPPUNIT_MINI_HIDE_UNUSED_VARIABLE(v)
139 #define CPPUNIT_TEST_SUITE(X) \
140 typedef CPPUNIT_NS::TestCase Base; \
141 virtual void myRun(const char *in_name, bool invert = false) { \
142 char *className = #X; CPPUNIT_MINI_HIDE_UNUSED_VARIABLE(className) \
143 bool ignoring = false; CPPUNIT_MINI_HIDE_UNUSED_VARIABLE(ignoring)
145 #if defined CPPUNIT_MINI_USE_EXCEPTIONS
146 # define CPPUNIT_TEST(X) \
147 if (shouldRunThis(in_name, className, #X, invert)) { \
149 progress(className, #X, ignoring); \
155 Base::error("Test Failed: An Exception was thrown.", #X, __FILE__, __LINE__); \
161 # define CPPUNIT_TEST(X) \
162 if (shouldRunThis(in_name, className, #X, invert)) { \
164 progress(className, #X, ignoring); \
171 # define CPPUNIT_IGNORE \
174 # define CPPUNIT_STOP_IGNORE \
177 #define CPPUNIT_TEST_EXCEPTION(X, Y) \
178 if (shouldRunThis(in_name, className, #X, invert)) { \
179 progress(className, #X, ignoring); \
182 #define CPPUNIT_TEST_SUITE_END() }
184 #define CPPUNIT_TEST_SUITE_REGISTRATION(X) static X local
186 #define CPPUNIT_CHECK(X) \
188 Base::failure("CPPUNIT_CHECK", #X, __FILE__, __LINE__); \
191 #define CPPUNIT_ASSERT(X) \
193 Base::error("CPPUNIT_ASSERT", #X, __FILE__, __LINE__); \
197 #define CPPUNIT_ASSERT_EQUAL(X, Y) \
199 Base::error("CPPUNIT_ASSERT_EQUAL", #X","#Y, __FILE__, __LINE__); \
203 #define CPPUNIT_ASSERT_DOUBLES_EQUAL(X, Y, Z) \
204 if (!equalDoubles((X), (Y), (Z))) { \
205 Base::error("CPPUNIT_ASSERT_DOUBLES_EQUAL", #X","#Y","#Z, __FILE__, __LINE__); \
209 #define CPPUNIT_MESSAGE(m) CPPUNIT_NS::TestCase::message(m)