ensure first_log isn't null after append

This commit is contained in:
jlamothe
2023-11-11 21:36:05 +00:00
parent c0f28d41b0
commit 9f4a51d8c7
3 changed files with 52 additions and 5 deletions

View File

@@ -110,8 +110,9 @@ static void chk_TestState_ptr_eq(
const TestState *
);
decl_test(chk_int_eq_test);
decl_test(chk_ptr_eq_test);
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
// Public Functions
@@ -179,6 +180,24 @@ chk_ptr_eq(
s->ptr = old_ptr;
}
void
chk_ptr_ne(
TestState *s,
const char *context,
const void *actual,
const void *prohibited
)
{
void *old_ptr = s->ptr;
ComparePtrs cp;
cp.context = context;
cp.chk_val = actual;
cp.ref_val = prohibited;
s->ptr = &cp;
run_test(s, chk_ptr_ne_test);
s->ptr = old_ptr;
}
// Local Functions
static void
@@ -319,4 +338,15 @@ def_test(chk_ptr_eq_test, s)
return test_failure;
}
def_test(chk_ptr_ne_test, s)
{
const ComparePtrs *cp = s->ptr;
if (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, "\tcannot be: 0x%x", cp->ref_val);
append_test_log(s, str);
return test_failure;
}
//jl