diff --git a/9unit.c b/9unit.c index 7345514..d24e295 100644 --- a/9unit.c +++ b/9unit.c @@ -33,6 +33,7 @@ typedef struct ContextData ContextData; typedef struct TestContextWith TestContextWith; typedef struct TestContextCompare TestContextCompare; typedef struct SingleTestContextWith SingleTestContextWith; +typedef struct SingleTestContextCompare SingleTestContextCompare; // data required by run_test_with() struct RunTestWith @@ -81,6 +82,14 @@ struct SingleTestContextWith void *val; }; +// data needed by single_test_context_compare() +struct SingleTestContextCompare +{ + TestResult (*test)(TestState *, void *, void *); + void *val1; + void *val2; +}; + // Internal Prototypes static void init_TestState(TestState *); @@ -97,6 +106,7 @@ 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 TestResult single_test_context_compare_test(TestState *, void *); // Public Functions @@ -299,6 +309,27 @@ single_test_context_with( ); } +void +single_test_context_compare( + TestState *s, + const char *context, + TestResult (*test)(TestState *s, void *, void *), + void *val1, + void *val2 +) +{ + SingleTestContextCompare d; + d.test = test; + d.val1 = val1; + d.val2 = val2; + single_test_context_with( + s, + context, + single_test_context_compare_test, + &d + ); +} + // Internal Functions static void @@ -444,4 +475,11 @@ single_test_context_with_test(TestState *s, void *ptr) run_test_with(s, d->test, d->val); } +static TestResult +single_test_context_compare_test(TestState *s, void *ptr) +{ + SingleTestContextCompare *d = ptr; + return (*d->test)(s, d->val1, d->val2); +} + //jl diff --git a/9unit.h b/9unit.h index c0e9b31..d102554 100644 --- a/9unit.h +++ b/9unit.h @@ -152,4 +152,21 @@ extern void single_test_context_with( void * // the value being passed ); +// Runs a single test with a context, passing it two values to be +// compared +extern void single_test_context_compare( + TestState *, // the state + const char *, // the context + + // the test function + TestResult (*)( + TestState *, // the state + void *, // the first value + void * // the second value + ), + + void *, // the first value + void * // the second value +); + //jl