made check_value() use test_context_with()

eliminates some redundant code
This commit is contained in:
jlamothe 2023-11-17 23:07:05 +00:00
parent 5d67b7aeb8
commit 37ce34b160

18
9unit.c
View File

@ -37,7 +37,7 @@ typedef struct SingleTestContext SingleTestContext;
typedef struct TestContextWith TestContextWith;
// data used by check_value()
typedef struct CheckValueData CheckValueData;
typedef struct CheckValue CheckValue;
struct ContextData
{
@ -60,9 +60,8 @@ struct TestContextWith
void (*test)(TestState *, void *); // the test function
};
struct CheckValueData
struct CheckValue
{
void *ptr; // state's original ptr value
void *chk_val; // the value being checked
void *ref_val; // the reference value
void (*test)(TestState *, void *, void *); // the test
@ -80,7 +79,7 @@ static void display_context(TestState *);
static void restore_context(TestState *, ContextData *);
static void run_single_test_context(TestState *);
static void test_context_with_test(TestState *);
static void check_value_test(TestState *);
static void check_value_test(TestState *, void *);
// Public Functions
@ -222,13 +221,11 @@ check_value(
)
{
if (!(s && test)) return;
CheckValueData d;
d.ptr = s->ptr;
CheckValue d;
d.chk_val = chk_val;
d.ref_val = ref_val;
d.test = test;
s->ptr = &d;
test_context(s, context, check_value_test);
test_context_with(s, context, check_value_test, &d);
}
// Internal Functions
@ -344,10 +341,9 @@ test_context_with_test(TestState *s)
}
static void
check_value_test(TestState *s)
check_value_test(TestState *s, void *ptr)
{
CheckValueData *d = s->ptr;
s->ptr = d->ptr;
CheckValue *d = ptr;
(*d->test)(s, d->chk_val, d->ref_val);
}