struct expectation

Scope: stub::function< R(Args…)>

In header: #include <function.hpp>

Member functions (public)

  expectation (const function & the_function)
  operator bool () const
bool to_bool () const
expectation & with (WithArgs &&… args)

Description

Represent a expectation of how the function object has been invoked. Using the API it is possible to setup how we expect the function object looks like. The expectation converts to bool allowing the user to detect whether the expectation was correct.

Member Function Description

expectation (const function & the_function)

Parameter the_function:
The function we configuring an expectation for

operator bool ()

Use the to_bool member function when casting this expectation to a boolean value.

Returns:
True if the expectation matches the function, otherwise false

bool to_bool ()

Convert the expectation to a boolean value either true of false depending on whether the expectations match the actual call. The first argument passed to the predicate function is the actual call arguments and the second is the expectation.

Returns:
True if the expectation matches the call, otherwise false

expectation & with (WithArgs &&… args)

Calling with(…) will add a set of arguments we expect to see. with(…) can be called multiple times in a row if we expect multiple function calls to the function object. As an example:

stub::function<void(uint32_t,uint32_t)> function;
function(3,1);
function(4,2);

assert(function.expect_calls()
           .with(3,1).with(4,2));
Parameter args:
The arguments for a function call
Returns:
The expectation itself, which allows chaining function calls