00001
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef MOCKPP_ResponseVector2_H
00032 #define MOCKPP_ResponseVector2_H
00033
00034 #include <mockpp/constraint/ConstraintHolder.h>
00035 #include <mockpp/constraint/IsEqual.h>
00036 #include <mockpp/visiting/VisitableMockObject_template.h>
00037
00038
00039 MOCKPP_NS_START
00040
00041
00045 template <typename P1, typename P2>
00046 class ResponseThrowableVector2 : public ResponseVectorBase
00047 {
00048 public:
00049
00055 ResponseThrowableVector2(const String &aName, VerifiableList *parent)
00056 : ResponseVectorBase(aName, parent)
00057 {}
00058
00061 virtual ~ResponseThrowableVector2()
00062 {
00063 reset();
00064 }
00065
00072 void add(Throwable *throwable, const P1 &p1, const P2 &p2, unsigned count)
00073 {
00074 const ConstraintHolder<P1> h1 = new IsEqual<P1>(p1);
00075 const ConstraintHolder<P2> h2 = new IsEqual<P2>(p2);
00076 add(throwable, h1, h2, count);
00077 }
00078
00085 void add(Throwable *throwable,
00086 const ConstraintHolder<P1> &p1,
00087 const ConstraintHolder<P2> &p2,
00088 unsigned count)
00089 {
00090 counter.push_back(count);
00091 tvec.push_back(throwable);
00092 typename MOCKPP_NS::Constraint<P1>::AP cons1 (p1);
00093 typename MOCKPP_NS::Constraint<P2>::AP cons2 (p2);
00094 t1vec.push_back(cons1.release());
00095 t2vec.push_back(cons2.release());
00096 }
00097
00100 void reset()
00101 {
00102 counter.clear();
00103 tvec.reset();
00104
00105 for (unsigned i1 = 0; i1 < t1vec.size(); ++i1)
00106 delete t1vec[i1];
00107 t1vec.clear();
00108
00109 for (unsigned i2 = 0; i2 < t2vec.size(); ++i2)
00110 delete t2vec[i2];
00111 t2vec.clear();
00112 }
00113
00120 bool find(Throwable * &throwable, const P1 &p1, const P2 &p2)
00121 {
00122 for (unsigned i = 0; i < t1vec.size(); ++i)
00123 if ( counter[i] > 0
00124 && t1vec[i]->eval(p1)
00125 && t2vec[i]->eval(p2)
00126 )
00127 {
00128 if (tvec.at(i) == 0)
00129 return false;
00130
00131 if (counter[i] != MOCKPP_UNLIMITED)
00132 --counter[i];
00133
00134 throwable = tvec.at(i);
00135 return true;
00136 }
00137 return false;
00138 }
00139
00140 protected:
00141
00142 MOCKPP_STL::vector<Constraint<P1>*> t1vec;
00143 MOCKPP_STL::vector<Constraint<P2>*> t2vec;
00144 };
00145
00146
00150 template <typename R, typename P1, typename P2>
00151 class ResponseVector2 : public ResponseThrowableVector2<P1, P2>
00152 {
00153 public:
00154
00159 ResponseVector2(const String &aName, VerifiableList *parent)
00160 : ResponseThrowableVector2<P1, P2>(aName, parent)
00161 {}
00162
00169 void add(Throwable *throwable, const P1 &p1, const P2 &p2, unsigned count)
00170 {
00171 MOCKPP_ASSERT_TRUE(throwable != 0);
00172 ResponseThrowableVector2<P1, P2>::add(throwable, p1, p2, count);
00173 R r;
00174 rvec.push_back(r);
00175 }
00176
00183 void add(Throwable *throwable,
00184 const ConstraintHolder<P1> &p1,
00185 const ConstraintHolder<P2> &p2,
00186 unsigned count)
00187 {
00188 MOCKPP_ASSERT_TRUE(throwable != 0);
00189 ResponseThrowableVector2<P1, P2>::add (throwable, p1, p2, count);
00190 R r;
00191 rvec.push_back(r);
00192 }
00193
00200 void add(const R &r, const P1 &p1, const P2 &p2, unsigned count)
00201 {
00202 ResponseThrowableVector2<P1, P2>::add((Throwable*)0, p1, p2, count);
00203 rvec.push_back(r);
00204 }
00205
00212 void add(const R &r,
00213 const ConstraintHolder<P1> &p1,
00214 const ConstraintHolder<P2> &p2,
00215 unsigned count)
00216 {
00217 ResponseThrowableVector2<P1, P2>::add((Throwable*)0, p1, p2, count);
00218 rvec.push_back(r);
00219 }
00220
00223 void reset()
00224 {
00225 ResponseThrowableVector2<P1, P2>::reset();
00226 rvec.clear();
00227 }
00228
00229 #if defined(__BORLANDC__) || (__GNUC__ < 3) // ==> BCB5.5.1 ?? F1004 Internal compiler error at 0x12548c1 with base 0x1200000
00230 bool find(Throwable * &throwable, const P1 &p1, const P2 &p2)
00231 {
00232 return ResponseThrowableVector2<P1, P2>::find(throwable, p1, p2);
00233 }
00234 #else
00235 using ResponseThrowableVector2<P1, P2>::find;
00236 #endif
00237
00244 bool find(R &r, const P1 &p1, const P2 &p2)
00245 {
00246 for (unsigned i = 0; i < this->t1vec.size(); ++i)
00247 if ( this->counter[i] > 0
00248 && this->t1vec[i]->eval(p1)
00249 && this->t2vec[i]->eval(p2)
00250 )
00251 {
00252 if (this->tvec.at(i) != 0)
00253 return false;
00254
00255 if (this->counter[i] != MOCKPP_UNLIMITED)
00256 --this->counter[i];
00257
00258 r = rvec[i];
00259 return true;
00260 }
00261 return false;
00262 }
00263
00264 private:
00265
00266 MOCKPP_STL::vector<R> rvec;
00267 };
00268
00269 MOCKPP_NS_END
00270
00271
00272 #endif // MOCKPP_ResponseVector2_H
00273