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_VisitableMockMethod2_H
00032 #define MOCKPP_VisitableMockMethod2_H
00033
00034 #include <mockpp/mockpp.h>
00035
00036 #include <mockpp/visiting/VisitableMockObject.h>
00037 #include <mockpp/visiting/VisitableMockMethod.h>
00038 #include <mockpp/visiting/ResponseVector2.h>
00039
00040
00041 MOCKPP_NS_START
00042
00043
00047 template <typename R, typename P1, typename P2>
00048 class VisitableMockMethod2Common : public VisitableMockReturningMethodBase<R>
00049 {
00050 public:
00051
00056 VisitableMockMethod2Common(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 {
00062 }
00063
00064
00069 void forward (const ConstraintHolder<P1> &p1, const ConstraintHolder<P2> &p2) const
00070 {
00071 MOCKPP_ASSERT_FALSE_MESSAGE(this->getVisitableMockObject()->getVerifiableName() + MOCKPP_PCHAR(".isActivated() != true"),
00072 this->getVisitableMockObject()->isActivated());
00073 this->getVisitableMockObject()->addExpectedMethod(this->getMethodIdentifier());
00074 parameter1.addExpected(p1);
00075 parameter2.addExpected(p2);
00076 }
00077
00078 protected:
00079
00084 void forward_param(const P1 &p1, const P2 &p2) const
00085 {
00086 if (!this->getVisitableMockObject()->isActivated() )
00087 {
00088 this->getVisitableMockObject()->addExpectedMethod(this->getMethodIdentifier());
00089 parameter1.addExpected(p1);
00090 parameter2.addExpected(p2);
00091 }
00092
00093 else
00094 {
00095 MOCKPP_TRY
00096 {
00097 this->getVisitableMockObject()->addActualMethod(this->getMethodIdentifier());
00098
00099 Throwable *t;
00100 if (this->responseThrowables.find(t, p1, p2))
00101 t->throw_me();
00102
00103 this->throwAvailableException();
00104 }
00105
00106 MOCKPP_CATCH_ALL
00107 {
00108 parameter1.balanceActual();
00109 parameter2.balanceActual();
00110 MOCKPP_RETHROW;
00111 }
00112
00113 parameter1.addActual(p1);
00114 parameter2.addActual(p2);
00115 }
00116 }
00117
00118 public:
00119
00128 void addResponseThrowable(Throwable *t, const P1 &p1, const P2 &p2, unsigned count = MOCKPP_UNLIMITED)
00129 {
00130 MOCKPP_ASSERT_FALSE(this->getVisitableMockObject()->isActivated());
00131 this->responseThrowables.add(t, p1, p2, count);
00132 }
00133
00142 void addResponseThrowable(Throwable *t, const ConstraintHolder<P1> &p1, const ConstraintHolder<P2> &p2, unsigned count = MOCKPP_UNLIMITED)
00143 {
00144 MOCKPP_ASSERT_FALSE(this->getVisitableMockObject()->isActivated());
00145 this->responseThrowables.add(t, p1, p2, count);
00146 }
00147
00148 private:
00149
00150 mutable ResponseThrowableVector2<P1, P2> responseThrowables;
00151
00152 mutable ConstraintList<P1> parameter1;
00153 mutable ConstraintList<P2> parameter2;
00154 };
00155
00156
00160 template <typename R, typename P1, typename P2>
00161 class VisitableMockMethod2
00162 : public VisitableMockMethod2Common<R, P1, P2>
00163 {
00164 public:
00165
00170 VisitableMockMethod2(const String &name, VisitableMockObject *parent)
00171 : VisitableMockMethod2Common<R, P1, P2>(name, parent)
00172 , responseValues(this->getMethodName() + MOCKPP_PCHAR("/responseValues") , this)
00173 {
00174 }
00175
00181 R forward(const P1 &p1, const P2 &p2) const
00182 {
00183 this->forward_param(p1, p2);
00184
00185 if (this->getVisitableMockObject()->isActivated() )
00186 {
00187 R ret_val;
00188 if (this->responseValues.find(ret_val, p1, p2))
00189 return ret_val;
00190
00191 return this->determineReturnValue();
00192 }
00193 else
00194 return R();
00195 }
00196
00197 #if defined(__BORLANDC__) // ==> BCB5.5.1 ?? F1004 Internal compiler error at 0x12548c1 with base 0x1200000
00198
00202 void forward (const ConstraintHolder<P1> &p1, const ConstraintHolder<P2> &p2) const
00203 {
00204 VisitableMockMethod2Common<R, P1, P2>::forward(p1, p2);
00205 }
00206 #else
00207 using VisitableMockMethod2Common<R, P1, P2>::forward;
00208 #endif
00209
00218 void addResponseValue(const R &rv, const P1 &p1, const P2 &p2, unsigned count = MOCKPP_UNLIMITED)
00219 {
00220 MOCKPP_ASSERT_FALSE(this->getVisitableMockObject()->isActivated());
00221 this->responseValues.add(rv, p1, p2, count);
00222 }
00223
00232 void addResponseValue(const R &rv, const ConstraintHolder<P1> &p1, const ConstraintHolder<P2> &p2, unsigned count = MOCKPP_UNLIMITED)
00233 {
00234 MOCKPP_ASSERT_FALSE(this->getVisitableMockObject()->isActivated());
00235 this->responseValues.add(rv, p1, p2, count);
00236 }
00237
00238 private:
00239
00240 mutable ResponseVector2<R, P1, P2> responseValues;
00241 };
00242
00243
00248 template <typename P1, typename P2>
00249 class VisitableMockMethod2<void, P1, P2>
00250 : public VisitableMockMethod2Common<void, P1, P2>
00251 {
00252 public:
00253
00258 VisitableMockMethod2(const String &name, VisitableMockObject *parent)
00259 : VisitableMockMethod2Common<void, P1, P2>(name, parent)
00260 {
00261 }
00262
00268 void forward(const P1 &p1, const P2 &p2) const
00269 {
00270 this->forward_param(p1, p2);
00271 }
00272
00273 #if defined(__BORLANDC__) // ==> BCB5.5.1 ?? F1004 Internal compiler error at 0x12548c1 with base 0x1200000
00274
00278 void forward (const ConstraintHolder<P1> &p1, const ConstraintHolder<P2> &p2) const
00279 {
00280 VisitableMockMethod2Common<void, P1, P2>::forward(p1, p2);
00281 }
00282 #else
00283 using VisitableMockMethod2Common<void, P1, P2>::forward;
00284 #endif
00285 };
00286
00287
00288 MOCKPP_NS_END
00289
00290
00291 #endif // MOCKPP_VisitableMockMethod2_H
00292