[go: up one dir, main page]

Menu

[r7]: / development / cut / src / CTest.h  Maximize  Restore  History

Download this file

137 lines (100 with data), 3.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#ifndef __CTEST_H__
#define __CTEST_H__
/******************************************************************************
** NOTE: All the source code in this file is published under the license,
** which is defined under <Project_Root>/license.
** The work under cut is based on Michael Feathers' CppUnitLite. Please
** note the special section within the license related to CppUnitLite.
**
** @author ROder
**
** @description Encapsulating tests and holding the test macros.
**
** @ingroup coal/cut
**
** @year 2006
******************************************************************************/
#include <cmath>
#include <stdio.h>
#include <CSimpleString.h>
class CTestResult;
class CTest
{
public:
/** constructor
*
* @param testName the test's name
*/
CTest(const CSimpleString& testName);
/// destructor
virtual ~CTest();
/** pure virtual function which is overwritten and implemented with
* the actual test cases
*
* @param result a reference to be filled with test results
*/
virtual void run (CTestResult& result) = 0;
/** sets the next test in once linked list of tests
*
* @param test the next test in list
*/
void setNext(CTest* test);
/** gets next test in list
*
* @return pointer to next test
*/
CTest* getNext() const;
/** function to get the test's name
*
* @return the test's name
*/
const CSimpleString& getName() const;
protected:
/// name of this test
CSimpleString mName;
/// pointer to this test's next test in execution list
CTest* mpNext;
};
// inline
inline
CTest* CTest::getNext() const
{
return mpNext;
}
inline
void CTest::setNext(CTest* test)
{
mpNext = test;
}
inline
const CSimpleString& CTest::getName() const
{
return mName;
}
#define TEST(testName, testGroup)\
class testGroup##testName##Test : public CTest \
{ public: testGroup##testName##Test() : CTest (#testName "Test") {} \
void run (CTestResult& result_); } \
testGroup##testName##Instance; \
void testGroup##testName##Test::run(CTestResult& result_)
#define CHECK(condition)\
{ if (!(condition)) \
{ result_.addFailure (CFailure (mName, __FILE__,__LINE__, #condition)); return; } }
#define CHECK_EQUAL(expected,actual)\
{ if ((expected) == (actual)) return; result_.addFailure(CFailure(name_ \
, __FILE__, __LINE__, StringFrom(expected), StringFrom(actual))); }
#define LONGS_EQUAL(expected,actual)\
{ long actualTemp = actual; \
long expectedTemp = expected; \
if ((expectedTemp) != (actualTemp)) \
{ result_.addFailure (CFailure (mName, __FILE__, __LINE__, StringFrom(expectedTemp) \
, StringFrom(actualTemp))); return; } }
#define DOUBLES_EQUAL(expected,actual,threshold)\
{ double actualTemp = actual; \
double expectedTemp = expected; \
if (fabs ((expectedTemp)-(actualTemp)) > threshold) \
{ result_.addFailure (CFailure (mName, __FILE__, __LINE__, \
StringFrom((double)expectedTemp), StringFrom((double)actualTemp))); return; } }
#define FAIL(text) \
{ result_.addFailure (CFailure (mName, __FILE__, __LINE__,(text))); return; }
#endif // __CTEST_H__