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_VisitableMockMethod4_H
00032 #define MOCKPP_VisitableMockMethod4_H
00033
00034 #include <mockpp/mockpp.h>
00035
00036 #include <mockpp/visiting/VisitableMockObject.h>
00037 #include <mockpp/visiting/VisitableMockMethod.h>
00038 #include <mockpp/visiting/ResponseVector4.h>
00039
00040
00041 MOCKPP_NS_START
00042
00043
00047 template <typename R, typename P1, typename P2, typename P3, typename P4>
00048 class VisitableMockMethod4Common : public VisitableMockReturningMethodBase<R>
00049 {
00050 public:
00051
00056 VisitableMockMethod4Common(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 , parameter4(this->getMethodName() + MOCKPP_PCHAR("/parameter4"), this)
00063 {
00064 }
00065
00066
00073 void forward (const ConstraintHolder<P1> &p1, const ConstraintHolder<P2> &p2, const ConstraintHolder<P3> &p3, const ConstraintHolder<P4> &p4) const
00074 {
00075 MOCKPP_ASSERT_FALSE_MESSAGE(this->getVisitableMockObject()->getVerifiableName() + MOCKPP_PCHAR(".isActivated() != true"),
00076 this->getVisitableMockObject()->isActivated());
00077 this->getVisitableMockObject()->addExpectedMethod(this->getMethodIdentifier());
00078 parameter1.addExpected(p1);
00079 parameter2.addExpected(p2);
00080 parameter3.addExpected(p3);
00081 parameter4.addExpected(p4);
00082 }
00083
00084 protected:
00085
00092 void forward_param(const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4) const
00093 {
00094 if (!this->getVisitableMockObject()->isActivated() )
00095 {
00096 this->getVisitableMockObject()->addExpectedMethod(this->getMethodIdentifier());
00097 parameter1.addExpected(p1);
00098 parameter2.addExpected(p2);
00099 parameter3.addExpected(p3);
00100 parameter4.addExpected(p4);
00101 }
00102
00103 else
00104 {
00105 MOCKPP_TRY
00106 {
00107 this->getVisitableMockObject()->addActualMethod(this->getMethodIdentifier());
00108
00109 Throwable *t;
00110 if (this->responseThrowables.find(t, p1, p2, p3, p4))
00111 t->throw_me();
00112
00113 this->throwAvailableException();
00114 }
00115
00116 MOCKPP_CATCH_ALL
00117 {
00118 parameter1.balanceActual();
00119 parameter2.balanceActual();
00120 parameter3.balanceActual();
00121 parameter4.balanceActual();
00122 MOCKPP_RETHROW;
00123 }
00124
00125 parameter1.addActual(p1);
00126 parameter2.addActual(p2);
00127 parameter3.addActual(p3);
00128 parameter4.addActual(p4);
00129 }
00130 }
00131
00132 public:
00133
00144 void addResponseThrowable(Throwable *t, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4, unsigned count = MOCKPP_UNLIMITED)
00145 {
00146 MOCKPP_ASSERT_FALSE(this->getVisitableMockObject()->isActivated());
00147 this->responseThrowables.add(t, p1, p2, p3, p4, count);
00148 }
00149
00160 void addResponseThrowable(Throwable *t, const ConstraintHolder<P1> &p1, const ConstraintHolder<P2> &p2, const ConstraintHolder<P3> &p3, const ConstraintHolder<P4> &p4, unsigned count = MOCKPP_UNLIMITED)
00161 {
00162 MOCKPP_ASSERT_FALSE(this->getVisitableMockObject()->isActivated());
00163 this->responseThrowables.add(t, p1, p2, p3, p4, count);
00164 }
00165
00166 private:
00167
00168 mutable ResponseThrowableVector4<P1, P2, P3, P4> responseThrowables;
00169
00170 mutable ConstraintList<P1> parameter1;
00171 mutable ConstraintList<P2> parameter2;
00172 mutable ConstraintList<P3> parameter3;
00173 mutable ConstraintList<P4> parameter4;
00174 };
00175
00176
00180 template <typename R, typename P1, typename P2, typename P3, typename P4>
00181 class VisitableMockMethod4
00182 : public VisitableMockMethod4Common<R, P1, P2, P3, P4>
00183 {
00184 public:
00185
00190 VisitableMockMethod4(const String &name, VisitableMockObject *parent)
00191 : VisitableMockMethod4Common<R, P1, P2, P3, P4>(name, parent)
00192 , responseValues(this->getMethodName() + MOCKPP_PCHAR("/responseValues") , this)
00193 {
00194 }
00195
00203 R forward(const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4) const
00204 {
00205 this->forward_param(p1, p2, p3, p4);
00206
00207 if (this->getVisitableMockObject()->isActivated() )
00208 {
00209 R ret_val;
00210 if (this->responseValues.find(ret_val, p1, p2, p3, p4))
00211 return ret_val;
00212
00213 return this->determineReturnValue();
00214 }
00215 else
00216 return R();
00217 }
00218
00219 #if defined(__BORLANDC__) // ==> BCB5.5.1 ?? F1004 Internal compiler error at 0x12548c1 with base 0x1200000
00220
00226 void forward (const ConstraintHolder<P1> &p1, const ConstraintHolder<P2> &p2, const ConstraintHolder<P3> &p3, const ConstraintHolder<P4> &p4) const
00227 {
00228 VisitableMockMethod4Common<R, P1, P2, P3, P4>::forward(p1, p2, p3, p4);
00229 }
00230 #else
00231 using VisitableMockMethod4Common<R, P1, P2, P3, P4>::forward;
00232 #endif
00233
00244 void addResponseValue(const R &rv, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4, unsigned count = MOCKPP_UNLIMITED)
00245 {
00246 MOCKPP_ASSERT_FALSE(this->getVisitableMockObject()->isActivated());
00247 this->responseValues.add(rv, p1, p2, p3, p4, count);
00248 }
00249
00260 void addResponseValue(const R &rv, const ConstraintHolder<P1> &p1, const ConstraintHolder<P2> &p2, const ConstraintHolder<P3> &p3, const ConstraintHolder<P4> &p4, unsigned count = MOCKPP_UNLIMITED)
00261 {
00262 MOCKPP_ASSERT_FALSE(this->getVisitableMockObject()->isActivated());
00263 this->responseValues.add(rv, p1, p2, p3, p4, count);
00264 }
00265
00266 private:
00267
00268 mutable ResponseVector4<R, P1, P2, P3, P4> responseValues;
00269 };
00270
00271
00276 template <typename P1, typename P2, typename P3, typename P4>
00277 class VisitableMockMethod4<void, P1, P2, P3, P4>
00278 : public VisitableMockMethod4Common<void, P1, P2, P3, P4>
00279 {
00280 public:
00281
00286 VisitableMockMethod4(const String &name, VisitableMockObject *parent)
00287 : VisitableMockMethod4Common<void, P1, P2, P3, P4>(name, parent)
00288 {
00289 }
00290
00298 void forward(const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4) const
00299 {
00300 this->forward_param(p1, p2, p3, p4);
00301 }
00302
00303 #if defined(__BORLANDC__) // ==> BCB5.5.1 ?? F1004 Internal compiler error at 0x12548c1 with base 0x1200000
00304
00310 void forward (const ConstraintHolder<P1> &p1, const ConstraintHolder<P2> &p2, const ConstraintHolder<P3> &p3, const ConstraintHolder<P4> &p4) const
00311 {
00312 VisitableMockMethod4Common<void, P1, P2, P3, P4>::forward(p1, p2, p3, p4);
00313 }
00314 #else
00315 using VisitableMockMethod4Common<void, P1, P2, P3, P4>::forward;
00316 #endif
00317 };
00318
00319
00320 MOCKPP_NS_END
00321
00322
00323 #endif // MOCKPP_VisitableMockMethod4_H
00324