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_ResponseVector3_H
00032 #define MOCKPP_ResponseVector3_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>
00046 class ResponseThrowableVector3 : public ResponseVectorBase
00047 {
00048 public:
00049
00055 ResponseThrowableVector3(const String &aName, VerifiableList *parent)
00056 : ResponseVectorBase(aName, parent)
00057 {}
00058
00061 virtual ~ResponseThrowableVector3()
00062 {
00063 reset();
00064 }
00065
00073 void add(Throwable *throwable, const P1 &p1, const P2 &p2, const P3 &p3, unsigned count)
00074 {
00075 const ConstraintHolder<P1> h1 = new IsEqual<P1>(p1);
00076 const ConstraintHolder<P2> h2 = new IsEqual<P2>(p2);
00077 const ConstraintHolder<P3> h3 = new IsEqual<P3>(p3);
00078 add(throwable, h1, h2, h3, count);
00079 }
00080
00088 void add(Throwable *throwable,
00089 const ConstraintHolder<P1> &p1,
00090 const ConstraintHolder<P2> &p2,
00091 const ConstraintHolder<P3> &p3,
00092 unsigned count)
00093 {
00094 counter.push_back(count);
00095 tvec.push_back(throwable);
00096 typename MOCKPP_NS::Constraint<P1>::AP cons1 (p1);
00097 typename MOCKPP_NS::Constraint<P2>::AP cons2 (p2);
00098 typename MOCKPP_NS::Constraint<P3>::AP cons3 (p3);
00099 t1vec.push_back(cons1.release());
00100 t2vec.push_back(cons2.release());
00101 t3vec.push_back(cons3.release());
00102 }
00103
00106 void reset()
00107 {
00108 counter.clear();
00109 tvec.reset();
00110
00111 for (unsigned i1 = 0; i1 < t1vec.size(); ++i1)
00112 delete t1vec[i1];
00113 t1vec.clear();
00114
00115 for (unsigned i2 = 0; i2 < t2vec.size(); ++i2)
00116 delete t2vec[i2];
00117 t2vec.clear();
00118
00119 for (unsigned i3 = 0; i3 < t3vec.size(); ++i3)
00120 delete t3vec[i3];
00121 t3vec.clear();
00122 }
00123
00131 bool find(Throwable * &throwable, const P1 &p1, const P2 &p2, const P3 &p3)
00132 {
00133 for (unsigned i = 0; i < t1vec.size(); ++i)
00134 if ( counter[i] > 0
00135 && t1vec[i]->eval(p1)
00136 && t2vec[i]->eval(p2)
00137 && t3vec[i]->eval(p3)
00138 )
00139 {
00140 if (tvec.at(i) == 0)
00141 return false;
00142
00143 if (counter[i] != MOCKPP_UNLIMITED)
00144 --counter[i];
00145
00146 throwable = tvec.at(i);
00147 return true;
00148 }
00149 return false;
00150 }
00151
00152 protected:
00153
00154 MOCKPP_STL::vector<Constraint<P1>*> t1vec;
00155 MOCKPP_STL::vector<Constraint<P2>*> t2vec;
00156 MOCKPP_STL::vector<Constraint<P3>*> t3vec;
00157 };
00158
00159
00163 template <typename R, typename P1, typename P2, typename P3>
00164 class ResponseVector3 : public ResponseThrowableVector3<P1, P2, P3>
00165 {
00166 public:
00167
00172 ResponseVector3(const String &aName, VerifiableList *parent)
00173 : ResponseThrowableVector3<P1, P2, P3>(aName, parent)
00174 {}
00175
00183 void add(Throwable *throwable, const P1 &p1, const P2 &p2, const P3 &p3, unsigned count)
00184 {
00185 MOCKPP_ASSERT_TRUE(throwable != 0);
00186 ResponseThrowableVector3<P1, P2, P3>::add(throwable, p1, p2, p3, count);
00187 R r;
00188 rvec.push_back(r);
00189 }
00190
00198 void add(Throwable *throwable,
00199 const ConstraintHolder<P1> &p1,
00200 const ConstraintHolder<P2> &p2,
00201 const ConstraintHolder<P3> &p3,
00202 unsigned count)
00203 {
00204 MOCKPP_ASSERT_TRUE(throwable != 0);
00205 ResponseThrowableVector3<P1, P2, P3>::add (throwable, p1, p2, p3, count);
00206 R r;
00207 rvec.push_back(r);
00208 }
00209
00217 void add(const R &r, const P1 &p1, const P2 &p2, const P3 &p3, unsigned count)
00218 {
00219 ResponseThrowableVector3<P1, P2, P3>::add((Throwable*)0, p1, p2, p3, count);
00220 rvec.push_back(r);
00221 }
00222
00230 void add(const R &r,
00231 const ConstraintHolder<P1> &p1,
00232 const ConstraintHolder<P2> &p2,
00233 const ConstraintHolder<P3> &p3,
00234 unsigned count)
00235 {
00236 ResponseThrowableVector3<P1, P2, P3>::add((Throwable*)0, p1, p2, p3, count);
00237 rvec.push_back(r);
00238 }
00239
00242 void reset()
00243 {
00244 ResponseThrowableVector3<P1, P2, P3>::reset();
00245 rvec.clear();
00246 }
00247
00248 #if defined(__BORLANDC__) || (__GNUC__ < 3) // ==> BCB5.5.1 ?? F1004 Internal compiler error at 0x12548c1 with base 0x1200000
00249 bool find(Throwable * &throwable, const P1 &p1, const P2 &p2, const P3 &p3)
00250 {
00251 return ResponseThrowableVector3<P1, P2, P3>::find(throwable, p1, p2, p3);
00252 }
00253 #else
00254 using ResponseThrowableVector3<P1, P2, P3>::find;
00255 #endif
00256
00264 bool find(R &r, const P1 &p1, const P2 &p2, const P3 &p3)
00265 {
00266 for (unsigned i = 0; i < this->t1vec.size(); ++i)
00267 if ( this->counter[i] > 0
00268 && this->t1vec[i]->eval(p1)
00269 && this->t2vec[i]->eval(p2)
00270 && this->t3vec[i]->eval(p3)
00271 )
00272 {
00273 if (this->tvec.at(i) != 0)
00274 return false;
00275
00276 if (this->counter[i] != MOCKPP_UNLIMITED)
00277 --this->counter[i];
00278
00279 r = rvec[i];
00280 return true;
00281 }
00282 return false;
00283 }
00284
00285 private:
00286
00287 MOCKPP_STL::vector<R> rvec;
00288 };
00289
00290 MOCKPP_NS_END
00291
00292
00293 #endif // MOCKPP_ResponseVector3_H
00294