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_VisitableMockMethod1_H
00032 #define MOCKPP_VisitableMockMethod1_H
00033
00034 #include <mockpp/mockpp.h>
00035
00036 #include <mockpp/visiting/VisitableMockObject.h>
00037 #include <mockpp/visiting/VisitableMockMethod.h>
00038 #include <mockpp/visiting/ResponseVector1.h>
00039
00040
00041 MOCKPP_NS_START
00042
00043
00047 template <typename R, typename P1>
00048 class VisitableMockMethod1Common : public VisitableMockReturningMethodBase<R>
00049 {
00050 public:
00051
00056 VisitableMockMethod1Common(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 {
00061 }
00062
00063
00067 void forward (const ConstraintHolder<P1> &p1) const
00068 {
00069 MOCKPP_ASSERT_FALSE_MESSAGE(this->getVisitableMockObject()->getVerifiableName() + MOCKPP_PCHAR(".isActivated() != true"),
00070 this->getVisitableMockObject()->isActivated());
00071 this->getVisitableMockObject()->addExpectedMethod(this->getMethodIdentifier());
00072 parameter1.addExpected(p1);
00073 }
00074
00075 protected:
00076
00080 void forward_param(const P1 &p1) const
00081 {
00082 if (!this->getVisitableMockObject()->isActivated() )
00083 {
00084 this->getVisitableMockObject()->addExpectedMethod(this->getMethodIdentifier());
00085 parameter1.addExpected(p1);
00086 }
00087
00088 else
00089 {
00090 MOCKPP_TRY
00091 {
00092 this->getVisitableMockObject()->addActualMethod(this->getMethodIdentifier());
00093
00094 Throwable *t;
00095 if (this->responseThrowables.find(t, p1))
00096 t->throw_me();
00097
00098 this->throwAvailableException();
00099 }
00100
00101 MOCKPP_CATCH_ALL
00102 {
00103 parameter1.balanceActual();
00104 MOCKPP_RETHROW;
00105 }
00106
00107 parameter1.addActual(p1);
00108 }
00109 }
00110
00111 public:
00112
00120 void addResponseThrowable(Throwable *t, const P1 &p1, unsigned count = MOCKPP_UNLIMITED)
00121 {
00122 MOCKPP_ASSERT_FALSE(this->getVisitableMockObject()->isActivated());
00123 this->responseThrowables.add(t, p1, count);
00124 }
00125
00133 void addResponseThrowable(Throwable *t, const ConstraintHolder<P1> &p1, unsigned count = MOCKPP_UNLIMITED)
00134 {
00135 MOCKPP_ASSERT_FALSE(this->getVisitableMockObject()->isActivated());
00136 this->responseThrowables.add(t, p1, count);
00137 }
00138
00139 private:
00140
00141 mutable ResponseThrowableVector1<P1> responseThrowables;
00142
00143 mutable ConstraintList<P1> parameter1;
00144 };
00145
00146
00150 template <typename R, typename P1>
00151 class VisitableMockMethod1
00152 : public VisitableMockMethod1Common<R, P1>
00153 {
00154 public:
00155
00160 VisitableMockMethod1(const String &name, VisitableMockObject *parent)
00161 : VisitableMockMethod1Common<R, P1>(name, parent)
00162 , responseValues(this->getMethodName() + MOCKPP_PCHAR("/responseValues") , this)
00163 {
00164 }
00165
00170 R forward(const P1 &p1) const
00171 {
00172 this->forward_param(p1);
00173
00174 if (this->getVisitableMockObject()->isActivated() )
00175 {
00176 R ret_val;
00177 if (this->responseValues.find(ret_val, p1))
00178 return ret_val;
00179
00180 return this->determineReturnValue();
00181 }
00182 else
00183 return R();
00184 }
00185
00186 #if defined(__BORLANDC__) // ==> BCB5.5.1 ?? F1004 Internal compiler error at 0x12548c1 with base 0x1200000
00187
00190 void forward (const ConstraintHolder<P1> &p1) const
00191 {
00192 VisitableMockMethod1Common<R, P1>::forward(p1);
00193 }
00194 #else
00195 using VisitableMockMethod1Common<R, P1>::forward;
00196 #endif
00197
00205 void addResponseValue(const R &rv, const P1 &p1, unsigned count = MOCKPP_UNLIMITED)
00206 {
00207 MOCKPP_ASSERT_FALSE(this->getVisitableMockObject()->isActivated());
00208 this->responseValues.add(rv, p1, count);
00209 }
00210
00218 void addResponseValue(const R &rv, const ConstraintHolder<P1> &p1, unsigned count = MOCKPP_UNLIMITED)
00219 {
00220 MOCKPP_ASSERT_FALSE(this->getVisitableMockObject()->isActivated());
00221 this->responseValues.add(rv, p1, count);
00222 }
00223
00224 private:
00225
00226 mutable ResponseVector1<R, P1> responseValues;
00227 };
00228
00229
00234 template <typename P1>
00235 class VisitableMockMethod1<void, P1>
00236 : public VisitableMockMethod1Common<void, P1>
00237 {
00238 public:
00239
00244 VisitableMockMethod1(const String &name, VisitableMockObject *parent)
00245 : VisitableMockMethod1Common<void, P1>(name, parent)
00246 {
00247 }
00248
00253 void forward(const P1 &p1) const
00254 {
00255 this->forward_param(p1);
00256 }
00257
00258 #if defined(__BORLANDC__) // ==> BCB5.5.1 ?? F1004 Internal compiler error at 0x12548c1 with base 0x1200000
00259
00262 void forward (const ConstraintHolder<P1> &p1) const
00263 {
00264 VisitableMockMethod1Common<void, P1>::forward(p1);
00265 }
00266 #else
00267 using VisitableMockMethod1Common<void, P1>::forward;
00268 #endif
00269 };
00270
00271
00272 MOCKPP_NS_END
00273
00274
00275 #endif // MOCKPP_VisitableMockMethod1_H
00276