00001
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef MOCKPP_RETURNOBJECTLISTSTUB_H
00035 #define MOCKPP_RETURNOBJECTLISTSTUB_H
00036
00037 #include <mockpp/mockpp.h>
00038
00039 #include <mockpp/compat/Formatter.h>
00040 #include <mockpp/compat/Asserter.h>
00041 #include <mockpp/stub/TypelessStub.h>
00042 #include <mockpp/ReturnObjectList.h>
00043
00044
00045 MOCKPP_NS_START
00046
00053 template <typename R>
00054 class ReturnObjectListStub : public TypelessStub<R>
00055 , public Verifiable
00056 {
00057 public:
00058
00064 ReturnObjectListStub( const R &result, const String &name = MOCKPP_PCHAR(""), VerifiableList *parent = 0 )
00065 : Verifiable (name, parent)
00066 , returnObjects(MOCKPP_PCHAR("ReturnObjectListStub/returnObjects"), 0)
00067 {
00068 addObjectToReturn(result);
00069 }
00070
00077 template <class I>
00078 ReturnObjectListStub( I items, I end, const String &name = MOCKPP_PCHAR(""), VerifiableList *parent = 0 )
00079 : Verifiable (name, parent)
00080 , returnObjects(MOCKPP_PCHAR("ReturnObjectListStub/returnObjects"), 0)
00081 {
00082 addObjectToReturn(items, end);
00083 }
00084
00087 virtual void verify()
00088 {
00089 returnObjects.verify();
00090 }
00091
00095 virtual void reset()
00096 {
00097 returnObjects.reset();
00098 }
00099
00103 void addObjectToReturn( const R &retArg )
00104 {
00105 returnObjects.addObjectToReturn(retArg);
00106 }
00107
00113 template <class I>
00114 ReturnObjectListStub& addObjectToReturn(I items, I end)
00115 {
00116 for ( ; items != end; ++items)
00117 addObjectToReturn(*items);
00118 return *this;
00119 }
00120
00124 virtual R typelessInvoke()
00125 {
00126 return returnObjects.nextReturnObject();
00127 }
00128
00133 virtual String describeTo( String &buffer ) const
00134 {
00135 String fmt = MOCKPP_PCHAR("returns %1");
00136 fmt << returnObjects.toString();
00137 buffer += fmt;
00138 return buffer;
00139 }
00140
00141 private:
00142
00143 mutable ReturnObjectList<R> returnObjects;
00144 };
00145
00146
00147 MOCKPP_NS_END
00148
00149
00150 #endif // MOCKPP_RETURNOBJECTLISTSTUB_H
00151
00152