Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #491, Add UT macros #695

Merged
merged 1 commit into from
May 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 142 additions & 0 deletions fsw/cfe-core/unit-test/ut_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -693,3 +693,145 @@ uint32 UT_PrintfIsInHistory(const char *MsgToSearchFor)
return UT_GetMessageCount(MsgToSearchFor, &UT_PrintfBuffer, UT_StrCmpFormatStr);
}

int32 TestStat;

void UT_STARTBLOCK_impl(const char *FileName, int LineNum, const char *TestName)
{
#ifdef VERBOSE
char cMsg[UT_MAX_MESSAGE_LENGTH];
snprintf(cMsg, UT_MAX_MESSAGE_LENGTH, "%s (%s:%d) Start Block", TestName, FileName, LineNum);
UT_Text(cMsg);
#endif /* VERBOSE */
}

void UT_START_impl(const char *FileName, int LineNum, const char *TestName)
{
#ifdef VERBOSE
char cMsg[UT_MAX_MESSAGE_LENGTH];
snprintf(cMsg, UT_MAX_MESSAGE_LENGTH, "%s (%s:%d) Start", TestName, FileName, LineNum);
UT_Text(cMsg);
#endif /* VERBOSE */

TestStat = CFE_PASS;
}

void UT_REPORT_impl(const char *FileName, int LineNum, const char *TestName)
{
UT_Report(FileName, LineNum, TestStat, TestName, "Report");
}

bool UT_SETUP_impl(const char *FileName, int LineNum, const char *TestName, const char *FnName, int32 FnRet)
{
char cMsg[UT_MAX_MESSAGE_LENGTH];

if(FnRet != CFE_SUCCESS)
{
snprintf(cMsg, UT_MAX_MESSAGE_LENGTH, "%s (%s:%d) Setup failed (%s returned %ld)",
TestName, FileName, LineNum, FnName, (long int)FnRet);
UT_Text(cMsg);
TestStat = CFE_FAIL;
return false;
}
return true;
}

bool UT_ASSERT_impl(const char *FileName, int LineNum, const char *TestName, const char *FnName, int32 FnRet)
{
char cMsg[UT_MAX_MESSAGE_LENGTH];

if(FnRet != CFE_SUCCESS)
{
snprintf(cMsg, UT_MAX_MESSAGE_LENGTH, "%s (%s:%d) Assert failed (%s returned %ld)",
TestName, FileName, LineNum, FnName, (long int)FnRet);
UT_Text(cMsg);
TestStat = CFE_FAIL;
return false;
}
return true;
}

bool UT_ASSERT_EQ_impl(const char *FileName, int LineNum, const char *TestName,
const char *FnName, int32 FnRet, const char *ExpName, int32 Exp)
{
char cMsg[UT_MAX_MESSAGE_LENGTH];

if(FnRet != Exp)
{
snprintf(cMsg, UT_MAX_MESSAGE_LENGTH, "%s (%s:%d) Assert failed (%s [%ld] != %s[%ld])",
TestName, FileName, LineNum, FnName, (long int)FnRet, ExpName, (long int)Exp);
UT_Text(cMsg);
TestStat = CFE_FAIL;
return false;
}
return true;
}

bool UT_ASSERT_TRUE_impl(const char *FileName, int LineNum, const char *TestName,
const char *ExpName, bool Exp)
{
char cMsg[UT_MAX_MESSAGE_LENGTH];

if(!Exp)
{
snprintf(cMsg, UT_MAX_MESSAGE_LENGTH, "%s (%s:%d) Assert failed (%s)",
TestName, FileName, LineNum, ExpName);
UT_Text(cMsg);
TestStat = CFE_FAIL;
return false;
}
return true;
}

bool UT_EVTCNT_impl(const char *FileName, int LineNum, const char *TestName, int32 CntExp)
{
char cMsg[UT_MAX_MESSAGE_LENGTH];

int32 CntSent = UT_GetNumEventsSent();
if(CntSent != CntExp)
{
snprintf(cMsg, UT_MAX_MESSAGE_LENGTH, "%s (%s:%d) Event count (sent: %ld != expected: %ld)",
TestName, FileName, LineNum, (long int)CntSent, (long int)CntExp);
UT_Text(cMsg);
TestStat = CFE_FAIL;
return false;
}
return true;
}

bool UT_EVTSENT_impl(const char *FileName, int LineNum, const char *TestName, const char *EvtName, int32 EvtId)
{
char cMsg[UT_MAX_MESSAGE_LENGTH];

if(!UT_EventIsInHistory(EvtId))
{
snprintf(cMsg, UT_MAX_MESSAGE_LENGTH, "%s (%s:%d) Event not sent (%s [%ld])",
TestName, FileName, LineNum, EvtName, (long int)EvtId);
UT_Text(cMsg);
TestStat = CFE_FAIL;
return false;
}
return true;
}

bool UT_TEARDOWN_impl(const char *FileName, int LineNum, const char *TestName, const char *FnName, int32 FnRet)
{
char cMsg[UT_MAX_MESSAGE_LENGTH];

if(FnRet != CFE_SUCCESS)
{
snprintf(cMsg, UT_MAX_MESSAGE_LENGTH, "%s (%s:%d) Teardown failed (%s returned %ld)",
TestName, FileName, LineNum, FnName, (long int)FnRet);
UT_Text(cMsg);
TestStat = CFE_FAIL;
return false;
}
return true;
}

void UT_ENDBLOCK_impl(const char *FileName, int LineNum, const char *TestName)
{
#ifdef VERBOSE
snprintf(cMsg, UT_MAX_MESSAGE_LENGTH, "%s (%s:%d) End Block", TestName, FileName, LineNum);
UT_Text();
#endif /* VERBOSE */
}
Loading