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_VisitableMockMethod3_H
00032 #define MOCKPP_VisitableMockMethod3_H
00033
00034 #include <mockpp/mockpp.h>
00035
00036 #include <mockpp/visiting/VisitableMockObject.h>
00037 #include <mockpp/visiting/VisitableMockMethod.h>
00038 #include <mockpp/visiting/ResponseVector3.h>
00039
00040
00041 MOCKPP_NS_START
00042
00043
00047 template <typename R, typename P1, typename P2, typename P3>
00048 class VisitableMockMethod3Common : public VisitableMockReturningMethodBase<R>
00049 {
00050 public:
00051
00056 VisitableMockMethod3Common(const String &name, VisitableMockObject *parent)
00057 : VisitableMockReturningMethodBase<R>(name, parent)
00058 , responseThrowables(this->getMethodName() + MOCKPP_PCHAR("/responseThrowables") , this)
00059 , parameter1(this->getMethodName() + MOCKPP_PCHAR("/parameter1"), this)
00060 , parameter2(this->getMethodName() + MOCKPP_PCHAR("/parameter2"), this)
00061 , parameter3(this->getMethodName() + MOCKPP_PCHAR("/parameter3"), this)
00062 {
00063 }
00064
00065
00071 void forward (const ConstraintHolder<P1> &p1, const ConstraintHolder<P2> &p2, const ConstraintHolder<P3> &p3) const
00072 {
00073 MOCKPP_ASSERT_FALSE_MESSAGE(this->getVisitableMockObject()->getVerifiableName() + MOCKPP_PCHAR(".isActivated() != true"),
00074 this->getVisitableMockObject()->isActivated());
00075 this->getVisitableMockObject()->addExpectedMethod(this->getMethodIdentifier());
00076 parameter1.addExpected(p1);
00077 parameter2.addExpected(p2);
00078 parameter3.addExpected(p3);
00079 }
00080
00081 protected:
00082
00088 void forward_param(const P1 &p1, const P2 &p2, const P3 &p3) const
00089 {
00090 if (!this->getVisitableMockObject()->isActivated() )
00091 {
00092 this->getVisitableMockObject()->addExpectedMethod(this->getMethodIdentifier());
00093 parameter1.addExpected(p1);
00094 parameter2.addExpected(p2);
00095 parameter3.addExpected(p3);
00096 }
00097
00098 else
00099 {
00100 MOCKPP_TRY
00101 {
00102 this->getVisitableMockObject()->addActualMethod(this->getMethodIdentifier());
00103
00104 Throwable *t;
00105 if (this->responseThrowables.find(t, p1, p2, p3))
00106 t->throw_me();
00107
00108 this->throwAvailableException();
00109 }
00110
00111 MOCKPP_CATCH_ALL
00112 {
00113 parameter1.balanceActual();
00114 parameter2.balanceActual();
00115 parameter3.balanceActual();
00116 MOCKPP_RETHROW;
00117 }
00118
00119 parameter1.addActual(p1);
00120 parameter2.addActual(p2);
00121 parameter3.addActual(p3);
00122 }
00123 }
00124
00125 public:
00126
00136 void addResponseThrowable(Throwable *t, const P1 &p1, const P2 &p2, const P3 &p3, unsigned count = MOCKPP_UNLIMITED)
00137 {
00138 MOCKPP_ASSERT_FALSE(this->getVisitableMockObject()->isActivated());
00139 this->responseThrowables.add(t, p1, p2, p3, count);
00140 }
00141
00151 void addResponseThrowable(Throwable *t, const ConstraintHolder<P1> &p1, const ConstraintHolder<P2> &p2, const ConstraintHolder<P3> &p3, unsigned count = MOCKPP_UNLIMITED)
00152 {
00153 MOCKPP_ASSERT_FALSE(this->getVisitableMockObject()->isActivated());
00154 this->responseThrowables.add(t, p1, p2, p3, count);
00155 }
00156
00157 private:
00158
00159 mutable ResponseThrowableVector3<P1, P2, P3> responseThrowables;
00160
00161 mutable ConstraintList<P1> parameter1;
00162 mutable ConstraintList<P2> parameter2;
00163 mutable ConstraintList<P3> parameter3;
00164 };
00165
00166
00170 template <typename R, typename P1, typename P2, typename P3>
00171 class VisitableMockMethod3
00172 : public VisitableMockMethod3Common<R, P1, P2, P3>
00173 {
00174 public:
00175
00180 VisitableMockMethod3(const String &name, VisitableMockObject *parent)
00181 : VisitableMockMethod3Common<R, P1, P2, P3>(name, parent)
00182 , responseValues(this->getMethodName() + MOCKPP_PCHAR("/responseValues") , this)
00183 {
00184 }
00185
00192 R forward(const P1 &p1, const P2 &p2, const P3 &p3) const
00193 {
00194 this->forward_param(p1, p2, p3);
00195
00196 if (this->getVisitableMockObject()->isActivated() )
00197 {
00198 R ret_val;
00199 if (this->responseValues.find(ret_val, p1, p2, p3))
00200 return ret_val;
00201
00202 return this->determineReturnValue();
00203 }
00204 else
00205 return R();
00206 }
00207
00208 #if defined(__BORLANDC__) // ==> BCB5.5.1 ?? F1004 Internal compiler error at 0x12548c1 with base 0x1200000
00209
00214 void forward (const ConstraintHolder<P1> &p1, const ConstraintHolder<P2> &p2, const ConstraintHolder<P3> &p3) const
00215 {
00216 VisitableMockMethod3Common<R, P1, P2, P3>::forward(p1, p2, p3);
00217 }
00218 #else
00219 using VisitableMockMethod3Common<R, P1, P2, P3>::forward;
00220 #endif
00221
00231 void addResponseValue(const R &rv, const P1 &p1, const P2 &p2, const P3 &p3, unsigned count = MOCKPP_UNLIMITED)
00232 {
00233 MOCKPP_ASSERT_FALSE(this->getVisitableMockObject()->isActivated());
00234 this->responseValues.add(rv, p1, p2, p3, count);
00235 }
00236
00246 void addResponseValue(const R &rv, const ConstraintHolder<P1> &p1, const ConstraintHolder<P2> &p2, const ConstraintHolder<P3> &p3, unsigned count = MOCKPP_UNLIMITED)
00247 {
00248 MOCKPP_ASSERT_FALSE(this->getVisitableMockObject()->isActivated());
00249 this->responseValues.add(rv, p1, p2, p3, count);
00250 }
00251
00252 private:
00253
00254 mutable ResponseVector3<R, P1, P2, P3> responseValues;
00255 };
00256
00257
00262 template <typename P1, typename P2, typename P3>
00263 class VisitableMockMethod3<void, P1, P2, P3>
00264 : public VisitableMockMethod3Common<void, P1, P2, P3>
00265 {
00266 public:
00267
00272 VisitableMockMethod3(const String &name, VisitableMockObject *parent)
00273 : VisitableMockMethod3Common<void, P1, P2, P3>(name, parent)
00274 {
00275 }
00276
00283 void forward(const P1 &p1, const P2 &p2, const P3 &p3) const
00284 {
00285 this->forward_param(p1, p2, p3);
00286 }
00287
00288 #if defined(__BORLANDC__) // ==> BCB5.5.1 ?? F1004 Internal compiler error at 0x12548c1 with base 0x1200000
00289
00294 void forward (const ConstraintHolder<P1> &p1, const ConstraintHolder<P2> &p2, const ConstraintHolder<P3> &p3) const
00295 {
00296 VisitableMockMethod3Common<void, P1, P2, P3>::forward(p1, p2, p3);
00297 }
00298 #else
00299 using VisitableMockMethod3Common<void, P1, P2, P3>::forward;
00300 #endif
00301 };
00302
00303
00304 MOCKPP_NS_END
00305
00306
00307 #endif // MOCKPP_VisitableMockMethod3_H
00308