#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__