blob: c2e155c2b9aa38952d4d02b3630b882b1ae868c7 [file] [log] [blame]
shiqiane35fdd92008-12-10 05:08:54 +00001// This file was GENERATED by a script. DO NOT EDIT BY HAND!!!
2
3// Copyright 2007, Google Inc.
4// All rights reserved.
5//
6// Redistribution and use in source and binary forms, with or without
7// modification, are permitted provided that the following conditions are
8// met:
9//
10// * Redistributions of source code must retain the above copyright
11// notice, this list of conditions and the following disclaimer.
12// * Redistributions in binary form must reproduce the above
13// copyright notice, this list of conditions and the following disclaimer
14// in the documentation and/or other materials provided with the
15// distribution.
16// * Neither the name of Google Inc. nor the names of its
17// contributors may be used to endorse or promote products derived from
18// this software without specific prior written permission.
19//
20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31//
32// Author: wan@google.com (Zhanyong Wan)
33
34// Google Mock - a framework for writing C++ mock classes.
35//
36// This file implements some commonly used variadic actions.
37
38#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
39#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
40
41#include <gmock/gmock-actions.h>
42#include <gmock/internal/gmock-port.h>
43
44namespace testing {
45namespace internal {
46
47// InvokeHelper<F> knows how to unpack an N-tuple and invoke an N-ary
48// function or method with the unpacked values, where F is a function
49// type that takes N arguments.
50template <typename Result, typename ArgumentTuple>
51class InvokeHelper;
52
53template <typename R>
54class InvokeHelper<R, ::std::tr1::tuple<> > {
55 public:
56 template <typename Function>
57 static R Invoke(Function function, const ::std::tr1::tuple<>&) {
58 return function();
59 }
60
61 template <class Class, typename MethodPtr>
62 static R InvokeMethod(Class* obj_ptr,
63 MethodPtr method_ptr,
64 const ::std::tr1::tuple<>&) {
65 return (obj_ptr->*method_ptr)();
66 }
67};
68
69template <typename R, typename A1>
70class InvokeHelper<R, ::std::tr1::tuple<A1> > {
71 public:
72 template <typename Function>
73 static R Invoke(Function function, const ::std::tr1::tuple<A1>& args) {
74 using ::std::tr1::get;
75 return function(get<0>(args));
76 }
77
78 template <class Class, typename MethodPtr>
79 static R InvokeMethod(Class* obj_ptr,
80 MethodPtr method_ptr,
81 const ::std::tr1::tuple<A1>& args) {
82 using ::std::tr1::get;
83 return (obj_ptr->*method_ptr)(get<0>(args));
84 }
85};
86
87template <typename R, typename A1, typename A2>
88class InvokeHelper<R, ::std::tr1::tuple<A1, A2> > {
89 public:
90 template <typename Function>
91 static R Invoke(Function function, const ::std::tr1::tuple<A1, A2>& args) {
92 using ::std::tr1::get;
93 return function(get<0>(args), get<1>(args));
94 }
95
96 template <class Class, typename MethodPtr>
97 static R InvokeMethod(Class* obj_ptr,
98 MethodPtr method_ptr,
99 const ::std::tr1::tuple<A1, A2>& args) {
100 using ::std::tr1::get;
101 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args));
102 }
103};
104
105template <typename R, typename A1, typename A2, typename A3>
106class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3> > {
107 public:
108 template <typename Function>
109 static R Invoke(Function function, const ::std::tr1::tuple<A1, A2,
110 A3>& args) {
111 using ::std::tr1::get;
112 return function(get<0>(args), get<1>(args), get<2>(args));
113 }
114
115 template <class Class, typename MethodPtr>
116 static R InvokeMethod(Class* obj_ptr,
117 MethodPtr method_ptr,
118 const ::std::tr1::tuple<A1, A2, A3>& args) {
119 using ::std::tr1::get;
120 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args));
121 }
122};
123
124template <typename R, typename A1, typename A2, typename A3, typename A4>
125class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4> > {
126 public:
127 template <typename Function>
128 static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3,
129 A4>& args) {
130 using ::std::tr1::get;
131 return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args));
132 }
133
134 template <class Class, typename MethodPtr>
135 static R InvokeMethod(Class* obj_ptr,
136 MethodPtr method_ptr,
137 const ::std::tr1::tuple<A1, A2, A3, A4>& args) {
138 using ::std::tr1::get;
139 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args),
140 get<3>(args));
141 }
142};
143
144template <typename R, typename A1, typename A2, typename A3, typename A4,
145 typename A5>
146class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5> > {
147 public:
148 template <typename Function>
149 static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4,
150 A5>& args) {
151 using ::std::tr1::get;
152 return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args),
153 get<4>(args));
154 }
155
156 template <class Class, typename MethodPtr>
157 static R InvokeMethod(Class* obj_ptr,
158 MethodPtr method_ptr,
159 const ::std::tr1::tuple<A1, A2, A3, A4, A5>& args) {
160 using ::std::tr1::get;
161 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args),
162 get<3>(args), get<4>(args));
163 }
164};
165
166template <typename R, typename A1, typename A2, typename A3, typename A4,
167 typename A5, typename A6>
168class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5, A6> > {
169 public:
170 template <typename Function>
171 static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4,
172 A5, A6>& args) {
173 using ::std::tr1::get;
174 return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args),
175 get<4>(args), get<5>(args));
176 }
177
178 template <class Class, typename MethodPtr>
179 static R InvokeMethod(Class* obj_ptr,
180 MethodPtr method_ptr,
181 const ::std::tr1::tuple<A1, A2, A3, A4, A5, A6>& args) {
182 using ::std::tr1::get;
183 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args),
184 get<3>(args), get<4>(args), get<5>(args));
185 }
186};
187
188template <typename R, typename A1, typename A2, typename A3, typename A4,
189 typename A5, typename A6, typename A7>
190class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7> > {
191 public:
192 template <typename Function>
193 static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4,
194 A5, A6, A7>& args) {
195 using ::std::tr1::get;
196 return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args),
197 get<4>(args), get<5>(args), get<6>(args));
198 }
199
200 template <class Class, typename MethodPtr>
201 static R InvokeMethod(Class* obj_ptr,
202 MethodPtr method_ptr,
203 const ::std::tr1::tuple<A1, A2, A3, A4, A5, A6,
204 A7>& args) {
205 using ::std::tr1::get;
206 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args),
207 get<3>(args), get<4>(args), get<5>(args), get<6>(args));
208 }
209};
210
211template <typename R, typename A1, typename A2, typename A3, typename A4,
212 typename A5, typename A6, typename A7, typename A8>
213class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8> > {
214 public:
215 template <typename Function>
216 static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4,
217 A5, A6, A7, A8>& args) {
218 using ::std::tr1::get;
219 return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args),
220 get<4>(args), get<5>(args), get<6>(args), get<7>(args));
221 }
222
223 template <class Class, typename MethodPtr>
224 static R InvokeMethod(Class* obj_ptr,
225 MethodPtr method_ptr,
226 const ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7,
227 A8>& args) {
228 using ::std::tr1::get;
229 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args),
230 get<3>(args), get<4>(args), get<5>(args), get<6>(args), get<7>(args));
231 }
232};
233
234template <typename R, typename A1, typename A2, typename A3, typename A4,
235 typename A5, typename A6, typename A7, typename A8, typename A9>
236class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9> > {
237 public:
238 template <typename Function>
239 static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4,
240 A5, A6, A7, A8, A9>& args) {
241 using ::std::tr1::get;
242 return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args),
243 get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args));
244 }
245
246 template <class Class, typename MethodPtr>
247 static R InvokeMethod(Class* obj_ptr,
248 MethodPtr method_ptr,
249 const ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8,
250 A9>& args) {
251 using ::std::tr1::get;
252 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args),
253 get<3>(args), get<4>(args), get<5>(args), get<6>(args), get<7>(args),
254 get<8>(args));
255 }
256};
257
258template <typename R, typename A1, typename A2, typename A3, typename A4,
259 typename A5, typename A6, typename A7, typename A8, typename A9,
260 typename A10>
261class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9,
262 A10> > {
263 public:
264 template <typename Function>
265 static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4,
266 A5, A6, A7, A8, A9, A10>& args) {
267 using ::std::tr1::get;
268 return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args),
269 get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args),
270 get<9>(args));
271 }
272
273 template <class Class, typename MethodPtr>
274 static R InvokeMethod(Class* obj_ptr,
275 MethodPtr method_ptr,
276 const ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8,
277 A9, A10>& args) {
278 using ::std::tr1::get;
279 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args),
280 get<3>(args), get<4>(args), get<5>(args), get<6>(args), get<7>(args),
281 get<8>(args), get<9>(args));
282 }
283};
284
285
286// Implements the Invoke(f) action. The template argument
287// FunctionImpl is the implementation type of f, which can be either a
288// function pointer or a functor. Invoke(f) can be used as an
289// Action<F> as long as f's type is compatible with F (i.e. f can be
290// assigned to a tr1::function<F>).
291template <typename FunctionImpl>
292class InvokeAction {
293 public:
294 // The c'tor makes a copy of function_impl (either a function
295 // pointer or a functor).
296 explicit InvokeAction(FunctionImpl function_impl)
297 : function_impl_(function_impl) {}
298
299 template <typename Result, typename ArgumentTuple>
300 Result Perform(const ArgumentTuple& args) {
301 return InvokeHelper<Result, ArgumentTuple>::Invoke(function_impl_, args);
302 }
303 private:
304 FunctionImpl function_impl_;
305};
306
307// Implements the Invoke(object_ptr, &Class::Method) action.
308template <class Class, typename MethodPtr>
309class InvokeMethodAction {
310 public:
311 InvokeMethodAction(Class* obj_ptr, MethodPtr method_ptr)
312 : obj_ptr_(obj_ptr), method_ptr_(method_ptr) {}
313
314 template <typename Result, typename ArgumentTuple>
315 Result Perform(const ArgumentTuple& args) const {
316 return InvokeHelper<Result, ArgumentTuple>::InvokeMethod(
317 obj_ptr_, method_ptr_, args);
318 }
319 private:
320 Class* const obj_ptr_;
321 const MethodPtr method_ptr_;
322};
323
324// A ReferenceWrapper<T> object represents a reference to type T,
325// which can be either const or not. It can be explicitly converted
326// from, and implicitly converted to, a T&. Unlike a reference,
327// ReferenceWrapper<T> can be copied and can survive template type
328// inference. This is used to support by-reference arguments in the
329// InvokeArgument<N>(...) action. The idea was from "reference
330// wrappers" in tr1, which we don't have in our source tree yet.
331template <typename T>
332class ReferenceWrapper {
333 public:
334 // Constructs a ReferenceWrapper<T> object from a T&.
335 explicit ReferenceWrapper(T& l_value) : pointer_(&l_value) {} // NOLINT
336
337 // Allows a ReferenceWrapper<T> object to be implicitly converted to
338 // a T&.
339 operator T&() const { return *pointer_; }
340 private:
341 T* pointer_;
342};
343
344// CallableHelper has static methods for invoking "callables",
345// i.e. function pointers and functors. It uses overloading to
346// provide a uniform interface for invoking different kinds of
347// callables. In particular, you can use:
348//
349// CallableHelper<R>::Call(callable, a1, a2, ..., an)
350//
351// to invoke an n-ary callable, where R is its return type. If an
352// argument, say a2, needs to be passed by reference, you should write
353// ByRef(a2) instead of a2 in the above expression.
354template <typename R>
355class CallableHelper {
356 public:
357 // Calls a nullary callable.
358 template <typename Function>
359 static R Call(Function function) { return function(); }
360
361 // Calls a unary callable.
362
363 // We deliberately pass a1 by value instead of const reference here
364 // in case it is a C-string literal. If we had declared the
365 // parameter as 'const A1& a1' and write Call(function, "Hi"), the
366 // compiler would've thought A1 is 'char[3]', which causes trouble
367 // when you need to copy a value of type A1. By declaring the
368 // parameter as 'A1 a1', the compiler will correctly infer that A1
369 // is 'const char*' when it sees Call(function, "Hi").
370 //
371 // Since this function is defined inline, the compiler can get rid
372 // of the copying of the arguments. Therefore the performance won't
373 // be hurt.
374 template <typename Function, typename A1>
375 static R Call(Function function, A1 a1) { return function(a1); }
376
377 // Calls a binary callable.
378 template <typename Function, typename A1, typename A2>
379 static R Call(Function function, A1 a1, A2 a2) {
380 return function(a1, a2);
381 }
382
383 // Calls a ternary callable.
384 template <typename Function, typename A1, typename A2, typename A3>
385 static R Call(Function function, A1 a1, A2 a2, A3 a3) {
386 return function(a1, a2, a3);
387 }
388
389 // Calls a 4-ary callable.
390 template <typename Function, typename A1, typename A2, typename A3,
391 typename A4>
392 static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4) {
393 return function(a1, a2, a3, a4);
394 }
395
396 // Calls a 5-ary callable.
397 template <typename Function, typename A1, typename A2, typename A3,
398 typename A4, typename A5>
399 static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) {
400 return function(a1, a2, a3, a4, a5);
401 }
402
403 // Calls a 6-ary callable.
404 template <typename Function, typename A1, typename A2, typename A3,
405 typename A4, typename A5, typename A6>
406 static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) {
407 return function(a1, a2, a3, a4, a5, a6);
408 }
409
410 // Calls a 7-ary callable.
411 template <typename Function, typename A1, typename A2, typename A3,
412 typename A4, typename A5, typename A6, typename A7>
413 static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
414 A7 a7) {
415 return function(a1, a2, a3, a4, a5, a6, a7);
416 }
417
418 // Calls a 8-ary callable.
419 template <typename Function, typename A1, typename A2, typename A3,
420 typename A4, typename A5, typename A6, typename A7, typename A8>
421 static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
422 A7 a7, A8 a8) {
423 return function(a1, a2, a3, a4, a5, a6, a7, a8);
424 }
425
426 // Calls a 9-ary callable.
427 template <typename Function, typename A1, typename A2, typename A3,
428 typename A4, typename A5, typename A6, typename A7, typename A8,
429 typename A9>
430 static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
431 A7 a7, A8 a8, A9 a9) {
432 return function(a1, a2, a3, a4, a5, a6, a7, a8, a9);
433 }
434
435 // Calls a 10-ary callable.
436 template <typename Function, typename A1, typename A2, typename A3,
437 typename A4, typename A5, typename A6, typename A7, typename A8,
438 typename A9, typename A10>
439 static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
440 A7 a7, A8 a8, A9 a9, A10 a10) {
441 return function(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
442 }
443
444}; // class CallableHelper
445
446// Invokes a nullary callable argument.
447template <size_t N>
448class InvokeArgumentAction0 {
449 public:
450 template <typename Result, typename ArgumentTuple>
451 static Result Perform(const ArgumentTuple& args) {
452 return CallableHelper<Result>::Call(::std::tr1::get<N>(args));
453 }
454};
455
456// Invokes a unary callable argument with the given argument.
457template <size_t N, typename A1>
458class InvokeArgumentAction1 {
459 public:
460 // We deliberately pass a1 by value instead of const reference here
461 // in case it is a C-string literal.
462 //
463 // Since this function is defined inline, the compiler can get rid
464 // of the copying of the arguments. Therefore the performance won't
465 // be hurt.
466 explicit InvokeArgumentAction1(A1 a1) : arg1_(a1) {}
467
468 template <typename Result, typename ArgumentTuple>
469 Result Perform(const ArgumentTuple& args) {
470 return CallableHelper<Result>::Call(::std::tr1::get<N>(args), arg1_);
471 }
472 private:
473 const A1 arg1_;
474};
475
476// Invokes a binary callable argument with the given arguments.
477template <size_t N, typename A1, typename A2>
478class InvokeArgumentAction2 {
479 public:
480 InvokeArgumentAction2(A1 a1, A2 a2) :
481 arg1_(a1), arg2_(a2) {}
482
483 template <typename Result, typename ArgumentTuple>
484 Result Perform(const ArgumentTuple& args) {
485 return CallableHelper<Result>::Call(::std::tr1::get<N>(args), arg1_, arg2_);
486 }
487 private:
488 const A1 arg1_;
489 const A2 arg2_;
490};
491
492// Invokes a ternary callable argument with the given arguments.
493template <size_t N, typename A1, typename A2, typename A3>
494class InvokeArgumentAction3 {
495 public:
496 InvokeArgumentAction3(A1 a1, A2 a2, A3 a3) :
497 arg1_(a1), arg2_(a2), arg3_(a3) {}
498
499 template <typename Result, typename ArgumentTuple>
500 Result Perform(const ArgumentTuple& args) {
501 return CallableHelper<Result>::Call(::std::tr1::get<N>(args), arg1_, arg2_,
502 arg3_);
503 }
504 private:
505 const A1 arg1_;
506 const A2 arg2_;
507 const A3 arg3_;
508};
509
510// Invokes a 4-ary callable argument with the given arguments.
511template <size_t N, typename A1, typename A2, typename A3, typename A4>
512class InvokeArgumentAction4 {
513 public:
514 InvokeArgumentAction4(A1 a1, A2 a2, A3 a3, A4 a4) :
515 arg1_(a1), arg2_(a2), arg3_(a3), arg4_(a4) {}
516
517 template <typename Result, typename ArgumentTuple>
518 Result Perform(const ArgumentTuple& args) {
519 return CallableHelper<Result>::Call(::std::tr1::get<N>(args), arg1_, arg2_,
520 arg3_, arg4_);
521 }
522 private:
523 const A1 arg1_;
524 const A2 arg2_;
525 const A3 arg3_;
526 const A4 arg4_;
527};
528
529// Invokes a 5-ary callable argument with the given arguments.
530template <size_t N, typename A1, typename A2, typename A3, typename A4,
531 typename A5>
532class InvokeArgumentAction5 {
533 public:
534 InvokeArgumentAction5(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) :
535 arg1_(a1), arg2_(a2), arg3_(a3), arg4_(a4), arg5_(a5) {}
536
537 template <typename Result, typename ArgumentTuple>
538 Result Perform(const ArgumentTuple& args) {
539 // We extract the callable to a variable before invoking it, in
540 // case it is a functor passed by value and its operator() is not
541 // const.
542 typename ::std::tr1::tuple_element<N, ArgumentTuple>::type function =
543 ::std::tr1::get<N>(args);
544 return function(arg1_, arg2_, arg3_, arg4_, arg5_);
545 }
546 private:
547 const A1 arg1_;
548 const A2 arg2_;
549 const A3 arg3_;
550 const A4 arg4_;
551 const A5 arg5_;
552};
553
554// Invokes a 6-ary callable argument with the given arguments.
555template <size_t N, typename A1, typename A2, typename A3, typename A4,
556 typename A5, typename A6>
557class InvokeArgumentAction6 {
558 public:
559 InvokeArgumentAction6(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) :
560 arg1_(a1), arg2_(a2), arg3_(a3), arg4_(a4), arg5_(a5), arg6_(a6) {}
561
562 template <typename Result, typename ArgumentTuple>
563 Result Perform(const ArgumentTuple& args) {
564 // We extract the callable to a variable before invoking it, in
565 // case it is a functor passed by value and its operator() is not
566 // const.
567 typename ::std::tr1::tuple_element<N, ArgumentTuple>::type function =
568 ::std::tr1::get<N>(args);
569 return function(arg1_, arg2_, arg3_, arg4_, arg5_, arg6_);
570 }
571 private:
572 const A1 arg1_;
573 const A2 arg2_;
574 const A3 arg3_;
575 const A4 arg4_;
576 const A5 arg5_;
577 const A6 arg6_;
578};
579
580// Invokes a 7-ary callable argument with the given arguments.
581template <size_t N, typename A1, typename A2, typename A3, typename A4,
582 typename A5, typename A6, typename A7>
583class InvokeArgumentAction7 {
584 public:
585 InvokeArgumentAction7(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) :
586 arg1_(a1), arg2_(a2), arg3_(a3), arg4_(a4), arg5_(a5), arg6_(a6),
587 arg7_(a7) {}
588
589 template <typename Result, typename ArgumentTuple>
590 Result Perform(const ArgumentTuple& args) {
591 // We extract the callable to a variable before invoking it, in
592 // case it is a functor passed by value and its operator() is not
593 // const.
594 typename ::std::tr1::tuple_element<N, ArgumentTuple>::type function =
595 ::std::tr1::get<N>(args);
596 return function(arg1_, arg2_, arg3_, arg4_, arg5_, arg6_, arg7_);
597 }
598 private:
599 const A1 arg1_;
600 const A2 arg2_;
601 const A3 arg3_;
602 const A4 arg4_;
603 const A5 arg5_;
604 const A6 arg6_;
605 const A7 arg7_;
606};
607
608// Invokes a 8-ary callable argument with the given arguments.
609template <size_t N, typename A1, typename A2, typename A3, typename A4,
610 typename A5, typename A6, typename A7, typename A8>
611class InvokeArgumentAction8 {
612 public:
613 InvokeArgumentAction8(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7,
614 A8 a8) :
615 arg1_(a1), arg2_(a2), arg3_(a3), arg4_(a4), arg5_(a5), arg6_(a6),
616 arg7_(a7), arg8_(a8) {}
617
618 template <typename Result, typename ArgumentTuple>
619 Result Perform(const ArgumentTuple& args) {
620 // We extract the callable to a variable before invoking it, in
621 // case it is a functor passed by value and its operator() is not
622 // const.
623 typename ::std::tr1::tuple_element<N, ArgumentTuple>::type function =
624 ::std::tr1::get<N>(args);
625 return function(arg1_, arg2_, arg3_, arg4_, arg5_, arg6_, arg7_, arg8_);
626 }
627 private:
628 const A1 arg1_;
629 const A2 arg2_;
630 const A3 arg3_;
631 const A4 arg4_;
632 const A5 arg5_;
633 const A6 arg6_;
634 const A7 arg7_;
635 const A8 arg8_;
636};
637
638// Invokes a 9-ary callable argument with the given arguments.
639template <size_t N, typename A1, typename A2, typename A3, typename A4,
640 typename A5, typename A6, typename A7, typename A8, typename A9>
641class InvokeArgumentAction9 {
642 public:
643 InvokeArgumentAction9(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8,
644 A9 a9) :
645 arg1_(a1), arg2_(a2), arg3_(a3), arg4_(a4), arg5_(a5), arg6_(a6),
646 arg7_(a7), arg8_(a8), arg9_(a9) {}
647
648 template <typename Result, typename ArgumentTuple>
649 Result Perform(const ArgumentTuple& args) {
650 // We extract the callable to a variable before invoking it, in
651 // case it is a functor passed by value and its operator() is not
652 // const.
653 typename ::std::tr1::tuple_element<N, ArgumentTuple>::type function =
654 ::std::tr1::get<N>(args);
655 return function(arg1_, arg2_, arg3_, arg4_, arg5_, arg6_, arg7_, arg8_,
656 arg9_);
657 }
658 private:
659 const A1 arg1_;
660 const A2 arg2_;
661 const A3 arg3_;
662 const A4 arg4_;
663 const A5 arg5_;
664 const A6 arg6_;
665 const A7 arg7_;
666 const A8 arg8_;
667 const A9 arg9_;
668};
669
670// Invokes a 10-ary callable argument with the given arguments.
671template <size_t N, typename A1, typename A2, typename A3, typename A4,
672 typename A5, typename A6, typename A7, typename A8, typename A9,
673 typename A10>
674class InvokeArgumentAction10 {
675 public:
676 InvokeArgumentAction10(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7,
677 A8 a8, A9 a9, A10 a10) :
678 arg1_(a1), arg2_(a2), arg3_(a3), arg4_(a4), arg5_(a5), arg6_(a6),
679 arg7_(a7), arg8_(a8), arg9_(a9), arg10_(a10) {}
680
681 template <typename Result, typename ArgumentTuple>
682 Result Perform(const ArgumentTuple& args) {
683 // We extract the callable to a variable before invoking it, in
684 // case it is a functor passed by value and its operator() is not
685 // const.
686 typename ::std::tr1::tuple_element<N, ArgumentTuple>::type function =
687 ::std::tr1::get<N>(args);
688 return function(arg1_, arg2_, arg3_, arg4_, arg5_, arg6_, arg7_, arg8_,
689 arg9_, arg10_);
690 }
691 private:
692 const A1 arg1_;
693 const A2 arg2_;
694 const A3 arg3_;
695 const A4 arg4_;
696 const A5 arg5_;
697 const A6 arg6_;
698 const A7 arg7_;
699 const A8 arg8_;
700 const A9 arg9_;
701 const A10 arg10_;
702};
703
704// An INTERNAL macro for extracting the type of a tuple field. It's
705// subject to change without notice - DO NOT USE IN USER CODE!
zhanyong.wane0d051e2009-02-19 00:33:37 +0000706#define GMOCK_FIELD_(Tuple, N) \
shiqiane35fdd92008-12-10 05:08:54 +0000707 typename ::std::tr1::tuple_element<N, Tuple>::type
708
709// SelectArgs<Result, ArgumentTuple, k1, k2, ..., k_n>::type is the
710// type of an n-ary function whose i-th (1-based) argument type is the
711// k{i}-th (0-based) field of ArgumentTuple, which must be a tuple
712// type, and whose return type is Result. For example,
713// SelectArgs<int, ::std::tr1::tuple<bool, char, double, long>, 0, 3>::type
714// is int(bool, long).
715//
716// SelectArgs<Result, ArgumentTuple, k1, k2, ..., k_n>::Select(args)
717// returns the selected fields (k1, k2, ..., k_n) of args as a tuple.
718// For example,
719// SelectArgs<int, ::std::tr1::tuple<bool, char, double>, 2, 0>::Select(
720// ::std::tr1::make_tuple(true, 'a', 2.5))
721// returns ::std::tr1::tuple (2.5, true).
722//
723// The numbers in list k1, k2, ..., k_n must be >= 0, where n can be
724// in the range [0, 10]. Duplicates are allowed and they don't have
725// to be in an ascending or descending order.
726
727template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
728 int k4, int k5, int k6, int k7, int k8, int k9, int k10>
729class SelectArgs {
730 public:
zhanyong.wane0d051e2009-02-19 00:33:37 +0000731 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
732 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
733 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5),
734 GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7),
735 GMOCK_FIELD_(ArgumentTuple, k8), GMOCK_FIELD_(ArgumentTuple, k9),
736 GMOCK_FIELD_(ArgumentTuple, k10));
shiqiane35fdd92008-12-10 05:08:54 +0000737 typedef typename Function<type>::ArgumentTuple SelectedArgs;
738 static SelectedArgs Select(const ArgumentTuple& args) {
739 using ::std::tr1::get;
740 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
741 get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args),
742 get<k8>(args), get<k9>(args), get<k10>(args));
743 }
744};
745
746template <typename Result, typename ArgumentTuple>
747class SelectArgs<Result, ArgumentTuple,
748 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1> {
749 public:
750 typedef Result type();
751 typedef typename Function<type>::ArgumentTuple SelectedArgs;
752 static SelectedArgs Select(const ArgumentTuple& args) {
753 using ::std::tr1::get;
754 return SelectedArgs();
755 }
756};
757
758template <typename Result, typename ArgumentTuple, int k1>
759class SelectArgs<Result, ArgumentTuple,
760 k1, -1, -1, -1, -1, -1, -1, -1, -1, -1> {
761 public:
zhanyong.wane0d051e2009-02-19 00:33:37 +0000762 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1));
shiqiane35fdd92008-12-10 05:08:54 +0000763 typedef typename Function<type>::ArgumentTuple SelectedArgs;
764 static SelectedArgs Select(const ArgumentTuple& args) {
765 using ::std::tr1::get;
766 return SelectedArgs(get<k1>(args));
767 }
768};
769
770template <typename Result, typename ArgumentTuple, int k1, int k2>
771class SelectArgs<Result, ArgumentTuple,
772 k1, k2, -1, -1, -1, -1, -1, -1, -1, -1> {
773 public:
zhanyong.wane0d051e2009-02-19 00:33:37 +0000774 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
775 GMOCK_FIELD_(ArgumentTuple, k2));
shiqiane35fdd92008-12-10 05:08:54 +0000776 typedef typename Function<type>::ArgumentTuple SelectedArgs;
777 static SelectedArgs Select(const ArgumentTuple& args) {
778 using ::std::tr1::get;
779 return SelectedArgs(get<k1>(args), get<k2>(args));
780 }
781};
782
783template <typename Result, typename ArgumentTuple, int k1, int k2, int k3>
784class SelectArgs<Result, ArgumentTuple,
785 k1, k2, k3, -1, -1, -1, -1, -1, -1, -1> {
786 public:
zhanyong.wane0d051e2009-02-19 00:33:37 +0000787 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
788 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3));
shiqiane35fdd92008-12-10 05:08:54 +0000789 typedef typename Function<type>::ArgumentTuple SelectedArgs;
790 static SelectedArgs Select(const ArgumentTuple& args) {
791 using ::std::tr1::get;
792 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args));
793 }
794};
795
796template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
797 int k4>
798class SelectArgs<Result, ArgumentTuple,
799 k1, k2, k3, k4, -1, -1, -1, -1, -1, -1> {
800 public:
zhanyong.wane0d051e2009-02-19 00:33:37 +0000801 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
802 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
803 GMOCK_FIELD_(ArgumentTuple, k4));
shiqiane35fdd92008-12-10 05:08:54 +0000804 typedef typename Function<type>::ArgumentTuple SelectedArgs;
805 static SelectedArgs Select(const ArgumentTuple& args) {
806 using ::std::tr1::get;
807 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
808 get<k4>(args));
809 }
810};
811
812template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
813 int k4, int k5>
814class SelectArgs<Result, ArgumentTuple,
815 k1, k2, k3, k4, k5, -1, -1, -1, -1, -1> {
816 public:
zhanyong.wane0d051e2009-02-19 00:33:37 +0000817 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
818 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
819 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5));
shiqiane35fdd92008-12-10 05:08:54 +0000820 typedef typename Function<type>::ArgumentTuple SelectedArgs;
821 static SelectedArgs Select(const ArgumentTuple& args) {
822 using ::std::tr1::get;
823 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
824 get<k4>(args), get<k5>(args));
825 }
826};
827
828template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
829 int k4, int k5, int k6>
830class SelectArgs<Result, ArgumentTuple,
831 k1, k2, k3, k4, k5, k6, -1, -1, -1, -1> {
832 public:
zhanyong.wane0d051e2009-02-19 00:33:37 +0000833 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
834 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
835 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5),
836 GMOCK_FIELD_(ArgumentTuple, k6));
shiqiane35fdd92008-12-10 05:08:54 +0000837 typedef typename Function<type>::ArgumentTuple SelectedArgs;
838 static SelectedArgs Select(const ArgumentTuple& args) {
839 using ::std::tr1::get;
840 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
841 get<k4>(args), get<k5>(args), get<k6>(args));
842 }
843};
844
845template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
846 int k4, int k5, int k6, int k7>
847class SelectArgs<Result, ArgumentTuple,
848 k1, k2, k3, k4, k5, k6, k7, -1, -1, -1> {
849 public:
zhanyong.wane0d051e2009-02-19 00:33:37 +0000850 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
851 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
852 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5),
853 GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7));
shiqiane35fdd92008-12-10 05:08:54 +0000854 typedef typename Function<type>::ArgumentTuple SelectedArgs;
855 static SelectedArgs Select(const ArgumentTuple& args) {
856 using ::std::tr1::get;
857 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
858 get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args));
859 }
860};
861
862template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
863 int k4, int k5, int k6, int k7, int k8>
864class SelectArgs<Result, ArgumentTuple,
865 k1, k2, k3, k4, k5, k6, k7, k8, -1, -1> {
866 public:
zhanyong.wane0d051e2009-02-19 00:33:37 +0000867 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
868 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
869 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5),
870 GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7),
871 GMOCK_FIELD_(ArgumentTuple, k8));
shiqiane35fdd92008-12-10 05:08:54 +0000872 typedef typename Function<type>::ArgumentTuple SelectedArgs;
873 static SelectedArgs Select(const ArgumentTuple& args) {
874 using ::std::tr1::get;
875 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
876 get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args),
877 get<k8>(args));
878 }
879};
880
881template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
882 int k4, int k5, int k6, int k7, int k8, int k9>
883class SelectArgs<Result, ArgumentTuple,
884 k1, k2, k3, k4, k5, k6, k7, k8, k9, -1> {
885 public:
zhanyong.wane0d051e2009-02-19 00:33:37 +0000886 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
887 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
888 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5),
889 GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7),
890 GMOCK_FIELD_(ArgumentTuple, k8), GMOCK_FIELD_(ArgumentTuple, k9));
shiqiane35fdd92008-12-10 05:08:54 +0000891 typedef typename Function<type>::ArgumentTuple SelectedArgs;
892 static SelectedArgs Select(const ArgumentTuple& args) {
893 using ::std::tr1::get;
894 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
895 get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args),
896 get<k8>(args), get<k9>(args));
897 }
898};
899
zhanyong.wane0d051e2009-02-19 00:33:37 +0000900#undef GMOCK_FIELD_
shiqiane35fdd92008-12-10 05:08:54 +0000901
902// Implements the WithArgs action.
903template <typename InnerAction, int k1 = -1, int k2 = -1, int k3 = -1,
904 int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1, int k8 = -1,
905 int k9 = -1, int k10 = -1>
906class WithArgsAction {
907 public:
908 explicit WithArgsAction(const InnerAction& action) : action_(action) {}
909
910 template <typename F>
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000911 operator Action<F>() const { return MakeAction(new Impl<F>(action_)); }
912
913 private:
914 template <typename F>
915 class Impl : public ActionInterface<F> {
916 public:
shiqiane35fdd92008-12-10 05:08:54 +0000917 typedef typename Function<F>::Result Result;
918 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000919
920 explicit Impl(const InnerAction& action) : action_(action) {}
921
922 virtual Result Perform(const ArgumentTuple& args) {
923 return action_.Perform(SelectArgs<Result, ArgumentTuple, k1, k2, k3, k4,
924 k5, k6, k7, k8, k9, k10>::Select(args));
925 }
926
927 private:
shiqiane35fdd92008-12-10 05:08:54 +0000928 typedef typename SelectArgs<Result, ArgumentTuple,
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000929 k1, k2, k3, k4, k5, k6, k7, k8, k9, k10>::type InnerFunctionType;
shiqiane35fdd92008-12-10 05:08:54 +0000930
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000931 Action<InnerFunctionType> action_;
932 };
shiqiane35fdd92008-12-10 05:08:54 +0000933
shiqiane35fdd92008-12-10 05:08:54 +0000934 const InnerAction action_;
935};
936
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000937
shiqiane35fdd92008-12-10 05:08:54 +0000938// Does two actions sequentially. Used for implementing the DoAll(a1,
939// a2, ...) action.
940template <typename Action1, typename Action2>
941class DoBothAction {
942 public:
943 DoBothAction(Action1 action1, Action2 action2)
944 : action1_(action1), action2_(action2) {}
945
946 // This template type conversion operator allows DoAll(a1, ..., a_n)
947 // to be used in ANY function of compatible type.
948 template <typename F>
949 operator Action<F>() const {
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000950 return Action<F>(new Impl<F>(action1_, action2_));
951 }
952
953 private:
954 // Implements the DoAll(...) action for a particular function type F.
955 template <typename F>
956 class Impl : public ActionInterface<F> {
957 public:
shiqiane35fdd92008-12-10 05:08:54 +0000958 typedef typename Function<F>::Result Result;
959 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
960 typedef typename Function<F>::MakeResultVoid VoidResult;
961
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000962 Impl(const Action<VoidResult>& action1, const Action<F>& action2)
963 : action1_(action1), action2_(action2) {}
shiqiane35fdd92008-12-10 05:08:54 +0000964
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000965 virtual Result Perform(const ArgumentTuple& args) {
966 action1_.Perform(args);
967 return action2_.Perform(args);
968 }
shiqiane35fdd92008-12-10 05:08:54 +0000969
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000970 private:
971 const Action<VoidResult> action1_;
972 const Action<F> action2_;
973 };
974
shiqiane35fdd92008-12-10 05:08:54 +0000975 Action1 action1_;
976 Action2 action2_;
977};
978
shiqian326aa562009-01-09 21:43:57 +0000979// A macro from the ACTION* family (defined later in this file)
980// defines an action that can be used in a mock function. Typically,
981// these actions only care about a subset of the arguments of the mock
982// function. For example, if such an action only uses the second
983// argument, it can be used in any mock function that takes >= 2
984// arguments where the type of the second argument is compatible.
985//
986// Therefore, the action implementation must be prepared to take more
987// arguments than it needs. The ExcessiveArg type is used to
988// represent those excessive arguments. In order to keep the compiler
989// error messages tractable, we define it in the testing namespace
990// instead of testing::internal. However, this is an INTERNAL TYPE
991// and subject to change without notice, so a user MUST NOT USE THIS
992// TYPE DIRECTLY.
993struct ExcessiveArg {};
994
995// A helper class needed for implementing the ACTION* macros.
996template <typename Result, class Impl>
997class ActionHelper {
998 public:
999 static Result Perform(Impl* impl, const ::std::tr1::tuple<>& args) {
1000 using ::std::tr1::get;
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00001001 return impl->template gmock_PerformImpl<>(args, ExcessiveArg(),
shiqian326aa562009-01-09 21:43:57 +00001002 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00001003 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
1004 ExcessiveArg());
shiqian326aa562009-01-09 21:43:57 +00001005 }
1006
1007 template <typename A0>
1008 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0>& args) {
1009 using ::std::tr1::get;
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00001010 return impl->template gmock_PerformImpl<A0>(args, get<0>(args),
shiqian326aa562009-01-09 21:43:57 +00001011 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00001012 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
1013 ExcessiveArg());
shiqian326aa562009-01-09 21:43:57 +00001014 }
1015
1016 template <typename A0, typename A1>
1017 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1>& args) {
1018 using ::std::tr1::get;
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00001019 return impl->template gmock_PerformImpl<A0, A1>(args, get<0>(args),
1020 get<1>(args), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
shiqian326aa562009-01-09 21:43:57 +00001021 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00001022 ExcessiveArg());
shiqian326aa562009-01-09 21:43:57 +00001023 }
1024
1025 template <typename A0, typename A1, typename A2>
1026 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2>& args) {
1027 using ::std::tr1::get;
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00001028 return impl->template gmock_PerformImpl<A0, A1, A2>(args, get<0>(args),
1029 get<1>(args), get<2>(args), ExcessiveArg(), ExcessiveArg(),
1030 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
1031 ExcessiveArg());
shiqian326aa562009-01-09 21:43:57 +00001032 }
1033
1034 template <typename A0, typename A1, typename A2, typename A3>
1035 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2,
1036 A3>& args) {
1037 using ::std::tr1::get;
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00001038 return impl->template gmock_PerformImpl<A0, A1, A2, A3>(args, get<0>(args),
1039 get<1>(args), get<2>(args), get<3>(args), ExcessiveArg(),
1040 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
1041 ExcessiveArg());
shiqian326aa562009-01-09 21:43:57 +00001042 }
1043
1044 template <typename A0, typename A1, typename A2, typename A3, typename A4>
1045 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3,
1046 A4>& args) {
1047 using ::std::tr1::get;
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00001048 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4>(args,
1049 get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args),
1050 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
1051 ExcessiveArg());
shiqian326aa562009-01-09 21:43:57 +00001052 }
1053
1054 template <typename A0, typename A1, typename A2, typename A3, typename A4,
1055 typename A5>
1056 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4,
1057 A5>& args) {
1058 using ::std::tr1::get;
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00001059 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5>(args,
1060 get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args),
1061 get<5>(args), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
1062 ExcessiveArg());
shiqian326aa562009-01-09 21:43:57 +00001063 }
1064
1065 template <typename A0, typename A1, typename A2, typename A3, typename A4,
1066 typename A5, typename A6>
1067 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4,
1068 A5, A6>& args) {
1069 using ::std::tr1::get;
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00001070 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6>(args,
1071 get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args),
1072 get<5>(args), get<6>(args), ExcessiveArg(), ExcessiveArg(),
1073 ExcessiveArg());
shiqian326aa562009-01-09 21:43:57 +00001074 }
1075
1076 template <typename A0, typename A1, typename A2, typename A3, typename A4,
1077 typename A5, typename A6, typename A7>
1078 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4,
1079 A5, A6, A7>& args) {
1080 using ::std::tr1::get;
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00001081 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6,
1082 A7>(args, get<0>(args), get<1>(args), get<2>(args), get<3>(args),
1083 get<4>(args), get<5>(args), get<6>(args), get<7>(args), ExcessiveArg(),
1084 ExcessiveArg());
shiqian326aa562009-01-09 21:43:57 +00001085 }
1086
1087 template <typename A0, typename A1, typename A2, typename A3, typename A4,
1088 typename A5, typename A6, typename A7, typename A8>
1089 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4,
1090 A5, A6, A7, A8>& args) {
1091 using ::std::tr1::get;
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00001092 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6, A7,
1093 A8>(args, get<0>(args), get<1>(args), get<2>(args), get<3>(args),
1094 get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args),
1095 ExcessiveArg());
shiqian326aa562009-01-09 21:43:57 +00001096 }
1097
1098 template <typename A0, typename A1, typename A2, typename A3, typename A4,
1099 typename A5, typename A6, typename A7, typename A8, typename A9>
1100 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4,
1101 A5, A6, A7, A8, A9>& args) {
1102 using ::std::tr1::get;
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00001103 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6, A7, A8,
1104 A9>(args, get<0>(args), get<1>(args), get<2>(args), get<3>(args),
1105 get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args),
1106 get<9>(args));
shiqian326aa562009-01-09 21:43:57 +00001107 }
1108};
1109
shiqiane35fdd92008-12-10 05:08:54 +00001110} // namespace internal
1111
1112// Various overloads for Invoke().
1113
1114// Creates an action that invokes 'function_impl' with the mock
1115// function's arguments.
1116template <typename FunctionImpl>
1117PolymorphicAction<internal::InvokeAction<FunctionImpl> > Invoke(
1118 FunctionImpl function_impl) {
1119 return MakePolymorphicAction(
1120 internal::InvokeAction<FunctionImpl>(function_impl));
1121}
1122
1123// Creates an action that invokes the given method on the given object
1124// with the mock function's arguments.
1125template <class Class, typename MethodPtr>
1126PolymorphicAction<internal::InvokeMethodAction<Class, MethodPtr> > Invoke(
1127 Class* obj_ptr, MethodPtr method_ptr) {
1128 return MakePolymorphicAction(
1129 internal::InvokeMethodAction<Class, MethodPtr>(obj_ptr, method_ptr));
1130}
1131
1132// Creates a reference wrapper for the given L-value. If necessary,
1133// you can explicitly specify the type of the reference. For example,
1134// suppose 'derived' is an object of type Derived, ByRef(derived)
1135// would wrap a Derived&. If you want to wrap a const Base& instead,
1136// where Base is a base class of Derived, just write:
1137//
1138// ByRef<const Base>(derived)
1139template <typename T>
1140inline internal::ReferenceWrapper<T> ByRef(T& l_value) { // NOLINT
1141 return internal::ReferenceWrapper<T>(l_value);
1142}
1143
1144// Various overloads for InvokeArgument<N>().
1145//
1146// The InvokeArgument<N>(a1, a2, ..., a_k) action invokes the N-th
1147// (0-based) argument, which must be a k-ary callable, of the mock
1148// function, with arguments a1, a2, ..., a_k.
1149//
1150// Notes:
1151//
1152// 1. The arguments are passed by value by default. If you need to
1153// pass an argument by reference, wrap it inside ByRef(). For
1154// example,
1155//
1156// InvokeArgument<1>(5, string("Hello"), ByRef(foo))
1157//
1158// passes 5 and string("Hello") by value, and passes foo by
1159// reference.
1160//
1161// 2. If the callable takes an argument by reference but ByRef() is
1162// not used, it will receive the reference to a copy of the value,
1163// instead of the original value. For example, when the 0-th
1164// argument of the mock function takes a const string&, the action
1165//
1166// InvokeArgument<0>(string("Hello"))
1167//
1168// makes a copy of the temporary string("Hello") object and passes a
1169// reference of the copy, instead of the original temporary object,
1170// to the callable. This makes it easy for a user to define an
1171// InvokeArgument action from temporary values and have it performed
1172// later.
1173template <size_t N>
1174inline PolymorphicAction<internal::InvokeArgumentAction0<N> > InvokeArgument() {
1175 return MakePolymorphicAction(internal::InvokeArgumentAction0<N>());
1176}
1177
1178// We deliberately pass a1 by value instead of const reference here in
1179// case it is a C-string literal. If we had declared the parameter as
1180// 'const A1& a1' and write InvokeArgument<0>("Hi"), the compiler
1181// would've thought A1 is 'char[3]', which causes trouble as the
1182// implementation needs to copy a value of type A1. By declaring the
1183// parameter as 'A1 a1', the compiler will correctly infer that A1 is
1184// 'const char*' when it sees InvokeArgument<0>("Hi").
1185//
1186// Since this function is defined inline, the compiler can get rid of
1187// the copying of the arguments. Therefore the performance won't be
1188// hurt.
1189template <size_t N, typename A1>
1190inline PolymorphicAction<internal::InvokeArgumentAction1<N, A1> >
1191InvokeArgument(A1 a1) {
1192 return MakePolymorphicAction(internal::InvokeArgumentAction1<N, A1>(a1));
1193}
1194
1195template <size_t N, typename A1, typename A2>
1196inline PolymorphicAction<internal::InvokeArgumentAction2<N, A1, A2> >
1197InvokeArgument(A1 a1, A2 a2) {
1198 return MakePolymorphicAction(
1199 internal::InvokeArgumentAction2<N, A1, A2>(a1, a2));
1200}
1201
1202template <size_t N, typename A1, typename A2, typename A3>
1203inline PolymorphicAction<internal::InvokeArgumentAction3<N, A1, A2, A3> >
1204InvokeArgument(A1 a1, A2 a2, A3 a3) {
1205 return MakePolymorphicAction(
1206 internal::InvokeArgumentAction3<N, A1, A2, A3>(a1, a2, a3));
1207}
1208
1209template <size_t N, typename A1, typename A2, typename A3, typename A4>
1210inline PolymorphicAction<internal::InvokeArgumentAction4<N, A1, A2, A3, A4> >
1211InvokeArgument(A1 a1, A2 a2, A3 a3, A4 a4) {
1212 return MakePolymorphicAction(
1213 internal::InvokeArgumentAction4<N, A1, A2, A3, A4>(a1, a2, a3, a4));
1214}
1215
1216template <size_t N, typename A1, typename A2, typename A3, typename A4,
1217 typename A5>
1218inline PolymorphicAction<internal::InvokeArgumentAction5<N, A1, A2, A3, A4,
1219 A5> >
1220InvokeArgument(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) {
1221 return MakePolymorphicAction(
1222 internal::InvokeArgumentAction5<N, A1, A2, A3, A4, A5>(a1, a2, a3, a4,
1223 a5));
1224}
1225
1226template <size_t N, typename A1, typename A2, typename A3, typename A4,
1227 typename A5, typename A6>
1228inline PolymorphicAction<internal::InvokeArgumentAction6<N, A1, A2, A3, A4, A5,
1229 A6> >
1230InvokeArgument(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) {
1231 return MakePolymorphicAction(
1232 internal::InvokeArgumentAction6<N, A1, A2, A3, A4, A5, A6>(a1, a2, a3,
1233 a4, a5, a6));
1234}
1235
1236template <size_t N, typename A1, typename A2, typename A3, typename A4,
1237 typename A5, typename A6, typename A7>
1238inline PolymorphicAction<internal::InvokeArgumentAction7<N, A1, A2, A3, A4, A5,
1239 A6, A7> >
1240InvokeArgument(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) {
1241 return MakePolymorphicAction(
1242 internal::InvokeArgumentAction7<N, A1, A2, A3, A4, A5, A6, A7>(a1, a2,
1243 a3, a4, a5, a6, a7));
1244}
1245
1246template <size_t N, typename A1, typename A2, typename A3, typename A4,
1247 typename A5, typename A6, typename A7, typename A8>
1248inline PolymorphicAction<internal::InvokeArgumentAction8<N, A1, A2, A3, A4, A5,
1249 A6, A7, A8> >
1250InvokeArgument(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) {
1251 return MakePolymorphicAction(
1252 internal::InvokeArgumentAction8<N, A1, A2, A3, A4, A5, A6, A7, A8>(a1,
1253 a2, a3, a4, a5, a6, a7, a8));
1254}
1255
1256template <size_t N, typename A1, typename A2, typename A3, typename A4,
1257 typename A5, typename A6, typename A7, typename A8, typename A9>
1258inline PolymorphicAction<internal::InvokeArgumentAction9<N, A1, A2, A3, A4, A5,
1259 A6, A7, A8, A9> >
1260InvokeArgument(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) {
1261 return MakePolymorphicAction(
1262 internal::InvokeArgumentAction9<N, A1, A2, A3, A4, A5, A6, A7, A8,
1263 A9>(a1, a2, a3, a4, a5, a6, a7, a8, a9));
1264}
1265
1266template <size_t N, typename A1, typename A2, typename A3, typename A4,
1267 typename A5, typename A6, typename A7, typename A8, typename A9,
1268 typename A10>
1269inline PolymorphicAction<internal::InvokeArgumentAction10<N, A1, A2, A3, A4,
1270 A5, A6, A7, A8, A9, A10> >
1271InvokeArgument(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9,
1272 A10 a10) {
1273 return MakePolymorphicAction(
1274 internal::InvokeArgumentAction10<N, A1, A2, A3, A4, A5, A6, A7, A8, A9,
1275 A10>(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10));
1276}
1277
1278// WithoutArgs(inner_action) can be used in a mock function with a
1279// non-empty argument list to perform inner_action, which takes no
1280// argument. In other words, it adapts an action accepting no
1281// argument to one that accepts (and ignores) arguments.
1282template <typename InnerAction>
1283inline internal::WithArgsAction<InnerAction>
1284WithoutArgs(const InnerAction& action) {
1285 return internal::WithArgsAction<InnerAction>(action);
1286}
1287
1288// WithArg<k>(an_action) creates an action that passes the k-th
1289// (0-based) argument of the mock function to an_action and performs
1290// it. It adapts an action accepting one argument to one that accepts
1291// multiple arguments. For convenience, we also provide
1292// WithArgs<k>(an_action) (defined below) as a synonym.
1293template <int k, typename InnerAction>
1294inline internal::WithArgsAction<InnerAction, k>
1295WithArg(const InnerAction& action) {
1296 return internal::WithArgsAction<InnerAction, k>(action);
1297}
1298
1299// WithArgs<N1, N2, ..., Nk>(an_action) creates an action that passes
1300// the selected arguments of the mock function to an_action and
1301// performs it. It serves as an adaptor between actions with
1302// different argument lists. C++ doesn't support default arguments for
1303// function templates, so we have to overload it.
1304template <int k1, typename InnerAction>
1305inline internal::WithArgsAction<InnerAction, k1>
1306WithArgs(const InnerAction& action) {
1307 return internal::WithArgsAction<InnerAction, k1>(action);
1308}
1309
1310template <int k1, int k2, typename InnerAction>
1311inline internal::WithArgsAction<InnerAction, k1, k2>
1312WithArgs(const InnerAction& action) {
1313 return internal::WithArgsAction<InnerAction, k1, k2>(action);
1314}
1315
1316template <int k1, int k2, int k3, typename InnerAction>
1317inline internal::WithArgsAction<InnerAction, k1, k2, k3>
1318WithArgs(const InnerAction& action) {
1319 return internal::WithArgsAction<InnerAction, k1, k2, k3>(action);
1320}
1321
1322template <int k1, int k2, int k3, int k4, typename InnerAction>
1323inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4>
1324WithArgs(const InnerAction& action) {
1325 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4>(action);
1326}
1327
1328template <int k1, int k2, int k3, int k4, int k5, typename InnerAction>
1329inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5>
1330WithArgs(const InnerAction& action) {
1331 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5>(action);
1332}
1333
1334template <int k1, int k2, int k3, int k4, int k5, int k6, typename InnerAction>
1335inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6>
1336WithArgs(const InnerAction& action) {
1337 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6>(action);
1338}
1339
1340template <int k1, int k2, int k3, int k4, int k5, int k6, int k7,
1341 typename InnerAction>
1342inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7>
1343WithArgs(const InnerAction& action) {
1344 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6,
1345 k7>(action);
1346}
1347
1348template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
1349 typename InnerAction>
1350inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8>
1351WithArgs(const InnerAction& action) {
1352 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7,
1353 k8>(action);
1354}
1355
1356template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
1357 int k9, typename InnerAction>
1358inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8, k9>
1359WithArgs(const InnerAction& action) {
1360 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8,
1361 k9>(action);
1362}
1363
1364template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
1365 int k9, int k10, typename InnerAction>
1366inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8,
1367 k9, k10>
1368WithArgs(const InnerAction& action) {
1369 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8,
1370 k9, k10>(action);
1371}
1372
1373// Creates an action that does actions a1, a2, ..., sequentially in
1374// each invocation.
1375template <typename Action1, typename Action2>
1376inline internal::DoBothAction<Action1, Action2>
1377DoAll(Action1 a1, Action2 a2) {
1378 return internal::DoBothAction<Action1, Action2>(a1, a2);
1379}
1380
1381template <typename Action1, typename Action2, typename Action3>
1382inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
1383 Action3> >
1384DoAll(Action1 a1, Action2 a2, Action3 a3) {
1385 return DoAll(a1, DoAll(a2, a3));
1386}
1387
1388template <typename Action1, typename Action2, typename Action3,
1389 typename Action4>
1390inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
1391 internal::DoBothAction<Action3, Action4> > >
1392DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4) {
1393 return DoAll(a1, DoAll(a2, a3, a4));
1394}
1395
1396template <typename Action1, typename Action2, typename Action3,
1397 typename Action4, typename Action5>
1398inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
1399 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
1400 Action5> > > >
1401DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5) {
1402 return DoAll(a1, DoAll(a2, a3, a4, a5));
1403}
1404
1405template <typename Action1, typename Action2, typename Action3,
1406 typename Action4, typename Action5, typename Action6>
1407inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
1408 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
1409 internal::DoBothAction<Action5, Action6> > > > >
1410DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6) {
1411 return DoAll(a1, DoAll(a2, a3, a4, a5, a6));
1412}
1413
1414template <typename Action1, typename Action2, typename Action3,
1415 typename Action4, typename Action5, typename Action6, typename Action7>
1416inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
1417 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
1418 internal::DoBothAction<Action5, internal::DoBothAction<Action6,
1419 Action7> > > > > >
1420DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
1421 Action7 a7) {
1422 return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7));
1423}
1424
1425template <typename Action1, typename Action2, typename Action3,
1426 typename Action4, typename Action5, typename Action6, typename Action7,
1427 typename Action8>
1428inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
1429 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
1430 internal::DoBothAction<Action5, internal::DoBothAction<Action6,
1431 internal::DoBothAction<Action7, Action8> > > > > > >
1432DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
1433 Action7 a7, Action8 a8) {
1434 return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8));
1435}
1436
1437template <typename Action1, typename Action2, typename Action3,
1438 typename Action4, typename Action5, typename Action6, typename Action7,
1439 typename Action8, typename Action9>
1440inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
1441 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
1442 internal::DoBothAction<Action5, internal::DoBothAction<Action6,
1443 internal::DoBothAction<Action7, internal::DoBothAction<Action8,
1444 Action9> > > > > > > >
1445DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
1446 Action7 a7, Action8 a8, Action9 a9) {
1447 return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8, a9));
1448}
1449
1450template <typename Action1, typename Action2, typename Action3,
1451 typename Action4, typename Action5, typename Action6, typename Action7,
1452 typename Action8, typename Action9, typename Action10>
1453inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
1454 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
1455 internal::DoBothAction<Action5, internal::DoBothAction<Action6,
1456 internal::DoBothAction<Action7, internal::DoBothAction<Action8,
1457 internal::DoBothAction<Action9, Action10> > > > > > > > >
1458DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
1459 Action7 a7, Action8 a8, Action9 a9, Action10 a10) {
1460 return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8, a9, a10));
1461}
1462
1463} // namespace testing
1464
shiqian326aa562009-01-09 21:43:57 +00001465// The ACTION* family of macros can be used in a namespace scope to
1466// define custom actions easily. The syntax:
1467//
1468// ACTION(name) { statements; }
1469//
1470// will define an action with the given name that executes the
1471// statements. The value returned by the statements will be used as
1472// the return value of the action. Inside the statements, you can
1473// refer to the K-th (0-based) argument of the mock function by
1474// 'argK', and refer to its type by 'argK_type'. For example:
1475//
1476// ACTION(IncrementArg1) {
1477// arg1_type temp = arg1;
1478// return ++(*temp);
1479// }
1480//
1481// allows you to write
1482//
1483// ...WillOnce(IncrementArg1());
1484//
1485// You can also refer to the entire argument tuple and its type by
1486// 'args' and 'args_type', and refer to the mock function type and its
1487// return type by 'function_type' and 'return_type'.
1488//
1489// Note that you don't need to specify the types of the mock function
1490// arguments. However rest assured that your code is still type-safe:
1491// you'll get a compiler error if *arg1 doesn't support the ++
1492// operator, or if the type of ++(*arg1) isn't compatible with the
1493// mock function's return type, for example.
1494//
1495// Sometimes you'll want to parameterize the action. For that you can use
1496// another macro:
1497//
1498// ACTION_P(name, param_name) { statements; }
1499//
1500// For example:
1501//
1502// ACTION_P(Add, n) { return arg0 + n; }
1503//
1504// will allow you to write:
1505//
1506// ...WillOnce(Add(5));
1507//
1508// Note that you don't need to provide the type of the parameter
1509// either. If you need to reference the type of a parameter named
1510// 'foo', you can write 'foo_type'. For example, in the body of
1511// ACTION_P(Add, n) above, you can write 'n_type' to refer to the type
1512// of 'n'.
1513//
1514// We also provide ACTION_P2, ACTION_P3, ..., up to ACTION_P10 to support
1515// multi-parameter actions.
1516//
1517// For the purpose of typing, you can view
1518//
1519// ACTION_Pk(Foo, p1, ..., pk) { ... }
1520//
1521// as shorthand for
1522//
1523// template <typename p1_type, ..., typename pk_type>
1524// FooActionPk<p1_type, ..., pk_type> Foo(p1_type p1, ..., pk_type pk) { ... }
1525//
1526// In particular, you can provide the template type arguments
1527// explicitly when invoking Foo(), as in Foo<long, bool>(5, false);
1528// although usually you can rely on the compiler to infer the types
1529// for you automatically. You can assign the result of expression
1530// Foo(p1, ..., pk) to a variable of type FooActionPk<p1_type, ...,
1531// pk_type>. This can be useful when composing actions.
1532//
1533// You can also overload actions with different numbers of parameters:
1534//
1535// ACTION_P(Plus, a) { ... }
1536// ACTION_P2(Plus, a, b) { ... }
1537//
1538// While it's tempting to always use the ACTION* macros when defining
1539// a new action, you should also consider implementing ActionInterface
1540// or using MakePolymorphicAction() instead, especially if you need to
1541// use the action a lot. While these approaches require more work,
1542// they give you more control on the types of the mock function
1543// arguments and the action parameters, which in general leads to
1544// better compiler error messages that pay off in the long run. They
1545// also allow overloading actions based on parameter types (as opposed
1546// to just based on the number of parameters).
1547//
1548// CAVEAT:
1549//
1550// ACTION*() can only be used in a namespace scope. The reason is
1551// that C++ doesn't yet allow function-local types to be used to
1552// instantiate templates. The up-coming C++0x standard will fix this.
1553// Once that's done, we'll consider supporting using ACTION*() inside
1554// a function.
1555//
1556// MORE INFORMATION:
1557//
1558// To learn more about using these macros, please search for 'ACTION'
1559// on http://code.google.com/p/googlemock/wiki/CookBook.
1560
1561#define ACTION(name)\
1562 class name##Action {\
1563 public:\
1564 name##Action() {}\
1565 template <typename F>\
1566 class gmock_Impl : public ::testing::ActionInterface<F> {\
1567 public:\
1568 typedef F function_type;\
1569 typedef typename ::testing::internal::Function<F>::Result return_type;\
1570 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
1571 args_type;\
1572 gmock_Impl() {}\
1573 virtual return_type Perform(const args_type& args) {\
1574 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
1575 Perform(this, args);\
1576 }\
1577 template <typename arg0_type, typename arg1_type, typename arg2_type, \
1578 typename arg3_type, typename arg4_type, typename arg5_type, \
1579 typename arg6_type, typename arg7_type, typename arg8_type, \
1580 typename arg9_type>\
1581 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
1582 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
1583 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
1584 arg9_type arg9) const;\
1585 };\
1586 template <typename F> operator ::testing::Action<F>() const {\
1587 return ::testing::Action<F>(new gmock_Impl<F>());\
1588 }\
1589 };\
1590 inline name##Action name() {\
1591 return name##Action();\
1592 }\
1593 template <typename F>\
1594 template <typename arg0_type, typename arg1_type, typename arg2_type, \
1595 typename arg3_type, typename arg4_type, typename arg5_type, \
1596 typename arg6_type, typename arg7_type, typename arg8_type, \
1597 typename arg9_type>\
1598 typename ::testing::internal::Function<F>::Result\
1599 name##Action::\
1600 gmock_Impl<F>::gmock_PerformImpl(const args_type& args, \
1601 arg0_type arg0, arg1_type arg1, arg2_type arg2, arg3_type arg3, \
1602 arg4_type arg4, arg5_type arg5, arg6_type arg6, arg7_type arg7, \
1603 arg8_type arg8, arg9_type arg9) const
1604
1605#define ACTION_P(name, p0)\
1606 template <typename p0##_type>\
1607 class name##ActionP {\
1608 public:\
1609 name##ActionP(p0##_type gmock_p0) : p0(gmock_p0) {}\
1610 template <typename F>\
1611 class gmock_Impl : public ::testing::ActionInterface<F> {\
1612 public:\
1613 typedef F function_type;\
1614 typedef typename ::testing::internal::Function<F>::Result return_type;\
1615 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
1616 args_type;\
1617 explicit gmock_Impl(p0##_type gmock_p0) : p0(gmock_p0) {}\
1618 virtual return_type Perform(const args_type& args) {\
1619 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
1620 Perform(this, args);\
1621 }\
1622 template <typename arg0_type, typename arg1_type, typename arg2_type, \
1623 typename arg3_type, typename arg4_type, typename arg5_type, \
1624 typename arg6_type, typename arg7_type, typename arg8_type, \
1625 typename arg9_type>\
1626 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
1627 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
1628 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
1629 arg9_type arg9) const;\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00001630 p0##_type p0;\
shiqian326aa562009-01-09 21:43:57 +00001631 };\
1632 template <typename F> operator ::testing::Action<F>() const {\
1633 return ::testing::Action<F>(new gmock_Impl<F>(p0));\
1634 }\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00001635 p0##_type p0;\
shiqian326aa562009-01-09 21:43:57 +00001636 };\
1637 template <typename p0##_type>\
1638 inline name##ActionP<p0##_type> name(p0##_type p0) {\
1639 return name##ActionP<p0##_type>(p0);\
1640 }\
1641 template <typename p0##_type>\
1642 template <typename F>\
1643 template <typename arg0_type, typename arg1_type, typename arg2_type, \
1644 typename arg3_type, typename arg4_type, typename arg5_type, \
1645 typename arg6_type, typename arg7_type, typename arg8_type, \
1646 typename arg9_type>\
1647 typename ::testing::internal::Function<F>::Result\
1648 name##ActionP<p0##_type>::\
1649 gmock_Impl<F>::gmock_PerformImpl(const args_type& args, \
1650 arg0_type arg0, arg1_type arg1, arg2_type arg2, arg3_type arg3, \
1651 arg4_type arg4, arg5_type arg5, arg6_type arg6, arg7_type arg7, \
1652 arg8_type arg8, arg9_type arg9) const
1653
1654#define ACTION_P2(name, p0, p1)\
1655 template <typename p0##_type, typename p1##_type>\
1656 class name##ActionP2 {\
1657 public:\
1658 name##ActionP2(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \
1659 p1(gmock_p1) {}\
1660 template <typename F>\
1661 class gmock_Impl : public ::testing::ActionInterface<F> {\
1662 public:\
1663 typedef F function_type;\
1664 typedef typename ::testing::internal::Function<F>::Result return_type;\
1665 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
1666 args_type;\
1667 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \
1668 p1(gmock_p1) {}\
1669 virtual return_type Perform(const args_type& args) {\
1670 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
1671 Perform(this, args);\
1672 }\
1673 template <typename arg0_type, typename arg1_type, typename arg2_type, \
1674 typename arg3_type, typename arg4_type, typename arg5_type, \
1675 typename arg6_type, typename arg7_type, typename arg8_type, \
1676 typename arg9_type>\
1677 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
1678 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
1679 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
1680 arg9_type arg9) const;\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00001681 p0##_type p0;\
1682 p1##_type p1;\
shiqian326aa562009-01-09 21:43:57 +00001683 };\
1684 template <typename F> operator ::testing::Action<F>() const {\
1685 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1));\
1686 }\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00001687 p0##_type p0;\
1688 p1##_type p1;\
shiqian326aa562009-01-09 21:43:57 +00001689 };\
1690 template <typename p0##_type, typename p1##_type>\
1691 inline name##ActionP2<p0##_type, p1##_type> name(p0##_type p0, \
1692 p1##_type p1) {\
1693 return name##ActionP2<p0##_type, p1##_type>(p0, p1);\
1694 }\
1695 template <typename p0##_type, typename p1##_type>\
1696 template <typename F>\
1697 template <typename arg0_type, typename arg1_type, typename arg2_type, \
1698 typename arg3_type, typename arg4_type, typename arg5_type, \
1699 typename arg6_type, typename arg7_type, typename arg8_type, \
1700 typename arg9_type>\
1701 typename ::testing::internal::Function<F>::Result\
1702 name##ActionP2<p0##_type, p1##_type>::\
1703 gmock_Impl<F>::gmock_PerformImpl(const args_type& args, \
1704 arg0_type arg0, arg1_type arg1, arg2_type arg2, arg3_type arg3, \
1705 arg4_type arg4, arg5_type arg5, arg6_type arg6, arg7_type arg7, \
1706 arg8_type arg8, arg9_type arg9) const
1707
1708#define ACTION_P3(name, p0, p1, p2)\
1709 template <typename p0##_type, typename p1##_type, typename p2##_type>\
1710 class name##ActionP3 {\
1711 public:\
1712 name##ActionP3(p0##_type gmock_p0, p1##_type gmock_p1, \
1713 p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\
1714 template <typename F>\
1715 class gmock_Impl : public ::testing::ActionInterface<F> {\
1716 public:\
1717 typedef F function_type;\
1718 typedef typename ::testing::internal::Function<F>::Result return_type;\
1719 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
1720 args_type;\
1721 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, \
1722 p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\
1723 virtual return_type Perform(const args_type& args) {\
1724 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
1725 Perform(this, args);\
1726 }\
1727 template <typename arg0_type, typename arg1_type, typename arg2_type, \
1728 typename arg3_type, typename arg4_type, typename arg5_type, \
1729 typename arg6_type, typename arg7_type, typename arg8_type, \
1730 typename arg9_type>\
1731 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
1732 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
1733 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
1734 arg9_type arg9) const;\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00001735 p0##_type p0;\
1736 p1##_type p1;\
1737 p2##_type p2;\
shiqian326aa562009-01-09 21:43:57 +00001738 };\
1739 template <typename F> operator ::testing::Action<F>() const {\
1740 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2));\
1741 }\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00001742 p0##_type p0;\
1743 p1##_type p1;\
1744 p2##_type p2;\
shiqian326aa562009-01-09 21:43:57 +00001745 };\
1746 template <typename p0##_type, typename p1##_type, typename p2##_type>\
1747 inline name##ActionP3<p0##_type, p1##_type, p2##_type> name(p0##_type p0, \
1748 p1##_type p1, p2##_type p2) {\
1749 return name##ActionP3<p0##_type, p1##_type, p2##_type>(p0, p1, p2);\
1750 }\
1751 template <typename p0##_type, typename p1##_type, typename p2##_type>\
1752 template <typename F>\
1753 template <typename arg0_type, typename arg1_type, typename arg2_type, \
1754 typename arg3_type, typename arg4_type, typename arg5_type, \
1755 typename arg6_type, typename arg7_type, typename arg8_type, \
1756 typename arg9_type>\
1757 typename ::testing::internal::Function<F>::Result\
1758 name##ActionP3<p0##_type, p1##_type, p2##_type>::\
1759 gmock_Impl<F>::gmock_PerformImpl(const args_type& args, \
1760 arg0_type arg0, arg1_type arg1, arg2_type arg2, arg3_type arg3, \
1761 arg4_type arg4, arg5_type arg5, arg6_type arg6, arg7_type arg7, \
1762 arg8_type arg8, arg9_type arg9) const
1763
1764#define ACTION_P4(name, p0, p1, p2, p3)\
1765 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1766 typename p3##_type>\
1767 class name##ActionP4 {\
1768 public:\
1769 name##ActionP4(p0##_type gmock_p0, p1##_type gmock_p1, \
1770 p2##_type gmock_p2, p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), \
1771 p2(gmock_p2), p3(gmock_p3) {}\
1772 template <typename F>\
1773 class gmock_Impl : public ::testing::ActionInterface<F> {\
1774 public:\
1775 typedef F function_type;\
1776 typedef typename ::testing::internal::Function<F>::Result return_type;\
1777 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
1778 args_type;\
1779 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
1780 p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
1781 p3(gmock_p3) {}\
1782 virtual return_type Perform(const args_type& args) {\
1783 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
1784 Perform(this, args);\
1785 }\
1786 template <typename arg0_type, typename arg1_type, typename arg2_type, \
1787 typename arg3_type, typename arg4_type, typename arg5_type, \
1788 typename arg6_type, typename arg7_type, typename arg8_type, \
1789 typename arg9_type>\
1790 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
1791 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
1792 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
1793 arg9_type arg9) const;\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00001794 p0##_type p0;\
1795 p1##_type p1;\
1796 p2##_type p2;\
1797 p3##_type p3;\
shiqian326aa562009-01-09 21:43:57 +00001798 };\
1799 template <typename F> operator ::testing::Action<F>() const {\
1800 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3));\
1801 }\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00001802 p0##_type p0;\
1803 p1##_type p1;\
1804 p2##_type p2;\
1805 p3##_type p3;\
shiqian326aa562009-01-09 21:43:57 +00001806 };\
1807 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1808 typename p3##_type>\
1809 inline name##ActionP4<p0##_type, p1##_type, p2##_type, \
1810 p3##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
1811 p3##_type p3) {\
1812 return name##ActionP4<p0##_type, p1##_type, p2##_type, p3##_type>(p0, p1, \
1813 p2, p3);\
1814 }\
1815 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1816 typename p3##_type>\
1817 template <typename F>\
1818 template <typename arg0_type, typename arg1_type, typename arg2_type, \
1819 typename arg3_type, typename arg4_type, typename arg5_type, \
1820 typename arg6_type, typename arg7_type, typename arg8_type, \
1821 typename arg9_type>\
1822 typename ::testing::internal::Function<F>::Result\
1823 name##ActionP4<p0##_type, p1##_type, p2##_type, p3##_type>::\
1824 gmock_Impl<F>::gmock_PerformImpl(const args_type& args, \
1825 arg0_type arg0, arg1_type arg1, arg2_type arg2, arg3_type arg3, \
1826 arg4_type arg4, arg5_type arg5, arg6_type arg6, arg7_type arg7, \
1827 arg8_type arg8, arg9_type arg9) const
1828
1829#define ACTION_P5(name, p0, p1, p2, p3, p4)\
1830 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1831 typename p3##_type, typename p4##_type>\
1832 class name##ActionP5 {\
1833 public:\
1834 name##ActionP5(p0##_type gmock_p0, p1##_type gmock_p1, \
1835 p2##_type gmock_p2, p3##_type gmock_p3, \
1836 p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
1837 p3(gmock_p3), p4(gmock_p4) {}\
1838 template <typename F>\
1839 class gmock_Impl : public ::testing::ActionInterface<F> {\
1840 public:\
1841 typedef F function_type;\
1842 typedef typename ::testing::internal::Function<F>::Result return_type;\
1843 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
1844 args_type;\
1845 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
1846 p3##_type gmock_p3, p4##_type gmock_p4) : p0(gmock_p0), \
1847 p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), p4(gmock_p4) {}\
1848 virtual return_type Perform(const args_type& args) {\
1849 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
1850 Perform(this, args);\
1851 }\
1852 template <typename arg0_type, typename arg1_type, typename arg2_type, \
1853 typename arg3_type, typename arg4_type, typename arg5_type, \
1854 typename arg6_type, typename arg7_type, typename arg8_type, \
1855 typename arg9_type>\
1856 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
1857 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
1858 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
1859 arg9_type arg9) const;\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00001860 p0##_type p0;\
1861 p1##_type p1;\
1862 p2##_type p2;\
1863 p3##_type p3;\
1864 p4##_type p4;\
shiqian326aa562009-01-09 21:43:57 +00001865 };\
1866 template <typename F> operator ::testing::Action<F>() const {\
1867 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4));\
1868 }\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00001869 p0##_type p0;\
1870 p1##_type p1;\
1871 p2##_type p2;\
1872 p3##_type p3;\
1873 p4##_type p4;\
shiqian326aa562009-01-09 21:43:57 +00001874 };\
1875 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1876 typename p3##_type, typename p4##_type>\
1877 inline name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \
1878 p4##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
1879 p4##_type p4) {\
1880 return name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \
1881 p4##_type>(p0, p1, p2, p3, p4);\
1882 }\
1883 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1884 typename p3##_type, typename p4##_type>\
1885 template <typename F>\
1886 template <typename arg0_type, typename arg1_type, typename arg2_type, \
1887 typename arg3_type, typename arg4_type, typename arg5_type, \
1888 typename arg6_type, typename arg7_type, typename arg8_type, \
1889 typename arg9_type>\
1890 typename ::testing::internal::Function<F>::Result\
1891 name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type>::\
1892 gmock_Impl<F>::gmock_PerformImpl(const args_type& args, \
1893 arg0_type arg0, arg1_type arg1, arg2_type arg2, arg3_type arg3, \
1894 arg4_type arg4, arg5_type arg5, arg6_type arg6, arg7_type arg7, \
1895 arg8_type arg8, arg9_type arg9) const
1896
1897#define ACTION_P6(name, p0, p1, p2, p3, p4, p5)\
1898 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1899 typename p3##_type, typename p4##_type, typename p5##_type>\
1900 class name##ActionP6 {\
1901 public:\
1902 name##ActionP6(p0##_type gmock_p0, p1##_type gmock_p1, \
1903 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
1904 p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
1905 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {}\
1906 template <typename F>\
1907 class gmock_Impl : public ::testing::ActionInterface<F> {\
1908 public:\
1909 typedef F function_type;\
1910 typedef typename ::testing::internal::Function<F>::Result return_type;\
1911 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
1912 args_type;\
1913 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
1914 p3##_type gmock_p3, p4##_type gmock_p4, \
1915 p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
1916 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {}\
1917 virtual return_type Perform(const args_type& args) {\
1918 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
1919 Perform(this, args);\
1920 }\
1921 template <typename arg0_type, typename arg1_type, typename arg2_type, \
1922 typename arg3_type, typename arg4_type, typename arg5_type, \
1923 typename arg6_type, typename arg7_type, typename arg8_type, \
1924 typename arg9_type>\
1925 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
1926 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
1927 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
1928 arg9_type arg9) const;\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00001929 p0##_type p0;\
1930 p1##_type p1;\
1931 p2##_type p2;\
1932 p3##_type p3;\
1933 p4##_type p4;\
1934 p5##_type p5;\
shiqian326aa562009-01-09 21:43:57 +00001935 };\
1936 template <typename F> operator ::testing::Action<F>() const {\
1937 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5));\
1938 }\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00001939 p0##_type p0;\
1940 p1##_type p1;\
1941 p2##_type p2;\
1942 p3##_type p3;\
1943 p4##_type p4;\
1944 p5##_type p5;\
shiqian326aa562009-01-09 21:43:57 +00001945 };\
1946 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1947 typename p3##_type, typename p4##_type, typename p5##_type>\
1948 inline name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, \
1949 p4##_type, p5##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
1950 p3##_type p3, p4##_type p4, p5##_type p5) {\
1951 return name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, \
1952 p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5);\
1953 }\
1954 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1955 typename p3##_type, typename p4##_type, typename p5##_type>\
1956 template <typename F>\
1957 template <typename arg0_type, typename arg1_type, typename arg2_type, \
1958 typename arg3_type, typename arg4_type, typename arg5_type, \
1959 typename arg6_type, typename arg7_type, typename arg8_type, \
1960 typename arg9_type>\
1961 typename ::testing::internal::Function<F>::Result\
1962 name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
1963 p5##_type>::\
1964 gmock_Impl<F>::gmock_PerformImpl(const args_type& args, \
1965 arg0_type arg0, arg1_type arg1, arg2_type arg2, arg3_type arg3, \
1966 arg4_type arg4, arg5_type arg5, arg6_type arg6, arg7_type arg7, \
1967 arg8_type arg8, arg9_type arg9) const
1968
1969#define ACTION_P7(name, p0, p1, p2, p3, p4, p5, p6)\
1970 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1971 typename p3##_type, typename p4##_type, typename p5##_type, \
1972 typename p6##_type>\
1973 class name##ActionP7 {\
1974 public:\
1975 name##ActionP7(p0##_type gmock_p0, p1##_type gmock_p1, \
1976 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
1977 p5##_type gmock_p5, p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), \
1978 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), \
1979 p6(gmock_p6) {}\
1980 template <typename F>\
1981 class gmock_Impl : public ::testing::ActionInterface<F> {\
1982 public:\
1983 typedef F function_type;\
1984 typedef typename ::testing::internal::Function<F>::Result return_type;\
1985 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
1986 args_type;\
1987 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
1988 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
1989 p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
1990 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6) {}\
1991 virtual return_type Perform(const args_type& args) {\
1992 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
1993 Perform(this, args);\
1994 }\
1995 template <typename arg0_type, typename arg1_type, typename arg2_type, \
1996 typename arg3_type, typename arg4_type, typename arg5_type, \
1997 typename arg6_type, typename arg7_type, typename arg8_type, \
1998 typename arg9_type>\
1999 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
2000 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
2001 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
2002 arg9_type arg9) const;\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00002003 p0##_type p0;\
2004 p1##_type p1;\
2005 p2##_type p2;\
2006 p3##_type p3;\
2007 p4##_type p4;\
2008 p5##_type p5;\
2009 p6##_type p6;\
shiqian326aa562009-01-09 21:43:57 +00002010 };\
2011 template <typename F> operator ::testing::Action<F>() const {\
2012 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
2013 p6));\
2014 }\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00002015 p0##_type p0;\
2016 p1##_type p1;\
2017 p2##_type p2;\
2018 p3##_type p3;\
2019 p4##_type p4;\
2020 p5##_type p5;\
2021 p6##_type p6;\
shiqian326aa562009-01-09 21:43:57 +00002022 };\
2023 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2024 typename p3##_type, typename p4##_type, typename p5##_type, \
2025 typename p6##_type>\
2026 inline name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, \
2027 p4##_type, p5##_type, p6##_type> name(p0##_type p0, p1##_type p1, \
2028 p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
2029 p6##_type p6) {\
2030 return name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, \
2031 p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, p6);\
2032 }\
2033 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2034 typename p3##_type, typename p4##_type, typename p5##_type, \
2035 typename p6##_type>\
2036 template <typename F>\
2037 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2038 typename arg3_type, typename arg4_type, typename arg5_type, \
2039 typename arg6_type, typename arg7_type, typename arg8_type, \
2040 typename arg9_type>\
2041 typename ::testing::internal::Function<F>::Result\
2042 name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
2043 p5##_type, p6##_type>::\
2044 gmock_Impl<F>::gmock_PerformImpl(const args_type& args, \
2045 arg0_type arg0, arg1_type arg1, arg2_type arg2, arg3_type arg3, \
2046 arg4_type arg4, arg5_type arg5, arg6_type arg6, arg7_type arg7, \
2047 arg8_type arg8, arg9_type arg9) const
2048
2049#define ACTION_P8(name, p0, p1, p2, p3, p4, p5, p6, p7)\
2050 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2051 typename p3##_type, typename p4##_type, typename p5##_type, \
2052 typename p6##_type, typename p7##_type>\
2053 class name##ActionP8 {\
2054 public:\
2055 name##ActionP8(p0##_type gmock_p0, p1##_type gmock_p1, \
2056 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
2057 p5##_type gmock_p5, p6##_type gmock_p6, \
2058 p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
2059 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
2060 p7(gmock_p7) {}\
2061 template <typename F>\
2062 class gmock_Impl : public ::testing::ActionInterface<F> {\
2063 public:\
2064 typedef F function_type;\
2065 typedef typename ::testing::internal::Function<F>::Result return_type;\
2066 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
2067 args_type;\
2068 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
2069 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
2070 p6##_type gmock_p6, p7##_type gmock_p7) : p0(gmock_p0), \
2071 p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), \
2072 p5(gmock_p5), p6(gmock_p6), p7(gmock_p7) {}\
2073 virtual return_type Perform(const args_type& args) {\
2074 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
2075 Perform(this, args);\
2076 }\
2077 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2078 typename arg3_type, typename arg4_type, typename arg5_type, \
2079 typename arg6_type, typename arg7_type, typename arg8_type, \
2080 typename arg9_type>\
2081 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
2082 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
2083 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
2084 arg9_type arg9) const;\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00002085 p0##_type p0;\
2086 p1##_type p1;\
2087 p2##_type p2;\
2088 p3##_type p3;\
2089 p4##_type p4;\
2090 p5##_type p5;\
2091 p6##_type p6;\
2092 p7##_type p7;\
shiqian326aa562009-01-09 21:43:57 +00002093 };\
2094 template <typename F> operator ::testing::Action<F>() const {\
2095 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
2096 p6, p7));\
2097 }\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00002098 p0##_type p0;\
2099 p1##_type p1;\
2100 p2##_type p2;\
2101 p3##_type p3;\
2102 p4##_type p4;\
2103 p5##_type p5;\
2104 p6##_type p6;\
2105 p7##_type p7;\
shiqian326aa562009-01-09 21:43:57 +00002106 };\
2107 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2108 typename p3##_type, typename p4##_type, typename p5##_type, \
2109 typename p6##_type, typename p7##_type>\
2110 inline name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, \
2111 p4##_type, p5##_type, p6##_type, p7##_type> name(p0##_type p0, \
2112 p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
2113 p6##_type p6, p7##_type p7) {\
2114 return name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, \
2115 p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, p3, p4, p5, \
2116 p6, p7);\
2117 }\
2118 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2119 typename p3##_type, typename p4##_type, typename p5##_type, \
2120 typename p6##_type, typename p7##_type>\
2121 template <typename F>\
2122 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2123 typename arg3_type, typename arg4_type, typename arg5_type, \
2124 typename arg6_type, typename arg7_type, typename arg8_type, \
2125 typename arg9_type>\
2126 typename ::testing::internal::Function<F>::Result\
2127 name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
2128 p5##_type, p6##_type, p7##_type>::\
2129 gmock_Impl<F>::gmock_PerformImpl(const args_type& args, \
2130 arg0_type arg0, arg1_type arg1, arg2_type arg2, arg3_type arg3, \
2131 arg4_type arg4, arg5_type arg5, arg6_type arg6, arg7_type arg7, \
2132 arg8_type arg8, arg9_type arg9) const
2133
2134#define ACTION_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8)\
2135 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2136 typename p3##_type, typename p4##_type, typename p5##_type, \
2137 typename p6##_type, typename p7##_type, typename p8##_type>\
2138 class name##ActionP9 {\
2139 public:\
2140 name##ActionP9(p0##_type gmock_p0, p1##_type gmock_p1, \
2141 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
2142 p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
2143 p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
2144 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
2145 p8(gmock_p8) {}\
2146 template <typename F>\
2147 class gmock_Impl : public ::testing::ActionInterface<F> {\
2148 public:\
2149 typedef F function_type;\
2150 typedef typename ::testing::internal::Function<F>::Result return_type;\
2151 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
2152 args_type;\
2153 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
2154 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
2155 p6##_type gmock_p6, p7##_type gmock_p7, \
2156 p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
2157 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
2158 p7(gmock_p7), p8(gmock_p8) {}\
2159 virtual return_type Perform(const args_type& args) {\
2160 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
2161 Perform(this, args);\
2162 }\
2163 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2164 typename arg3_type, typename arg4_type, typename arg5_type, \
2165 typename arg6_type, typename arg7_type, typename arg8_type, \
2166 typename arg9_type>\
2167 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
2168 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
2169 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
2170 arg9_type arg9) const;\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00002171 p0##_type p0;\
2172 p1##_type p1;\
2173 p2##_type p2;\
2174 p3##_type p3;\
2175 p4##_type p4;\
2176 p5##_type p5;\
2177 p6##_type p6;\
2178 p7##_type p7;\
2179 p8##_type p8;\
shiqian326aa562009-01-09 21:43:57 +00002180 };\
2181 template <typename F> operator ::testing::Action<F>() const {\
2182 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
2183 p6, p7, p8));\
2184 }\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00002185 p0##_type p0;\
2186 p1##_type p1;\
2187 p2##_type p2;\
2188 p3##_type p3;\
2189 p4##_type p4;\
2190 p5##_type p5;\
2191 p6##_type p6;\
2192 p7##_type p7;\
2193 p8##_type p8;\
shiqian326aa562009-01-09 21:43:57 +00002194 };\
2195 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2196 typename p3##_type, typename p4##_type, typename p5##_type, \
2197 typename p6##_type, typename p7##_type, typename p8##_type>\
2198 inline name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, \
2199 p4##_type, p5##_type, p6##_type, p7##_type, \
2200 p8##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
2201 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, \
2202 p8##_type p8) {\
2203 return name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, \
2204 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type>(p0, p1, p2, \
2205 p3, p4, p5, p6, p7, p8);\
2206 }\
2207 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2208 typename p3##_type, typename p4##_type, typename p5##_type, \
2209 typename p6##_type, typename p7##_type, typename p8##_type>\
2210 template <typename F>\
2211 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2212 typename arg3_type, typename arg4_type, typename arg5_type, \
2213 typename arg6_type, typename arg7_type, typename arg8_type, \
2214 typename arg9_type>\
2215 typename ::testing::internal::Function<F>::Result\
2216 name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
2217 p5##_type, p6##_type, p7##_type, p8##_type>::\
2218 gmock_Impl<F>::gmock_PerformImpl(const args_type& args, \
2219 arg0_type arg0, arg1_type arg1, arg2_type arg2, arg3_type arg3, \
2220 arg4_type arg4, arg5_type arg5, arg6_type arg6, arg7_type arg7, \
2221 arg8_type arg8, arg9_type arg9) const
2222
2223#define ACTION_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)\
2224 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2225 typename p3##_type, typename p4##_type, typename p5##_type, \
2226 typename p6##_type, typename p7##_type, typename p8##_type, \
2227 typename p9##_type>\
2228 class name##ActionP10 {\
2229 public:\
2230 name##ActionP10(p0##_type gmock_p0, p1##_type gmock_p1, \
2231 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
2232 p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
2233 p8##_type gmock_p8, p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), \
2234 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
2235 p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {}\
2236 template <typename F>\
2237 class gmock_Impl : public ::testing::ActionInterface<F> {\
2238 public:\
2239 typedef F function_type;\
2240 typedef typename ::testing::internal::Function<F>::Result return_type;\
2241 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
2242 args_type;\
2243 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
2244 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
2245 p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
2246 p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
2247 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
2248 p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {}\
2249 virtual return_type Perform(const args_type& args) {\
2250 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
2251 Perform(this, args);\
2252 }\
2253 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2254 typename arg3_type, typename arg4_type, typename arg5_type, \
2255 typename arg6_type, typename arg7_type, typename arg8_type, \
2256 typename arg9_type>\
2257 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
2258 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
2259 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
2260 arg9_type arg9) const;\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00002261 p0##_type p0;\
2262 p1##_type p1;\
2263 p2##_type p2;\
2264 p3##_type p3;\
2265 p4##_type p4;\
2266 p5##_type p5;\
2267 p6##_type p6;\
2268 p7##_type p7;\
2269 p8##_type p8;\
2270 p9##_type p9;\
shiqian326aa562009-01-09 21:43:57 +00002271 };\
2272 template <typename F> operator ::testing::Action<F>() const {\
2273 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
2274 p6, p7, p8, p9));\
2275 }\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00002276 p0##_type p0;\
2277 p1##_type p1;\
2278 p2##_type p2;\
2279 p3##_type p3;\
2280 p4##_type p4;\
2281 p5##_type p5;\
2282 p6##_type p6;\
2283 p7##_type p7;\
2284 p8##_type p8;\
2285 p9##_type p9;\
shiqian326aa562009-01-09 21:43:57 +00002286 };\
2287 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2288 typename p3##_type, typename p4##_type, typename p5##_type, \
2289 typename p6##_type, typename p7##_type, typename p8##_type, \
2290 typename p9##_type>\
2291 inline name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, \
2292 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
2293 p9##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
2294 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \
2295 p9##_type p9) {\
2296 return name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, \
2297 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, p9##_type>(p0, \
2298 p1, p2, p3, p4, p5, p6, p7, p8, p9);\
2299 }\
2300 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2301 typename p3##_type, typename p4##_type, typename p5##_type, \
2302 typename p6##_type, typename p7##_type, typename p8##_type, \
2303 typename p9##_type>\
2304 template <typename F>\
2305 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2306 typename arg3_type, typename arg4_type, typename arg5_type, \
2307 typename arg6_type, typename arg7_type, typename arg8_type, \
2308 typename arg9_type>\
2309 typename ::testing::internal::Function<F>::Result\
2310 name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
2311 p5##_type, p6##_type, p7##_type, p8##_type, p9##_type>::\
2312 gmock_Impl<F>::gmock_PerformImpl(const args_type& args, \
2313 arg0_type arg0, arg1_type arg1, arg2_type arg2, arg3_type arg3, \
2314 arg4_type arg4, arg5_type arg5, arg6_type arg6, arg7_type arg7, \
2315 arg8_type arg8, arg9_type arg9) const
2316
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00002317// TODO(wan@google.com): move the following to a different .h file
2318// such that we don't have to run 'pump' every time the code is
2319// updated.
zhanyong.wane1cdce52009-02-06 01:09:43 +00002320namespace testing {
2321
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00002322namespace internal {
2323
2324// Saves argument #0 to where the pointer points.
2325ACTION_P(SaveArg0, pointer) { *pointer = arg0; }
2326
2327// Assigns 'value' to the variable referenced by argument #0.
2328ACTION_P(SetArg0Referee, value) {
2329 // Ensures that argument #0 is a reference. If you get a compiler
2330 // error on the next line, you are using SetArgReferee<k>(value) in
2331 // a mock function whose k-th (0-based) argument is not a reference.
2332 GMOCK_COMPILE_ASSERT_(internal::is_reference<arg0_type>::value,
2333 SetArgReferee_must_be_used_with_a_reference_argument);
2334 arg0 = value;
2335}
2336
2337} // namespace internal
2338
2339// Action SaveArg<k>(pointer) saves the k-th (0-based) argument of the
2340// mock function to *pointer.
2341template <int k, typename Pointer>
2342inline internal::WithArgsAction<internal::SaveArg0ActionP<Pointer>, k>
2343SaveArg(const Pointer& pointer) {
2344 return WithArg<k>(internal::SaveArg0(pointer));
2345}
2346
2347// Action SetArgReferee<k>(value) assigns 'value' to the variable
2348// referenced by the k-th (0-based) argument of the mock function.
2349template <int k, typename Value>
2350inline internal::WithArgsAction<internal::SetArg0RefereeActionP<Value>, k>
2351SetArgReferee(const Value& value) {
2352 return WithArg<k>(internal::SetArg0Referee(value));
2353}
2354
zhanyong.wane1cdce52009-02-06 01:09:43 +00002355// Action Throw(exception) can be used in a mock function of any type
2356// to throw the given exception. Any copyable value can be thrown.
2357#if GTEST_HAS_EXCEPTIONS
2358ACTION_P(Throw, exception) { throw exception; }
2359#endif // GTEST_HAS_EXCEPTIONS
2360
2361} // namespace testing
2362
shiqiane35fdd92008-12-10 05:08:54 +00002363#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_