1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cppstdlib/stl/test/unit/cppunit/cppunit_mini.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,211 @@
1.4 +/*
1.5 + * Copyright (c) 2003, 2004
1.6 + * Zdenek Nemec
1.7 + *
1.8 + * This material is provided "as is", with absolutely no warranty expressed
1.9 + * or implied. Any use is at your own risk.
1.10 + *
1.11 + * Permission to use or copy this software for any purpose is hereby granted
1.12 + * without fee, provided the above notices are retained on all copies.
1.13 + * Permission to modify the code and to distribute modified code is granted,
1.14 + * provided the above notices are retained, and a notice that the code was
1.15 + * modified is included with the above copyright notice.
1.16 + *
1.17 + */
1.18 +
1.19 +/* $Id: cppunit_mini.h 2490 2006-06-27 19:49:26Z dums $ */
1.20 +
1.21 +#ifndef _CPPUNITMPFR_H_
1.22 +#define _CPPUNITMPFR_H_
1.23 +
1.24 +#define CPPUNIT_NS CppUnitMini
1.25 +
1.26 +#include <string.h>
1.27 +
1.28 +namespace CPPUNIT_NS
1.29 +{
1.30 + class Reporter {
1.31 + public:
1.32 + virtual ~Reporter() {}
1.33 + virtual void error(const char * /*macroName*/, const char * /*in_macro*/, const char * /*in_file*/, int /*in_line*/) {}
1.34 + virtual void failure(const char * /*macroName*/, const char * /*in_macro*/, const char * /*in_file*/, int /*in_line*/) {}
1.35 + virtual void message( const char * /*msg*/ ) {}
1.36 + virtual void progress( const char * /*in_className*/, const char * /*in_testName*/, bool /*ignored*/) {}
1.37 + virtual void end() {}
1.38 + virtual void printSummary() {}
1.39 + void setFirstStep(const bool in_firstStep) {m_firstStep = in_firstStep;}
1.40 + const bool firstStep() { return m_firstStep; }
1.41 + private:
1.42 + bool m_firstStep;
1.43 + };
1.44 +
1.45 + class TestFixture {
1.46 + public:
1.47 + virtual ~TestFixture() {}
1.48 +
1.49 + //! \brief Set up context before running a test.
1.50 + virtual void setUp() {}
1.51 +
1.52 + //! Clean up after the test run.
1.53 + virtual void tearDown() {}
1.54 + };
1.55 +
1.56 + class TestCase : public TestFixture {
1.57 + public:
1.58 + TestCase() { m_failed = false; registerTestCase(this); }
1.59 +
1.60 + static int run(Reporter *in_reporter = 0, const char *in_testName = "", bool invert = false);
1.61 + int numErrors() { return m_numErrors; }
1.62 + static void registerTestCase(TestCase *in_testCase);
1.63 +
1.64 + virtual void myRun(const char * /*in_name*/, bool /*invert*/ = false) {}
1.65 +
1.66 + virtual void failure(const char *in_macroName, const char *in_macro, const char *in_file, int in_line) {
1.67 + m_failed = true;
1.68 + if (m_reporter) {
1.69 + m_reporter->failure(in_macroName, in_macro, in_file, in_line);
1.70 + }
1.71 + }
1.72 +
1.73 + virtual void error(const char *in_macroName, const char *in_macro, const char *in_file, int in_line) {
1.74 + ++m_numErrors;
1.75 + if (m_reporter) {
1.76 + m_reporter->error(in_macroName, in_macro, in_file, in_line);
1.77 + }
1.78 + }
1.79 +
1.80 + static void message(const char *msg) {
1.81 + if (m_reporter) {
1.82 + m_reporter->message(msg);
1.83 + }
1.84 + }
1.85 +
1.86 + bool equalDoubles(double in_expected, double in_real, double in_maxErr) {
1.87 + double diff = in_expected - in_real;
1.88 + if (diff < 0.) {
1.89 + diff = -diff;
1.90 + }
1.91 + return diff < in_maxErr;
1.92 + }
1.93 +
1.94 + virtual void progress(const char *in_className, const char *in_functionName, bool ignored) {
1.95 + ++m_numTests;
1.96 + if (m_reporter) {
1.97 + m_reporter->progress(in_className, in_functionName, ignored);
1.98 + }
1.99 + }
1.100 +
1.101 + bool shouldRunThis(const char *in_desiredTest, const char *in_className, const char *in_functionName, bool invert = false) {
1.102 + if ((in_desiredTest) && (in_desiredTest[0] != '\0')) {
1.103 + const char *ptr = strstr(in_desiredTest, "::");
1.104 + if (ptr) {
1.105 + bool decision = (strncmp(in_desiredTest, in_className, strlen(in_className)) == 0) &&
1.106 + (strncmp(ptr + 2, in_functionName, strlen(in_functionName)) == 0);
1.107 + return invert ? !decision : decision;
1.108 + }
1.109 + bool decision = strcmp(in_desiredTest, in_className) == 0;
1.110 + return invert ? !decision : decision;
1.111 + }
1.112 + return true;
1.113 + }
1.114 +
1.115 + void tearDown() {
1.116 + if (m_failed)
1.117 + ++m_numErrors;
1.118 + m_reporter->end();
1.119 + }
1.120 +
1.121 + protected:
1.122 + static int m_numErrors;
1.123 + static int m_numTests;
1.124 +
1.125 + private:
1.126 + static TestCase *m_root;
1.127 + TestCase *m_next;
1.128 + bool m_failed;
1.129 +
1.130 + static Reporter *m_reporter;
1.131 + };
1.132 +}
1.133 +
1.134 +#if !defined (CPPUNIT_MINI_HIDE_UNUSED_VARIABLE)
1.135 +# if defined (_MSC_VER)
1.136 +# define CPPUNIT_MINI_HIDE_UNUSED_VARIABLE(v) (v);
1.137 +# else
1.138 +# define CPPUNIT_MINI_HIDE_UNUSED_VARIABLE(v)
1.139 +# endif
1.140 +#endif
1.141 +
1.142 +#define CPPUNIT_TEST_SUITE(X) \
1.143 + typedef CPPUNIT_NS::TestCase Base; \
1.144 + virtual void myRun(const char *in_name, bool invert = false) { \
1.145 + char *className = #X; CPPUNIT_MINI_HIDE_UNUSED_VARIABLE(className) \
1.146 + bool ignoring = false; CPPUNIT_MINI_HIDE_UNUSED_VARIABLE(ignoring)
1.147 +
1.148 +#if defined CPPUNIT_MINI_USE_EXCEPTIONS
1.149 +# define CPPUNIT_TEST(X) \
1.150 + if (shouldRunThis(in_name, className, #X, invert)) { \
1.151 + setUp(); \
1.152 + progress(className, #X, ignoring); \
1.153 + if (!ignoring) { \
1.154 + try { \
1.155 + X(); \
1.156 + } \
1.157 + catch(...) { \
1.158 + Base::error("Test Failed: An Exception was thrown.", #X, __FILE__, __LINE__); \
1.159 + } \
1.160 + } \
1.161 + tearDown(); \
1.162 + }
1.163 +#else
1.164 +# define CPPUNIT_TEST(X) \
1.165 + if (shouldRunThis(in_name, className, #X, invert)) { \
1.166 + setUp(); \
1.167 + progress(className, #X, ignoring); \
1.168 + if (!ignoring) \
1.169 + X(); \
1.170 + tearDown(); \
1.171 + }
1.172 +#endif
1.173 +
1.174 +# define CPPUNIT_IGNORE \
1.175 + ignoring = true
1.176 +
1.177 +# define CPPUNIT_STOP_IGNORE \
1.178 + ignoring = false
1.179 +
1.180 +#define CPPUNIT_TEST_EXCEPTION(X, Y) \
1.181 + if (shouldRunThis(in_name, className, #X, invert)) { \
1.182 + progress(className, #X, ignoring); \
1.183 + }
1.184 +
1.185 +#define CPPUNIT_TEST_SUITE_END() }
1.186 +
1.187 +#define CPPUNIT_TEST_SUITE_REGISTRATION(X) static X local
1.188 +
1.189 +#define CPPUNIT_CHECK(X) \
1.190 + if (!(X)) { \
1.191 + Base::failure("CPPUNIT_CHECK", #X, __FILE__, __LINE__); \
1.192 + }
1.193 +
1.194 +#define CPPUNIT_ASSERT(X) \
1.195 + if (!(X)) { \
1.196 + Base::error("CPPUNIT_ASSERT", #X, __FILE__, __LINE__); \
1.197 + return; \
1.198 + }
1.199 +
1.200 +#define CPPUNIT_ASSERT_EQUAL(X, Y) \
1.201 + if ((X) != (Y)) { \
1.202 + Base::error("CPPUNIT_ASSERT_EQUAL", #X","#Y, __FILE__, __LINE__); \
1.203 + return; \
1.204 + }
1.205 +
1.206 +#define CPPUNIT_ASSERT_DOUBLES_EQUAL(X, Y, Z) \
1.207 + if (!equalDoubles((X), (Y), (Z))) { \
1.208 + Base::error("CPPUNIT_ASSERT_DOUBLES_EQUAL", #X","#Y","#Z, __FILE__, __LINE__); \
1.209 + return; \
1.210 + }
1.211 +
1.212 +#define CPPUNIT_MESSAGE(m) CPPUNIT_NS::TestCase::message(m)
1.213 +
1.214 +#endif