renamed various checking functions

This commit is contained in:
jlamothe 2023-11-11 03:40:00 +00:00
parent 3309ac7aee
commit c0f28d41b0
3 changed files with 88 additions and 88 deletions

View File

@ -65,12 +65,12 @@ test_pass(TestState *s)
mk_sample_state(&actual);
run_test(&actual, always_passes);
compare_states(
chk_TestState_eq(
s,
"\t\t",
"ERROR: run_test(): passing:",
&expected,
&actual
&actual,
&expected
);
}
@ -91,7 +91,7 @@ test_fail(TestState *s)
mk_sample_state(&actual);
run_test(&actual, always_fails);
compare_states(
chk_TestState_eq(
s,
"\t\t",
"ERROR: run_test(): failing:",
@ -117,7 +117,7 @@ test_pend(TestState *s)
mk_sample_state(&actual);
run_test(&actual, always_pends);
compare_states(
chk_TestState_eq(
s,
"\t\t",
"ERROR: run_test(): pending:",

View File

@ -34,21 +34,21 @@ typedef struct ComparePtrs ComparePtrs;
struct CompareInts
{
const char *context;
int expected;
int actual;
int chk_val;
int ref_val;
};
struct ComparePtrs
{
const char *context;
const void *expected;
const void *actual;
const void *chk_val;
const void *ref_val;
};
// Local Prototypes
// compare the run value of two states
static void compare_run(
static void chk_TestState_run_eq(
TestState *,
const char *,
const char *,
@ -57,7 +57,7 @@ static void compare_run(
);
// compare the passed value of two states
static void compare_passed(
static void chk_TestState_passed_eq(
TestState *,
const char *,
const char *,
@ -66,7 +66,7 @@ static void compare_passed(
);
// compare the failed value of two states
static void compare_failed(
static void chk_TestState_failed_eq(
TestState *,
const char *,
const char *,
@ -75,7 +75,7 @@ static void compare_failed(
);
// compare the pending value of two states
static void compare_pending(
static void chk_TestState_pending_eq(
TestState *,
const char *,
const char *,
@ -84,7 +84,7 @@ static void compare_pending(
);
// compare the first_log value of two states
static void compare_first_log(
static void chk_TestState_first_log_eq(
TestState *,
const char *,
const char *,
@ -93,7 +93,7 @@ static void compare_first_log(
);
// compare the last_log value of two states
static void compare_last_log(
static void chk_TestState_last_log_eq(
TestState *,
const char *,
const char *,
@ -102,7 +102,7 @@ static void compare_last_log(
);
// compare the ptr value of two states
static void compare_ptr(
static void chk_TestState_ptr_eq(
TestState *,
const char *,
const char *,
@ -110,8 +110,8 @@ static void compare_ptr(
const TestState *
);
decl_test(compare_ints_test);
decl_test(compare_ptrs_test);
decl_test(chk_int_eq_test);
decl_test(chk_ptr_eq_test);
// Public Functions
@ -126,195 +126,195 @@ mk_sample_state(TestState *s)
}
void
compare_states(
chk_TestState_eq(
TestState *s,
const char *prefix,
const char *context,
const TestState *expected,
const TestState *actual
const TestState *actual,
const TestState *expected
)
{
compare_run(s, prefix, context, expected, actual);
compare_passed(s, prefix, context, expected, actual);
compare_failed(s, prefix, context, expected, actual);
compare_pending(s, prefix, context, expected, actual);
compare_first_log(s, prefix, context, expected, actual);
compare_last_log(s, prefix, context, expected, actual);
compare_ptr(s, prefix, context, expected, actual);
chk_TestState_run_eq(s, prefix, context, actual, expected);
chk_TestState_passed_eq(s, prefix, context, actual, expected);
chk_TestState_failed_eq(s, prefix, context, actual, expected);
chk_TestState_pending_eq(s, prefix, context, actual, expected);
chk_TestState_first_log_eq(s, prefix, context, actual, expected);
chk_TestState_last_log_eq(s, prefix, context, actual, expected);
chk_TestState_ptr_eq(s, prefix, context, actual, expected);
}
void
compare_ints(
chk_int_eq(
TestState *s,
const char *context,
int expected,
int actual
int actual,
int expected
)
{
void *old_ptr = s->ptr;
CompareInts ci;
ci.context = context;
ci.expected = expected;
ci.actual = actual;
ci.chk_val = actual;
ci.ref_val = expected;
s->ptr = &ci;
run_test(s, compare_ints_test);
run_test(s, chk_int_eq_test);
s->ptr = old_ptr;
}
void
compare_ptrs(
chk_ptr_eq(
TestState *s,
const char *context,
void *expected,
void *actual
void *actual,
void *expected
)
{
void *old_ptr = s->ptr;
ComparePtrs cp;
cp.context = context;
cp.expected = expected;
cp.actual = actual;
cp.chk_val = actual;
cp.ref_val = expected;
s->ptr = &cp;
run_test(s, compare_ptrs_test);
run_test(s, chk_ptr_eq_test);
s->ptr = old_ptr;
}
// Local Functions
static void
compare_run(
chk_TestState_run_eq(
TestState *s,
const char *prefix,
const char *context,
const TestState *expected,
const TestState *actual
const TestState *actual,
const TestState *expected
)
{
char full_context[STR_BUF_SIZE];
print(prefix);
print("run\n");
snprintf(full_context, STR_BUF_SIZE, "%s run:", context);
compare_ints(s, full_context, expected->run, actual->run);
chk_int_eq(s, full_context, actual->run, expected->run);
}
static void
compare_passed(
chk_TestState_passed_eq(
TestState *s,
const char *prefix,
const char *context,
const TestState *expected,
const TestState *actual
const TestState *actual,
const TestState *expected
)
{
char full_context[STR_BUF_SIZE];
print(prefix);
print("passed\n");
snprintf(full_context, STR_BUF_SIZE, "%s passed:", context);
compare_ints(s, full_context, expected->passed, actual->passed);
chk_int_eq(s, full_context, actual->passed, expected->passed);
}
static void
compare_failed(
chk_TestState_failed_eq(
TestState *s,
const char *prefix,
const char *context,
const TestState *expected,
const TestState *actual
const TestState *actual,
const TestState *expected
)
{
char full_context[STR_BUF_SIZE];
print(prefix);
print("failed\n");
snprintf(full_context, STR_BUF_SIZE, "%s failed:", context);
compare_ints(s, full_context, expected->failed, actual->failed);
chk_int_eq(s, full_context, actual->failed, expected->failed);
}
static void
compare_pending(
chk_TestState_pending_eq(
TestState *s,
const char *prefix,
const char *context,
const TestState *expected,
const TestState *actual
const TestState *actual,
const TestState *expected
)
{
char full_context[STR_BUF_SIZE];
print(prefix);
print("pending\n");
snprintf(full_context, STR_BUF_SIZE, "%s pending:", context);
compare_ints(s, full_context, expected->pending, actual->pending);
chk_int_eq(s, full_context, actual->pending, expected->pending);
}
static void
compare_first_log(
chk_TestState_first_log_eq(
TestState *s,
const char *prefix,
const char *context,
const TestState *expected,
const TestState *actual
const TestState *actual,
const TestState *expected
)
{
char full_context[STR_BUF_SIZE];
print(prefix);
print("first_log\n");
snprintf(full_context, STR_BUF_SIZE, "%s first_log:", context);
compare_ptrs(s, full_context, expected->first_log, actual->first_log);
chk_ptr_eq(s, full_context, actual->first_log, expected->first_log);
}
static void
compare_last_log(
chk_TestState_last_log_eq(
TestState *s,
const char *prefix,
const char *context,
const TestState *expected,
const TestState *actual
const TestState *actual,
const TestState *expected
)
{
char full_context[STR_BUF_SIZE];
print(prefix);
print("last_log\n");
snprintf(full_context, STR_BUF_SIZE, "%s last_log:", context);
compare_ptrs(s, full_context, expected->last_log, actual->last_log);
chk_ptr_eq(s, full_context, actual->last_log, expected->last_log);
}
static void
compare_ptr(
chk_TestState_ptr_eq(
TestState *s,
const char *prefix,
const char *context,
const TestState *expected,
const TestState *actual
const TestState *actual,
const TestState *expected
)
{
char full_context[STR_BUF_SIZE];
print(prefix);
print("ptr\n");
snprintf(full_context, STR_BUF_SIZE, "%s ptr:", context);
compare_ptrs(s, full_context, expected->ptr, actual->ptr);
chk_ptr_eq(s, full_context, actual->ptr, expected->ptr);
}
def_test(compare_ints_test, s)
def_test(chk_int_eq_test, s)
{
const CompareInts *ci = s->ptr;
if (ci->actual == ci->expected) return test_success;
if (ci->chk_val == ci->ref_val) return test_success;
char str[STR_BUF_SIZE];
append_test_log(s, ci->context);
snprintf(str, STR_BUF_SIZE, "\texpected: %d", ci->expected);
snprintf(str, STR_BUF_SIZE, "\texpected: %d", ci->ref_val);
append_test_log(s, str);
snprintf(str, STR_BUF_SIZE, "\tactual: %d", ci->actual);
snprintf(str, STR_BUF_SIZE, "\tactual: %d", ci->chk_val);
append_test_log(s, str);
return test_failure;
}
def_test(compare_ptrs_test, s)
def_test(chk_ptr_eq_test, s)
{
const ComparePtrs *cp = s->ptr;
if (cp->actual == cp->expected) return test_success;
if (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: 0x%x", cp->expected);
snprintf(str, STR_BUF_SIZE, "\texpected: 0x%x", cp->ref_val);
append_test_log(s, str);
snprintf(str, STR_BUF_SIZE, "\tactual: 0x%x", cp->actual);
snprintf(str, STR_BUF_SIZE, "\tactual: 0x%x", cp->chk_val);
append_test_log(s, str);
return test_failure;
}

View File

@ -27,29 +27,29 @@
// initializes a sample TestState value
void mk_sample_state(TestState *);
// compares two TestState values
extern void compare_states(
// ensures two TestState values are equal
extern void chk_TestState_eq(
TestState *, // the state we are *actually* updating ;)
const char *, // prefix for each status line
const char *, // context for errors
const TestState *, // expected state
const TestState * // actual state
const TestState *, // actual state
const TestState * // expected state
);
// compare two ints
extern void compare_ints(
// ensure two integers are equal
extern void chk_int_eq(
TestState *,
const char *, // the error context
int, // the expected value
int // the actual value
int, // the actual value
int // the expected value
);
// compare two pointers
extern void compare_ptrs(
// ensure two pointers are equal
extern void chk_ptr_eq(
TestState *,
const char *, // the error context
void *, // the expected value
void * // the actual value
void *, // the actual value
void * // the expected value
);
//jl