00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef _FU_TESTBED_H_
00010 #define _FU_TESTBED_H_
00011
00012 #ifndef _FU_LOG_FILE_H_
00013 #include "FUtils/FULogFile.h"
00014 #endif // _FU_LOG_FILE_H_
00015 #ifndef _FU_ASSERT_H_
00016 #include "FUtils/FUAssert.h"
00017 #endif // _FU_ASSERT_H_
00018
00019 class FUTestSuite;
00020
00026 class FCOLLADA_EXPORT FUTestBed
00027 {
00028 private:
00029 size_t testPassed, testFailed;
00030 FULogFile fileOut;
00031 fstring filename;
00032 bool isVerbose;
00033
00034 public:
00040 FUTestBed(const fchar* filename, bool isVerbose);
00041
00044 inline bool IsVerbose() const { return isVerbose; }
00045
00049 FULogFile& GetLogFile() { return fileOut; }
00050
00054 bool RunTestbed(FUTestSuite* headTestSuite);
00055
00059 void RunTestSuite(FUTestSuite* testSuite);
00060 };
00061
00062 extern FCOLLADA_EXPORT bool FUTestBed_skipAsserts;
00063
00070 class FUTestSuite
00071 {
00072 public:
00074 virtual ~FUTestSuite() {}
00075
00083 virtual bool RunTest(FUTestBed& testBed, FULogFile& fileOut, bool& __testSuiteDone, size_t testIndex) = 0;
00084 };
00085
00087
00088
00089 #if defined(_FU_ASSERT_H_) && defined(_DEBUG)
00090 #define FailIf(a) \
00091 if ((a)) { \
00092 fileOut.WriteLine(__FILE__, __LINE__, " Test('%s') failed: %s.", szTestName, #a); \
00093 if (!FUTestBed_skipAsserts) { \
00094 FUBreak; \
00095 FUTestBed_skipAsserts = ignoreAssert; } \
00096 return false; }
00097
00098 #else // _FU_ASSERT_H_ && _DEBUG
00099
00100 #define FailIf(a) \
00101 if ((a)) { \
00102 fileOut.WriteLine(__FILE__, __LINE__, " Test('%s') failed: %s.", szTestName, #a); \
00103 return false; }
00104
00105 #endif // _FU_ASSERT_H_
00106
00107 #define PassIf(a) FailIf(!(a))
00108
00109 #define Fail { bool b = true; FailIf(b); }
00110
00112
00113
00114
00115 #ifdef ENABLE_TEST
00116 #define TESTSUITE_START(suiteName) \
00117 FUTestSuite* _test##suiteName; \
00118 static class FUTestSuite##suiteName : public FUTestSuite \
00119 { \
00120 public: \
00121 FUTestSuite##suiteName() : FUTestSuite() { _test##suiteName = this; } \
00122 virtual ~FUTestSuite##suiteName() {} \
00123 virtual bool RunTest(FUTestBed& testBed, FULogFile& fileOut, bool& __testSuiteDone, size_t testIndex) \
00124 { \
00125 switch (testIndex) { \
00126 case ~0 : { \
00127 if (testBed.IsVerbose()) { \
00128 fileOut.WriteLine("Running %s...", #suiteName); \
00129 }
00130
00131 #define TESTSUITE_TEST(testIndex, testName) \
00132 } return true; \
00133 case testIndex: { \
00134 static const char* szTestName = #testName;
00135
00136 #define TESTSUITE_END \
00137 } return true; \
00138 default: { __testSuiteDone = true; return true; } \
00139 } \
00140 fileOut.WriteLine(__FILE__, __LINE__, " Test suite implementation error."); \
00141 return false; \
00142 } \
00143 } __testSuite;
00144
00145 #define RUN_TESTSUITE(suiteName) \
00146 extern FUTestSuite* _test##suiteName; \
00147 testBed.RunTestSuite(_test##suiteName);
00148
00149 #define RUN_TESTBED(testBedObject, szTestSuiteHead, testPassed) { \
00150 extern FUTestSuite* _test##szTestSuiteHead; \
00151 testPassed = testBedObject.RunTestbed(_test##szTestSuiteHead); }
00152
00153 #else // ENABLE_TEST
00154
00155
00156 #define TESTSUITE_START(suiteName) \
00157 extern FUTestSuite* _test##suiteName = NULL; \
00158 inline bool __testCode##suiteName(FULogFile& fileOut, const char* szTestName) { { fileOut; szTestName;
00159 #define TESTSUITE_TEST(testIndex, testName) } {
00160 #define TESTSUITE_END } return true; }
00161 #define RUN_TESTSUITE(suiteName)
00162 #define RUN_TESTBED(testBedObject, szTestSuiteHead, testPassed) testPassed = true;
00163
00164 #endif
00165
00166 #endif // _FU_TESTBED_H_