renamed check_values() to test_context_compare() and reimplemented

This commit is contained in:
jlamothe
2023-11-20 01:16:44 +00:00
parent f808eb4cb0
commit eaa8ae06a7
2 changed files with 58 additions and 50 deletions

76
9unit.c
View File

@@ -31,8 +31,8 @@ typedef struct RunTestWith RunTestWith;
typedef struct RunTestCompare RunTestCompare;
typedef struct ContextData ContextData;
typedef struct TestContextWith TestContextWith;
typedef struct TestContextCompare TestContextCompare;
typedef struct SingleTestContextWith SingleTestContextWith;
typedef struct CheckValue CheckValue;
// data required by run_test_with()
struct RunTestWith
@@ -66,6 +66,14 @@ struct TestContextWith
void *val; // the value being passed in
};
// data needed by test_context_compare()
struct TestContextCompare
{
void (*test)(TestState *, void *, void *);
void *val1;
void *val2;
};
// data needed by single_test_context_with()
struct SingleTestContextWith
{
@@ -73,13 +81,6 @@ struct SingleTestContextWith
void *val;
};
struct CheckValue
{
void *chk_val; // the value being checked
void *ref_val; // the reference value
void (*test)(TestState *, void *, void *); // the test
};
// Internal Prototypes
static void init_TestState(TestState *);
@@ -92,10 +93,10 @@ static void display_context(TestState *);
static void restore_context(TestState *, ContextData *);
static TestResult run_test_with_test(TestState *);
static TestResult run_test_compare_test(TestState *, void *);
static void single_test_context_test(TestState *, void *);
static void test_context_with_test(TestState *);
static void test_context_compare_test(TestState *, void *);
static void single_test_context_test(TestState *, void *);
static void single_test_context_with_test(TestState *, void *);
static void check_value_test(TestState *, void *);
// Public Functions
@@ -248,6 +249,27 @@ test_context_with(
test_context(s, context, test_context_with_test);
}
void
test_context_compare(
TestState *s,
const char *context,
void (*test)(TestState *, void *, void *),
void *val1,
void *val2
)
{
TestContextCompare d;
d.test = test;
d.val1 = val1;
d.val2 = val2;
test_context_with(
s,
context,
test_context_compare_test,
&d
);
}
void
single_test_context(
TestState *s,
@@ -277,23 +299,6 @@ single_test_context_with(
);
}
void
check_value(
TestState *s,
const char *context,
void (*test)(TestState *, void *, void *),
void *chk_val,
void *ref_val
)
{
if (!(s && test)) return;
CheckValue d;
d.chk_val = chk_val;
d.ref_val = ref_val;
d.test = test;
test_context_with(s, context, check_value_test, &d);
}
// Internal Functions
static void
@@ -416,6 +421,16 @@ test_context_with_test(TestState *s)
(*d->test)(s, d->val);
}
static void
test_context_compare_test(
TestState *s,
void *ptr
)
{
TestContextCompare *d = ptr;
(*d->test)(s, d->val1, d->val2);
}
static void
single_test_context_test(TestState *s, void *test)
{
@@ -429,11 +444,4 @@ single_test_context_with_test(TestState *s, void *ptr)
run_test_with(s, d->test, d->val);
}
static void
check_value_test(TestState *s, void *ptr)
{
CheckValue *d = ptr;
(*d->test)(s, d->chk_val, d->ref_val);
}
//jl