diff --git a/include/criterion/theories.h b/include/criterion/theories.h index 3dc42c5..29055b5 100644 --- a/include/criterion/theories.h +++ b/include/criterion/theories.h @@ -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; }() diff --git a/samples/theories.c b/samples/theories.c index 564297d..6e96a6d 100644 --- a/samples/theories.c +++ b/samples/theories.c @@ -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 +} diff --git a/samples/theories.cc b/samples/theories.cc index 62f8b91..d0e3dd3 100644 --- a/samples/theories.cc +++ b/samples/theories.cc @@ -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 +}