Thread: [Mockpp-commits] mockpp/mockpp VisitableMockMethod.h,1.1,1.2
Brought to you by:
ewald-arnold
From: Ewald A. <ewa...@us...> - 2005-10-05 16:02:37
|
Update of /cvsroot/mockpp/mockpp/mockpp In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3628/mockpp Modified Files: VisitableMockMethod.h Log Message: intermediate update Index: VisitableMockMethod.h =================================================================== RCS file: /cvsroot/mockpp/mockpp/mockpp/VisitableMockMethod.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- VisitableMockMethod.h 2 Oct 2005 18:51:33 -0000 1.1 +++ VisitableMockMethod.h 5 Oct 2005 16:02:11 -0000 1.2 @@ -38,6 +38,7 @@ namespace mockpp { +#ifdef MOCKPP_XXX template <typename R> class VisitableMockMethodBase : public MockObject @@ -77,20 +78,204 @@ R forward(P1 param1) const { - return R(); + std::string func_name (getMethodName()); + if (!isActivated() ) + { + addExpectedMethod(getLatin1(getVerifiableName()) + "." + func_name); + Parameter1.addExpected((v_type1)param1); + return; + } + else + { + addActualMethod(getLatin1(getVerifiableName()) + "." + func_name); + try { + Throwable *t; + if (ResponseValues.find(t, (v_type1)param1)) + t->throw_me(); + + bool do_throw = true; + if (ThrowablesInline) + { + if (ThrowableInsteadReturn.size() != 0) + { + do_throw = ThrowableInsteadReturn[0]; + ThrowableInsteadReturn.erase(ThrowableInsteadReturn.begin()); + } + } + + if (do_throw && Throwables.hasMoreObjects() != 0) + { + Throwable *thr = Throwables.nextThrowableObject(); + if (thr != 0) + thr->throw_me(); + } + + if (DefaultThrowable.get() != 0) + DefaultThrowable.get()->throw_me() + + } + catch(...) + { + Parameter1.balanceActual(); + throw; + } + Parameter1.addActual((v_type1&)param1); + return; + } } - class ChainerFor + R forward (const ConstraintHolder< v_type1 > ¶m1) /* @todo const? */ { + addExpectedMethod(getLatin1(getVerifiableName()) + "." + getMethodName()); + Parameter1.addExpected(param1); + } + + private: + + ThrowableItem DefaultThrowable; + mutable ThrowableList Throwables; + bool ThrowablesInline; + mutable std::vector<bool> ThrowableInsteadReturn; + mutable ResponseThrowableVector1< v_type1 > ResponseValues; + mutable ConstraintList< type1 > Parameter1; + } + + friend class ControllerFor; + + public: + + class ControllerFor : public VisitableMockObject::Controller + { + classname *objptr; + public: + ControllerFor (classname *cls) + : objptr(cls) + { + objptr->addController(this); + } + + virtual ~ControllerFor () + { + objptr->removeController(this); + } + public: + void reset() + { + MOCKPP_ASSERT_FALSE(objptr->isActivated()); + objptr->Throwables.clear(); \ + objptr->DefaultThrowable.clear(); \ + objptr->ThrowablesInline = MOCKPP_THROWABLE_INLINE; \ + objptr->ThrowableInsteadReturn.clear() + objptr->ResponseValues.clear(); \ + objptr->Parameter1.clear(); + } + + virtual void unsetThrowablesInline() + { + MOCKPP_ASSERT_FALSE(objptr->isActivated()); + objptr->methThrowablesInline = false; }; - private: + void addThrowable(Throwable *t_) + { + std::auto_ptr<Throwable> at (t_); + MOCKPP_ASSERT_FALSE(objptr->isActivated()); + objptr->methThrowables.push_back(at.release()); + objptr->methThrowableInsteadReturn.push_back(true); + } + + template <class T> + void addThrowable(const T &w, unsigned count = 1) + { + for ( ; count > 0; --count) + addThrowable(make_throwable(w)); + } + + void setDefaultThrowable(Throwable *t_) + { + std::auto_ptr<Throwable> at (t_); + MOCKPP_ASSERT_FALSE(objptr->isActivated()); + objptr->methDefaultThrowable.take(at.release()); + } + + virtual void verify() + { + if (objptr->methhaveDefaultReturnValue) + { + String fmt = mockpp_i18n(MOCKPP_PCHAR("%1 is unused.")); + fmt << MOCKPP_PCHAR(getMethodName()) MOCKPP_PCHAR("DefaultReturnValueUsed"); + MOCKPP_ASSERT_TRUE_MESSAGE(fmt, objptr->methDefaultReturnValueUsed); + } + + Throwable *dt = objptr->methDefaultThrowable.get(); + if (dt != 0) + { + String fmt = mockpp_i18n(MOCKPP_PCHAR("%1 is unused.")); + fmt << MOCKPP_PCHAR(getMethodName()) MOCKPP_PCHAR("DefaultThrowable"); + MOCKPP_ASSERT_TRUE_MESSAGE(fmt, dt->hasThrown()); + } + } + + void addReturnValue(const ret_type &rv, unsigned count = 1) + { + MOCKPP_ASSERT_FALSE(objptr->isActivated()); + for ( ; count > 0; --count) + { + objptr->methReturnValues.addObjectToReturn(rv); + objptr->methThrowableInsteadReturn.push_back(false); + } + } + + void setDefaultReturnValue(const ret_type &rv) + { + MOCKPP_ASSERT_FALSE(objptr->isActivated()); + objptr->methhaveDefaultReturnValue = true; + objptr->methDefaultReturnValue = rv; + } + + void addResponseValue(const ret_type &rv, const type1 &p1, unsigned count = MOCKPP_UNLIMITED) + { + MOCKPP_ASSERT_FALSE(objptr->isActivated()); + objptr->methResponseValues.add(rv, (type1&)p1, count); + } + + void addResponseValue(const ret_type &rv, const ConstraintHolder< type1 > &p1, unsigned count = MOCKPP_UNLIMITED) + { + MOCKPP_ASSERT_FALSE(objptr->isActivated()); + objptr->methResponseValues.add(rv, p1, count); + } + + void addResponseThrowable(Throwable *t, const type1 &p1, unsigned count = MOCKPP_UNLIMITED) + { + MOCKPP_ASSERT_FALSE(objptr->isActivated()); + objptr->methResponseValues.add(t, (type1&)p1, count); + } + + void addResponseThrowable(Throwable *t, const ConstraintHolder< type1 > &p1, unsigned count = MOCKPP_UNLIMITED) + { + MOCKPP_ASSERT_FALSE(objptr->isActivated()); + objptr->methResponseValues.add(t, p1, count); + } + }; + + ThrowableItem DefaultThrowable; + mutable ThrowableList Throwables; + bool ThrowablesInline; + mutable std::vector<bool> ThrowableInsteadReturn; + + mutable ReturnObjectList< ret_type > ReturnValues; + bool haveDefaultReturnValue; + mutable bool DefaultReturnValueUsed; + ret_type DefaultReturnValue; + + mutable ConstraintList< type1 > Parameter1 + - VisitableMockObject *Visitable_parent; }; +#endif } // namespace mockpp |