[go: up one dir, main page]

Menu

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

Download this file

110 lines (77 with data), 2.9 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
#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:
CTest(const CSimpleString& testName);
virtual ~CTest();
virtual void run (CTestResult& result) = 0;
void setNext(CTest *test);
CTest* getNext () const;
const CSimpleString& getName() const;
protected:
/**
*
* @param
* @return true if the test was passed, false otherwise
*/
bool check( long expected, long actual, CTestResult& result
, const CSimpleString& fileName, long lineNumber);
/**
*
* @param
* @return
*/
bool check( const CSimpleString& expected, const CSimpleString& actual
, CTestResult& result, const CSimpleString& fileName
, long lineNumber);
/// name of this test
CSimpleString mName;
/// pointer to this test's next test in execution list
CTest* mpNext;
};
#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__