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

@ -58,6 +58,15 @@ append_to_empty(TestState *s)
0 0
); );
// log should say "foo"
print("\t\t\ttext\n");
chk_str_eq(
s,
"ERROR: append_test_log(): append to empty: first_log: text:",
test.first_log->text,
"foo"
);
// last_log should match first_log // last_log should match first_log
print("\t\tlast_log\n"); print("\t\tlast_log\n");
chk_ptr_eq( chk_ptr_eq(

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_int_eq_test); // ensure ints are equal
decl_test(chk_ptr_eq_test); // ensure pointers 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_ptr_ne_test); // ensure pointers are not equal
decl_test(chk_str_eq_test); // ensure strings are equal
// Public Functions // Public Functions
@ -198,6 +199,24 @@ chk_ptr_ne(
s->ptr = old_ptr; 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 // Local Functions
static void static void
@ -349,4 +368,17 @@ def_test(chk_ptr_ne_test, s)
return test_failure; 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 //jl

View File

@ -60,4 +60,12 @@ extern void chk_ptr_ne(
const void * // the prohibited value const void * // the prohibited value
); );
// ensure two strings are equal
extern void chk_str_eq(
TestState *,
const char *, // the error context
const char *, // the actual value
const char * // the expected value
);
//jl //jl