define and start using single_text_context()
This commit is contained in:
33
9unit.c
33
9unit.c
@@ -30,6 +30,9 @@
|
||||
// data required by the context management functions
|
||||
typedef struct ContextData ContextData;
|
||||
|
||||
// data required to run a single test with a label
|
||||
typedef struct SingleTestContext SingleTestContext;
|
||||
|
||||
struct ContextData
|
||||
{
|
||||
const char *old_c; // previous context
|
||||
@@ -38,6 +41,12 @@ 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
|
||||
};
|
||||
|
||||
// Internal Prototypes
|
||||
|
||||
static void init_TestState(TestState *);
|
||||
@@ -48,6 +57,7 @@ static void report(const char *);
|
||||
static void build_new_context(TestState *, ContextData *);
|
||||
static void display_context(TestState *);
|
||||
static void restore_context(TestState *, ContextData *);
|
||||
static void run_single_test_context(TestState *);
|
||||
|
||||
// Public Functions
|
||||
|
||||
@@ -147,6 +157,21 @@ test_context(
|
||||
else (*test)(s);
|
||||
}
|
||||
|
||||
void
|
||||
single_test_context(
|
||||
TestState *s,
|
||||
const char *label,
|
||||
TestResult (*test)(TestState *)
|
||||
)
|
||||
{
|
||||
if (!s) return;
|
||||
SingleTestContext stc;
|
||||
stc.ptr = s->ptr;
|
||||
stc.test = test;
|
||||
s->ptr = &stc;
|
||||
test_context(s, label, run_single_test_context);
|
||||
}
|
||||
|
||||
// Internal Functions
|
||||
|
||||
static void
|
||||
@@ -243,4 +268,12 @@ restore_context(TestState *s, ContextData *cd)
|
||||
free(cd->new_fc);
|
||||
}
|
||||
|
||||
static void
|
||||
run_single_test_context(TestState *s)
|
||||
{
|
||||
SingleTestContext *stc = s->ptr;
|
||||
s->ptr = stc->ptr;
|
||||
run_test(s, stc->test);
|
||||
}
|
||||
|
||||
//jl
|
||||
|
||||
Reference in New Issue
Block a user