Mocks.h File Reference


Detailed Description

Includes all relevant header files required for creating mock classes and for defining test scenarios and test. It further defines a number of utility macros which cause call context information (source file name, file line and expectation expression) to be seamlessly passed on to the mocking objects.

Todo:
Write a script that generates the macros EXPECTED_FUNCTION_CHECKERX and the like to make modifications and adding new macros easier and less error-prone.
Todo:
A test driver should implement all virtual functions and create expectations similarly like for virtual functions of mocked classes. The difference would be that the return values will not be stubbed and after the parameter values have been checked, the return value of the base implementation should be returned. If the function is pure virtual then the call is completely mocked, including the stubbed return value.

Definition in file Mocks.h.

#include "Imports.h" [code]
#include "BoundFunction.h" [code]
#include "CallDriver.h" [code]
#include "DelayedCallDriver.h" [code]
#include "ExpectationDriver.h" [code]
#include "ExpectationsList.h" [code]
#include "ExpectedFunction.h" [code]

Include dependency graph for Mocks.h:

Go to the source code of this file.

Namespaces

namespace  Utils
namespace  Utils::CalitkoMocks

Classes

struct  Utils::CalitkoMocks::MockBase
struct  Utils::CalitkoMocks::SignalWaitHelper

Defines

#define willReturn(expr)   willReturnMsg (expr, std::string ("Expression: " #expr), CPPUNIT_SOURCELINE())
 Expand to willReturn() calls taking also the call context.
#define willCall(foo)   willCallMsg (foo, std::string ("Function: " #foo), CPPUNIT_SOURCELINE())
 Expand to willCall() calls taking also the call context.
#define willEmit(foo)   willEmitMsg (foo, std::string ("Function: " #foo), CPPUNIT_SOURCELINE())
 Expand to willEmit() calls taking also the call context.
#define call(foo)   callMsg (foo, std::string ("Function: " #foo), CPPUNIT_SOURCELINE())
 Expand to call() calls taking also the call context.
#define calls(foo)   callsMsg (foo, std::string ("Function: " #foo), CPPUNIT_SOURCELINE())
 Expand to calls() calls taking also the call context.
#define willBeEqual(a, b)
 Expand to willBeEqual() calls taking also the call context.

Functions

template<typename Host, typename Func>
CallDriver< BoundFunction<
Host, Func > > 
Utils::CalitkoMocks::call (auto_ptr< BoundFunction< Host, Func > > f)
template<typename Host, typename Func>
CallDriver< BoundFunction<
Host, Func > > 
Utils::CalitkoMocks::callMsg (auto_ptr< BoundFunction< Host, Func > > f, const std::string &expressionString, const SourceLine &sourceLine)
template<typename Checker>
auto_ptr< ExpectedFunction<
typename Checker::Function > > 
Utils::CalitkoMocks::checker (const Checker &checker)
CallDriver< BoundFunction<
SignalWaitHelper, void(int)> > 
Utils::CalitkoMocks::waitFor (int maxTime)
 Returns a CallDriver bound to SignalWaitHelper::processEvents().
template<typename T>
void Utils::CalitkoMocks::willBeEqual (T v1, T v2)
template<typename T>
void Utils::CalitkoMocks::willBeEqualMsg (T v1, T v2, const std::string &expectationString, const SourceLine &sourceLine)
void Utils::CalitkoMocks::willFail (const std::string &reason)


Define Documentation

#define call foo   )     callMsg (foo, std::string ("Function: " #foo), CPPUNIT_SOURCELINE())
 

Expand to call() calls taking also the call context.

Definition at line 157 of file Mocks.h.

#define calls foo   )     callsMsg (foo, std::string ("Function: " #foo), CPPUNIT_SOURCELINE())
 

Expand to calls() calls taking also the call context.

Definition at line 161 of file Mocks.h.

#define willBeEqual a,
 ) 
 

Value:

willBeEqualMsg ((a), (b),                           \
                        std::string (#a ", " #b),           \
                        CPPUNIT_SOURCELINE())
Expand to willBeEqual() calls taking also the call context.

Definition at line 165 of file Mocks.h.

#define willCall foo   )     willCallMsg (foo, std::string ("Function: " #foo), CPPUNIT_SOURCELINE())
 

Expand to willCall() calls taking also the call context.

Definition at line 149 of file Mocks.h.

#define willEmit foo   )     willEmitMsg (foo, std::string ("Function: " #foo), CPPUNIT_SOURCELINE())
 

Expand to willEmit() calls taking also the call context.

Definition at line 153 of file Mocks.h.

#define willReturn expr   )     willReturnMsg (expr, std::string ("Expression: " #expr), CPPUNIT_SOURCELINE())
 

Expand to willReturn() calls taking also the call context.

Definition at line 145 of file Mocks.h.