more thorough testing of append_test_log()

This commit is contained in:
jlamothe 2023-11-21 22:45:56 +00:00
parent cb3788cf02
commit 00ffef2f0a

View File

@ -39,12 +39,14 @@ struct LogData
// Local Prototypes
static void append_to_empty(TestState *);
static void chk_empty_first(TestState *, void *);
static void append_to_existing(TestState *);
static void missing_last(TestState *);
static void missing_first(TestState *);
static void null_message(TestState *);
static TestResult null_state(TestState *);
static void chk_empty_first(TestState *, void *);
static void chk_first(TestState *, void *);
static void chk_second(TestState *, void *);
static void chk_last(TestState *, void *);
static void mk_log_data(LogData *);
@ -91,21 +93,14 @@ append_to_empty(TestState *s)
chk_ptr_eq(s, "last_log", test.last_log, test.first_log);
}
static void
chk_empty_first(TestState *s, void *ptr)
{
TestState *test = ptr;
chk_str_eq(s, "text", test->first_log->text, "foo");
chk_ptr_eq(s, "next", test->first_log->next, 0);
}
static void
append_to_existing(TestState *s)
{
LogData ld;
mk_log_data(&ld);
append_test_log(&ld.state, "baz");
chk_ptr_eq(s, "first_log", ld.state.first_log, &ld.first);
test_context_with(s, "first_log", chk_first, &ld);
test_context_with(s, "second log", chk_second, &ld);
test_context_with(s, "last_log", chk_last, &ld);
}
@ -116,7 +111,8 @@ missing_last(TestState *s)
mk_log_data(&ld);
ld.state.last_log = 0;
append_test_log(&ld.state, "baz");
chk_ptr_eq(s, "first_log", ld.state.first_log, &ld.first);
test_context_with(s, "first_log", chk_first, &ld);
test_context_with(s, "second log", chk_second, &ld);
test_context_with(s, "last_log", chk_last, &ld);
}
@ -149,6 +145,48 @@ null_state(TestState *)
return test_success;
}
static void
chk_empty_first(TestState *s, void *ptr)
{
TestState *test = ptr;
chk_str_eq(s, "text", test->first_log->text, "foo");
chk_ptr_eq(s, "next", test->first_log->next, 0);
}
static void
chk_first(TestState *s, void *ptr)
{
LogData *ld = ptr;
// first_log
chk_ptr_eq(
s,
0,
ld->state.first_log,
&ld->first
);
// next
chk_ptr_eq(
s,
"next",
ld->state.first_log->next,
&ld->second
);
}
static void
chk_second(TestState *s, void *ptr)
{
LogData *ld = ptr;
chk_ptr_eq(
s,
"next",
ld->second.next,
ld->state.last_log
);
}
static void
chk_last(TestState *s, void *ptr)
{