ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

cppunit_mini.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2003, 2004
00003  * Zdenek Nemec
00004  *
00005  * This material is provided "as is", with absolutely no warranty expressed
00006  * or implied. Any use is at your own risk.
00007  *
00008  * Permission to use or copy this software for any purpose is hereby granted
00009  * without fee, provided the above notices are retained on all copies.
00010  * Permission to modify the code and to distribute modified code is granted,
00011  * provided the above notices are retained, and a notice that the code was
00012  * modified is included with the above copyright notice.
00013  *
00014  */
00015 
00016 /* $Id$ */
00017 
00018 #ifndef _CPPUNITMPFR_H_
00019 #define _CPPUNITMPFR_H_
00020 
00021 #if 0
00022 #  define CPPUNIT_NS CppUnitMini
00023 #else
00024 #  define CPPUNIT_NS
00025 #endif
00026 
00027 #include <string.h>
00028 
00029 #if 0
00030 namespace CPPUNIT_NS
00031 {
00032 #endif
00033   class Reporter {
00034   public:
00035     virtual ~Reporter() {}
00036     virtual void error(const char * /*macroName*/, const char * /*in_macro*/, const char * /*in_file*/, int /*in_line*/) {}
00037     virtual void message( const char * /*msg*/ ) {}
00038     virtual void progress( const char * /*in_className*/, const char * /*in_testName*/, bool /*ignored*/, bool /* explicit */) {}
00039     virtual void end() {}
00040     virtual void printSummary() {}
00041   };
00042 
00043   class TestFixture {
00044   public:
00045     virtual ~TestFixture() {}
00046 
00048     virtual void setUp() {}
00049 
00051     virtual void tearDown() {}
00052   };
00053 
00054   class TestCase : public TestFixture {
00055   public:
00056     TestCase() { registerTestCase(this); }
00057 
00058     void setUp() { m_failed = false; }
00059     static int run(Reporter *in_reporter = 0, const char *in_testName = "", bool invert = false);
00060     int numErrors() { return m_numErrors; }
00061     static void registerTestCase(TestCase *in_testCase);
00062 
00063     virtual void myRun(const char * /*in_name*/, bool /*invert*/ = false) {}
00064 
00065     virtual void error(const char *in_macroName, const char *in_macro, const char *in_file, int in_line) {
00066       m_failed = true;
00067       if (m_reporter) {
00068         m_reporter->error(in_macroName, in_macro, in_file, in_line);
00069       }
00070     }
00071 
00072     static void message(const char *msg) {
00073       if (m_reporter) {
00074         m_reporter->message(msg);
00075       }
00076     }
00077 
00078     bool equalDoubles(double in_expected, double in_real, double in_maxErr) {
00079       double diff = in_expected - in_real;
00080       if (diff < 0.) {
00081         diff = -diff;
00082       }
00083       return diff < in_maxErr;
00084     }
00085 
00086     virtual void progress(const char *in_className, const char *in_functionName, bool ignored, bool explicitTest) {
00087       ++m_numTests;
00088       if (m_reporter) {
00089         m_reporter->progress(in_className, in_functionName, ignored, explicitTest);
00090       }
00091     }
00092 
00093     bool shouldRunThis(const char *in_desiredTest, const char *in_className, const char *in_functionName,
00094                        bool invert, bool explicit_test, bool &do_progress) {
00095       if ((in_desiredTest) && (in_desiredTest[0] != '\0')) {
00096         do_progress = false;
00097         const char *ptr = strstr(in_desiredTest, "::");
00098         if (ptr) {
00099           bool match = (strncmp(in_desiredTest, in_className, strlen(in_className)) == 0) &&
00100                        (strncmp(ptr + 2, in_functionName, strlen(in_functionName)) == 0);
00101           // Invert shall not make explicit test run:
00102           return invert ? (match ? !match : !explicit_test)
00103                         : match;
00104         }
00105         bool match = (strcmp(in_desiredTest, in_className) == 0);
00106         do_progress = match;
00107         return !explicit_test && (match == !invert);
00108       }
00109       do_progress = true;
00110       return !explicit_test;
00111     }
00112 
00113     void tearDown() {
00114       if (m_failed)
00115         ++m_numErrors;
00116       m_reporter->end();
00117     }
00118 
00119   protected:
00120     static int m_numErrors;
00121     static int m_numTests;
00122 
00123   private:
00124     static TestCase *m_root;
00125     TestCase *m_next;
00126     bool m_failed;
00127 
00128     static Reporter *m_reporter;
00129   };
00130 #if 0
00131 }
00132 #endif
00133 
00134 #if !defined (CPPUNIT_MINI_HIDE_UNUSED_VARIABLE)
00135 #  if defined (_MSC_VER)
00136 #    define CPPUNIT_MINI_HIDE_UNUSED_VARIABLE(v) (v);
00137 #  else
00138 #    define CPPUNIT_MINI_HIDE_UNUSED_VARIABLE(v)
00139 #  endif
00140 #endif
00141 
00142 #define CPPUNIT_TEST_SUITE(X) \
00143   typedef CPPUNIT_NS::TestCase Base; \
00144   virtual void myRun(const char *in_name, bool invert = false) { \
00145     const char *className = #X; CPPUNIT_MINI_HIDE_UNUSED_VARIABLE(className) \
00146     bool ignoring = false; CPPUNIT_MINI_HIDE_UNUSED_VARIABLE(ignoring)
00147 
00148 #if defined CPPUNIT_MINI_USE_EXCEPTIONS
00149 #  define CPPUNIT_TEST_BASE(X, Y) \
00150   { \
00151     bool do_progress; \
00152     bool shouldRun = shouldRunThis(in_name, className, #X, invert, Y, do_progress); \
00153     if (shouldRun || do_progress) { \
00154       setUp(); \
00155       progress(className, #X, ignoring || !shouldRun, !ignoring && Y); \
00156       if (shouldRun && !ignoring) { \
00157         try { \
00158           X(); \
00159         } \
00160         catch(...) { \
00161           Base::error("Test Failed: An Exception was thrown.", #X, __FILE__, __LINE__); \
00162         } \
00163       } \
00164       tearDown(); \
00165     } \
00166   }
00167 #else
00168 #  define CPPUNIT_TEST_BASE(X, Y) \
00169   { \
00170     bool do_progress; \
00171     bool shouldRun = shouldRunThis(in_name, className, #X, invert, Y, do_progress); \
00172     if (shouldRun || do_progress) { \
00173       setUp(); \
00174       progress(className, #X, ignoring || !shouldRun, !ignoring && Y); \
00175       if (shouldRun && !ignoring) \
00176         X(); \
00177       tearDown(); \
00178     } \
00179   }
00180 #endif
00181 
00182 #define CPPUNIT_TEST(X) CPPUNIT_TEST_BASE(X, false)
00183 #define CPPUNIT_EXPLICIT_TEST(X) CPPUNIT_TEST_BASE(X, true)
00184 
00185 #define CPPUNIT_IGNORE \
00186   ignoring = true
00187 
00188 #define CPPUNIT_STOP_IGNORE \
00189   ignoring = false
00190 
00191 #define CPPUNIT_TEST_SUITE_END() }
00192 
00193 #define CPPUNIT_TEST_SUITE_REGISTRATION(X) static X local
00194 
00195 #define CPPUNIT_CHECK(X) \
00196   if (!(X)) { \
00197     Base::error("CPPUNIT_CHECK", #X, __FILE__, __LINE__); \
00198   }
00199 
00200 #define CPPUNIT_ASSERT(X) \
00201   if (!(X)) { \
00202     Base::error("CPPUNIT_ASSERT", #X, __FILE__, __LINE__); \
00203     return; \
00204   }
00205 
00206 #define CPPUNIT_FAIL { \
00207     Base::error("CPPUNIT_FAIL", "", __FILE__, __LINE__); \
00208     return; \
00209   }
00210 
00211 #define CPPUNIT_ASSERT_EQUAL(X, Y) \
00212   if ((X) != (Y)) { \
00213     Base::error("CPPUNIT_ASSERT_EQUAL", #X","#Y, __FILE__, __LINE__); \
00214     return; \
00215   }
00216 
00217 #define CPPUNIT_ASSERT_DOUBLES_EQUAL(X, Y, Z) \
00218   if (!equalDoubles((X), (Y), (Z))) { \
00219     Base::error("CPPUNIT_ASSERT_DOUBLES_EQUAL", #X","#Y","#Z, __FILE__, __LINE__); \
00220     return; \
00221   }
00222 
00223 #define CPPUNIT_MESSAGE(m) CPPUNIT_NS::TestCase::message(m)
00224 
00225 #endif

Generated on Mon May 28 2012 04:35:05 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.