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

@ -42,12 +42,21 @@ test_append_test_log(TestState *s)
// Local Functions
static void
append_to_empty(TestState *)
append_to_empty(TestState *s)
{
TestState test;
print("\tappend to empty\n");
mk_sample_state(&test);
append_test_log(&test, "foo");
// first_log shouldn't be null
print("\t\tfirst_log\n");
chk_ptr_ne(
s,
"ERROR: append_test_log(): append to empty: first_log:",
test.first_log,
0
);
}
//jl

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

View File

@ -48,8 +48,16 @@ extern void chk_int_eq(
extern void chk_ptr_eq(
TestState *,
const char *, // the error context
void *, // the actual value
void * // the expected value
const void *, // the actual value
const void * // the expected value
);
// ensure two pointers are not equal
extern void chk_ptr_ne(
TestState *,
const char *, // the error context
const void *, // the actual value
const void * // the prohibited value
);
//jl