00001
00002
00003
00004
00005
00006 #ifndef _FU_TESTBED_H_
00007 #define _FU_TESTBED_H_
00008
00009 #include "FUtils/FULogFile.h"
00010
00011 class FUTestSuite;
00012
00014
00015
00016 class FUTestBed
00017 {
00018 private:
00019 size_t testPassed, testFailed;
00020 FULogFile fileOut;
00021 string filename;
00022 bool isVerbose;
00023
00024 public:
00025 FUTestBed(const char* filename, bool isVerbose);
00026
00027 inline bool IsVerbose() const { return isVerbose; }
00028
00029 bool RunTestbed(FUTestSuite* headTestSuite);
00030 void RunTestSuite(FUTestSuite* testSuite);
00031 };
00032
00034
00035
00036 class FUTestSuite
00037 {
00038 public:
00039 virtual size_t GetTestCount() = 0;
00040 virtual bool RunTest(FUTestBed& testBed, FULogFile& fileOut, size_t testIndex) = 0;
00041 };
00042
00044
00045
00046 #if defined(_FU_ASSERT_H_) && defined(_DEBUG)
00047 #define FailIf(a) \
00048 if ((a)) { \
00049 fileOut.WriteLine(__FILE__, __LINE__, " Test('%s') failed: %s.", szTestName, #a); \
00050 extern bool skipAsserts; \
00051 if (!skipAsserts) { \
00052 __DEBUGGER_BREAK; \
00053 skipAsserts = ignoreAssert; } \
00054 return false; }
00055
00056 #else // _FU_ASSERT_H_ && _DEBUG
00057
00058 #define FailIf(a) \
00059 if ((a)) { \
00060 fileOut.WriteLine(__FILE__, __LINE__, " Test('%s') failed: %s.", szTestName, #a); \
00061 return false; }
00062
00063 #endif // _FU_ASSERT_H_
00064
00065 #define PassIf(a) FailIf(!(a))
00066
00067 #define Fail { bool b = true; FailIf(b); }
00068
00069 #define TESTSUITE_START(suiteName) \
00070 FUTestSuite* _test##suiteName; \
00071 class FUTestSuite##suiteName : public FUTestSuite \
00072 { \
00073 public: \
00074 FUTestSuite##suiteName() : FUTestSuite() { _test##suiteName = this; } \
00075 bool RunTest(FUTestBed& testBed, FULogFile& fileOut, size_t testIndex) \
00076 { \
00077 switch (testIndex) { \
00078 case ~0u : { \
00079 if (testBed.IsVerbose()) { \
00080 fileOut.WriteLine("Running %s...", #suiteName); \
00081 }
00082
00083 #define TESTSUITE_TEST(test_name) \
00084 } return true; \
00085 case (__COUNTER__): { \
00086 static const char* szTestName = #test_name;
00087
00088 #define TESTSUITE_END \
00089 } return true; \
00090 } \
00091 fileOut.WriteLine(__FILE__, __LINE__, " Test suite implementation error."); \
00092 return false; \
00093 } \
00094 size_t GetTestCount() { return __COUNTER__; } \
00095 } __testSuite;
00096
00097 #define RUN_TESTSUITE(suiteName) \
00098 extern FUTestSuite* _test##suiteName; \
00099 testBed.RunTestSuite(_test##suiteName);
00100
00101 #define RUN_TESTBED(szTestSuiteHead, testPassed) { \
00102 FUTestBed testBed; \
00103 extern FUTestSuite* _test##szTestSuiteHead; \
00104 testPassed = testBed.RunTestbed(_test##szTestSuiteHead); }
00105
00106 #endif // _FU_TESTBED_H_