implemented run_test_compare()
This commit is contained in:
parent
01e01243dd
commit
55926ec0d8
35
9unit.c
35
9unit.c
|
@ -28,6 +28,7 @@
|
||||||
// Internal Types
|
// Internal Types
|
||||||
|
|
||||||
typedef struct RunTestWith RunTestWith;
|
typedef struct RunTestWith RunTestWith;
|
||||||
|
typedef struct RunTestCompare RunTestCompare;
|
||||||
typedef struct ContextData ContextData;
|
typedef struct ContextData ContextData;
|
||||||
typedef struct TestContextWith TestContextWith;
|
typedef struct TestContextWith TestContextWith;
|
||||||
typedef struct SingleTestContextWith SingleTestContextWith;
|
typedef struct SingleTestContextWith SingleTestContextWith;
|
||||||
|
@ -41,6 +42,14 @@ struct RunTestWith
|
||||||
void *val; // the value passed in
|
void *val; // the value passed in
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// data needed by run_test_compare()
|
||||||
|
struct RunTestCompare
|
||||||
|
{
|
||||||
|
TestResult (*test)(TestState *, void *, void *);
|
||||||
|
void *val1;
|
||||||
|
void *val2;
|
||||||
|
};
|
||||||
|
|
||||||
struct ContextData
|
struct ContextData
|
||||||
{
|
{
|
||||||
const char *old_c; // previous context
|
const char *old_c; // previous context
|
||||||
|
@ -79,6 +88,7 @@ static void clear_log(TestState *);
|
||||||
static void reindex(TestState *);
|
static void reindex(TestState *);
|
||||||
static void report(const char *);
|
static void report(const char *);
|
||||||
static TestResult run_test_with_test(TestState *);
|
static TestResult run_test_with_test(TestState *);
|
||||||
|
static TestResult run_test_compare_test(TestState *, void *);
|
||||||
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 *);
|
||||||
|
@ -139,6 +149,21 @@ run_test_with(
|
||||||
run_test(s, run_test_with_test);
|
run_test(s, run_test_with_test);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
run_test_compare(
|
||||||
|
TestState *s,
|
||||||
|
TestResult (*test)(TestState *, void *, void *),
|
||||||
|
void *val1,
|
||||||
|
void *val2
|
||||||
|
)
|
||||||
|
{
|
||||||
|
RunTestCompare d;
|
||||||
|
d.test = test;
|
||||||
|
d.val1 = val1;
|
||||||
|
d.val2 = val2;
|
||||||
|
run_test_with(s, run_test_compare_test, &d);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
run_tests(void (*tests)(TestState *))
|
run_tests(void (*tests)(TestState *))
|
||||||
{
|
{
|
||||||
|
@ -373,6 +398,16 @@ run_test_with_test(TestState *s)
|
||||||
return (*d->test)(s, d->val);
|
return (*d->test)(s, d->val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static TestResult
|
||||||
|
run_test_compare_test(
|
||||||
|
TestState *s,
|
||||||
|
void *ptr
|
||||||
|
)
|
||||||
|
{
|
||||||
|
RunTestCompare *d = ptr;
|
||||||
|
return (*d->test)(s, d->val1, d->val2);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_context_with_test(TestState *s)
|
test_context_with_test(TestState *s)
|
||||||
{
|
{
|
||||||
|
|
15
9unit.h
15
9unit.h
|
@ -74,6 +74,21 @@ extern void run_test_with(
|
||||||
void * // the value to pass in
|
void * // the value to pass in
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Runs a single test passing in two values to be compared
|
||||||
|
extern void run_test_compare(
|
||||||
|
TestState *, // the current state
|
||||||
|
|
||||||
|
// the test to be run
|
||||||
|
TestResult (*test)(
|
||||||
|
TestState *, // the current state
|
||||||
|
void *, // the first value
|
||||||
|
void * // the second value
|
||||||
|
),
|
||||||
|
|
||||||
|
void *, // the first value
|
||||||
|
void * // the second value
|
||||||
|
);
|
||||||
|
|
||||||
// Creates an initial TestState, passes it to the supplied function,
|
// Creates an initial TestState, passes it to the supplied function,
|
||||||
// and displays the resulting log and summary
|
// and displays the resulting log and summary
|
||||||
extern void run_tests(void (*)(TestState *));
|
extern void run_tests(void (*)(TestState *));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user