[Mockpp-commits] mockpp/mockpp/chaining ChainableMockObject.cpp,NONE,1.1 ChainableMockObject.h,NONE,
Brought to you by:
ewald-arnold
From: Ewald A. <ewa...@us...> - 2005-12-10 19:18:58
|
Update of /cvsroot/mockpp/mockpp/mockpp/chaining In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31638/mockpp/chaining Added Files: ChainableMockObject.cpp ChainableMockObject.h Log Message: moved to subdir chaining --- NEW FILE: ChainableMockObject.cpp --- /** @file @brief MockObjects with chained setup parameters $Id: ChainableMockObject.cpp,v 1.1 2005/12/10 19:18:50 ewald-arnold Exp $ ***************************************************************************/ /************************************************************************** begin : Thu Sep 28 2004 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_ALGORITHM_H #include <mockpp/ChainableMockObject.h> namespace mockpp { MOCKPP_EXPORT ChainableMockObjectBase::ChainableMockObjectBase(const String &name) : BuilderNamespace(name) { } MOCKPP_EXPORT ChainableMockObjectBase::~ChainableMockObjectBase() { chainableReset(); } void MOCKPP_EXPORT ChainableMockObjectBase::chainableVerify() { checkPendingRecorders(); } void MOCKPP_EXPORT ChainableMockObjectBase::checkPendingRecorders() const { String penders; while(pendingRecorders.size() != 0) { if (penders.length() != 0) penders += MOCKPP_PCHAR(", "); penders += (*pendingRecorders.begin()).first; delete (*pendingRecorders.begin()).second; pendingRecorders.erase(pendingRecorders.begin()); } if (penders.length() != 0) assertionFailed( __LINE__, __FILE__, MOCKPP_PCHAR("Chaining mock object \"") + getIdent() + MOCKPP_PCHAR( "\": there are unassigned idenfiers:\n " ) + penders); } MatchBuilderAdapterBase * MOCKPP_EXPORT ChainableMockObjectBase::lookupID( const String &id ) const { TableType::const_iterator it = idTable.find( id ); if ( it == idTable.end() ) return 0; return ( (*it).second ); } void MOCKPP_EXPORT ChainableMockObjectBase::registerUniqueID( const String &id, MatchBuilderAdapterBase *builder ) { MatchBuilderAdapterBase *tmb = lookupID(id); if ( tmb != 0 ) assertionFailed( __LINE__, __FILE__, MOCKPP_PCHAR( "duplicate invocation named \"" ) + id + MOCKPP_PCHAR( "\"" ) ); storeID(id, builder); } void MOCKPP_EXPORT ChainableMockObjectBase::storeBuilder( AutoPointer<MatchBuilderAdapterBase> builder ) { allBuilders.push_back(builder.release()); } void MOCKPP_EXPORT ChainableMockObjectBase::addPendingRecorder(const String &id, InvokedRecorder::AP recorder) { pendingRecorders.insert( MOCKPP_STL::make_pair(id, recorder.release()) ); } void MOCKPP_EXPORT ChainableMockObjectBase::storeID( const String &id, MatchBuilderAdapterBase *builder ) { idTable.insert( MOCKPP_STL::make_pair(id, builder) ); PendingType::iterator it; while ( (it = pendingRecorders.find( id )) != pendingRecorders.end() ) { builder->match( (*it).second ); pendingRecorders.erase(it); } } void MOCKPP_EXPORT ChainableMockObjectBase::chainableReset() { while(idTable.size() != 0) { delete (*idTable.begin()).second; idTable.erase(idTable.begin()); } for (unsigned i = 0; i < allBuilders.size(); ++i) delete allBuilders[i]; allBuilders.clear(); while(pendingRecorders.size() != 0) { delete (*pendingRecorders.begin()).second; pendingRecorders.erase(pendingRecorders.begin()); } } ///////////////////////////////////////////////////////////////// MOCKPP_EXPORT ChainableMockObject::ChainableMockObject(const String &name, VerifiableList *parent) : MockObject(name, parent) , ChainableMockObjectBase(name) { } MOCKPP_EXPORT ChainableMockObject::~ChainableMockObject() { reset(); } void MOCKPP_EXPORT ChainableMockObject::verify() { MockObject::verify(); chainableVerify(); } void MOCKPP_EXPORT ChainableMockObject::reset() { MockObject::reset(); chainableReset(); } } // namespace mockpp --- NEW FILE: ChainableMockObject.h --- /** @file @brief MockObjects that can be chained under control. $Id: ChainableMockObject.h,v 1.1 2005/12/10 19:18:50 ewald-arnold Exp $ ***************************************************************************/ /************************************************************************** begin : Thu Sep 28 2004 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, [...1218 lines suppressed...] /** Implements the initializers for the internal variables of a * method with 5 parameters. * @param name the method name */ #define MOCKPP_CONSTRUCT_MEMBERS_FOR_CHAINABLE5(name) \ MOCKPP_CONSTRUCT_CHAINABLE_MEMBERS(name) /** Implements the initializers for the internal variables of a * method with 5 parameters. * @param m_name the method name * @param x_name extension for internal naming */ #define MOCKPP_CONSTRUCT_MEMBERS_FOR_CHAINABLE_EXT5(m_name, x_name) \ MOCKPP_CONSTRUCT_MEMBERS_FOR_CHAINABLE5(m_name ## x_name) #endif // MOCKPP_CHAINABLEMOCKOBJECT_H |