From 47638ef0b7d5ba4b4066bdad136a5277953a1ab5 Mon Sep 17 00:00:00 2001 From: jlamothe Date: Tue, 14 Nov 2023 19:16:21 +0000 Subject: [PATCH] ensure last_log repairs itself when appending --- test/append-test-log.c | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/test/append-test-log.c b/test/append-test-log.c index ff8f82a..a392b7a 100644 --- a/test/append-test-log.c +++ b/test/append-test-log.c @@ -41,7 +41,8 @@ struct LogData static void append_to_empty(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 chk_ptr_chg( @@ -60,6 +61,7 @@ test_append_test_log(TestState *s) print("append_test_log()\n"); append_to_empty(s); append_to_existing(s); + missing_last(s); } // Local Functions @@ -112,23 +114,53 @@ append_to_existing(TestState *s) print("\t\tfirst_log\n"); chk_ptr_eq( s, - "ERROR: append_test_log(): first_log:", + "ERROR: append_test_log(): append to existing: first_log:", ld.state.first_log, &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); } 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"); chk_ptr_chg( s, "\t\t\t", - "ERROR: append_test_log(): last_log:", + context, ld->state.last_log, &ld->second );