DelayedCallDriver.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef UTILS__CALITKO_MOCKS__DELAYED_CALL_DRIVER_H
00024 #define UTILS__CALITKO_MOCKS__DELAYED_CALL_DRIVER_H
00025
00026 #include "Imports.h"
00027 #include "BasicTypes.h"
00028 #include "ExpectedFunction.h"
00029 #include "ExpectationsList.h"
00030
00031 namespace Utils {
00032 namespace CalitkoMocks {
00033
00034 class ExpectedFunctionBase;
00035 template <typename CallDriver, typename Function> class ExpectationDriver;
00036
00056 template <typename OuterExpectationDriver, typename Function>
00057 class DelayedCallDriver
00058 {
00059 public:
00060 typedef typename Function::ReturnType ReturnType;
00061
00062 DelayedCallDriver (OuterExpectationDriver &expectationDriver_, Function &f_)
00063 : f (f_), outerExpectationDriver (expectationDriver_) {}
00064
00066
00070 template <typename Foo>
00071 ExpectationDriver <DelayedCallDriver, ExpectedFunction <Foo> >
00072 willCall (ExpectationPair <ExpectedFunction <Foo> > expectation)
00073 {
00074 ExpectedFunction <Foo> *expectedFunction = expectation.function.get();
00075 expectation.list.add (expectation.function);
00076 f.addExpectation (expectedFunction);
00077 return ExpectationDriver <DelayedCallDriver, ExpectedFunction <Foo> >
00078 (*this, *expectedFunction);
00079 }
00080
00084 template <typename Foo>
00085 ExpectationDriver <DelayedCallDriver, ExpectedFunction <Foo> >
00086 willCallMsg (ExpectationPair <ExpectedFunction <Foo> > expectation,
00087 const std::string &expressionString,
00088 const SourceLine &sourceLine)
00089 {
00090 expectation.function->setContext (expressionString, sourceLine);
00091 return willCall (expectation);
00092 }
00093
00095 OuterExpectationDriver &
00096 willReturn (const ReturnTypeWrapper <ReturnType> &returnValue)
00097 {
00098 f.willReturn (returnValue);
00099 return outerExpectationDriver;
00100 }
00101
00106 OuterExpectationDriver &
00107 willReturnMsg (const ReturnTypeWrapper <ReturnType> &returnValue,
00108 const std::string &expressionString,
00109 const SourceLine &sourceLine)
00110 {
00111 f.setContext (expressionString, sourceLine);
00112 return willReturn (returnValue);
00113 }
00114
00116 OuterExpectationDriver & returns()
00117 {
00118 return willReturn (ReturnTypeWrapper <void>());
00119 }
00120
00122 template <typename Foo>
00123 DelayedCallDriver &
00124 willEmit (ExpectationPair <ExpectedFunction <Foo> > expectation)
00125 {
00126 ExpectedFunction <Foo> *signalExpectation = expectation.function.get();
00127 expectation.list.add (expectation.function);
00128 f.addExpectation (signalExpectation);
00129 return *this;
00130 }
00131
00136 template <typename Foo>
00137 DelayedCallDriver &
00138 willEmitMsg (ExpectationPair <ExpectedFunction <Foo> > expectation,
00139 const std::string &expressionString,
00140 const SourceLine &sourceLine)
00141 {
00142 expectation.function->setContext (expressionString, sourceLine);
00143 return willEmit (expectation);
00144 }
00145
00146 protected:
00147 Function &f;
00148 OuterExpectationDriver &outerExpectationDriver;
00149 };
00150
00151 }
00152 }
00153
00154 #endif // UTILS__CALITKO_MOCKS__DELAYED_CALL_DRIVER_H