ensure latest log text is correct when appended

This commit is contained in:
jlamothe
2023-11-11 22:53:04 +00:00
parent 63f0bd73e4
commit 3393c3b9af
3 changed files with 49 additions and 0 deletions

View File

@@ -113,6 +113,7 @@ static void chk_TestState_ptr_eq(
decl_test(chk_int_eq_test); // ensure ints are equal
decl_test(chk_ptr_eq_test); // ensure pointers are equal
decl_test(chk_ptr_ne_test); // ensure pointers are not equal
decl_test(chk_str_eq_test); // ensure strings are equal
// Public Functions
@@ -198,6 +199,24 @@ chk_ptr_ne(
s->ptr = old_ptr;
}
void
chk_str_eq(
TestState *s,
const char *context,
const char *actual,
const char *expected
)
{
void *old_ptr = s->ptr;
ComparePtrs cp;
cp.context = context;
cp.chk_val = actual;
cp.ref_val = expected;
s->ptr = &cp;
run_test(s, chk_str_eq_test);
s->ptr = old_ptr;
}
// Local Functions
static void
@@ -349,4 +368,17 @@ def_test(chk_ptr_ne_test, s)
return test_failure;
}
def_test(chk_str_eq_test, s)
{
const ComparePtrs *cp = s->ptr;
if (!strcmp(cp->chk_val, cp->ref_val)) return test_success;
char str[STR_BUF_SIZE];
append_test_log(s, cp->context);
snprintf(str, STR_BUF_SIZE, "\texpected: %s", cp->ref_val);
append_test_log(s, str);
snprintf(str, STR_BUF_SIZE, "\tactual: %s", cp->ref_val);
append_test_log(s, str);
return test_failure;
}
//jl