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 void run (TestResult& result_) override;} \ 67 testGroup##testName##Instance; \ 68 void testGroup##testName##Test::run (TestResult& result_) 73 #define FRIEND_TEST(testGroup, testName) \ 74 friend class testGroup##testName##Test; 80 #define TEST_UNSAFE(testGroup, testName)\ 81 class testGroup##testName##Test : public Test \ 82 { public: testGroup##testName##Test () : Test (#testName "Test", __FILE__, __LINE__, false) {} \ 83 virtual ~testGroup##testName##Test () {} \ 84 void run (TestResult& result_) override;} \ 85 testGroup##testName##Instance; \ 86 void testGroup##testName##Test::run (TestResult& result_) 91 #define TEST_DISABLED(testGroup, testName)\ 92 void testGroup##testName##Test(TestResult& result_, const std::string& name_) 108 #define CHECK(condition)\ 109 { if (!(condition)) \ 110 { result_.addFailure (Failure (name_, __FILE__,__LINE__, #condition)); return; } } 112 #define THROWS_EXCEPTION(condition)\ 114 result_.addFailure (Failure (name_, __FILE__,__LINE__, std::string("Didn't throw: ") + std::string(#condition))); \ 118 #define CHECK_EXCEPTION(condition, exception_name)\ 120 result_.addFailure (Failure (name_, __FILE__,__LINE__, std::string("Didn't throw: ") + std::string(#condition))); \ 122 catch (exception_name&) {} \ 124 result_.addFailure (Failure (name_, __FILE__,__LINE__, std::string("Wrong exception: ") + std::string(#condition) + std::string(", expected: ") + std::string(#exception_name))); \ 127 #define EQUALITY(expected,actual)\ 128 { if (!assert_equal(expected,actual)) \ 129 result_.addFailure(Failure(name_, __FILE__, __LINE__, #expected, #actual)); } 131 #define CHECK_EQUAL(expected,actual)\ 132 { if ((expected) == (actual)) return; result_.addFailure(Failure(name_, __FILE__, __LINE__, std::to_string(expected), std::to_string(actual))); } 134 #define LONGS_EQUAL(expected,actual)\ 135 { long actualTemp = actual; \ 136 long expectedTemp = expected; \ 137 if ((expectedTemp) != (actualTemp)) \ 138 { result_.addFailure (Failure (name_, __FILE__, __LINE__, std::to_string(expectedTemp), \ 139 std::to_string(actualTemp))); return; } } 141 #define DOUBLES_EQUAL(expected,actual,threshold)\ 142 { double actualTemp = actual; \ 143 double expectedTemp = expected; \ 144 if (!std::isfinite(actualTemp) || !std::isfinite(expectedTemp) || fabs ((expectedTemp)-(actualTemp)) > threshold) \ 145 { result_.addFailure (Failure (name_, __FILE__, __LINE__, \ 146 std::to_string((double)expectedTemp), std::to_string((double)actualTemp))); return; } } 150 #define EXPECT(condition)\ 151 { if (!(condition)) \ 152 { result_.addFailure (Failure (name_, __FILE__,__LINE__, #condition)); } } 154 #define EXPECT_LONGS_EQUAL(expected,actual)\ 155 { long actualTemp = actual; \ 156 long expectedTemp = expected; \ 157 if ((expectedTemp) != (actualTemp)) \ 158 { result_.addFailure (Failure (name_, __FILE__, __LINE__, std::to_string(expectedTemp), \ 159 std::to_string(actualTemp))); } } 161 #define EXPECT_DOUBLES_EQUAL(expected,actual,threshold)\ 162 { double actualTemp = actual; \ 163 double expectedTemp = expected; \ 164 if (!std::isfinite(actualTemp) || !std::isfinite(expectedTemp) || fabs ((expectedTemp)-(actualTemp)) > threshold) \ 165 { result_.addFailure (Failure (name_, __FILE__, __LINE__, \ 166 std::to_string((double)expectedTemp), std::to_string((double)actualTemp))); } } 170 { result_.addFailure (Failure (name_, __FILE__, __LINE__,(text))); return; }
bool check(long expected, long actual, TestResult &result, const std::string &fileName, long lineNumber)
virtual void run(TestResult &result)=0
std::string getFilename() const
Test(const std::string &testName)
long getLineNumber() const
std::string getName() const
bool safeCheck_
This is the line line number of the test, rather than the a single check.