locked
How to: mock async call RRS feed

  • Question

  • Hi

    A function I have to mock gets a callback as a parameter. In my stub I would like to return immediately but call the callback asynchronously later on (like it would be in reality as the function normally accesses a database).

    What's best practice how to do that in C++?

    I guess it's something like:

    bool functionToBeMocked(CallbackObject* cb)
    {
      doAsync(cb->callback()); //how to implement doAsync?? using a new thead?
      return true;
    }


    I'm using Google's C++ mock framework.

    Thanks!
    • Edited by Dunken Wednesday, September 28, 2011 6:51 AM layout
    Wednesday, September 28, 2011 6:49 AM

Answers