renamed check_values() to test_context_compare() and reimplemented
This commit is contained in:
parent
f808eb4cb0
commit
eaa8ae06a7
76
9unit.c
76
9unit.c
|
@ -31,8 +31,8 @@ typedef struct RunTestWith RunTestWith;
|
||||||
typedef struct RunTestCompare RunTestCompare;
|
typedef struct RunTestCompare RunTestCompare;
|
||||||
typedef struct ContextData ContextData;
|
typedef struct ContextData ContextData;
|
||||||
typedef struct TestContextWith TestContextWith;
|
typedef struct TestContextWith TestContextWith;
|
||||||
|
typedef struct TestContextCompare TestContextCompare;
|
||||||
typedef struct SingleTestContextWith SingleTestContextWith;
|
typedef struct SingleTestContextWith SingleTestContextWith;
|
||||||
typedef struct CheckValue CheckValue;
|
|
||||||
|
|
||||||
// data required by run_test_with()
|
// data required by run_test_with()
|
||||||
struct RunTestWith
|
struct RunTestWith
|
||||||
|
@ -66,6 +66,14 @@ struct TestContextWith
|
||||||
void *val; // the value being passed in
|
void *val; // the value being passed in
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// data needed by test_context_compare()
|
||||||
|
struct TestContextCompare
|
||||||
|
{
|
||||||
|
void (*test)(TestState *, void *, void *);
|
||||||
|
void *val1;
|
||||||
|
void *val2;
|
||||||
|
};
|
||||||
|
|
||||||
// data needed by single_test_context_with()
|
// data needed by single_test_context_with()
|
||||||
struct SingleTestContextWith
|
struct SingleTestContextWith
|
||||||
{
|
{
|
||||||
|
@ -73,13 +81,6 @@ struct SingleTestContextWith
|
||||||
void *val;
|
void *val;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CheckValue
|
|
||||||
{
|
|
||||||
void *chk_val; // the value being checked
|
|
||||||
void *ref_val; // the reference value
|
|
||||||
void (*test)(TestState *, void *, void *); // the test
|
|
||||||
};
|
|
||||||
|
|
||||||
// Internal Prototypes
|
// Internal Prototypes
|
||||||
|
|
||||||
static void init_TestState(TestState *);
|
static void init_TestState(TestState *);
|
||||||
|
@ -92,10 +93,10 @@ static void display_context(TestState *);
|
||||||
static void restore_context(TestState *, ContextData *);
|
static void restore_context(TestState *, ContextData *);
|
||||||
static TestResult run_test_with_test(TestState *);
|
static TestResult run_test_with_test(TestState *);
|
||||||
static TestResult run_test_compare_test(TestState *, void *);
|
static TestResult run_test_compare_test(TestState *, void *);
|
||||||
static void single_test_context_test(TestState *, void *);
|
|
||||||
static void test_context_with_test(TestState *);
|
static void test_context_with_test(TestState *);
|
||||||
|
static void test_context_compare_test(TestState *, void *);
|
||||||
|
static void single_test_context_test(TestState *, void *);
|
||||||
static void single_test_context_with_test(TestState *, void *);
|
static void single_test_context_with_test(TestState *, void *);
|
||||||
static void check_value_test(TestState *, void *);
|
|
||||||
|
|
||||||
// Public Functions
|
// Public Functions
|
||||||
|
|
||||||
|
@ -248,6 +249,27 @@ test_context_with(
|
||||||
test_context(s, context, test_context_with_test);
|
test_context(s, context, test_context_with_test);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
test_context_compare(
|
||||||
|
TestState *s,
|
||||||
|
const char *context,
|
||||||
|
void (*test)(TestState *, void *, void *),
|
||||||
|
void *val1,
|
||||||
|
void *val2
|
||||||
|
)
|
||||||
|
{
|
||||||
|
TestContextCompare d;
|
||||||
|
d.test = test;
|
||||||
|
d.val1 = val1;
|
||||||
|
d.val2 = val2;
|
||||||
|
test_context_with(
|
||||||
|
s,
|
||||||
|
context,
|
||||||
|
test_context_compare_test,
|
||||||
|
&d
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
single_test_context(
|
single_test_context(
|
||||||
TestState *s,
|
TestState *s,
|
||||||
|
@ -277,23 +299,6 @@ single_test_context_with(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
check_value(
|
|
||||||
TestState *s,
|
|
||||||
const char *context,
|
|
||||||
void (*test)(TestState *, void *, void *),
|
|
||||||
void *chk_val,
|
|
||||||
void *ref_val
|
|
||||||
)
|
|
||||||
{
|
|
||||||
if (!(s && test)) return;
|
|
||||||
CheckValue d;
|
|
||||||
d.chk_val = chk_val;
|
|
||||||
d.ref_val = ref_val;
|
|
||||||
d.test = test;
|
|
||||||
test_context_with(s, context, check_value_test, &d);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Internal Functions
|
// Internal Functions
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -416,6 +421,16 @@ test_context_with_test(TestState *s)
|
||||||
(*d->test)(s, d->val);
|
(*d->test)(s, d->val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_context_compare_test(
|
||||||
|
TestState *s,
|
||||||
|
void *ptr
|
||||||
|
)
|
||||||
|
{
|
||||||
|
TestContextCompare *d = ptr;
|
||||||
|
(*d->test)(s, d->val1, d->val2);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
single_test_context_test(TestState *s, void *test)
|
single_test_context_test(TestState *s, void *test)
|
||||||
{
|
{
|
||||||
|
@ -429,11 +444,4 @@ single_test_context_with_test(TestState *s, void *ptr)
|
||||||
run_test_with(s, d->test, d->val);
|
run_test_with(s, d->test, d->val);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
check_value_test(TestState *s, void *ptr)
|
|
||||||
{
|
|
||||||
CheckValue *d = ptr;
|
|
||||||
(*d->test)(s, d->chk_val, d->ref_val);
|
|
||||||
}
|
|
||||||
|
|
||||||
//jl
|
//jl
|
||||||
|
|
32
9unit.h
32
9unit.h
|
@ -115,6 +115,22 @@ extern void test_context_with(
|
||||||
void * // the value being passed in
|
void * // the value being passed in
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Passes two values into a test context
|
||||||
|
void test_context_compare(
|
||||||
|
TestState *, // the current state
|
||||||
|
const char *, // the context label
|
||||||
|
|
||||||
|
// test function
|
||||||
|
void (*)(
|
||||||
|
TestState *, // the current state
|
||||||
|
void *, // the first value
|
||||||
|
void * // the second value
|
||||||
|
),
|
||||||
|
|
||||||
|
void *, // the first value
|
||||||
|
void * // the second value
|
||||||
|
);
|
||||||
|
|
||||||
// Runs a single test with a context label
|
// Runs a single test with a context label
|
||||||
extern void single_test_context(
|
extern void single_test_context(
|
||||||
TestState *, // the current state
|
TestState *, // the current state
|
||||||
|
@ -136,20 +152,4 @@ extern void single_test_context_with(
|
||||||
void * // the value being passed
|
void * // the value being passed
|
||||||
);
|
);
|
||||||
|
|
||||||
// Runs a test to check a value
|
|
||||||
extern void check_value(
|
|
||||||
TestState *, // the current test state
|
|
||||||
const char *, // a description of the context
|
|
||||||
|
|
||||||
// the test function
|
|
||||||
void (*)(
|
|
||||||
TestState *,
|
|
||||||
void *, // the check value
|
|
||||||
void * // the reference value
|
|
||||||
),
|
|
||||||
|
|
||||||
void *, // the value being checked
|
|
||||||
void * // the reference value
|
|
||||||
);
|
|
||||||
|
|
||||||
//jl
|
//jl
|
||||||
|
|
Loading…
Reference in New Issue
Block a user