diff --git a/9unit.c b/9unit.c index 958f3a1..7345514 100644 --- a/9unit.c +++ b/9unit.c @@ -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 diff --git a/9unit.h b/9unit.h index 0e5fd37..c0e9b31 100644 --- a/9unit.h +++ b/9unit.h @@ -115,6 +115,22 @@ extern void test_context_with( void * // the value being passed in ); +// Passes two values into a test context +void test_context_compare( + TestState *, // the current state + const char *, // the context label + + // test function + void (*)( + TestState *, // the current state + void *, // the first value + void * // the second value + ), + + void *, // the first value + void * // the second value +); + // Runs a single test with a context label extern void single_test_context( TestState *, // the current state @@ -136,20 +152,4 @@ extern void single_test_context_with( void * // the value being passed ); -// Runs a test to check a value -extern void check_value( - TestState *, // the current test state - const char *, // a description of the context - - // the test function - void (*)( - TestState *, - void *, // the check value - void * // the reference value - ), - - void *, // the value being checked - void * // the reference value -); - //jl