1 #include "ReportAssert.h"
2 #include "ReportAssertImpl.h"
3 #include "AssertException.h"
4 #include "CurrentTest.h"
5 #include "TestResults.h"
6 #include "TestDetails.h"
7
8 #ifdef UNITTEST_NO_EXCEPTIONS
9 #include "ReportAssertImpl.h"
10 #endif
11
12 namespace UnitTest {
13
14 namespace
15 {
AssertExpectedFlag()16 bool& AssertExpectedFlag()
17 {
18 static bool s_assertExpected = false;
19 return s_assertExpected;
20 }
21 }
22
ReportAssert(char const * description,char const * filename,int lineNumber)23 UNITTEST_LINKAGE void ReportAssert(char const* description, char const* filename, int lineNumber)
24 {
25 Detail::ReportAssertEx(CurrentTest::Results(), CurrentTest::Details(),
26 description, filename, lineNumber);
27 }
28
29 namespace Detail {
30
31 #ifdef UNITTEST_NO_EXCEPTIONS
GetAssertJmpBuf()32 UNITTEST_JMPBUF* GetAssertJmpBuf()
33 {
34 static UNITTEST_JMPBUF s_jmpBuf;
35 return &s_jmpBuf;
36 }
37 #endif
38
ReportAssertEx(TestResults * testResults,const TestDetails * testDetails,char const * description,char const * filename,int lineNumber)39 UNITTEST_LINKAGE void ReportAssertEx(TestResults* testResults,
40 const TestDetails* testDetails,
41 char const* description,
42 char const* filename,
43 int lineNumber)
44 {
45 if (AssertExpectedFlag() == false)
46 {
47 TestDetails assertDetails(testDetails->testName, testDetails->suiteName, filename, lineNumber);
48 testResults->OnTestFailure(assertDetails, description);
49 }
50
51 ExpectAssert(false);
52
53 #ifndef UNITTEST_NO_EXCEPTIONS
54 throw AssertException();
55 #else
56 UNITTEST_JUMP_TO_ASSERT_JUMP_TARGET();
57 #endif
58 }
59
ExpectAssert(bool expected)60 UNITTEST_LINKAGE void ExpectAssert(bool expected)
61 {
62 AssertExpectedFlag() = expected;
63 }
64
AssertExpected()65 UNITTEST_LINKAGE bool AssertExpected()
66 {
67 return AssertExpectedFlag();
68 }
69
70 }}
71