Returning a boost::shared_ptr from a mocked function

581 views
Skip to first unread message

Thomas

unread,
May 26, 2010, 11:09:55 PM5/26/10
to Google C++ Mocking Framework
I have a class member function with following signature:

boost::shared_ptr<Message> ReceiveMessage();

with the following mock declaration:

MOCK_METHOD0(ReceiveMessage, boost::shared_ptr<CciMessage>());

This compiles without problems. I would like to write an EXPECT_CALL
that returns a shared_ptr that points to an object with a particular
value. I've tried things like

Message message;
EXPECT_CALL(mLayer,
ReceiveMessage()).Times(1).WillOnce(Return(Pointee(message)));

but this does not compile. There's no specific Returnx() for a
boost::shared_ptr, like there is for a C++ reference. Is this
possible? Perhaps there is another way to go about this?

Vlad Losev

unread,
Jun 8, 2010, 5:12:52 PM6/8/10
to Google C++ Mocking Framework
On Wed, May 26, 2010 at 8:09 PM, Thomas <thomas....@gmail.com> wrote:
I have a class member function with following signature:

 boost::shared_ptr<Message> ReceiveMessage();

with the following mock declaration:

MOCK_METHOD0(ReceiveMessage, boost::shared_ptr<CciMessage>());

This compiles without problems. I would like to write an EXPECT_CALL
that returns a shared_ptr that points to an object with a particular
value. I've tried things like

Message message;
EXPECT_CALL(mLayer,
ReceiveMessage()).Times(1).WillOnce(Return(Pointee(message)));

but this does not compile.

Pointee() is a matcher, it doesn't really return values and you cannot use it with Return().
 
There's no specific Returnx() for a
boost::shared_ptr, like there is for a C++ reference. Is this
possible? Perhaps there is another way to go about this?

Doesn't

boost::shared_ptr<CciMessage> message(new CciMessage);
EXPECT_CALL(mLayer, ReceiveMessage()).WillOnce(Return(message));

work? I assume you used CciMessage in both your class and mock definitions.

Reply all
Reply to author
Forward
0 new messages