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_ResponseVector5_H
00032 #define MOCKPP_ResponseVector5_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, typename P3, typename P4, typename P5>
00046 class ResponseThrowableVector5 : public ResponseVectorBase
00047 {
00048 public:
00049
00055 ResponseThrowableVector5(const String &aName, VerifiableList *parent)
00056 : ResponseVectorBase(aName, parent)
00057 {}
00058
00061 virtual ~ResponseThrowableVector5()
00062 {
00063 reset();
00064 }
00065
00075 void add(Throwable *throwable, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4, const P5 &p5, unsigned count)
00076 {
00077 const ConstraintHolder<P1> h1 = new IsEqual<P1>(p1);
00078 const ConstraintHolder<P2> h2 = new IsEqual<P2>(p2);
00079 const ConstraintHolder<P3> h3 = new IsEqual<P3>(p3);
00080 const ConstraintHolder<P4> h4 = new IsEqual<P4>(p4);
00081 const ConstraintHolder<P5> h5 = new IsEqual<P5>(p5);
00082 add(throwable, h1, h2, h3, h4, h5, count);
00083 }
00084
00094 void add(Throwable *throwable,
00095 const ConstraintHolder<P1> &p1,
00096 const ConstraintHolder<P2> &p2,
00097 const ConstraintHolder<P3> &p3,
00098 const ConstraintHolder<P4> &p4,
00099 const ConstraintHolder<P5> &p5,
00100 unsigned count)
00101 {
00102 counter.push_back(count);
00103 tvec.push_back(throwable);
00104 typename MOCKPP_NS::Constraint<P1>::AP cons1 (p1);
00105 typename MOCKPP_NS::Constraint<P2>::AP cons2 (p2);
00106 typename MOCKPP_NS::Constraint<P3>::AP cons3 (p3);
00107 typename MOCKPP_NS::Constraint<P4>::AP cons4 (p4);
00108 typename MOCKPP_NS::Constraint<P5>::AP cons5 (p5);
00109 t1vec.push_back(cons1.release());
00110 t2vec.push_back(cons2.release());
00111 t3vec.push_back(cons3.release());
00112 t4vec.push_back(cons4.release());
00113 t5vec.push_back(cons5.release());
00114 }
00115
00118 void reset()
00119 {
00120 counter.clear();
00121 tvec.reset();
00122
00123 for (unsigned i1 = 0; i1 < t1vec.size(); ++i1)
00124 delete t1vec[i1];
00125 t1vec.clear();
00126
00127 for (unsigned i2 = 0; i2 < t2vec.size(); ++i2)
00128 delete t2vec[i2];
00129 t2vec.clear();
00130
00131 for (unsigned i3 = 0; i3 < t3vec.size(); ++i3)
00132 delete t3vec[i3];
00133 t3vec.clear();
00134
00135 for (unsigned i4 = 0; i4 < t4vec.size(); ++i4)
00136 delete t4vec[i4];
00137 t4vec.clear();
00138
00139 for (unsigned i5 = 0; i5 < t5vec.size(); ++i5)
00140 delete t5vec[i5];
00141 t5vec.clear();
00142 }
00143
00153 bool find(Throwable * &throwable, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4, const P5 &p5)
00154 {
00155 for (unsigned i = 0; i < t1vec.size(); ++i)
00156 if ( counter[i] > 0
00157 && t1vec[i]->eval(p1)
00158 && t2vec[i]->eval(p2)
00159 && t3vec[i]->eval(p3)
00160 && t4vec[i]->eval(p4)
00161 && t5vec[i]->eval(p5)
00162 )
00163 {
00164 if (tvec.at(i) == 0)
00165 return false;
00166
00167 if (counter[i] != MOCKPP_UNLIMITED)
00168 --counter[i];
00169
00170 throwable = tvec.at(i);
00171 return true;
00172 }
00173 return false;
00174 }
00175
00176 protected:
00177
00178 MOCKPP_STL::vector<Constraint<P1>*> t1vec;
00179 MOCKPP_STL::vector<Constraint<P2>*> t2vec;
00180 MOCKPP_STL::vector<Constraint<P3>*> t3vec;
00181 MOCKPP_STL::vector<Constraint<P4>*> t4vec;
00182 MOCKPP_STL::vector<Constraint<P5>*> t5vec;
00183 };
00184
00185
00189 template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5>
00190 class ResponseVector5 : public ResponseThrowableVector5<P1, P2, P3, P4, P5>
00191 {
00192 public:
00193
00198 ResponseVector5(const String &aName, VerifiableList *parent)
00199 : ResponseThrowableVector5<P1, P2, P3, P4, P5>(aName, parent)
00200 {}
00201
00211 void add(Throwable *throwable, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4, const P5 &p5, unsigned count)
00212 {
00213 MOCKPP_ASSERT_TRUE(throwable != 0);
00214 ResponseThrowableVector5<P1, P2, P3, P4, P5>::add(throwable, p1, p2, p3, p4, p5, count);
00215 R r;
00216 rvec.push_back(r);
00217 }
00218
00228 void add(Throwable *throwable,
00229 const ConstraintHolder<P1> &p1,
00230 const ConstraintHolder<P2> &p2,
00231 const ConstraintHolder<P3> &p3,
00232 const ConstraintHolder<P4> &p4,
00233 const ConstraintHolder<P5> &p5,
00234 unsigned count)
00235 {
00236 MOCKPP_ASSERT_TRUE(throwable != 0);
00237 ResponseThrowableVector5<P1, P2, P3, P4, P5>::add (throwable, p1, p2, p3, p4, p5, count);
00238 R r;
00239 rvec.push_back(r);
00240 }
00241
00251 void add(const R &r, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4, const P5 &p5, unsigned count)
00252 {
00253 ResponseThrowableVector5<P1, P2, P3, P4, P5>::add((Throwable*)0, p1, p2, p3, p4, p5, count);
00254 rvec.push_back(r);
00255 }
00256
00266 void add(const R &r,
00267 const ConstraintHolder<P1> &p1,
00268 const ConstraintHolder<P2> &p2,
00269 const ConstraintHolder<P3> &p3,
00270 const ConstraintHolder<P4> &p4,
00271 const ConstraintHolder<P5> &p5,
00272 unsigned count)
00273 {
00274 ResponseThrowableVector5<P1, P2, P3, P4, P5>::add((Throwable*)0, p1, p2, p3, p4, p5, count);
00275 rvec.push_back(r);
00276 }
00277
00280 void reset()
00281 {
00282 ResponseThrowableVector5<P1, P2, P3, P4, P5>::reset();
00283 rvec.clear();
00284 }
00285
00286 #if defined(__BORLANDC__) || (__GNUC__ < 3) // ==> BCB5.5.1 ?? F1004 Internal compiler error at 0x12548c1 with base 0x1200000
00287 bool find(Throwable * &throwable, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4, const P5 &p5)
00288 {
00289 return ResponseThrowableVector5<P1, P2, P3, P4, P5>::find(throwable, p1, p2, p3, p4, p5);
00290 }
00291 #else
00292 using ResponseThrowableVector5<P1, P2, P3, P4, P5>::find;
00293 #endif
00294
00304 bool find(R &r, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4, const P5 &p5)
00305 {
00306 for (unsigned i = 0; i < this->t1vec.size(); ++i)
00307 if ( this->counter[i] > 0
00308 && this->t1vec[i]->eval(p1)
00309 && this->t2vec[i]->eval(p2)
00310 && this->t3vec[i]->eval(p3)
00311 && this->t4vec[i]->eval(p4)
00312 && this->t5vec[i]->eval(p5)
00313 )
00314 {
00315 if (this->tvec.at(i) != 0)
00316 return false;
00317
00318 if (this->counter[i] != MOCKPP_UNLIMITED)
00319 --this->counter[i];
00320
00321 r = rvec[i];
00322 return true;
00323 }
00324 return false;
00325 }
00326
00327 private:
00328
00329 MOCKPP_STL::vector<R> rvec;
00330 };
00331
00332 MOCKPP_NS_END
00333
00334
00335 #endif // MOCKPP_ResponseVector5_H
00336