我试图模拟硬件抽象层函数,通过编写假的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()
访问此成员?
谢谢你...