Compare commits
4
Commits
cd590339b7
...
291d25927c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
291d25927c | ||
|
|
ad4abe68e0 | ||
|
|
1c4fb1e87d | ||
|
|
8138f59fef |
@@ -27,12 +27,20 @@
|
|||||||
|
|
||||||
// Internal Types
|
// Internal Types
|
||||||
|
|
||||||
|
typedef struct RunTestWith RunTestWith;
|
||||||
typedef struct ContextData ContextData;
|
typedef struct ContextData ContextData;
|
||||||
typedef struct SingleTestContext SingleTestContext;
|
|
||||||
typedef struct TestContextWith TestContextWith;
|
typedef struct TestContextWith TestContextWith;
|
||||||
typedef struct SingleTestContextWith SingleTestContextWith;
|
typedef struct SingleTestContextWith SingleTestContextWith;
|
||||||
typedef struct CheckValue CheckValue;
|
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
|
struct ContextData
|
||||||
{
|
{
|
||||||
const char *old_c; // previous context
|
const char *old_c; // previous context
|
||||||
@@ -41,22 +49,17 @@ struct ContextData
|
|||||||
char *new_fc; // new full context
|
char *new_fc; // new full context
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SingleTestContext
|
// data needed by test_context_with()
|
||||||
{
|
|
||||||
void *ptr; // the state's previous ptr value
|
|
||||||
TestResult (*test)(TestState *); // the test to run
|
|
||||||
};
|
|
||||||
|
|
||||||
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
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// data needed by single_test_context_with()
|
||||||
struct SingleTestContextWith
|
struct SingleTestContextWith
|
||||||
{
|
{
|
||||||
void *ptr;
|
|
||||||
TestResult (*test)(TestState *, void *);
|
TestResult (*test)(TestState *, void *);
|
||||||
void *val;
|
void *val;
|
||||||
};
|
};
|
||||||
@@ -79,9 +82,9 @@ static TestResult run_test_with_test(TestState *);
|
|||||||
static void build_new_context(TestState *, ContextData *);
|
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 single_test_context_test(TestState *);
|
static void single_test_context_test(TestState *, void *);
|
||||||
static void test_context_with_test(TestState *);
|
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 *);
|
static void check_value_test(TestState *, void *);
|
||||||
|
|
||||||
// Public Functions
|
// Public Functions
|
||||||
@@ -122,7 +125,18 @@ run_test_with(
|
|||||||
void *val // the value being passed in
|
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
|
void
|
||||||
@@ -192,21 +206,6 @@ test_context(
|
|||||||
else (*test)(s);
|
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
|
void
|
||||||
test_context_with(
|
test_context_with(
|
||||||
TestState *s,
|
TestState *s,
|
||||||
@@ -215,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,
|
||||||
@@ -232,14 +241,15 @@ single_test_context_with(
|
|||||||
void *val
|
void *val
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (!s) return;
|
|
||||||
if (!test) single_test_context(s, context, 0);
|
|
||||||
SingleTestContextWith d;
|
SingleTestContextWith d;
|
||||||
d.ptr = s->ptr;
|
|
||||||
d.test = test;
|
d.test = test;
|
||||||
d.val = val;
|
d.val = val;
|
||||||
s->ptr = &d;
|
test_context_with(
|
||||||
single_test_context(s, context, single_test_context_with_test);
|
s,
|
||||||
|
context,
|
||||||
|
single_test_context_with_test,
|
||||||
|
&d
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -355,12 +365,12 @@ restore_context(TestState *s, ContextData *cd)
|
|||||||
free(cd->new_fc);
|
free(cd->new_fc);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static TestResult
|
||||||
single_test_context_test(TestState *s)
|
run_test_with_test(TestState *s)
|
||||||
{
|
{
|
||||||
SingleTestContext *d = s->ptr;
|
RunTestWith *d = s->ptr;
|
||||||
s->ptr = d->ptr;
|
s->ptr = d->ptr;
|
||||||
run_test(s, d->test);
|
return (*d->test)(s, d->val);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -371,12 +381,17 @@ test_context_with_test(TestState *s)
|
|||||||
(*d->test)(s, d->val);
|
(*d->test)(s, d->val);
|
||||||
}
|
}
|
||||||
|
|
||||||
static TestResult
|
static void
|
||||||
single_test_context_with_test(TestState *s)
|
single_test_context_test(TestState *s, void *test)
|
||||||
{
|
{
|
||||||
SingleTestContextWith *d = s->ptr;
|
run_test(s, test);
|
||||||
s->ptr = d->ptr;
|
}
|
||||||
return (*d->test)(s, d->val);
|
|
||||||
|
static void
|
||||||
|
single_test_context_with_test(TestState *s, void *ptr)
|
||||||
|
{
|
||||||
|
SingleTestContextWith *d = ptr;
|
||||||
|
run_test_with(s, d->test, d->val);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user