renamed various checking functions
This commit is contained in:
parent
3309ac7aee
commit
c0f28d41b0
|
@ -65,12 +65,12 @@ test_pass(TestState *s)
|
||||||
mk_sample_state(&actual);
|
mk_sample_state(&actual);
|
||||||
run_test(&actual, always_passes);
|
run_test(&actual, always_passes);
|
||||||
|
|
||||||
compare_states(
|
chk_TestState_eq(
|
||||||
s,
|
s,
|
||||||
"\t\t",
|
"\t\t",
|
||||||
"ERROR: run_test(): passing:",
|
"ERROR: run_test(): passing:",
|
||||||
&expected,
|
&actual,
|
||||||
&actual
|
&expected
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ test_fail(TestState *s)
|
||||||
mk_sample_state(&actual);
|
mk_sample_state(&actual);
|
||||||
run_test(&actual, always_fails);
|
run_test(&actual, always_fails);
|
||||||
|
|
||||||
compare_states(
|
chk_TestState_eq(
|
||||||
s,
|
s,
|
||||||
"\t\t",
|
"\t\t",
|
||||||
"ERROR: run_test(): failing:",
|
"ERROR: run_test(): failing:",
|
||||||
|
@ -117,7 +117,7 @@ test_pend(TestState *s)
|
||||||
mk_sample_state(&actual);
|
mk_sample_state(&actual);
|
||||||
run_test(&actual, always_pends);
|
run_test(&actual, always_pends);
|
||||||
|
|
||||||
compare_states(
|
chk_TestState_eq(
|
||||||
s,
|
s,
|
||||||
"\t\t",
|
"\t\t",
|
||||||
"ERROR: run_test(): pending:",
|
"ERROR: run_test(): pending:",
|
||||||
|
|
142
test/util.c
142
test/util.c
|
@ -34,21 +34,21 @@ typedef struct ComparePtrs ComparePtrs;
|
||||||
struct CompareInts
|
struct CompareInts
|
||||||
{
|
{
|
||||||
const char *context;
|
const char *context;
|
||||||
int expected;
|
int chk_val;
|
||||||
int actual;
|
int ref_val;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ComparePtrs
|
struct ComparePtrs
|
||||||
{
|
{
|
||||||
const char *context;
|
const char *context;
|
||||||
const void *expected;
|
const void *chk_val;
|
||||||
const void *actual;
|
const void *ref_val;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Local Prototypes
|
// Local Prototypes
|
||||||
|
|
||||||
// compare the run value of two states
|
// compare the run value of two states
|
||||||
static void compare_run(
|
static void chk_TestState_run_eq(
|
||||||
TestState *,
|
TestState *,
|
||||||
const char *,
|
const char *,
|
||||||
const char *,
|
const char *,
|
||||||
|
@ -57,7 +57,7 @@ static void compare_run(
|
||||||
);
|
);
|
||||||
|
|
||||||
// compare the passed value of two states
|
// compare the passed value of two states
|
||||||
static void compare_passed(
|
static void chk_TestState_passed_eq(
|
||||||
TestState *,
|
TestState *,
|
||||||
const char *,
|
const char *,
|
||||||
const char *,
|
const char *,
|
||||||
|
@ -66,7 +66,7 @@ static void compare_passed(
|
||||||
);
|
);
|
||||||
|
|
||||||
// compare the failed value of two states
|
// compare the failed value of two states
|
||||||
static void compare_failed(
|
static void chk_TestState_failed_eq(
|
||||||
TestState *,
|
TestState *,
|
||||||
const char *,
|
const char *,
|
||||||
const char *,
|
const char *,
|
||||||
|
@ -75,7 +75,7 @@ static void compare_failed(
|
||||||
);
|
);
|
||||||
|
|
||||||
// compare the pending value of two states
|
// compare the pending value of two states
|
||||||
static void compare_pending(
|
static void chk_TestState_pending_eq(
|
||||||
TestState *,
|
TestState *,
|
||||||
const char *,
|
const char *,
|
||||||
const char *,
|
const char *,
|
||||||
|
@ -84,7 +84,7 @@ static void compare_pending(
|
||||||
);
|
);
|
||||||
|
|
||||||
// compare the first_log value of two states
|
// compare the first_log value of two states
|
||||||
static void compare_first_log(
|
static void chk_TestState_first_log_eq(
|
||||||
TestState *,
|
TestState *,
|
||||||
const char *,
|
const char *,
|
||||||
const char *,
|
const char *,
|
||||||
|
@ -93,7 +93,7 @@ static void compare_first_log(
|
||||||
);
|
);
|
||||||
|
|
||||||
// compare the last_log value of two states
|
// compare the last_log value of two states
|
||||||
static void compare_last_log(
|
static void chk_TestState_last_log_eq(
|
||||||
TestState *,
|
TestState *,
|
||||||
const char *,
|
const char *,
|
||||||
const char *,
|
const char *,
|
||||||
|
@ -102,7 +102,7 @@ static void compare_last_log(
|
||||||
);
|
);
|
||||||
|
|
||||||
// compare the ptr value of two states
|
// compare the ptr value of two states
|
||||||
static void compare_ptr(
|
static void chk_TestState_ptr_eq(
|
||||||
TestState *,
|
TestState *,
|
||||||
const char *,
|
const char *,
|
||||||
const char *,
|
const char *,
|
||||||
|
@ -110,8 +110,8 @@ static void compare_ptr(
|
||||||
const TestState *
|
const TestState *
|
||||||
);
|
);
|
||||||
|
|
||||||
decl_test(compare_ints_test);
|
decl_test(chk_int_eq_test);
|
||||||
decl_test(compare_ptrs_test);
|
decl_test(chk_ptr_eq_test);
|
||||||
|
|
||||||
// Public Functions
|
// Public Functions
|
||||||
|
|
||||||
|
@ -126,195 +126,195 @@ mk_sample_state(TestState *s)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
compare_states(
|
chk_TestState_eq(
|
||||||
TestState *s,
|
TestState *s,
|
||||||
const char *prefix,
|
const char *prefix,
|
||||||
const char *context,
|
const char *context,
|
||||||
const TestState *expected,
|
const TestState *actual,
|
||||||
const TestState *actual
|
const TestState *expected
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
compare_run(s, prefix, context, expected, actual);
|
chk_TestState_run_eq(s, prefix, context, actual, expected);
|
||||||
compare_passed(s, prefix, context, expected, actual);
|
chk_TestState_passed_eq(s, prefix, context, actual, expected);
|
||||||
compare_failed(s, prefix, context, expected, actual);
|
chk_TestState_failed_eq(s, prefix, context, actual, expected);
|
||||||
compare_pending(s, prefix, context, expected, actual);
|
chk_TestState_pending_eq(s, prefix, context, actual, expected);
|
||||||
compare_first_log(s, prefix, context, expected, actual);
|
chk_TestState_first_log_eq(s, prefix, context, actual, expected);
|
||||||
compare_last_log(s, prefix, context, expected, actual);
|
chk_TestState_last_log_eq(s, prefix, context, actual, expected);
|
||||||
compare_ptr(s, prefix, context, expected, actual);
|
chk_TestState_ptr_eq(s, prefix, context, actual, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
compare_ints(
|
chk_int_eq(
|
||||||
TestState *s,
|
TestState *s,
|
||||||
const char *context,
|
const char *context,
|
||||||
int expected,
|
int actual,
|
||||||
int actual
|
int expected
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
void *old_ptr = s->ptr;
|
void *old_ptr = s->ptr;
|
||||||
CompareInts ci;
|
CompareInts ci;
|
||||||
ci.context = context;
|
ci.context = context;
|
||||||
ci.expected = expected;
|
ci.chk_val = actual;
|
||||||
ci.actual = actual;
|
ci.ref_val = expected;
|
||||||
s->ptr = &ci;
|
s->ptr = &ci;
|
||||||
run_test(s, compare_ints_test);
|
run_test(s, chk_int_eq_test);
|
||||||
s->ptr = old_ptr;
|
s->ptr = old_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
compare_ptrs(
|
chk_ptr_eq(
|
||||||
TestState *s,
|
TestState *s,
|
||||||
const char *context,
|
const char *context,
|
||||||
void *expected,
|
void *actual,
|
||||||
void *actual
|
void *expected
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
void *old_ptr = s->ptr;
|
void *old_ptr = s->ptr;
|
||||||
ComparePtrs cp;
|
ComparePtrs cp;
|
||||||
cp.context = context;
|
cp.context = context;
|
||||||
cp.expected = expected;
|
cp.chk_val = actual;
|
||||||
cp.actual = actual;
|
cp.ref_val = expected;
|
||||||
s->ptr = &cp;
|
s->ptr = &cp;
|
||||||
run_test(s, compare_ptrs_test);
|
run_test(s, chk_ptr_eq_test);
|
||||||
s->ptr = old_ptr;
|
s->ptr = old_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Local Functions
|
// Local Functions
|
||||||
|
|
||||||
static void
|
static void
|
||||||
compare_run(
|
chk_TestState_run_eq(
|
||||||
TestState *s,
|
TestState *s,
|
||||||
const char *prefix,
|
const char *prefix,
|
||||||
const char *context,
|
const char *context,
|
||||||
const TestState *expected,
|
const TestState *actual,
|
||||||
const TestState *actual
|
const TestState *expected
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
char full_context[STR_BUF_SIZE];
|
char full_context[STR_BUF_SIZE];
|
||||||
print(prefix);
|
print(prefix);
|
||||||
print("run\n");
|
print("run\n");
|
||||||
snprintf(full_context, STR_BUF_SIZE, "%s run:", context);
|
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
|
static void
|
||||||
compare_passed(
|
chk_TestState_passed_eq(
|
||||||
TestState *s,
|
TestState *s,
|
||||||
const char *prefix,
|
const char *prefix,
|
||||||
const char *context,
|
const char *context,
|
||||||
const TestState *expected,
|
const TestState *actual,
|
||||||
const TestState *actual
|
const TestState *expected
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
char full_context[STR_BUF_SIZE];
|
char full_context[STR_BUF_SIZE];
|
||||||
print(prefix);
|
print(prefix);
|
||||||
print("passed\n");
|
print("passed\n");
|
||||||
snprintf(full_context, STR_BUF_SIZE, "%s passed:", context);
|
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
|
static void
|
||||||
compare_failed(
|
chk_TestState_failed_eq(
|
||||||
TestState *s,
|
TestState *s,
|
||||||
const char *prefix,
|
const char *prefix,
|
||||||
const char *context,
|
const char *context,
|
||||||
const TestState *expected,
|
const TestState *actual,
|
||||||
const TestState *actual
|
const TestState *expected
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
char full_context[STR_BUF_SIZE];
|
char full_context[STR_BUF_SIZE];
|
||||||
print(prefix);
|
print(prefix);
|
||||||
print("failed\n");
|
print("failed\n");
|
||||||
snprintf(full_context, STR_BUF_SIZE, "%s failed:", context);
|
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
|
static void
|
||||||
compare_pending(
|
chk_TestState_pending_eq(
|
||||||
TestState *s,
|
TestState *s,
|
||||||
const char *prefix,
|
const char *prefix,
|
||||||
const char *context,
|
const char *context,
|
||||||
const TestState *expected,
|
const TestState *actual,
|
||||||
const TestState *actual
|
const TestState *expected
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
char full_context[STR_BUF_SIZE];
|
char full_context[STR_BUF_SIZE];
|
||||||
print(prefix);
|
print(prefix);
|
||||||
print("pending\n");
|
print("pending\n");
|
||||||
snprintf(full_context, STR_BUF_SIZE, "%s pending:", context);
|
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
|
static void
|
||||||
compare_first_log(
|
chk_TestState_first_log_eq(
|
||||||
TestState *s,
|
TestState *s,
|
||||||
const char *prefix,
|
const char *prefix,
|
||||||
const char *context,
|
const char *context,
|
||||||
const TestState *expected,
|
const TestState *actual,
|
||||||
const TestState *actual
|
const TestState *expected
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
char full_context[STR_BUF_SIZE];
|
char full_context[STR_BUF_SIZE];
|
||||||
print(prefix);
|
print(prefix);
|
||||||
print("first_log\n");
|
print("first_log\n");
|
||||||
snprintf(full_context, STR_BUF_SIZE, "%s first_log:", context);
|
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
|
static void
|
||||||
compare_last_log(
|
chk_TestState_last_log_eq(
|
||||||
TestState *s,
|
TestState *s,
|
||||||
const char *prefix,
|
const char *prefix,
|
||||||
const char *context,
|
const char *context,
|
||||||
const TestState *expected,
|
const TestState *actual,
|
||||||
const TestState *actual
|
const TestState *expected
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
char full_context[STR_BUF_SIZE];
|
char full_context[STR_BUF_SIZE];
|
||||||
print(prefix);
|
print(prefix);
|
||||||
print("last_log\n");
|
print("last_log\n");
|
||||||
snprintf(full_context, STR_BUF_SIZE, "%s last_log:", context);
|
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
|
static void
|
||||||
compare_ptr(
|
chk_TestState_ptr_eq(
|
||||||
TestState *s,
|
TestState *s,
|
||||||
const char *prefix,
|
const char *prefix,
|
||||||
const char *context,
|
const char *context,
|
||||||
const TestState *expected,
|
const TestState *actual,
|
||||||
const TestState *actual
|
const TestState *expected
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
char full_context[STR_BUF_SIZE];
|
char full_context[STR_BUF_SIZE];
|
||||||
print(prefix);
|
print(prefix);
|
||||||
print("ptr\n");
|
print("ptr\n");
|
||||||
snprintf(full_context, STR_BUF_SIZE, "%s ptr:", context);
|
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;
|
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];
|
char str[STR_BUF_SIZE];
|
||||||
append_test_log(s, ci->context);
|
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);
|
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);
|
append_test_log(s, str);
|
||||||
return test_failure;
|
return test_failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
def_test(compare_ptrs_test, s)
|
def_test(chk_ptr_eq_test, s)
|
||||||
{
|
{
|
||||||
const ComparePtrs *cp = s->ptr;
|
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];
|
char str[STR_BUF_SIZE];
|
||||||
append_test_log(s, cp->context);
|
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);
|
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);
|
append_test_log(s, str);
|
||||||
return test_failure;
|
return test_failure;
|
||||||
}
|
}
|
||||||
|
|
24
test/util.h
24
test/util.h
|
@ -27,29 +27,29 @@
|
||||||
// initializes a sample TestState value
|
// initializes a sample TestState value
|
||||||
void mk_sample_state(TestState *);
|
void mk_sample_state(TestState *);
|
||||||
|
|
||||||
// compares two TestState values
|
// ensures two TestState values are equal
|
||||||
extern void compare_states(
|
extern void chk_TestState_eq(
|
||||||
TestState *, // the state we are *actually* updating ;)
|
TestState *, // the state we are *actually* updating ;)
|
||||||
const char *, // prefix for each status line
|
const char *, // prefix for each status line
|
||||||
const char *, // context for errors
|
const char *, // context for errors
|
||||||
const TestState *, // expected state
|
const TestState *, // actual state
|
||||||
const TestState * // actual state
|
const TestState * // expected state
|
||||||
);
|
);
|
||||||
|
|
||||||
// compare two ints
|
// ensure two integers are equal
|
||||||
extern void compare_ints(
|
extern void chk_int_eq(
|
||||||
TestState *,
|
TestState *,
|
||||||
const char *, // the error context
|
const char *, // the error context
|
||||||
int, // the expected value
|
int, // the actual value
|
||||||
int // the actual value
|
int // the expected value
|
||||||
);
|
);
|
||||||
|
|
||||||
// compare two pointers
|
// ensure two pointers are equal
|
||||||
extern void compare_ptrs(
|
extern void chk_ptr_eq(
|
||||||
TestState *,
|
TestState *,
|
||||||
const char *, // the error context
|
const char *, // the error context
|
||||||
void *, // the expected value
|
void *, // the actual value
|
||||||
void * // the actual value
|
void * // the expected value
|
||||||
);
|
);
|
||||||
|
|
||||||
//jl
|
//jl
|
||||||
|
|
Loading…
Reference in New Issue
Block a user