From 37ce34b160db24738b90a0504373fea9294d6d25 Mon Sep 17 00:00:00 2001 From: jlamothe Date: Fri, 17 Nov 2023 23:07:05 +0000 Subject: [PATCH] made check_value() use test_context_with() eliminates some redundant code --- 9unit.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/9unit.c b/9unit.c index 39b4398..012fdba 100644 --- a/9unit.c +++ b/9unit.c @@ -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); }