Is there a way to create a custom parameters generator with googletest?

Viewed 2053

I am actually using googletest framework. I have a value parameterized test with

std::tuple<int, double> 

This int represents the number of vertices in a regular polygon and the double represents its radius. I could represent this using a struct like this :

struct RegularPolygon{
    int NbVertices;
    double Radius;
}

The problem is that I actually create tests using the combine paramaters generator :

INSTANTIATE_TEST_CASE_P(RegularPolygon, PolygonTestCase, testing::Combine(
    testing::Range(3, 10),
    testing::Range(1.0, 10.0)));

So if I want to switch to the use of the

RegularPolygon

struct as my parameter, I have to hard code the cartesian product of the two ranges.

Unless there is a way to define my own RegularPolygon Generator that would only map the int to RegularPolygon::NbVertices and the double to RegularPolygon::Radius.

Is there a way to do so?

If there isn't, what would be the best practice to convert the tuple to a RegularPolygon instance?

2 Answers
Related