0

When I try and reference an enum class from a test fixture, it fails to compile with error ./gtest_mcp23s17.cpp:25:52: error: no type named 'HW_ADDR_6' in 'mcp23s17::HardwareAddress' TC_mcp23s17 _gpio_x(mcp23s17::HardwareAddress::HW_ADDR_6); ~~~~~~~~~~~~~~~~~~~~~~~~~~~^

However, if I leave the reference in the test itself (leaving ALL other code untouched), it compiles without error and runs the test as you would expect. Is this a bug in GoogleTest, or what differentiates this scenario as far as the test is concerned?

Test (generic): [COMPILES]

TEST(Construction, WHENObjectIsConstructedTHENAddressParameterIsStored) {
    TC_mcp23s17 gpio_x(mcp23s17::HardwareAddress::HW_ADDR_6);
    EXPECT_EQ(0x4C, gpio_x.getSpiBusAddress());
}

Test Fixture: [COMPILES]

TEST_F(SPITransfer, WHENPinModeHasNotBeenCalledTHENTheCallersChipSelectPinIsHigh) {
    TC_mcp23s17 gpio_x(mcp23s17::HardwareAddress::HW_ADDR_6);
    EXPECT_EQ(HIGH, getPinLatchValue(SS));
}

Test Fixture (with gpio_x declared in fixture class): [FAILS]

class SPITransfer : public ::testing::Test {
  protected:
    TC_mcp23s17 gpio_x(mcp23s17::HardwareAddress::HW_ADDR_6);
    ...
}
TEST_F(SPITransfer, WHENPinModeHasNotBeenCalledTHENTheCallersChipSelectPinIsHigh) {
    EXPECT_EQ(HIGH, getPinLatchValue(SS));
}
Zak
  • 12,213
  • 21
  • 59
  • 105

1 Answers1

0

A class member can only be initialised with = or {}, not (). So either of these should work:

TC_mcp23s17 gpio_x=mcp23s17::HardwareAddress::HW_ADDR_6;
TC_mcp23s17 gpio_x{mcp23s17::HardwareAddress::HW_ADDR_6};

The rather unhelpful error message is because the compiler interprets the use of () to denote a function declaration, then gets confused because the thing inside the brackets isn't a type.

Mike Seymour
  • 249,747
  • 28
  • 448
  • 644
  • Wow, I feel super dumb. However, now that I fixed that, it's not displaying my tests. I'm still getting a valid success/error code after the test suite is called. Any ideas about this? – Zak Mar 28 '15 at 21:15
  • @Zak: I've no idea how Google Test works. If you have another question, ask another question. – Mike Seymour Mar 29 '15 at 01:07