Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How (if at all) can I mock a mocked class on the heap?

Tags:

c++

googlemock

I created a test mock class pretty much as simple as described in the docs:

class MockLogicLoopable : public LogicLoopable 
{
public:
  MOCK_METHOD0(update,void());
  MOCK_METHOD0(loopableType,LoopableType());
};

Now I'd like to do something like this:

TEST(Examplegroup,Example)
{
    MockLogicLoopable* mll = new MockLogicLoopable();
    EXPECT_CALL(mll,loopableType())
        .WillRepeatedly(Return(LOGIC));
}

I'm not really sure how, if at all, something like this can be realized with googlemock.

like image 333
Daniel Ziltener Avatar asked Jan 21 '26 04:01

Daniel Ziltener


1 Answers

You have a pointer in mll, but EXPECT_CALL expects its first argument to be a value. Dereference your pointer with *, just as you would any other:

EXPECT_CALL(*mll, loopableType())
  .WillRepeatedly(Return(LOGIC));
like image 171
Rob Kennedy Avatar answered Jan 22 '26 16:01

Rob Kennedy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!