Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gtest: Expected Class-Name Before '{'

I'm attempting to convert a test case under Gtest to use a test fixture so I can have a common setup as I add more tests. This is, however, leading to an error:

test_integrate.cc:4:47: error: expected class-name before '{' token
  class IntegratorTest : public ::testing::test {

This failure is something that I cannot understand, as it normally arises from a circular import in my experience, and there has been no change in the imports as opposed to the working code. The full code follows:

#include "gtest/gtest.h"
#include "utils/integrate.hpp"

class IntegratorTest : public ::testing::test {
protected:
    Integrator integ;
    VectorXf v, xdot;
    float cur_time;

    virtual void SetUp() {
        integ = Integrator(1.0);
        v = VectorXf::Ones(10);
        xdot = VectorXf::Ones(10);
        cur_time = 0.0;
    }
};

TEST_F(IntegratorTest, Euler) {
    // Use e^t for a simple test algorithm
    for (short i = 1; i < 5; i++) {
        v = integ.Euler(v, xdot, cur_time);
        xdot *= 2.0;
        EXPECT_EQ(i, cur_time);
        EXPECT_EQ(xdot, v);
    }
}

If I remove the fixture and go to initializing the setup within the test case, the code compiles just fine. This working code is as follows.

#include "gtest/gtest.h"
#include "utils/integrate.hpp"

TEST(Integrate, Euler) {
    Integrator integ = Integrator(1.0);
    VectorXf v = VectorXf::Ones(10);
    VectorXf xdot = VectorXf::Ones(10);
    float cur_time = 0.0;

    // Use e^t for a simple test algorithm
    for (uint16_t i = 1; i < 5; i++) {
        v = integ.Euler(v, xdot, cur_time);
        xdot *= 2.0;
        EXPECT_EQ(i, cur_time);
        EXPECT_EQ(xdot, v);
    }
}

I can't seem to find anything explaining how I could resolve this error such that it will allow me to compile.

Just in case it might matter, to compile I'm running GCC 5.3.0 installed via Homebrew on an up-to-date El Capitan OS X.

like image 854
Matthew Tanous Avatar asked Mar 11 '16 03:03

Matthew Tanous


1 Answers

The class you want to inherit is called ::testing::Test, not ::testing::test

like image 144
Martin G Avatar answered Oct 11 '22 18:10

Martin G