From 4ff1aa2d6d89af190efa7cb0e292ce772e22e3e3 Mon Sep 17 00:00:00 2001 From: jlamothe Date: Mon, 13 Nov 2023 03:47:21 +0000 Subject: [PATCH] build a struct to represent a sample log --- test/append-test-log.c | 47 +++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/test/append-test-log.c b/test/append-test-log.c index e05107e..ee35f8b 100644 --- a/test/append-test-log.c +++ b/test/append-test-log.c @@ -27,10 +27,21 @@ #include "util.h" #include "append-test-log.h" +// Local Types + +typedef struct LogData LogData; + +struct LogData +{ + TestState state; + TestLogEntry first, second; +}; + // Local Prototypes static void append_to_empty(TestState *); static void append_to_existing(TestState *); +static void mk_log_data(LogData *); static void chk_ptr_chg( TestState *, @@ -91,28 +102,18 @@ append_to_empty(TestState *s) static void append_to_existing(TestState *s) { - TestState test; - TestLogEntry first, second; + LogData ld; print("\tappend to existing\n"); - - // build initial state/log - mk_sample_state(&test); - first.text = "foo"; - first.next = &second; - second.text = "bar"; - second.next = 0; - test.first_log = &first; - test.last_log = &second; - - append_test_log(&test, "baz"); + mk_log_data(&ld); + append_test_log(&ld.state, "baz"); // first shouldn't change print("\t\tfirst_log\n"); chk_ptr_eq( s, "ERROR: append_test_log(): first_log:", - test.first_log, - &first + ld.state.first_log, + &ld.first ); // last should change @@ -121,11 +122,23 @@ append_to_existing(TestState *s) s, "\t\t\t", "ERROR: append_test_log(): last_log:", - test.last_log, - &second + ld.state.last_log, + &ld.second ); } +static void +mk_log_data(LogData *ld) +{ + mk_sample_state(&ld->state); + ld->state.first_log = &ld->first; + ld->state.last_log = &ld->second; + ld->first.text = "foo"; + ld->first.next = &ld->second; + ld->second.text = "bar"; + ld->second.next = 0; +} + static void chk_ptr_chg( TestState *s,