Compare commits

...

6 Commits

Author SHA1 Message Date
jlamothe 1d306f32c0 actually count the null state test for run_test() 2023-11-14 20:32:07 +00:00
jlamothe bcfd584608 make sure passing a null state to append_test_log() doesn't crash it 2023-11-14 20:16:30 +00:00
jlamothe 2a092d1050 ensure the log doesn't change when the message is null 2023-11-14 19:59:13 +00:00
jlamothe a772db08ce try to rebuild log when first entry missing 2023-11-14 19:33:02 +00:00
jlamothe 47638ef0b7 ensure last_log repairs itself when appending 2023-11-14 19:16:21 +00:00
jlamothe 580af62244 fix memory leak 2023-11-14 18:43:06 +00:00
2 changed files with 107 additions and 11 deletions

View File

@ -41,7 +41,11 @@ 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 missing_first(TestState *);
static void null_message(TestState *);
decl_test(null_state);
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 +64,10 @@ 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);
missing_first(s);
null_message(s);
run_test(s, null_state);
} }
// Local Functions // Local Functions
@ -112,22 +120,112 @@ 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);
} }
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
missing_first(TestState *s)
{
LogData ld;
print("\tfirst_log missing\n");
mk_log_data(&ld);
ld.state.first_log = 0;
append_test_log(&ld.state, "baz");
// first_log should point to second
print("\t\tfirst_log\n");
chk_ptr_eq(
s,
"ERROR: append_test_log(): first_log missing: first_log:",
ld.state.first_log,
&ld.second
);
chk_last(
s,
&ld,
"ERROR: append_test_log(): first_log missing: last_log:"
);
free(ld.state.last_log);
}
static void
null_message(TestState *s)
{
LogData ld;
print("\tnull message\n");
mk_log_data(&ld);
append_test_log(&ld.state, 0);
// first shouldn't change
print("\t\tfirst_log\n");
chk_ptr_eq(
s,
"ERROR: append_test_log(): null message: first_log:",
ld.state.first_log,
&ld.first
);
// last shouldn't change
print("\t\tlast_log\n");
chk_ptr_eq(
s,
"ERROR: append_test_log(): null message: last_log:",
ld.state.last_log,
&ld.second
);
}
decl_test(null_state)
{
append_test_log(0, "foo");
return test_success;
}
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
); );

View File

@ -31,7 +31,7 @@
static void test_pass(TestState *); static void test_pass(TestState *);
static void test_fail(TestState *); static void test_fail(TestState *);
static void test_pend(TestState *); static void test_pend(TestState *);
static void null_state(TestState *); decl_test(null_state);
static void null_test(TestState *); static void null_test(TestState *);
decl_test(always_passes); decl_test(always_passes);
decl_test(always_fails); decl_test(always_fails);
@ -46,7 +46,7 @@ test_run_test(TestState *s)
test_pass(s); test_pass(s);
test_fail(s); test_fail(s);
test_pend(s); test_pend(s);
null_state(s); run_test(s, null_state);
null_test(s); null_test(s);
} }
@ -130,13 +130,11 @@ test_pend(TestState *s)
); );
} }
static void decl_test(null_state)
null_state(TestState *)
{ {
print("\tnull state\n"); print("\tnull state\n");
// make sure it doesn't crash
run_test(0, always_passes); run_test(0, always_passes);
return test_success;
} }
static void static void