implemented test_context_with()
This commit is contained in:
parent
7818e3d646
commit
5d67b7aeb8
39
9unit.c
39
9unit.c
|
@ -33,6 +33,9 @@ typedef struct ContextData ContextData;
|
||||||
// data required to run a single test with a label
|
// data required to run a single test with a label
|
||||||
typedef struct SingleTestContext SingleTestContext;
|
typedef struct SingleTestContext SingleTestContext;
|
||||||
|
|
||||||
|
// data required by test_context_with()
|
||||||
|
typedef struct TestContextWith TestContextWith;
|
||||||
|
|
||||||
// data used by check_value()
|
// data used by check_value()
|
||||||
typedef struct CheckValueData CheckValueData;
|
typedef struct CheckValueData CheckValueData;
|
||||||
|
|
||||||
|
@ -50,6 +53,13 @@ struct SingleTestContext
|
||||||
TestResult (*test)(TestState *); // the test to run
|
TestResult (*test)(TestState *); // the test to run
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct TestContextWith
|
||||||
|
{
|
||||||
|
void *ptr; // state's original ptr value
|
||||||
|
void *val; // the value being passed in
|
||||||
|
void (*test)(TestState *, void *); // the test function
|
||||||
|
};
|
||||||
|
|
||||||
struct CheckValueData
|
struct CheckValueData
|
||||||
{
|
{
|
||||||
void *ptr; // state's original ptr value
|
void *ptr; // state's original ptr value
|
||||||
|
@ -69,6 +79,7 @@ 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 run_single_test_context(TestState *);
|
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 *);
|
||||||
|
|
||||||
// Public Functions
|
// Public Functions
|
||||||
|
@ -184,7 +195,25 @@ single_test_context(
|
||||||
test_context(s, label, run_single_test_context);
|
test_context(s, label, run_single_test_context);
|
||||||
}
|
}
|
||||||
|
|
||||||
void check_value(
|
void
|
||||||
|
test_context_with(
|
||||||
|
TestState *s,
|
||||||
|
const char *context,
|
||||||
|
void (*test)(TestState *, void *),
|
||||||
|
void *val
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (!(s && test)) return;
|
||||||
|
TestContextWith d;
|
||||||
|
d.ptr = s->ptr;
|
||||||
|
d.val = val;
|
||||||
|
d.test = test;
|
||||||
|
s->ptr = &d;
|
||||||
|
test_context(s, context, test_context_with_test);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
check_value(
|
||||||
TestState *s,
|
TestState *s,
|
||||||
const char *context,
|
const char *context,
|
||||||
void (*test)(TestState *, void *, void *),
|
void (*test)(TestState *, void *, void *),
|
||||||
|
@ -306,6 +335,14 @@ run_single_test_context(TestState *s)
|
||||||
run_test(s, stc->test);
|
run_test(s, stc->test);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_context_with_test(TestState *s)
|
||||||
|
{
|
||||||
|
TestContextWith *d = s->ptr;
|
||||||
|
s->ptr = d->ptr;
|
||||||
|
(*d->test)(s, d->val);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
check_value_test(TestState *s)
|
check_value_test(TestState *s)
|
||||||
{
|
{
|
||||||
|
|
8
9unit.h
8
9unit.h
|
@ -94,6 +94,14 @@ extern void single_test_context(
|
||||||
TestResult (*)(TestState *) // the actual test
|
TestResult (*)(TestState *) // the actual test
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Runs a test with a context and an additional input
|
||||||
|
extern void test_context_with(
|
||||||
|
TestState *, // the current state
|
||||||
|
const char *, // a description of the context
|
||||||
|
void (*)(TestState *, void *), // the test function
|
||||||
|
void * // the value being passed in
|
||||||
|
);
|
||||||
|
|
||||||
// Runs a test to check a value
|
// Runs a test to check a value
|
||||||
extern void check_value(
|
extern void check_value(
|
||||||
TestState *, // the current test state
|
TestState *, // the current test state
|
||||||
|
|
Loading…
Reference in New Issue
Block a user