Mocking multiple return values in multiple calls to the same function

2,717 views
Skip to first unread message

Pradeepa Senanayake

unread,
Feb 12, 2016, 5:18:08 AM2/12/16
to cpputest
Hello All,

In my code under test, the same function will be called twice within a function under test.

functionA()
{

a = functionB(param1);

b = functionB(param2);

}

Here the results coming to a and b are different. In fact what I am mocking is a function in the OS. 

The actual function I want to mock is WaitForSingleObject. I want the first call to return WAIT_OBJECT_0 and the second call return WAIT_TIMEOUT.

Please let me know how to write the expectations for this scenario?

Thank you.

Ryan Hartlage

unread,
Feb 12, 2016, 11:03:21 AM2/12/16
to cpputest
Hey Pradeepa,

This should be as simple as setting up two expectations with
mock().expectOneCall(...).andReturn(...). Each expectation can set a
different return value and CppUTest will emit those returns in the
right order.

Ryan
> --
> You received this message because you are subscribed to the Google Groups
> "cpputest" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cpputest+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Pradeepa Senanayake

unread,
Feb 18, 2016, 2:33:11 AM2/18/16
to cpputest
Thank you very much. It works.
Reply all
Reply to author
Forward
0 new messages