Update of /cvsroot/mockpp/mockpp/mockpp/chaining
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27208/mockpp/chaining
Added Files:
ChainableMockMethod.h
Log Message:
draft
--- NEW FILE: ChainableMockMethod.h ---
/** @file
@brief Chainable Mock Methods based on templates
$Id: ChainableMockMethod.h,v 1.1 2005/10/02 10:56:02 ewald-arnold Exp $
***************************************************************************/
/**************************************************************************
begin : Thu Oct 2 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_CHAINABLEMOCKMETHOD_H
#define MOCKPP_CHAINABLEMOCKMETHOD_H
#include <mockpp/mockpp.h>
#include <mockpp/ChainableMockObject.h>
namespace mockpp {
template <typename R, typename P1>
class ChainableMockMethod : public MockObject
{
public:
typedef Invocation1<P1> InvocationType;
typedef CoreMock<R, InvocationType> CoreMockType;
typedef R ReturnType;
/** Constructs the mock object.
* @param name human readable description about the expectation
* @param parent parent chainable mock object
*/
ChainableMockMethod(const String &name, ChainableMockObject *parent = 0)
: MockObject(name, parent)
, chainable_parent(parent)
, coremock(MOCKPP_PCHAR("CoreMock_in_") + name, this)
{}
R forward(P1 param1) const
{
Invocation1<P1> inv(MOCKPP_PCHAR("name"), param1);
return coremock.invoke(inv);
}
CoreMockType & getCoreMock()
{
return coremock;
}
String getMethodName() const
{
// static CppString method_name = getVerifiableName() + MOCKPP_PCHAR(".") + m_name;
return getVerifiableName();
}
private:
ChainableMockObject *chainable_parent;
mutable CoreMockType coremock;
};
template <typename CMM>
class ChainerFor
: public ChainingMockBuilder <ArgumentsMatchBuilder1<typename CMM::ReturnType,
typename CMM::InvocationType> >
{
public:
typedef ChainingMockBuilder <ArgumentsMatchBuilder1<typename CMM::ReturnType,
typename CMM::InvocationType> > Builder;
ChainerFor(ChainableMockObject &obj, CMM &method)
: Builder(&method.getCoreMock(), &obj, method.getMethodName())
{}
};
} // namespace mockpp
#endif // MOCKPP_CHAINABLEMOCKMETHOD_H
|