OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 #ifndef CHROME_FRAME_TEST_HELPER_GMOCK_H_ |
| 5 #define CHROME_FRAME_TEST_HELPER_GMOCK_H_ |
| 6 // This intention of this file is to make possible gmock WithArgs<> in |
| 7 // Chromium code base. |
| 8 // MutantImpl is like CallbackImpl, but also has prebound arguments (like Task) |
| 9 // There is also functor wrapper around it that should be used with |
| 10 // testing::Invoke, for example: |
| 11 // testing::WithArgs<0, 2>( |
| 12 // testing::Invoke(CBF(&mock_object, &MockObject::Something, &tmp_obj, 12))); |
| 13 // This will invoke MockObject::Something(tmp_obj, 12, arg_0, arg_2) |
| 14 |
| 15 // DispatchToMethod supporting two sets of arguments - |
| 16 // prebound (P) and calltime (C) |
| 17 // 1 - 1 |
| 18 template <class ObjT, class Method, class P1, class C1> |
| 19 inline void DispatchToMethod(ObjT* obj, Method method, |
| 20 const Tuple1<P1>& p, |
| 21 const Tuple1<C1>& c) { |
| 22 (obj->*method)(p.a, c.a); |
| 23 } |
| 24 // 2 - 1 |
| 25 template <class ObjT, class Method, class P1, class P2, class C1> |
| 26 inline void DispatchToMethod(ObjT* obj, Method method, |
| 27 const Tuple2<P1, P2>& p, |
| 28 const Tuple1<C1>& c) { |
| 29 (obj->*method)(p.a, p.b, c.a); |
| 30 } |
| 31 // 3 - 1 |
| 32 template <class ObjT, class Method, class P1, class P2, class P3, class C1> |
| 33 inline void DispatchToMethod(ObjT* obj, Method method, |
| 34 const Tuple3<P1, P2, P3>& p, |
| 35 const Tuple1<C1>& c) { |
| 36 (obj->*method)(p.a, p.b, p.c, c.a); |
| 37 } |
| 38 // 4 - 1 |
| 39 template <class ObjT, class Method, class P1, class P2, class P3, |
| 40 class P4, class C1> |
| 41 inline void DispatchToMethod(ObjT* obj, Method method, |
| 42 const Tuple4<P1, P2, P3, P4>& p, |
| 43 const Tuple1<C1>& c) { |
| 44 (obj->*method)(p.a, p.b, p.c, p.d, c.a); |
| 45 } |
| 46 |
| 47 // 1 - 2 |
| 48 template <class ObjT, class Method, class P1, class C1, class C2> |
| 49 inline void DispatchToMethod(ObjT* obj, Method method, |
| 50 const Tuple1<P1>& p, |
| 51 const Tuple2<C1, C2>& c) { |
| 52 (obj->*method)(p.a, c.a, c.b); |
| 53 } |
| 54 |
| 55 // 2 - 2 |
| 56 template <class ObjT, class Method, class P1, class P2, class C1, class C2> |
| 57 inline void DispatchToMethod(ObjT* obj, Method method, |
| 58 const Tuple2<P1, P2>& p, |
| 59 const Tuple2<C1, C2>& c) { |
| 60 (obj->*method)(p.a, p.b, c.a, c.b); |
| 61 } |
| 62 |
| 63 // 3 - 2 |
| 64 template <class ObjT, class Method, class P1, class P2, class P3, class C1, |
| 65 class C2> |
| 66 inline void DispatchToMethod(ObjT* obj, Method method, |
| 67 const Tuple3<P1, P2, P3>& p, |
| 68 const Tuple2<C1, C2>& c) { |
| 69 (obj->*method)(p.a, p.b, p.c, c.a, c.b); |
| 70 } |
| 71 |
| 72 // 4 - 2 |
| 73 template <class ObjT, class Method, class P1, class P2, class P3, class P4, |
| 74 class C1, class C2> |
| 75 inline void DispatchToMethod(ObjT* obj, Method method, |
| 76 const Tuple4<P1, P2, P3, P4>& p, |
| 77 const Tuple2<C1, C2>& c) { |
| 78 (obj->*method)(p.a, p.b, p.c, p.d, c.a, c.b); |
| 79 } |
| 80 |
| 81 // 1 - 3 |
| 82 template <class ObjT, class Method, class P1, class C1, class C2, class C3> |
| 83 inline void DispatchToMethod(ObjT* obj, Method method, |
| 84 const Tuple1<P1>& p, |
| 85 const Tuple3<C1, C2, C3>& c) { |
| 86 (obj->*method)(p.a, c.a, c.b, c.c); |
| 87 } |
| 88 |
| 89 // 2 - 3 |
| 90 template <class ObjT, class Method, class P1, class P2, class C1, class C2, |
| 91 class C3> |
| 92 inline void DispatchToMethod(ObjT* obj, Method method, |
| 93 const Tuple2<P1, P2>& p, |
| 94 const Tuple3<C1, C2, C3>& c) { |
| 95 (obj->*method)(p.a, p.b, c.a, c.b, c.c); |
| 96 } |
| 97 |
| 98 // 3 - 3 |
| 99 template <class ObjT, class Method, class P1, class P2, class P3, class C1, |
| 100 class C2, class C3> |
| 101 inline void DispatchToMethod(ObjT* obj, Method method, |
| 102 const Tuple3<P1, P2, P3>& p, |
| 103 const Tuple3<C1, C2, C3>& c) { |
| 104 (obj->*method)(p.a, p.b, p.c, c.a, c.b, c.c); |
| 105 } |
| 106 |
| 107 // 4 - 3 |
| 108 template <class ObjT, class Method, class P1, class P2, class P3, class P4, |
| 109 class C1, class C2, class C3> |
| 110 inline void DispatchToMethod(ObjT* obj, Method method, |
| 111 const Tuple4<P1, P2, P3, P4>& p, |
| 112 const Tuple3<C1, C2, C3>& c) { |
| 113 (obj->*method)(p.a, p.b, p.c, p.d, c.a, c.b, c.c); |
| 114 } |
| 115 |
| 116 // 1 - 4 |
| 117 template <class ObjT, class Method, class P1, class C1, class C2, class C3, |
| 118 class C4> |
| 119 inline void DispatchToMethod(ObjT* obj, Method method, |
| 120 const Tuple1<P1>& p, |
| 121 const Tuple4<C1, C2, C3, C4>& c) { |
| 122 (obj->*method)(p.a, c.a, c.b, c.c, c.d); |
| 123 } |
| 124 |
| 125 // 2 - 4 |
| 126 template <class ObjT, class Method, class P1, class P2, class C1, class C2, |
| 127 class C3, class C4> |
| 128 inline void DispatchToMethod(ObjT* obj, Method method, |
| 129 const Tuple2<P1, P2>& p, |
| 130 const Tuple4<C1, C2, C3, C4>& c) { |
| 131 (obj->*method)(p.a, p.b, c.a, c.b, c.c, c.d); |
| 132 } |
| 133 |
| 134 // 3 - 4 |
| 135 template <class ObjT, class Method, class P1, class P2, class P3, |
| 136 class C1, class C2, class C3, class C4> |
| 137 inline void DispatchToMethod(ObjT* obj, Method method, |
| 138 const Tuple3<P1, P2, P3>& p, |
| 139 const Tuple4<C1, C2, C3, C4>& c) { |
| 140 (obj->*method)(p.a, p.b, p.c, c.a, c.b, c.c, c.d); |
| 141 } |
| 142 |
| 143 // 4 - 4 |
| 144 template <class ObjT, class Method, class P1, class P2, class P3, class P4, |
| 145 class C1, class C2, class C3, class C4> |
| 146 inline void DispatchToMethod(ObjT* obj, Method method, |
| 147 const Tuple4<P1, P2, P3, P4>& p, |
| 148 const Tuple4<C1, C2, C3, C4>& c) { |
| 149 (obj->*method)(p.a, p.b, p.c, p.d, c.a, c.b, c.c, c.d); |
| 150 } |
| 151 |
| 152 |
| 153 //////////////////////////////////////////////////////////////////////////////// |
| 154 |
| 155 // Like CallbackImpl but has prebound arguments (like Task) |
| 156 template <class T, typename Method, typename PreBound, typename Params> |
| 157 class MutantImpl : public CallbackStorage<T, Method>, |
| 158 public CallbackRunner<Params> { |
| 159 public: |
| 160 MutantImpl(T* obj, Method meth, const PreBound& pb) |
| 161 : CallbackStorage<T, Method>(obj, meth), |
| 162 pb_(pb) { |
| 163 } |
| 164 |
| 165 virtual void RunWithParams(const Params& params) { |
| 166 // use "this->" to force C++ to look inside our templatized base class; see |
| 167 // Effective C++, 3rd Ed, item 43, p210 for details. |
| 168 DispatchToMethod(this->obj_, this->meth_, pb_, params); |
| 169 } |
| 170 |
| 171 PreBound pb_; |
| 172 }; |
| 173 |
| 174 //////////////////////////////////////////////////////////////////////////////// |
| 175 // Mutant creation simplification |
| 176 // 1 - 1 |
| 177 template <class T, typename P1, typename A1> |
| 178 inline typename Callback1<A1>::Type* NewMutant(T* obj, |
| 179 void (T::*method)(P1, A1), |
| 180 P1 p1) { |
| 181 return new MutantImpl<T, void (T::*)(P1, A1), P1, A1>(obj, method, |
| 182 MakeTuple(p1)); |
| 183 } |
| 184 |
| 185 // 1 - 2 |
| 186 template <class T, typename P1, typename A1, typename A2> |
| 187 inline typename Callback2<A1, A2>::Type* NewMutant(T* obj, |
| 188 void (T::*method)(P1, A1, A2), |
| 189 P1 p1) { |
| 190 return new MutantImpl<T, void (T::*)(P1, A1, A2), Tuple1<P1>, Tuple2<A1, A2> > |
| 191 (obj, method, MakeTuple(p1)); |
| 192 } |
| 193 |
| 194 // 1 - 3 |
| 195 template <class T, typename P1, typename A1, typename A2, typename A3> |
| 196 inline typename Callback3<A1, A2, A3>::Type* |
| 197 NewMutant(T* obj, void (T::*method)(P1, A1, A2, A3), P1 p1) { |
| 198 return new MutantImpl<T, void (T::*)(P1, A1, A2, A3), Tuple1<P1>, |
| 199 Tuple3<A1, A2, A3> >(obj, method, MakeTuple(p1)); |
| 200 } |
| 201 |
| 202 // 1 - 4 |
| 203 template <class T, typename P1, typename A1, typename A2, typename A3, |
| 204 typename A4> |
| 205 inline typename Callback4<A1, A2, A3, A4>::Type* |
| 206 NewMutant(T* obj, void (T::*method)(P1, A1, A2, A3, A4), P1 p1) { |
| 207 return new MutantImpl<T, void (T::*)(P1, A1, A2, A3, A4), Tuple1<P1>, |
| 208 Tuple4<A1, A2, A3, A4> >(obj, method, MakeTuple(p1)); |
| 209 } |
| 210 |
| 211 |
| 212 // 2 - 1 |
| 213 template <class T, typename P1, typename P2, typename A1> |
| 214 inline typename Callback1<A1>::Type* |
| 215 NewMutant(T* obj, void (T::*method)(P1, P2, A1), P1 p1, P2 p2) { |
| 216 return new MutantImpl<T, void (T::*)(P1, P2, A1), Tuple2<P1, P2>, |
| 217 Tuple1<A1> >(obj, method, MakeTuple(p1, p2)); |
| 218 } |
| 219 |
| 220 // 2 - 2 |
| 221 template <class T, typename P1, typename P2, typename A1, typename A2> |
| 222 inline typename Callback2<A1, A2>::Type* |
| 223 NewMutant(T* obj, void (T::*method)(P1, P2, A1, A2), P1 p1, P2 p2) { |
| 224 return new MutantImpl<T, void (T::*)(P1, P2, A1, A2), Tuple2<P1, P2>, |
| 225 Tuple2<A1, A2> >(obj, method, MakeTuple(p1, p2)); |
| 226 } |
| 227 |
| 228 // 2 - 3 |
| 229 template <class T, typename P1, typename P2, typename A1, typename A2, |
| 230 typename A3> |
| 231 inline typename Callback3<A1, A2, A3>::Type* |
| 232 NewMutant(T* obj, void (T::*method)(P1, P2, A1, A2, A3), P1 p1, P2 p2) { |
| 233 return new MutantImpl<T, void (T::*)(P1, P2, A1, A2, A3), Tuple2<P1, P2>, |
| 234 Tuple3<A1, A2, A3> >(obj, method, MakeTuple(p1, p2)); |
| 235 } |
| 236 |
| 237 // 2 - 4 |
| 238 template <class T, typename P1, typename P2, typename A1, typename A2, |
| 239 typename A3, typename A4> |
| 240 inline typename Callback4<A1, A2, A3, A4>::Type* |
| 241 NewMutant(T* obj, void (T::*method)(P1, P2, A1, A2, A3, A4), P1 p1, P2 p2) { |
| 242 return new MutantImpl<T, void (T::*)(P1, P2, A1, A2, A3, A4), Tuple2<P1, P2>, |
| 243 Tuple3<A1, A2, A3, A4> >(obj, method, MakeTuple(p1, p2)); |
| 244 } |
| 245 |
| 246 // 3 - 1 |
| 247 template <class T, typename P1, typename P2, typename P3, typename A1> |
| 248 inline typename Callback1<A1>::Type* |
| 249 NewMutant(T* obj, void (T::*method)(P1, P2, P3, A1), P1 p1, P2 p2, P3 p3) { |
| 250 return new MutantImpl<T, void (T::*)(P1, P2, P3, A1), Tuple3<P1, P2, P3>, |
| 251 Tuple1<A1> >(obj, method, MakeTuple(p1, p2, p3)); |
| 252 } |
| 253 |
| 254 // 3 - 2 |
| 255 template <class T, typename P1, typename P2, typename P3, typename A1, |
| 256 typename A2> |
| 257 inline typename Callback2<A1, A2>::Type* |
| 258 NewMutant(T* obj, void (T::*method)(P1, P2, P3, A1, A2), P1 p1, P2 p2, P3 p3) { |
| 259 return new MutantImpl<T, void (T::*)(P1, P2, P3, A1, A2), Tuple3<P1, P2, P3>, |
| 260 Tuple2<A1, A2> >(obj, method, MakeTuple(p1, p2, p3)); |
| 261 } |
| 262 |
| 263 // 3 - 3 |
| 264 template <class T, typename P1, typename P2, typename P3, typename A1, |
| 265 typename A2, typename A3> |
| 266 inline typename Callback3<A1, A2, A3>::Type* |
| 267 NewMutant(T* obj, void (T::*method)(P1, P2, P3, A1, A2, A3), P1 p1, P2 p2, |
| 268 P3 p3) { |
| 269 return new MutantImpl<T, void (T::*)(P1, P2, P3, A1, A2, A3), |
| 270 Tuple3<P1, P2, P3>, Tuple3<A1, A2, A3> >(obj, method, |
| 271 MakeTuple(p1, p2, p3)); |
| 272 } |
| 273 |
| 274 // 3 - 4 |
| 275 template <class T, typename P1, typename P2, typename P3, typename A1, |
| 276 typename A2, typename A3, typename A4> |
| 277 inline typename Callback4<A1, A2, A3, A4>::Type* |
| 278 NewMutant(T* obj, void (T::*method)(P1, P2, P3, A1, A2, A3, A4), P1 p1, P2 p2, |
| 279 P3 p3) { |
| 280 return new MutantImpl<T, void (T::*)(P1, P2, P3, A1, A2, A3, A4), |
| 281 Tuple3<P1, P2, P3>, Tuple3<A1, A2, A3, A4> >(obj, method, |
| 282 MakeTuple(p1, p2, p3)); |
| 283 } |
| 284 |
| 285 // 4 - 1 |
| 286 template <class T, typename P1, typename P2, typename P3, typename P4, |
| 287 typename A1> |
| 288 inline typename Callback1<A1>::Type* |
| 289 NewMutant(T* obj, void (T::*method)(P1, P2, P3, P4, A1), P1 p1, P2 p2, P3 p3, |
| 290 P4 p4) { |
| 291 return new MutantImpl<T, void (T::*)(P1, P2, P3, P4, A1), |
| 292 Tuple4<P1, P2, P3, P4>, Tuple1<A1> >(obj, method, |
| 293 MakeTuple(p1, p2, p3, p4)); |
| 294 } |
| 295 |
| 296 // 4 - 2 |
| 297 template <class T, typename P1, typename P2, typename P3, typename P4, |
| 298 typename A1, typename A2> |
| 299 inline typename Callback2<A1, A2>::Type* |
| 300 NewMutant(T* obj, void (T::*method)(P1, P2, P3, P4, A1, A2), P1 p1, P2 p2, |
| 301 P3 p3, P4 p4) { |
| 302 return new MutantImpl<T, void (T::*)(P1, P2, P3, P4, A1, A2), |
| 303 Tuple4<P1, P2, P3, P4>, Tuple2<A1, A2> >(obj, method, |
| 304 MakeTuple(p1, p2, p3, p4)); |
| 305 } |
| 306 |
| 307 // 4 - 3 |
| 308 template <class T, typename P1, typename P2, typename P3, typename P4, |
| 309 typename A1, typename A2, typename A3> |
| 310 inline typename Callback3<A1, A2, A3>::Type* |
| 311 NewMutant(T* obj, void (T::*method)(P1, P2, P3, P4, A1, A2, A3), P1 p1, P2 p2, |
| 312 P3 p3, P4 p4) { |
| 313 return new MutantImpl<T, void (T::*)(P1, P2, P3, P4, A1, A2, A3), |
| 314 Tuple4<P1, P2, P3, P4>, Tuple3<A1, A2, A3> >(obj, method, |
| 315 MakeTuple(p1, p2, p3, p4)); |
| 316 } |
| 317 |
| 318 // 4 - 4 |
| 319 template <class T, typename P1, typename P2, typename P3, typename P4, |
| 320 typename A1, typename A2, typename A3, typename A4> |
| 321 inline typename Callback4<A1, A2, A3, A4>::Type* |
| 322 NewMutant(T* obj, void (T::*method)(P1, P2, P3, P4, A1, A2, A3, A4), |
| 323 P1 p1, P2 p2, P3 p3, P4 p4) { |
| 324 return new MutantImpl<T, void (T::*)(P1, P2, P3, P4, A1, A2, A3, A4), |
| 325 Tuple4<P1, P2, P3, P4>, Tuple3<A1, A2, A3, A4> >(obj, method, |
| 326 MakeTuple(p1, p2, p3, p4)); |
| 327 } |
| 328 |
| 329 //////////////////////////////////////////////////////////////////////////////// |
| 330 // Simple callback wrapper acting as a functor. |
| 331 // Redirects operator() to CallbackRunner<Params>::Run |
| 332 // We cannot delete the inner impl_ in object's destructor because |
| 333 // this object is copied few times inside from GMock machinery. |
| 334 template <typename Params> |
| 335 struct CallbackFunctor { |
| 336 explicit CallbackFunctor(CallbackRunner<Params>* cb) : impl_(cb) {} |
| 337 |
| 338 template <typename Arg1> |
| 339 inline void operator()(const Arg1& a) { |
| 340 impl_->Run(a); |
| 341 delete impl_; |
| 342 impl_ = NULL; |
| 343 } |
| 344 |
| 345 template <typename Arg1, typename Arg2> |
| 346 inline void operator()(const Arg1& a, const Arg2& b) { |
| 347 impl_->Run(a, b); |
| 348 delete impl_; |
| 349 impl_ = NULL; |
| 350 } |
| 351 |
| 352 template <typename Arg1, typename Arg2, typename Arg3> |
| 353 inline void operator()(const Arg1& a, const Arg2& b, const Arg3& c) { |
| 354 impl_->Run(a, b, c); |
| 355 delete impl_; |
| 356 impl_ = NULL; |
| 357 } |
| 358 |
| 359 template <typename Arg1, typename Arg2, typename Arg3, typename Arg4> |
| 360 inline void operator()(const Arg1& a, const Arg2& b, const Arg3& c, |
| 361 const Arg4& d) { |
| 362 impl_->Run(a, b, c, d); |
| 363 delete impl_; |
| 364 impl_ = NULL; |
| 365 } |
| 366 |
| 367 private: |
| 368 CallbackFunctor(); |
| 369 CallbackRunner<Params>* impl_; |
| 370 }; |
| 371 |
| 372 |
| 373 /////////////////////////////////////////////////////////////////////////////// |
| 374 // CallbackFunctors creation |
| 375 |
| 376 // 0 - 1 |
| 377 template <class T, typename A1> |
| 378 inline CallbackFunctor<Tuple1<A1> > |
| 379 CBF(T* obj, void (T::*method)(A1)) { |
| 380 return CallbackFunctor<Tuple1<A1> >(NewCallback(obj, method)); |
| 381 } |
| 382 |
| 383 // 0 - 2 |
| 384 template <class T, typename A1, typename A2> |
| 385 inline CallbackFunctor<Tuple2<A1, A2> > |
| 386 CBF(T* obj, void (T::*method)(A1, A2)) { |
| 387 return CallbackFunctor<Tuple2<A1, A2> >(NewCallback(obj, method)); |
| 388 } |
| 389 |
| 390 // 0 - 3 |
| 391 template <class T, typename A1, typename A2, typename A3> |
| 392 inline CallbackFunctor<Tuple3<A1, A2, A3> > |
| 393 CBF(T* obj, void (T::*method)(A1, A2, A3)) { |
| 394 return CallbackFunctor<Tuple3<A1, A2, A3> >(NewCallback(obj, method)); |
| 395 } |
| 396 |
| 397 // 0 - 4 |
| 398 template <class T, typename A1, typename A2, typename A3, typename A4> |
| 399 inline CallbackFunctor<Tuple4<A1, A2, A3, A4> > |
| 400 CBF(T* obj, void (T::*method)(A1, A2, A3, A4)) { |
| 401 return CallbackFunctor<Tuple4<A1, A2, A3, A4> >(NewCallback(obj, method)); |
| 402 } |
| 403 |
| 404 // 1 - 1 |
| 405 template <class T, typename P1, typename A1> |
| 406 inline CallbackFunctor<Tuple1<A1> > |
| 407 CBF(T* obj, void (T::*method)(P1, A1), P1 p1) { |
| 408 Callback1<A1>::Type* t = new MutantImpl<T, void (T::*)(P1, A1), Tuple1<P1>, |
| 409 Tuple1<A1> >(obj, method, MakeTuple(p1)); |
| 410 return CallbackFunctor<Tuple1<A1> >(t); |
| 411 } |
| 412 |
| 413 // 1 - 2 |
| 414 template <class T, typename P1, typename A1, typename A2> |
| 415 inline CallbackFunctor<Tuple2<A1, A2> > |
| 416 CBF(T* obj, void (T::*method)(P1, A1, A2), P1 p1) { |
| 417 Callback2<A1, A2>::Type* t = new MutantImpl<T, void (T::*)(P1, A1, A2), |
| 418 Tuple1<P1>, Tuple2<A1, A2> >(obj, method, MakeTuple(p1)); |
| 419 return CallbackFunctor<Tuple2<A1, A2> >(t); |
| 420 } |
| 421 |
| 422 // 1 - 3 |
| 423 template <class T, typename P1, typename A1, typename A2, typename A3> |
| 424 inline CallbackFunctor<Tuple3<A1, A2, A3> > |
| 425 CBF(T* obj, void (T::*method)(P1, A1, A2, A3), P1 p1) { |
| 426 Callback3<A1, A2, A3>::Type* t = |
| 427 new MutantImpl<T, void (T::*)(P1, A1, A2, A3), Tuple1<P1>, |
| 428 Tuple3<A1, A2, A3> >(obj, method, MakeTuple(p1)); |
| 429 return CallbackFunctor<Tuple3<A1, A2, A3> >(t); |
| 430 } |
| 431 |
| 432 // 1 - 4 |
| 433 template <class T, typename P1, typename A1, typename A2, typename A3, |
| 434 typename A4> |
| 435 inline CallbackFunctor<Tuple4<A1, A2, A3, A4> > |
| 436 CBF(T* obj, void (T::*method)(P1, A1, A2, A3, A4), P1 p1) { |
| 437 Callback4<A1, A2, A3>::Type* t = |
| 438 new MutantImpl<T, void (T::*)(P1, A1, A2, A3, A4), Tuple1<P1>, |
| 439 Tuple4<A1, A2, A3, A4> >(obj, method, MakeTuple(p1)); |
| 440 return CallbackFunctor<Tuple4<A1, A2, A3, A4> >(t); |
| 441 } |
| 442 |
| 443 // 2 - 1 |
| 444 template <class T, typename P1, typename P2, typename A1> |
| 445 inline CallbackFunctor<Tuple1<A1> > |
| 446 CBF(T* obj, void (T::*method)(P1, P2, A1), P1 p1, P2 p2) { |
| 447 Callback1<A1>::Type* t = new MutantImpl<T, void (T::*)(P1, P2, A1), |
| 448 Tuple2<P1, P2>, Tuple1<A1> >(obj, method, MakeTuple(p1, p2)); |
| 449 return CallbackFunctor<Tuple1<A1> >(t); |
| 450 } |
| 451 |
| 452 // 2 - 2 |
| 453 template <class T, typename P1, typename P2, typename A1, typename A2> |
| 454 inline CallbackFunctor<Tuple2<A1, A2> > |
| 455 CBF(T* obj, void (T::*method)(P1, P2, A1, A2), P1 p1, P2 p2) { |
| 456 Callback2<A1, A2>::Type* t = new MutantImpl<T, void (T::*)(P1, P2, A1, A2), |
| 457 Tuple2<P1, P2>, Tuple2<A1, A2> >(obj, method, MakeTuple(p1, p2)); |
| 458 return CallbackFunctor<Tuple2<A1, A2> >(t); |
| 459 } |
| 460 |
| 461 // 2 - 3 |
| 462 template <class T, typename P1, typename P2, typename A1, typename A2, |
| 463 typename A3> inline CallbackFunctor<Tuple3<A1, A2, A3> > |
| 464 CBF(T* obj, void (T::*method)(P1, P2, A1, A2, A3), P1 p1, P2 p2) { |
| 465 Callback3<A1, A2, A3>::Type* t = |
| 466 new MutantImpl<T, void (T::*)(P1, P2, A1, A2, A3), Tuple2<P1, P2>, |
| 467 Tuple3<A1, A2, A3> >(obj, method, MakeTuple(p1, p2)); |
| 468 return CallbackFunctor<Tuple3<A1, A2, A3> >(t); |
| 469 } |
| 470 |
| 471 // 2 - 4 |
| 472 template <class T, typename P1, typename P2, typename A1, typename A2, |
| 473 typename A3, typename A4> |
| 474 inline CallbackFunctor<Tuple4<A1, A2, A3, A4> > |
| 475 CBF(T* obj, void (T::*method)(P1, P2, A1, A2, A3, A4), P1 p1, P2 p2) { |
| 476 Callback4<A1, A2, A3>::Type* t = |
| 477 new MutantImpl<T, void (T::*)(P1, P2, A1, A2, A3, A4), Tuple2<P1, P2>, |
| 478 Tuple4<A1, A2, A3, A4> >(obj, method, MakeTuple(p1, p2)); |
| 479 return CallbackFunctor<Tuple4<A1, A2, A3, A4> >(t); |
| 480 } |
| 481 |
| 482 |
| 483 // 3 - 1 |
| 484 template <class T, typename P1, typename P2, typename P3, typename A1> |
| 485 inline CallbackFunctor<Tuple1<A1> > |
| 486 CBF(T* obj, void (T::*method)(P1, P2, P3, A1), P1 p1, P2 p2, P3 p3) { |
| 487 Callback1<A1>::Type* t = new MutantImpl<T, void (T::*)(P1, P2, P3, A1), |
| 488 Tuple3<P1, P2, P3>, Tuple1<A1> >(obj, method, MakeTuple(p1, p2, p3)); |
| 489 return CallbackFunctor<Tuple1<A1> >(t); |
| 490 } |
| 491 |
| 492 |
| 493 // 3 - 2 |
| 494 template <class T, typename P1, typename P2, typename P3, typename A1, |
| 495 typename A2> inline CallbackFunctor<Tuple2<A1, A2> > |
| 496 CBF(T* obj, void (T::*method)(P1, P2, P3, A1, A2), P1 p1, P2 p2, P3 p3) { |
| 497 Callback2<A1, A2>::Type* t = |
| 498 new MutantImpl<T, void (T::*)(P1, P2, P3, A1, A2), Tuple3<P1, P2, P3>, |
| 499 Tuple2<A1, A2> >(obj, method, MakeTuple(p1, p2, p3)); |
| 500 return CallbackFunctor<Tuple2<A1, A2> >(t); |
| 501 } |
| 502 |
| 503 // 3 - 3 |
| 504 template <class T, typename P1, typename P2, typename P3, typename A1, |
| 505 typename A2, typename A3> |
| 506 inline CallbackFunctor<Tuple3<A1, A2, A3> > |
| 507 CBF(T* obj, void (T::*method)(P1, P2, P3, A1, A2, A3), P1 p1, P2 p2, P3 p3) { |
| 508 Callback3<A1, A2, A3>::Type* t = |
| 509 new MutantImpl<T, void (T::*)(P1, P2, P3, A1, A2, A3), Tuple3<P1, P2, P3>, |
| 510 Tuple3<A1, A2, A3> >(obj, method, MakeTuple(p1, p2, p3)); |
| 511 return CallbackFunctor<Tuple3<A1, A2, A3> >(t); |
| 512 } |
| 513 |
| 514 // 3 - 4 |
| 515 template <class T, typename P1, typename P2, typename P3, typename A1, |
| 516 typename A2, typename A3, typename A4> |
| 517 inline CallbackFunctor<Tuple4<A1, A2, A3, A4> > |
| 518 CBF(T* obj, void (T::*method)(P1, P2, P3, A1, A2, A3, A4), |
| 519 P1 p1, P2 p2, P3 p3) { |
| 520 Callback4<A1, A2, A3>::Type* t = |
| 521 new MutantImpl<T, void (T::*)(P1, P2, P3, A1, A2, A3, A4), |
| 522 Tuple3<P1, P2, P3>, Tuple4<A1, A2, A3, A4> >(obj, method, |
| 523 MakeTuple(p1, p2, p3)); |
| 524 return CallbackFunctor<Tuple4<A1, A2, A3, A4> >(t); |
| 525 } |
| 526 |
| 527 |
| 528 |
| 529 // 4 - 1 |
| 530 template <class T, typename P1, typename P2, typename P3, typename P4, |
| 531 typename A1> |
| 532 inline CallbackFunctor<Tuple1<A1> > |
| 533 CBF(T* obj, void (T::*method)(P1, P2, P3, P4, A1), P1 p1, P2 p2, P3 p3, P4 p4) { |
| 534 Callback1<A1>::Type* t = new MutantImpl<T, void (T::*)(P1, P2, P3, P4, A1), |
| 535 Tuple4<P1, P2, P3, P4>, Tuple1<A1> > |
| 536 (obj, method, MakeTuple(p1, p2, p3, p4)); |
| 537 return CallbackFunctor<Tuple1<A1> >(t); |
| 538 } |
| 539 |
| 540 |
| 541 // 4 - 2 |
| 542 template <class T, typename P1, typename P2, typename P3, typename P4, |
| 543 typename A1, typename A2> |
| 544 inline CallbackFunctor<Tuple2<A1, A2> > |
| 545 CBF(T* obj, void (T::*method)(P1, P2, P3, P4, A1, A2), |
| 546 P1 p1, P2 p2, P3 p3, P4 p4) { |
| 547 Callback2<A1, A2>::Type* t = |
| 548 new MutantImpl<T, void (T::*)(P1, P2, P3, P4, A1, A2), |
| 549 Tuple4<P1, P2, P3, P4>, |
| 550 Tuple2<A1, A2> >(obj, method, MakeTuple(p1, p2, p3, p4)); |
| 551 return CallbackFunctor<Tuple2<A1, A2> >(t); |
| 552 } |
| 553 |
| 554 // 4 - 3 |
| 555 template <class T, typename P1, typename P2, typename P3, typename P4, |
| 556 typename A1, typename A2, typename A3> |
| 557 inline CallbackFunctor<Tuple3<A1, A2, A3> > |
| 558 CBF(T* obj, void (T::*method)(P1, P2, P3, P4, A1, A2, A3), |
| 559 P1 p1, P2 p2, P3 p3, P4 p4) { |
| 560 Callback3<A1, A2, A3>::Type* t = |
| 561 new MutantImpl<T, void (T::*)(P1, P2, P3, P4, A1, A2, A3), |
| 562 Tuple4<P1, P2, P3, P4>, Tuple3<A1, A2, A3> > |
| 563 (obj, method, MakeTuple(p1, p2, p3, p4)); |
| 564 return CallbackFunctor<Tuple3<A1, A2, A3> >(t); |
| 565 } |
| 566 |
| 567 // 4 - 4 |
| 568 template <class T, typename P1, typename P2, typename P3, typename P4, |
| 569 typename A1, typename A2, typename A3, typename A4> |
| 570 inline CallbackFunctor<Tuple4<A1, A2, A3, A4> > |
| 571 CBF(T* obj, void (T::*method)(P1, P2, P3, P4, A1, A2, A3, A4), |
| 572 P1 p1, P2 p2, P3 p3, P4 p4) { |
| 573 Callback4<A1, A2, A3>::Type* t = |
| 574 new MutantImpl<T, void (T::*)(P1, P2, P3, P4, A1, A2, A3, A4), |
| 575 Tuple4<P1, P2, P3, P4>, Tuple4<A1, A2, A3, A4> >(obj, method, |
| 576 MakeTuple(p1, p2, p3, p4)); |
| 577 return CallbackFunctor<Tuple4<A1, A2, A3, A4> >(t); |
| 578 } |
| 579 |
| 580 |
| 581 // Simple task wrapper acting as a functor. |
| 582 // Redirects operator() to Task::Run. We cannot delete the inner impl_ object |
| 583 // in object's destructor because this object is copied few times inside |
| 584 // from GMock machinery. |
| 585 struct TaskHolder { |
| 586 explicit TaskHolder(Task* impl) : impl_(impl) {} |
| 587 void operator()() { |
| 588 impl_->Run(); |
| 589 delete impl_; |
| 590 impl_ = NULL; |
| 591 } |
| 592 private: |
| 593 TaskHolder(); |
| 594 Task* impl_; |
| 595 }; |
| 596 |
| 597 #endif // CHROME_FRAME_TEST_HELPER_GMOCK_H_ |
OLD | NEW |