source: NonGTP/FCollada/FUtils/FUTestBed.h @ 964

Revision 964, 2.7 KB checked in by igarcia, 18 years ago (diff)
RevLine 
[964]1/*
2        Copyright (C) 2005-2006 Feeling Software Inc.
3        MIT License: http://www.opensource.org/licenses/mit-license.php
4*/
5
6#ifndef _FU_TESTBED_H_
7#define _FU_TESTBED_H_
8
9#include "FUtils/FULogFile.h"
10
11class FUTestSuite;
12
13///////////////////////////////////////////////////////////////////////////////
14// QTestBed class
15//
16class FUTestBed
17{
18private:
19        size_t testPassed, testFailed;
20        FULogFile fileOut;
21        string filename;
22        bool isVerbose;
23
24public:
25        FUTestBed(const char* filename, bool isVerbose);
26
27        inline bool IsVerbose() const { return isVerbose; }
28
29        bool RunTestbed(FUTestSuite* headTestSuite);
30        void RunTestSuite(FUTestSuite* testSuite);
31};
32
33///////////////////////////////////////////////////////////////////////////////
34// QTestSuite class
35//
36class FUTestSuite
37{
38public:
39        virtual size_t GetTestCount() = 0;
40        virtual bool RunTest(FUTestBed& testBed, FULogFile& fileOut, size_t testIndex) = 0;
41};
42
43///////////////////////////////////////////////////////////////////////////////
44// Helpful Macros
45//
46#if defined(_FU_ASSERT_H_) && defined(_DEBUG)
47#define FailIf(a) \
48        if ((a)) { \
49                fileOut.WriteLine(__FILE__, __LINE__, " Test('%s') failed: %s.", szTestName, #a); \
50                extern bool skipAsserts; \
51                if (!skipAsserts) { \
52                        __DEBUGGER_BREAK; \
53                        skipAsserts = ignoreAssert; } \
54                return false; }
55
56#else // _FU_ASSERT_H_ && _DEBUG
57
58#define FailIf(a) \
59        if ((a)) { \
60                fileOut.WriteLine(__FILE__, __LINE__, " Test('%s') failed: %s.", szTestName, #a); \
61                return false; }
62
63#endif // _FU_ASSERT_H_
64
65#define PassIf(a) FailIf(!(a))
66
67#define Fail { bool b = true; FailIf(b); }
68
69#define TESTSUITE_START(suiteName) \
70FUTestSuite* _test##suiteName; \
71class FUTestSuite##suiteName : public FUTestSuite \
72{ \
73public: \
74        FUTestSuite##suiteName() : FUTestSuite() { _test##suiteName = this; } \
75        bool RunTest(FUTestBed& testBed, FULogFile& fileOut, size_t testIndex) \
76        { \
77                switch (testIndex) { \
78                        case ~0u : { \
79                                if (testBed.IsVerbose()) { \
80                                        fileOut.WriteLine("Running %s...", #suiteName); \
81                                }
82
83#define TESTSUITE_TEST(test_name) \
84                        } return true; \
85                case (__COUNTER__): { \
86                        static const char* szTestName = #test_name;
87
88#define TESTSUITE_END \
89                        } return true; \
90                } \
91                fileOut.WriteLine(__FILE__, __LINE__, " Test suite implementation error."); \
92                return false; \
93        } \
94        size_t GetTestCount() { return __COUNTER__; } \
95} __testSuite;
96
97#define RUN_TESTSUITE(suiteName) \
98        extern FUTestSuite* _test##suiteName; \
99        testBed.RunTestSuite(_test##suiteName);
100
101#define RUN_TESTBED(szTestSuiteHead, testPassed) { \
102        FUTestBed testBed; \
103        extern FUTestSuite* _test##szTestSuiteHead; \
104        testPassed = testBed.RunTestbed(_test##szTestSuiteHead); }
105
106#endif // _FU_TESTBED_H_
Note: See TracBrowser for help on using the repository browser.