我有一个类,其成员数组类型为int
// Class Defenition
class Foo {
int array[5];
// ... Other Memebers
}
让另一个具有成员函数的类具有类型为Foo *
的参数class SerialTXInterface {
public:
virtual bool print_foo(Foo* strPtr) = 0;
// ... Other Members
};
模拟上述方法:
MOCK_METHOD1(print_str_s, bool(Array_s<char>* strPtr));
SerialTX界面
SerialTXInterface* STX = &SerialTXObject;
Foo对象
Foo FooObj;
函数调用
STX.print_foo(&FooOjb)
如何验证Foo成员数组[5] == {1,2,3,4,5}
答案 0 :(得分:1)
这对我有用(如果我公开Foo::array
)
#include <gtest/gtest.h>
#include <gmock/gmock.h>
using namespace testing;
class Foo {
public:
int array[5];
// ... Other Memebers
};
class SerialTXInterface {
public:
virtual bool print_foo(Foo* strPtr) = 0;
// ... Other Members
};
class SerialTXMock {
public:
MOCK_METHOD1(print_foo, bool(Foo* strPtr));
};
TEST(STXUser, Sends12345)
{
SerialTXMock STXM;
EXPECT_CALL(STXM, print_foo(Pointee(Field(&Foo::array,ElementsAre(1,2,3,4, 5)))));
Foo testfoo = {{1,2,3,4,5}};
STXM.print_foo(&testfoo);
}