nonamer92
nonamer92

Reputation: 1917

GTest - run multiple testcase on different parameters

Note: I know this question was asked in different ways, but I couldn't solve it based on my restrictions:

  1. I am using google test version 1.7
  2. Compiling in Visual studio 2010, with platform toolset V100

I am writing google test for a library I have created.

In my library, I have 3 structs, as follows:

struct utc_clock{ .... }
struct system_clock {....}
struct cpu_clock {....}

moreover, I have another class that uses them as template parameters.

In my test case, I do as follows:

TEST(MyTest, testImportantThings)
{
    time_point<utc_clock> tp = utc_clock::now();

    ASSERT_EQ(..things with tp... );
    ... more ASSERTION 
}

What I am trying to do, is to run

TEST(MyTest, testImportantThings)

multiple times for each of the utc_clock, system_clock, cpu_clock

I have looked into How to get gtest TYPED_TEST parameter type,

after that, I got the following:

template<typename T>
struct MyTest: public testing::Test{
    using MyParamType = T;
};

using MyTypes = testing::TYpes<utc_clock, system_clock, cpu_clock>;

TYPED_TEST_CASE(MyTest, MyTypes);

TYPED_TEST(MyTest, testImportantStuff)
{
    using clock = typename TestFixture::MyParamType;

    timepoint<clock> tp = clock::now();

    ASSERT_EQ(..things with tp... );
    ... more ASSERTION 

}

But I get the following errors:

  1. unexpected token(s) preceding ';' on: using MyParamType = T;

  2. testing::internal::TYpeList use of class template requires template arguement list online on: using MyTypes = testing::TYpes<utc_clock, system_clock, cpu_clock>;

and more...

Upvotes: 0

Views: 490

Answers (1)

NicholasM
NicholasM

Reputation: 4673

It is possible that your compiler is too old to support defining type aliases with using. What if you replace those with old-style typedef statements?

For example, you could replace

using MyParamType = T;

With the equivalent:

typedef T MyParamType;

Upvotes: 1

Related Questions