implemented check_value()
This commit is contained in:
parent
0ad79ea3b0
commit
a7351b5667
38
9unit.c
38
9unit.c
@ -33,6 +33,9 @@ typedef struct ContextData ContextData;
|
|||||||
// data required to run a single test with a label
|
// data required to run a single test with a label
|
||||||
typedef struct SingleTestContext SingleTestContext;
|
typedef struct SingleTestContext SingleTestContext;
|
||||||
|
|
||||||
|
// data used by check_value()
|
||||||
|
typedef struct CheckValueData CheckValueData;
|
||||||
|
|
||||||
struct ContextData
|
struct ContextData
|
||||||
{
|
{
|
||||||
const char *old_c; // previous context
|
const char *old_c; // previous context
|
||||||
@ -47,6 +50,14 @@ struct SingleTestContext
|
|||||||
TestResult (*test)(TestState *); // the test to run
|
TestResult (*test)(TestState *); // the test to run
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct CheckValueData
|
||||||
|
{
|
||||||
|
void *ptr; // state's original ptr value
|
||||||
|
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 *);
|
||||||
@ -58,6 +69,7 @@ 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 run_single_test_context(TestState *);
|
static void run_single_test_context(TestState *);
|
||||||
|
static void check_value_test(TestState *);
|
||||||
|
|
||||||
// Public Functions
|
// Public Functions
|
||||||
|
|
||||||
@ -172,6 +184,24 @@ single_test_context(
|
|||||||
test_context(s, label, run_single_test_context);
|
test_context(s, label, run_single_test_context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void check_value(
|
||||||
|
TestState *s,
|
||||||
|
const char *context,
|
||||||
|
void *chk_val,
|
||||||
|
void *ref_val,
|
||||||
|
void (*test)(TestState *, void *, void *)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (!(s && test)) return;
|
||||||
|
CheckValueData d;
|
||||||
|
d.ptr = s->ptr;
|
||||||
|
d.chk_val = chk_val;
|
||||||
|
d.ref_val = ref_val;
|
||||||
|
d.test = test;
|
||||||
|
s->ptr = &d;
|
||||||
|
test_context(s, context, check_value_test);
|
||||||
|
}
|
||||||
|
|
||||||
// Internal Functions
|
// Internal Functions
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -276,4 +306,12 @@ run_single_test_context(TestState *s)
|
|||||||
run_test(s, stc->test);
|
run_test(s, stc->test);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
check_value_test(TestState *s)
|
||||||
|
{
|
||||||
|
CheckValueData *d = s->ptr;
|
||||||
|
s->ptr = d->ptr;
|
||||||
|
(*d->test)(s, d->chk_val, d->ref_val);
|
||||||
|
}
|
||||||
|
|
||||||
//jl
|
//jl
|
||||||
|
13
9unit.h
13
9unit.h
@ -94,4 +94,17 @@ extern void single_test_context(
|
|||||||
TestResult (*)(TestState *) // the actual test
|
TestResult (*)(TestState *) // the actual test
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Runs a test to check a value
|
||||||
|
extern void check_value(
|
||||||
|
TestState *, // the current test state
|
||||||
|
const char *, // a description of the context
|
||||||
|
void *, // the value being checked
|
||||||
|
void *, // the reference value
|
||||||
|
void (*)( // the test function
|
||||||
|
TestState *,
|
||||||
|
void *, // the check value
|
||||||
|
void * // the reference value
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
//jl
|
//jl
|
||||||
|
Loading…
x
Reference in New Issue
Block a user