[Mockpp-commits] mockpp/mockpp/visiting CountedVisitableMethod.h,NONE,1.1 gen_countvisitable_N.pl,NO
Brought to you by:
ewald-arnold
Update of /cvsroot/mockpp/mockpp/mockpp/visiting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31785/mockpp/visiting Added Files: CountedVisitableMethod.h gen_countvisitable_N.pl gen_responsevector_N.pl gen_visitablemethod_N.pl ResponseVector1.h ResponseVector2.h ResponseVector3.h ResponseVector4.h ResponseVector5.h ResponseVector6.h VisitableMockMethod0.h VisitableMockMethod1.h VisitableMockMethod2.h VisitableMockMethod3.h VisitableMockMethod4.h VisitableMockMethod5.h VisitableMockMethod6.h VisitableMockMethod.cpp VisitableMockMethod.h VisitableMockObject.cpp VisitableMockObject.h VisitableMockObject_macro.h VisitableMockObject_template.h Log Message: moved to subdir visiting --- NEW FILE: ResponseVector3.h --- /** @file @internal NOT INTENDED FOR PUBLIC INCLUSION @brief Generated with gen_responsevector_N.pl. $Id: ResponseVector3.h,v 1.1 2005/12/10 19:20:00 ewald-arnold Exp $ ***************************************************************************/ /************************************************************************** begin : Sat Feb 15 2003 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_ResponseVector3_H #define MOCKPP_ResponseVector3_H #include <mockpp/constraint/ConstraintHolder.h> #include <mockpp/constraint/IsEqual.h> namespace mockpp { /** Class returning a throwable depending on the parameters * passed to a method. */ template <typename P1, typename P2, typename P3> class ResponseThrowableVector3 : public ResponseVectorBase { public: /** * Construct a new empty vector * @param aName Label used to identify vector * @param parent parent verifiable */ ResponseThrowableVector3(const String &aName, VerifiableList *parent) : ResponseVectorBase(aName, parent) {} /** Destroys the vector */ virtual ~ResponseThrowableVector3() { reset(); } /** Adds a throwable. * @param t the throwable * @param p1 the parameter 1 upon which to return * @param p2 the parameter 2 upon which to return * @param p3 the parameter 3 upon which to return * @param count the number of times the object may be used */ void add(Throwable *t, const P1 &p1, const P2 &p2, const P3 &p3, unsigned count) { const ConstraintHolder<P1> h1 = new IsEqual<P1>(p1); const ConstraintHolder<P2> h2 = new IsEqual<P2>(p2); const ConstraintHolder<P3> h3 = new IsEqual<P3>(p3); add(t, h1, h2, h3, count); } /** Adds a throwable. * @param t the throwable * @param p1 the parameter 1 upon which to return * @param p2 the parameter 2 upon which to return * @param p3 the parameter 3 upon which to return * @param count the number of times the object may be used */ void add(Throwable *t, const ConstraintHolder<P1> &p1, const ConstraintHolder<P2> &p2, const ConstraintHolder<P3> &p3, unsigned count) { counter.push_back(count); tvec.push_back(t); typename mockpp::Constraint<P1>::AP cons1 (p1); typename mockpp::Constraint<P2>::AP cons2 (p2); typename mockpp::Constraint<P3>::AP cons3 (p3); t1vec.push_back(cons1.release()); t2vec.push_back(cons2.release()); t3vec.push_back(cons3.release()); } /** Removes all the objects from the list. */ void reset() { counter.clear(); tvec.reset(); for (unsigned i1 = 0; i1 < t1vec.size(); ++i1) delete t1vec[i1]; t1vec.clear(); for (unsigned i2 = 0; i2 < t2vec.size(); ++i2) delete t2vec[i2]; t2vec.clear(); for (unsigned i3 = 0; i3 < t3vec.size(); ++i3) delete t3vec[i3]; t3vec.clear(); } /** Finds a throwable for a set of parameters. * @param t the throwable * @param p1 the parameter 1 upon which to return * @param p2 the parameter 2 upon which to return * @param p3 the parameter 3 upon which to return * @return true: throwable found for parameters */ bool find(Throwable * &t, const P1 &p1, const P2 &p2, const P3 &p3) { for (unsigned i = 0; i < t1vec.size(); ++i) if ( counter[i] > 0 && t1vec[i]->eval(p1) && t2vec[i]->eval(p2) && t3vec[i]->eval(p3) ) { if (tvec.at(i) == 0) return false; if (counter[i] != MOCKPP_UNLIMITED) --counter[i]; t = tvec.at(i); return true; } return false; } protected: MOCKPP_STL::vector<Constraint<P1>*> t1vec; MOCKPP_STL::vector<Constraint<P2>*> t2vec; MOCKPP_STL::vector<Constraint<P3>*> t3vec; }; /** Class returning a throwable depending on the parameters * passed to a method. */ template <typename R, typename P1, typename P2, typename P3> class ResponseVector3 : public ResponseThrowableVector3<P1, P2, P3> { public: /** Construct a new empty vector * @param aName Label used to identify vector * @param parent parent verifiable */ ResponseVector3(const String &aName, VerifiableList *parent) : ResponseThrowableVector3<P1, P2, P3>(aName, parent) {} /** Adds a throwable. * @param t the throwable * @param p1 the parameter 1 upon which to return * @param p2 the parameter 2 upon which to return * @param p3 the parameter 3 upon which to return * @param count the number of times the object may be used */ void add(Throwable *t, const P1 &p1, const P2 &p2, const P3 &p3, unsigned count) { MOCKPP_ASSERT_TRUE(t != 0); ResponseThrowableVector3<P1, P2, P3>::add(t, p1, p2, p3, count); R r; rvec.push_back(r); } /** Adds a throwable. * @param t the throwable * @param p1 the parameter 1 upon which to return * @param p2 the parameter 2 upon which to return * @param p3 the parameter 3 upon which to return * @param count the number of times the object may be used */ void add(Throwable *t, const ConstraintHolder<P1> &p1, const ConstraintHolder<P2> &p2, const ConstraintHolder<P3> &p3, unsigned count) { MOCKPP_ASSERT_TRUE(t != 0); ResponseThrowableVector3<P1, P2, P3>::add (t, p1, p2, p3, count); R r; rvec.push_back(r); } /** Adds a return value. * @param r the return value * @param p1 the parameter 1 upon which to return * @param p2 the parameter 2 upon which to return * @param p3 the parameter 3 upon which to return * @param count the number of times the object may be used */ void add(const R &r, const P1 &p1, const P2 &p2, const P3 &p3, unsigned count) { ResponseThrowableVector3<P1, P2, P3>::add((Throwable*)0, p1, p2, p3, count); rvec.push_back(r); } /** Adds a return value. * @param r the return value * @param p1 the parameter 1 upon which to return * @param p2 the parameter 2 upon which to return * @param p3 the parameter 3 upon which to return * @param count the number of times the object may be used */ void add(const R &r, const ConstraintHolder<P1> &p1, const ConstraintHolder<P2> &p2, const ConstraintHolder<P3> &p3, unsigned count) { ResponseThrowableVector3<P1, P2, P3>::add((Throwable*)0, p1, p2, p3, count); rvec.push_back(r); } /** Removes all the objects from the list. */ void reset() { ResponseThrowableVector3<P1, P2, P3>::reset(); rvec.clear(); } #if defined(__BORLANDC__) || (__GNUC__ < 3) // ==> BCB5.5.1 ?? F1004 Internal compiler error at 0x12548c1 with base 0x1200000 bool find(Throwable * &t, const P1 &p1, const P2 &p2, const P3 &p3) { return ResponseThrowableVector3<P1, P2, P3>::find(t, p1, p2, p3); } #else using ResponseThrowableVector3<P1, P2, P3>::find; #endif /** Finds a return value for a set of parameters. * @param r the value * @param p1 the parameter 1 upon which to return * @param p2 the parameter 2 upon which to return * @param p3 the parameter 3 upon which to return * @return true: return value found for parameters */ bool find(R &r, const P1 &p1, const P2 &p2, const P3 &p3) { for (unsigned i = 0; i < this->t1vec.size(); ++i) if ( this->counter[i] > 0 && this->t1vec[i]->eval(p1) && this->t2vec[i]->eval(p2) && this->t3vec[i]->eval(p3) ) { if (this->tvec.at(i) != 0) return false; if (this->counter[i] != MOCKPP_UNLIMITED) --this->counter[i]; r = rvec[i]; return true; } return false; } private: MOCKPP_STL::vector<R> rvec; }; } // ns mockpp #endif // MOCKPP_ResponseVector3_H --- NEW FILE: ResponseVector2.h --- /** @file @internal NOT INTENDED FOR PUBLIC INCLUSION @brief Generated with gen_responsevector_N.pl. $Id: ResponseVector2.h,v 1.1 2005/12/10 19:20:00 ewald-arnold Exp $ ***************************************************************************/ /************************************************************************** begin : Sat Feb 15 2003 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_ResponseVector2_H #define MOCKPP_ResponseVector2_H #include <mockpp/constraint/ConstraintHolder.h> #include <mockpp/constraint/IsEqual.h> namespace mockpp { /** Class returning a throwable depending on the parameters * passed to a method. */ template <typename P1, typename P2> class ResponseThrowableVector2 : public ResponseVectorBase { public: /** * Construct a new empty vector * @param aName Label used to identify vector * @param parent parent verifiable */ ResponseThrowableVector2(const String &aName, VerifiableList *parent) : ResponseVectorBase(aName, parent) {} /** Destroys the vector */ virtual ~ResponseThrowableVector2() { reset(); } /** Adds a throwable. * @param t the throwable * @param p1 the parameter 1 upon which to return * @param p2 the parameter 2 upon which to return * @param count the number of times the object may be used */ void add(Throwable *t, const P1 &p1, const P2 &p2, unsigned count) { const ConstraintHolder<P1> h1 = new IsEqual<P1>(p1); const ConstraintHolder<P2> h2 = new IsEqual<P2>(p2); add(t, h1, h2, count); } /** Adds a throwable. * @param t the throwable * @param p1 the parameter 1 upon which to return * @param p2 the parameter 2 upon which to return * @param count the number of times the object may be used */ void add(Throwable *t, const ConstraintHolder<P1> &p1, const ConstraintHolder<P2> &p2, unsigned count) { counter.push_back(count); tvec.push_back(t); typename mockpp::Constraint<P1>::AP cons1 (p1); typename mockpp::Constraint<P2>::AP cons2 (p2); t1vec.push_back(cons1.release()); t2vec.push_back(cons2.release()); } /** Removes all the objects from the list. */ void reset() { counter.clear(); tvec.reset(); for (unsigned i1 = 0; i1 < t1vec.size(); ++i1) delete t1vec[i1]; t1vec.clear(); for (unsigned i2 = 0; i2 < t2vec.size(); ++i2) delete t2vec[i2]; t2vec.clear(); } /** Finds a throwable for a set of parameters. * @param t the throwable * @param p1 the parameter 1 upon which to return * @param p2 the parameter 2 upon which to return * @return true: throwable found for parameters */ bool find(Throwable * &t, const P1 &p1, const P2 &p2) { for (unsigned i = 0; i < t1vec.size(); ++i) if ( counter[i] > 0 && t1vec[i]->eval(p1) && t2vec[i]->eval(p2) ) { if (tvec.at(i) == 0) return false; if (counter[i] != MOCKPP_UNLIMITED) --counter[i]; t = tvec.at(i); return true; } return false; } protected: MOCKPP_STL::vector<Constraint<P1>*> t1vec; MOCKPP_STL::vector<Constraint<P2>*> t2vec; }; /** Class returning a throwable depending on the parameters * passed to a method. */ template <typename R, typename P1, typename P2> class ResponseVector2 : public ResponseThrowableVector2<P1, P2> { public: /** Construct a new empty vector * @param aName Label used to identify vector * @param parent parent verifiable */ ResponseVector2(const String &aName, VerifiableList *parent) : ResponseThrowableVector2<P1, P2>(aName, parent) {} /** Adds a throwable. * @param t the throwable * @param p1 the parameter 1 upon which to return * @param p2 the parameter 2 upon which to return * @param count the number of times the object may be used */ void add(Throwable *t, const P1 &p1, const P2 &p2, unsigned count) { MOCKPP_ASSERT_TRUE(t != 0); ResponseThrowableVector2<P1, P2>::add(t, p1, p2, count); R r; rvec.push_back(r); } /** Adds a throwable. * @param t the throwable * @param p1 the parameter 1 upon which to return * @param p2 the parameter 2 upon which to return * @param count the number of times the object may be used */ void add(Throwable *t, const ConstraintHolder<P1> &p1, const ConstraintHolder<P2> &p2, unsigned count) { MOCKPP_ASSERT_TRUE(t != 0); ResponseThrowableVector2<P1, P2>::add (t, p1, p2, count); R r; rvec.push_back(r); } /** Adds a return value. * @param r the return value * @param p1 the parameter 1 upon which to return * @param p2 the parameter 2 upon which to return * @param count the number of times the object may be used */ void add(const R &r, const P1 &p1, const P2 &p2, unsigned count) { ResponseThrowableVector2<P1, P2>::add((Throwable*)0, p1, p2, count); rvec.push_back(r); } /** Adds a return value. * @param r the return value * @param p1 the parameter 1 upon which to return * @param p2 the parameter 2 upon which to return * @param count the number of times the object may be used */ void add(const R &r, const ConstraintHolder<P1> &p1, const ConstraintHolder<P2> &p2, unsigned count) { ResponseThrowableVector2<P1, P2>::add((Throwable*)0, p1, p2, count); rvec.push_back(r); } /** Removes all the objects from the list. */ void reset() { ResponseThrowableVector2<P1, P2>::reset(); rvec.clear(); } #if defined(__BORLANDC__) || (__GNUC__ < 3) // ==> BCB5.5.1 ?? F1004 Internal compiler error at 0x12548c1 with base 0x1200000 bool find(Throwable * &t, const P1 &p1, const P2 &p2) { return ResponseThrowableVector2<P1, P2>::find(t, p1, p2); } #else using ResponseThrowableVector2<P1, P2>::find; #endif /** Finds a return value for a set of parameters. * @param r the value * @param p1 the parameter 1 upon which to return * @param p2 the parameter 2 upon which to return * @return true: return value found for parameters */ bool find(R &r, const P1 &p1, const P2 &p2) { for (unsigned i = 0; i < this->t1vec.size(); ++i) if ( this->counter[i] > 0 && this->t1vec[i]->eval(p1) && this->t2vec[i]->eval(p2) ) { if (this->tvec.at(i) != 0) return false; if (this->counter[i] != MOCKPP_UNLIMITED) --this->counter[i]; r = rvec[i]; return true; } return false; } private: MOCKPP_STL::vector<R> rvec; }; } // ns mockpp #endif // MOCKPP_ResponseVector2_H --- NEW FILE: VisitableMockObject_macro.h --- /** @file @internal NOT INTENDED FOR PUBLIC INCLUSION, USE @p VisitableMockObject.h INSTEAD @brief Keep ugly macros away from header files $Id: VisitableMockObject_macro.h,v 1.1 2005/12/10 19:20:00 ewald-arnold Exp $ ***************************************************************************/ /************************************************************************** begin : Fri Feb 07 2003 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. [...1393 lines suppressed...] addExpectedMethod(mockpp::getLatin1(getVerifiableName()) + "." + #m_name); \ m_name ## Parameter1.addExpected(param1); \ m_name ## Parameter2.addExpected(param2); \ m_name ## Parameter3.addExpected(param3); \ m_name ## Parameter4.addExpected(param4); \ m_name ## Parameter5.addExpected(param5); \ return v_ret_type(); \ } \ MOCKPP_MEMBER_RESTRICTOR_PRIVATE: \ MOCKPP_DECLARE_DEFAULT_VARS(m_name); \ MOCKPP_DECLARE_RETURN_VARS(v_ret_type, m_name); \ mutable mockpp::ResponseVector5< v_ret_type, v_type1, v_type2, v_type3, v_type4, v_type5 > m_name ## ResponseValues; \ MOCKPP_DECLARE_PARAMETER_VARS5(m_name, v_type1, v_type2, v_type3, v_type4, v_type5); \ MOCKPP_CONTROLLER_DECL5(classname, v_ret_type, m_name, v_type1, v_type2, v_type3, v_type4, v_type5) #endif // DOXYGEN_SHOULD_SKIP_THIS #endif // MOCKPP_VISITABLEMOCKOBJECT_MACRO_H --- NEW FILE: VisitableMockObject.cpp --- /** @file @brief MockObjects that can be visited under control $Id: VisitableMockObject.cpp,v 1.1 2005/12/10 19:20:00 ewald-arnold Exp $ ***************************************************************************/ /************************************************************************** begin : Fri Dec 18 2002 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/VisitableMockObject.h> namespace mockpp { MOCKPP_EXPORT VisitableMockObjectBase::VisitableMockObjectBase(const String &name, VerifiableList *parent) :methodList(name+MOCKPP_PCSTRING("/methodList"), parent) { activated = false; } MOCKPP_EXPORT VisitableMockObjectBase::~VisitableMockObjectBase() { } void MOCKPP_EXPORT VisitableMockObjectBase::addExpectedMethod(const MOCKPP_STL::string &name) const { MOCKPP_ASSERT_EQUALS(isActivated(), false); methodList.addExpected(name); } void MOCKPP_EXPORT VisitableMockObjectBase::addActualMethod(const MOCKPP_STL::string &name) const { MOCKPP_ASSERT_EQUALS(isActivated(), true); methodList.addActual(name); } void MOCKPP_EXPORT VisitableMockObjectBase::activate() { activated = true; } bool MOCKPP_EXPORT VisitableMockObjectBase::isActivated() const { return activated; } void MOCKPP_EXPORT VisitableMockObjectBase::visitableVerify() { methodList.verify(); for (unsigned i = 0; i < controllers.size(); ++i) controllers[i]->verify(); } void MOCKPP_EXPORT VisitableMockObjectBase::visitableReset() { activated = false; for (unsigned i = 0; i < controllers.size(); ++i) controllers[i]->reset(); } void MOCKPP_EXPORT VisitableMockObjectBase::unsetThrowablesInline() { for (unsigned i = 0; i < controllers.size(); ++i) controllers[i]->unsetThrowablesInline(); } void MOCKPP_EXPORT VisitableMockObjectBase::addController (Controller *ctr) { controllers.push_back(ctr); } void MOCKPP_EXPORT VisitableMockObjectBase::removeController (Controller *ctr) { MOCKPP_STL::vector<Controller*>::iterator it = MOCKPP_STL::find (controllers.begin(), controllers.end(), ctr); if (it != controllers.end()) controllers.erase(it); } unsigned MOCKPP_EXPORT VisitableMockObjectBase::numController() const { return controllers.size(); } ///////////////////////////////////////////////////////////////// MOCKPP_EXPORT VisitableMockObject::VisitableMockObject(const String &name, VerifiableList *parent) : MockObject(name, parent) , VisitableMockObjectBase(name, this) { } MOCKPP_EXPORT VisitableMockObject::~VisitableMockObject() { } void MOCKPP_EXPORT VisitableMockObject::verify() { MockObject::verify(); visitableVerify(); } void MOCKPP_EXPORT VisitableMockObject::reset() { MockObject::reset(); visitableReset(); } ///////////////////////////////////////////////////////////////// MOCKPP_EXPORT VisitableMockObject::Controller::~Controller() { } } // namespace mockpp --- NEW FILE: CountedVisitableMethod.h --- /** @file @internal NOT INTENDED FOR PUBLIC INCLUSION @brief Generated with gen_countvisitable.pl. $Id: CountedVisitableMethod.h,v 1.1 2005/12/10 19:19:59 ewald-arnold Exp $ ***************************************************************************/ /************************************************************************** begin : Sun Oct 30 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_COUNTEDVISITABLEMETHOD_H #define MOCKPP_COUNTEDVISITABLEMETHOD_H #include <mockpp/CountParameters.h> #include <mockpp/VisitableMockMethod0.h> #include <mockpp/VisitableMockMethod1.h> #include <mockpp/VisitableMockMethod2.h> #include <mockpp/VisitableMockMethod3.h> #include <mockpp/VisitableMockMethod4.h> #include <mockpp/VisitableMockMethod5.h> #include <mockpp/VisitableMockMethod6.h> namespace mockpp { #ifndef MOCKPP_COUNTED_WEAKNESS /** Helper class to select the method mock with the correct number of parameters. * Works with meta programming. * @internal */ template<unsigned params> class SwitchVisitable { }; /** Helper class to select the method mock with 0 parameters. * Works with meta programming. * @internal */ template<> class SwitchVisitable<0> { public: /** Helper class with an embeded type to the the method mock with 0 parameters. */ template< typename R , typename P1 , typename P2 , typename P3 , typename P4 , typename P5 , typename P6> class Method { public: typedef VisitableMockMethod0<R> VisitableMockMethodType; }; }; /** Helper class to select the method mock with 1 parameters. * Works with meta programming. * @internal */ template<> class SwitchVisitable<1> { public: /** Helper class with an embeded type to the the method mock with 1 parameters. */ template< typename R , typename P1 , typename P2 , typename P3 , typename P4 , typename P5 , typename P6> class Method { public: typedef VisitableMockMethod1<R, P1> VisitableMockMethodType; }; }; /** Helper class to select the method mock with 2 parameters. * Works with meta programming. * @internal */ template<> class SwitchVisitable<2> { public: /** Helper class with an embeded type to the the method mock with 2 parameters. */ template< typename R , typename P1 , typename P2 , typename P3 , typename P4 , typename P5 , typename P6> class Method { public: typedef VisitableMockMethod2<R, P1, P2> VisitableMockMethodType; }; }; /** Helper class to select the method mock with 3 parameters. * Works with meta programming. * @internal */ template<> class SwitchVisitable<3> { public: /** Helper class with an embeded type to the the method mock with 3 parameters. */ template< typename R , typename P1 , typename P2 , typename P3 , typename P4 , typename P5 , typename P6> class Method { public: typedef VisitableMockMethod3<R, P1, P2, P3> VisitableMockMethodType; }; }; /** Helper class to select the method mock with 4 parameters. * Works with meta programming. * @internal */ template<> class SwitchVisitable<4> { public: /** Helper class with an embeded type to the the method mock with 4 parameters. */ template< typename R , typename P1 , typename P2 , typename P3 , typename P4 , typename P5 , typename P6> class Method { public: typedef VisitableMockMethod4<R, P1, P2, P3, P4> VisitableMockMethodType; }; }; /** Helper class to select the method mock with 5 parameters. * Works with meta programming. * @internal */ template<> class SwitchVisitable<5> { public: /** Helper class with an embeded type to the the method mock with 5 parameters. */ template< typename R , typename P1 , typename P2 , typename P3 , typename P4 , typename P5 , typename P6> class Method { public: typedef VisitableMockMethod5<R, P1, P2, P3, P4, P5> VisitableMockMethodType; }; }; /** Helper class to select the method mock with 6 parameters. * Works with meta programming. * @internal */ template<> class SwitchVisitable<6> { public: /** Helper class with an embeded type to the the method mock with 6 parameters. */ template< typename R , typename P1 , typename P2 , typename P3 , typename P4 , typename P5 , typename P6> class Method { public: typedef VisitableMockMethod6<R, P1, P2, P3, P4, P5, P6> VisitableMockMethodType; }; }; /** Method mock class to select the actual class with the desired number of parameters. * Works with meta programming. */ template< typename R , typename P1 = NoParameter , typename P2 = NoParameter , typename P3 = NoParameter , typename P4 = NoParameter , typename P5 = NoParameter , typename P6 = NoParameter> class VisitableMockMethod : public SwitchVisitable<CountParameters<R, P1, P2, P3, P4, P5, P6>::value> ::template Method<R, P1, P2, P3, P4, P5, P6> ::VisitableMockMethodType { public: /** Constructs the mock object. * @param name human readable description about the expectation * @param parent parent chainable mock object */ VisitableMockMethod(const String &name, VisitableMockObject *parent ) : SwitchVisitable<CountParameters<R, P1, P2, P3, P4, P5, P6>::value > ::template Method<R, P1, P2, P3, P4, P5, P6> ::VisitableMockMethodType(name, parent) { } }; #else // MOCKPP_COUNTED_WEAKNESS /** Helper class to select the method mock with the correct number of parameters. * Works with partial specialisation. * @internal */ template< typename R , typename P1 = NoParameter , typename P2 = NoParameter , typename P3 = NoParameter , typename P4 = NoParameter , typename P5 = NoParameter , typename P6 = NoParameter , typename P7 = NoParameter> class VisitableMockMethod { }; /** Method mock class to select the actual class with 0 parameters. * Works with partial specialisation. */ template<typename R> class VisitableMockMethod<R, NoParameter, NoParameter, NoParameter, NoParameter, NoParameter, NoParameter> : public VisitableMockMethod0<R> { public: /** Constructs the mock object. * @param name human readable description about the expectation * @param parent parent chainable mock object */ VisitableMockMethod<R, NoParameter, NoParameter, NoParameter, NoParameter, NoParameter, NoParameter> (const String &name, VisitableMockObject *parent ) : VisitableMockMethod0<R>(name, parent) { } }; /** Method mock class to select the actual class with 1 parameters. * Works with partial specialisation. */ template<typename R, typename P1> class VisitableMockMethod<R, P1, NoParameter, NoParameter, NoParameter, NoParameter, NoParameter> : public VisitableMockMethod1<R, P1> { public: /** Constructs the mock object. * @param name human readable description about the expectation * @param parent parent chainable mock object */ VisitableMockMethod<R, P1, NoParameter, NoParameter, NoParameter, NoParameter, NoParameter> (const String &name, VisitableMockObject *parent ) : VisitableMockMethod1<R, P1>(name, parent) { } }; /** Method mock class to select the actual class with 2 parameters. * Works with partial specialisation. */ template<typename R, typename P1, typename P2> class VisitableMockMethod<R, P1, P2, NoParameter, NoParameter, NoParameter, NoParameter> : public VisitableMockMethod2<R, P1, P2> { public: /** Constructs the mock object. * @param name human readable description about the expectation * @param parent parent chainable mock object */ VisitableMockMethod<R, P1, P2, NoParameter, NoParameter, NoParameter, NoParameter> (const String &name, VisitableMockObject *parent ) : VisitableMockMethod2<R, P1, P2>(name, parent) { } }; /** Method mock class to select the actual class with 3 parameters. * Works with partial specialisation. */ template<typename R, typename P1, typename P2, typename P3> class VisitableMockMethod<R, P1, P2, P3, NoParameter, NoParameter, NoParameter> : public VisitableMockMethod3<R, P1, P2, P3> { public: /** Constructs the mock object. * @param name human readable description about the expectation * @param parent parent chainable mock object */ VisitableMockMethod<R, P1, P2, P3, NoParameter, NoParameter, NoParameter> (const String &name, VisitableMockObject *parent ) : VisitableMockMethod3<R, P1, P2, P3>(name, parent) { } }; /** Method mock class to select the actual class with 4 parameters. * Works with partial specialisation. */ template<typename R, typename P1, typename P2, typename P3, typename P4> class VisitableMockMethod<R, P1, P2, P3, P4, NoParameter, NoParameter> : public VisitableMockMethod4<R, P1, P2, P3, P4> { public: /** Constructs the mock object. * @param name human readable description about the expectation * @param parent parent chainable mock object */ VisitableMockMethod<R, P1, P2, P3, P4, NoParameter, NoParameter> (const String &name, VisitableMockObject *parent ) : VisitableMockMethod4<R, P1, P2, P3, P4>(name, parent) { } }; /** Method mock class to select the actual class with 5 parameters. * Works with partial specialisation. */ template<typename R, typename P1, typename P2, typename P3, typename P4, typename P5> class VisitableMockMethod<R, P1, P2, P3, P4, P5, NoParameter> : public VisitableMockMethod5<R, P1, P2, P3, P4, P5> { public: /** Constructs the mock object. * @param name human readable description about the expectation * @param parent parent chainable mock object */ VisitableMockMethod<R, P1, P2, P3, P4, P5, NoParameter> (const String &name, VisitableMockObject *parent ) : VisitableMockMethod5<R, P1, P2, P3, P4, P5>(name, parent) { } }; /** Method mock class to select the actual class with 6 parameters. * Works with partial specialisation. */ template<typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6> class VisitableMockMethod<R, P1, P2, P3, P4, P5, P6> : public VisitableMockMethod6<R, P1, P2, P3, P4, P5, P6> { public: /** Constructs the mock object. * @param name human readable description about the expectation * @param parent parent chainable mock object */ VisitableMockMethod<R, P1, P2, P3, P4, P5, P6> (const String &name, VisitableMockObject *parent ) : VisitableMockMethod6<R, P1, P2, P3, P4, P5, P6>(name, parent) { } }; #endif // MOCKPP_COUNTED_WEAKNESS } // ns mockpp #endif // MOCKPP_COUNTEDVISITABLEMETHOD_H --- NEW FILE: VisitableMockMethod4.h --- /** @file @brief Visitable Mock Method with 4 parameters. Generated with gen_visitablemethod_N.pl. $Id: VisitableMockMethod4.h,v 1.1 2005/12/10 19:20:00 ewald-arnold Exp $ ***************************************************************************/ /************************************************************************** begin : Thu Oct 22 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_VisitableMockMethod4_H #define MOCKPP_VisitableMockMethod4_H #include <mockpp/mockpp.h> #include <mockpp/VisitableMockObject.h> #include <mockpp/VisitableMockMethod.h> #include <mockpp/ResponseVector4.h> namespace mockpp { /** Common stuff to set up visitable mock method expectations with 4 parameters. * @ingroup grp_controller */ template <typename R, typename P1, typename P2, typename P3, typename P4> class VisitableMockMethod4Common : public VisitableMockReturningMethodBase<R> { public: /** Constructs the mock object. * @param name human readable description about the expectation * @param parent parent Visitable mock object */ VisitableMockMethod4Common(const String &name, VisitableMockObject *parent = 0) : VisitableMockReturningMethodBase<R>(name, parent) , responseThrowables(this->getMethodName() + MOCKPP_PCHAR("/responseThrowables") , this) , parameter1(this->getMethodName() + MOCKPP_PCHAR("/parameter1"), this) , parameter2(this->getMethodName() + MOCKPP_PCHAR("/parameter2"), this) , parameter3(this->getMethodName() + MOCKPP_PCHAR("/parameter3"), this) , parameter4(this->getMethodName() + MOCKPP_PCHAR("/parameter4"), this) { } /** Set up expectations with constraints. * @param p1 mock method parameter 1 * @param p2 mock method parameter 2 * @param p3 mock method parameter 3 * @param p4 mock method parameter 4 */ void forward (const ConstraintHolder<P1> &p1, const ConstraintHolder<P2> &p2, const ConstraintHolder<P3> &p3, const ConstraintHolder<P4> &p4) const { MOCKPP_ASSERT_FALSE(this->getVisitableMockObject()->isActivated()); this->getVisitableMockObject()->addExpectedMethod(this->getMethodIdentifier()); parameter1.addExpected(p1); parameter2.addExpected(p2); parameter3.addExpected(p3); parameter4.addExpected(p4); } protected: /** Perform the internals to verify a mocked method or setup expectations. * @param p1 mock method parameter 1 * @param p2 mock method parameter 2 * @param p3 mock method parameter 3 * @param p4 mock method parameter 4 */ void forward_param(const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4) const { if (!this->getVisitableMockObject()->isActivated() ) { this->getVisitableMockObject()->addExpectedMethod(this->getMethodIdentifier()); parameter1.addExpected(p1); parameter2.addExpected(p2); parameter3.addExpected(p3); parameter4.addExpected(p4); } else { try { this->getVisitableMockObject()->addActualMethod(this->getMethodIdentifier()); Throwable *t; if (this->responseThrowables.find(t, p1, p2, p3, p4)) t->throw_me(); this->throwAvailableException(); } catch(...) { parameter1.balanceActual(); parameter2.balanceActual(); parameter3.balanceActual(); parameter4.balanceActual(); MOCKPP_RETHROW; } parameter1.addActual(p1); parameter2.addActual(p2); parameter3.addActual(p3); parameter4.addActual(p4); } } public: /** Adds another response throwable. * Response values are determined on the parameters you pass. This way the * object returns a value that is totally based on the input. * @param t the throwable object * @param p1 mock method parameter 1 * @param p2 mock method parameter 2 * @param p3 mock method parameter 3 * @param p4 mock method parameter 4 * @param count the number of times this value shall be returned. Default is unlimited. */ void addResponseThrowable(Throwable *t, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4, unsigned count = MOCKPP_UNLIMITED) { MOCKPP_ASSERT_FALSE(this->getVisitableMockObject()->isActivated()); this->responseThrowables.add(t, p1, p2, p3, p4, count); } /** Adds another response throwable. * Response values are determined on the parameters you pass. This way the * object returns a value that is totally based on the input. * @param t the throwable object * @param p1 mock method parameter 1 * @param p2 mock method parameter 2 * @param p3 mock method parameter 3 * @param p4 mock method parameter 4 * @param count the number of times this value shall be returned. Default is unlimited. */ void addResponseThrowable(Throwable *t, const ConstraintHolder<P1> &p1, const ConstraintHolder<P2> &p2, const ConstraintHolder<P3> &p3, const ConstraintHolder<P4> &p4, unsigned count = MOCKPP_UNLIMITED) { MOCKPP_ASSERT_FALSE(this->getVisitableMockObject()->isActivated()); this->responseThrowables.add(t, p1, p2, p3, p4, count); } private: mutable ResponseThrowableVector4<P1, P2, P3, P4> responseThrowables; mutable ConstraintList<P1> parameter1; mutable ConstraintList<P2> parameter2; mutable ConstraintList<P3> parameter3; mutable ConstraintList<P4> parameter4; }; /** Set up visitable mock method expectations with 4 parameters. * @ingroup grp_controller */ template <typename R, typename P1, typename P2, typename P3, typename P4> class VisitableMockMethod4 : public VisitableMockMethod4Common<R, P1, P2, P3, P4> { public: /** Constructs the mock object. * @param name human readable description about the expectation * @param parent parent Visitable mock object */ VisitableMockMethod4(const String &name, VisitableMockObject *parent = 0) : VisitableMockMethod4Common<R, P1, P2, P3, P4>(name, parent) , responseValues(this->getMethodName() + MOCKPP_PCHAR("/responseValues") , this) { } /** Actually verifies the mocked method. * Must be called by the client code. * @param p1 mock method parameter 1 * @param p2 mock method parameter 2 * @param p3 mock method parameter 3 * @param p4 mock method parameter 4 */ R forward(const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4) const { this->forward_param(p1, p2, p3, p4); if (this->getVisitableMockObject()->isActivated() ) { R ret_val; if (this->responseValues.find(ret_val, p1, p2, p3, p4)) return ret_val; return this->determineReturnValue(); } else return R(); // only dummy value to make the compiler happy } #if defined(__BORLANDC__) // ==> BCB5.5.1 ?? F1004 Internal compiler error at 0x12548c1 with base 0x1200000 /** Set up expectations with constraints. * @param p1 mock method parameter 1 * @param p2 mock method parameter 2 * @param p3 mock method parameter 3 * @param p4 mock method parameter 4 */ void forward (const ConstraintHolder<P1> &p1, const ConstraintHolder<P2> &p2, const ConstraintHolder<P3> &p3, const ConstraintHolder<P4> &p4) const { VisitableMockMethod4Common<R, P1, P2, P3, P4>::forward(p1, p2, p3, p4); } #else using VisitableMockMethod4Common<R, P1, P2, P3, P4>::forward; #endif /** Adds another response value. * Response values are determined on the parameters you pass. This way the * object returns a value that is totally based on the input. * @param rv the return value * @param p1 mock method parameter 1 * @param p2 mock method parameter 2 * @param p3 mock method parameter 3 * @param p4 mock method parameter 4 * @param count the number of times this value shall be returned. Default is unlimited. */ void addResponseValue(const R &rv, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4, unsigned count = MOCKPP_UNLIMITED) { MOCKPP_ASSERT_FALSE(this->getVisitableMockObject()->isActivated()); this->responseValues.add(rv, p1, p2, p3, p4, count); } /** Adds another response value. * Response values are determined on the parameters you pass. This way the * object returns a value that is totally based on the input. * @param rv the return value * @param p1 mock method parameter 1 * @param p2 mock method parameter 2 * @param p3 mock method parameter 3 * @param p4 mock method parameter 4 * @param count the number of times this value shall be returned. Default is unlimited. */ void addResponseValue(const R &rv, const ConstraintHolder<P1> &p1, const ConstraintHolder<P2> &p2, const ConstraintHolder<P3> &p3, const ConstraintHolder<P4> &p4, unsigned count = MOCKPP_UNLIMITED) { MOCKPP_ASSERT_FALSE(this->getVisitableMockObject()->isActivated()); this->responseValues.add(rv, p1, p2, p3, p4, count); } private: mutable ResponseVector4<R, P1, P2, P3, P4> responseValues; }; /** Set up visitable mock method expectations with 4 parameters. * Partial specialisation for a void return value. * @ingroup grp_controller */ template <typename P1, typename P2, typename P3, typename P4> class VisitableMockMethod4<void, P1, P2, P3, P4> : public VisitableMockMethod4Common<void, P1, P2, P3, P4> { public: /** Constructs the mock object. * @param name human readable description about the expectation * @param parent parent Visitable mock object */ VisitableMockMethod4(const String &name, VisitableMockObject *parent = 0) : VisitableMockMethod4Common<void, P1, P2, P3, P4>(name, parent) { } /** Actually verifies the mocked method. * Must be called by the client code. * @param p1 mock method parameter 1 * @param p2 mock method parameter 2 * @param p3 mock method parameter 3 * @param p4 mock method parameter 4 */ void forward(const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4) const { this->forward_param(p1, p2, p3, p4); } #if defined(__BORLANDC__) // ==> BCB5.5.1 ?? F1004 Internal compiler error at 0x12548c1 with base 0x1200000 /** Set up expectations with constraints. * @param p1 mock method parameter 1 * @param p2 mock method parameter 2 * @param p3 mock method parameter 3 * @param p4 mock method parameter 4 */ void forward (const ConstraintHolder<P1> &p1, const ConstraintHolder<P2> &p2, const ConstraintHolder<P3> &p3, const ConstraintHolder<P4> &p4) const { VisitableMockMethod4Common<void, P1, P2, P3, P4>::forward(p1, p2, p3, p4); } #else using VisitableMockMethod4Common<void, P1, P2, P3, P4>::forward; #endif }; } // ns mockpp #endif // MOCKPP_VisitableMockMethod4_H --- NEW FILE: gen_countvisitable_N.pl --- #!/usr/bin/perl -w # # $Id: gen_countvisitable_N.pl,v 1.1 2005/12/10 19:19:59 ewald-arnold Exp $ use English; if ($#ARGV < 0) { print "Usage: perl gen_countvisitable <number of arguments>\n"; exit; } $totalNumArgs = $ARGV[0]; if ($totalNumArgs < 5) { $totalNumArgs = 5; } for ($numArgs = 1; $numArgs <= $totalNumArgs; ++$numArgs) { } open OUT, ">CountedVisitableMethod.h"; print OUT "/** \@file \@internal NOT INTENDED FOR PUBLIC INCLUSION \@brief Generated with gen_countvisitable.pl. \$I" . "d: CountedVisitableMethod.h,v 1.7 2005/10/19 20:53:09 ewald-arnold Exp \$ ***************************************************************************/ /************************************************************************** begin : Sun Oct 30 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_COUNTEDVISITABLEMETHOD_H #define MOCKPP_COUNTEDVISITABLEMETHOD_H #include <mockpp/CountParameters.h> "; for ($p = 0; $p <= $totalNumArgs; ++$p) { print OUT " #include <mockpp/VisitableMockMethod" . $p . ".h>";} print OUT " namespace mockpp { #ifndef MOCKPP_COUNTED_WEAKNESS /** Helper class to select the method mock with the correct number of parameters. * Works with meta programming. * \@internal */ template<unsigned params> class SwitchVisitable { }; "; for ($numArgs = 0; $numArgs <= $totalNumArgs; ++$numArgs) { $templateParms = ""; $templateParms_colon = ""; for ($i = 1; $i <= $numArgs; ++$i) { if ($i > 1) { $templateParms .= ", "; } $templateParms .= "typename P$i"; } if ($numArgs > 0) { $templateParms_colon = ", " . $templateParms; } $templateArgs_colon = ""; $_ = $templateParms; s/typename //g; $templateArgs = $_; if ($numArgs > 0) { $templateArgs_colon = ", ". $templateArgs; } print "Creating CountedVisitableMethod" . $numArgs ."\n"; print OUT " /** Helper class to select the method mock with " . $numArgs ." parameters. * Works with meta programming. * \@internal */ template<> class SwitchVisitable<" . $numArgs ."> { public: "; print OUT " /** Helper class with an embeded type to the the method mock with " . $numArgs ." parameters. */ template< typename R"; for($p = 1; $p <= $totalNumArgs; ++$p) { print OUT " , typename P" . $p; } print OUT "> class Method { public: typedef VisitableMockMethod" . $numArgs ."<R" . $templateArgs_colon . "> VisitableMockMethodType; }; }; "; } print OUT " /** Method mock class to select the actual class with the desired number of parameters. * Works with meta programming. */ template< typename R , typename P1 = NoParameter"; for($p = 2; $p <= $totalNumArgs; ++$p) { print OUT " , typename P" . $p . " = NoParameter"; }; print OUT "> class VisitableMockMethod : public SwitchVisitable<CountParameters<R, " . $templateArgs . ">::value> ::template Method<R, " . $templateArgs . "> ::VisitableMockMethodType { public: /** Constructs the mock object. * \@param name human readable description about the expectation * \@param parent parent chainable mock object */ VisitableMockMethod(const String &name, VisitableMockObject *parent ) : SwitchVisitable<CountParameters<R, " . $templateArgs . ">::value > ::template Method<R, " . $templateArgs . "> ::VisitableMockMethodType(name, parent) { } }; #else // MOCKPP_COUNTED_WEAKNESS /** Helper class to select the method mock with the correct number of parameters. * Works with partial specialisation. * \@internal */ template< typename R , typename P1 = NoParameter"; for($p = 2; $p <= $totalNumArgs+1; ++$p) { print OUT " , typename P" . $p . " = NoParameter"; }; print OUT "> class VisitableMockMethod { }; "; for ($numArgs = 0; $numArgs <= $totalNumArgs; ++$numArgs) { $templateParms = ""; $templateParms_colon = ""; for ($i = 1; $i <= $numArgs; ++$i) { if ($i > 1) { $templateParms .= ", "; } $templateParms .= "typename P$i"; } if ($numArgs > 0) { $templateParms_colon = ", " . $templateParms; } $templateArgs_colon = ""; $_ = $templateParms; s/typename //g; $templateArgs = $_; if ($numArgs > 0) { $templateArgs_colon = ", ". $templateArgs; } $noParamArgs = $templateArgs; for ($i = $numArgs+1; $i <= $totalNumArgs; ++$i) { if ($i > 1) { $noParamArgs .= ", "; } $noParamArgs .= "NoParameter"; } print OUT " /** Method mock class to select the actual class with " . $numArgs . " parameters. * Works with partial specialisation. */ template<typename R" . $templateParms_colon . "> class VisitableMockMethod<R, " . $noParamArgs . "> : public VisitableMockMethod" . $numArgs . "<R" . $templateArgs_colon . "> { public: /** Constructs the mock object. * \@param name human readable description about the expectation * \@param parent parent chainable mock object */ VisitableMockMethod<R, " . $noParamArgs . "> (const String &name, VisitableMockObject *parent ) : VisitableMockMethod" . $numArgs . "<R" . $templateArgs_colon . ">(name, parent) { } }; "; } print OUT " #endif // MOCKPP_COUNTED_WEAKNESS } // ns mockpp #endif // MOCKPP_COUNTEDVISITABLEMETHOD_H "; close OUT; --- NEW FILE: VisitableMockMethod5.h --- /** @file @brief Visitable Mock Method with 5 parameters. Generated with gen_visitablemethod_N.pl. $Id: VisitableMockMethod5.h,v 1.1 2005/12/10 19:20:00 ewald-arnold Exp $ ***************************************************************************/ /************************************************************************** begin : Thu Oct 22 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_VisitableMockMethod5_H #define MOCKPP_VisitableMockMethod5_H #include <mockpp/mockpp.h> #include <mockpp/VisitableMockObject.h> #include <mockpp/VisitableMockMethod.h> #include <mockpp/ResponseVector5.h> namespace mockpp { /** Common stuff to set up visitable mock method expectations with 5 parameters. * @ingroup grp_controller */ template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5> class VisitableMockMethod5Common : public VisitableMockReturningMethodBase<R> { public: /** Constructs the mock object. * @param name human readable description about the expectation * @param parent parent Visitable mock object */ VisitableMockMethod5Common(const String &name, VisitableMockObject *parent = 0) : VisitableMockReturningMethodBase<R>(name, parent) , responseThrowables(this->getMethodName() + MOCKPP_PCHAR("/responseThrowables") , this) , parameter1(this->getMethodName() + MOCKPP_PCHAR("/parameter1"), this) , parameter2(this->getMethodName() + MOCKPP_PCHAR("/parameter2"), this) , parameter3(this->getMethodName() + MOCKPP_PCHAR("/parameter3"), this) , parameter4(this->getMethodName() + MOCKPP_PCHAR("/parameter4"), this) , parameter5(this->getMethodName() + MOCKPP_PCHAR("/parameter5"), this) { } /** Set up expectations with constraints. * @param p1 mock method parameter 1 * @param p2 mock method parameter 2 * @param p3 mock method parameter 3 * @param p4 mock method parameter 4 * @param p5 mock method parameter 5 */ void forward (const ConstraintHolder<P1> &p1, const ConstraintHolder<P2> &p2, const ConstraintHolder<P3> &p3, const ConstraintHolder<P4> &p4, const ConstraintHolder<P5> &p5) const { MOCKPP_ASSERT_FALSE(this->getVisitableMockObject()->isActivated()); this->getVisitableMockObject()->addExpectedMethod(this->getMethodIdentifier()); parameter1.addExpected(p1); parameter2.addExpected(p2); parameter3.addExpected(p3); parameter4.addExpected(p4); parameter5.addExpected(p5); } protected: /** Perform the internals to verify a mocked method or setup expectations. * @param p1 mock method parameter 1 * @param p2 mock method parameter 2 * @param p3 mock method parameter 3 * @param p4 mock method parameter 4 * @param p5 mock method parameter 5 */ void forward_param(const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4, const P5 &p5) const { if (!this->getVisitableMockObject()->isActivated() ) { this->getVisitableMockObject()->addExpectedMethod(this->getMethodIdentifier()); parameter1.addExpected(p1); parameter2.addExpected(p2); parameter3.addExpected(p3); parameter4.addExpected(p4); parameter5.addExpected(p5); } else { try { this->getVisitableMockObject()->addActualMethod(this->getMethodIdentifier()); Throwable *t; if (this->responseThrowables.find(t, p1, p2, p3, p4, p5)) t->throw_me(); this->throwAvailableException(); } catch(...) { parameter1.balanceActual(); parameter2.balanceActual(); parameter3.balanceActual(); parameter4.balanceActual(); parameter5.balanceActual(); MOCKPP_RETHROW; } parameter1.addActual(p1); parameter2.addActual(p2); parameter3.addActual(p3); parameter4.addActual(p4); parameter5.addActual(p5); } } public: /** Adds another response throwable. * Response values are determined on the parameters you pass. This way the * object returns a value that is totally based on the input. * @param t the throwable object * @param p1 mock method parameter 1 * @param p2 mock method parameter 2 * @param p3 mock method parameter 3 * @param p4 mock method parameter 4 * @param p5 mock method parameter 5 * @param count the number of times this value shall be returned. Default is unlimited. */ void addResponseThrowable(Throwable *t, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4, const P5 &p5, unsigned count = MOCKPP_UNLIMITED) { MOCKPP_ASSERT_FALSE(this->getVisitableMockObject()->isActivated()); this->responseThrowables.add(t, p1, p2, p3, p4, p5, count); } /** Adds another response throwable. * Response values are determined on the parameters you pass. This way the * object returns a value that is totally based on the input. * @param t the throwable object * @param p1 mock method parameter 1 * @param p2 mock method parameter 2 * @param p3 mock method parameter 3 * @param p4 mock method parameter 4 * @param p5 mock method parameter 5 * @param count the number of times this value shall be returned. Default is unlimited. */ void addResponseThrowable(Throwable *t, const ConstraintHolder<P1> &p1, const ConstraintHolder<P2> &p2, const ConstraintHolder<P3> &p3, const ConstraintHolder<P4> &p4, const ConstraintHolder<P5> &p5, unsigned count = MOCKPP_UNLIMITED) { MOCKPP_ASSERT_FALSE(this->getVisitableMockObject()->isActivated()); this->responseThrowables.add(t, p1, p2, p3, p4, p5, count); } private: mutable ResponseThrowableVector5<P1, P2, P3, P4, P5> responseThrowables; mutable ConstraintList<P1> parameter1; mutable ConstraintList<P2> parameter2; mutable ConstraintList<P3> ... [truncated message content] |