refactored single_test_context()

This commit is contained in:
jlamothe 2023-11-19 04:01:10 +00:00
parent 8138f59fef
commit 1c4fb1e87d

24
9unit.c
View File

@ -29,7 +29,6 @@
typedef struct RunTestWith RunTestWith; typedef struct RunTestWith RunTestWith;
typedef struct ContextData ContextData; typedef struct ContextData ContextData;
typedef struct SingleTestContext SingleTestContext;
typedef struct TestContextWith TestContextWith; typedef struct TestContextWith TestContextWith;
typedef struct SingleTestContextWith SingleTestContextWith; typedef struct SingleTestContextWith SingleTestContextWith;
typedef struct CheckValue CheckValue; typedef struct CheckValue CheckValue;
@ -50,12 +49,6 @@ struct ContextData
char *new_fc; // new full context char *new_fc; // new full context
}; };
struct SingleTestContext
{
void *ptr; // the state's previous ptr value
TestResult (*test)(TestState *); // the test to run
};
struct TestContextWith struct TestContextWith
{ {
void *ptr; // state's original ptr value void *ptr; // state's original ptr value
@ -88,7 +81,7 @@ static TestResult run_test_with_test(TestState *);
static void build_new_context(TestState *, ContextData *); static void build_new_context(TestState *, ContextData *);
static void display_context(TestState *); static void display_context(TestState *);
static void restore_context(TestState *, ContextData *); static void restore_context(TestState *, ContextData *);
static void single_test_context_test(TestState *); 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 TestResult single_test_context_with_test(TestState *);
static void check_value_test(TestState *, void *); static void check_value_test(TestState *, void *);
@ -215,16 +208,11 @@ test_context(
void void
single_test_context( single_test_context(
TestState *s, TestState *s,
const char *label, const char *context,
TestResult (*test)(TestState *) TestResult (*test)(TestState *)
) )
{ {
if (!s) return; test_context_with(s, context, single_test_context_test, test);
SingleTestContext d;
d.ptr = s->ptr;
d.test = test;
s->ptr = &d;
test_context(s, label, single_test_context_test);
} }
void void
@ -384,11 +372,9 @@ run_test_with_test(TestState *s)
} }
static void static void
single_test_context_test(TestState *s) single_test_context_test(TestState *s, void *test)
{ {
SingleTestContext *d = s->ptr; run_test(s, test);
s->ptr = d->ptr;
run_test(s, d->test);
} }
static void static void