访问 Google 测试夹具成员

Access Google Test fixture member

我正在尝试模拟硬件抽象层函数,它是 uint32_t hw_epoch() 通过编写一个伪造的,并从一个伪造的调用模拟方法,这将让我验证 hw_epoch() 函数被调用.所以考虑下面的简化代码:

#include <stdint.h>
#include "gmock/gmock.h"

using ::testing::Return;

class FooInterface {
 public:
    virtual ~FooInterface() {}
    virtual uint32_t m_hw_epoch() = 0;
};

class MockFoo : public FooInterface {
 public:
    MOCK_METHOD0(m_hw_epoch, uint32_t());
 private:
};

// ----- Test Fixture:
class FooTest : public ::testing::Test {
 public:
    FooTest() : FooInterfacePtr(&MockFooObj) {}
    ~FooTest() {}

    MockFoo MockFooObj;
    FooInterface* FooInterfacePtr;
};

// ----- Fakes
uint32_t hw_epoch() {
    FooInterfacePtr->m_hw_epoch();  // *** How Can I access FooInterfacePtr?
    return 5;
}

TEST_F(FooTest, constructor) {
}

FooTest Fixture 有成员 FooInterfacePtr,我如何从自由函数 uint32_t hw_epoch() 访问这个成员?

谢谢...

Per @πìντα ῥεῖ,不可能用自由函数来做。自定义操作是一种可能的解决方案。