26 #include <boost/lexical_cast.hpp> 33 Test (
const std::string& testName);
34 Test (
const std::string& testName,
const std::string&
filename,
long lineNumber,
bool safeCheck);
50 bool check (
const std::string& expected,
const std::string& actual,
TestResult& result,
const std::string& fileName,
long lineNumber);
63 #define TEST(testGroup, testName)\ 64 class testGroup##testName##Test : public Test \ 65 { public: testGroup##testName##Test () : Test (#testName "Test", __FILE__, __LINE__, true) {} \ 66 virtual ~testGroup##testName##Test () {};\ 67 void run (TestResult& result_) override;} \ 68 testGroup##testName##Instance; \ 69 void testGroup##testName##Test::run (TestResult& result_) 74 #define FRIEND_TEST(testGroup, testName) \ 75 friend class testGroup##testName##Test; 81 #define TEST_UNSAFE(testGroup, testName)\ 82 class testGroup##testName##Test : public Test \ 83 { public: testGroup##testName##Test () : Test (#testName "Test", __FILE__, __LINE__, false) {} \ 84 virtual ~testGroup##testName##Test () {};\ 85 void run (TestResult& result_) override;} \ 86 testGroup##testName##Instance; \ 87 void testGroup##testName##Test::run (TestResult& result_) 92 #define TEST_DISABLED(testGroup, testName)\ 93 void testGroup##testName##Test(TestResult& result_, const std::string& name_) 109 #define CHECK(condition)\ 110 { if (!(condition)) \ 111 { result_.addFailure (Failure (name_, __FILE__,__LINE__, #condition)); return; } } 113 #define THROWS_EXCEPTION(condition)\ 115 result_.addFailure (Failure (name_, __FILE__,__LINE__, std::string("Didn't throw: ") + boost::lexical_cast<std::string>(#condition))); \ 119 #define CHECK_EXCEPTION(condition, exception_name)\ 121 result_.addFailure (Failure (name_, __FILE__,__LINE__, std::string("Didn't throw: ") + boost::lexical_cast<std::string>(#condition))); \ 123 catch (exception_name&) {} \ 125 result_.addFailure (Failure (name_, __FILE__,__LINE__, std::string("Wrong exception: ") + boost::lexical_cast<std::string>(#condition) + boost::lexical_cast<std::string>(", expected: ") + boost::lexical_cast<std::string>(#exception_name))); \ 128 #define EQUALITY(expected,actual)\ 129 { if (!assert_equal(expected,actual)) \ 130 result_.addFailure(Failure(name_, __FILE__, __LINE__, #expected, #actual)); } 132 #define CHECK_EQUAL(expected,actual)\ 133 { if ((expected) == (actual)) return; result_.addFailure(Failure(name_, __FILE__, __LINE__, boost::lexical_cast<std::string>(expected), boost::lexical_cast<std::string>(actual))); } 135 #define LONGS_EQUAL(expected,actual)\ 136 { long actualTemp = actual; \ 137 long expectedTemp = expected; \ 138 if ((expectedTemp) != (actualTemp)) \ 139 { result_.addFailure (Failure (name_, __FILE__, __LINE__, boost::lexical_cast<std::string>(expectedTemp), \ 140 boost::lexical_cast<std::string>(actualTemp))); return; } } 142 #define DOUBLES_EQUAL(expected,actual,threshold)\ 143 { double actualTemp = actual; \ 144 double expectedTemp = expected; \ 145 if (!std::isfinite(actualTemp) || !std::isfinite(expectedTemp) || fabs ((expectedTemp)-(actualTemp)) > threshold) \ 146 { result_.addFailure (Failure (name_, __FILE__, __LINE__, \ 147 boost::lexical_cast<std::string>((double)expectedTemp), boost::lexical_cast<std::string>((double)actualTemp))); return; } } 151 #define EXPECT(condition)\ 152 { if (!(condition)) \ 153 { result_.addFailure (Failure (name_, __FILE__,__LINE__, #condition)); } } 155 #define EXPECT_LONGS_EQUAL(expected,actual)\ 156 { long actualTemp = actual; \ 157 long expectedTemp = expected; \ 158 if ((expectedTemp) != (actualTemp)) \ 159 { result_.addFailure (Failure (name_, __FILE__, __LINE__, boost::lexical_cast<std::string>(expectedTemp), \ 160 boost::lexical_cast<std::string>(actualTemp))); } } 162 #define EXPECT_DOUBLES_EQUAL(expected,actual,threshold)\ 163 { double actualTemp = actual; \ 164 double expectedTemp = expected; \ 165 if (!std::isfinite(actualTemp) || !std::isfinite(expectedTemp) || fabs ((expectedTemp)-(actualTemp)) > threshold) \ 166 { result_.addFailure (Failure (name_, __FILE__, __LINE__, \ 167 boost::lexical_cast<std::string>((double)expectedTemp), boost::lexical_cast<std::string>((double)actualTemp))); } } 171 { result_.addFailure (Failure (name_, __FILE__, __LINE__,(text))); return; } std::string getName() const
bool check(long expected, long actual, TestResult &result, const std::string &fileName, long lineNumber)
long getLineNumber() const
virtual void run(TestResult &result)=0
std::string getFilename() const
Test(const std::string &testName)
bool safeCheck_
This is the line line number of the test, rather than the a single check.