[Mockpp-commits] mockpp/mockpp VisitableMockMethod.cpp,1.1,1.2 VisitableMockMethod.h,1.4,1.5
Brought to you by:
ewald-arnold
From: Ewald A. <ewa...@us...> - 2005-10-17 19:15:21
|
Update of /cvsroot/mockpp/mockpp/mockpp In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30905/mockpp Modified Files: VisitableMockMethod.cpp VisitableMockMethod.h Log Message: backup Index: VisitableMockMethod.cpp =================================================================== RCS file: /cvsroot/mockpp/mockpp/mockpp/VisitableMockMethod.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- VisitableMockMethod.cpp 15 Oct 2005 15:13:10 -0000 1.1 +++ VisitableMockMethod.cpp 17 Oct 2005 19:15:09 -0000 1.2 @@ -40,7 +40,7 @@ VisitableMockObject *parent) : MockObject(name, parent) , visitable(parent) - , throwables (name + MOCKPP_PCHAR("Throwables"), this) + , throwables (name + MOCKPP_PCHAR("/throwables"), this) , throwablesInline (true) { } Index: VisitableMockMethod.h =================================================================== RCS file: /cvsroot/mockpp/mockpp/mockpp/VisitableMockMethod.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- VisitableMockMethod.h 15 Oct 2005 15:13:26 -0000 1.4 +++ VisitableMockMethod.h 17 Oct 2005 19:15:09 -0000 1.5 @@ -44,10 +44,10 @@ public: /** Constructs the mock object. - * @param name human readable description about the expectation + * @param name the method name to mock * @param parent parent Visitable mock object */ - VisitableMockMethodBase(const String &name, VisitableMockObject *parent); + VisitableMockMethodBase(const String &methodname, VisitableMockObject *parent); String getMethodName() const; @@ -56,13 +56,13 @@ //------------------------------------------------------------- template <class VMM> - class ControllerFor : public VisitableMockObject::Controller + friend class ControllerFor : public VisitableMockObject::Controller { public: ControllerFor (VMM *meth) : method(meth) - , object(meth->getParent()) + , object(meth->getVisitableMockObject()) { object->addController(this); } @@ -82,7 +82,7 @@ { std::auto_ptr<Throwable> at (t_); MOCKPP_ASSERT_FALSE(object->isActivated()); - object->throwables.push_back(at.release()); + method->throwables.push_back(at.release()); method->throwableInsteadReturn.push_back(true); } @@ -100,22 +100,37 @@ method->defaultThrowable.take(at.release()); } + /** Clears all expectations and puts the object in record mode again. + */ + virtual void reset() + { + method->defaultThrowable.clear(); + method->throwables.clear(); + method->throwableInsteadReturn.clear(); + method->throwablesInline = true; + } + + /** + * Verify the conditions which are not in the verify() chain. + * If it fails, an AssertionFailedError is thrown + */ + virtual void verify() + { + mockpp::Throwable *dt = method->defaultThrowable.get(); + if (dt != 0) + { + String fmt = mockpp_i18n(MOCKPP_PCHAR("%1 is unused.")); + fmt << method->getMethodName() + MOCKPP_PCHAR("/defaultThrowable"); + MOCKPP_ASSERT_TRUE_MESSAGE(fmt, dt->hasThrown()); + } + } + private: - VisitableMockObject *object; VMM *method; + VisitableMockObject *object; }; - protected: - - virtual void reset() - { - defaultThrowable.clear(); - throwables.clear(); - throwableInsteadReturn.clear(); - throwablesInline = true; - } - private: VisitableMockObject *visitable; @@ -131,13 +146,24 @@ ////////////////////////////////////////////////////////////////////////////////////////////// -template <typename R> +template <typename R, const char* Name> class VisitableMockMethod0Base : public VisitableMockMethodBase { public: - class ControllerFor : public VisitableMockMethodBase::ControllerFor<VisitableMockMethod0Base> + /** Constructs the mock object. + * @param parent parent Visitable mock object + */ + VisitableMockMethod0Base(VisitableMockObject *parent) + : VisitableMockMethodBase(Name, parent) + , returnValues(getMethodName() + MOCKPP_PCHAR("/returnValues") + {} + + + friend class ControllerFor : public VisitableMockMethodBase::ControllerFor<VisitableMockMethod0Base> { + typedef VisitableMockMethodBase::ControllerFor<VisitableMockMethod0Base> Inherited; + public: void setDefaultReturnValue(const R &rv) @@ -149,11 +175,26 @@ virtual void reset() { + Inherited::reset(); VisitableMockMethodBase::ControllerFor<VisitableMockMethod0Base>::reset(); object->haveDefaultReturnValue = false; object->DefaultReturnValueUsed = false; returnValues.clear(); } + + virtual void verify() + { + Inherited::verify(); + if (method->haveDefaultReturnValue) + { + String fmt = mockpp_i18n(MOCKPP_PCHAR("%1 is unused.")); + fmt << method->getMethodName() + MOCKPP_PCHAR("/defaultReturnValueUsed"); + MOCKPP_ASSERT_TRUE_MESSAGE(fmt, object->defaultReturnValueUsed); + } + + returnvalues.verify(); + } + }; protected: @@ -165,10 +206,19 @@ } -template <> -class VisitableMockMethod0Base<void> : public VisitableMockMethodBase +template <const char* Name> +class VisitableMockMethod0Base<void, const char*> : public VisitableMockMethodBase { - class ControllerFor : public ControllerFor<VisitableMockMethod0Base> + public: + + /** Constructs the mock object. + * @param parent parent Visitable mock object + */ + VisitableMockMethod0Base(VisitableMockObject *parent) + : VisitableMockMethodBase(Name, parent) + {} + + friend class ControllerFor : public ControllerFor<VisitableMockMethod0Base> { public: @@ -192,18 +242,18 @@ : VisitableMockMethod0Base<R>(name, parent) {} - R forward(P1 param1) const + R forward(const P1 ¶m1) const { if (!isActivated() ) { - addExpectedMethod(getLatin1(getMethodName())); - Parameter1.addExpected((v_type1)param1); + getParent()->addExpectedMethod(getMethodName()); + Parameter1.addExpected(param1); return; } else { - addActualMethod(getLatin1(getMethodName())); + getParent()->addActualMethod(getMethodName()); try { Throwable *t; @@ -211,9 +261,9 @@ t->throw_me(); bool do_throw = true; - if (ThrowablesInline) + if (throwablesInline) { - if (ThrowableInsteadReturn.size() != 0) + if (throwableInsteadReturn.size() != 0) { do_throw = ThrowableInsteadReturn[0]; ThrowableInsteadReturn.erase(ThrowableInsteadReturn.begin()); @@ -245,11 +295,12 @@ R forward (const ConstraintHolder<v_type1> ¶m1) /* @todo const? */ { - addExpectedMethod(getLatin1(getMethodName()); + MOCKPP_ASSERT_FALSE(object->isActivated()); + getParent()->addExpectedMethod(getMethodName(); Parameter1.addExpected(param1); } - class ControllerFor : public VisitableMockMethod0Base<R>::ControllerFor + friend class ControllerFor : public VisitableMockMethod0Base<R>::ControllerFor { public: @@ -257,10 +308,6 @@ private: - ThrowableItem defaultThrowable; - mutable ThrowableList throwables; - bool throwablesInline; - mutable std::vector<bool> throwableInsteadReturn; mutable ResponseThrowableVector1< v_type1> responseValues; mutable ConstraintList< type1 > parameter1; } @@ -269,7 +316,7 @@ public: - class ControllerFor : public VisitableMockObject::Controller + friend class ControllerFor : public VisitableMockObject::Controller { classname *object; @@ -282,25 +329,16 @@ void reset() { + VisitableMockObject::Controller::reset(); MOCKPP_ASSERT_FALSE(object->isActivated()); - object->Throwables.clear(); - object->DefaultThrowable.clear(); - object->ThrowablesInline = MOCKPP_THROWABLE_INLINE; - object->ThrowableInsteadReturn.clear() object->ResponseValues.clear(); object->Parameter1.clear(); } virtual void verify() { - if (object->haveDefaultReturnValue) - { - String fmt = mockpp_i18n(MOCKPP_PCHAR("%1 is unused.")); - fmt << MOCKPP_PCHAR(getMethodName()) MOCKPP_PCHAR("DefaultReturnValueUsed"); - MOCKPP_ASSERT_TRUE_MESSAGE(fmt, object->methDefaultReturnValueUsed); - } - - Throwable *dt = object->methDefaultThrowable.get(); + VisitableMockObject::Controller::verify(); + Throwable *dt = object->defaultThrowable.get(); if (dt != 0) { String fmt = mockpp_i18n(MOCKPP_PCHAR("%1 is unused.")); |