ExpectationDriver.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__EXPECTATION_DRIVER_H
00024 #define UTILS__CALITKO_MOCKS__EXPECTATION_DRIVER_H
00025
00026 #include "Imports.h"
00027 #include "BasicTypes.h"
00028
00029 namespace Utils {
00030 namespace CalitkoMocks {
00031
00032 template <typename Host, typename Function> class BoundFunction;
00033 template <typename Function> class CallDriver;
00034 template <typename ExpectationDrv, typename Function> class DelayedCallDriver;
00035
00037
00054 template <typename OwningCallDriver, typename Function>
00055 class ExpectationDriver
00056 {
00057 public:
00058 typedef typename Function::ReturnType ReturnType;
00059
00060 ExpectationDriver (OwningCallDriver &owningCallDriver_,
00061 Function &expectedFunction_)
00062 : owningCallDriver (owningCallDriver_),
00063 expectedFunction (expectedFunction_)
00064 {
00065 }
00066
00068
00074 template <typename H, typename T>
00075 DelayedCallDriver <ExpectationDriver, BoundFunction <H, T> >
00076 willCall (auto_ptr <BoundFunction <H, T> > f)
00077 {
00078 DelayedCallDriver <ExpectationDriver, BoundFunction <H, T> >
00079 delayedCall (*this, *(f.get()));
00080 expectedFunction.addCall (
00081 auto_ptr <typename BoundFunction <H, T>::Base> (f.get()));
00082 f.release();
00083 return delayedCall;
00084 }
00085
00089 template <typename H, typename T>
00090 DelayedCallDriver <ExpectationDriver, BoundFunction <H, T> >
00091 willCallMsg (auto_ptr <BoundFunction <H, T> > f,
00092 const std::string &expressionString,
00093 const SourceLine &sourceLine)
00094 {
00095 f->setContext (expressionString, sourceLine);
00096 return willCall (f);
00097 }
00098
00100
00104 OwningCallDriver & willReturn (ReturnTypeWrapper <ReturnType> r)
00105 {
00106 expectedFunction.willReturn (r);
00107 return owningCallDriver;
00108 }
00109
00115 OwningCallDriver & willReturnMsg (ReturnTypeWrapper <ReturnType> r,
00116 const std::string &,
00117 const SourceLine &)
00118 {
00119 return willReturn (r);
00120 }
00121
00124 OwningCallDriver & returns()
00125 {
00126 return willReturn (ReturnTypeWrapper <void>());
00127 }
00128
00129 ExpectationDriver & numberOfTimes (int from)
00130 {
00131 expectedFunction.setNumberOfTimesShouldBeInvoked (from, from);
00132 return *this;
00133 }
00134
00135 ExpectationDriver & numberOfTimes (int from, int to)
00136 {
00137 expectedFunction.setNumberOfTimesShouldBeInvoked (from, to);
00138 return *this;
00139 }
00140
00141 private:
00142 OwningCallDriver &owningCallDriver;
00143 Function &expectedFunction;
00144 };
00145
00146 }
00147 }
00148
00149 #endif // UTILS__CALITKO_MOCKS__EXPECTATION_DRIVER_H