build a struct to represent a sample log

This commit is contained in:
jlamothe 2023-11-13 03:47:21 +00:00
parent 5e8b1b73c7
commit 4ff1aa2d6d

View File

@ -27,10 +27,21 @@
#include "util.h" #include "util.h"
#include "append-test-log.h" #include "append-test-log.h"
// Local Types
typedef struct LogData LogData;
struct LogData
{
TestState state;
TestLogEntry first, second;
};
// Local Prototypes // Local Prototypes
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 mk_log_data(LogData *);
static void chk_ptr_chg( static void chk_ptr_chg(
TestState *, TestState *,
@ -91,28 +102,18 @@ append_to_empty(TestState *s)
static void static void
append_to_existing(TestState *s) append_to_existing(TestState *s)
{ {
TestState test; LogData ld;
TestLogEntry first, second;
print("\tappend to existing\n"); print("\tappend to existing\n");
mk_log_data(&ld);
// build initial state/log append_test_log(&ld.state, "baz");
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");
// first shouldn't change // first shouldn't change
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(): first_log:",
test.first_log, ld.state.first_log,
&first &ld.first
); );
// last should change // last should change
@ -121,11 +122,23 @@ append_to_existing(TestState *s)
s, s,
"\t\t\t", "\t\t\t",
"ERROR: append_test_log(): last_log:", "ERROR: append_test_log(): last_log:",
test.last_log, ld.state.last_log,
&second &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 static void
chk_ptr_chg( chk_ptr_chg(
TestState *s, TestState *s,