Skip to content

Commit

Permalink
Fix nasa#59, replace direct ref to ArgPtr with macro
Browse files Browse the repository at this point in the history
The UT_Hook_GetArgValueByName macro provided by UT assert is the preferred
way to get an argument in the current version.  Reading the pointer directly
is not advised as it depends on how the stub was actually implemented,
whereas the macro should produce consistent results.
  • Loading branch information
jphickey committed Apr 16, 2021
1 parent 1b9eea3 commit 0b94235
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion unit-test/coveragetest/coveragetest_sample_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,15 @@ static int32 UT_printf_hook(void *UserObj, int32 StubRetcode, uint32 CallCount,
va_list va)
{
SAMPLE_LIB_Function_TestState_t *State = UserObj;
const char *string = UT_Hook_GetArgValueByName(Context, "string", const char *);

/*
* The OS_printf() stub passes format string as the argument
* This confirms the whole string; normally this level of test
* detail would not be needed, but this serves as an example
* of how it can be done.
*/
if (Context->ArgCount > 0 && strcmp(Context->ArgPtr[0], "SAMPLE_LIB_Function called, buffer=\'%s\'\n") == 0)
if (Context->ArgCount > 0 && strcmp(string, "SAMPLE_LIB_Function called, buffer=\'%s\'\n") == 0)
{
State->format_string_valid = true;

Expand Down

0 comments on commit 0b94235

Please sign in to comment.