I have a class, with member array of type int
// Class Defenition
class Foo {
int array[5];
// ... Other Memebers
}
Have another class with member function that has a parameter of type Foo*
class SerialTXInterface {
public:
virtual bool print_foo(Foo* strPtr) = 0;
// ... Other Members
};
Mock for the above method:
MOCK_METHOD1(print_str_s, bool(Array_s<char>* strPtr));
The SerialTX interface
SerialTXInterface* STX = &SerialTXObject;
The Foo object
Foo FooObj;
The function call
STX.print_foo(&FooOjb)
How can I verify that the Foo member array[5] == {1, 2, 3, 4, 5}
This works for me (if I make Foo::array
public)
#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);
}