ensure last_log repairs itself when appending

This commit is contained in:
jlamothe 2023-11-14 19:16:21 +00:00
parent 580af62244
commit 47638ef0b7

View File

@ -41,7 +41,8 @@ struct LogData
static void append_to_empty(TestState *); static void append_to_empty(TestState *);
static void append_to_existing(TestState *); static void append_to_existing(TestState *);
static void a2e_chk_last(TestState *, LogData *); static void missing_last(TestState *);
static void chk_last(TestState *, LogData *, const char *);
static void mk_log_data(LogData *); static void mk_log_data(LogData *);
static void chk_ptr_chg( static void chk_ptr_chg(
@ -60,6 +61,7 @@ test_append_test_log(TestState *s)
print("append_test_log()\n"); print("append_test_log()\n");
append_to_empty(s); append_to_empty(s);
append_to_existing(s); append_to_existing(s);
missing_last(s);
} }
// Local Functions // Local Functions
@ -112,23 +114,53 @@ append_to_existing(TestState *s)
print("\t\tfirst_log\n"); print("\t\tfirst_log\n");
chk_ptr_eq( chk_ptr_eq(
s, s,
"ERROR: append_test_log(): first_log:", "ERROR: append_test_log(): append to existing: first_log:",
ld.state.first_log, ld.state.first_log,
&ld.first &ld.first
); );
a2e_chk_last(s, &ld); chk_last(
s,
&ld,
"ERROR: append_test_log(): append to existing: last_log:"
);
free(ld.state.last_log); free(ld.state.last_log);
} }
static void static void
a2e_chk_last(TestState *s, LogData *ld) missing_last(TestState *s)
{
LogData ld;
print("\tlast_log missing\n");
mk_log_data(&ld);
ld.state.last_log = 0;
append_test_log(&ld.state, "baz");
// first shouldn't change
print("\t\tfirst_log\n");
chk_ptr_eq(
s,
"ERROR: append_test_log(): last_log missing: first_log:",
ld.state.first_log,
&ld.first
);
chk_last(
s,
&ld,
"ERROR: append_test_log(): last_log missing: last_log:"
);
free(ld.state.last_log);
}
static void
chk_last(TestState *s, LogData *ld, const char *context)
{ {
print("\t\tlast_log\n"); print("\t\tlast_log\n");
chk_ptr_chg( chk_ptr_chg(
s, s,
"\t\t\t", "\t\t\t",
"ERROR: append_test_log(): last_log:", context,
ld->state.last_log, ld->state.last_log,
&ld->second &ld->second
); );