[Mockpp-commits] mockpp/mockpp MixedMockObject.cpp,NONE,1.1 MixedMockObject.h,NONE,1.1 ChainableMock
Brought to you by:
ewald-arnold
Update of /cvsroot/mockpp/mockpp/mockpp In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29577/mockpp Modified Files: ChainableMockObject.cpp ChainableMockObject.h Makefile.am VisitableMockObject.cpp VisitableMockObject.h Added Files: MixedMockObject.cpp MixedMockObject.h Log Message: restructured for new MixedMockObject class Index: Makefile.am =================================================================== RCS file: /cvsroot/mockpp/mockpp/mockpp/Makefile.am,v retrieving revision 1.70 retrieving revision 1.71 diff -u -d -r1.70 -r1.71 --- Makefile.am 4 Mar 2005 17:39:40 -0000 1.70 +++ Makefile.am 6 Mar 2005 21:45:51 -0000 1.71 @@ -15,9 +15,9 @@ $(top_builddir)/mockpp/chaining/libchaining.la $(top_builddir)/mockpp/builder/libbuilder.la libmockpp_la_SOURCES = ExpectationCounter.cpp mockpp.cpp Throwable.cpp \ - ThrowableList.cpp MockObject.cpp VisitableMockObject.cpp VerifiableList.cpp \ - Verifiable.cpp VerifyingTestCase.cpp SelfDescribing.cpp ChainableMockObject.cpp \ - VerifyingTestCaller.cpp TrackingCounter.cpp + ThrowableList.cpp MockObject.cpp VisitableMockObject.cpp VerifiableList.cpp \ + Verifiable.cpp VerifyingTestCase.cpp SelfDescribing.cpp ChainableMockObject.cpp \ + VerifyingTestCaller.cpp TrackingCounter.cpp MixedMockObject.cpp pkginclude_HEADERS = mockpp_config.h ReturnObjectList.h Expectation.h \ AbstractExpectation.h ExpectationValue.h ExpectationSegment.h ExpectationList.h \ --- NEW FILE: MixedMockObject.cpp --- /** @file @brief MockObject that merges all the advanced mock objects $Id: MixedMockObject.cpp,v 1.1 2005/03/06 21:45:52 ewald-arnold Exp $ ***************************************************************************/ /************************************************************************** begin : Sat Mar 05 2005 copyright : (C) 2002-2005 by Ewald Arnold email : mockpp at ewald-arnold dot de This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. **/ #include <mockpp/mockpp.h> // always first #include <mockpp/MixedMockObject.h> namespace mockpp { MOCKPP_EXPORT MixedMockObject::MixedMockObject(const String &name, VerifiableList *parent) : VerifiableList(name, parent) , VisitableMockObjectBase(name+MOCKPP_PCHAR("/Visitable"), parent) , ChainableMockObjectBase(name+MOCKPP_PCHAR("/Chainable")) { } MOCKPP_EXPORT MixedMockObject::~MixedMockObject() { } void MOCKPP_EXPORT MixedMockObject::verify() { visitableVerify(); chainableVerify(); } void MOCKPP_EXPORT MixedMockObject::clear() { reset(); } void MOCKPP_EXPORT MixedMockObject::reset() { visitableReset(); chainableClear(); } } // namespace mockpp --- NEW FILE: MixedMockObject.h --- /** @file @brief MockObject that merges all the advanced mock objects $Id: MixedMockObject.h,v 1.1 2005/03/06 21:45:52 ewald-arnold Exp $ ***************************************************************************/ /************************************************************************** begin : Sat Mar 05 2005 copyright : (C) 2002-2005 by Ewald Arnold email : mockpp at ewald-arnold dot de This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. **/ #ifndef MOCKPP_MixedMOCKOBJECT_H #define MOCKPP_MixedMOCKOBJECT_H #include <mockpp/mockpp.h> // always first #include <mockpp/VisitableMockObject.h> #include <mockpp/ChainableMockObject.h> namespace mockpp { /** A MockObject that merges all the advanced mock objects. * \ingroup grp_advanced_mo */ class MixedMockObject : public VerifiableList , public VisitableMockObjectBase , public ChainableMockObjectBase { public: /** Construct the item. * @param name human readable description about the object * @param parent parent verifiable */ MixedMockObject(const String &name, VerifiableList *parent = 0); /** Destruct the item. */ virtual ~MixedMockObject(); /** Frees all internal data. */ virtual void clear(); /** Frees all internal data. */ virtual void reset(); /** Verifies the object and the mock objects it contains.. * If it fails, an AssertionFailedError is thrown */ virtual void verify(); }; } // namespace mockpp #endif // MOCKPP_MixedMOCKOBJECT_H Index: ChainableMockObject.cpp =================================================================== RCS file: /cvsroot/mockpp/mockpp/mockpp/ChainableMockObject.cpp,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- ChainableMockObject.cpp 27 Feb 2005 11:48:14 -0000 1.15 +++ ChainableMockObject.cpp 6 Mar 2005 21:45:51 -0000 1.16 @@ -38,27 +38,25 @@ namespace mockpp { -MOCKPP_EXPORT ChainableMockObject::ChainableMockObject(const String &name, VerifiableList *parent) - : MockObject(name, parent) - , BuilderNamespace(name) +MOCKPP_EXPORT ChainableMockObjectBase::ChainableMockObjectBase(const String &name) + : BuilderNamespace(name) { } -MOCKPP_EXPORT ChainableMockObject::~ChainableMockObject() +MOCKPP_EXPORT ChainableMockObjectBase::~ChainableMockObjectBase() { - clear(); + chainableClear(); } -void MOCKPP_EXPORT ChainableMockObject::verify() +void MOCKPP_EXPORT ChainableMockObjectBase::chainableVerify() { - MockObject::verify(); checkPendingRecorders(); } -void MOCKPP_EXPORT ChainableMockObject::checkPendingRecorders() const +void MOCKPP_EXPORT ChainableMockObjectBase::checkPendingRecorders() const { String penders; while(pendingRecorders.size() != 0) @@ -73,13 +71,13 @@ if (penders.length() != 0) throw AssertionFailedError( __LINE__, __FILE__, - MOCKPP_PCHAR("Chaining mock object \"") + getVerifiableName() + MOCKPP_PCHAR("Chaining mock object \"") + getIdent() + MOCKPP_PCHAR( "\": there are unassigned idenfiers:\n " ) + penders); } -MatchBuilderAdapterBase * MOCKPP_EXPORT ChainableMockObject::lookupID( const String &id ) const +MatchBuilderAdapterBase * MOCKPP_EXPORT ChainableMockObjectBase::lookupID( const String &id ) const { TableType::const_iterator it = idTable.find( id ); if ( it == idTable.end() ) @@ -89,7 +87,7 @@ } -void MOCKPP_EXPORT ChainableMockObject::registerUniqueID( const String &id, MatchBuilderAdapterBase *builder ) +void MOCKPP_EXPORT ChainableMockObjectBase::registerUniqueID( const String &id, MatchBuilderAdapterBase *builder ) { MatchBuilderAdapterBase *tmb = lookupID(id); if ( tmb != 0 ) @@ -101,19 +99,19 @@ } -void MOCKPP_EXPORT ChainableMockObject::storeBuilder( AutoPointer<MatchBuilderAdapterBase> builder ) +void MOCKPP_EXPORT ChainableMockObjectBase::storeBuilder( AutoPointer<MatchBuilderAdapterBase> builder ) { allBuilders.push_back(builder.release()); } -void MOCKPP_EXPORT ChainableMockObject::addPendingRecorder(const String &id, InvokedRecorder::AP recorder) +void MOCKPP_EXPORT ChainableMockObjectBase::addPendingRecorder(const String &id, InvokedRecorder::AP recorder) { pendingRecorders.insert( std::make_pair(id, recorder.release()) ); } -void MOCKPP_EXPORT ChainableMockObject::storeID( const String &id, MatchBuilderAdapterBase *builder ) +void MOCKPP_EXPORT ChainableMockObjectBase::storeID( const String &id, MatchBuilderAdapterBase *builder ) { idTable.insert( std::make_pair(id, builder) ); @@ -126,7 +124,7 @@ } -void MOCKPP_EXPORT ChainableMockObject::clear() +void MOCKPP_EXPORT ChainableMockObjectBase::chainableClear() { while(idTable.size() != 0) { @@ -146,4 +144,33 @@ } +///////////////////////////////////////////////////////////////// + + +MOCKPP_EXPORT ChainableMockObject::ChainableMockObject(const String &name, VerifiableList *parent) + : MockObject(name, parent) + , ChainableMockObjectBase(name) +{ +} + + +MOCKPP_EXPORT ChainableMockObject::~ChainableMockObject() +{ + clear(); +} + + +void MOCKPP_EXPORT ChainableMockObject::verify() +{ + MockObject::verify(); + chainableVerify(); +} + + +void MOCKPP_EXPORT ChainableMockObject::clear() +{ + chainableClear(); +} + + } // namespace mockpp Index: ChainableMockObject.h =================================================================== RCS file: /cvsroot/mockpp/mockpp/mockpp/ChainableMockObject.h,v retrieving revision 1.23 retrieving revision 1.24 diff -u -d -r1.23 -r1.24 --- ChainableMockObject.h 4 Mar 2005 20:26:40 -0000 1.23 +++ ChainableMockObject.h 6 Mar 2005 21:45:51 -0000 1.24 @@ -49,12 +49,11 @@ namespace mockpp { -/** A generic object that can be used to replace a real world object for testing purposes. +/** Base for a generic object that can be used to replace a real world object for testing purposes. * It emulates the real world behaviour by feeding it "chained expectations". * \ingroup grp_advanced_mo */ -class ChainableMockObject : public MockObject, - public BuilderNamespace +class ChainableMockObjectBase : public BuilderNamespace { typedef std::map<String, MatchBuilderAdapterBase*> TableType; typedef std::multimap<String, InvokedRecorder*> PendingType; @@ -63,13 +62,12 @@ /** Construct the item. * @param name human readable description about the object - * @param parent parent verifiable */ - ChainableMockObject(const String &name, VerifiableList *parent = 0); + ChainableMockObjectBase(const String &name); /** Destruct the item. */ - virtual ~ChainableMockObject(); + virtual ~ChainableMockObjectBase(); /** Searches a name. * @internal @@ -96,11 +94,6 @@ */ virtual void storeBuilder( AutoPointer<MatchBuilderAdapterBase> builder ); - /** Frees all internal data. - * @internal - */ - virtual void clear(); - /** Stores another recorder object for later use. * @internal * Pending recorders occur when an after() or before() call occurs before the @@ -116,10 +109,17 @@ */ void checkPendingRecorders() const; // @todo make private + protected: + /** Verifies the object and the mock objects it contains.. * If it fails, an AssertionFailedError is thrown */ - virtual void verify(); + void chainableVerify(); + + /** Frees all internal data. + * @internal + */ + virtual void chainableClear(); private: @@ -136,6 +136,37 @@ }; +/** A generic object that can be used to replace a real world object for testing purposes. + * It emulates the real world behaviour by feeding it "chained expectations". + * \ingroup grp_advanced_mo + */ +class ChainableMockObject : public MockObject, + public ChainableMockObjectBase +{ + public: + + /** Construct the item. + * @param name human readable description about the object + * @param parent parent verifiable + */ + ChainableMockObject(const String &name, VerifiableList *parent = 0); + + /** Destruct the item. + */ + virtual ~ChainableMockObject(); + + /** Verifies the object and the mock objects it contains.. + * If it fails, an AssertionFailedError is thrown + */ + virtual void verify(); + + /** Frees all internal data. + * @internal + */ + virtual void clear(); +}; + + } // namespace mockpp Index: VisitableMockObject.cpp =================================================================== RCS file: /cvsroot/mockpp/mockpp/mockpp/VisitableMockObject.cpp,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -r1.22 -r1.23 --- VisitableMockObject.cpp 5 Mar 2005 20:43:37 -0000 1.22 +++ VisitableMockObject.cpp 6 Mar 2005 21:45:52 -0000 1.23 @@ -36,77 +36,73 @@ namespace mockpp { -MOCKPP_EXPORT VisitableMockObject::VisitableMockObject(const String &name, VerifiableList *parent) - : MockObject(name, parent), - methodList(name+MOCKPP_PCSTRING("/methodList"), this) +MOCKPP_EXPORT VisitableMockObjectBase::VisitableMockObjectBase(const String &name, VerifiableList *parent) + :methodList(name+MOCKPP_PCSTRING("/methodList"), parent) { activated = false; } -void MOCKPP_EXPORT VisitableMockObject::addExpectedMethod(const std::string &name) const +MOCKPP_EXPORT VisitableMockObjectBase::~VisitableMockObjectBase() +{ +} + + +void MOCKPP_EXPORT VisitableMockObjectBase::addExpectedMethod(const std::string &name) const { MOCKPP_ASSERT_EQUALS(isActivated(), false); methodList.addExpected(name); } -void MOCKPP_EXPORT VisitableMockObject::addActualMethod(const std::string &name) const +void MOCKPP_EXPORT VisitableMockObjectBase::addActualMethod(const std::string &name) const { MOCKPP_ASSERT_EQUALS(isActivated(), true); methodList.addActual(name); } -void MOCKPP_EXPORT VisitableMockObject::activate() +void MOCKPP_EXPORT VisitableMockObjectBase::activate() { activated = true; } -bool MOCKPP_EXPORT VisitableMockObject::isActivated() const +bool MOCKPP_EXPORT VisitableMockObjectBase::isActivated() const { return activated; } -void MOCKPP_EXPORT VisitableMockObject::verify() +void MOCKPP_EXPORT VisitableMockObjectBase::visitableVerify() { - MockObject::verify(); for (unsigned i = 0; i < controllers.size(); ++i) controllers[i]->verify(); } -void MOCKPP_EXPORT VisitableMockObject::clear() -{ - reset(); -} - - -void MOCKPP_EXPORT VisitableMockObject::reset() +void MOCKPP_EXPORT VisitableMockObjectBase::visitableReset() { - MockObject::reset(); activated = false; for (unsigned i = 0; i < controllers.size(); ++i) controllers[i]->reset(); } -void MOCKPP_EXPORT VisitableMockObject::unsetThrowablesInline() +void MOCKPP_EXPORT VisitableMockObjectBase::unsetThrowablesInline() { for (unsigned i = 0; i < controllers.size(); ++i) controllers[i]->unsetThrowablesInline(); } -void MOCKPP_EXPORT VisitableMockObject::addController (Controller *ctr) +void MOCKPP_EXPORT VisitableMockObjectBase::addController (Controller *ctr) { controllers.push_back(ctr); } -void MOCKPP_EXPORT VisitableMockObject::removeController (Controller *ctr) +void MOCKPP_EXPORT VisitableMockObjectBase::removeController (Controller *ctr) { std::vector<Controller*>::iterator it = std::find (controllers.begin(), controllers.end(), ctr); @@ -115,7 +111,7 @@ } -unsigned MOCKPP_EXPORT VisitableMockObject::numController() const +unsigned MOCKPP_EXPORT VisitableMockObjectBase::numController() const { return controllers.size(); } @@ -123,6 +119,41 @@ ///////////////////////////////////////////////////////////////// + +MOCKPP_EXPORT VisitableMockObject::VisitableMockObject(const String &name, VerifiableList *parent) + : MockObject(name, parent) + , VisitableMockObjectBase(name, this) +{ +} + + +MOCKPP_EXPORT VisitableMockObject::~VisitableMockObject() +{ +} + + +void MOCKPP_EXPORT VisitableMockObject::verify() +{ + visitableVerify(); +} + + +void MOCKPP_EXPORT VisitableMockObject::reset() +{ + MockObject::reset(); + visitableReset(); +} + + +void MOCKPP_EXPORT VisitableMockObject::clear() +{ + reset(); +} + + +///////////////////////////////////////////////////////////////// + + MOCKPP_EXPORT VisitableMockObject::Controller::~Controller() { } Index: VisitableMockObject.h =================================================================== RCS file: /cvsroot/mockpp/mockpp/mockpp/VisitableMockObject.h,v retrieving revision 1.37 retrieving revision 1.38 diff -u -d -r1.37 -r1.38 --- VisitableMockObject.h 5 Mar 2005 20:43:07 -0000 1.37 +++ VisitableMockObject.h 6 Mar 2005 21:45:52 -0000 1.38 @@ -49,42 +49,28 @@ namespace mockpp { -/** A generic object that can be used to replace a real world object for testing purposes. +/** Base class for a generic object that can be used to replace a real world object for testing purposes. * It emulates the real world behaviour by feeding it values and exceptions. * \ingroup grp_advanced_mo */ -class VisitableMockObject : public MockObject +class VisitableMockObjectBase { public: - /** - * Construct the item. + /** Construct the item. * @param name human readable description about the object * @param parent parent verifiable */ - VisitableMockObject(const String &name, VerifiableList *parent = 0); + VisitableMockObjectBase(const String &name, VerifiableList *parent); - /** - * Verify that the expected and actual values are equal. - * If it fails, an AssertionFailedError is thrown + /** Destruct the item. */ - virtual void verify(); + virtual ~VisitableMockObjectBase(); - /** - * Changes from record mode to normal working mode so you can use the object + /** Changes from record mode to normal working mode so you can use the object */ void activate(); - /** - * Sets all internal objects to the state after construction. - */ - virtual void reset(); - - /** - * Sets all internal objects to the state after construction. - */ - virtual void clear(); - /** Switches exception handling back to pre-1.2 behaviour. * @see VisitableMockObject::Controller::unsetThrowablesInline() */ @@ -126,6 +112,17 @@ */ unsigned numController() const; + protected: + + /** Verify that the expected and actual values are equal. + * If it fails, an AssertionFailedError is thrown + */ + void visitableVerify(); + + /** Sets all internal objects to the state after construction. + */ + void visitableReset(); + private: mutable ExpectationList<std::string> methodList; @@ -133,6 +130,46 @@ std::vector<Controller*> controllers; }; + +/** A generic object that can be used to replace a real world object for testing purposes. + * It emulates the real world behaviour by feeding it values and exceptions. + * \ingroup grp_advanced_mo + */ +class VisitableMockObject : public MockObject + , public VisitableMockObjectBase +{ + public: + + /** + * Construct the item. + * @param name human readable description about the object + * @param parent parent verifiable + */ + VisitableMockObject(const String &name, VerifiableList *parent = 0); + + /** Destruct the item. + */ + virtual ~VisitableMockObject(); + + /** + * Verify that the expected and actual values are equal. + * If it fails, an AssertionFailedError is thrown + */ + virtual void verify(); + +/** + * Sets all internal objects to the state after construction. + */ + virtual void reset(); + + /** + * Sets all internal objects to the state after construction. + */ + virtual void clear(); +}; + + + /** * @defgroup grp_controller Controlling behaviour of a Visitable Mock Object */ |