/*** mockcpp is a generic C/C++ mock framework. Copyright (C) <2009> This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 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 General Public License along with this program. If not, see . ***/ #ifndef __MOCKCPP_CHAINABLE_MOCK_METHOD_H #define __MOCKCPP_CHAINABLE_MOCK_METHOD_H #include #include #include #include #include #include #include #include MOCKCPP_NS_START struct SelfDescribe; template struct ChainableMockMethodBase { ChainableMockMethodBase(Invokable* invokable_) : invokable(invokable_) {} RT operator()(const std::string& nameOfCaller , const RefAny& pThisPointer = RefAny() , const RefAny& p01 = RefAny() , const RefAny& p02 = RefAny() , const RefAny& p03 = RefAny() , const RefAny& p04 = RefAny() , const RefAny& p05 = RefAny() , const RefAny& p06 = RefAny() , const RefAny& p07 = RefAny() , const RefAny& p08 = RefAny() , const RefAny& p09 = RefAny() , const RefAny& p10 = RefAny() , const RefAny& p11 = RefAny() , const RefAny& p12 = RefAny() ) { SelfDescribe* resultProvider = 0; try { const Any& result = \ invokable->invoke(nameOfCaller, pThisPointer , p01, p02, p03, p04, p05, p06 , p07, p08, p09, p10, p11, p12 , resultProvider); return getResult(result, resultProvider); } catch (std::exception& ex) { MOCKCPP_REPORT_FAILURE(ex.what()); } const Any& dummyResult = Any(); return getResult(dummyResult, resultProvider); } virtual ~ChainableMockMethodBase() {} protected: virtual RT getResult(const Any& result, SelfDescribe*) = 0; private: Invokable* invokable; }; ////////////////////////////////////////////////////////////////// template struct ChainableMockMethod : public ChainableMockMethodBase { RT getResult(const Any& anyResult, SelfDescribe* resultProvider) { const Any& result = \ Result(any_castable(anyResult) , typeid(RT) , TypeString::value() , resultProvider).getResult(anyResult); MOCKCPP_ASSERT_FALSE_MESSAGE( "The return value for a non-void method was not specified", result.empty()); return any_cast(result); } public: ChainableMockMethod(Invokable* invokable) : ChainableMockMethodBase(invokable) {} }; ////////////////////////////////////////////////////////////////// template <> struct ChainableMockMethod : public ChainableMockMethodBase { void getResult(const Any& result, SelfDescribe*) { } public: ChainableMockMethod(Invokable* invokable) : ChainableMockMethodBase(invokable) {} }; ////////////////////////////////////////////////////////////////// MOCKCPP_NS_END #endif