|
|
|
@@ -27,12 +27,20 @@
|
|
|
|
|
|
|
|
|
|
// Internal Types
|
|
|
|
|
|
|
|
|
|
typedef struct RunTestWith RunTestWith;
|
|
|
|
|
typedef struct ContextData ContextData;
|
|
|
|
|
typedef struct SingleTestContext SingleTestContext;
|
|
|
|
|
typedef struct TestContextWith TestContextWith;
|
|
|
|
|
typedef struct SingleTestContextWith SingleTestContextWith;
|
|
|
|
|
typedef struct CheckValue CheckValue;
|
|
|
|
|
|
|
|
|
|
// data required by run_test_with()
|
|
|
|
|
struct RunTestWith
|
|
|
|
|
{
|
|
|
|
|
void *ptr; // the state's previous ptr value
|
|
|
|
|
TestResult (*test)(TestState *, void *); // the test
|
|
|
|
|
void *val; // the value passed in
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct ContextData
|
|
|
|
|
{
|
|
|
|
|
const char *old_c; // previous context
|
|
|
|
@@ -41,22 +49,17 @@ struct ContextData
|
|
|
|
|
char *new_fc; // new full context
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SingleTestContext
|
|
|
|
|
{
|
|
|
|
|
void *ptr; // the state's previous ptr value
|
|
|
|
|
TestResult (*test)(TestState *); // the test to run
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// data needed by test_context_with()
|
|
|
|
|
struct TestContextWith
|
|
|
|
|
{
|
|
|
|
|
void *ptr; // state's original ptr value
|
|
|
|
|
void *val; // the value being passed in
|
|
|
|
|
void (*test)(TestState *, void *); // the test function
|
|
|
|
|
void *val; // the value being passed in
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// data needed by single_test_context_with()
|
|
|
|
|
struct SingleTestContextWith
|
|
|
|
|
{
|
|
|
|
|
void *ptr;
|
|
|
|
|
TestResult (*test)(TestState *, void *);
|
|
|
|
|
void *val;
|
|
|
|
|
};
|
|
|
|
@@ -79,9 +82,9 @@ static TestResult run_test_with_test(TestState *);
|
|
|
|
|
static void build_new_context(TestState *, ContextData *);
|
|
|
|
|
static void display_context(TestState *);
|
|
|
|
|
static void restore_context(TestState *, ContextData *);
|
|
|
|
|
static void single_test_context_test(TestState *);
|
|
|
|
|
static void single_test_context_test(TestState *, void *);
|
|
|
|
|
static void test_context_with_test(TestState *);
|
|
|
|
|
static TestResult single_test_context_with_test(TestState *);
|
|
|
|
|
static void single_test_context_with_test(TestState *, void *);
|
|
|
|
|
static void check_value_test(TestState *, void *);
|
|
|
|
|
|
|
|
|
|
// Public Functions
|
|
|
|
@@ -122,7 +125,18 @@ run_test_with(
|
|
|
|
|
void *val // the value being passed in
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
single_test_context_with(s, 0, test, val);
|
|
|
|
|
if (!s) return;
|
|
|
|
|
if (!test)
|
|
|
|
|
{
|
|
|
|
|
run_test(s, 0);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
RunTestWith d;
|
|
|
|
|
d.ptr = s->ptr;
|
|
|
|
|
d.test = test;
|
|
|
|
|
d.val = val;
|
|
|
|
|
s->ptr = &d;
|
|
|
|
|
run_test(s, run_test_with_test);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
@@ -192,21 +206,6 @@ test_context(
|
|
|
|
|
else (*test)(s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
single_test_context(
|
|
|
|
|
TestState *s,
|
|
|
|
|
const char *label,
|
|
|
|
|
TestResult (*test)(TestState *)
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
if (!s) return;
|
|
|
|
|
SingleTestContext d;
|
|
|
|
|
d.ptr = s->ptr;
|
|
|
|
|
d.test = test;
|
|
|
|
|
s->ptr = &d;
|
|
|
|
|
test_context(s, label, single_test_context_test);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
test_context_with(
|
|
|
|
|
TestState *s,
|
|
|
|
@@ -215,15 +214,25 @@ test_context_with(
|
|
|
|
|
void *val
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
if (!(s && test)) return;
|
|
|
|
|
if (!s) return;
|
|
|
|
|
TestContextWith d;
|
|
|
|
|
d.ptr = s->ptr;
|
|
|
|
|
d.val = val;
|
|
|
|
|
d.test = test;
|
|
|
|
|
d.val = val;
|
|
|
|
|
s->ptr = &d;
|
|
|
|
|
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
|
|
|
|
|
single_test_context_with(
|
|
|
|
|
TestState *s,
|
|
|
|
@@ -232,14 +241,15 @@ single_test_context_with(
|
|
|
|
|
void *val
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
if (!s) return;
|
|
|
|
|
if (!test) single_test_context(s, context, 0);
|
|
|
|
|
SingleTestContextWith d;
|
|
|
|
|
d.ptr = s->ptr;
|
|
|
|
|
d.test = test;
|
|
|
|
|
d.val = val;
|
|
|
|
|
s->ptr = &d;
|
|
|
|
|
single_test_context(s, context, single_test_context_with_test);
|
|
|
|
|
test_context_with(
|
|
|
|
|
s,
|
|
|
|
|
context,
|
|
|
|
|
single_test_context_with_test,
|
|
|
|
|
&d
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
@@ -355,12 +365,12 @@ restore_context(TestState *s, ContextData *cd)
|
|
|
|
|
free(cd->new_fc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
single_test_context_test(TestState *s)
|
|
|
|
|
static TestResult
|
|
|
|
|
run_test_with_test(TestState *s)
|
|
|
|
|
{
|
|
|
|
|
SingleTestContext *d = s->ptr;
|
|
|
|
|
RunTestWith *d = s->ptr;
|
|
|
|
|
s->ptr = d->ptr;
|
|
|
|
|
run_test(s, d->test);
|
|
|
|
|
return (*d->test)(s, d->val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
@@ -371,12 +381,17 @@ test_context_with_test(TestState *s)
|
|
|
|
|
(*d->test)(s, d->val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static TestResult
|
|
|
|
|
single_test_context_with_test(TestState *s)
|
|
|
|
|
static void
|
|
|
|
|
single_test_context_test(TestState *s, void *test)
|
|
|
|
|
{
|
|
|
|
|
SingleTestContextWith *d = s->ptr;
|
|
|
|
|
s->ptr = d->ptr;
|
|
|
|
|
return (*d->test)(s, d->val);
|
|
|
|
|
run_test(s, test);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
single_test_context_with_test(TestState *s, void *ptr)
|
|
|
|
|
{
|
|
|
|
|
SingleTestContextWith *d = ptr;
|
|
|
|
|
run_test_with(s, d->test, d->val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|