Compare commits
2 Commits
9f4a51d8c7
...
3393c3b9af
Author | SHA1 | Date | |
---|---|---|---|
3393c3b9af | |||
63f0bd73e4 |
|
@ -57,6 +57,24 @@ append_to_empty(TestState *s)
|
|||
test.first_log,
|
||||
0
|
||||
);
|
||||
|
||||
// log should say "foo"
|
||||
print("\t\t\ttext\n");
|
||||
chk_str_eq(
|
||||
s,
|
||||
"ERROR: append_test_log(): append to empty: first_log: text:",
|
||||
test.first_log->text,
|
||||
"foo"
|
||||
);
|
||||
|
||||
// last_log should match first_log
|
||||
print("\t\tlast_log\n");
|
||||
chk_ptr_eq(
|
||||
s,
|
||||
"ERROR: append_test_log(): append to empty: last_log:",
|
||||
test.last_log,
|
||||
test.first_log
|
||||
);
|
||||
}
|
||||
|
||||
//jl
|
||||
|
|
32
test/util.c
32
test/util.c
|
@ -113,6 +113,7 @@ static void chk_TestState_ptr_eq(
|
|||
decl_test(chk_int_eq_test); // ensure ints are equal
|
||||
decl_test(chk_ptr_eq_test); // ensure pointers are equal
|
||||
decl_test(chk_ptr_ne_test); // ensure pointers are not equal
|
||||
decl_test(chk_str_eq_test); // ensure strings are equal
|
||||
|
||||
// Public Functions
|
||||
|
||||
|
@ -198,6 +199,24 @@ chk_ptr_ne(
|
|||
s->ptr = old_ptr;
|
||||
}
|
||||
|
||||
void
|
||||
chk_str_eq(
|
||||
TestState *s,
|
||||
const char *context,
|
||||
const char *actual,
|
||||
const char *expected
|
||||
)
|
||||
{
|
||||
void *old_ptr = s->ptr;
|
||||
ComparePtrs cp;
|
||||
cp.context = context;
|
||||
cp.chk_val = actual;
|
||||
cp.ref_val = expected;
|
||||
s->ptr = &cp;
|
||||
run_test(s, chk_str_eq_test);
|
||||
s->ptr = old_ptr;
|
||||
}
|
||||
|
||||
// Local Functions
|
||||
|
||||
static void
|
||||
|
@ -349,4 +368,17 @@ def_test(chk_ptr_ne_test, s)
|
|||
return test_failure;
|
||||
}
|
||||
|
||||
def_test(chk_str_eq_test, s)
|
||||
{
|
||||
const ComparePtrs *cp = s->ptr;
|
||||
if (!strcmp(cp->chk_val, cp->ref_val)) return test_success;
|
||||
char str[STR_BUF_SIZE];
|
||||
append_test_log(s, cp->context);
|
||||
snprintf(str, STR_BUF_SIZE, "\texpected: %s", cp->ref_val);
|
||||
append_test_log(s, str);
|
||||
snprintf(str, STR_BUF_SIZE, "\tactual: %s", cp->ref_val);
|
||||
append_test_log(s, str);
|
||||
return test_failure;
|
||||
}
|
||||
|
||||
//jl
|
||||
|
|
|
@ -60,4 +60,12 @@ extern void chk_ptr_ne(
|
|||
const void * // the prohibited value
|
||||
);
|
||||
|
||||
// ensure two strings are equal
|
||||
extern void chk_str_eq(
|
||||
TestState *,
|
||||
const char *, // the error context
|
||||
const char *, // the actual value
|
||||
const char * // the expected value
|
||||
);
|
||||
|
||||
//jl
|
||||
|
|
Loading…
Reference in New Issue
Block a user