Compare commits

...

3 Commits

Author SHA1 Message Date
jlamothe 5e8b1b73c7 make sure last_log changes, but isn't null on append 2023-11-13 01:27:07 +00:00
jlamothe fc167d8d05 ensure first_log doesn't change on append 2023-11-13 00:49:33 +00:00
jlamothe 586bbe71ed started append to existing test 2023-11-13 00:37:19 +00:00

View File

@ -21,6 +21,7 @@
#include <u.h> #include <u.h>
#include <libc.h> #include <libc.h>
#include <stdio.h>
#include "../9unit.h" #include "../9unit.h"
#include "util.h" #include "util.h"
@ -29,6 +30,15 @@
// Local Prototypes // Local Prototypes
static void append_to_empty(TestState *); static void append_to_empty(TestState *);
static void append_to_existing(TestState *);
static void chk_ptr_chg(
TestState *,
const char *,
const char *,
const void *,
const void *
);
// Public Functions // Public Functions
@ -37,6 +47,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);
} }
// Local Functions // Local Functions
@ -77,4 +88,76 @@ append_to_empty(TestState *s)
); );
} }
static void
append_to_existing(TestState *s)
{
TestState test;
TestLogEntry first, second;
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");
// first shouldn't change
print("\t\tfirst_log\n");
chk_ptr_eq(
s,
"ERROR: append_test_log(): first_log:",
test.first_log,
&first
);
// last should change
print("\t\tlast_log\n");
chk_ptr_chg(
s,
"\t\t\t",
"ERROR: append_test_log(): last_log:",
test.last_log,
&second
);
}
static void
chk_ptr_chg(
TestState *s,
const char *prefix,
const char *context,
const void *actual,
const void *prohibited
)
{
char str[STR_BUF_SIZE];
// make sure it's changed
print(prefix);
print("changed\n");
snprintf(str, STR_BUF_SIZE, "%s changed:", context);
chk_ptr_ne(
s,
str,
actual,
prohibited
);
// make sure it's not null
print(prefix);
print("not null\n");
snprintf(str, STR_BUF_SIZE, "%s not null:", context);
chk_ptr_ne(
s,
str,
actual,
0
);
}
//jl //jl