refactored single_test_context_with()

This commit is contained in:
jlamothe 2023-11-19 20:44:14 +00:00
parent ad4abe68e0
commit 291d25927c

24
9unit.c
View File

@ -57,9 +57,9 @@ struct TestContextWith
void *val; // the value being passed in void *val; // the value being passed in
}; };
// data needed by single_test_context_with()
struct SingleTestContextWith struct SingleTestContextWith
{ {
void *ptr;
TestResult (*test)(TestState *, void *); TestResult (*test)(TestState *, void *);
void *val; void *val;
}; };
@ -84,7 +84,7 @@ static void display_context(TestState *);
static void restore_context(TestState *, ContextData *); static void restore_context(TestState *, ContextData *);
static void single_test_context_test(TestState *, void *); static void single_test_context_test(TestState *, void *);
static void test_context_with_test(TestState *); static void test_context_with_test(TestState *);
static TestResult single_test_context_with_test(TestState *); static void single_test_context_with_test(TestState *, void *);
static void check_value_test(TestState *, void *); static void check_value_test(TestState *, void *);
// Public Functions // Public Functions
@ -241,14 +241,15 @@ single_test_context_with(
void *val void *val
) )
{ {
if (!s) return;
if (!test) single_test_context(s, context, 0);
SingleTestContextWith d; SingleTestContextWith d;
d.ptr = s->ptr;
d.test = test; d.test = test;
d.val = val; d.val = val;
s->ptr = &d; test_context_with(
single_test_context(s, context, single_test_context_with_test); s,
context,
single_test_context_with_test,
&d
);
} }
void void
@ -386,12 +387,11 @@ single_test_context_test(TestState *s, void *test)
run_test(s, test); run_test(s, test);
} }
static TestResult static void
single_test_context_with_test(TestState *s) single_test_context_with_test(TestState *s, void *ptr)
{ {
SingleTestContextWith *d = s->ptr; SingleTestContextWith *d = ptr;
s->ptr = d->ptr; run_test_with(s, d->test, d->val);
return (*d->test)(s, d->val);
} }
static void static void