1

How does one set up an expect call with a class instance or structure instance as one of the parameters in the "with" part? The documentation doesn't seem to show how to do that. I see using simple arguments like strings and integers - but not class instances. Do you usually just set that parameter as "_" and be done with it?

MKaras
  • 2,063
  • 2
  • 20
  • 35

2 Answers2

0

For equality comparable instances, you can pass an instance and use that.

For uncomparable instances, it would not be possible to determine if the arguments match what you put in .With so that will not compile. You need to somehow make them comparable to allow Hippomocks to determine whether your call matches.

dascandy
  • 7,184
  • 1
  • 29
  • 50
0

Dascandy already explained it.

Solution is, to provide your own comparer implementation, e.g. for the example above:

inline bool operator==(const MyStruct& lhs, const MyStruct& rhs)
{
    if ((lhs.a == rhs.a) && (lhs.b == rhs.b))
    {
        return true;
    }
    return false;
}

That makes the compiler to shut up and the test works as expected:

TEST(check_CanCompareStructArguments)
{
    MockRepository mocks;

    IStruct* is = mocks.Mock<IStruct>();
    MyStruct ms;
    ms.a = 5;
    ms.b = 7;

    mocks.ExpectCall(is, IStruct::A).With(ms);

    is->A(ms);
}
mrAtari
  • 620
  • 5
  • 17