-9

I'm building a Grid framework in C and just started using the Criterion framework for testing. The Grid framework provides many functions for creating different kinds of grids such as grid* new_row_major_double_grid() and grid* new_col_major_int(). The framework also provides the possibility to perform a number of operations on these grids, such as grid* add_grids(grid* gr1, grid* gr2) and grid* multiply_grids(grid* gr1, grid* gr2)

Currently, I have a test suite that checks the correctness of these operations when performed on grids created with grid* new_row_major_double_grid(). Each test starts by creating the needed grids using this function and ends by freeing them.

What I'd like to do is to parameterize this test suite by passing a pointer to the function responsible for the creation of the grid in each test.

In the Criterion Docs, they show you how to parameterize a single test using the following example:

#include <criterion/parameterized.h>

struct my_params {
    int param0;
    double param1;
    ...
};

ParameterizedTestParameters(suite_name, test_name) {
    static struct my_params params[] = {
        // parameter set
    };

    size_t nb_params = sizeof (params) / sizeof (struct my_params);
    return cr_make_param_array(struct my_params, params, nb_params);
}

ParameterizedTest(struct my_params *param, suite_name, test_name) {
    // access param->param0, param->param1, ...
}

Is there a way to achieve a similar behaviour at the test suite level?

Mehdi Charife
  • 722
  • 1
  • 7
  • 22

0 Answers0