|
1 | 1 | #include "ReportAssert.h" |
2 | 2 | #include "AssertException.h" |
| 3 | +#include "CurrentTest.h" |
| 4 | +#include "TestResults.h" |
| 5 | +#include "TestDetails.h" |
3 | 6 |
|
4 | 7 | namespace UnitTest { |
5 | 8 |
|
| 9 | +namespace |
| 10 | +{ |
| 11 | + bool& AssertExpectedFlag() |
| 12 | + { |
| 13 | + static bool s_assertExpected = false; |
| 14 | + return s_assertExpected; |
| 15 | + } |
| 16 | +} |
| 17 | + |
6 | 18 | void ReportAssert(char const* description, char const* filename, int lineNumber) |
7 | 19 | { |
8 | | - (void)description; |
9 | | - (void)filename; |
10 | | - (void)lineNumber; |
| 20 | + ReportAssertEx(CurrentTest::Results(), CurrentTest::Details(), description, filename, lineNumber); |
| 21 | +} |
| 22 | + |
| 23 | +void ReportAssertEx(TestResults* testResults, |
| 24 | + const TestDetails* testDetails, |
| 25 | + char const* description, |
| 26 | + char const* filename, |
| 27 | + int lineNumber) |
| 28 | +{ |
| 29 | + if (AssertExpectedFlag() == false) |
| 30 | + { |
| 31 | + TestDetails assertDetails(testDetails->testName, testDetails->suiteName, filename, lineNumber); |
| 32 | + testResults->OnTestFailure(assertDetails, description); |
| 33 | + } |
| 34 | + |
| 35 | + ExpectAssert(false); |
11 | 36 |
|
12 | 37 | #ifdef UNITTEST_USE_EXCEPTIONS |
13 | | - throw AssertException(description, filename, lineNumber); |
| 38 | + throw AssertException(); |
14 | 39 | #endif |
15 | 40 | } |
16 | 41 |
|
| 42 | +void ExpectAssert(bool expected) |
| 43 | +{ |
| 44 | + AssertExpectedFlag() = expected; |
| 45 | +} |
| 46 | + |
| 47 | +bool AssertExpected() |
| 48 | +{ |
| 49 | + return AssertExpectedFlag(); |
| 50 | +} |
| 51 | + |
17 | 52 | } |
0 commit comments