| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * UnitTestAssert.cpp | ||
| 3 | * | ||
| 4 | * Created on: Feb 8, 2016 | ||
| 5 | * Author: tcanham | ||
| 6 | * Revised July 2020 | ||
| 7 | * Author: bocchino | ||
| 8 | */ | ||
| 9 | |||
| 10 | #include <Fw/Test/UnitTestAssert.hpp> | ||
| 11 | #include <cstdio> | ||
| 12 | #include <cstring> | ||
| 13 | |||
| 14 | namespace Test { | ||
| 15 | |||
| 16 | #if FW_ASSERT_LEVEL == FW_FILEID_ASSERT | ||
| 17 | const UnitTestAssert::File UnitTestAssert::fileInit = 0; | ||
| 18 | #else | ||
| 19 | const UnitTestAssert::File UnitTestAssert::fileInit = ""; | ||
| 20 | #endif | ||
| 21 | |||
| 22 | ✗ | UnitTestAssert::UnitTestAssert() | |
| 23 | ✗ | : m_file(fileInit), | |
| 24 | ✗ | m_lineNo(0), | |
| 25 | ✗ | m_numArgs(0), | |
| 26 | ✗ | m_arg1(0), | |
| 27 | ✗ | m_arg2(0), | |
| 28 | ✗ | m_arg3(0), | |
| 29 | ✗ | m_arg4(0), | |
| 30 | ✗ | m_arg5(0), | |
| 31 | ✗ | m_arg6(0), | |
| 32 | ✗ | m_assertFailed(false) { | |
| 33 | // register this hook | ||
| 34 | ✗ | Fw::AssertHook::registerHook(); | |
| 35 | ✗ | } | |
| 36 | |||
| 37 | ✗ | UnitTestAssert::~UnitTestAssert() { | |
| 38 | // deregister the hook | ||
| 39 | ✗ | Fw::AssertHook::deregisterHook(); | |
| 40 | ✗ | } | |
| 41 | |||
| 42 | ✗ | void UnitTestAssert::doAssert() { | |
| 43 | ✗ | this->m_assertFailed = true; | |
| 44 | #if FW_ASSERT_LEVEL == FW_FILEID_ASSERT | ||
| 45 | (void)fprintf(stderr, "Assert: 0x%" PRIx32 ":%" PRI_FwSizeType "\n", this->m_file, this->m_lineNo); | ||
| 46 | #else | ||
| 47 | ✗ | (void)fprintf(stderr, "Assert: %s:%" PRI_FwSizeType "\n", this->m_file.toChar(), this->m_lineNo); | |
| 48 | #endif | ||
| 49 | ✗ | } | |
| 50 | |||
| 51 | ✗ | void UnitTestAssert::reportAssert(FILE_NAME_ARG file, | |
| 52 | FwSizeType lineNo, | ||
| 53 | FwSizeType numArgs, | ||
| 54 | FwAssertArgType arg1, | ||
| 55 | FwAssertArgType arg2, | ||
| 56 | FwAssertArgType arg3, | ||
| 57 | FwAssertArgType arg4, | ||
| 58 | FwAssertArgType arg5, | ||
| 59 | FwAssertArgType arg6) { | ||
| 60 | #if FW_ASSERT_LEVEL == FW_FILEID_ASSERT | ||
| 61 | this->m_file = file; | ||
| 62 | #else | ||
| 63 | ✗ | this->m_file = reinterpret_cast<const char*>(file); | |
| 64 | #endif | ||
| 65 | ✗ | this->m_lineNo = lineNo; | |
| 66 | ✗ | this->m_numArgs = numArgs; | |
| 67 | ✗ | this->m_arg1 = arg1; | |
| 68 | ✗ | this->m_arg2 = arg2; | |
| 69 | ✗ | this->m_arg3 = arg3; | |
| 70 | ✗ | this->m_arg4 = arg4; | |
| 71 | ✗ | this->m_arg5 = arg5; | |
| 72 | ✗ | this->m_arg6 = arg6; | |
| 73 | ✗ | } | |
| 74 | |||
| 75 | ✗ | void UnitTestAssert::retrieveAssert(File& file, | |
| 76 | FwSizeType& lineNo, | ||
| 77 | FwSizeType& numArgs, | ||
| 78 | FwAssertArgType& arg1, | ||
| 79 | FwAssertArgType& arg2, | ||
| 80 | FwAssertArgType& arg3, | ||
| 81 | FwAssertArgType& arg4, | ||
| 82 | FwAssertArgType& arg5, | ||
| 83 | FwAssertArgType& arg6) const { | ||
| 84 | ✗ | file = this->m_file; | |
| 85 | ✗ | lineNo = this->m_lineNo; | |
| 86 | ✗ | numArgs = this->m_numArgs; | |
| 87 | ✗ | arg1 = this->m_arg1; | |
| 88 | ✗ | arg2 = this->m_arg2; | |
| 89 | ✗ | arg3 = this->m_arg3; | |
| 90 | ✗ | arg4 = this->m_arg4; | |
| 91 | ✗ | arg5 = this->m_arg5; | |
| 92 | ✗ | arg6 = this->m_arg6; | |
| 93 | ✗ | } | |
| 94 | |||
| 95 | ✗ | bool UnitTestAssert::assertFailed() const { | |
| 96 | ✗ | return this->m_assertFailed; | |
| 97 | } | ||
| 98 | |||
| 99 | ✗ | void UnitTestAssert::clearAssertFailure() { | |
| 100 | ✗ | this->m_assertFailed = false; | |
| 101 | ✗ | } | |
| 102 | |||
| 103 | } /* namespace Test */ | ||
| 104 |