From b01784ab0881e7c2925d20150b72949cdf9bcf6a Mon Sep 17 00:00:00 2001 From: "stoyan@google.com" Date: Mon, 19 Oct 2009 16:11:24 +0000 Subject: Simplification, generalization (and perhaps additional mystification) of gmock helpers. Leak fixed - when gmock call is not satisfied, the callback that was set was leaked. Suggestion for better names here and there are very welcome (though MF seems nice to me). TEST=mocked tests runs Review URL: http://codereview.chromium.org/285007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29402 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome_frame/test/chrome_frame_unittests.cc | 31 +- chrome_frame/test/helper_gmock.h | 924 ++++++++++++++-------------- 2 files changed, 495 insertions(+), 460 deletions(-) (limited to 'chrome_frame') diff --git a/chrome_frame/test/chrome_frame_unittests.cc b/chrome_frame/test/chrome_frame_unittests.cc index 8e1ad92..ed8f71d 100644 --- a/chrome_frame/test/chrome_frame_unittests.cc +++ b/chrome_frame/test/chrome_frame_unittests.cc @@ -1026,8 +1026,8 @@ template <> struct RunnableMethodTraits { // Saves typing. It's somewhat hard to create a wrapper around // testing::InvokeWithoutArgs since it returns a // non-public (testing::internal) type. -#define QUIT_LOOP(loop) testing::InvokeWithoutArgs(TaskHolder(\ - NewRunnableMethod(&loop, &TimedMsgLoop::Quit))) +#define QUIT_LOOP(loop) testing::InvokeWithoutArgs(\ + CreateFunctor(&loop, &TimedMsgLoop::Quit)) // We mock ChromeFrameDelegate only. The rest is with real AutomationProxy TEST(CFACWithChrome, CreateTooFast) { @@ -1099,7 +1099,7 @@ TEST(CFACWithChrome, NavigateOk) { client.reset(new ChromeFrameAutomationClient); EXPECT_CALL(cfd, OnAutomationServerReady()) - .WillOnce(testing::InvokeWithoutArgs(TaskHolder(NewRunnableMethod( + .WillOnce(testing::IgnoreResult(testing::InvokeWithoutArgs(CreateFunctor( client.get(), &ChromeFrameAutomationClient::InitiateNavigation, url, false)))); @@ -1139,7 +1139,7 @@ TEST(CFACWithChrome, DISABLED_NavigateFailed) { client.reset(new ChromeFrameAutomationClient); EXPECT_CALL(cfd, OnAutomationServerReady()) - .WillOnce(testing::InvokeWithoutArgs(TaskHolder(NewRunnableMethod( + .WillOnce(testing::IgnoreResult(testing::InvokeWithoutArgs(CreateFunctor( client.get(), &ChromeFrameAutomationClient::InitiateNavigation, url, false)))); @@ -1197,7 +1197,7 @@ TEST(CFACWithChrome, UseHostNetworkStack) { cfd.SetAutomationSender(client.get()); EXPECT_CALL(cfd, OnAutomationServerReady()) - .WillOnce(testing::InvokeWithoutArgs(TaskHolder(NewRunnableMethod( + .WillOnce(testing::IgnoreResult(testing::InvokeWithoutArgs(CreateFunctor( client.get(), &ChromeFrameAutomationClient::InitiateNavigation, url, false)))); @@ -1219,16 +1219,18 @@ TEST(CFACWithChrome, UseHostNetworkStack) { EXPECT_CALL(cfd, OnRequestStart(tab_id, request_id, EqUrlGet(url + '/'))) .Times(1) - .WillOnce(testing::Invoke(CBF(&cfd, &MockCFDelegate::ReplyStarted, - &found))); + .WillOnce(testing::Invoke(CreateFunctor(&cfd, + &MockCFDelegate::ReplyStarted, + &found))); // Return some trivial page, that have a link to a "logo.gif" image const std::string data = "Hello" ""; EXPECT_CALL(cfd, OnRequestRead(tab_id, request_id, testing::Ge(0))) .Times(2) - .WillOnce(testing::Invoke(CBF(&cfd, &MockCFDelegate::ReplyData, &data))) - .WillOnce(testing::WithArgs<0, 1>(testing::Invoke(CBF(&cfd, + .WillOnce(testing::Invoke(CreateFunctor(&cfd, &MockCFDelegate::ReplyData, + &data))) + .WillOnce(testing::WithArgs<0, 1>(testing::Invoke(CreateFunctor(&cfd, &MockCFDelegate::ReplyEOF)))); EXPECT_CALL(cfd, OnDidNavigate(tab_id, EqNavigationInfoUrl(GURL(url)))) @@ -1241,7 +1243,8 @@ TEST(CFACWithChrome, UseHostNetworkStack) { EXPECT_CALL(cfd, OnRequestStart(tab_id, request_id, EqUrlGet(url + "/logo.gif"))) .Times(1) - .WillOnce(testing::Invoke(CBF(&cfd, &MockCFDelegate::Reply404))); + .WillOnce(testing::Invoke(CreateFunctor(&cfd, + &MockCFDelegate::Reply404))); EXPECT_CALL(cfd, OnRequestRead(tab_id, request_id, testing::_)) .Times(testing::AtMost(1)); @@ -1251,7 +1254,8 @@ TEST(CFACWithChrome, UseHostNetworkStack) { EXPECT_CALL(cfd, OnRequestStart(tab_id, request_id, EqUrlGet(url + "/favicon.ico"))) .Times(1) - .WillOnce(testing::Invoke(CBF(&cfd, &MockCFDelegate::Reply404))); + .WillOnce(testing::Invoke(CreateFunctor(&cfd, + &MockCFDelegate::Reply404))); EXPECT_CALL(cfd, OnRequestRead(tab_id, request_id, testing::_)) .Times(testing::AtMost(1)); @@ -1315,8 +1319,9 @@ class CFACMockTest : public testing::Test { .Times(1) .WillOnce(testing::DoAll( testing::WithArgs<0, 4>( - testing::Invoke(CBF(&factory_, &MockProxyFactory::GetServerImpl, - get_proxy(), AUTOMATION_SUCCESS))), + testing::Invoke(CreateFunctor(&factory_, + &MockProxyFactory::GetServerImpl, + get_proxy(), AUTOMATION_SUCCESS))), testing::Return(id_))); EXPECT_CALL(factory_, ReleaseAutomationServer(testing::Eq(id_))).Times(1); diff --git a/chrome_frame/test/helper_gmock.h b/chrome_frame/test/helper_gmock.h index 7f6d0a7..2475186 100644 --- a/chrome_frame/test/helper_gmock.h +++ b/chrome_frame/test/helper_gmock.h @@ -3,595 +3,625 @@ // found in the LICENSE file. #ifndef CHROME_FRAME_TEST_HELPER_GMOCK_H_ #define CHROME_FRAME_TEST_HELPER_GMOCK_H_ -// This intention of this file is to make possible gmock WithArgs<> in -// Chromium code base. -// MutantImpl is like CallbackImpl, but also has prebound arguments (like Task) -// There is also functor wrapper around it that should be used with -// testing::Invoke, for example: -// testing::WithArgs<0, 2>( -// testing::Invoke(CBF(&mock_object, &MockObject::Something, &tmp_obj, 12))); -// This will invoke MockObject::Something(tmp_obj, 12, arg_0, arg_2) - +// The intention of this file is to make possible using GMock actions in +// all of its syntactic beauty. Classes and helper functions could be used as +// more generic variants of Task and Callback classes (see base/task.h) +// Mutant supports both pre-bound arguments (like Task) and call-time arguments +// (like Callback) - hence the name. :-) // DispatchToMethod supporting two sets of arguments - -// prebound (P) and calltime (C) -// 1 - 1 -template -inline void DispatchToMethod(ObjT* obj, Method method, - const Tuple1& p, - const Tuple1& c) { - (obj->*method)(p.a, c.a); -} -// 2 - 1 -template -inline void DispatchToMethod(ObjT* obj, Method method, - const Tuple2& p, - const Tuple1& c) { - (obj->*method)(p.a, p.b, c.a); -} -// 3 - 1 -template -inline void DispatchToMethod(ObjT* obj, Method method, - const Tuple3& p, - const Tuple1& c) { - (obj->*method)(p.a, p.b, p.c, c.a); -} -// 4 - 1 -template -inline void DispatchToMethod(ObjT* obj, Method method, - const Tuple4& p, - const Tuple1& c) { - (obj->*method)(p.a, p.b, p.c, p.d, c.a); -} +// pre-bound (P) and call-time (C) as well as return value type is templatized +// It will also try to call the selected method even if provided pre-bound args +// does not match exactly with the function signature - hence the X1, X2 +// parameters in CreateFunctor. -// 1 - 2 -template -inline void DispatchToMethod(ObjT* obj, Method method, - const Tuple1& p, - const Tuple2& c) { - (obj->*method)(p.a, c.a, c.b); -} +#include "base/linked_ptr.h" +#include "base/task.h" // for CallBackStorage +#include "base/tuple.h" // for Tuple -// 2 - 2 -template -inline void DispatchToMethod(ObjT* obj, Method method, - const Tuple2& p, - const Tuple2& c) { - (obj->*method)(p.a, p.b, c.a, c.b); -} -// 3 - 2 -template -inline void DispatchToMethod(ObjT* obj, Method method, - const Tuple3& p, - const Tuple2& c) { - (obj->*method)(p.a, p.b, p.c, c.a, c.b); -} - -// 4 - 2 -template -inline void DispatchToMethod(ObjT* obj, Method method, - const Tuple4& p, - const Tuple2& c) { - (obj->*method)(p.a, p.b, p.c, p.d, c.a, c.b); -} - -// 1 - 3 -template -inline void DispatchToMethod(ObjT* obj, Method method, - const Tuple1& p, - const Tuple3& c) { - (obj->*method)(p.a, c.a, c.b, c.c); -} - -// 2 - 3 -template -inline void DispatchToMethod(ObjT* obj, Method method, - const Tuple2& p, - const Tuple3& c) { - (obj->*method)(p.a, p.b, c.a, c.b, c.c); +// 0 - 0 +template +inline R DispatchToMethod(T* obj, Method method, + const Tuple0& p, + const Tuple0& c) { + return (obj->*method)(); } -// 3 - 3 -template -inline void DispatchToMethod(ObjT* obj, Method method, - const Tuple3& p, - const Tuple3& c) { - (obj->*method)(p.a, p.b, p.c, c.a, c.b, c.c); -} - -// 4 - 3 -template -inline void DispatchToMethod(ObjT* obj, Method method, - const Tuple4& p, - const Tuple3& c) { - (obj->*method)(p.a, p.b, p.c, p.d, c.a, c.b, c.c); +// 0 - 1 +template +inline R DispatchToMethod(T* obj, Method method, + const Tuple0& p, + const Tuple1& c) { + return (obj->*method)(c.a); } -// 1 - 4 -template -inline void DispatchToMethod(ObjT* obj, Method method, - const Tuple1& p, - const Tuple4& c) { - (obj->*method)(p.a, c.a, c.b, c.c, c.d); +// 0 - 2 +template +inline R DispatchToMethod(T* obj, Method method, + const Tuple0& p, + const Tuple2& c) { + return (obj->*method)(c.a, c.b); } -// 2 - 4 -template -inline void DispatchToMethod(ObjT* obj, Method method, - const Tuple2& p, - const Tuple4& c) { - (obj->*method)(p.a, p.b, c.a, c.b, c.c, c.d); +// 0 - 3 +template +inline R DispatchToMethod(T* obj, Method method, + const Tuple0& p, + const Tuple3& c) { + return (obj->*method)(c.a, c.b, c.c); } -// 3 - 4 -template -inline void DispatchToMethod(ObjT* obj, Method method, - const Tuple3& p, - const Tuple4& c) { - (obj->*method)(p.a, p.b, p.c, c.a, c.b, c.c, c.d); +// 0 - 4 +template +inline R DispatchToMethod(T* obj, Method method, + const Tuple0& p, + const Tuple4& c) { + return (obj->*method)(c.a, c.b, c.c, c.d); } -// 4 - 4 -template -inline void DispatchToMethod(ObjT* obj, Method method, - const Tuple4& p, - const Tuple4& c) { - (obj->*method)(p.a, p.b, p.c, p.d, c.a, c.b, c.c, c.d); +// 1 - 0 +template +inline R DispatchToMethod(T* obj, Method method, + const Tuple1& p, + const Tuple0& c) { + return (obj->*method)(p.a); } - -//////////////////////////////////////////////////////////////////////////////// - -// Like CallbackImpl but has prebound arguments (like Task) -template -class MutantImpl : public CallbackStorage, - public CallbackRunner { - public: - MutantImpl(T* obj, Method meth, const PreBound& pb) - : CallbackStorage(obj, meth), - pb_(pb) { - } - - virtual void RunWithParams(const Params& params) { - // use "this->" to force C++ to look inside our templatized base class; see - // Effective C++, 3rd Ed, item 43, p210 for details. - DispatchToMethod(this->obj_, this->meth_, pb_, params); - } - - PreBound pb_; -}; - -//////////////////////////////////////////////////////////////////////////////// -// Mutant creation simplification // 1 - 1 -template -inline typename Callback1::Type* NewMutant(T* obj, - void (T::*method)(P1, A1), - P1 p1) { - return new MutantImpl(obj, method, - MakeTuple(p1)); +template +inline R DispatchToMethod(T* obj, Method method, + const Tuple1& p, + const Tuple1& c) { + return (obj->*method)(p.a, c.a); } // 1 - 2 -template -inline typename Callback2::Type* NewMutant(T* obj, - void (T::*method)(P1, A1, A2), - P1 p1) { - return new MutantImpl, Tuple2 > - (obj, method, MakeTuple(p1)); +template +inline R DispatchToMethod(T* obj, Method method, + const Tuple1& p, + const Tuple2& c) { + return (obj->*method)(p.a, c.a, c.b); } // 1 - 3 -template -inline typename Callback3::Type* -NewMutant(T* obj, void (T::*method)(P1, A1, A2, A3), P1 p1) { - return new MutantImpl, - Tuple3 >(obj, method, MakeTuple(p1)); +template +inline R DispatchToMethod(T* obj, Method method, + const Tuple1& p, + const Tuple3& c) { + return (obj->*method)(p.a, c.a, c.b, c.c); } // 1 - 4 -template -inline typename Callback4::Type* -NewMutant(T* obj, void (T::*method)(P1, A1, A2, A3, A4), P1 p1) { - return new MutantImpl, - Tuple4 >(obj, method, MakeTuple(p1)); +template +inline R DispatchToMethod(T* obj, Method method, + const Tuple1& p, + const Tuple4& c) { + return (obj->*method)(p.a, c.a, c.b, c.c, c.d); } +// 2 - 0 +template +inline R DispatchToMethod(T* obj, Method method, + const Tuple2& p, + const Tuple0& c) { + return (obj->*method)(p.a, p.b); +} // 2 - 1 -template -inline typename Callback1::Type* -NewMutant(T* obj, void (T::*method)(P1, P2, A1), P1 p1, P2 p2) { - return new MutantImpl, - Tuple1 >(obj, method, MakeTuple(p1, p2)); +template +inline R DispatchToMethod(T* obj, Method method, + const Tuple2& p, + const Tuple1& c) { + return (obj->*method)(p.a, p.b, c.a); } // 2 - 2 -template -inline typename Callback2::Type* -NewMutant(T* obj, void (T::*method)(P1, P2, A1, A2), P1 p1, P2 p2) { - return new MutantImpl, - Tuple2 >(obj, method, MakeTuple(p1, p2)); +template +inline R DispatchToMethod(T* obj, Method method, + const Tuple2& p, + const Tuple2& c) { + return (obj->*method)(p.a, p.b, c.a, c.b); } // 2 - 3 -template -inline typename Callback3::Type* -NewMutant(T* obj, void (T::*method)(P1, P2, A1, A2, A3), P1 p1, P2 p2) { - return new MutantImpl, - Tuple3 >(obj, method, MakeTuple(p1, p2)); +template +inline R DispatchToMethod(T* obj, Method method, + const Tuple2& p, + const Tuple3& c) { + return (obj->*method)(p.a, p.b, c.a, c.b, c.c); } // 2 - 4 -template -inline typename Callback4::Type* -NewMutant(T* obj, void (T::*method)(P1, P2, A1, A2, A3, A4), P1 p1, P2 p2) { - return new MutantImpl, - Tuple3 >(obj, method, MakeTuple(p1, p2)); +template +inline R DispatchToMethod(T* obj, Method method, + const Tuple2& p, + const Tuple4& c) { + return (obj->*method)(p.a, p.b, c.a, c.b, c.c, c.d); +} + +// 3 - 0 +template +inline R DispatchToMethod(T* obj, Method method, + const Tuple3& p, + const Tuple0& c) { + return (obj->*method)(p.a, p.b, p.c); } // 3 - 1 -template -inline typename Callback1::Type* -NewMutant(T* obj, void (T::*method)(P1, P2, P3, A1), P1 p1, P2 p2, P3 p3) { - return new MutantImpl, - Tuple1 >(obj, method, MakeTuple(p1, p2, p3)); +template +inline R DispatchToMethod(T* obj, Method method, + const Tuple3& p, + const Tuple1& c) { + return (obj->*method)(p.a, p.b, p.c, c.a); } // 3 - 2 -template -inline typename Callback2::Type* -NewMutant(T* obj, void (T::*method)(P1, P2, P3, A1, A2), P1 p1, P2 p2, P3 p3) { - return new MutantImpl, - Tuple2 >(obj, method, MakeTuple(p1, p2, p3)); +template +inline R DispatchToMethod(T* obj, Method method, + const Tuple3& p, + const Tuple2& c) { + return (obj->*method)(p.a, p.b, p.c, c.a, c.b); } // 3 - 3 -template -inline typename Callback3::Type* -NewMutant(T* obj, void (T::*method)(P1, P2, P3, A1, A2, A3), P1 p1, P2 p2, - P3 p3) { - return new MutantImpl, Tuple3 >(obj, method, - MakeTuple(p1, p2, p3)); +template +inline R DispatchToMethod(T* obj, Method method, + const Tuple3& p, + const Tuple3& c) { + return (obj->*method)(p.a, p.b, p.c, c.a, c.b, c.c); } // 3 - 4 -template -inline typename Callback4::Type* -NewMutant(T* obj, void (T::*method)(P1, P2, P3, A1, A2, A3, A4), P1 p1, P2 p2, - P3 p3) { - return new MutantImpl, Tuple3 >(obj, method, - MakeTuple(p1, p2, p3)); +template +inline R DispatchToMethod(T* obj, Method method, + const Tuple3& p, + const Tuple4& c) { + return (obj->*method)(p.a, p.b, p.c, c.a, c.b, c.c, c.d); +} + +// 4 - 0 +template +inline R DispatchToMethod(T* obj, Method method, + const Tuple4& p, + const Tuple0& c) { + return (obj->*method)(p.a, p.b, p.c, p.d); } // 4 - 1 -template -inline typename Callback1::Type* -NewMutant(T* obj, void (T::*method)(P1, P2, P3, P4, A1), P1 p1, P2 p2, P3 p3, - P4 p4) { - return new MutantImpl, Tuple1 >(obj, method, - MakeTuple(p1, p2, p3, p4)); +template +inline R DispatchToMethod(T* obj, Method method, + const Tuple4& p, + const Tuple1& c) { + return (obj->*method)(p.a, p.b, p.c, p.d, c.a); } // 4 - 2 -template -inline typename Callback2::Type* -NewMutant(T* obj, void (T::*method)(P1, P2, P3, P4, A1, A2), P1 p1, P2 p2, - P3 p3, P4 p4) { - return new MutantImpl, Tuple2 >(obj, method, - MakeTuple(p1, p2, p3, p4)); +template +inline R DispatchToMethod(T* obj, Method method, + const Tuple4& p, + const Tuple2& c) { + return (obj->*method)(p.a, p.b, p.c, p.d, c.a, c.b); } // 4 - 3 -template -inline typename Callback3::Type* -NewMutant(T* obj, void (T::*method)(P1, P2, P3, P4, A1, A2, A3), P1 p1, P2 p2, - P3 p3, P4 p4) { - return new MutantImpl, Tuple3 >(obj, method, - MakeTuple(p1, p2, p3, p4)); +template +inline R DispatchToMethod(T* obj, Method method, + const Tuple4& p, + const Tuple3& c) { + return (obj->*method)(p.a, p.b, p.c, p.d, c.a, c.b, c.c); } // 4 - 4 -template -inline typename Callback4::Type* -NewMutant(T* obj, void (T::*method)(P1, P2, P3, P4, A1, A2, A3, A4), - P1 p1, P2 p2, P3 p3, P4 p4) { - return new MutantImpl, Tuple3 >(obj, method, - MakeTuple(p1, p2, p3, p4)); -} - -//////////////////////////////////////////////////////////////////////////////// -// Simple callback wrapper acting as a functor. -// Redirects operator() to CallbackRunner::Run -// We cannot delete the inner impl_ in object's destructor because -// this object is copied few times inside from GMock machinery. -template -struct CallbackFunctor { - explicit CallbackFunctor(CallbackRunner* cb) : impl_(cb) {} +template +inline R DispatchToMethod(T* obj, Method method, + const Tuple4& p, + const Tuple4& c) { + return (obj->*method)(p.a, p.b, p.c, p.d, c.a, c.b, c.c, c.d); +} + +// Interface that is exposed to the consumer, that does the actual calling +// of the method. +template +class MutantRunner { + public: + virtual R RunWithParams(const Params& params) = 0; + virtual ~MutantRunner() {} +}; + +// MutantImpl holds pre-bound arguments (like Task) and like Callback +// allows call-time arguments. +template +class MutantImpl : public CallbackStorage, + public MutantRunner { + public: + MutantImpl(T* obj, Method meth, const PreBound& pb) + : CallbackStorage(obj, meth), + pb_(pb) { + } + + // MutantRunner implementation + virtual R RunWithParams(const Params& params) { + return DispatchToMethod(this->obj_, this->meth_, pb_, params); + } + + PreBound pb_; +}; + +// Simple MutantRunner<> wrapper acting as a functor. +// Redirects operator() to MutantRunner::Run() +template +struct MutantFunctor { + explicit MutantFunctor(MutantRunner* cb) : impl_(cb) { + } + + ~MutantFunctor() { + } + + inline R operator()() { + return impl_->RunWithParams(Tuple0()); + } template - inline void operator()(const Arg1& a) { - impl_->Run(a); - delete impl_; - impl_ = NULL; + inline R operator()(const Arg1& a) { + return impl_->RunWithParams(Params(a)); } template - inline void operator()(const Arg1& a, const Arg2& b) { - impl_->Run(a, b); - delete impl_; - impl_ = NULL; + inline R operator()(const Arg1& a, const Arg2& b) { + return impl_->RunWithParams(Params(a, b)); } template - inline void operator()(const Arg1& a, const Arg2& b, const Arg3& c) { - impl_->Run(a, b, c); - delete impl_; - impl_ = NULL; + inline R operator()(const Arg1& a, const Arg2& b, const Arg3& c) { + return impl_->RunWithParams(Params(a, b, c)); } template - inline void operator()(const Arg1& a, const Arg2& b, const Arg3& c, + inline R operator()(const Arg1& a, const Arg2& b, const Arg3& c, const Arg4& d) { - impl_->Run(a, b, c, d); - delete impl_; - impl_ = NULL; + return impl_->RunWithParams(Params(a, b, c, d)); } private: - CallbackFunctor(); - CallbackRunner* impl_; + // We need copy constructor since MutantFunctor is copied few times + // inside GMock machinery, hence no DISALLOW_EVIL_CONTRUCTORS + MutantFunctor(); + linked_ptr > impl_; }; -/////////////////////////////////////////////////////////////////////////////// -// CallbackFunctors creation + +// 0 - 0 +template +inline MutantFunctor +CreateFunctor(T* obj, R (T::*method)()) { + MutantRunner *t = new MutantImpl + (obj, method, MakeTuple()); + return MutantFunctor(t); +} // 0 - 1 -template -inline CallbackFunctor > -CBF(T* obj, void (T::*method)(A1)) { - return CallbackFunctor >(NewCallback(obj, method)); +template +inline MutantFunctor > +CreateFunctor(T* obj, R (T::*method)(A1)) { + MutantRunner > *t = new MutantImpl > + (obj, method, MakeTuple()); + return MutantFunctor >(t); } // 0 - 2 -template -inline CallbackFunctor > -CBF(T* obj, void (T::*method)(A1, A2)) { - return CallbackFunctor >(NewCallback(obj, method)); +template +inline MutantFunctor > +CreateFunctor(T* obj, R (T::*method)(A1, A2)) { + MutantRunner > *t = new MutantImpl > + (obj, method, MakeTuple()); + return MutantFunctor >(t); } // 0 - 3 -template -inline CallbackFunctor > -CBF(T* obj, void (T::*method)(A1, A2, A3)) { - return CallbackFunctor >(NewCallback(obj, method)); +template +inline MutantFunctor > +CreateFunctor(T* obj, R (T::*method)(A1, A2, A3)) { + MutantRunner > *t = new MutantImpl > + (obj, method, MakeTuple()); + return MutantFunctor >(t); } // 0 - 4 -template -inline CallbackFunctor > -CBF(T* obj, void (T::*method)(A1, A2, A3, A4)) { - return CallbackFunctor >(NewCallback(obj, method)); +template +inline MutantFunctor > +CreateFunctor(T* obj, R (T::*method)(A1, A2, A3, A4)) { + MutantRunner > *t = new MutantImpl > + (obj, method, MakeTuple()); + return MutantFunctor >(t); +} + +// 1 - 0 +template +inline MutantFunctor +CreateFunctor(T* obj, R (T::*method)(X1), const P1& p1) { + MutantRunner *t = new MutantImpl, Tuple0> + (obj, method, MakeTuple(p1)); + return MutantFunctor(t); } // 1 - 1 -template -inline CallbackFunctor > -CBF(T* obj, void (T::*method)(P1, A1), P1 p1) { - Callback1::Type* t = new MutantImpl, - Tuple1 >(obj, method, MakeTuple(p1)); - return CallbackFunctor >(t); +template +inline MutantFunctor > +CreateFunctor(T* obj, R (T::*method)(X1, A1), const P1& p1) { + MutantRunner > *t = new MutantImpl, Tuple1 > + (obj, method, MakeTuple(p1)); + return MutantFunctor >(t); } // 1 - 2 -template -inline CallbackFunctor > -CBF(T* obj, void (T::*method)(P1, A1, A2), P1 p1) { - Callback2::Type* t = new MutantImpl, Tuple2 >(obj, method, MakeTuple(p1)); - return CallbackFunctor >(t); +template +inline MutantFunctor > +CreateFunctor(T* obj, R (T::*method)(X1, A1, A2), const P1& p1) { + MutantRunner > *t = new MutantImpl, Tuple2 > + (obj, method, MakeTuple(p1)); + return MutantFunctor >(t); } // 1 - 3 -template -inline CallbackFunctor > -CBF(T* obj, void (T::*method)(P1, A1, A2, A3), P1 p1) { - Callback3::Type* t = - new MutantImpl, - Tuple3 >(obj, method, MakeTuple(p1)); - return CallbackFunctor >(t); +template +inline MutantFunctor > +CreateFunctor(T* obj, R (T::*method)(X1, A1, A2, A3), const P1& p1) { + MutantRunner > *t = new MutantImpl, Tuple3 > + (obj, method, MakeTuple(p1)); + return MutantFunctor >(t); } // 1 - 4 -template -inline CallbackFunctor > -CBF(T* obj, void (T::*method)(P1, A1, A2, A3, A4), P1 p1) { - Callback4::Type* t = - new MutantImpl, - Tuple4 >(obj, method, MakeTuple(p1)); - return CallbackFunctor >(t); +template +inline MutantFunctor > +CreateFunctor(T* obj, R (T::*method)(X1, A1, A2, A3, A4), const P1& p1) { + MutantRunner > *t = new MutantImpl, Tuple4 > + (obj, method, MakeTuple(p1)); + return MutantFunctor >(t); +} + +// 2 - 0 +template +inline MutantFunctor +CreateFunctor(T* obj, R (T::*method)(X1, X2), const P1& p1, const P2& p2) { + MutantRunner *t = new MutantImpl, Tuple0> + (obj, method, MakeTuple(p1, p2)); + return MutantFunctor(t); } // 2 - 1 -template -inline CallbackFunctor > -CBF(T* obj, void (T::*method)(P1, P2, A1), P1 p1, P2 p2) { - Callback1::Type* t = new MutantImpl, Tuple1 >(obj, method, MakeTuple(p1, p2)); - return CallbackFunctor >(t); +template +inline MutantFunctor > +CreateFunctor(T* obj, R (T::*method)(X1, X2, A1), const P1& p1, const P2& p2) { + MutantRunner > *t = new MutantImpl, Tuple1 > + (obj, method, MakeTuple(p1, p2)); + return MutantFunctor >(t); } // 2 - 2 -template -inline CallbackFunctor > -CBF(T* obj, void (T::*method)(P1, P2, A1, A2), P1 p1, P2 p2) { - Callback2::Type* t = new MutantImpl, Tuple2 >(obj, method, MakeTuple(p1, p2)); - return CallbackFunctor >(t); +template +inline MutantFunctor > +CreateFunctor(T* obj, R (T::*method)(X1, X2, A1, A2), const P1& p1, + const P2& p2) { + MutantRunner > *t = new MutantImpl, Tuple2 > + (obj, method, MakeTuple(p1, p2)); + return MutantFunctor >(t); } // 2 - 3 -template inline CallbackFunctor > -CBF(T* obj, void (T::*method)(P1, P2, A1, A2, A3), P1 p1, P2 p2) { - Callback3::Type* t = - new MutantImpl, - Tuple3 >(obj, method, MakeTuple(p1, p2)); - return CallbackFunctor >(t); +template +inline MutantFunctor > +CreateFunctor(T* obj, R (T::*method)(X1, X2, A1, A2, A3), const P1& p1, + const P2& p2) { + MutantRunner > *t = new MutantImpl, Tuple3 > + (obj, method, MakeTuple(p1, p2)); + return MutantFunctor >(t); } // 2 - 4 -template -inline CallbackFunctor > -CBF(T* obj, void (T::*method)(P1, P2, A1, A2, A3, A4), P1 p1, P2 p2) { - Callback4::Type* t = - new MutantImpl, - Tuple4 >(obj, method, MakeTuple(p1, p2)); - return CallbackFunctor >(t); +template +inline MutantFunctor > +CreateFunctor(T* obj, R (T::*method)(X1, X2, A1, A2, A3, A4), const P1& p1, + const P2& p2) { + MutantRunner > *t = new MutantImpl, Tuple4 > + (obj, method, MakeTuple(p1, p2)); + return MutantFunctor >(t); +} + +// 3 - 0 +template +inline MutantFunctor +CreateFunctor(T* obj, R (T::*method)(X1, X2, X3), const P1& p1, const P2& p2, + const P3& p3) { + MutantRunner *t = new MutantImpl, Tuple0> + (obj, method, MakeTuple(p1, p2, p3)); + return MutantFunctor(t); } - // 3 - 1 -template -inline CallbackFunctor > -CBF(T* obj, void (T::*method)(P1, P2, P3, A1), P1 p1, P2 p2, P3 p3) { - Callback1::Type* t = new MutantImpl, Tuple1 >(obj, method, MakeTuple(p1, p2, p3)); - return CallbackFunctor >(t); +template +inline MutantFunctor > +CreateFunctor(T* obj, R (T::*method)(X1, X2, X3, A1), const P1& p1, + const P2& p2, const P3& p3) { + MutantRunner > *t = new MutantImpl, Tuple1 > + (obj, method, MakeTuple(p1, p2, p3)); + return MutantFunctor >(t); } - // 3 - 2 -template inline CallbackFunctor > -CBF(T* obj, void (T::*method)(P1, P2, P3, A1, A2), P1 p1, P2 p2, P3 p3) { - Callback2::Type* t = - new MutantImpl, - Tuple2 >(obj, method, MakeTuple(p1, p2, p3)); - return CallbackFunctor >(t); +template +inline MutantFunctor > +CreateFunctor(T* obj, R (T::*method)(X1, X2, X3, A1, A2), const P1& p1, + const P2& p2, const P3& p3) { + MutantRunner > *t = new MutantImpl, Tuple2 > + (obj, method, MakeTuple(p1, p2, p3)); + return MutantFunctor >(t); } // 3 - 3 -template -inline CallbackFunctor > -CBF(T* obj, void (T::*method)(P1, P2, P3, A1, A2, A3), P1 p1, P2 p2, P3 p3) { - Callback3::Type* t = - new MutantImpl, - Tuple3 >(obj, method, MakeTuple(p1, p2, p3)); - return CallbackFunctor >(t); +template +inline MutantFunctor > +CreateFunctor(T* obj, R (T::*method)(X1, X2, X3, A1, A2, A3), const P1& p1, + const P2& p2, const P3& p3) { + MutantRunner > *t = new MutantImpl, Tuple3 > + (obj, method, MakeTuple(p1, p2, p3)); + return MutantFunctor >(t); } // 3 - 4 -template -inline CallbackFunctor > -CBF(T* obj, void (T::*method)(P1, P2, P3, A1, A2, A3, A4), - P1 p1, P2 p2, P3 p3) { - Callback4::Type* t = - new MutantImpl, Tuple4 >(obj, method, - MakeTuple(p1, p2, p3)); - return CallbackFunctor >(t); +template +inline MutantFunctor > +CreateFunctor(T* obj, R (T::*method)(X1, X2, X3, A1, A2, A3, A4), const P1& p1, + const P2& p2, const P3& p3) { + MutantRunner > *t = new MutantImpl, Tuple4 > + (obj, method, MakeTuple(p1, p2, p3)); + return MutantFunctor >(t); +} + +// 4 - 0 +template +inline MutantFunctor +CreateFunctor(T* obj, R (T::*method)(X1, X2, X3, X4), const P1& p1, + const P2& p2, const P3& p3, const P4& p4) { + MutantRunner *t = new MutantImpl, Tuple0> + (obj, method, MakeTuple(p1, p2, p3, p4)); + return MutantFunctor(t); } - - // 4 - 1 -template -inline CallbackFunctor > -CBF(T* obj, void (T::*method)(P1, P2, P3, P4, A1), P1 p1, P2 p2, P3 p3, P4 p4) { - Callback1::Type* t = new MutantImpl +inline MutantFunctor > +CreateFunctor(T* obj, R (T::*method)(X1, X2, X3, X4, A1), const P1& p1, + const P2& p2, const P3& p3, const P4& p4) { + MutantRunner > *t = new MutantImpl, Tuple1 > (obj, method, MakeTuple(p1, p2, p3, p4)); - return CallbackFunctor >(t); + return MutantFunctor >(t); } - // 4 - 2 -template -inline CallbackFunctor > -CBF(T* obj, void (T::*method)(P1, P2, P3, P4, A1, A2), - P1 p1, P2 p2, P3 p3, P4 p4) { - Callback2::Type* t = - new MutantImpl, - Tuple2 >(obj, method, MakeTuple(p1, p2, p3, p4)); - return CallbackFunctor >(t); +template +inline MutantFunctor > +CreateFunctor(T* obj, R (T::*method)(X1, X2, X3, X4, A1, A2), const P1& p1, + const P2& p2, const P3& p3, const P4& p4) { + MutantRunner > *t = new MutantImpl, Tuple2 > + (obj, method, MakeTuple(p1, p2, p3, p4)); + return MutantFunctor >(t); } // 4 - 3 -template -inline CallbackFunctor > -CBF(T* obj, void (T::*method)(P1, P2, P3, P4, A1, A2, A3), - P1 p1, P2 p2, P3 p3, P4 p4) { - Callback3::Type* t = - new MutantImpl +inline MutantFunctor > +CreateFunctor(T* obj, R (T::*method)(X1, X2, X3, X4, A1, A2, A3), const P1& p1, + const P2& p2, const P3& p3, const P4& p4) { + MutantRunner > *t = new MutantImpl, Tuple3 > (obj, method, MakeTuple(p1, p2, p3, p4)); - return CallbackFunctor >(t); + return MutantFunctor >(t); } // 4 - 4 -template -inline CallbackFunctor > -CBF(T* obj, void (T::*method)(P1, P2, P3, P4, A1, A2, A3, A4), - P1 p1, P2 p2, P3 p3, P4 p4) { - Callback4::Type* t = - new MutantImpl, Tuple4 >(obj, method, - MakeTuple(p1, p2, p3, p4)); - return CallbackFunctor >(t); -} - - -// Simple task wrapper acting as a functor. -// Redirects operator() to Task::Run. We cannot delete the inner impl_ object -// in object's destructor because this object is copied few times inside -// from GMock machinery. -struct TaskHolder { - explicit TaskHolder(Task* impl) : impl_(impl) {} - void operator()() { - impl_->Run(); - delete impl_; - impl_ = NULL; - } - private: - TaskHolder(); - Task* impl_; -}; - +template +inline MutantFunctor > +CreateFunctor(T* obj, R (T::*method)(X1, X2, X3, X4, A1, A2, A3, A4), + const P1& p1, const P2& p2, const P3& p3, const P4& p4) { + MutantRunner > *t = new MutantImpl, Tuple4 > + (obj, method, MakeTuple(p1, p2, p3, p4)); + return MutantFunctor >(t); +} #endif // CHROME_FRAME_TEST_HELPER_GMOCK_H_ -- cgit v1.1