refactored test_context_with()
This commit is contained in:
parent
1c4fb1e87d
commit
ad4abe68e0
39
9unit.c
39
9unit.c
|
@ -49,11 +49,12 @@ struct ContextData
|
||||||
char *new_fc; // new full context
|
char *new_fc; // new full context
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// data needed by test_context_with()
|
||||||
struct TestContextWith
|
struct TestContextWith
|
||||||
{
|
{
|
||||||
void *ptr; // state's original ptr value
|
void *ptr; // state's original ptr value
|
||||||
void *val; // the value being passed in
|
|
||||||
void (*test)(TestState *, void *); // the test function
|
void (*test)(TestState *, void *); // the test function
|
||||||
|
void *val; // the value being passed in
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SingleTestContextWith
|
struct SingleTestContextWith
|
||||||
|
@ -205,16 +206,6 @@ test_context(
|
||||||
else (*test)(s);
|
else (*test)(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
single_test_context(
|
|
||||||
TestState *s,
|
|
||||||
const char *context,
|
|
||||||
TestResult (*test)(TestState *)
|
|
||||||
)
|
|
||||||
{
|
|
||||||
test_context_with(s, context, single_test_context_test, test);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
test_context_with(
|
test_context_with(
|
||||||
TestState *s,
|
TestState *s,
|
||||||
|
@ -223,15 +214,25 @@ test_context_with(
|
||||||
void *val
|
void *val
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (!(s && test)) return;
|
if (!s) return;
|
||||||
TestContextWith d;
|
TestContextWith d;
|
||||||
d.ptr = s->ptr;
|
d.ptr = s->ptr;
|
||||||
d.val = val;
|
|
||||||
d.test = test;
|
d.test = test;
|
||||||
|
d.val = val;
|
||||||
s->ptr = &d;
|
s->ptr = &d;
|
||||||
test_context(s, context, test_context_with_test);
|
test_context(s, context, test_context_with_test);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
single_test_context(
|
||||||
|
TestState *s,
|
||||||
|
const char *context,
|
||||||
|
TestResult (*test)(TestState *)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
test_context_with(s, context, single_test_context_test, test);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
single_test_context_with(
|
single_test_context_with(
|
||||||
TestState *s,
|
TestState *s,
|
||||||
|
@ -371,12 +372,6 @@ run_test_with_test(TestState *s)
|
||||||
return (*d->test)(s, d->val);
|
return (*d->test)(s, d->val);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
single_test_context_test(TestState *s, void *test)
|
|
||||||
{
|
|
||||||
run_test(s, test);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_context_with_test(TestState *s)
|
test_context_with_test(TestState *s)
|
||||||
{
|
{
|
||||||
|
@ -385,6 +380,12 @@ test_context_with_test(TestState *s)
|
||||||
(*d->test)(s, d->val);
|
(*d->test)(s, d->val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
single_test_context_test(TestState *s, void *test)
|
||||||
|
{
|
||||||
|
run_test(s, test);
|
||||||
|
}
|
||||||
|
|
||||||
static TestResult
|
static TestResult
|
||||||
single_test_context_with_test(TestState *s)
|
single_test_context_with_test(TestState *s)
|
||||||
{
|
{
|
||||||
|
|
14
9unit.h
14
9unit.h
|
@ -94,13 +94,6 @@ extern void test_context(
|
||||||
void (*)(TestState *) // the actual test
|
void (*)(TestState *) // the actual test
|
||||||
);
|
);
|
||||||
|
|
||||||
// Runs a single test with a context label
|
|
||||||
extern void single_test_context(
|
|
||||||
TestState *, // the current state
|
|
||||||
const char *, // a description of the context
|
|
||||||
TestResult (*)(TestState *) // the actual test
|
|
||||||
);
|
|
||||||
|
|
||||||
// Runs a test with a context and an additional input
|
// Runs a test with a context and an additional input
|
||||||
extern void test_context_with(
|
extern void test_context_with(
|
||||||
TestState *, // the current state
|
TestState *, // the current state
|
||||||
|
@ -109,6 +102,13 @@ extern void test_context_with(
|
||||||
void * // the value being passed in
|
void * // the value being passed in
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Runs a single test with a context label
|
||||||
|
extern void single_test_context(
|
||||||
|
TestState *, // the current state
|
||||||
|
const char *, // a description of the context
|
||||||
|
TestResult (*)(TestState *) // the actual test
|
||||||
|
);
|
||||||
|
|
||||||
// Runs a single test with a context and input
|
// Runs a single test with a context and input
|
||||||
extern void single_test_context_with(
|
extern void single_test_context_with(
|
||||||
TestState *, // the state
|
TestState *, // the state
|
||||||
|
|
Loading…
Reference in New Issue
Block a user