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_ResponseVector4_H
00032 #define MOCKPP_ResponseVector4_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>
00046 class ResponseThrowableVector4 : public ResponseVectorBase
00047 {
00048 public:
00049
00055 ResponseThrowableVector4(const String &aName, VerifiableList *parent)
00056 : ResponseVectorBase(aName, parent)
00057 {}
00058
00061 virtual ~ResponseThrowableVector4()
00062 {
00063 reset();
00064 }
00065
00074 void add(Throwable *throwable, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4, unsigned count)
00075 {
00076 const ConstraintHolder<P1> h1 = new IsEqual<P1>(p1);
00077 const ConstraintHolder<P2> h2 = new IsEqual<P2>(p2);
00078 const ConstraintHolder<P3> h3 = new IsEqual<P3>(p3);
00079 const ConstraintHolder<P4> h4 = new IsEqual<P4>(p4);
00080 add(throwable, h1, h2, h3, h4, count);
00081 }
00082
00091 void add(Throwable *throwable,
00092 const ConstraintHolder<P1> &p1,
00093 const ConstraintHolder<P2> &p2,
00094 const ConstraintHolder<P3> &p3,
00095 const ConstraintHolder<P4> &p4,
00096 unsigned count)
00097 {
00098 counter.push_back(count);
00099 tvec.push_back(throwable);
00100 typename MOCKPP_NS::Constraint<P1>::AP cons1 (p1);
00101 typename MOCKPP_NS::Constraint<P2>::AP cons2 (p2);
00102 typename MOCKPP_NS::Constraint<P3>::AP cons3 (p3);
00103 typename MOCKPP_NS::Constraint<P4>::AP cons4 (p4);
00104 t1vec.push_back(cons1.release());
00105 t2vec.push_back(cons2.release());
00106 t3vec.push_back(cons3.release());
00107 t4vec.push_back(cons4.release());
00108 }
00109
00112 void reset()
00113 {
00114 counter.clear();
00115 tvec.reset();
00116
00117 for (unsigned i1 = 0; i1 < t1vec.size(); ++i1)
00118 delete t1vec[i1];
00119 t1vec.clear();
00120
00121 for (unsigned i2 = 0; i2 < t2vec.size(); ++i2)
00122 delete t2vec[i2];
00123 t2vec.clear();
00124
00125 for (unsigned i3 = 0; i3 < t3vec.size(); ++i3)
00126 delete t3vec[i3];
00127 t3vec.clear();
00128
00129 for (unsigned i4 = 0; i4 < t4vec.size(); ++i4)
00130 delete t4vec[i4];
00131 t4vec.clear();
00132 }
00133
00142 bool find(Throwable * &throwable, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4)
00143 {
00144 for (unsigned i = 0; i < t1vec.size(); ++i)
00145 if ( counter[i] > 0
00146 && t1vec[i]->eval(p1)
00147 && t2vec[i]->eval(p2)
00148 && t3vec[i]->eval(p3)
00149 && t4vec[i]->eval(p4)
00150 )
00151 {
00152 if (tvec.at(i) == 0)
00153 return false;
00154
00155 if (counter[i] != MOCKPP_UNLIMITED)
00156 --counter[i];
00157
00158 throwable = tvec.at(i);
00159 return true;
00160 }
00161 return false;
00162 }
00163
00164 protected:
00165
00166 MOCKPP_STL::vector<Constraint<P1>*> t1vec;
00167 MOCKPP_STL::vector<Constraint<P2>*> t2vec;
00168 MOCKPP_STL::vector<Constraint<P3>*> t3vec;
00169 MOCKPP_STL::vector<Constraint<P4>*> t4vec;
00170 };
00171
00172
00176 template <typename R, typename P1, typename P2, typename P3, typename P4>
00177 class ResponseVector4 : public ResponseThrowableVector4<P1, P2, P3, P4>
00178 {
00179 public:
00180
00185 ResponseVector4(const String &aName, VerifiableList *parent)
00186 : ResponseThrowableVector4<P1, P2, P3, P4>(aName, parent)
00187 {}
00188
00197 void add(Throwable *throwable, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4, unsigned count)
00198 {
00199 MOCKPP_ASSERT_TRUE(throwable != 0);
00200 ResponseThrowableVector4<P1, P2, P3, P4>::add(throwable, p1, p2, p3, p4, count);
00201 R r;
00202 rvec.push_back(r);
00203 }
00204
00213 void add(Throwable *throwable,
00214 const ConstraintHolder<P1> &p1,
00215 const ConstraintHolder<P2> &p2,
00216 const ConstraintHolder<P3> &p3,
00217 const ConstraintHolder<P4> &p4,
00218 unsigned count)
00219 {
00220 MOCKPP_ASSERT_TRUE(throwable != 0);
00221 ResponseThrowableVector4<P1, P2, P3, P4>::add (throwable, p1, p2, p3, p4, count);
00222 R r;
00223 rvec.push_back(r);
00224 }
00225
00234 void add(const R &r, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4, unsigned count)
00235 {
00236 ResponseThrowableVector4<P1, P2, P3, P4>::add((Throwable*)0, p1, p2, p3, p4, count);
00237 rvec.push_back(r);
00238 }
00239
00248 void add(const R &r,
00249 const ConstraintHolder<P1> &p1,
00250 const ConstraintHolder<P2> &p2,
00251 const ConstraintHolder<P3> &p3,
00252 const ConstraintHolder<P4> &p4,
00253 unsigned count)
00254 {
00255 ResponseThrowableVector4<P1, P2, P3, P4>::add((Throwable*)0, p1, p2, p3, p4, count);
00256 rvec.push_back(r);
00257 }
00258
00261 void reset()
00262 {
00263 ResponseThrowableVector4<P1, P2, P3, P4>::reset();
00264 rvec.clear();
00265 }
00266
00267 #if defined(__BORLANDC__) || (__GNUC__ < 3) // ==> BCB5.5.1 ?? F1004 Internal compiler error at 0x12548c1 with base 0x1200000
00268 bool find(Throwable * &throwable, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4)
00269 {
00270 return ResponseThrowableVector4<P1, P2, P3, P4>::find(throwable, p1, p2, p3, p4);
00271 }
00272 #else
00273 using ResponseThrowableVector4<P1, P2, P3, P4>::find;
00274 #endif
00275
00284 bool find(R &r, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4)
00285 {
00286 for (unsigned i = 0; i < this->t1vec.size(); ++i)
00287 if ( this->counter[i] > 0
00288 && this->t1vec[i]->eval(p1)
00289 && this->t2vec[i]->eval(p2)
00290 && this->t3vec[i]->eval(p3)
00291 && this->t4vec[i]->eval(p4)
00292 )
00293 {
00294 if (this->tvec.at(i) != 0)
00295 return false;
00296
00297 if (this->counter[i] != MOCKPP_UNLIMITED)
00298 --this->counter[i];
00299
00300 r = rvec[i];
00301 return true;
00302 }
00303 return false;
00304 }
00305
00306 private:
00307
00308 MOCKPP_STL::vector<R> rvec;
00309 };
00310
00311 MOCKPP_NS_END
00312
00313
00314 #endif // MOCKPP_ResponseVector4_H
00315