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_STUBSEQUENCE_H
00035 #define MOCKPP_STUBSEQUENCE_H
00036
00037 #include <mockpp/mockpp.h>
00038
00039 #include MOCKPP_VECTOR_H
00040
00041 #include <mockpp/stub/Stub.h>
00042 #include <mockpp/compat/Asserter.h>
00043
00044
00045 MOCKPP_NS_START
00046
00047
00052 template <typename R,
00053 typename I>
00054 class StubSequence : public Stub<R, I>
00055 {
00056 public:
00057
00062 template<typename P>
00063 StubSequence(P start, P end)
00064 : stubs(start, end)
00065 {
00066 }
00067
00071 virtual ~StubSequence()
00072 {
00073 while (!stubs.empty() )
00074 {
00075 delete stubs[0];
00076 stubs.erase(stubs.begin());
00077 }
00078 }
00079
00084 virtual R invoke( const I &invocation )
00085 {
00086 if (!stubs.empty())
00087 {
00088 MOCKPP_STD_NS::auto_ptr< Stub<R, I> > curr (stubs[0]);
00089 stubs.erase(stubs.begin());
00090 return curr->invoke(invocation);
00091 }
00092 assertionFailed(__LINE__, __FILE__, MOCKPP_PCHAR("no more stubs available"));
00093 return R();
00094 }
00095
00100 virtual String describeTo( String &buffer ) const
00101 {
00102 for (unsigned i = 0; i < stubs.size(); i++)
00103 {
00104 if (i > 0)
00105 buffer += MOCKPP_PCHAR(", and then ");
00106
00107 buffer = stubs[i]->describeTo(buffer);
00108 }
00109
00110 return buffer;
00111 }
00112
00113 private:
00114
00115
00116 StubSequence(const StubSequence &);
00117 StubSequence &operator =(const StubSequence &);
00118
00119 MOCKPP_STL::vector<Stub<R, I>* > stubs;
00120 };
00121
00122
00123 MOCKPP_NS_END
00124
00125
00126 #endif // MOCKPP_STUBSEQUENCE_H
00127