fprime/Fw/Test/UnitTestAssert.cpp
M Starch b76d8c9a0c
Update/types refactor as constants (#1623)
* lestarch: adding logical types implementation into Linux/StandardTypes.hpp

* lestarch: removing VxWorks StandardTypes from repository

* updated fprime types for correct compilation with vxworks and baremetal

* lestarch: refactoring types and configuration header w.r.t type design

* lestarch: replacing usages of AssertArg with FwAssertArgType

* lestarch: missspelled configuration

* lestarch: minor compilation fixes

* lestarch: renaming StandardTypes.hpp -> PlatformTypes.hpp

* lestarch: updating PRI tokens

* lestarch: replacing BasicTypes.hpp includes with FpConfig.hpp

* lestarch: UT and compilation fixes for types refactor

* lestarch: sp

* lestarch: fixing RPI issues in PassiveConsoleTextLogger

* lestarch: converting RPI build to debug

* lestarch: removing duplicate config imports

* lestarch: fixing documentation

* lestarch: fixing up multiple definitions and RPI compilation problems

* lestarch: reverting debug build

* lestarch: reverting platform types to class-based constants

* lestarch: reworking basic types

* lestarch: configured types refactor into classes

* lestarch: fixing bugs with static constants in classes

* lestarch: fixing platform types spelling and documentation

* lestarch: adding include guards to types headers

Co-authored-by: Kevin F Ortega <kevin.f.ortega@jpl.nasa.gov>
2022-08-18 13:25:56 -07:00

113 lines
2.8 KiB
C++

/*
* UnitTestAssert.cpp
*
* Created on: Feb 8, 2016
* Author: tcanham
* Revised July 2020
* Author: bocchino
*/
#include <Fw/Test/UnitTestAssert.hpp>
#include <cstdio>
#include <cstring>
namespace Test {
#if FW_ASSERT_LEVEL == FW_FILEID_ASSERT
const UnitTestAssert::File UnitTestAssert::fileInit = 0;
#else
const UnitTestAssert::File UnitTestAssert::fileInit = "";
#endif
UnitTestAssert::UnitTestAssert() :
m_file(fileInit),
m_lineNo(0),
m_numArgs(0),
m_arg1(0),
m_arg2(0),
m_arg3(0),
m_arg4(0),
m_arg5(0),
m_arg6(0),
m_assertFailed(false)
{
// register this hook
Fw::AssertHook::registerHook();
}
UnitTestAssert::~UnitTestAssert() {
// deregister the hook
Fw::AssertHook::deregisterHook();
}
void UnitTestAssert::doAssert() {
this->m_assertFailed = true;
#if FW_ASSERT_LEVEL == FW_FILEID_ASSERT
(void)fprintf(stderr,"Assert File: 0x%x, Line: %" PRI_FwAssertArgType "\n", this->m_file, this->m_lineNo);
#else
(void)fprintf(stderr,"Assert File: %s, Line: %" PRI_FwAssertArgType "\n", this->m_file.toChar(), this->m_lineNo);
#endif
}
void UnitTestAssert::reportAssert(
FILE_NAME_ARG file,
NATIVE_UINT_TYPE lineNo,
NATIVE_UINT_TYPE numArgs,
FwAssertArgType arg1,
FwAssertArgType arg2,
FwAssertArgType arg3,
FwAssertArgType arg4,
FwAssertArgType arg5,
FwAssertArgType arg6
) {
#if FW_ASSERT_LEVEL == FW_FILEID_ASSERT
this->m_file = file;
#else
this->m_file = reinterpret_cast<const char*>(file);
#endif
this->m_lineNo = lineNo;
this->m_numArgs = numArgs;
this->m_arg1 = arg1;
this->m_arg2 = arg2;
this->m_arg3 = arg3;
this->m_arg4 = arg4;
this->m_arg5 = arg5;
this->m_arg6 = arg6;
}
void UnitTestAssert::retrieveAssert(
File& file,
NATIVE_UINT_TYPE& lineNo,
NATIVE_UINT_TYPE& numArgs,
FwAssertArgType& arg1,
FwAssertArgType& arg2,
FwAssertArgType& arg3,
FwAssertArgType& arg4,
FwAssertArgType& arg5,
FwAssertArgType& arg6
) const {
file = this->m_file;
lineNo = this->m_lineNo;
numArgs = this->m_numArgs;
arg1 = this->m_arg1;
arg2 = this->m_arg2;
arg3 = this->m_arg3;
arg4 = this->m_arg4;
arg5 = this->m_arg5;
arg6 = this->m_arg6;
}
bool UnitTestAssert::assertFailed() const {
return this->m_assertFailed;
}
void UnitTestAssert::clearAssertFailure() {
this->m_assertFailed = false;
}
} /* namespace Test */