Added generated datapoints theory sample

This commit is contained in:
Snaipe 2015-09-07 18:03:05 +02:00
parent f6b6139607
commit afad78c433
3 changed files with 37 additions and 0 deletions

View file

@ -56,6 +56,9 @@ CR_API void cr_theory_call(struct criterion_theory_context *ctx, void (*fnptr)(v
# define TheoryDataPoints(Category, Name) \
static struct criterion_datapoints IDENTIFIER_(Category, Name, dps)[]
# define TheoryDataPoint(Category, Name) \
(IDENTIFIER_(Category, Name, dps))
# ifdef __cplusplus
# define CR_TH_VA_NUM(Type, ...) criterion_va_num__(__VA_ARGS__)
# define CR_TH_TEMP_ARRAY(Type, ...) []() { static Type arr[] = { __VA_ARGS__ }; return &arr; }()

View file

@ -102,3 +102,20 @@ Theory((char c, bool b, short s, int i, long l, long long ll, float f, double d,
// abort to see the formatted string of all parameters
cr_abort_test(NULL);
}
// Manually generate datapoints
TheoryDataPoints(theory, gen) = {
DataPoints(int, 0), // placeholder
};
static void generate_datapoints(void) {
static int arr[] = {1, 2, 3, 4, 5};
TheoryDataPoint(theory, gen)[0].len = 5;
TheoryDataPoint(theory, gen)[0].arr = &arr;
}
Theory((int i), theory, gen, .init = generate_datapoints) {
(void) i;
cr_abort_test(NULL); // we fail to display the parameter
}

View file

@ -110,3 +110,20 @@ Theory((char c, bool b, short s, int i, long l, long long ll, float f, double d,
// abort to see the formatted string of all parameters
cr_abort_test(NULL);
}
// Manually generate datapoints
TheoryDataPoints(theory, gen) = {
DataPoints(int, 0), // placeholder
};
static void generate_datapoints(void) {
static int arr[] = {1, 2, 3, 4, 5};
TheoryDataPoint(theory, gen)[0].len = 5;
TheoryDataPoint(theory, gen)[0].arr = &arr;
}
Theory((int i), theory, gen, .init = generate_datapoints) {
(void) i;
cr_abort_test(NULL); // we fail to display the parameter
}