blob: 6d49c600255bcbd96951baa2231c090af4fa02ec [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;
zhanyong.wan3fbd2dd2009-03-26 19:06:45 +0000752 static SelectedArgs Select(const ArgumentTuple& /* args */) {
shiqiane35fdd92008-12-10 05:08:54 +0000753 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
937// Does two actions sequentially. Used for implementing the DoAll(a1,
938// a2, ...) action.
939template <typename Action1, typename Action2>
940class DoBothAction {
941 public:
942 DoBothAction(Action1 action1, Action2 action2)
943 : action1_(action1), action2_(action2) {}
944
945 // This template type conversion operator allows DoAll(a1, ..., a_n)
946 // to be used in ANY function of compatible type.
947 template <typename F>
948 operator Action<F>() const {
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000949 return Action<F>(new Impl<F>(action1_, action2_));
950 }
951
952 private:
953 // Implements the DoAll(...) action for a particular function type F.
954 template <typename F>
955 class Impl : public ActionInterface<F> {
956 public:
shiqiane35fdd92008-12-10 05:08:54 +0000957 typedef typename Function<F>::Result Result;
958 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
959 typedef typename Function<F>::MakeResultVoid VoidResult;
960
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000961 Impl(const Action<VoidResult>& action1, const Action<F>& action2)
962 : action1_(action1), action2_(action2) {}
shiqiane35fdd92008-12-10 05:08:54 +0000963
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000964 virtual Result Perform(const ArgumentTuple& args) {
965 action1_.Perform(args);
966 return action2_.Perform(args);
967 }
shiqiane35fdd92008-12-10 05:08:54 +0000968
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000969 private:
970 const Action<VoidResult> action1_;
971 const Action<F> action2_;
972 };
973
shiqiane35fdd92008-12-10 05:08:54 +0000974 Action1 action1_;
975 Action2 action2_;
976};
977
shiqian326aa562009-01-09 21:43:57 +0000978// A macro from the ACTION* family (defined later in this file)
979// defines an action that can be used in a mock function. Typically,
980// these actions only care about a subset of the arguments of the mock
981// function. For example, if such an action only uses the second
982// argument, it can be used in any mock function that takes >= 2
983// arguments where the type of the second argument is compatible.
984//
985// Therefore, the action implementation must be prepared to take more
986// arguments than it needs. The ExcessiveArg type is used to
987// represent those excessive arguments. In order to keep the compiler
988// error messages tractable, we define it in the testing namespace
989// instead of testing::internal. However, this is an INTERNAL TYPE
990// and subject to change without notice, so a user MUST NOT USE THIS
991// TYPE DIRECTLY.
992struct ExcessiveArg {};
993
994// A helper class needed for implementing the ACTION* macros.
995template <typename Result, class Impl>
996class ActionHelper {
997 public:
998 static Result Perform(Impl* impl, const ::std::tr1::tuple<>& args) {
999 using ::std::tr1::get;
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00001000 return impl->template gmock_PerformImpl<>(args, ExcessiveArg(),
shiqian326aa562009-01-09 21:43:57 +00001001 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00001002 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
1003 ExcessiveArg());
shiqian326aa562009-01-09 21:43:57 +00001004 }
1005
1006 template <typename A0>
1007 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0>& args) {
1008 using ::std::tr1::get;
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00001009 return impl->template gmock_PerformImpl<A0>(args, get<0>(args),
shiqian326aa562009-01-09 21:43:57 +00001010 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00001011 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
1012 ExcessiveArg());
shiqian326aa562009-01-09 21:43:57 +00001013 }
1014
1015 template <typename A0, typename A1>
1016 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1>& args) {
1017 using ::std::tr1::get;
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00001018 return impl->template gmock_PerformImpl<A0, A1>(args, get<0>(args),
1019 get<1>(args), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
shiqian326aa562009-01-09 21:43:57 +00001020 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00001021 ExcessiveArg());
shiqian326aa562009-01-09 21:43:57 +00001022 }
1023
1024 template <typename A0, typename A1, typename A2>
1025 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2>& args) {
1026 using ::std::tr1::get;
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00001027 return impl->template gmock_PerformImpl<A0, A1, A2>(args, get<0>(args),
1028 get<1>(args), get<2>(args), ExcessiveArg(), ExcessiveArg(),
1029 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
1030 ExcessiveArg());
shiqian326aa562009-01-09 21:43:57 +00001031 }
1032
1033 template <typename A0, typename A1, typename A2, typename A3>
1034 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2,
1035 A3>& args) {
1036 using ::std::tr1::get;
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00001037 return impl->template gmock_PerformImpl<A0, A1, A2, A3>(args, get<0>(args),
1038 get<1>(args), get<2>(args), get<3>(args), ExcessiveArg(),
1039 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
1040 ExcessiveArg());
shiqian326aa562009-01-09 21:43:57 +00001041 }
1042
1043 template <typename A0, typename A1, typename A2, typename A3, typename A4>
1044 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3,
1045 A4>& args) {
1046 using ::std::tr1::get;
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00001047 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4>(args,
1048 get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args),
1049 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
1050 ExcessiveArg());
shiqian326aa562009-01-09 21:43:57 +00001051 }
1052
1053 template <typename A0, typename A1, typename A2, typename A3, typename A4,
1054 typename A5>
1055 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4,
1056 A5>& args) {
1057 using ::std::tr1::get;
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00001058 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5>(args,
1059 get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args),
1060 get<5>(args), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
1061 ExcessiveArg());
shiqian326aa562009-01-09 21:43:57 +00001062 }
1063
1064 template <typename A0, typename A1, typename A2, typename A3, typename A4,
1065 typename A5, typename A6>
1066 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4,
1067 A5, A6>& args) {
1068 using ::std::tr1::get;
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00001069 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6>(args,
1070 get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args),
1071 get<5>(args), get<6>(args), ExcessiveArg(), ExcessiveArg(),
1072 ExcessiveArg());
shiqian326aa562009-01-09 21:43:57 +00001073 }
1074
1075 template <typename A0, typename A1, typename A2, typename A3, typename A4,
1076 typename A5, typename A6, typename A7>
1077 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4,
1078 A5, A6, A7>& args) {
1079 using ::std::tr1::get;
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00001080 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6,
1081 A7>(args, get<0>(args), get<1>(args), get<2>(args), get<3>(args),
1082 get<4>(args), get<5>(args), get<6>(args), get<7>(args), ExcessiveArg(),
1083 ExcessiveArg());
shiqian326aa562009-01-09 21:43:57 +00001084 }
1085
1086 template <typename A0, typename A1, typename A2, typename A3, typename A4,
1087 typename A5, typename A6, typename A7, typename A8>
1088 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4,
1089 A5, A6, A7, A8>& args) {
1090 using ::std::tr1::get;
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00001091 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6, A7,
1092 A8>(args, get<0>(args), get<1>(args), get<2>(args), get<3>(args),
1093 get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args),
1094 ExcessiveArg());
shiqian326aa562009-01-09 21:43:57 +00001095 }
1096
1097 template <typename A0, typename A1, typename A2, typename A3, typename A4,
1098 typename A5, typename A6, typename A7, typename A8, typename A9>
1099 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4,
1100 A5, A6, A7, A8, A9>& args) {
1101 using ::std::tr1::get;
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00001102 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6, A7, A8,
1103 A9>(args, get<0>(args), get<1>(args), get<2>(args), get<3>(args),
1104 get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args),
1105 get<9>(args));
shiqian326aa562009-01-09 21:43:57 +00001106 }
1107};
1108
shiqiane35fdd92008-12-10 05:08:54 +00001109} // namespace internal
1110
1111// Various overloads for Invoke().
1112
1113// Creates an action that invokes 'function_impl' with the mock
1114// function's arguments.
1115template <typename FunctionImpl>
1116PolymorphicAction<internal::InvokeAction<FunctionImpl> > Invoke(
1117 FunctionImpl function_impl) {
1118 return MakePolymorphicAction(
1119 internal::InvokeAction<FunctionImpl>(function_impl));
1120}
1121
1122// Creates an action that invokes the given method on the given object
1123// with the mock function's arguments.
1124template <class Class, typename MethodPtr>
1125PolymorphicAction<internal::InvokeMethodAction<Class, MethodPtr> > Invoke(
1126 Class* obj_ptr, MethodPtr method_ptr) {
1127 return MakePolymorphicAction(
1128 internal::InvokeMethodAction<Class, MethodPtr>(obj_ptr, method_ptr));
1129}
1130
1131// Creates a reference wrapper for the given L-value. If necessary,
1132// you can explicitly specify the type of the reference. For example,
1133// suppose 'derived' is an object of type Derived, ByRef(derived)
1134// would wrap a Derived&. If you want to wrap a const Base& instead,
1135// where Base is a base class of Derived, just write:
1136//
1137// ByRef<const Base>(derived)
1138template <typename T>
1139inline internal::ReferenceWrapper<T> ByRef(T& l_value) { // NOLINT
1140 return internal::ReferenceWrapper<T>(l_value);
1141}
1142
1143// Various overloads for InvokeArgument<N>().
1144//
1145// The InvokeArgument<N>(a1, a2, ..., a_k) action invokes the N-th
1146// (0-based) argument, which must be a k-ary callable, of the mock
1147// function, with arguments a1, a2, ..., a_k.
1148//
1149// Notes:
1150//
1151// 1. The arguments are passed by value by default. If you need to
1152// pass an argument by reference, wrap it inside ByRef(). For
1153// example,
1154//
1155// InvokeArgument<1>(5, string("Hello"), ByRef(foo))
1156//
1157// passes 5 and string("Hello") by value, and passes foo by
1158// reference.
1159//
1160// 2. If the callable takes an argument by reference but ByRef() is
1161// not used, it will receive the reference to a copy of the value,
1162// instead of the original value. For example, when the 0-th
1163// argument of the mock function takes a const string&, the action
1164//
1165// InvokeArgument<0>(string("Hello"))
1166//
1167// makes a copy of the temporary string("Hello") object and passes a
1168// reference of the copy, instead of the original temporary object,
1169// to the callable. This makes it easy for a user to define an
1170// InvokeArgument action from temporary values and have it performed
1171// later.
1172template <size_t N>
1173inline PolymorphicAction<internal::InvokeArgumentAction0<N> > InvokeArgument() {
1174 return MakePolymorphicAction(internal::InvokeArgumentAction0<N>());
1175}
1176
1177// We deliberately pass a1 by value instead of const reference here in
1178// case it is a C-string literal. If we had declared the parameter as
1179// 'const A1& a1' and write InvokeArgument<0>("Hi"), the compiler
1180// would've thought A1 is 'char[3]', which causes trouble as the
1181// implementation needs to copy a value of type A1. By declaring the
1182// parameter as 'A1 a1', the compiler will correctly infer that A1 is
1183// 'const char*' when it sees InvokeArgument<0>("Hi").
1184//
1185// Since this function is defined inline, the compiler can get rid of
1186// the copying of the arguments. Therefore the performance won't be
1187// hurt.
1188template <size_t N, typename A1>
1189inline PolymorphicAction<internal::InvokeArgumentAction1<N, A1> >
1190InvokeArgument(A1 a1) {
1191 return MakePolymorphicAction(internal::InvokeArgumentAction1<N, A1>(a1));
1192}
1193
1194template <size_t N, typename A1, typename A2>
1195inline PolymorphicAction<internal::InvokeArgumentAction2<N, A1, A2> >
1196InvokeArgument(A1 a1, A2 a2) {
1197 return MakePolymorphicAction(
1198 internal::InvokeArgumentAction2<N, A1, A2>(a1, a2));
1199}
1200
1201template <size_t N, typename A1, typename A2, typename A3>
1202inline PolymorphicAction<internal::InvokeArgumentAction3<N, A1, A2, A3> >
1203InvokeArgument(A1 a1, A2 a2, A3 a3) {
1204 return MakePolymorphicAction(
1205 internal::InvokeArgumentAction3<N, A1, A2, A3>(a1, a2, a3));
1206}
1207
1208template <size_t N, typename A1, typename A2, typename A3, typename A4>
1209inline PolymorphicAction<internal::InvokeArgumentAction4<N, A1, A2, A3, A4> >
1210InvokeArgument(A1 a1, A2 a2, A3 a3, A4 a4) {
1211 return MakePolymorphicAction(
1212 internal::InvokeArgumentAction4<N, A1, A2, A3, A4>(a1, a2, a3, a4));
1213}
1214
1215template <size_t N, typename A1, typename A2, typename A3, typename A4,
1216 typename A5>
1217inline PolymorphicAction<internal::InvokeArgumentAction5<N, A1, A2, A3, A4,
1218 A5> >
1219InvokeArgument(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) {
1220 return MakePolymorphicAction(
1221 internal::InvokeArgumentAction5<N, A1, A2, A3, A4, A5>(a1, a2, a3, a4,
1222 a5));
1223}
1224
1225template <size_t N, typename A1, typename A2, typename A3, typename A4,
1226 typename A5, typename A6>
1227inline PolymorphicAction<internal::InvokeArgumentAction6<N, A1, A2, A3, A4, A5,
1228 A6> >
1229InvokeArgument(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) {
1230 return MakePolymorphicAction(
1231 internal::InvokeArgumentAction6<N, A1, A2, A3, A4, A5, A6>(a1, a2, a3,
1232 a4, a5, a6));
1233}
1234
1235template <size_t N, typename A1, typename A2, typename A3, typename A4,
1236 typename A5, typename A6, typename A7>
1237inline PolymorphicAction<internal::InvokeArgumentAction7<N, A1, A2, A3, A4, A5,
1238 A6, A7> >
1239InvokeArgument(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) {
1240 return MakePolymorphicAction(
1241 internal::InvokeArgumentAction7<N, A1, A2, A3, A4, A5, A6, A7>(a1, a2,
1242 a3, a4, a5, a6, a7));
1243}
1244
1245template <size_t N, typename A1, typename A2, typename A3, typename A4,
1246 typename A5, typename A6, typename A7, typename A8>
1247inline PolymorphicAction<internal::InvokeArgumentAction8<N, A1, A2, A3, A4, A5,
1248 A6, A7, A8> >
1249InvokeArgument(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) {
1250 return MakePolymorphicAction(
1251 internal::InvokeArgumentAction8<N, A1, A2, A3, A4, A5, A6, A7, A8>(a1,
1252 a2, a3, a4, a5, a6, a7, a8));
1253}
1254
1255template <size_t N, typename A1, typename A2, typename A3, typename A4,
1256 typename A5, typename A6, typename A7, typename A8, typename A9>
1257inline PolymorphicAction<internal::InvokeArgumentAction9<N, A1, A2, A3, A4, A5,
1258 A6, A7, A8, A9> >
1259InvokeArgument(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) {
1260 return MakePolymorphicAction(
1261 internal::InvokeArgumentAction9<N, A1, A2, A3, A4, A5, A6, A7, A8,
1262 A9>(a1, a2, a3, a4, a5, a6, a7, a8, a9));
1263}
1264
1265template <size_t N, typename A1, typename A2, typename A3, typename A4,
1266 typename A5, typename A6, typename A7, typename A8, typename A9,
1267 typename A10>
1268inline PolymorphicAction<internal::InvokeArgumentAction10<N, A1, A2, A3, A4,
1269 A5, A6, A7, A8, A9, A10> >
1270InvokeArgument(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9,
1271 A10 a10) {
1272 return MakePolymorphicAction(
1273 internal::InvokeArgumentAction10<N, A1, A2, A3, A4, A5, A6, A7, A8, A9,
1274 A10>(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10));
1275}
1276
1277// WithoutArgs(inner_action) can be used in a mock function with a
1278// non-empty argument list to perform inner_action, which takes no
1279// argument. In other words, it adapts an action accepting no
1280// argument to one that accepts (and ignores) arguments.
1281template <typename InnerAction>
1282inline internal::WithArgsAction<InnerAction>
1283WithoutArgs(const InnerAction& action) {
1284 return internal::WithArgsAction<InnerAction>(action);
1285}
1286
1287// WithArg<k>(an_action) creates an action that passes the k-th
1288// (0-based) argument of the mock function to an_action and performs
1289// it. It adapts an action accepting one argument to one that accepts
1290// multiple arguments. For convenience, we also provide
1291// WithArgs<k>(an_action) (defined below) as a synonym.
1292template <int k, typename InnerAction>
1293inline internal::WithArgsAction<InnerAction, k>
1294WithArg(const InnerAction& action) {
1295 return internal::WithArgsAction<InnerAction, k>(action);
1296}
1297
1298// WithArgs<N1, N2, ..., Nk>(an_action) creates an action that passes
1299// the selected arguments of the mock function to an_action and
1300// performs it. It serves as an adaptor between actions with
1301// different argument lists. C++ doesn't support default arguments for
1302// function templates, so we have to overload it.
1303template <int k1, typename InnerAction>
1304inline internal::WithArgsAction<InnerAction, k1>
1305WithArgs(const InnerAction& action) {
1306 return internal::WithArgsAction<InnerAction, k1>(action);
1307}
1308
1309template <int k1, int k2, typename InnerAction>
1310inline internal::WithArgsAction<InnerAction, k1, k2>
1311WithArgs(const InnerAction& action) {
1312 return internal::WithArgsAction<InnerAction, k1, k2>(action);
1313}
1314
1315template <int k1, int k2, int k3, typename InnerAction>
1316inline internal::WithArgsAction<InnerAction, k1, k2, k3>
1317WithArgs(const InnerAction& action) {
1318 return internal::WithArgsAction<InnerAction, k1, k2, k3>(action);
1319}
1320
1321template <int k1, int k2, int k3, int k4, typename InnerAction>
1322inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4>
1323WithArgs(const InnerAction& action) {
1324 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4>(action);
1325}
1326
1327template <int k1, int k2, int k3, int k4, int k5, typename InnerAction>
1328inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5>
1329WithArgs(const InnerAction& action) {
1330 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5>(action);
1331}
1332
1333template <int k1, int k2, int k3, int k4, int k5, int k6, typename InnerAction>
1334inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6>
1335WithArgs(const InnerAction& action) {
1336 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6>(action);
1337}
1338
1339template <int k1, int k2, int k3, int k4, int k5, int k6, int k7,
1340 typename InnerAction>
1341inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7>
1342WithArgs(const InnerAction& action) {
1343 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6,
1344 k7>(action);
1345}
1346
1347template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
1348 typename InnerAction>
1349inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8>
1350WithArgs(const InnerAction& action) {
1351 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7,
1352 k8>(action);
1353}
1354
1355template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
1356 int k9, typename InnerAction>
1357inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8, k9>
1358WithArgs(const InnerAction& action) {
1359 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8,
1360 k9>(action);
1361}
1362
1363template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
1364 int k9, int k10, typename InnerAction>
1365inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8,
1366 k9, k10>
1367WithArgs(const InnerAction& action) {
1368 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8,
1369 k9, k10>(action);
1370}
1371
1372// Creates an action that does actions a1, a2, ..., sequentially in
1373// each invocation.
1374template <typename Action1, typename Action2>
1375inline internal::DoBothAction<Action1, Action2>
1376DoAll(Action1 a1, Action2 a2) {
1377 return internal::DoBothAction<Action1, Action2>(a1, a2);
1378}
1379
1380template <typename Action1, typename Action2, typename Action3>
1381inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
1382 Action3> >
1383DoAll(Action1 a1, Action2 a2, Action3 a3) {
1384 return DoAll(a1, DoAll(a2, a3));
1385}
1386
1387template <typename Action1, typename Action2, typename Action3,
1388 typename Action4>
1389inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
1390 internal::DoBothAction<Action3, Action4> > >
1391DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4) {
1392 return DoAll(a1, DoAll(a2, a3, a4));
1393}
1394
1395template <typename Action1, typename Action2, typename Action3,
1396 typename Action4, typename Action5>
1397inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
1398 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
1399 Action5> > > >
1400DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5) {
1401 return DoAll(a1, DoAll(a2, a3, a4, a5));
1402}
1403
1404template <typename Action1, typename Action2, typename Action3,
1405 typename Action4, typename Action5, typename Action6>
1406inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
1407 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
1408 internal::DoBothAction<Action5, Action6> > > > >
1409DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6) {
1410 return DoAll(a1, DoAll(a2, a3, a4, a5, a6));
1411}
1412
1413template <typename Action1, typename Action2, typename Action3,
1414 typename Action4, typename Action5, typename Action6, typename Action7>
1415inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
1416 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
1417 internal::DoBothAction<Action5, internal::DoBothAction<Action6,
1418 Action7> > > > > >
1419DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
1420 Action7 a7) {
1421 return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7));
1422}
1423
1424template <typename Action1, typename Action2, typename Action3,
1425 typename Action4, typename Action5, typename Action6, typename Action7,
1426 typename Action8>
1427inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
1428 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
1429 internal::DoBothAction<Action5, internal::DoBothAction<Action6,
1430 internal::DoBothAction<Action7, Action8> > > > > > >
1431DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
1432 Action7 a7, Action8 a8) {
1433 return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8));
1434}
1435
1436template <typename Action1, typename Action2, typename Action3,
1437 typename Action4, typename Action5, typename Action6, typename Action7,
1438 typename Action8, typename Action9>
1439inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
1440 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
1441 internal::DoBothAction<Action5, internal::DoBothAction<Action6,
1442 internal::DoBothAction<Action7, internal::DoBothAction<Action8,
1443 Action9> > > > > > > >
1444DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
1445 Action7 a7, Action8 a8, Action9 a9) {
1446 return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8, a9));
1447}
1448
1449template <typename Action1, typename Action2, typename Action3,
1450 typename Action4, typename Action5, typename Action6, typename Action7,
1451 typename Action8, typename Action9, typename Action10>
1452inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
1453 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
1454 internal::DoBothAction<Action5, internal::DoBothAction<Action6,
1455 internal::DoBothAction<Action7, internal::DoBothAction<Action8,
1456 internal::DoBothAction<Action9, Action10> > > > > > > > >
1457DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
1458 Action7 a7, Action8 a8, Action9 a9, Action10 a10) {
1459 return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8, a9, a10));
1460}
1461
1462} // namespace testing
1463
shiqian326aa562009-01-09 21:43:57 +00001464// The ACTION* family of macros can be used in a namespace scope to
1465// define custom actions easily. The syntax:
1466//
1467// ACTION(name) { statements; }
1468//
1469// will define an action with the given name that executes the
1470// statements. The value returned by the statements will be used as
1471// the return value of the action. Inside the statements, you can
1472// refer to the K-th (0-based) argument of the mock function by
1473// 'argK', and refer to its type by 'argK_type'. For example:
1474//
1475// ACTION(IncrementArg1) {
1476// arg1_type temp = arg1;
1477// return ++(*temp);
1478// }
1479//
1480// allows you to write
1481//
1482// ...WillOnce(IncrementArg1());
1483//
1484// You can also refer to the entire argument tuple and its type by
1485// 'args' and 'args_type', and refer to the mock function type and its
1486// return type by 'function_type' and 'return_type'.
1487//
1488// Note that you don't need to specify the types of the mock function
1489// arguments. However rest assured that your code is still type-safe:
1490// you'll get a compiler error if *arg1 doesn't support the ++
1491// operator, or if the type of ++(*arg1) isn't compatible with the
1492// mock function's return type, for example.
1493//
1494// Sometimes you'll want to parameterize the action. For that you can use
1495// another macro:
1496//
1497// ACTION_P(name, param_name) { statements; }
1498//
1499// For example:
1500//
1501// ACTION_P(Add, n) { return arg0 + n; }
1502//
1503// will allow you to write:
1504//
1505// ...WillOnce(Add(5));
1506//
1507// Note that you don't need to provide the type of the parameter
1508// either. If you need to reference the type of a parameter named
1509// 'foo', you can write 'foo_type'. For example, in the body of
1510// ACTION_P(Add, n) above, you can write 'n_type' to refer to the type
1511// of 'n'.
1512//
1513// We also provide ACTION_P2, ACTION_P3, ..., up to ACTION_P10 to support
1514// multi-parameter actions.
1515//
1516// For the purpose of typing, you can view
1517//
1518// ACTION_Pk(Foo, p1, ..., pk) { ... }
1519//
1520// as shorthand for
1521//
1522// template <typename p1_type, ..., typename pk_type>
1523// FooActionPk<p1_type, ..., pk_type> Foo(p1_type p1, ..., pk_type pk) { ... }
1524//
1525// In particular, you can provide the template type arguments
1526// explicitly when invoking Foo(), as in Foo<long, bool>(5, false);
1527// although usually you can rely on the compiler to infer the types
1528// for you automatically. You can assign the result of expression
1529// Foo(p1, ..., pk) to a variable of type FooActionPk<p1_type, ...,
1530// pk_type>. This can be useful when composing actions.
1531//
1532// You can also overload actions with different numbers of parameters:
1533//
1534// ACTION_P(Plus, a) { ... }
1535// ACTION_P2(Plus, a, b) { ... }
1536//
1537// While it's tempting to always use the ACTION* macros when defining
1538// a new action, you should also consider implementing ActionInterface
1539// or using MakePolymorphicAction() instead, especially if you need to
1540// use the action a lot. While these approaches require more work,
1541// they give you more control on the types of the mock function
1542// arguments and the action parameters, which in general leads to
1543// better compiler error messages that pay off in the long run. They
1544// also allow overloading actions based on parameter types (as opposed
1545// to just based on the number of parameters).
1546//
1547// CAVEAT:
1548//
1549// ACTION*() can only be used in a namespace scope. The reason is
1550// that C++ doesn't yet allow function-local types to be used to
1551// instantiate templates. The up-coming C++0x standard will fix this.
1552// Once that's done, we'll consider supporting using ACTION*() inside
1553// a function.
1554//
1555// MORE INFORMATION:
1556//
1557// To learn more about using these macros, please search for 'ACTION'
1558// on http://code.google.com/p/googlemock/wiki/CookBook.
1559
zhanyong.wan33c0af02009-04-03 00:10:12 +00001560// An internal macro needed for implementing ACTION*().
1561#define GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_\
1562 const args_type& args GTEST_ATTRIBUTE_UNUSED_,\
1563 arg0_type arg0 GTEST_ATTRIBUTE_UNUSED_,\
1564 arg1_type arg1 GTEST_ATTRIBUTE_UNUSED_,\
1565 arg2_type arg2 GTEST_ATTRIBUTE_UNUSED_,\
1566 arg3_type arg3 GTEST_ATTRIBUTE_UNUSED_,\
1567 arg4_type arg4 GTEST_ATTRIBUTE_UNUSED_,\
1568 arg5_type arg5 GTEST_ATTRIBUTE_UNUSED_,\
1569 arg6_type arg6 GTEST_ATTRIBUTE_UNUSED_,\
1570 arg7_type arg7 GTEST_ATTRIBUTE_UNUSED_,\
1571 arg8_type arg8 GTEST_ATTRIBUTE_UNUSED_,\
1572 arg9_type arg9 GTEST_ATTRIBUTE_UNUSED_
1573
zhanyong.wan18490652009-05-11 18:54:08 +00001574// Sometimes you want to give an action explicit template parameters
1575// that cannot be inferred from its value parameters. ACTION() and
1576// ACTION_P*() don't support that. ACTION_TEMPLATE() remedies that
1577// and can be viewed as an extension to ACTION() and ACTION_P*().
1578//
1579// The syntax:
1580//
1581// ACTION_TEMPLATE(ActionName,
1582// HAS_m_TEMPLATE_PARAMS(kind1, name1, ..., kind_m, name_m),
1583// AND_n_VALUE_PARAMS(p1, ..., p_n)) { statements; }
1584//
1585// defines an action template that takes m explicit template
1586// parameters and n value parameters. name_i is the name of the i-th
1587// template parameter, and kind_i specifies whether it's a typename,
1588// an integral constant, or a template. p_i is the name of the i-th
1589// value parameter.
1590//
1591// Example:
1592//
1593// // DuplicateArg<k, T>(output) converts the k-th argument of the mock
1594// // function to type T and copies it to *output.
1595// ACTION_TEMPLATE(DuplicateArg,
1596// HAS_2_TEMPLATE_PARAMS(int, k, typename, T),
1597// AND_1_VALUE_PARAMS(output)) {
1598// *output = T(std::tr1::get<k>(args));
1599// }
1600// ...
1601// int n;
1602// EXPECT_CALL(mock, Foo(_, _))
1603// .WillOnce(DuplicateArg<1, unsigned char>(&n));
1604//
1605// To create an instance of an action template, write:
1606//
1607// ActionName<t1, ..., t_m>(v1, ..., v_n)
1608//
1609// where the ts are the template arguments and the vs are the value
1610// arguments. The value argument types are inferred by the compiler.
1611// If you want to explicitly specify the value argument types, you can
1612// provide additional template arguments:
1613//
1614// ActionName<t1, ..., t_m, u1, ..., u_k>(v1, ..., v_n)
1615//
1616// where u_i is the desired type of v_i.
1617//
1618// ACTION_TEMPLATE and ACTION/ACTION_P* can be overloaded on the
1619// number of value parameters, but not on the number of template
1620// parameters. Without the restriction, the meaning of the following
1621// is unclear:
1622//
1623// OverloadedAction<int, bool>(x);
1624//
1625// Are we using a single-template-parameter action where 'bool' refers
1626// to the type of x, or are we using a two-template-parameter action
1627// where the compiler is asked to infer the type of x?
1628//
1629// Implementation notes:
1630//
1631// GMOCK_INTERNAL_*_HAS_m_TEMPLATE_PARAMS and
1632// GMOCK_INTERNAL_*_AND_n_VALUE_PARAMS are internal macros for
1633// implementing ACTION_TEMPLATE. The main trick we use is to create
1634// new macro invocations when expanding a macro. For example, we have
1635//
1636// #define ACTION_TEMPLATE(name, template_params, value_params)
1637// ... GMOCK_INTERNAL_DECL_##template_params ...
1638//
1639// which causes ACTION_TEMPLATE(..., HAS_1_TEMPLATE_PARAMS(typename, T), ...)
1640// to expand to
1641//
1642// ... GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(typename, T) ...
1643//
1644// Since GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS is a macro, the
1645// preprocessor will continue to expand it to
1646//
1647// ... typename T ...
1648//
1649// This technique conforms to the C++ standard and is portable. It
1650// allows us to implement action templates using O(N) code, where N is
1651// the maximum number of template/value parameters supported. Without
1652// using it, we'd have to devote O(N^2) amount of code to implement all
1653// combinations of m and n.
1654
1655// Declares the template parameters.
1656#define GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(kind0, name0) kind0 name0
1657#define GMOCK_INTERNAL_DECL_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, \
1658 name1) kind0 name0, kind1 name1
1659#define GMOCK_INTERNAL_DECL_HAS_3_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
1660 kind2, name2) kind0 name0, kind1 name1, kind2 name2
1661#define GMOCK_INTERNAL_DECL_HAS_4_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
1662 kind2, name2, kind3, name3) kind0 name0, kind1 name1, kind2 name2, \
1663 kind3 name3
1664#define GMOCK_INTERNAL_DECL_HAS_5_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
1665 kind2, name2, kind3, name3, kind4, name4) kind0 name0, kind1 name1, \
1666 kind2 name2, kind3 name3, kind4 name4
1667#define GMOCK_INTERNAL_DECL_HAS_6_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
1668 kind2, name2, kind3, name3, kind4, name4, kind5, name5) kind0 name0, \
1669 kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5
1670#define GMOCK_INTERNAL_DECL_HAS_7_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
1671 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
1672 name6) kind0 name0, kind1 name1, kind2 name2, kind3 name3, kind4 name4, \
1673 kind5 name5, kind6 name6
1674#define GMOCK_INTERNAL_DECL_HAS_8_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
1675 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
1676 kind7, name7) kind0 name0, kind1 name1, kind2 name2, kind3 name3, \
1677 kind4 name4, kind5 name5, kind6 name6, kind7 name7
1678#define GMOCK_INTERNAL_DECL_HAS_9_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
1679 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
1680 kind7, name7, kind8, name8) kind0 name0, kind1 name1, kind2 name2, \
1681 kind3 name3, kind4 name4, kind5 name5, kind6 name6, kind7 name7, \
1682 kind8 name8
1683#define GMOCK_INTERNAL_DECL_HAS_10_TEMPLATE_PARAMS(kind0, name0, kind1, \
1684 name1, kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
1685 name6, kind7, name7, kind8, name8, kind9, name9) kind0 name0, \
1686 kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5, \
1687 kind6 name6, kind7 name7, kind8 name8, kind9 name9
1688
1689// Lists the template parameters.
1690#define GMOCK_INTERNAL_LIST_HAS_1_TEMPLATE_PARAMS(kind0, name0) name0
1691#define GMOCK_INTERNAL_LIST_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, \
1692 name1) name0, name1
1693#define GMOCK_INTERNAL_LIST_HAS_3_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
1694 kind2, name2) name0, name1, name2
1695#define GMOCK_INTERNAL_LIST_HAS_4_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
1696 kind2, name2, kind3, name3) name0, name1, name2, name3
1697#define GMOCK_INTERNAL_LIST_HAS_5_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
1698 kind2, name2, kind3, name3, kind4, name4) name0, name1, name2, name3, \
1699 name4
1700#define GMOCK_INTERNAL_LIST_HAS_6_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
1701 kind2, name2, kind3, name3, kind4, name4, kind5, name5) name0, name1, \
1702 name2, name3, name4, name5
1703#define GMOCK_INTERNAL_LIST_HAS_7_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
1704 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
1705 name6) name0, name1, name2, name3, name4, name5, name6
1706#define GMOCK_INTERNAL_LIST_HAS_8_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
1707 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
1708 kind7, name7) name0, name1, name2, name3, name4, name5, name6, name7
1709#define GMOCK_INTERNAL_LIST_HAS_9_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
1710 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
1711 kind7, name7, kind8, name8) name0, name1, name2, name3, name4, name5, \
1712 name6, name7, name8
1713#define GMOCK_INTERNAL_LIST_HAS_10_TEMPLATE_PARAMS(kind0, name0, kind1, \
1714 name1, kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
1715 name6, kind7, name7, kind8, name8, kind9, name9) name0, name1, name2, \
1716 name3, name4, name5, name6, name7, name8, name9
1717
1718// Declares the types of value parameters.
1719#define GMOCK_INTERNAL_DECL_TYPE_AND_0_VALUE_PARAMS()
1720#define GMOCK_INTERNAL_DECL_TYPE_AND_1_VALUE_PARAMS(p0) , typename p0##_type
1721#define GMOCK_INTERNAL_DECL_TYPE_AND_2_VALUE_PARAMS(p0, p1) , \
1722 typename p0##_type, typename p1##_type
1723#define GMOCK_INTERNAL_DECL_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) , \
1724 typename p0##_type, typename p1##_type, typename p2##_type
1725#define GMOCK_INTERNAL_DECL_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) , \
1726 typename p0##_type, typename p1##_type, typename p2##_type, \
1727 typename p3##_type
1728#define GMOCK_INTERNAL_DECL_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) , \
1729 typename p0##_type, typename p1##_type, typename p2##_type, \
1730 typename p3##_type, typename p4##_type
1731#define GMOCK_INTERNAL_DECL_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) , \
1732 typename p0##_type, typename p1##_type, typename p2##_type, \
1733 typename p3##_type, typename p4##_type, typename p5##_type
1734#define GMOCK_INTERNAL_DECL_TYPE_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
1735 p6) , typename p0##_type, typename p1##_type, typename p2##_type, \
1736 typename p3##_type, typename p4##_type, typename p5##_type, \
1737 typename p6##_type
1738#define GMOCK_INTERNAL_DECL_TYPE_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
1739 p6, p7) , typename p0##_type, typename p1##_type, typename p2##_type, \
1740 typename p3##_type, typename p4##_type, typename p5##_type, \
1741 typename p6##_type, typename p7##_type
1742#define GMOCK_INTERNAL_DECL_TYPE_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
1743 p6, p7, p8) , typename p0##_type, typename p1##_type, typename p2##_type, \
1744 typename p3##_type, typename p4##_type, typename p5##_type, \
1745 typename p6##_type, typename p7##_type, typename p8##_type
1746#define GMOCK_INTERNAL_DECL_TYPE_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
1747 p6, p7, p8, p9) , typename p0##_type, typename p1##_type, \
1748 typename p2##_type, typename p3##_type, typename p4##_type, \
1749 typename p5##_type, typename p6##_type, typename p7##_type, \
1750 typename p8##_type, typename p9##_type
1751
1752// Initializes the value parameters.
1753#define GMOCK_INTERNAL_INIT_AND_0_VALUE_PARAMS()\
1754 ()
1755#define GMOCK_INTERNAL_INIT_AND_1_VALUE_PARAMS(p0)\
1756 (p0##_type gmock_p0) : p0(gmock_p0)
1757#define GMOCK_INTERNAL_INIT_AND_2_VALUE_PARAMS(p0, p1)\
1758 (p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), p1(gmock_p1)
1759#define GMOCK_INTERNAL_INIT_AND_3_VALUE_PARAMS(p0, p1, p2)\
1760 (p0##_type gmock_p0, p1##_type gmock_p1, \
1761 p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2)
1762#define GMOCK_INTERNAL_INIT_AND_4_VALUE_PARAMS(p0, p1, p2, p3)\
1763 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
1764 p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
1765 p3(gmock_p3)
1766#define GMOCK_INTERNAL_INIT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)\
1767 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
1768 p3##_type gmock_p3, p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), \
1769 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4)
1770#define GMOCK_INTERNAL_INIT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)\
1771 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
1772 p3##_type gmock_p3, p4##_type gmock_p4, \
1773 p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
1774 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5)
1775#define GMOCK_INTERNAL_INIT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)\
1776 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
1777 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
1778 p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
1779 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6)
1780#define GMOCK_INTERNAL_INIT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)\
1781 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
1782 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
1783 p6##_type gmock_p6, p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), \
1784 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
1785 p7(gmock_p7)
1786#define GMOCK_INTERNAL_INIT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
1787 p7, p8)\
1788 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
1789 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
1790 p6##_type gmock_p6, p7##_type gmock_p7, \
1791 p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
1792 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
1793 p8(gmock_p8)
1794#define GMOCK_INTERNAL_INIT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
1795 p7, p8, p9)\
1796 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
1797 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
1798 p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
1799 p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
1800 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
1801 p8(gmock_p8), p9(gmock_p9)
1802
1803// Declares the fields for storing the value parameters.
1804#define GMOCK_INTERNAL_DEFN_AND_0_VALUE_PARAMS()
1805#define GMOCK_INTERNAL_DEFN_AND_1_VALUE_PARAMS(p0) p0##_type p0;
1806#define GMOCK_INTERNAL_DEFN_AND_2_VALUE_PARAMS(p0, p1) p0##_type p0; \
1807 p1##_type p1;
1808#define GMOCK_INTERNAL_DEFN_AND_3_VALUE_PARAMS(p0, p1, p2) p0##_type p0; \
1809 p1##_type p1; p2##_type p2;
1810#define GMOCK_INTERNAL_DEFN_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0##_type p0; \
1811 p1##_type p1; p2##_type p2; p3##_type p3;
1812#define GMOCK_INTERNAL_DEFN_AND_5_VALUE_PARAMS(p0, p1, p2, p3, \
1813 p4) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4;
1814#define GMOCK_INTERNAL_DEFN_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, \
1815 p5) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \
1816 p5##_type p5;
1817#define GMOCK_INTERNAL_DEFN_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
1818 p6) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \
1819 p5##_type p5; p6##_type p6;
1820#define GMOCK_INTERNAL_DEFN_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
1821 p7) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \
1822 p5##_type p5; p6##_type p6; p7##_type p7;
1823#define GMOCK_INTERNAL_DEFN_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
1824 p7, p8) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; \
1825 p4##_type p4; p5##_type p5; p6##_type p6; p7##_type p7; p8##_type p8;
1826#define GMOCK_INTERNAL_DEFN_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
1827 p7, p8, p9) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; \
1828 p4##_type p4; p5##_type p5; p6##_type p6; p7##_type p7; p8##_type p8; \
1829 p9##_type p9;
1830
1831// Lists the value parameters.
1832#define GMOCK_INTERNAL_LIST_AND_0_VALUE_PARAMS()
1833#define GMOCK_INTERNAL_LIST_AND_1_VALUE_PARAMS(p0) p0
1834#define GMOCK_INTERNAL_LIST_AND_2_VALUE_PARAMS(p0, p1) p0, p1
1835#define GMOCK_INTERNAL_LIST_AND_3_VALUE_PARAMS(p0, p1, p2) p0, p1, p2
1836#define GMOCK_INTERNAL_LIST_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0, p1, p2, p3
1837#define GMOCK_INTERNAL_LIST_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) p0, p1, \
1838 p2, p3, p4
1839#define GMOCK_INTERNAL_LIST_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) p0, \
1840 p1, p2, p3, p4, p5
1841#define GMOCK_INTERNAL_LIST_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
1842 p6) p0, p1, p2, p3, p4, p5, p6
1843#define GMOCK_INTERNAL_LIST_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
1844 p7) p0, p1, p2, p3, p4, p5, p6, p7
1845#define GMOCK_INTERNAL_LIST_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
1846 p7, p8) p0, p1, p2, p3, p4, p5, p6, p7, p8
1847#define GMOCK_INTERNAL_LIST_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
1848 p7, p8, p9) p0, p1, p2, p3, p4, p5, p6, p7, p8, p9
1849
1850// Lists the value parameter types.
1851#define GMOCK_INTERNAL_LIST_TYPE_AND_0_VALUE_PARAMS()
1852#define GMOCK_INTERNAL_LIST_TYPE_AND_1_VALUE_PARAMS(p0) , p0##_type
1853#define GMOCK_INTERNAL_LIST_TYPE_AND_2_VALUE_PARAMS(p0, p1) , p0##_type, \
1854 p1##_type
1855#define GMOCK_INTERNAL_LIST_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) , p0##_type, \
1856 p1##_type, p2##_type
1857#define GMOCK_INTERNAL_LIST_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) , \
1858 p0##_type, p1##_type, p2##_type, p3##_type
1859#define GMOCK_INTERNAL_LIST_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) , \
1860 p0##_type, p1##_type, p2##_type, p3##_type, p4##_type
1861#define GMOCK_INTERNAL_LIST_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) , \
1862 p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type
1863#define GMOCK_INTERNAL_LIST_TYPE_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
1864 p6) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type, \
1865 p6##_type
1866#define GMOCK_INTERNAL_LIST_TYPE_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
1867 p6, p7) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
1868 p5##_type, p6##_type, p7##_type
1869#define GMOCK_INTERNAL_LIST_TYPE_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
1870 p6, p7, p8) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
1871 p5##_type, p6##_type, p7##_type, p8##_type
1872#define GMOCK_INTERNAL_LIST_TYPE_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
1873 p6, p7, p8, p9) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
1874 p5##_type, p6##_type, p7##_type, p8##_type, p9##_type
1875
1876// Declares the value parameters.
1877#define GMOCK_INTERNAL_DECL_AND_0_VALUE_PARAMS()
1878#define GMOCK_INTERNAL_DECL_AND_1_VALUE_PARAMS(p0) p0##_type p0
1879#define GMOCK_INTERNAL_DECL_AND_2_VALUE_PARAMS(p0, p1) p0##_type p0, \
1880 p1##_type p1
1881#define GMOCK_INTERNAL_DECL_AND_3_VALUE_PARAMS(p0, p1, p2) p0##_type p0, \
1882 p1##_type p1, p2##_type p2
1883#define GMOCK_INTERNAL_DECL_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0##_type p0, \
1884 p1##_type p1, p2##_type p2, p3##_type p3
1885#define GMOCK_INTERNAL_DECL_AND_5_VALUE_PARAMS(p0, p1, p2, p3, \
1886 p4) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4
1887#define GMOCK_INTERNAL_DECL_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, \
1888 p5) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \
1889 p5##_type p5
1890#define GMOCK_INTERNAL_DECL_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
1891 p6) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \
1892 p5##_type p5, p6##_type p6
1893#define GMOCK_INTERNAL_DECL_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
1894 p7) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \
1895 p5##_type p5, p6##_type p6, p7##_type p7
1896#define GMOCK_INTERNAL_DECL_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
1897 p7, p8) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
1898 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8
1899#define GMOCK_INTERNAL_DECL_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
1900 p7, p8, p9) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
1901 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \
1902 p9##_type p9
1903
1904// The suffix of the class template implementing the action template.
1905#define GMOCK_INTERNAL_COUNT_AND_0_VALUE_PARAMS()
1906#define GMOCK_INTERNAL_COUNT_AND_1_VALUE_PARAMS(p0) P
1907#define GMOCK_INTERNAL_COUNT_AND_2_VALUE_PARAMS(p0, p1) P2
1908#define GMOCK_INTERNAL_COUNT_AND_3_VALUE_PARAMS(p0, p1, p2) P3
1909#define GMOCK_INTERNAL_COUNT_AND_4_VALUE_PARAMS(p0, p1, p2, p3) P4
1910#define GMOCK_INTERNAL_COUNT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) P5
1911#define GMOCK_INTERNAL_COUNT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) P6
1912#define GMOCK_INTERNAL_COUNT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6) P7
1913#define GMOCK_INTERNAL_COUNT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
1914 p7) P8
1915#define GMOCK_INTERNAL_COUNT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
1916 p7, p8) P9
1917#define GMOCK_INTERNAL_COUNT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
1918 p7, p8, p9) P10
1919
1920// The name of the class template implementing the action template.
1921#define GMOCK_ACTION_CLASS_(name, value_params)\
1922 GMOCK_CONCAT_TOKEN_(name##Action, GMOCK_INTERNAL_COUNT_##value_params)
1923
1924#define ACTION_TEMPLATE(name, template_params, value_params)\
1925 template <GMOCK_INTERNAL_DECL_##template_params\
1926 GMOCK_INTERNAL_DECL_TYPE_##value_params>\
1927 class GMOCK_ACTION_CLASS_(name, value_params) {\
1928 public:\
1929 GMOCK_ACTION_CLASS_(name, value_params)\
1930 GMOCK_INTERNAL_INIT_##value_params {}\
1931 template <typename F>\
1932 class gmock_Impl : public ::testing::ActionInterface<F> {\
1933 public:\
1934 typedef F function_type;\
1935 typedef typename ::testing::internal::Function<F>::Result return_type;\
1936 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
1937 args_type;\
1938 explicit gmock_Impl GMOCK_INTERNAL_INIT_##value_params {}\
1939 virtual return_type Perform(const args_type& args) {\
1940 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
1941 Perform(this, args);\
1942 }\
1943 template <typename arg0_type, typename arg1_type, typename arg2_type, \
1944 typename arg3_type, typename arg4_type, typename arg5_type, \
1945 typename arg6_type, typename arg7_type, typename arg8_type, \
1946 typename arg9_type>\
1947 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
1948 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
1949 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
1950 arg9_type arg9) const;\
1951 GMOCK_INTERNAL_DEFN_##value_params\
1952 };\
1953 template <typename F> operator ::testing::Action<F>() const {\
1954 return ::testing::Action<F>(\
1955 new gmock_Impl<F>(GMOCK_INTERNAL_LIST_##value_params));\
1956 }\
1957 GMOCK_INTERNAL_DEFN_##value_params\
1958 };\
1959 template <GMOCK_INTERNAL_DECL_##template_params\
1960 GMOCK_INTERNAL_DECL_TYPE_##value_params>\
1961 inline GMOCK_ACTION_CLASS_(name, value_params)<\
1962 GMOCK_INTERNAL_LIST_##template_params\
1963 GMOCK_INTERNAL_LIST_TYPE_##value_params> name(\
1964 GMOCK_INTERNAL_DECL_##value_params) {\
1965 return GMOCK_ACTION_CLASS_(name, value_params)<\
1966 GMOCK_INTERNAL_LIST_##template_params\
1967 GMOCK_INTERNAL_LIST_TYPE_##value_params>(\
1968 GMOCK_INTERNAL_LIST_##value_params);\
1969 }\
1970 template <GMOCK_INTERNAL_DECL_##template_params\
1971 GMOCK_INTERNAL_DECL_TYPE_##value_params>\
1972 template <typename F>\
1973 template <typename arg0_type, typename arg1_type, typename arg2_type,\
1974 typename arg3_type, typename arg4_type, typename arg5_type,\
1975 typename arg6_type, typename arg7_type, typename arg8_type,\
1976 typename arg9_type>\
1977 typename ::testing::internal::Function<F>::Result\
1978 GMOCK_ACTION_CLASS_(name, value_params)<\
1979 GMOCK_INTERNAL_LIST_##template_params\
1980 GMOCK_INTERNAL_LIST_TYPE_##value_params>::gmock_Impl<F>::\
1981 gmock_PerformImpl(\
1982 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
1983
shiqian326aa562009-01-09 21:43:57 +00001984#define ACTION(name)\
1985 class name##Action {\
1986 public:\
1987 name##Action() {}\
1988 template <typename F>\
1989 class gmock_Impl : public ::testing::ActionInterface<F> {\
1990 public:\
1991 typedef F function_type;\
1992 typedef typename ::testing::internal::Function<F>::Result return_type;\
1993 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
1994 args_type;\
1995 gmock_Impl() {}\
1996 virtual return_type Perform(const args_type& args) {\
1997 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
1998 Perform(this, args);\
1999 }\
2000 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2001 typename arg3_type, typename arg4_type, typename arg5_type, \
2002 typename arg6_type, typename arg7_type, typename arg8_type, \
2003 typename arg9_type>\
2004 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
2005 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
2006 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
2007 arg9_type arg9) const;\
2008 };\
2009 template <typename F> operator ::testing::Action<F>() const {\
2010 return ::testing::Action<F>(new gmock_Impl<F>());\
2011 }\
2012 };\
2013 inline name##Action name() {\
2014 return name##Action();\
2015 }\
2016 template <typename F>\
2017 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2018 typename arg3_type, typename arg4_type, typename arg5_type, \
2019 typename arg6_type, typename arg7_type, typename arg8_type, \
2020 typename arg9_type>\
2021 typename ::testing::internal::Function<F>::Result\
zhanyong.wan33c0af02009-04-03 00:10:12 +00002022 name##Action::gmock_Impl<F>::gmock_PerformImpl(\
2023 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
shiqian326aa562009-01-09 21:43:57 +00002024
2025#define ACTION_P(name, p0)\
2026 template <typename p0##_type>\
2027 class name##ActionP {\
2028 public:\
2029 name##ActionP(p0##_type gmock_p0) : p0(gmock_p0) {}\
2030 template <typename F>\
2031 class gmock_Impl : public ::testing::ActionInterface<F> {\
2032 public:\
2033 typedef F function_type;\
2034 typedef typename ::testing::internal::Function<F>::Result return_type;\
2035 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
2036 args_type;\
2037 explicit gmock_Impl(p0##_type gmock_p0) : p0(gmock_p0) {}\
2038 virtual return_type Perform(const args_type& args) {\
2039 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
2040 Perform(this, args);\
2041 }\
2042 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2043 typename arg3_type, typename arg4_type, typename arg5_type, \
2044 typename arg6_type, typename arg7_type, typename arg8_type, \
2045 typename arg9_type>\
2046 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
2047 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
2048 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
2049 arg9_type arg9) const;\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00002050 p0##_type p0;\
shiqian326aa562009-01-09 21:43:57 +00002051 };\
2052 template <typename F> operator ::testing::Action<F>() const {\
2053 return ::testing::Action<F>(new gmock_Impl<F>(p0));\
2054 }\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00002055 p0##_type p0;\
shiqian326aa562009-01-09 21:43:57 +00002056 };\
2057 template <typename p0##_type>\
2058 inline name##ActionP<p0##_type> name(p0##_type p0) {\
2059 return name##ActionP<p0##_type>(p0);\
2060 }\
2061 template <typename p0##_type>\
2062 template <typename F>\
2063 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2064 typename arg3_type, typename arg4_type, typename arg5_type, \
2065 typename arg6_type, typename arg7_type, typename arg8_type, \
2066 typename arg9_type>\
2067 typename ::testing::internal::Function<F>::Result\
zhanyong.wan33c0af02009-04-03 00:10:12 +00002068 name##ActionP<p0##_type>::gmock_Impl<F>::gmock_PerformImpl(\
2069 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
shiqian326aa562009-01-09 21:43:57 +00002070
2071#define ACTION_P2(name, p0, p1)\
2072 template <typename p0##_type, typename p1##_type>\
2073 class name##ActionP2 {\
2074 public:\
2075 name##ActionP2(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \
2076 p1(gmock_p1) {}\
2077 template <typename F>\
2078 class gmock_Impl : public ::testing::ActionInterface<F> {\
2079 public:\
2080 typedef F function_type;\
2081 typedef typename ::testing::internal::Function<F>::Result return_type;\
2082 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
2083 args_type;\
2084 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \
2085 p1(gmock_p1) {}\
2086 virtual return_type Perform(const args_type& args) {\
2087 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
2088 Perform(this, args);\
2089 }\
2090 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2091 typename arg3_type, typename arg4_type, typename arg5_type, \
2092 typename arg6_type, typename arg7_type, typename arg8_type, \
2093 typename arg9_type>\
2094 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
2095 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
2096 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
2097 arg9_type arg9) const;\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00002098 p0##_type p0;\
2099 p1##_type p1;\
shiqian326aa562009-01-09 21:43:57 +00002100 };\
2101 template <typename F> operator ::testing::Action<F>() const {\
2102 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1));\
2103 }\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00002104 p0##_type p0;\
2105 p1##_type p1;\
shiqian326aa562009-01-09 21:43:57 +00002106 };\
2107 template <typename p0##_type, typename p1##_type>\
2108 inline name##ActionP2<p0##_type, p1##_type> name(p0##_type p0, \
2109 p1##_type p1) {\
2110 return name##ActionP2<p0##_type, p1##_type>(p0, p1);\
2111 }\
2112 template <typename p0##_type, typename p1##_type>\
2113 template <typename F>\
2114 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2115 typename arg3_type, typename arg4_type, typename arg5_type, \
2116 typename arg6_type, typename arg7_type, typename arg8_type, \
2117 typename arg9_type>\
2118 typename ::testing::internal::Function<F>::Result\
zhanyong.wan33c0af02009-04-03 00:10:12 +00002119 name##ActionP2<p0##_type, p1##_type>::gmock_Impl<F>::gmock_PerformImpl(\
2120 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
shiqian326aa562009-01-09 21:43:57 +00002121
2122#define ACTION_P3(name, p0, p1, p2)\
2123 template <typename p0##_type, typename p1##_type, typename p2##_type>\
2124 class name##ActionP3 {\
2125 public:\
2126 name##ActionP3(p0##_type gmock_p0, p1##_type gmock_p1, \
2127 p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\
2128 template <typename F>\
2129 class gmock_Impl : public ::testing::ActionInterface<F> {\
2130 public:\
2131 typedef F function_type;\
2132 typedef typename ::testing::internal::Function<F>::Result return_type;\
2133 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
2134 args_type;\
2135 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, \
2136 p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\
2137 virtual return_type Perform(const args_type& args) {\
2138 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
2139 Perform(this, args);\
2140 }\
2141 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2142 typename arg3_type, typename arg4_type, typename arg5_type, \
2143 typename arg6_type, typename arg7_type, typename arg8_type, \
2144 typename arg9_type>\
2145 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
2146 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
2147 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
2148 arg9_type arg9) const;\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00002149 p0##_type p0;\
2150 p1##_type p1;\
2151 p2##_type p2;\
shiqian326aa562009-01-09 21:43:57 +00002152 };\
2153 template <typename F> operator ::testing::Action<F>() const {\
2154 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2));\
2155 }\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00002156 p0##_type p0;\
2157 p1##_type p1;\
2158 p2##_type p2;\
shiqian326aa562009-01-09 21:43:57 +00002159 };\
2160 template <typename p0##_type, typename p1##_type, typename p2##_type>\
2161 inline name##ActionP3<p0##_type, p1##_type, p2##_type> name(p0##_type p0, \
2162 p1##_type p1, p2##_type p2) {\
2163 return name##ActionP3<p0##_type, p1##_type, p2##_type>(p0, p1, p2);\
2164 }\
2165 template <typename p0##_type, typename p1##_type, typename p2##_type>\
2166 template <typename F>\
2167 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2168 typename arg3_type, typename arg4_type, typename arg5_type, \
2169 typename arg6_type, typename arg7_type, typename arg8_type, \
2170 typename arg9_type>\
2171 typename ::testing::internal::Function<F>::Result\
zhanyong.wan33c0af02009-04-03 00:10:12 +00002172 name##ActionP3<p0##_type, p1##_type, \
2173 p2##_type>::gmock_Impl<F>::gmock_PerformImpl(\
2174 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
shiqian326aa562009-01-09 21:43:57 +00002175
2176#define ACTION_P4(name, p0, p1, p2, p3)\
2177 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2178 typename p3##_type>\
2179 class name##ActionP4 {\
2180 public:\
2181 name##ActionP4(p0##_type gmock_p0, p1##_type gmock_p1, \
2182 p2##_type gmock_p2, p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), \
2183 p2(gmock_p2), p3(gmock_p3) {}\
2184 template <typename F>\
2185 class gmock_Impl : public ::testing::ActionInterface<F> {\
2186 public:\
2187 typedef F function_type;\
2188 typedef typename ::testing::internal::Function<F>::Result return_type;\
2189 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
2190 args_type;\
2191 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
2192 p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
2193 p3(gmock_p3) {}\
2194 virtual return_type Perform(const args_type& args) {\
2195 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
2196 Perform(this, args);\
2197 }\
2198 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2199 typename arg3_type, typename arg4_type, typename arg5_type, \
2200 typename arg6_type, typename arg7_type, typename arg8_type, \
2201 typename arg9_type>\
2202 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
2203 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
2204 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
2205 arg9_type arg9) const;\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00002206 p0##_type p0;\
2207 p1##_type p1;\
2208 p2##_type p2;\
2209 p3##_type p3;\
shiqian326aa562009-01-09 21:43:57 +00002210 };\
2211 template <typename F> operator ::testing::Action<F>() const {\
2212 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3));\
2213 }\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00002214 p0##_type p0;\
2215 p1##_type p1;\
2216 p2##_type p2;\
2217 p3##_type p3;\
shiqian326aa562009-01-09 21:43:57 +00002218 };\
2219 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2220 typename p3##_type>\
2221 inline name##ActionP4<p0##_type, p1##_type, p2##_type, \
2222 p3##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
2223 p3##_type p3) {\
2224 return name##ActionP4<p0##_type, p1##_type, p2##_type, p3##_type>(p0, p1, \
2225 p2, p3);\
2226 }\
2227 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2228 typename p3##_type>\
2229 template <typename F>\
2230 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2231 typename arg3_type, typename arg4_type, typename arg5_type, \
2232 typename arg6_type, typename arg7_type, typename arg8_type, \
2233 typename arg9_type>\
2234 typename ::testing::internal::Function<F>::Result\
zhanyong.wan33c0af02009-04-03 00:10:12 +00002235 name##ActionP4<p0##_type, p1##_type, p2##_type, \
2236 p3##_type>::gmock_Impl<F>::gmock_PerformImpl(\
2237 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
shiqian326aa562009-01-09 21:43:57 +00002238
2239#define ACTION_P5(name, p0, p1, p2, p3, p4)\
2240 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2241 typename p3##_type, typename p4##_type>\
2242 class name##ActionP5 {\
2243 public:\
2244 name##ActionP5(p0##_type gmock_p0, p1##_type gmock_p1, \
2245 p2##_type gmock_p2, p3##_type gmock_p3, \
2246 p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
2247 p3(gmock_p3), p4(gmock_p4) {}\
2248 template <typename F>\
2249 class gmock_Impl : public ::testing::ActionInterface<F> {\
2250 public:\
2251 typedef F function_type;\
2252 typedef typename ::testing::internal::Function<F>::Result return_type;\
2253 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
2254 args_type;\
2255 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
2256 p3##_type gmock_p3, p4##_type gmock_p4) : p0(gmock_p0), \
2257 p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), p4(gmock_p4) {}\
2258 virtual return_type Perform(const args_type& args) {\
2259 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
2260 Perform(this, args);\
2261 }\
2262 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2263 typename arg3_type, typename arg4_type, typename arg5_type, \
2264 typename arg6_type, typename arg7_type, typename arg8_type, \
2265 typename arg9_type>\
2266 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
2267 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
2268 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
2269 arg9_type arg9) const;\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00002270 p0##_type p0;\
2271 p1##_type p1;\
2272 p2##_type p2;\
2273 p3##_type p3;\
2274 p4##_type p4;\
shiqian326aa562009-01-09 21:43:57 +00002275 };\
2276 template <typename F> operator ::testing::Action<F>() const {\
2277 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4));\
2278 }\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00002279 p0##_type p0;\
2280 p1##_type p1;\
2281 p2##_type p2;\
2282 p3##_type p3;\
2283 p4##_type p4;\
shiqian326aa562009-01-09 21:43:57 +00002284 };\
2285 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2286 typename p3##_type, typename p4##_type>\
2287 inline name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \
2288 p4##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
2289 p4##_type p4) {\
2290 return name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \
2291 p4##_type>(p0, p1, p2, p3, p4);\
2292 }\
2293 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2294 typename p3##_type, typename p4##_type>\
2295 template <typename F>\
2296 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2297 typename arg3_type, typename arg4_type, typename arg5_type, \
2298 typename arg6_type, typename arg7_type, typename arg8_type, \
2299 typename arg9_type>\
2300 typename ::testing::internal::Function<F>::Result\
zhanyong.wan33c0af02009-04-03 00:10:12 +00002301 name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \
2302 p4##_type>::gmock_Impl<F>::gmock_PerformImpl(\
2303 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
shiqian326aa562009-01-09 21:43:57 +00002304
2305#define ACTION_P6(name, p0, p1, p2, p3, p4, p5)\
2306 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2307 typename p3##_type, typename p4##_type, typename p5##_type>\
2308 class name##ActionP6 {\
2309 public:\
2310 name##ActionP6(p0##_type gmock_p0, p1##_type gmock_p1, \
2311 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
2312 p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
2313 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {}\
2314 template <typename F>\
2315 class gmock_Impl : public ::testing::ActionInterface<F> {\
2316 public:\
2317 typedef F function_type;\
2318 typedef typename ::testing::internal::Function<F>::Result return_type;\
2319 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
2320 args_type;\
2321 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
2322 p3##_type gmock_p3, p4##_type gmock_p4, \
2323 p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
2324 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {}\
2325 virtual return_type Perform(const args_type& args) {\
2326 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
2327 Perform(this, args);\
2328 }\
2329 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2330 typename arg3_type, typename arg4_type, typename arg5_type, \
2331 typename arg6_type, typename arg7_type, typename arg8_type, \
2332 typename arg9_type>\
2333 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
2334 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
2335 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
2336 arg9_type arg9) const;\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00002337 p0##_type p0;\
2338 p1##_type p1;\
2339 p2##_type p2;\
2340 p3##_type p3;\
2341 p4##_type p4;\
2342 p5##_type p5;\
shiqian326aa562009-01-09 21:43:57 +00002343 };\
2344 template <typename F> operator ::testing::Action<F>() const {\
2345 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5));\
2346 }\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00002347 p0##_type p0;\
2348 p1##_type p1;\
2349 p2##_type p2;\
2350 p3##_type p3;\
2351 p4##_type p4;\
2352 p5##_type p5;\
shiqian326aa562009-01-09 21:43:57 +00002353 };\
2354 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2355 typename p3##_type, typename p4##_type, typename p5##_type>\
2356 inline name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, \
2357 p4##_type, p5##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
2358 p3##_type p3, p4##_type p4, p5##_type p5) {\
2359 return name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, \
2360 p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5);\
2361 }\
2362 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2363 typename p3##_type, typename p4##_type, typename p5##_type>\
2364 template <typename F>\
2365 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2366 typename arg3_type, typename arg4_type, typename arg5_type, \
2367 typename arg6_type, typename arg7_type, typename arg8_type, \
2368 typename arg9_type>\
2369 typename ::testing::internal::Function<F>::Result\
2370 name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
zhanyong.wan33c0af02009-04-03 00:10:12 +00002371 p5##_type>::gmock_Impl<F>::gmock_PerformImpl(\
2372 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
shiqian326aa562009-01-09 21:43:57 +00002373
2374#define ACTION_P7(name, p0, p1, p2, p3, p4, p5, p6)\
2375 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2376 typename p3##_type, typename p4##_type, typename p5##_type, \
2377 typename p6##_type>\
2378 class name##ActionP7 {\
2379 public:\
2380 name##ActionP7(p0##_type gmock_p0, p1##_type gmock_p1, \
2381 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
2382 p5##_type gmock_p5, p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), \
2383 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), \
2384 p6(gmock_p6) {}\
2385 template <typename F>\
2386 class gmock_Impl : public ::testing::ActionInterface<F> {\
2387 public:\
2388 typedef F function_type;\
2389 typedef typename ::testing::internal::Function<F>::Result return_type;\
2390 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
2391 args_type;\
2392 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
2393 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
2394 p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
2395 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6) {}\
2396 virtual return_type Perform(const args_type& args) {\
2397 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
2398 Perform(this, args);\
2399 }\
2400 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2401 typename arg3_type, typename arg4_type, typename arg5_type, \
2402 typename arg6_type, typename arg7_type, typename arg8_type, \
2403 typename arg9_type>\
2404 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
2405 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
2406 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
2407 arg9_type arg9) const;\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00002408 p0##_type p0;\
2409 p1##_type p1;\
2410 p2##_type p2;\
2411 p3##_type p3;\
2412 p4##_type p4;\
2413 p5##_type p5;\
2414 p6##_type p6;\
shiqian326aa562009-01-09 21:43:57 +00002415 };\
2416 template <typename F> operator ::testing::Action<F>() const {\
2417 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
2418 p6));\
2419 }\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00002420 p0##_type p0;\
2421 p1##_type p1;\
2422 p2##_type p2;\
2423 p3##_type p3;\
2424 p4##_type p4;\
2425 p5##_type p5;\
2426 p6##_type p6;\
shiqian326aa562009-01-09 21:43:57 +00002427 };\
2428 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2429 typename p3##_type, typename p4##_type, typename p5##_type, \
2430 typename p6##_type>\
2431 inline name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, \
2432 p4##_type, p5##_type, p6##_type> name(p0##_type p0, p1##_type p1, \
2433 p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
2434 p6##_type p6) {\
2435 return name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, \
2436 p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, p6);\
2437 }\
2438 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2439 typename p3##_type, typename p4##_type, typename p5##_type, \
2440 typename p6##_type>\
2441 template <typename F>\
2442 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2443 typename arg3_type, typename arg4_type, typename arg5_type, \
2444 typename arg6_type, typename arg7_type, typename arg8_type, \
2445 typename arg9_type>\
2446 typename ::testing::internal::Function<F>::Result\
2447 name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
zhanyong.wan33c0af02009-04-03 00:10:12 +00002448 p5##_type, p6##_type>::gmock_Impl<F>::gmock_PerformImpl(\
2449 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
shiqian326aa562009-01-09 21:43:57 +00002450
2451#define ACTION_P8(name, p0, p1, p2, p3, p4, p5, p6, p7)\
2452 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2453 typename p3##_type, typename p4##_type, typename p5##_type, \
2454 typename p6##_type, typename p7##_type>\
2455 class name##ActionP8 {\
2456 public:\
2457 name##ActionP8(p0##_type gmock_p0, p1##_type gmock_p1, \
2458 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
2459 p5##_type gmock_p5, p6##_type gmock_p6, \
2460 p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
2461 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
2462 p7(gmock_p7) {}\
2463 template <typename F>\
2464 class gmock_Impl : public ::testing::ActionInterface<F> {\
2465 public:\
2466 typedef F function_type;\
2467 typedef typename ::testing::internal::Function<F>::Result return_type;\
2468 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
2469 args_type;\
2470 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
2471 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
2472 p6##_type gmock_p6, p7##_type gmock_p7) : p0(gmock_p0), \
2473 p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), \
2474 p5(gmock_p5), p6(gmock_p6), p7(gmock_p7) {}\
2475 virtual return_type Perform(const args_type& args) {\
2476 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
2477 Perform(this, args);\
2478 }\
2479 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2480 typename arg3_type, typename arg4_type, typename arg5_type, \
2481 typename arg6_type, typename arg7_type, typename arg8_type, \
2482 typename arg9_type>\
2483 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
2484 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
2485 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
2486 arg9_type arg9) const;\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00002487 p0##_type p0;\
2488 p1##_type p1;\
2489 p2##_type p2;\
2490 p3##_type p3;\
2491 p4##_type p4;\
2492 p5##_type p5;\
2493 p6##_type p6;\
2494 p7##_type p7;\
shiqian326aa562009-01-09 21:43:57 +00002495 };\
2496 template <typename F> operator ::testing::Action<F>() const {\
2497 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
2498 p6, p7));\
2499 }\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00002500 p0##_type p0;\
2501 p1##_type p1;\
2502 p2##_type p2;\
2503 p3##_type p3;\
2504 p4##_type p4;\
2505 p5##_type p5;\
2506 p6##_type p6;\
2507 p7##_type p7;\
shiqian326aa562009-01-09 21:43:57 +00002508 };\
2509 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2510 typename p3##_type, typename p4##_type, typename p5##_type, \
2511 typename p6##_type, typename p7##_type>\
2512 inline name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, \
2513 p4##_type, p5##_type, p6##_type, p7##_type> name(p0##_type p0, \
2514 p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
2515 p6##_type p6, p7##_type p7) {\
2516 return name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, \
2517 p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, p3, p4, p5, \
2518 p6, p7);\
2519 }\
2520 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2521 typename p3##_type, typename p4##_type, typename p5##_type, \
2522 typename p6##_type, typename p7##_type>\
2523 template <typename F>\
2524 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2525 typename arg3_type, typename arg4_type, typename arg5_type, \
2526 typename arg6_type, typename arg7_type, typename arg8_type, \
2527 typename arg9_type>\
2528 typename ::testing::internal::Function<F>::Result\
2529 name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
zhanyong.wan33c0af02009-04-03 00:10:12 +00002530 p5##_type, p6##_type, \
2531 p7##_type>::gmock_Impl<F>::gmock_PerformImpl(\
2532 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
shiqian326aa562009-01-09 21:43:57 +00002533
2534#define ACTION_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8)\
2535 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2536 typename p3##_type, typename p4##_type, typename p5##_type, \
2537 typename p6##_type, typename p7##_type, typename p8##_type>\
2538 class name##ActionP9 {\
2539 public:\
2540 name##ActionP9(p0##_type gmock_p0, p1##_type gmock_p1, \
2541 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
2542 p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
2543 p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
2544 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
2545 p8(gmock_p8) {}\
2546 template <typename F>\
2547 class gmock_Impl : public ::testing::ActionInterface<F> {\
2548 public:\
2549 typedef F function_type;\
2550 typedef typename ::testing::internal::Function<F>::Result return_type;\
2551 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
2552 args_type;\
2553 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
2554 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
2555 p6##_type gmock_p6, p7##_type gmock_p7, \
2556 p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
2557 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
2558 p7(gmock_p7), p8(gmock_p8) {}\
2559 virtual return_type Perform(const args_type& args) {\
2560 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
2561 Perform(this, args);\
2562 }\
2563 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2564 typename arg3_type, typename arg4_type, typename arg5_type, \
2565 typename arg6_type, typename arg7_type, typename arg8_type, \
2566 typename arg9_type>\
2567 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
2568 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
2569 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
2570 arg9_type arg9) const;\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00002571 p0##_type p0;\
2572 p1##_type p1;\
2573 p2##_type p2;\
2574 p3##_type p3;\
2575 p4##_type p4;\
2576 p5##_type p5;\
2577 p6##_type p6;\
2578 p7##_type p7;\
2579 p8##_type p8;\
shiqian326aa562009-01-09 21:43:57 +00002580 };\
2581 template <typename F> operator ::testing::Action<F>() const {\
2582 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
2583 p6, p7, p8));\
2584 }\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00002585 p0##_type p0;\
2586 p1##_type p1;\
2587 p2##_type p2;\
2588 p3##_type p3;\
2589 p4##_type p4;\
2590 p5##_type p5;\
2591 p6##_type p6;\
2592 p7##_type p7;\
2593 p8##_type p8;\
shiqian326aa562009-01-09 21:43:57 +00002594 };\
2595 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2596 typename p3##_type, typename p4##_type, typename p5##_type, \
2597 typename p6##_type, typename p7##_type, typename p8##_type>\
2598 inline name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, \
2599 p4##_type, p5##_type, p6##_type, p7##_type, \
2600 p8##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
2601 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, \
2602 p8##_type p8) {\
2603 return name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, \
2604 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type>(p0, p1, p2, \
2605 p3, p4, p5, p6, p7, p8);\
2606 }\
2607 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2608 typename p3##_type, typename p4##_type, typename p5##_type, \
2609 typename p6##_type, typename p7##_type, typename p8##_type>\
2610 template <typename F>\
2611 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2612 typename arg3_type, typename arg4_type, typename arg5_type, \
2613 typename arg6_type, typename arg7_type, typename arg8_type, \
2614 typename arg9_type>\
2615 typename ::testing::internal::Function<F>::Result\
2616 name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
zhanyong.wan33c0af02009-04-03 00:10:12 +00002617 p5##_type, p6##_type, p7##_type, \
2618 p8##_type>::gmock_Impl<F>::gmock_PerformImpl(\
2619 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
shiqian326aa562009-01-09 21:43:57 +00002620
2621#define ACTION_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)\
2622 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2623 typename p3##_type, typename p4##_type, typename p5##_type, \
2624 typename p6##_type, typename p7##_type, typename p8##_type, \
2625 typename p9##_type>\
2626 class name##ActionP10 {\
2627 public:\
2628 name##ActionP10(p0##_type gmock_p0, p1##_type gmock_p1, \
2629 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
2630 p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
2631 p8##_type gmock_p8, p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), \
2632 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
2633 p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {}\
2634 template <typename F>\
2635 class gmock_Impl : public ::testing::ActionInterface<F> {\
2636 public:\
2637 typedef F function_type;\
2638 typedef typename ::testing::internal::Function<F>::Result return_type;\
2639 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
2640 args_type;\
2641 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
2642 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
2643 p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
2644 p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
2645 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
2646 p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {}\
2647 virtual return_type Perform(const args_type& args) {\
2648 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
2649 Perform(this, args);\
2650 }\
2651 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2652 typename arg3_type, typename arg4_type, typename arg5_type, \
2653 typename arg6_type, typename arg7_type, typename arg8_type, \
2654 typename arg9_type>\
2655 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
2656 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
2657 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
2658 arg9_type arg9) const;\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00002659 p0##_type p0;\
2660 p1##_type p1;\
2661 p2##_type p2;\
2662 p3##_type p3;\
2663 p4##_type p4;\
2664 p5##_type p5;\
2665 p6##_type p6;\
2666 p7##_type p7;\
2667 p8##_type p8;\
2668 p9##_type p9;\
shiqian326aa562009-01-09 21:43:57 +00002669 };\
2670 template <typename F> operator ::testing::Action<F>() const {\
2671 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
2672 p6, p7, p8, p9));\
2673 }\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00002674 p0##_type p0;\
2675 p1##_type p1;\
2676 p2##_type p2;\
2677 p3##_type p3;\
2678 p4##_type p4;\
2679 p5##_type p5;\
2680 p6##_type p6;\
2681 p7##_type p7;\
2682 p8##_type p8;\
2683 p9##_type p9;\
shiqian326aa562009-01-09 21:43:57 +00002684 };\
2685 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2686 typename p3##_type, typename p4##_type, typename p5##_type, \
2687 typename p6##_type, typename p7##_type, typename p8##_type, \
2688 typename p9##_type>\
2689 inline name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, \
2690 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
2691 p9##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
2692 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \
2693 p9##_type p9) {\
2694 return name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, \
2695 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, p9##_type>(p0, \
2696 p1, p2, p3, p4, p5, p6, p7, p8, p9);\
2697 }\
2698 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2699 typename p3##_type, typename p4##_type, typename p5##_type, \
2700 typename p6##_type, typename p7##_type, typename p8##_type, \
2701 typename p9##_type>\
2702 template <typename F>\
2703 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2704 typename arg3_type, typename arg4_type, typename arg5_type, \
2705 typename arg6_type, typename arg7_type, typename arg8_type, \
2706 typename arg9_type>\
2707 typename ::testing::internal::Function<F>::Result\
2708 name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
zhanyong.wan33c0af02009-04-03 00:10:12 +00002709 p5##_type, p6##_type, p7##_type, p8##_type, \
2710 p9##_type>::gmock_Impl<F>::gmock_PerformImpl(\
2711 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
shiqian326aa562009-01-09 21:43:57 +00002712
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00002713// TODO(wan@google.com): move the following to a different .h file
2714// such that we don't have to run 'pump' every time the code is
2715// updated.
zhanyong.wane1cdce52009-02-06 01:09:43 +00002716namespace testing {
2717
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00002718namespace internal {
2719
2720// Saves argument #0 to where the pointer points.
2721ACTION_P(SaveArg0, pointer) { *pointer = arg0; }
2722
2723// Assigns 'value' to the variable referenced by argument #0.
2724ACTION_P(SetArg0Referee, value) {
2725 // Ensures that argument #0 is a reference. If you get a compiler
2726 // error on the next line, you are using SetArgReferee<k>(value) in
2727 // a mock function whose k-th (0-based) argument is not a reference.
2728 GMOCK_COMPILE_ASSERT_(internal::is_reference<arg0_type>::value,
2729 SetArgReferee_must_be_used_with_a_reference_argument);
2730 arg0 = value;
2731}
2732
zhanyong.wan1c8eb1c2009-04-09 07:29:58 +00002733// ReturnNewAction<T> creates and returns a new instance of an object each time
2734// it is performed. It is overloaded to work with constructors that take
2735// different numbers of arguments.
2736// Returns a new instance of T using a nullary constructor with the given
2737// arguments.
2738template <typename T>
2739class ReturnNewAction0 {
2740 public:
2741 ReturnNewAction0() {}
2742
2743 template <typename Result, typename ArgumentTuple>
2744 Result Perform(const ArgumentTuple& /* args */) {
2745 return new T();
2746 }
2747 private:
2748};
2749
2750// Returns a new instance of T using a unary constructor with the given
2751// arguments.
2752template <typename T, typename A1>
2753class ReturnNewAction1 {
2754 public:
2755 explicit ReturnNewAction1(A1 a1) : arg1_(a1) {}
2756
2757 template <typename Result, typename ArgumentTuple>
2758 Result Perform(const ArgumentTuple& /* args */) {
2759 return new T(arg1_);
2760 }
2761 private:
2762 const A1 arg1_;
2763};
2764
2765// Returns a new instance of T using a binary constructor with the given
2766// arguments.
2767template <typename T, typename A1, typename A2>
2768class ReturnNewAction2 {
2769 public:
2770 ReturnNewAction2(A1 a1, A2 a2) : arg1_(a1), arg2_(a2) {}
2771
2772 template <typename Result, typename ArgumentTuple>
2773 Result Perform(const ArgumentTuple& /* args */) {
2774 return new T(arg1_, arg2_);
2775 }
2776 private:
2777 const A1 arg1_;
2778 const A2 arg2_;
2779};
2780
2781// Returns a new instance of T using a ternary constructor with the given
2782// arguments.
2783template <typename T, typename A1, typename A2, typename A3>
2784class ReturnNewAction3 {
2785 public:
2786 ReturnNewAction3(A1 a1, A2 a2, A3 a3) : arg1_(a1), arg2_(a2), arg3_(a3) {}
2787
2788 template <typename Result, typename ArgumentTuple>
2789 Result Perform(const ArgumentTuple& /* args */) {
2790 return new T(arg1_, arg2_, arg3_);
2791 }
2792 private:
2793 const A1 arg1_;
2794 const A2 arg2_;
2795 const A3 arg3_;
2796};
2797
2798// Returns a new instance of T using a 4-ary constructor with the given
2799// arguments.
2800template <typename T, typename A1, typename A2, typename A3, typename A4>
2801class ReturnNewAction4 {
2802 public:
2803 ReturnNewAction4(A1 a1, A2 a2, A3 a3, A4 a4) : arg1_(a1), arg2_(a2),
2804 arg3_(a3), arg4_(a4) {}
2805
2806 template <typename Result, typename ArgumentTuple>
2807 Result Perform(const ArgumentTuple& /* args */) {
2808 return new T(arg1_, arg2_, arg3_, arg4_);
2809 }
2810 private:
2811 const A1 arg1_;
2812 const A2 arg2_;
2813 const A3 arg3_;
2814 const A4 arg4_;
2815};
2816
2817// Returns a new instance of T using a 5-ary constructor with the given
2818// arguments.
2819template <typename T, typename A1, typename A2, typename A3, typename A4,
2820 typename A5>
2821class ReturnNewAction5 {
2822 public:
2823 ReturnNewAction5(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) : arg1_(a1), arg2_(a2),
2824 arg3_(a3), arg4_(a4), arg5_(a5) {}
2825
2826 template <typename Result, typename ArgumentTuple>
2827 Result Perform(const ArgumentTuple& /* args */) {
2828 return new T(arg1_, arg2_, arg3_, arg4_, arg5_);
2829 }
2830 private:
2831 const A1 arg1_;
2832 const A2 arg2_;
2833 const A3 arg3_;
2834 const A4 arg4_;
2835 const A5 arg5_;
2836};
2837
2838// Returns a new instance of T using a 6-ary constructor with the given
2839// arguments.
2840template <typename T, typename A1, typename A2, typename A3, typename A4,
2841 typename A5, typename A6>
2842class ReturnNewAction6 {
2843 public:
2844 ReturnNewAction6(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) : arg1_(a1),
2845 arg2_(a2), arg3_(a3), arg4_(a4), arg5_(a5), arg6_(a6) {}
2846
2847 template <typename Result, typename ArgumentTuple>
2848 Result Perform(const ArgumentTuple& /* args */) {
2849 return new T(arg1_, arg2_, arg3_, arg4_, arg5_, arg6_);
2850 }
2851 private:
2852 const A1 arg1_;
2853 const A2 arg2_;
2854 const A3 arg3_;
2855 const A4 arg4_;
2856 const A5 arg5_;
2857 const A6 arg6_;
2858};
2859
2860// Returns a new instance of T using a 7-ary constructor with the given
2861// arguments.
2862template <typename T, typename A1, typename A2, typename A3, typename A4,
2863 typename A5, typename A6, typename A7>
2864class ReturnNewAction7 {
2865 public:
2866 ReturnNewAction7(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
2867 A7 a7) : arg1_(a1), arg2_(a2), arg3_(a3), arg4_(a4), arg5_(a5),
2868 arg6_(a6), arg7_(a7) {}
2869
2870 template <typename Result, typename ArgumentTuple>
2871 Result Perform(const ArgumentTuple& /* args */) {
2872 return new T(arg1_, arg2_, arg3_, arg4_, arg5_, arg6_, arg7_);
2873 }
2874 private:
2875 const A1 arg1_;
2876 const A2 arg2_;
2877 const A3 arg3_;
2878 const A4 arg4_;
2879 const A5 arg5_;
2880 const A6 arg6_;
2881 const A7 arg7_;
2882};
2883
2884// Returns a new instance of T using a 8-ary constructor with the given
2885// arguments.
2886template <typename T, typename A1, typename A2, typename A3, typename A4,
2887 typename A5, typename A6, typename A7, typename A8>
2888class ReturnNewAction8 {
2889 public:
2890 ReturnNewAction8(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7,
2891 A8 a8) : arg1_(a1), arg2_(a2), arg3_(a3), arg4_(a4), arg5_(a5),
2892 arg6_(a6), arg7_(a7), arg8_(a8) {}
2893
2894 template <typename Result, typename ArgumentTuple>
2895 Result Perform(const ArgumentTuple& /* args */) {
2896 return new T(arg1_, arg2_, arg3_, arg4_, arg5_, arg6_, arg7_, arg8_);
2897 }
2898 private:
2899 const A1 arg1_;
2900 const A2 arg2_;
2901 const A3 arg3_;
2902 const A4 arg4_;
2903 const A5 arg5_;
2904 const A6 arg6_;
2905 const A7 arg7_;
2906 const A8 arg8_;
2907};
2908
2909// Returns a new instance of T using a 9-ary constructor with the given
2910// arguments.
2911template <typename T, typename A1, typename A2, typename A3, typename A4,
2912 typename A5, typename A6, typename A7, typename A8, typename A9>
2913class ReturnNewAction9 {
2914 public:
2915 ReturnNewAction9(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8,
2916 A9 a9) : arg1_(a1), arg2_(a2), arg3_(a3), arg4_(a4), arg5_(a5),
2917 arg6_(a6), arg7_(a7), arg8_(a8), arg9_(a9) {}
2918
2919 template <typename Result, typename ArgumentTuple>
2920 Result Perform(const ArgumentTuple& /* args */) {
2921 return new T(arg1_, arg2_, arg3_, arg4_, arg5_, arg6_, arg7_, arg8_, arg9_);
2922 }
2923 private:
2924 const A1 arg1_;
2925 const A2 arg2_;
2926 const A3 arg3_;
2927 const A4 arg4_;
2928 const A5 arg5_;
2929 const A6 arg6_;
2930 const A7 arg7_;
2931 const A8 arg8_;
2932 const A9 arg9_;
2933};
2934
2935// Returns a new instance of T using a 10-ary constructor with the given
2936// arguments.
2937template <typename T, typename A1, typename A2, typename A3, typename A4,
2938 typename A5, typename A6, typename A7, typename A8, typename A9,
2939 typename A10>
2940class ReturnNewAction10 {
2941 public:
2942 ReturnNewAction10(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8,
2943 A9 a9, A10 a10) : arg1_(a1), arg2_(a2), arg3_(a3), arg4_(a4), arg5_(a5),
2944 arg6_(a6), arg7_(a7), arg8_(a8), arg9_(a9), arg10_(a10) {}
2945
2946 template <typename Result, typename ArgumentTuple>
2947 Result Perform(const ArgumentTuple& /* args */) {
2948 return new T(arg1_, arg2_, arg3_, arg4_, arg5_, arg6_, arg7_, arg8_, arg9_,
2949 arg10_);
2950 }
2951 private:
2952 const A1 arg1_;
2953 const A2 arg2_;
2954 const A3 arg3_;
2955 const A4 arg4_;
2956 const A5 arg5_;
2957 const A6 arg6_;
2958 const A7 arg7_;
2959 const A8 arg8_;
2960 const A9 arg9_;
2961 const A10 arg10_;
2962};
2963
2964// Deletes the object pointed to by argument #0.
2965ACTION(DeleteArg0) { delete arg0; }
2966
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00002967} // namespace internal
2968
2969// Action SaveArg<k>(pointer) saves the k-th (0-based) argument of the
2970// mock function to *pointer.
2971template <int k, typename Pointer>
2972inline internal::WithArgsAction<internal::SaveArg0ActionP<Pointer>, k>
2973SaveArg(const Pointer& pointer) {
2974 return WithArg<k>(internal::SaveArg0(pointer));
2975}
2976
2977// Action SetArgReferee<k>(value) assigns 'value' to the variable
2978// referenced by the k-th (0-based) argument of the mock function.
2979template <int k, typename Value>
2980inline internal::WithArgsAction<internal::SetArg0RefereeActionP<Value>, k>
2981SetArgReferee(const Value& value) {
2982 return WithArg<k>(internal::SetArg0Referee(value));
2983}
2984
zhanyong.wan1c8eb1c2009-04-09 07:29:58 +00002985// Various overloads for ReturnNew<T>().
2986//
2987// The ReturnNew<T>(a1, a2, ..., a_k) action returns a pointer to a new
2988// instance of type T, constructed on the heap with constructor arguments
2989// a1, a2, ..., and a_k. The caller assumes ownership of the returned value.
2990template <typename T>
2991inline PolymorphicAction<internal::ReturnNewAction0<T> >
2992ReturnNew() {
2993 return MakePolymorphicAction(
2994 internal::ReturnNewAction0<T>());
2995}
2996
2997template <typename T, typename A1>
2998inline PolymorphicAction<internal::ReturnNewAction1<T, A1> >
2999ReturnNew(A1 a1) {
3000 return MakePolymorphicAction(
3001 internal::ReturnNewAction1<T, A1>(a1));
3002}
3003
3004template <typename T, typename A1, typename A2>
3005inline PolymorphicAction<internal::ReturnNewAction2<T, A1, A2> >
3006ReturnNew(A1 a1, A2 a2) {
3007 return MakePolymorphicAction(
3008 internal::ReturnNewAction2<T, A1, A2>(a1, a2));
3009}
3010
3011template <typename T, typename A1, typename A2, typename A3>
3012inline PolymorphicAction<internal::ReturnNewAction3<T, A1, A2, A3> >
3013ReturnNew(A1 a1, A2 a2, A3 a3) {
3014 return MakePolymorphicAction(
3015 internal::ReturnNewAction3<T, A1, A2, A3>(a1, a2, a3));
3016}
3017
3018template <typename T, typename A1, typename A2, typename A3, typename A4>
3019inline PolymorphicAction<internal::ReturnNewAction4<T, A1, A2, A3, A4> >
3020ReturnNew(A1 a1, A2 a2, A3 a3, A4 a4) {
3021 return MakePolymorphicAction(
3022 internal::ReturnNewAction4<T, A1, A2, A3, A4>(a1, a2, a3, a4));
3023}
3024
3025template <typename T, typename A1, typename A2, typename A3, typename A4,
3026 typename A5>
3027inline PolymorphicAction<internal::ReturnNewAction5<T, A1, A2, A3, A4, A5> >
3028ReturnNew(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) {
3029 return MakePolymorphicAction(
3030 internal::ReturnNewAction5<T, A1, A2, A3, A4, A5>(a1, a2, a3, a4, a5));
3031}
3032
3033template <typename T, typename A1, typename A2, typename A3, typename A4,
3034 typename A5, typename A6>
3035inline PolymorphicAction<internal::ReturnNewAction6<T, A1, A2, A3, A4, A5, A6> >
3036ReturnNew(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) {
3037 return MakePolymorphicAction(
3038 internal::ReturnNewAction6<T, A1, A2, A3, A4, A5, A6>(a1, a2, a3, a4, a5,
3039 a6));
3040}
3041
3042template <typename T, typename A1, typename A2, typename A3, typename A4,
3043 typename A5, typename A6, typename A7>
3044inline PolymorphicAction<internal::ReturnNewAction7<T, A1, A2, A3, A4, A5, A6,
3045 A7> >
3046ReturnNew(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) {
3047 return MakePolymorphicAction(
3048 internal::ReturnNewAction7<T, A1, A2, A3, A4, A5, A6, A7>(a1, a2, a3, a4,
3049 a5, a6, a7));
3050}
3051
3052template <typename T, typename A1, typename A2, typename A3, typename A4,
3053 typename A5, typename A6, typename A7, typename A8>
3054inline PolymorphicAction<internal::ReturnNewAction8<T, A1, A2, A3, A4, A5, A6,
3055 A7, A8> >
3056ReturnNew(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) {
3057 return MakePolymorphicAction(
3058 internal::ReturnNewAction8<T, A1, A2, A3, A4, A5, A6, A7, A8>(a1, a2, a3,
3059 a4, a5, a6, a7, a8));
3060}
3061
3062template <typename T, typename A1, typename A2, typename A3, typename A4,
3063 typename A5, typename A6, typename A7, typename A8, typename A9>
3064inline PolymorphicAction<internal::ReturnNewAction9<T, A1, A2, A3, A4, A5, A6,
3065 A7, A8, A9> >
3066ReturnNew(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) {
3067 return MakePolymorphicAction(
3068 internal::ReturnNewAction9<T, A1, A2, A3, A4, A5, A6, A7, A8, A9>(a1, a2,
3069 a3, a4, a5, a6, a7, a8, a9));
3070}
3071
3072template <typename T, typename A1, typename A2, typename A3, typename A4,
3073 typename A5, typename A6, typename A7, typename A8, typename A9,
3074 typename A10>
3075inline PolymorphicAction<internal::ReturnNewAction10<T, A1, A2, A3, A4, A5, A6,
3076 A7, A8, A9, A10> >
3077ReturnNew(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9,
3078 A10 a10) {
3079 return MakePolymorphicAction(
3080 internal::ReturnNewAction10<T, A1, A2, A3, A4, A5, A6, A7, A8, A9,
3081 A10>(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10));
3082}
3083
3084// Action DeleteArg<k>() deletes the k-th (0-based) argument of the mock
3085// function.
3086template <int k>
3087inline internal::WithArgsAction<internal::DeleteArg0Action, k>
3088DeleteArg() {
3089 return WithArg<k>(internal::DeleteArg0());
3090}
3091
zhanyong.wane1cdce52009-02-06 01:09:43 +00003092// Action Throw(exception) can be used in a mock function of any type
3093// to throw the given exception. Any copyable value can be thrown.
3094#if GTEST_HAS_EXCEPTIONS
3095ACTION_P(Throw, exception) { throw exception; }
3096#endif // GTEST_HAS_EXCEPTIONS
3097
3098} // namespace testing
3099
shiqiane35fdd92008-12-10 05:08:54 +00003100#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_