Thread: [Mockpp-commits] mockpp/mockpp/chaining ChainableMockMethod.h,1.2,1.3
Brought to you by:
ewald-arnold
From: Ewald A. <ewa...@us...> - 2005-10-03 09:54:48
|
Update of /cvsroot/mockpp/mockpp/mockpp/chaining In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20688/mockpp/chaining Modified Files: ChainableMockMethod.h Log Message: more tests and fixes Index: ChainableMockMethod.h =================================================================== RCS file: /cvsroot/mockpp/mockpp/mockpp/chaining/ChainableMockMethod.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- ChainableMockMethod.h 2 Oct 2005 18:51:33 -0000 1.2 +++ ChainableMockMethod.h 3 Oct 2005 09:54:39 -0000 1.3 @@ -60,8 +60,11 @@ }; +///////////////////////////////////////////////////////////////////////////////////////////// + + template <typename R, typename P1> -class ChainableMockMethod1 : public ChainableMockMethodBase<R> +class ChainableMockMethod1Base : public ChainableMockMethodBase<R> { public: @@ -73,18 +76,12 @@ * @param name human readable description about the expectation * @param parent parent chainable mock object */ - ChainableMockMethod1(const String &name, ChainableMockObject *parent = 0) + ChainableMockMethod1Base(const String &name, ChainableMockObject *parent = 0) : ChainableMockMethodBase<R>(name, parent) , coremock(MOCKPP_PCHAR("CoreMock_in_") + name, this) {} - R forward(P1 param1) const - { - InvocationType inv(MOCKPP_PCHAR("name"), param1); - return coremock.invoke(inv); - } - - CoreMockType & getCoreMock() + CoreMockType & getCoreMock() const { return coremock; } @@ -95,20 +92,68 @@ { public: - ChainerFor(ChainableMockObject &obj, ChainableMockMethod1 &method) + ChainerFor(ChainableMockObject &obj, ChainableMockMethod1Base &method) : Builder(&method.getCoreMock(), &obj, method.getMethodName()) {} }; private: - ChainableMockObject *chainable_parent; mutable CoreMockType coremock; }; +template <typename R, typename P1> +class ChainableMockMethod1 : public ChainableMockMethod1Base<R, P1> +{ + public: + + typedef typename ChainableMockMethod1Base<R, P1>::InvocationType InvocationType; + + /** Constructs the mock object. + * @param name human readable description about the expectation + * @param parent parent chainable mock object + */ + ChainableMockMethod1(const String &name, ChainableMockObject *parent = 0) + : ChainableMockMethod1Base<R, P1>(name, parent) + {} + + R forward(P1 param1) const + { + InvocationType inv(getMethodName(), param1); + return getCoreMock().invoke(inv); + } +}; + + +template <typename P1> +class ChainableMockMethod1<void, P1> : public ChainableMockMethod1Base<void, P1> +{ + public: + + typedef typename ChainableMockMethod1Base<void, P1>::InvocationType InvocationType; + + /** Constructs the mock object. + * @param name human readable description about the expectation + * @param parent parent chainable mock object + */ + ChainableMockMethod1(const String &name, ChainableMockObject *parent = 0) + : ChainableMockMethod1Base<void, P1>(name, parent) + {} + + void forward(P1 param1) const + { + InvocationType inv(MOCKPP_PCHAR("void-name"), param1); + getCoreMock().invoke(inv); + } +}; + + +///////////////////////////////////////////////////////////////////////////////////////////// + + template <typename R, typename P1, typename P2> -class ChainableMockMethod2 : public ChainableMockMethodBase<R> +class ChainableMockMethod2Base : public ChainableMockMethodBase<R> { public: @@ -120,18 +165,12 @@ * @param name human readable description about the expectation * @param parent parent chainable mock object */ - ChainableMockMethod2(const String &name, ChainableMockObject *parent = 0) + ChainableMockMethod2Base(const String &name, ChainableMockObject *parent = 0) : ChainableMockMethodBase<R>(name, parent) , coremock(MOCKPP_PCHAR("CoreMock_in_") + name, this) {} - R forward(P1 param1, P2 param2) const - { - InvocationType inv(MOCKPP_PCHAR("name"), param1, param2); - return coremock.invoke(inv); - } - - CoreMockType & getCoreMock() + CoreMockType & getCoreMock() const { return coremock; } @@ -142,7 +181,7 @@ { public: - ChainerFor(ChainableMockObject &obj, ChainableMockMethod2 &method) + ChainerFor(ChainableMockObject &obj, ChainableMockMethod2Base &method) : Builder(&method.getCoreMock(), &obj, method.getMethodName()) {} }; @@ -153,6 +192,52 @@ }; +template <typename R, typename P1, typename P2> +class ChainableMockMethod2 : public ChainableMockMethod2Base<R, P1, P2> +{ + public: + + typedef typename ChainableMockMethod2Base<void, P1, P2>::InvocationType InvocationType; + + /** Constructs the mock object. + * @param name human readable description about the expectation + * @param parent parent chainable mock object + */ + ChainableMockMethod2(const String &name, ChainableMockObject *parent = 0) + : ChainableMockMethod2Base<R, P1, P2>(name, parent) + {} + + R forward(P1 param1, P2 param2) const + { + InvocationType inv(getMethodName(), param1, param2); + return getCoreMock().invoke(inv); + } +}; + + +template <typename P1, typename P2> +class ChainableMockMethod2<void, P1, P2> : public ChainableMockMethod2Base<void, P1, P2> +{ + public: + + typedef typename ChainableMockMethod2Base<void, P1, P2>::InvocationType InvocationType; + + /** Constructs the mock object. + * @param name human readable description about the expectation + * @param parent parent chainable mock object + */ + ChainableMockMethod2(const String &name, ChainableMockObject *parent = 0) + : ChainableMockMethod2Base<void, P1, P2>(name, parent) + {} + + void forward(P1 param1, P2 param2) const + { + InvocationType inv(getMethodName(), param1, param2); + getCoreMock().invoke(inv); + } +}; + + } // namespace mockpp |