implemented single_test_context_compare()

This commit is contained in:
jlamothe 2023-11-20 03:58:21 +00:00
parent eaa8ae06a7
commit 24ed9060ba
2 changed files with 55 additions and 0 deletions

38
9unit.c
View File

@ -33,6 +33,7 @@ typedef struct ContextData ContextData;
typedef struct TestContextWith TestContextWith; typedef struct TestContextWith TestContextWith;
typedef struct TestContextCompare TestContextCompare; typedef struct TestContextCompare TestContextCompare;
typedef struct SingleTestContextWith SingleTestContextWith; typedef struct SingleTestContextWith SingleTestContextWith;
typedef struct SingleTestContextCompare SingleTestContextCompare;
// data required by run_test_with() // data required by run_test_with()
struct RunTestWith struct RunTestWith
@ -81,6 +82,14 @@ struct SingleTestContextWith
void *val; void *val;
}; };
// data needed by single_test_context_compare()
struct SingleTestContextCompare
{
TestResult (*test)(TestState *, void *, void *);
void *val1;
void *val2;
};
// Internal Prototypes // Internal Prototypes
static void init_TestState(TestState *); 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 test_context_compare_test(TestState *, void *);
static void single_test_context_test(TestState *, void *); static void single_test_context_test(TestState *, void *);
static void single_test_context_with_test(TestState *, void *); static void single_test_context_with_test(TestState *, void *);
static TestResult single_test_context_compare_test(TestState *, void *);
// Public Functions // 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 // Internal Functions
static void static void
@ -444,4 +475,11 @@ single_test_context_with_test(TestState *s, void *ptr)
run_test_with(s, d->test, d->val); 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 //jl

17
9unit.h
View File

@ -152,4 +152,21 @@ extern void single_test_context_with(
void * // the value being passed 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 //jl