blob: fa02faaad4b2f07529fd149de2f90744a768d95e [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
shiqiane35fdd92008-12-10 05:08:54 +0000446// An INTERNAL macro for extracting the type of a tuple field. It's
447// subject to change without notice - DO NOT USE IN USER CODE!
zhanyong.wane0d051e2009-02-19 00:33:37 +0000448#define GMOCK_FIELD_(Tuple, N) \
shiqiane35fdd92008-12-10 05:08:54 +0000449 typename ::std::tr1::tuple_element<N, Tuple>::type
450
451// SelectArgs<Result, ArgumentTuple, k1, k2, ..., k_n>::type is the
452// type of an n-ary function whose i-th (1-based) argument type is the
453// k{i}-th (0-based) field of ArgumentTuple, which must be a tuple
454// type, and whose return type is Result. For example,
455// SelectArgs<int, ::std::tr1::tuple<bool, char, double, long>, 0, 3>::type
456// is int(bool, long).
457//
458// SelectArgs<Result, ArgumentTuple, k1, k2, ..., k_n>::Select(args)
459// returns the selected fields (k1, k2, ..., k_n) of args as a tuple.
460// For example,
461// SelectArgs<int, ::std::tr1::tuple<bool, char, double>, 2, 0>::Select(
462// ::std::tr1::make_tuple(true, 'a', 2.5))
463// returns ::std::tr1::tuple (2.5, true).
464//
465// The numbers in list k1, k2, ..., k_n must be >= 0, where n can be
466// in the range [0, 10]. Duplicates are allowed and they don't have
467// to be in an ascending or descending order.
468
469template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
470 int k4, int k5, int k6, int k7, int k8, int k9, int k10>
471class SelectArgs {
472 public:
zhanyong.wane0d051e2009-02-19 00:33:37 +0000473 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
474 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
475 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5),
476 GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7),
477 GMOCK_FIELD_(ArgumentTuple, k8), GMOCK_FIELD_(ArgumentTuple, k9),
478 GMOCK_FIELD_(ArgumentTuple, k10));
shiqiane35fdd92008-12-10 05:08:54 +0000479 typedef typename Function<type>::ArgumentTuple SelectedArgs;
480 static SelectedArgs Select(const ArgumentTuple& args) {
481 using ::std::tr1::get;
482 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
483 get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args),
484 get<k8>(args), get<k9>(args), get<k10>(args));
485 }
486};
487
488template <typename Result, typename ArgumentTuple>
489class SelectArgs<Result, ArgumentTuple,
490 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1> {
491 public:
492 typedef Result type();
493 typedef typename Function<type>::ArgumentTuple SelectedArgs;
zhanyong.wan3fbd2dd2009-03-26 19:06:45 +0000494 static SelectedArgs Select(const ArgumentTuple& /* args */) {
shiqiane35fdd92008-12-10 05:08:54 +0000495 using ::std::tr1::get;
496 return SelectedArgs();
497 }
498};
499
500template <typename Result, typename ArgumentTuple, int k1>
501class SelectArgs<Result, ArgumentTuple,
502 k1, -1, -1, -1, -1, -1, -1, -1, -1, -1> {
503 public:
zhanyong.wane0d051e2009-02-19 00:33:37 +0000504 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1));
shiqiane35fdd92008-12-10 05:08:54 +0000505 typedef typename Function<type>::ArgumentTuple SelectedArgs;
506 static SelectedArgs Select(const ArgumentTuple& args) {
507 using ::std::tr1::get;
508 return SelectedArgs(get<k1>(args));
509 }
510};
511
512template <typename Result, typename ArgumentTuple, int k1, int k2>
513class SelectArgs<Result, ArgumentTuple,
514 k1, k2, -1, -1, -1, -1, -1, -1, -1, -1> {
515 public:
zhanyong.wane0d051e2009-02-19 00:33:37 +0000516 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
517 GMOCK_FIELD_(ArgumentTuple, k2));
shiqiane35fdd92008-12-10 05:08:54 +0000518 typedef typename Function<type>::ArgumentTuple SelectedArgs;
519 static SelectedArgs Select(const ArgumentTuple& args) {
520 using ::std::tr1::get;
521 return SelectedArgs(get<k1>(args), get<k2>(args));
522 }
523};
524
525template <typename Result, typename ArgumentTuple, int k1, int k2, int k3>
526class SelectArgs<Result, ArgumentTuple,
527 k1, k2, k3, -1, -1, -1, -1, -1, -1, -1> {
528 public:
zhanyong.wane0d051e2009-02-19 00:33:37 +0000529 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
530 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3));
shiqiane35fdd92008-12-10 05:08:54 +0000531 typedef typename Function<type>::ArgumentTuple SelectedArgs;
532 static SelectedArgs Select(const ArgumentTuple& args) {
533 using ::std::tr1::get;
534 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args));
535 }
536};
537
538template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
539 int k4>
540class SelectArgs<Result, ArgumentTuple,
541 k1, k2, k3, k4, -1, -1, -1, -1, -1, -1> {
542 public:
zhanyong.wane0d051e2009-02-19 00:33:37 +0000543 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
544 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
545 GMOCK_FIELD_(ArgumentTuple, k4));
shiqiane35fdd92008-12-10 05:08:54 +0000546 typedef typename Function<type>::ArgumentTuple SelectedArgs;
547 static SelectedArgs Select(const ArgumentTuple& args) {
548 using ::std::tr1::get;
549 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
550 get<k4>(args));
551 }
552};
553
554template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
555 int k4, int k5>
556class SelectArgs<Result, ArgumentTuple,
557 k1, k2, k3, k4, k5, -1, -1, -1, -1, -1> {
558 public:
zhanyong.wane0d051e2009-02-19 00:33:37 +0000559 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
560 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
561 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5));
shiqiane35fdd92008-12-10 05:08:54 +0000562 typedef typename Function<type>::ArgumentTuple SelectedArgs;
563 static SelectedArgs Select(const ArgumentTuple& args) {
564 using ::std::tr1::get;
565 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
566 get<k4>(args), get<k5>(args));
567 }
568};
569
570template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
571 int k4, int k5, int k6>
572class SelectArgs<Result, ArgumentTuple,
573 k1, k2, k3, k4, k5, k6, -1, -1, -1, -1> {
574 public:
zhanyong.wane0d051e2009-02-19 00:33:37 +0000575 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
576 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
577 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5),
578 GMOCK_FIELD_(ArgumentTuple, k6));
shiqiane35fdd92008-12-10 05:08:54 +0000579 typedef typename Function<type>::ArgumentTuple SelectedArgs;
580 static SelectedArgs Select(const ArgumentTuple& args) {
581 using ::std::tr1::get;
582 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
583 get<k4>(args), get<k5>(args), get<k6>(args));
584 }
585};
586
587template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
588 int k4, int k5, int k6, int k7>
589class SelectArgs<Result, ArgumentTuple,
590 k1, k2, k3, k4, k5, k6, k7, -1, -1, -1> {
591 public:
zhanyong.wane0d051e2009-02-19 00:33:37 +0000592 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
593 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
594 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5),
595 GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7));
shiqiane35fdd92008-12-10 05:08:54 +0000596 typedef typename Function<type>::ArgumentTuple SelectedArgs;
597 static SelectedArgs Select(const ArgumentTuple& args) {
598 using ::std::tr1::get;
599 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
600 get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args));
601 }
602};
603
604template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
605 int k4, int k5, int k6, int k7, int k8>
606class SelectArgs<Result, ArgumentTuple,
607 k1, k2, k3, k4, k5, k6, k7, k8, -1, -1> {
608 public:
zhanyong.wane0d051e2009-02-19 00:33:37 +0000609 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
610 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
611 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5),
612 GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7),
613 GMOCK_FIELD_(ArgumentTuple, k8));
shiqiane35fdd92008-12-10 05:08:54 +0000614 typedef typename Function<type>::ArgumentTuple SelectedArgs;
615 static SelectedArgs Select(const ArgumentTuple& args) {
616 using ::std::tr1::get;
617 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
618 get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args),
619 get<k8>(args));
620 }
621};
622
623template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
624 int k4, int k5, int k6, int k7, int k8, int k9>
625class SelectArgs<Result, ArgumentTuple,
626 k1, k2, k3, k4, k5, k6, k7, k8, k9, -1> {
627 public:
zhanyong.wane0d051e2009-02-19 00:33:37 +0000628 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
629 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
630 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5),
631 GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7),
632 GMOCK_FIELD_(ArgumentTuple, k8), GMOCK_FIELD_(ArgumentTuple, k9));
shiqiane35fdd92008-12-10 05:08:54 +0000633 typedef typename Function<type>::ArgumentTuple SelectedArgs;
634 static SelectedArgs Select(const ArgumentTuple& args) {
635 using ::std::tr1::get;
636 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
637 get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args),
638 get<k8>(args), get<k9>(args));
639 }
640};
641
zhanyong.wane0d051e2009-02-19 00:33:37 +0000642#undef GMOCK_FIELD_
shiqiane35fdd92008-12-10 05:08:54 +0000643
644// Implements the WithArgs action.
645template <typename InnerAction, int k1 = -1, int k2 = -1, int k3 = -1,
646 int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1, int k8 = -1,
647 int k9 = -1, int k10 = -1>
648class WithArgsAction {
649 public:
650 explicit WithArgsAction(const InnerAction& action) : action_(action) {}
651
652 template <typename F>
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000653 operator Action<F>() const { return MakeAction(new Impl<F>(action_)); }
654
655 private:
656 template <typename F>
657 class Impl : public ActionInterface<F> {
658 public:
shiqiane35fdd92008-12-10 05:08:54 +0000659 typedef typename Function<F>::Result Result;
660 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000661
662 explicit Impl(const InnerAction& action) : action_(action) {}
663
664 virtual Result Perform(const ArgumentTuple& args) {
665 return action_.Perform(SelectArgs<Result, ArgumentTuple, k1, k2, k3, k4,
666 k5, k6, k7, k8, k9, k10>::Select(args));
667 }
668
669 private:
shiqiane35fdd92008-12-10 05:08:54 +0000670 typedef typename SelectArgs<Result, ArgumentTuple,
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000671 k1, k2, k3, k4, k5, k6, k7, k8, k9, k10>::type InnerFunctionType;
shiqiane35fdd92008-12-10 05:08:54 +0000672
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000673 Action<InnerFunctionType> action_;
674 };
shiqiane35fdd92008-12-10 05:08:54 +0000675
shiqiane35fdd92008-12-10 05:08:54 +0000676 const InnerAction action_;
677};
678
679// Does two actions sequentially. Used for implementing the DoAll(a1,
680// a2, ...) action.
681template <typename Action1, typename Action2>
682class DoBothAction {
683 public:
684 DoBothAction(Action1 action1, Action2 action2)
685 : action1_(action1), action2_(action2) {}
686
687 // This template type conversion operator allows DoAll(a1, ..., a_n)
688 // to be used in ANY function of compatible type.
689 template <typename F>
690 operator Action<F>() const {
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000691 return Action<F>(new Impl<F>(action1_, action2_));
692 }
693
694 private:
695 // Implements the DoAll(...) action for a particular function type F.
696 template <typename F>
697 class Impl : public ActionInterface<F> {
698 public:
shiqiane35fdd92008-12-10 05:08:54 +0000699 typedef typename Function<F>::Result Result;
700 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
701 typedef typename Function<F>::MakeResultVoid VoidResult;
702
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000703 Impl(const Action<VoidResult>& action1, const Action<F>& action2)
704 : action1_(action1), action2_(action2) {}
shiqiane35fdd92008-12-10 05:08:54 +0000705
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000706 virtual Result Perform(const ArgumentTuple& args) {
707 action1_.Perform(args);
708 return action2_.Perform(args);
709 }
shiqiane35fdd92008-12-10 05:08:54 +0000710
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000711 private:
712 const Action<VoidResult> action1_;
713 const Action<F> action2_;
714 };
715
shiqiane35fdd92008-12-10 05:08:54 +0000716 Action1 action1_;
717 Action2 action2_;
718};
719
shiqian326aa562009-01-09 21:43:57 +0000720// A macro from the ACTION* family (defined later in this file)
721// defines an action that can be used in a mock function. Typically,
722// these actions only care about a subset of the arguments of the mock
723// function. For example, if such an action only uses the second
724// argument, it can be used in any mock function that takes >= 2
725// arguments where the type of the second argument is compatible.
726//
727// Therefore, the action implementation must be prepared to take more
728// arguments than it needs. The ExcessiveArg type is used to
729// represent those excessive arguments. In order to keep the compiler
730// error messages tractable, we define it in the testing namespace
731// instead of testing::internal. However, this is an INTERNAL TYPE
732// and subject to change without notice, so a user MUST NOT USE THIS
733// TYPE DIRECTLY.
734struct ExcessiveArg {};
735
736// A helper class needed for implementing the ACTION* macros.
737template <typename Result, class Impl>
738class ActionHelper {
739 public:
740 static Result Perform(Impl* impl, const ::std::tr1::tuple<>& args) {
741 using ::std::tr1::get;
zhanyong.wan7f4c2c02009-02-19 22:38:27 +0000742 return impl->template gmock_PerformImpl<>(args, ExcessiveArg(),
shiqian326aa562009-01-09 21:43:57 +0000743 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
zhanyong.wan7f4c2c02009-02-19 22:38:27 +0000744 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
745 ExcessiveArg());
shiqian326aa562009-01-09 21:43:57 +0000746 }
747
748 template <typename A0>
749 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0>& args) {
750 using ::std::tr1::get;
zhanyong.wan7f4c2c02009-02-19 22:38:27 +0000751 return impl->template gmock_PerformImpl<A0>(args, get<0>(args),
shiqian326aa562009-01-09 21:43:57 +0000752 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
zhanyong.wan7f4c2c02009-02-19 22:38:27 +0000753 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
754 ExcessiveArg());
shiqian326aa562009-01-09 21:43:57 +0000755 }
756
757 template <typename A0, typename A1>
758 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1>& args) {
759 using ::std::tr1::get;
zhanyong.wan7f4c2c02009-02-19 22:38:27 +0000760 return impl->template gmock_PerformImpl<A0, A1>(args, get<0>(args),
761 get<1>(args), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
shiqian326aa562009-01-09 21:43:57 +0000762 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
zhanyong.wan7f4c2c02009-02-19 22:38:27 +0000763 ExcessiveArg());
shiqian326aa562009-01-09 21:43:57 +0000764 }
765
766 template <typename A0, typename A1, typename A2>
767 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2>& args) {
768 using ::std::tr1::get;
zhanyong.wan7f4c2c02009-02-19 22:38:27 +0000769 return impl->template gmock_PerformImpl<A0, A1, A2>(args, get<0>(args),
770 get<1>(args), get<2>(args), ExcessiveArg(), ExcessiveArg(),
771 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
772 ExcessiveArg());
shiqian326aa562009-01-09 21:43:57 +0000773 }
774
775 template <typename A0, typename A1, typename A2, typename A3>
776 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2,
777 A3>& args) {
778 using ::std::tr1::get;
zhanyong.wan7f4c2c02009-02-19 22:38:27 +0000779 return impl->template gmock_PerformImpl<A0, A1, A2, A3>(args, get<0>(args),
780 get<1>(args), get<2>(args), get<3>(args), ExcessiveArg(),
781 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
782 ExcessiveArg());
shiqian326aa562009-01-09 21:43:57 +0000783 }
784
785 template <typename A0, typename A1, typename A2, typename A3, typename A4>
786 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3,
787 A4>& args) {
788 using ::std::tr1::get;
zhanyong.wan7f4c2c02009-02-19 22:38:27 +0000789 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4>(args,
790 get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args),
791 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
792 ExcessiveArg());
shiqian326aa562009-01-09 21:43:57 +0000793 }
794
795 template <typename A0, typename A1, typename A2, typename A3, typename A4,
796 typename A5>
797 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4,
798 A5>& args) {
799 using ::std::tr1::get;
zhanyong.wan7f4c2c02009-02-19 22:38:27 +0000800 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5>(args,
801 get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args),
802 get<5>(args), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
803 ExcessiveArg());
shiqian326aa562009-01-09 21:43:57 +0000804 }
805
806 template <typename A0, typename A1, typename A2, typename A3, typename A4,
807 typename A5, typename A6>
808 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4,
809 A5, A6>& args) {
810 using ::std::tr1::get;
zhanyong.wan7f4c2c02009-02-19 22:38:27 +0000811 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6>(args,
812 get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args),
813 get<5>(args), get<6>(args), ExcessiveArg(), ExcessiveArg(),
814 ExcessiveArg());
shiqian326aa562009-01-09 21:43:57 +0000815 }
816
817 template <typename A0, typename A1, typename A2, typename A3, typename A4,
818 typename A5, typename A6, typename A7>
819 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4,
820 A5, A6, A7>& args) {
821 using ::std::tr1::get;
zhanyong.wan7f4c2c02009-02-19 22:38:27 +0000822 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6,
823 A7>(args, get<0>(args), get<1>(args), get<2>(args), get<3>(args),
824 get<4>(args), get<5>(args), get<6>(args), get<7>(args), ExcessiveArg(),
825 ExcessiveArg());
shiqian326aa562009-01-09 21:43:57 +0000826 }
827
828 template <typename A0, typename A1, typename A2, typename A3, typename A4,
829 typename A5, typename A6, typename A7, typename A8>
830 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4,
831 A5, A6, A7, A8>& args) {
832 using ::std::tr1::get;
zhanyong.wan7f4c2c02009-02-19 22:38:27 +0000833 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6, A7,
834 A8>(args, get<0>(args), get<1>(args), get<2>(args), get<3>(args),
835 get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args),
836 ExcessiveArg());
shiqian326aa562009-01-09 21:43:57 +0000837 }
838
839 template <typename A0, typename A1, typename A2, typename A3, typename A4,
840 typename A5, typename A6, typename A7, typename A8, typename A9>
841 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4,
842 A5, A6, A7, A8, A9>& args) {
843 using ::std::tr1::get;
zhanyong.wan7f4c2c02009-02-19 22:38:27 +0000844 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6, A7, A8,
845 A9>(args, get<0>(args), get<1>(args), get<2>(args), get<3>(args),
846 get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args),
847 get<9>(args));
shiqian326aa562009-01-09 21:43:57 +0000848 }
849};
850
shiqiane35fdd92008-12-10 05:08:54 +0000851} // namespace internal
852
853// Various overloads for Invoke().
854
855// Creates an action that invokes 'function_impl' with the mock
856// function's arguments.
857template <typename FunctionImpl>
858PolymorphicAction<internal::InvokeAction<FunctionImpl> > Invoke(
859 FunctionImpl function_impl) {
860 return MakePolymorphicAction(
861 internal::InvokeAction<FunctionImpl>(function_impl));
862}
863
864// Creates an action that invokes the given method on the given object
865// with the mock function's arguments.
866template <class Class, typename MethodPtr>
867PolymorphicAction<internal::InvokeMethodAction<Class, MethodPtr> > Invoke(
868 Class* obj_ptr, MethodPtr method_ptr) {
869 return MakePolymorphicAction(
870 internal::InvokeMethodAction<Class, MethodPtr>(obj_ptr, method_ptr));
871}
872
873// Creates a reference wrapper for the given L-value. If necessary,
874// you can explicitly specify the type of the reference. For example,
875// suppose 'derived' is an object of type Derived, ByRef(derived)
876// would wrap a Derived&. If you want to wrap a const Base& instead,
877// where Base is a base class of Derived, just write:
878//
879// ByRef<const Base>(derived)
880template <typename T>
881inline internal::ReferenceWrapper<T> ByRef(T& l_value) { // NOLINT
882 return internal::ReferenceWrapper<T>(l_value);
883}
884
shiqiane35fdd92008-12-10 05:08:54 +0000885// WithoutArgs(inner_action) can be used in a mock function with a
886// non-empty argument list to perform inner_action, which takes no
887// argument. In other words, it adapts an action accepting no
888// argument to one that accepts (and ignores) arguments.
889template <typename InnerAction>
890inline internal::WithArgsAction<InnerAction>
891WithoutArgs(const InnerAction& action) {
892 return internal::WithArgsAction<InnerAction>(action);
893}
894
895// WithArg<k>(an_action) creates an action that passes the k-th
896// (0-based) argument of the mock function to an_action and performs
897// it. It adapts an action accepting one argument to one that accepts
898// multiple arguments. For convenience, we also provide
899// WithArgs<k>(an_action) (defined below) as a synonym.
900template <int k, typename InnerAction>
901inline internal::WithArgsAction<InnerAction, k>
902WithArg(const InnerAction& action) {
903 return internal::WithArgsAction<InnerAction, k>(action);
904}
905
906// WithArgs<N1, N2, ..., Nk>(an_action) creates an action that passes
907// the selected arguments of the mock function to an_action and
908// performs it. It serves as an adaptor between actions with
909// different argument lists. C++ doesn't support default arguments for
910// function templates, so we have to overload it.
911template <int k1, typename InnerAction>
912inline internal::WithArgsAction<InnerAction, k1>
913WithArgs(const InnerAction& action) {
914 return internal::WithArgsAction<InnerAction, k1>(action);
915}
916
917template <int k1, int k2, typename InnerAction>
918inline internal::WithArgsAction<InnerAction, k1, k2>
919WithArgs(const InnerAction& action) {
920 return internal::WithArgsAction<InnerAction, k1, k2>(action);
921}
922
923template <int k1, int k2, int k3, typename InnerAction>
924inline internal::WithArgsAction<InnerAction, k1, k2, k3>
925WithArgs(const InnerAction& action) {
926 return internal::WithArgsAction<InnerAction, k1, k2, k3>(action);
927}
928
929template <int k1, int k2, int k3, int k4, typename InnerAction>
930inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4>
931WithArgs(const InnerAction& action) {
932 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4>(action);
933}
934
935template <int k1, int k2, int k3, int k4, int k5, typename InnerAction>
936inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5>
937WithArgs(const InnerAction& action) {
938 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5>(action);
939}
940
941template <int k1, int k2, int k3, int k4, int k5, int k6, typename InnerAction>
942inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6>
943WithArgs(const InnerAction& action) {
944 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6>(action);
945}
946
947template <int k1, int k2, int k3, int k4, int k5, int k6, int k7,
948 typename InnerAction>
949inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7>
950WithArgs(const InnerAction& action) {
951 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6,
952 k7>(action);
953}
954
955template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
956 typename InnerAction>
957inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8>
958WithArgs(const InnerAction& action) {
959 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7,
960 k8>(action);
961}
962
963template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
964 int k9, typename InnerAction>
965inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8, k9>
966WithArgs(const InnerAction& action) {
967 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8,
968 k9>(action);
969}
970
971template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
972 int k9, int k10, typename InnerAction>
973inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8,
974 k9, k10>
975WithArgs(const InnerAction& action) {
976 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8,
977 k9, k10>(action);
978}
979
980// Creates an action that does actions a1, a2, ..., sequentially in
981// each invocation.
982template <typename Action1, typename Action2>
983inline internal::DoBothAction<Action1, Action2>
984DoAll(Action1 a1, Action2 a2) {
985 return internal::DoBothAction<Action1, Action2>(a1, a2);
986}
987
988template <typename Action1, typename Action2, typename Action3>
989inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
990 Action3> >
991DoAll(Action1 a1, Action2 a2, Action3 a3) {
992 return DoAll(a1, DoAll(a2, a3));
993}
994
995template <typename Action1, typename Action2, typename Action3,
996 typename Action4>
997inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
998 internal::DoBothAction<Action3, Action4> > >
999DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4) {
1000 return DoAll(a1, DoAll(a2, a3, a4));
1001}
1002
1003template <typename Action1, typename Action2, typename Action3,
1004 typename Action4, typename Action5>
1005inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
1006 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
1007 Action5> > > >
1008DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5) {
1009 return DoAll(a1, DoAll(a2, a3, a4, a5));
1010}
1011
1012template <typename Action1, typename Action2, typename Action3,
1013 typename Action4, typename Action5, typename Action6>
1014inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
1015 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
1016 internal::DoBothAction<Action5, Action6> > > > >
1017DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6) {
1018 return DoAll(a1, DoAll(a2, a3, a4, a5, a6));
1019}
1020
1021template <typename Action1, typename Action2, typename Action3,
1022 typename Action4, typename Action5, typename Action6, typename Action7>
1023inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
1024 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
1025 internal::DoBothAction<Action5, internal::DoBothAction<Action6,
1026 Action7> > > > > >
1027DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
1028 Action7 a7) {
1029 return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7));
1030}
1031
1032template <typename Action1, typename Action2, typename Action3,
1033 typename Action4, typename Action5, typename Action6, typename Action7,
1034 typename Action8>
1035inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
1036 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
1037 internal::DoBothAction<Action5, internal::DoBothAction<Action6,
1038 internal::DoBothAction<Action7, Action8> > > > > > >
1039DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
1040 Action7 a7, Action8 a8) {
1041 return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8));
1042}
1043
1044template <typename Action1, typename Action2, typename Action3,
1045 typename Action4, typename Action5, typename Action6, typename Action7,
1046 typename Action8, typename Action9>
1047inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
1048 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
1049 internal::DoBothAction<Action5, internal::DoBothAction<Action6,
1050 internal::DoBothAction<Action7, internal::DoBothAction<Action8,
1051 Action9> > > > > > > >
1052DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
1053 Action7 a7, Action8 a8, Action9 a9) {
1054 return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8, a9));
1055}
1056
1057template <typename Action1, typename Action2, typename Action3,
1058 typename Action4, typename Action5, typename Action6, typename Action7,
1059 typename Action8, typename Action9, typename Action10>
1060inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
1061 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
1062 internal::DoBothAction<Action5, internal::DoBothAction<Action6,
1063 internal::DoBothAction<Action7, internal::DoBothAction<Action8,
1064 internal::DoBothAction<Action9, Action10> > > > > > > > >
1065DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
1066 Action7 a7, Action8 a8, Action9 a9, Action10 a10) {
1067 return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8, a9, a10));
1068}
1069
1070} // namespace testing
1071
shiqian326aa562009-01-09 21:43:57 +00001072// The ACTION* family of macros can be used in a namespace scope to
1073// define custom actions easily. The syntax:
1074//
1075// ACTION(name) { statements; }
1076//
1077// will define an action with the given name that executes the
1078// statements. The value returned by the statements will be used as
1079// the return value of the action. Inside the statements, you can
1080// refer to the K-th (0-based) argument of the mock function by
1081// 'argK', and refer to its type by 'argK_type'. For example:
1082//
1083// ACTION(IncrementArg1) {
1084// arg1_type temp = arg1;
1085// return ++(*temp);
1086// }
1087//
1088// allows you to write
1089//
1090// ...WillOnce(IncrementArg1());
1091//
1092// You can also refer to the entire argument tuple and its type by
1093// 'args' and 'args_type', and refer to the mock function type and its
1094// return type by 'function_type' and 'return_type'.
1095//
1096// Note that you don't need to specify the types of the mock function
1097// arguments. However rest assured that your code is still type-safe:
1098// you'll get a compiler error if *arg1 doesn't support the ++
1099// operator, or if the type of ++(*arg1) isn't compatible with the
1100// mock function's return type, for example.
1101//
1102// Sometimes you'll want to parameterize the action. For that you can use
1103// another macro:
1104//
1105// ACTION_P(name, param_name) { statements; }
1106//
1107// For example:
1108//
1109// ACTION_P(Add, n) { return arg0 + n; }
1110//
1111// will allow you to write:
1112//
1113// ...WillOnce(Add(5));
1114//
1115// Note that you don't need to provide the type of the parameter
1116// either. If you need to reference the type of a parameter named
1117// 'foo', you can write 'foo_type'. For example, in the body of
1118// ACTION_P(Add, n) above, you can write 'n_type' to refer to the type
1119// of 'n'.
1120//
1121// We also provide ACTION_P2, ACTION_P3, ..., up to ACTION_P10 to support
1122// multi-parameter actions.
1123//
1124// For the purpose of typing, you can view
1125//
1126// ACTION_Pk(Foo, p1, ..., pk) { ... }
1127//
1128// as shorthand for
1129//
1130// template <typename p1_type, ..., typename pk_type>
1131// FooActionPk<p1_type, ..., pk_type> Foo(p1_type p1, ..., pk_type pk) { ... }
1132//
1133// In particular, you can provide the template type arguments
1134// explicitly when invoking Foo(), as in Foo<long, bool>(5, false);
1135// although usually you can rely on the compiler to infer the types
1136// for you automatically. You can assign the result of expression
1137// Foo(p1, ..., pk) to a variable of type FooActionPk<p1_type, ...,
1138// pk_type>. This can be useful when composing actions.
1139//
1140// You can also overload actions with different numbers of parameters:
1141//
1142// ACTION_P(Plus, a) { ... }
1143// ACTION_P2(Plus, a, b) { ... }
1144//
1145// While it's tempting to always use the ACTION* macros when defining
1146// a new action, you should also consider implementing ActionInterface
1147// or using MakePolymorphicAction() instead, especially if you need to
1148// use the action a lot. While these approaches require more work,
1149// they give you more control on the types of the mock function
1150// arguments and the action parameters, which in general leads to
1151// better compiler error messages that pay off in the long run. They
1152// also allow overloading actions based on parameter types (as opposed
1153// to just based on the number of parameters).
1154//
1155// CAVEAT:
1156//
1157// ACTION*() can only be used in a namespace scope. The reason is
1158// that C++ doesn't yet allow function-local types to be used to
1159// instantiate templates. The up-coming C++0x standard will fix this.
1160// Once that's done, we'll consider supporting using ACTION*() inside
1161// a function.
1162//
1163// MORE INFORMATION:
1164//
1165// To learn more about using these macros, please search for 'ACTION'
1166// on http://code.google.com/p/googlemock/wiki/CookBook.
1167
zhanyong.wan33c0af02009-04-03 00:10:12 +00001168// An internal macro needed for implementing ACTION*().
1169#define GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_\
1170 const args_type& args GTEST_ATTRIBUTE_UNUSED_,\
1171 arg0_type arg0 GTEST_ATTRIBUTE_UNUSED_,\
1172 arg1_type arg1 GTEST_ATTRIBUTE_UNUSED_,\
1173 arg2_type arg2 GTEST_ATTRIBUTE_UNUSED_,\
1174 arg3_type arg3 GTEST_ATTRIBUTE_UNUSED_,\
1175 arg4_type arg4 GTEST_ATTRIBUTE_UNUSED_,\
1176 arg5_type arg5 GTEST_ATTRIBUTE_UNUSED_,\
1177 arg6_type arg6 GTEST_ATTRIBUTE_UNUSED_,\
1178 arg7_type arg7 GTEST_ATTRIBUTE_UNUSED_,\
1179 arg8_type arg8 GTEST_ATTRIBUTE_UNUSED_,\
1180 arg9_type arg9 GTEST_ATTRIBUTE_UNUSED_
1181
zhanyong.wan18490652009-05-11 18:54:08 +00001182// Sometimes you want to give an action explicit template parameters
1183// that cannot be inferred from its value parameters. ACTION() and
1184// ACTION_P*() don't support that. ACTION_TEMPLATE() remedies that
1185// and can be viewed as an extension to ACTION() and ACTION_P*().
1186//
1187// The syntax:
1188//
1189// ACTION_TEMPLATE(ActionName,
1190// HAS_m_TEMPLATE_PARAMS(kind1, name1, ..., kind_m, name_m),
1191// AND_n_VALUE_PARAMS(p1, ..., p_n)) { statements; }
1192//
1193// defines an action template that takes m explicit template
1194// parameters and n value parameters. name_i is the name of the i-th
1195// template parameter, and kind_i specifies whether it's a typename,
1196// an integral constant, or a template. p_i is the name of the i-th
1197// value parameter.
1198//
1199// Example:
1200//
1201// // DuplicateArg<k, T>(output) converts the k-th argument of the mock
1202// // function to type T and copies it to *output.
1203// ACTION_TEMPLATE(DuplicateArg,
1204// HAS_2_TEMPLATE_PARAMS(int, k, typename, T),
1205// AND_1_VALUE_PARAMS(output)) {
1206// *output = T(std::tr1::get<k>(args));
1207// }
1208// ...
1209// int n;
1210// EXPECT_CALL(mock, Foo(_, _))
1211// .WillOnce(DuplicateArg<1, unsigned char>(&n));
1212//
1213// To create an instance of an action template, write:
1214//
1215// ActionName<t1, ..., t_m>(v1, ..., v_n)
1216//
1217// where the ts are the template arguments and the vs are the value
1218// arguments. The value argument types are inferred by the compiler.
1219// If you want to explicitly specify the value argument types, you can
1220// provide additional template arguments:
1221//
1222// ActionName<t1, ..., t_m, u1, ..., u_k>(v1, ..., v_n)
1223//
1224// where u_i is the desired type of v_i.
1225//
1226// ACTION_TEMPLATE and ACTION/ACTION_P* can be overloaded on the
1227// number of value parameters, but not on the number of template
1228// parameters. Without the restriction, the meaning of the following
1229// is unclear:
1230//
1231// OverloadedAction<int, bool>(x);
1232//
1233// Are we using a single-template-parameter action where 'bool' refers
1234// to the type of x, or are we using a two-template-parameter action
1235// where the compiler is asked to infer the type of x?
1236//
1237// Implementation notes:
1238//
1239// GMOCK_INTERNAL_*_HAS_m_TEMPLATE_PARAMS and
1240// GMOCK_INTERNAL_*_AND_n_VALUE_PARAMS are internal macros for
1241// implementing ACTION_TEMPLATE. The main trick we use is to create
1242// new macro invocations when expanding a macro. For example, we have
1243//
1244// #define ACTION_TEMPLATE(name, template_params, value_params)
1245// ... GMOCK_INTERNAL_DECL_##template_params ...
1246//
1247// which causes ACTION_TEMPLATE(..., HAS_1_TEMPLATE_PARAMS(typename, T), ...)
1248// to expand to
1249//
1250// ... GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(typename, T) ...
1251//
1252// Since GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS is a macro, the
1253// preprocessor will continue to expand it to
1254//
1255// ... typename T ...
1256//
1257// This technique conforms to the C++ standard and is portable. It
1258// allows us to implement action templates using O(N) code, where N is
1259// the maximum number of template/value parameters supported. Without
1260// using it, we'd have to devote O(N^2) amount of code to implement all
1261// combinations of m and n.
1262
1263// Declares the template parameters.
1264#define GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(kind0, name0) kind0 name0
1265#define GMOCK_INTERNAL_DECL_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, \
1266 name1) kind0 name0, kind1 name1
1267#define GMOCK_INTERNAL_DECL_HAS_3_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
1268 kind2, name2) kind0 name0, kind1 name1, kind2 name2
1269#define GMOCK_INTERNAL_DECL_HAS_4_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
1270 kind2, name2, kind3, name3) kind0 name0, kind1 name1, kind2 name2, \
1271 kind3 name3
1272#define GMOCK_INTERNAL_DECL_HAS_5_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
1273 kind2, name2, kind3, name3, kind4, name4) kind0 name0, kind1 name1, \
1274 kind2 name2, kind3 name3, kind4 name4
1275#define GMOCK_INTERNAL_DECL_HAS_6_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
1276 kind2, name2, kind3, name3, kind4, name4, kind5, name5) kind0 name0, \
1277 kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5
1278#define GMOCK_INTERNAL_DECL_HAS_7_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
1279 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
1280 name6) kind0 name0, kind1 name1, kind2 name2, kind3 name3, kind4 name4, \
1281 kind5 name5, kind6 name6
1282#define GMOCK_INTERNAL_DECL_HAS_8_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
1283 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
1284 kind7, name7) kind0 name0, kind1 name1, kind2 name2, kind3 name3, \
1285 kind4 name4, kind5 name5, kind6 name6, kind7 name7
1286#define GMOCK_INTERNAL_DECL_HAS_9_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
1287 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
1288 kind7, name7, kind8, name8) kind0 name0, kind1 name1, kind2 name2, \
1289 kind3 name3, kind4 name4, kind5 name5, kind6 name6, kind7 name7, \
1290 kind8 name8
1291#define GMOCK_INTERNAL_DECL_HAS_10_TEMPLATE_PARAMS(kind0, name0, kind1, \
1292 name1, kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
1293 name6, kind7, name7, kind8, name8, kind9, name9) kind0 name0, \
1294 kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5, \
1295 kind6 name6, kind7 name7, kind8 name8, kind9 name9
1296
1297// Lists the template parameters.
1298#define GMOCK_INTERNAL_LIST_HAS_1_TEMPLATE_PARAMS(kind0, name0) name0
1299#define GMOCK_INTERNAL_LIST_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, \
1300 name1) name0, name1
1301#define GMOCK_INTERNAL_LIST_HAS_3_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
1302 kind2, name2) name0, name1, name2
1303#define GMOCK_INTERNAL_LIST_HAS_4_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
1304 kind2, name2, kind3, name3) name0, name1, name2, name3
1305#define GMOCK_INTERNAL_LIST_HAS_5_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
1306 kind2, name2, kind3, name3, kind4, name4) name0, name1, name2, name3, \
1307 name4
1308#define GMOCK_INTERNAL_LIST_HAS_6_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
1309 kind2, name2, kind3, name3, kind4, name4, kind5, name5) name0, name1, \
1310 name2, name3, name4, name5
1311#define GMOCK_INTERNAL_LIST_HAS_7_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
1312 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
1313 name6) name0, name1, name2, name3, name4, name5, name6
1314#define GMOCK_INTERNAL_LIST_HAS_8_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
1315 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
1316 kind7, name7) name0, name1, name2, name3, name4, name5, name6, name7
1317#define GMOCK_INTERNAL_LIST_HAS_9_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
1318 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
1319 kind7, name7, kind8, name8) name0, name1, name2, name3, name4, name5, \
1320 name6, name7, name8
1321#define GMOCK_INTERNAL_LIST_HAS_10_TEMPLATE_PARAMS(kind0, name0, kind1, \
1322 name1, kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
1323 name6, kind7, name7, kind8, name8, kind9, name9) name0, name1, name2, \
1324 name3, name4, name5, name6, name7, name8, name9
1325
1326// Declares the types of value parameters.
1327#define GMOCK_INTERNAL_DECL_TYPE_AND_0_VALUE_PARAMS()
1328#define GMOCK_INTERNAL_DECL_TYPE_AND_1_VALUE_PARAMS(p0) , typename p0##_type
1329#define GMOCK_INTERNAL_DECL_TYPE_AND_2_VALUE_PARAMS(p0, p1) , \
1330 typename p0##_type, typename p1##_type
1331#define GMOCK_INTERNAL_DECL_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) , \
1332 typename p0##_type, typename p1##_type, typename p2##_type
1333#define GMOCK_INTERNAL_DECL_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) , \
1334 typename p0##_type, typename p1##_type, typename p2##_type, \
1335 typename p3##_type
1336#define GMOCK_INTERNAL_DECL_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) , \
1337 typename p0##_type, typename p1##_type, typename p2##_type, \
1338 typename p3##_type, typename p4##_type
1339#define GMOCK_INTERNAL_DECL_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) , \
1340 typename p0##_type, typename p1##_type, typename p2##_type, \
1341 typename p3##_type, typename p4##_type, typename p5##_type
1342#define GMOCK_INTERNAL_DECL_TYPE_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
1343 p6) , typename p0##_type, typename p1##_type, typename p2##_type, \
1344 typename p3##_type, typename p4##_type, typename p5##_type, \
1345 typename p6##_type
1346#define GMOCK_INTERNAL_DECL_TYPE_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
1347 p6, p7) , typename p0##_type, typename p1##_type, typename p2##_type, \
1348 typename p3##_type, typename p4##_type, typename p5##_type, \
1349 typename p6##_type, typename p7##_type
1350#define GMOCK_INTERNAL_DECL_TYPE_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
1351 p6, p7, p8) , typename p0##_type, typename p1##_type, typename p2##_type, \
1352 typename p3##_type, typename p4##_type, typename p5##_type, \
1353 typename p6##_type, typename p7##_type, typename p8##_type
1354#define GMOCK_INTERNAL_DECL_TYPE_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
1355 p6, p7, p8, p9) , typename p0##_type, typename p1##_type, \
1356 typename p2##_type, typename p3##_type, typename p4##_type, \
1357 typename p5##_type, typename p6##_type, typename p7##_type, \
1358 typename p8##_type, typename p9##_type
1359
1360// Initializes the value parameters.
1361#define GMOCK_INTERNAL_INIT_AND_0_VALUE_PARAMS()\
1362 ()
1363#define GMOCK_INTERNAL_INIT_AND_1_VALUE_PARAMS(p0)\
1364 (p0##_type gmock_p0) : p0(gmock_p0)
1365#define GMOCK_INTERNAL_INIT_AND_2_VALUE_PARAMS(p0, p1)\
1366 (p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), p1(gmock_p1)
1367#define GMOCK_INTERNAL_INIT_AND_3_VALUE_PARAMS(p0, p1, p2)\
1368 (p0##_type gmock_p0, p1##_type gmock_p1, \
1369 p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2)
1370#define GMOCK_INTERNAL_INIT_AND_4_VALUE_PARAMS(p0, p1, p2, p3)\
1371 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
1372 p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
1373 p3(gmock_p3)
1374#define GMOCK_INTERNAL_INIT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)\
1375 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
1376 p3##_type gmock_p3, p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), \
1377 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4)
1378#define GMOCK_INTERNAL_INIT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)\
1379 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
1380 p3##_type gmock_p3, p4##_type gmock_p4, \
1381 p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
1382 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5)
1383#define GMOCK_INTERNAL_INIT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)\
1384 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
1385 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
1386 p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
1387 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6)
1388#define GMOCK_INTERNAL_INIT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)\
1389 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
1390 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
1391 p6##_type gmock_p6, p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), \
1392 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
1393 p7(gmock_p7)
1394#define GMOCK_INTERNAL_INIT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
1395 p7, p8)\
1396 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
1397 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
1398 p6##_type gmock_p6, p7##_type gmock_p7, \
1399 p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
1400 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
1401 p8(gmock_p8)
1402#define GMOCK_INTERNAL_INIT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
1403 p7, p8, p9)\
1404 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
1405 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
1406 p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
1407 p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
1408 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
1409 p8(gmock_p8), p9(gmock_p9)
1410
1411// Declares the fields for storing the value parameters.
1412#define GMOCK_INTERNAL_DEFN_AND_0_VALUE_PARAMS()
1413#define GMOCK_INTERNAL_DEFN_AND_1_VALUE_PARAMS(p0) p0##_type p0;
1414#define GMOCK_INTERNAL_DEFN_AND_2_VALUE_PARAMS(p0, p1) p0##_type p0; \
1415 p1##_type p1;
1416#define GMOCK_INTERNAL_DEFN_AND_3_VALUE_PARAMS(p0, p1, p2) p0##_type p0; \
1417 p1##_type p1; p2##_type p2;
1418#define GMOCK_INTERNAL_DEFN_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0##_type p0; \
1419 p1##_type p1; p2##_type p2; p3##_type p3;
1420#define GMOCK_INTERNAL_DEFN_AND_5_VALUE_PARAMS(p0, p1, p2, p3, \
1421 p4) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4;
1422#define GMOCK_INTERNAL_DEFN_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, \
1423 p5) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \
1424 p5##_type p5;
1425#define GMOCK_INTERNAL_DEFN_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
1426 p6) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \
1427 p5##_type p5; p6##_type p6;
1428#define GMOCK_INTERNAL_DEFN_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
1429 p7) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \
1430 p5##_type p5; p6##_type p6; p7##_type p7;
1431#define GMOCK_INTERNAL_DEFN_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
1432 p7, p8) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; \
1433 p4##_type p4; p5##_type p5; p6##_type p6; p7##_type p7; p8##_type p8;
1434#define GMOCK_INTERNAL_DEFN_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
1435 p7, p8, p9) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; \
1436 p4##_type p4; p5##_type p5; p6##_type p6; p7##_type p7; p8##_type p8; \
1437 p9##_type p9;
1438
1439// Lists the value parameters.
1440#define GMOCK_INTERNAL_LIST_AND_0_VALUE_PARAMS()
1441#define GMOCK_INTERNAL_LIST_AND_1_VALUE_PARAMS(p0) p0
1442#define GMOCK_INTERNAL_LIST_AND_2_VALUE_PARAMS(p0, p1) p0, p1
1443#define GMOCK_INTERNAL_LIST_AND_3_VALUE_PARAMS(p0, p1, p2) p0, p1, p2
1444#define GMOCK_INTERNAL_LIST_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0, p1, p2, p3
1445#define GMOCK_INTERNAL_LIST_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) p0, p1, \
1446 p2, p3, p4
1447#define GMOCK_INTERNAL_LIST_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) p0, \
1448 p1, p2, p3, p4, p5
1449#define GMOCK_INTERNAL_LIST_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
1450 p6) p0, p1, p2, p3, p4, p5, p6
1451#define GMOCK_INTERNAL_LIST_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
1452 p7) p0, p1, p2, p3, p4, p5, p6, p7
1453#define GMOCK_INTERNAL_LIST_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
1454 p7, p8) p0, p1, p2, p3, p4, p5, p6, p7, p8
1455#define GMOCK_INTERNAL_LIST_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
1456 p7, p8, p9) p0, p1, p2, p3, p4, p5, p6, p7, p8, p9
1457
1458// Lists the value parameter types.
1459#define GMOCK_INTERNAL_LIST_TYPE_AND_0_VALUE_PARAMS()
1460#define GMOCK_INTERNAL_LIST_TYPE_AND_1_VALUE_PARAMS(p0) , p0##_type
1461#define GMOCK_INTERNAL_LIST_TYPE_AND_2_VALUE_PARAMS(p0, p1) , p0##_type, \
1462 p1##_type
1463#define GMOCK_INTERNAL_LIST_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) , p0##_type, \
1464 p1##_type, p2##_type
1465#define GMOCK_INTERNAL_LIST_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) , \
1466 p0##_type, p1##_type, p2##_type, p3##_type
1467#define GMOCK_INTERNAL_LIST_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) , \
1468 p0##_type, p1##_type, p2##_type, p3##_type, p4##_type
1469#define GMOCK_INTERNAL_LIST_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) , \
1470 p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type
1471#define GMOCK_INTERNAL_LIST_TYPE_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
1472 p6) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type, \
1473 p6##_type
1474#define GMOCK_INTERNAL_LIST_TYPE_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
1475 p6, p7) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
1476 p5##_type, p6##_type, p7##_type
1477#define GMOCK_INTERNAL_LIST_TYPE_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
1478 p6, p7, p8) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
1479 p5##_type, p6##_type, p7##_type, p8##_type
1480#define GMOCK_INTERNAL_LIST_TYPE_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
1481 p6, p7, p8, p9) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
1482 p5##_type, p6##_type, p7##_type, p8##_type, p9##_type
1483
1484// Declares the value parameters.
1485#define GMOCK_INTERNAL_DECL_AND_0_VALUE_PARAMS()
1486#define GMOCK_INTERNAL_DECL_AND_1_VALUE_PARAMS(p0) p0##_type p0
1487#define GMOCK_INTERNAL_DECL_AND_2_VALUE_PARAMS(p0, p1) p0##_type p0, \
1488 p1##_type p1
1489#define GMOCK_INTERNAL_DECL_AND_3_VALUE_PARAMS(p0, p1, p2) p0##_type p0, \
1490 p1##_type p1, p2##_type p2
1491#define GMOCK_INTERNAL_DECL_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0##_type p0, \
1492 p1##_type p1, p2##_type p2, p3##_type p3
1493#define GMOCK_INTERNAL_DECL_AND_5_VALUE_PARAMS(p0, p1, p2, p3, \
1494 p4) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4
1495#define GMOCK_INTERNAL_DECL_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, \
1496 p5) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \
1497 p5##_type p5
1498#define GMOCK_INTERNAL_DECL_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
1499 p6) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \
1500 p5##_type p5, p6##_type p6
1501#define GMOCK_INTERNAL_DECL_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
1502 p7) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \
1503 p5##_type p5, p6##_type p6, p7##_type p7
1504#define GMOCK_INTERNAL_DECL_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
1505 p7, p8) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
1506 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8
1507#define GMOCK_INTERNAL_DECL_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
1508 p7, p8, p9) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
1509 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \
1510 p9##_type p9
1511
1512// The suffix of the class template implementing the action template.
1513#define GMOCK_INTERNAL_COUNT_AND_0_VALUE_PARAMS()
1514#define GMOCK_INTERNAL_COUNT_AND_1_VALUE_PARAMS(p0) P
1515#define GMOCK_INTERNAL_COUNT_AND_2_VALUE_PARAMS(p0, p1) P2
1516#define GMOCK_INTERNAL_COUNT_AND_3_VALUE_PARAMS(p0, p1, p2) P3
1517#define GMOCK_INTERNAL_COUNT_AND_4_VALUE_PARAMS(p0, p1, p2, p3) P4
1518#define GMOCK_INTERNAL_COUNT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) P5
1519#define GMOCK_INTERNAL_COUNT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) P6
1520#define GMOCK_INTERNAL_COUNT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6) P7
1521#define GMOCK_INTERNAL_COUNT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
1522 p7) P8
1523#define GMOCK_INTERNAL_COUNT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
1524 p7, p8) P9
1525#define GMOCK_INTERNAL_COUNT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
1526 p7, p8, p9) P10
1527
1528// The name of the class template implementing the action template.
1529#define GMOCK_ACTION_CLASS_(name, value_params)\
1530 GMOCK_CONCAT_TOKEN_(name##Action, GMOCK_INTERNAL_COUNT_##value_params)
1531
1532#define ACTION_TEMPLATE(name, template_params, value_params)\
1533 template <GMOCK_INTERNAL_DECL_##template_params\
1534 GMOCK_INTERNAL_DECL_TYPE_##value_params>\
1535 class GMOCK_ACTION_CLASS_(name, value_params) {\
1536 public:\
1537 GMOCK_ACTION_CLASS_(name, value_params)\
1538 GMOCK_INTERNAL_INIT_##value_params {}\
1539 template <typename F>\
1540 class gmock_Impl : public ::testing::ActionInterface<F> {\
1541 public:\
1542 typedef F function_type;\
1543 typedef typename ::testing::internal::Function<F>::Result return_type;\
1544 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
1545 args_type;\
1546 explicit gmock_Impl GMOCK_INTERNAL_INIT_##value_params {}\
1547 virtual return_type Perform(const args_type& args) {\
1548 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
1549 Perform(this, args);\
1550 }\
1551 template <typename arg0_type, typename arg1_type, typename arg2_type, \
1552 typename arg3_type, typename arg4_type, typename arg5_type, \
1553 typename arg6_type, typename arg7_type, typename arg8_type, \
1554 typename arg9_type>\
1555 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
1556 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
1557 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
1558 arg9_type arg9) const;\
1559 GMOCK_INTERNAL_DEFN_##value_params\
1560 };\
1561 template <typename F> operator ::testing::Action<F>() const {\
1562 return ::testing::Action<F>(\
1563 new gmock_Impl<F>(GMOCK_INTERNAL_LIST_##value_params));\
1564 }\
1565 GMOCK_INTERNAL_DEFN_##value_params\
1566 };\
1567 template <GMOCK_INTERNAL_DECL_##template_params\
1568 GMOCK_INTERNAL_DECL_TYPE_##value_params>\
1569 inline GMOCK_ACTION_CLASS_(name, value_params)<\
1570 GMOCK_INTERNAL_LIST_##template_params\
1571 GMOCK_INTERNAL_LIST_TYPE_##value_params> name(\
1572 GMOCK_INTERNAL_DECL_##value_params) {\
1573 return GMOCK_ACTION_CLASS_(name, value_params)<\
1574 GMOCK_INTERNAL_LIST_##template_params\
1575 GMOCK_INTERNAL_LIST_TYPE_##value_params>(\
1576 GMOCK_INTERNAL_LIST_##value_params);\
1577 }\
1578 template <GMOCK_INTERNAL_DECL_##template_params\
1579 GMOCK_INTERNAL_DECL_TYPE_##value_params>\
1580 template <typename F>\
1581 template <typename arg0_type, typename arg1_type, typename arg2_type,\
1582 typename arg3_type, typename arg4_type, typename arg5_type,\
1583 typename arg6_type, typename arg7_type, typename arg8_type,\
1584 typename arg9_type>\
1585 typename ::testing::internal::Function<F>::Result\
1586 GMOCK_ACTION_CLASS_(name, value_params)<\
1587 GMOCK_INTERNAL_LIST_##template_params\
1588 GMOCK_INTERNAL_LIST_TYPE_##value_params>::gmock_Impl<F>::\
1589 gmock_PerformImpl(\
1590 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
1591
shiqian326aa562009-01-09 21:43:57 +00001592#define ACTION(name)\
1593 class name##Action {\
1594 public:\
1595 name##Action() {}\
1596 template <typename F>\
1597 class gmock_Impl : public ::testing::ActionInterface<F> {\
1598 public:\
1599 typedef F function_type;\
1600 typedef typename ::testing::internal::Function<F>::Result return_type;\
1601 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
1602 args_type;\
1603 gmock_Impl() {}\
1604 virtual return_type Perform(const args_type& args) {\
1605 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
1606 Perform(this, args);\
1607 }\
1608 template <typename arg0_type, typename arg1_type, typename arg2_type, \
1609 typename arg3_type, typename arg4_type, typename arg5_type, \
1610 typename arg6_type, typename arg7_type, typename arg8_type, \
1611 typename arg9_type>\
1612 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
1613 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
1614 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
1615 arg9_type arg9) const;\
1616 };\
1617 template <typename F> operator ::testing::Action<F>() const {\
1618 return ::testing::Action<F>(new gmock_Impl<F>());\
1619 }\
1620 };\
1621 inline name##Action name() {\
1622 return name##Action();\
1623 }\
1624 template <typename F>\
1625 template <typename arg0_type, typename arg1_type, typename arg2_type, \
1626 typename arg3_type, typename arg4_type, typename arg5_type, \
1627 typename arg6_type, typename arg7_type, typename arg8_type, \
1628 typename arg9_type>\
1629 typename ::testing::internal::Function<F>::Result\
zhanyong.wan33c0af02009-04-03 00:10:12 +00001630 name##Action::gmock_Impl<F>::gmock_PerformImpl(\
1631 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
shiqian326aa562009-01-09 21:43:57 +00001632
1633#define ACTION_P(name, p0)\
1634 template <typename p0##_type>\
1635 class name##ActionP {\
1636 public:\
1637 name##ActionP(p0##_type gmock_p0) : p0(gmock_p0) {}\
1638 template <typename F>\
1639 class gmock_Impl : public ::testing::ActionInterface<F> {\
1640 public:\
1641 typedef F function_type;\
1642 typedef typename ::testing::internal::Function<F>::Result return_type;\
1643 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
1644 args_type;\
1645 explicit gmock_Impl(p0##_type gmock_p0) : p0(gmock_p0) {}\
1646 virtual return_type Perform(const args_type& args) {\
1647 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
1648 Perform(this, args);\
1649 }\
1650 template <typename arg0_type, typename arg1_type, typename arg2_type, \
1651 typename arg3_type, typename arg4_type, typename arg5_type, \
1652 typename arg6_type, typename arg7_type, typename arg8_type, \
1653 typename arg9_type>\
1654 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
1655 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
1656 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
1657 arg9_type arg9) const;\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00001658 p0##_type p0;\
shiqian326aa562009-01-09 21:43:57 +00001659 };\
1660 template <typename F> operator ::testing::Action<F>() const {\
1661 return ::testing::Action<F>(new gmock_Impl<F>(p0));\
1662 }\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00001663 p0##_type p0;\
shiqian326aa562009-01-09 21:43:57 +00001664 };\
1665 template <typename p0##_type>\
1666 inline name##ActionP<p0##_type> name(p0##_type p0) {\
1667 return name##ActionP<p0##_type>(p0);\
1668 }\
1669 template <typename p0##_type>\
1670 template <typename F>\
1671 template <typename arg0_type, typename arg1_type, typename arg2_type, \
1672 typename arg3_type, typename arg4_type, typename arg5_type, \
1673 typename arg6_type, typename arg7_type, typename arg8_type, \
1674 typename arg9_type>\
1675 typename ::testing::internal::Function<F>::Result\
zhanyong.wan33c0af02009-04-03 00:10:12 +00001676 name##ActionP<p0##_type>::gmock_Impl<F>::gmock_PerformImpl(\
1677 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
shiqian326aa562009-01-09 21:43:57 +00001678
1679#define ACTION_P2(name, p0, p1)\
1680 template <typename p0##_type, typename p1##_type>\
1681 class name##ActionP2 {\
1682 public:\
1683 name##ActionP2(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \
1684 p1(gmock_p1) {}\
1685 template <typename F>\
1686 class gmock_Impl : public ::testing::ActionInterface<F> {\
1687 public:\
1688 typedef F function_type;\
1689 typedef typename ::testing::internal::Function<F>::Result return_type;\
1690 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
1691 args_type;\
1692 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \
1693 p1(gmock_p1) {}\
1694 virtual return_type Perform(const args_type& args) {\
1695 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
1696 Perform(this, args);\
1697 }\
1698 template <typename arg0_type, typename arg1_type, typename arg2_type, \
1699 typename arg3_type, typename arg4_type, typename arg5_type, \
1700 typename arg6_type, typename arg7_type, typename arg8_type, \
1701 typename arg9_type>\
1702 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
1703 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
1704 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
1705 arg9_type arg9) const;\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00001706 p0##_type p0;\
1707 p1##_type p1;\
shiqian326aa562009-01-09 21:43:57 +00001708 };\
1709 template <typename F> operator ::testing::Action<F>() const {\
1710 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1));\
1711 }\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00001712 p0##_type p0;\
1713 p1##_type p1;\
shiqian326aa562009-01-09 21:43:57 +00001714 };\
1715 template <typename p0##_type, typename p1##_type>\
1716 inline name##ActionP2<p0##_type, p1##_type> name(p0##_type p0, \
1717 p1##_type p1) {\
1718 return name##ActionP2<p0##_type, p1##_type>(p0, p1);\
1719 }\
1720 template <typename p0##_type, typename p1##_type>\
1721 template <typename F>\
1722 template <typename arg0_type, typename arg1_type, typename arg2_type, \
1723 typename arg3_type, typename arg4_type, typename arg5_type, \
1724 typename arg6_type, typename arg7_type, typename arg8_type, \
1725 typename arg9_type>\
1726 typename ::testing::internal::Function<F>::Result\
zhanyong.wan33c0af02009-04-03 00:10:12 +00001727 name##ActionP2<p0##_type, p1##_type>::gmock_Impl<F>::gmock_PerformImpl(\
1728 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
shiqian326aa562009-01-09 21:43:57 +00001729
1730#define ACTION_P3(name, p0, p1, p2)\
1731 template <typename p0##_type, typename p1##_type, typename p2##_type>\
1732 class name##ActionP3 {\
1733 public:\
1734 name##ActionP3(p0##_type gmock_p0, p1##_type gmock_p1, \
1735 p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\
1736 template <typename F>\
1737 class gmock_Impl : public ::testing::ActionInterface<F> {\
1738 public:\
1739 typedef F function_type;\
1740 typedef typename ::testing::internal::Function<F>::Result return_type;\
1741 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
1742 args_type;\
1743 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, \
1744 p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\
1745 virtual return_type Perform(const args_type& args) {\
1746 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
1747 Perform(this, args);\
1748 }\
1749 template <typename arg0_type, typename arg1_type, typename arg2_type, \
1750 typename arg3_type, typename arg4_type, typename arg5_type, \
1751 typename arg6_type, typename arg7_type, typename arg8_type, \
1752 typename arg9_type>\
1753 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
1754 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
1755 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
1756 arg9_type arg9) const;\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00001757 p0##_type p0;\
1758 p1##_type p1;\
1759 p2##_type p2;\
shiqian326aa562009-01-09 21:43:57 +00001760 };\
1761 template <typename F> operator ::testing::Action<F>() const {\
1762 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2));\
1763 }\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00001764 p0##_type p0;\
1765 p1##_type p1;\
1766 p2##_type p2;\
shiqian326aa562009-01-09 21:43:57 +00001767 };\
1768 template <typename p0##_type, typename p1##_type, typename p2##_type>\
1769 inline name##ActionP3<p0##_type, p1##_type, p2##_type> name(p0##_type p0, \
1770 p1##_type p1, p2##_type p2) {\
1771 return name##ActionP3<p0##_type, p1##_type, p2##_type>(p0, p1, p2);\
1772 }\
1773 template <typename p0##_type, typename p1##_type, typename p2##_type>\
1774 template <typename F>\
1775 template <typename arg0_type, typename arg1_type, typename arg2_type, \
1776 typename arg3_type, typename arg4_type, typename arg5_type, \
1777 typename arg6_type, typename arg7_type, typename arg8_type, \
1778 typename arg9_type>\
1779 typename ::testing::internal::Function<F>::Result\
zhanyong.wan33c0af02009-04-03 00:10:12 +00001780 name##ActionP3<p0##_type, p1##_type, \
1781 p2##_type>::gmock_Impl<F>::gmock_PerformImpl(\
1782 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
shiqian326aa562009-01-09 21:43:57 +00001783
1784#define ACTION_P4(name, p0, p1, p2, p3)\
1785 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1786 typename p3##_type>\
1787 class name##ActionP4 {\
1788 public:\
1789 name##ActionP4(p0##_type gmock_p0, p1##_type gmock_p1, \
1790 p2##_type gmock_p2, p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), \
1791 p2(gmock_p2), p3(gmock_p3) {}\
1792 template <typename F>\
1793 class gmock_Impl : public ::testing::ActionInterface<F> {\
1794 public:\
1795 typedef F function_type;\
1796 typedef typename ::testing::internal::Function<F>::Result return_type;\
1797 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
1798 args_type;\
1799 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
1800 p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
1801 p3(gmock_p3) {}\
1802 virtual return_type Perform(const args_type& args) {\
1803 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
1804 Perform(this, args);\
1805 }\
1806 template <typename arg0_type, typename arg1_type, typename arg2_type, \
1807 typename arg3_type, typename arg4_type, typename arg5_type, \
1808 typename arg6_type, typename arg7_type, typename arg8_type, \
1809 typename arg9_type>\
1810 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
1811 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
1812 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
1813 arg9_type arg9) const;\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00001814 p0##_type p0;\
1815 p1##_type p1;\
1816 p2##_type p2;\
1817 p3##_type p3;\
shiqian326aa562009-01-09 21:43:57 +00001818 };\
1819 template <typename F> operator ::testing::Action<F>() const {\
1820 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3));\
1821 }\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00001822 p0##_type p0;\
1823 p1##_type p1;\
1824 p2##_type p2;\
1825 p3##_type p3;\
shiqian326aa562009-01-09 21:43:57 +00001826 };\
1827 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1828 typename p3##_type>\
1829 inline name##ActionP4<p0##_type, p1##_type, p2##_type, \
1830 p3##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
1831 p3##_type p3) {\
1832 return name##ActionP4<p0##_type, p1##_type, p2##_type, p3##_type>(p0, p1, \
1833 p2, p3);\
1834 }\
1835 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1836 typename p3##_type>\
1837 template <typename F>\
1838 template <typename arg0_type, typename arg1_type, typename arg2_type, \
1839 typename arg3_type, typename arg4_type, typename arg5_type, \
1840 typename arg6_type, typename arg7_type, typename arg8_type, \
1841 typename arg9_type>\
1842 typename ::testing::internal::Function<F>::Result\
zhanyong.wan33c0af02009-04-03 00:10:12 +00001843 name##ActionP4<p0##_type, p1##_type, p2##_type, \
1844 p3##_type>::gmock_Impl<F>::gmock_PerformImpl(\
1845 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
shiqian326aa562009-01-09 21:43:57 +00001846
1847#define ACTION_P5(name, p0, p1, p2, p3, p4)\
1848 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1849 typename p3##_type, typename p4##_type>\
1850 class name##ActionP5 {\
1851 public:\
1852 name##ActionP5(p0##_type gmock_p0, p1##_type gmock_p1, \
1853 p2##_type gmock_p2, p3##_type gmock_p3, \
1854 p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
1855 p3(gmock_p3), p4(gmock_p4) {}\
1856 template <typename F>\
1857 class gmock_Impl : public ::testing::ActionInterface<F> {\
1858 public:\
1859 typedef F function_type;\
1860 typedef typename ::testing::internal::Function<F>::Result return_type;\
1861 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
1862 args_type;\
1863 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
1864 p3##_type gmock_p3, p4##_type gmock_p4) : p0(gmock_p0), \
1865 p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), p4(gmock_p4) {}\
1866 virtual return_type Perform(const args_type& args) {\
1867 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
1868 Perform(this, args);\
1869 }\
1870 template <typename arg0_type, typename arg1_type, typename arg2_type, \
1871 typename arg3_type, typename arg4_type, typename arg5_type, \
1872 typename arg6_type, typename arg7_type, typename arg8_type, \
1873 typename arg9_type>\
1874 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
1875 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
1876 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
1877 arg9_type arg9) const;\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00001878 p0##_type p0;\
1879 p1##_type p1;\
1880 p2##_type p2;\
1881 p3##_type p3;\
1882 p4##_type p4;\
shiqian326aa562009-01-09 21:43:57 +00001883 };\
1884 template <typename F> operator ::testing::Action<F>() const {\
1885 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4));\
1886 }\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00001887 p0##_type p0;\
1888 p1##_type p1;\
1889 p2##_type p2;\
1890 p3##_type p3;\
1891 p4##_type p4;\
shiqian326aa562009-01-09 21:43:57 +00001892 };\
1893 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1894 typename p3##_type, typename p4##_type>\
1895 inline name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \
1896 p4##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
1897 p4##_type p4) {\
1898 return name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \
1899 p4##_type>(p0, p1, p2, p3, p4);\
1900 }\
1901 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1902 typename p3##_type, typename p4##_type>\
1903 template <typename F>\
1904 template <typename arg0_type, typename arg1_type, typename arg2_type, \
1905 typename arg3_type, typename arg4_type, typename arg5_type, \
1906 typename arg6_type, typename arg7_type, typename arg8_type, \
1907 typename arg9_type>\
1908 typename ::testing::internal::Function<F>::Result\
zhanyong.wan33c0af02009-04-03 00:10:12 +00001909 name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \
1910 p4##_type>::gmock_Impl<F>::gmock_PerformImpl(\
1911 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
shiqian326aa562009-01-09 21:43:57 +00001912
1913#define ACTION_P6(name, p0, p1, p2, p3, p4, p5)\
1914 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1915 typename p3##_type, typename p4##_type, typename p5##_type>\
1916 class name##ActionP6 {\
1917 public:\
1918 name##ActionP6(p0##_type gmock_p0, p1##_type gmock_p1, \
1919 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
1920 p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
1921 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {}\
1922 template <typename F>\
1923 class gmock_Impl : public ::testing::ActionInterface<F> {\
1924 public:\
1925 typedef F function_type;\
1926 typedef typename ::testing::internal::Function<F>::Result return_type;\
1927 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
1928 args_type;\
1929 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
1930 p3##_type gmock_p3, p4##_type gmock_p4, \
1931 p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
1932 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {}\
1933 virtual return_type Perform(const args_type& args) {\
1934 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
1935 Perform(this, args);\
1936 }\
1937 template <typename arg0_type, typename arg1_type, typename arg2_type, \
1938 typename arg3_type, typename arg4_type, typename arg5_type, \
1939 typename arg6_type, typename arg7_type, typename arg8_type, \
1940 typename arg9_type>\
1941 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
1942 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
1943 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
1944 arg9_type arg9) const;\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00001945 p0##_type p0;\
1946 p1##_type p1;\
1947 p2##_type p2;\
1948 p3##_type p3;\
1949 p4##_type p4;\
1950 p5##_type p5;\
shiqian326aa562009-01-09 21:43:57 +00001951 };\
1952 template <typename F> operator ::testing::Action<F>() const {\
1953 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5));\
1954 }\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00001955 p0##_type p0;\
1956 p1##_type p1;\
1957 p2##_type p2;\
1958 p3##_type p3;\
1959 p4##_type p4;\
1960 p5##_type p5;\
shiqian326aa562009-01-09 21:43:57 +00001961 };\
1962 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1963 typename p3##_type, typename p4##_type, typename p5##_type>\
1964 inline name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, \
1965 p4##_type, p5##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
1966 p3##_type p3, p4##_type p4, p5##_type p5) {\
1967 return name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, \
1968 p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5);\
1969 }\
1970 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1971 typename p3##_type, typename p4##_type, typename p5##_type>\
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 name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
zhanyong.wan33c0af02009-04-03 00:10:12 +00001979 p5##_type>::gmock_Impl<F>::gmock_PerformImpl(\
1980 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
shiqian326aa562009-01-09 21:43:57 +00001981
1982#define ACTION_P7(name, p0, p1, p2, p3, p4, p5, p6)\
1983 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1984 typename p3##_type, typename p4##_type, typename p5##_type, \
1985 typename p6##_type>\
1986 class name##ActionP7 {\
1987 public:\
1988 name##ActionP7(p0##_type gmock_p0, p1##_type gmock_p1, \
1989 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
1990 p5##_type gmock_p5, p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), \
1991 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), \
1992 p6(gmock_p6) {}\
1993 template <typename F>\
1994 class gmock_Impl : public ::testing::ActionInterface<F> {\
1995 public:\
1996 typedef F function_type;\
1997 typedef typename ::testing::internal::Function<F>::Result return_type;\
1998 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
1999 args_type;\
2000 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
2001 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
2002 p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
2003 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6) {}\
2004 virtual return_type Perform(const args_type& args) {\
2005 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
2006 Perform(this, args);\
2007 }\
2008 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2009 typename arg3_type, typename arg4_type, typename arg5_type, \
2010 typename arg6_type, typename arg7_type, typename arg8_type, \
2011 typename arg9_type>\
2012 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
2013 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
2014 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
2015 arg9_type arg9) const;\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00002016 p0##_type p0;\
2017 p1##_type p1;\
2018 p2##_type p2;\
2019 p3##_type p3;\
2020 p4##_type p4;\
2021 p5##_type p5;\
2022 p6##_type p6;\
shiqian326aa562009-01-09 21:43:57 +00002023 };\
2024 template <typename F> operator ::testing::Action<F>() const {\
2025 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
2026 p6));\
2027 }\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00002028 p0##_type p0;\
2029 p1##_type p1;\
2030 p2##_type p2;\
2031 p3##_type p3;\
2032 p4##_type p4;\
2033 p5##_type p5;\
2034 p6##_type p6;\
shiqian326aa562009-01-09 21:43:57 +00002035 };\
2036 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2037 typename p3##_type, typename p4##_type, typename p5##_type, \
2038 typename p6##_type>\
2039 inline name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, \
2040 p4##_type, p5##_type, p6##_type> name(p0##_type p0, p1##_type p1, \
2041 p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
2042 p6##_type p6) {\
2043 return name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, \
2044 p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, p6);\
2045 }\
2046 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2047 typename p3##_type, typename p4##_type, typename p5##_type, \
2048 typename p6##_type>\
2049 template <typename F>\
2050 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2051 typename arg3_type, typename arg4_type, typename arg5_type, \
2052 typename arg6_type, typename arg7_type, typename arg8_type, \
2053 typename arg9_type>\
2054 typename ::testing::internal::Function<F>::Result\
2055 name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
zhanyong.wan33c0af02009-04-03 00:10:12 +00002056 p5##_type, p6##_type>::gmock_Impl<F>::gmock_PerformImpl(\
2057 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
shiqian326aa562009-01-09 21:43:57 +00002058
2059#define ACTION_P8(name, p0, p1, p2, p3, p4, p5, p6, p7)\
2060 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2061 typename p3##_type, typename p4##_type, typename p5##_type, \
2062 typename p6##_type, typename p7##_type>\
2063 class name##ActionP8 {\
2064 public:\
2065 name##ActionP8(p0##_type gmock_p0, p1##_type gmock_p1, \
2066 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
2067 p5##_type gmock_p5, p6##_type gmock_p6, \
2068 p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
2069 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
2070 p7(gmock_p7) {}\
2071 template <typename F>\
2072 class gmock_Impl : public ::testing::ActionInterface<F> {\
2073 public:\
2074 typedef F function_type;\
2075 typedef typename ::testing::internal::Function<F>::Result return_type;\
2076 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
2077 args_type;\
2078 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
2079 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
2080 p6##_type gmock_p6, p7##_type gmock_p7) : p0(gmock_p0), \
2081 p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), \
2082 p5(gmock_p5), p6(gmock_p6), p7(gmock_p7) {}\
2083 virtual return_type Perform(const args_type& args) {\
2084 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
2085 Perform(this, args);\
2086 }\
2087 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2088 typename arg3_type, typename arg4_type, typename arg5_type, \
2089 typename arg6_type, typename arg7_type, typename arg8_type, \
2090 typename arg9_type>\
2091 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
2092 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
2093 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
2094 arg9_type arg9) const;\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00002095 p0##_type p0;\
2096 p1##_type p1;\
2097 p2##_type p2;\
2098 p3##_type p3;\
2099 p4##_type p4;\
2100 p5##_type p5;\
2101 p6##_type p6;\
2102 p7##_type p7;\
shiqian326aa562009-01-09 21:43:57 +00002103 };\
2104 template <typename F> operator ::testing::Action<F>() const {\
2105 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
2106 p6, p7));\
2107 }\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00002108 p0##_type p0;\
2109 p1##_type p1;\
2110 p2##_type p2;\
2111 p3##_type p3;\
2112 p4##_type p4;\
2113 p5##_type p5;\
2114 p6##_type p6;\
2115 p7##_type p7;\
shiqian326aa562009-01-09 21:43:57 +00002116 };\
2117 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2118 typename p3##_type, typename p4##_type, typename p5##_type, \
2119 typename p6##_type, typename p7##_type>\
2120 inline name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, \
2121 p4##_type, p5##_type, p6##_type, p7##_type> name(p0##_type p0, \
2122 p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
2123 p6##_type p6, p7##_type p7) {\
2124 return name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, \
2125 p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, p3, p4, p5, \
2126 p6, p7);\
2127 }\
2128 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2129 typename p3##_type, typename p4##_type, typename p5##_type, \
2130 typename p6##_type, typename p7##_type>\
2131 template <typename F>\
2132 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2133 typename arg3_type, typename arg4_type, typename arg5_type, \
2134 typename arg6_type, typename arg7_type, typename arg8_type, \
2135 typename arg9_type>\
2136 typename ::testing::internal::Function<F>::Result\
2137 name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
zhanyong.wan33c0af02009-04-03 00:10:12 +00002138 p5##_type, p6##_type, \
2139 p7##_type>::gmock_Impl<F>::gmock_PerformImpl(\
2140 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
shiqian326aa562009-01-09 21:43:57 +00002141
2142#define ACTION_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8)\
2143 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2144 typename p3##_type, typename p4##_type, typename p5##_type, \
2145 typename p6##_type, typename p7##_type, typename p8##_type>\
2146 class name##ActionP9 {\
2147 public:\
2148 name##ActionP9(p0##_type gmock_p0, p1##_type gmock_p1, \
2149 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
2150 p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
2151 p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
2152 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
2153 p8(gmock_p8) {}\
2154 template <typename F>\
2155 class gmock_Impl : public ::testing::ActionInterface<F> {\
2156 public:\
2157 typedef F function_type;\
2158 typedef typename ::testing::internal::Function<F>::Result return_type;\
2159 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
2160 args_type;\
2161 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
2162 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
2163 p6##_type gmock_p6, p7##_type gmock_p7, \
2164 p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
2165 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
2166 p7(gmock_p7), p8(gmock_p8) {}\
2167 virtual return_type Perform(const args_type& args) {\
2168 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
2169 Perform(this, args);\
2170 }\
2171 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2172 typename arg3_type, typename arg4_type, typename arg5_type, \
2173 typename arg6_type, typename arg7_type, typename arg8_type, \
2174 typename arg9_type>\
2175 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
2176 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
2177 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
2178 arg9_type arg9) const;\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00002179 p0##_type p0;\
2180 p1##_type p1;\
2181 p2##_type p2;\
2182 p3##_type p3;\
2183 p4##_type p4;\
2184 p5##_type p5;\
2185 p6##_type p6;\
2186 p7##_type p7;\
2187 p8##_type p8;\
shiqian326aa562009-01-09 21:43:57 +00002188 };\
2189 template <typename F> operator ::testing::Action<F>() const {\
2190 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
2191 p6, p7, p8));\
2192 }\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00002193 p0##_type p0;\
2194 p1##_type p1;\
2195 p2##_type p2;\
2196 p3##_type p3;\
2197 p4##_type p4;\
2198 p5##_type p5;\
2199 p6##_type p6;\
2200 p7##_type p7;\
2201 p8##_type p8;\
shiqian326aa562009-01-09 21:43:57 +00002202 };\
2203 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2204 typename p3##_type, typename p4##_type, typename p5##_type, \
2205 typename p6##_type, typename p7##_type, typename p8##_type>\
2206 inline name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, \
2207 p4##_type, p5##_type, p6##_type, p7##_type, \
2208 p8##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
2209 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, \
2210 p8##_type p8) {\
2211 return name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, \
2212 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type>(p0, p1, p2, \
2213 p3, p4, p5, p6, p7, p8);\
2214 }\
2215 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2216 typename p3##_type, typename p4##_type, typename p5##_type, \
2217 typename p6##_type, typename p7##_type, typename p8##_type>\
2218 template <typename F>\
2219 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2220 typename arg3_type, typename arg4_type, typename arg5_type, \
2221 typename arg6_type, typename arg7_type, typename arg8_type, \
2222 typename arg9_type>\
2223 typename ::testing::internal::Function<F>::Result\
2224 name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
zhanyong.wan33c0af02009-04-03 00:10:12 +00002225 p5##_type, p6##_type, p7##_type, \
2226 p8##_type>::gmock_Impl<F>::gmock_PerformImpl(\
2227 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
shiqian326aa562009-01-09 21:43:57 +00002228
2229#define ACTION_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)\
2230 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2231 typename p3##_type, typename p4##_type, typename p5##_type, \
2232 typename p6##_type, typename p7##_type, typename p8##_type, \
2233 typename p9##_type>\
2234 class name##ActionP10 {\
2235 public:\
2236 name##ActionP10(p0##_type gmock_p0, p1##_type gmock_p1, \
2237 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
2238 p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
2239 p8##_type gmock_p8, p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), \
2240 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
2241 p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {}\
2242 template <typename F>\
2243 class gmock_Impl : public ::testing::ActionInterface<F> {\
2244 public:\
2245 typedef F function_type;\
2246 typedef typename ::testing::internal::Function<F>::Result return_type;\
2247 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
2248 args_type;\
2249 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
2250 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
2251 p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
2252 p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
2253 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
2254 p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {}\
2255 virtual return_type Perform(const args_type& args) {\
2256 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
2257 Perform(this, args);\
2258 }\
2259 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2260 typename arg3_type, typename arg4_type, typename arg5_type, \
2261 typename arg6_type, typename arg7_type, typename arg8_type, \
2262 typename arg9_type>\
2263 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
2264 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
2265 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
2266 arg9_type arg9) const;\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00002267 p0##_type p0;\
2268 p1##_type p1;\
2269 p2##_type p2;\
2270 p3##_type p3;\
2271 p4##_type p4;\
2272 p5##_type p5;\
2273 p6##_type p6;\
2274 p7##_type p7;\
2275 p8##_type p8;\
2276 p9##_type p9;\
shiqian326aa562009-01-09 21:43:57 +00002277 };\
2278 template <typename F> operator ::testing::Action<F>() const {\
2279 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
2280 p6, p7, p8, p9));\
2281 }\
zhanyong.wanc069d7f2009-02-02 20:51:53 +00002282 p0##_type p0;\
2283 p1##_type p1;\
2284 p2##_type p2;\
2285 p3##_type p3;\
2286 p4##_type p4;\
2287 p5##_type p5;\
2288 p6##_type p6;\
2289 p7##_type p7;\
2290 p8##_type p8;\
2291 p9##_type p9;\
shiqian326aa562009-01-09 21:43:57 +00002292 };\
2293 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2294 typename p3##_type, typename p4##_type, typename p5##_type, \
2295 typename p6##_type, typename p7##_type, typename p8##_type, \
2296 typename p9##_type>\
2297 inline name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, \
2298 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
2299 p9##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
2300 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \
2301 p9##_type p9) {\
2302 return name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, \
2303 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, p9##_type>(p0, \
2304 p1, p2, p3, p4, p5, p6, p7, p8, p9);\
2305 }\
2306 template <typename p0##_type, typename p1##_type, typename p2##_type, \
2307 typename p3##_type, typename p4##_type, typename p5##_type, \
2308 typename p6##_type, typename p7##_type, typename p8##_type, \
2309 typename p9##_type>\
2310 template <typename F>\
2311 template <typename arg0_type, typename arg1_type, typename arg2_type, \
2312 typename arg3_type, typename arg4_type, typename arg5_type, \
2313 typename arg6_type, typename arg7_type, typename arg8_type, \
2314 typename arg9_type>\
2315 typename ::testing::internal::Function<F>::Result\
2316 name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
zhanyong.wan33c0af02009-04-03 00:10:12 +00002317 p5##_type, p6##_type, p7##_type, p8##_type, \
2318 p9##_type>::gmock_Impl<F>::gmock_PerformImpl(\
2319 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
shiqian326aa562009-01-09 21:43:57 +00002320
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00002321// TODO(wan@google.com): move the following to a different .h file
2322// such that we don't have to run 'pump' every time the code is
2323// updated.
zhanyong.wane1cdce52009-02-06 01:09:43 +00002324namespace testing {
2325
zhanyong.wan16cf4732009-05-14 20:55:30 +00002326// Various overloads for InvokeArgument<N>().
2327//
2328// The InvokeArgument<N>(a1, a2, ..., a_k) action invokes the N-th
2329// (0-based) argument, which must be a k-ary callable, of the mock
2330// function, with arguments a1, a2, ..., a_k.
2331//
2332// Notes:
2333//
2334// 1. The arguments are passed by value by default. If you need to
2335// pass an argument by reference, wrap it inside ByRef(). For
2336// example,
2337//
2338// InvokeArgument<1>(5, string("Hello"), ByRef(foo))
2339//
2340// passes 5 and string("Hello") by value, and passes foo by
2341// reference.
2342//
2343// 2. If the callable takes an argument by reference but ByRef() is
2344// not used, it will receive the reference to a copy of the value,
2345// instead of the original value. For example, when the 0-th
2346// argument of the mock function takes a const string&, the action
2347//
2348// InvokeArgument<0>(string("Hello"))
2349//
2350// makes a copy of the temporary string("Hello") object and passes a
2351// reference of the copy, instead of the original temporary object,
2352// to the callable. This makes it easy for a user to define an
2353// InvokeArgument action from temporary values and have it performed
2354// later.
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00002355
zhanyong.wan16cf4732009-05-14 20:55:30 +00002356ACTION_TEMPLATE(InvokeArgument,
2357 HAS_1_TEMPLATE_PARAMS(int, k),
2358 AND_0_VALUE_PARAMS()) {
2359 return internal::CallableHelper<return_type>::Call(
2360 ::std::tr1::get<k>(args));
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00002361}
2362
zhanyong.wan16cf4732009-05-14 20:55:30 +00002363ACTION_TEMPLATE(InvokeArgument,
2364 HAS_1_TEMPLATE_PARAMS(int, k),
2365 AND_1_VALUE_PARAMS(p0)) {
2366 return internal::CallableHelper<return_type>::Call(
2367 ::std::tr1::get<k>(args), p0);
2368}
zhanyong.wan1c8eb1c2009-04-09 07:29:58 +00002369
zhanyong.wan16cf4732009-05-14 20:55:30 +00002370ACTION_TEMPLATE(InvokeArgument,
2371 HAS_1_TEMPLATE_PARAMS(int, k),
2372 AND_2_VALUE_PARAMS(p0, p1)) {
2373 return internal::CallableHelper<return_type>::Call(
2374 ::std::tr1::get<k>(args), p0, p1);
2375}
zhanyong.wan1c8eb1c2009-04-09 07:29:58 +00002376
zhanyong.wan16cf4732009-05-14 20:55:30 +00002377ACTION_TEMPLATE(InvokeArgument,
2378 HAS_1_TEMPLATE_PARAMS(int, k),
2379 AND_3_VALUE_PARAMS(p0, p1, p2)) {
2380 return internal::CallableHelper<return_type>::Call(
2381 ::std::tr1::get<k>(args), p0, p1, p2);
2382}
zhanyong.wan1c8eb1c2009-04-09 07:29:58 +00002383
zhanyong.wan16cf4732009-05-14 20:55:30 +00002384ACTION_TEMPLATE(InvokeArgument,
2385 HAS_1_TEMPLATE_PARAMS(int, k),
2386 AND_4_VALUE_PARAMS(p0, p1, p2, p3)) {
2387 return internal::CallableHelper<return_type>::Call(
2388 ::std::tr1::get<k>(args), p0, p1, p2, p3);
2389}
zhanyong.wan1c8eb1c2009-04-09 07:29:58 +00002390
zhanyong.wan16cf4732009-05-14 20:55:30 +00002391ACTION_TEMPLATE(InvokeArgument,
2392 HAS_1_TEMPLATE_PARAMS(int, k),
2393 AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)) {
2394 return internal::CallableHelper<return_type>::Call(
2395 ::std::tr1::get<k>(args), p0, p1, p2, p3, p4);
2396}
zhanyong.wan1c8eb1c2009-04-09 07:29:58 +00002397
zhanyong.wan16cf4732009-05-14 20:55:30 +00002398ACTION_TEMPLATE(InvokeArgument,
2399 HAS_1_TEMPLATE_PARAMS(int, k),
2400 AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)) {
2401 return internal::CallableHelper<return_type>::Call(
2402 ::std::tr1::get<k>(args), p0, p1, p2, p3, p4, p5);
2403}
zhanyong.wan1c8eb1c2009-04-09 07:29:58 +00002404
zhanyong.wan16cf4732009-05-14 20:55:30 +00002405ACTION_TEMPLATE(InvokeArgument,
2406 HAS_1_TEMPLATE_PARAMS(int, k),
2407 AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)) {
2408 return internal::CallableHelper<return_type>::Call(
2409 ::std::tr1::get<k>(args), p0, p1, p2, p3, p4, p5, p6);
2410}
zhanyong.wan1c8eb1c2009-04-09 07:29:58 +00002411
zhanyong.wan16cf4732009-05-14 20:55:30 +00002412ACTION_TEMPLATE(InvokeArgument,
2413 HAS_1_TEMPLATE_PARAMS(int, k),
2414 AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)) {
2415 return internal::CallableHelper<return_type>::Call(
2416 ::std::tr1::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7);
2417}
zhanyong.wan1c8eb1c2009-04-09 07:29:58 +00002418
zhanyong.wan16cf4732009-05-14 20:55:30 +00002419ACTION_TEMPLATE(InvokeArgument,
2420 HAS_1_TEMPLATE_PARAMS(int, k),
2421 AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8)) {
2422 return internal::CallableHelper<return_type>::Call(
2423 ::std::tr1::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7, p8);
2424}
zhanyong.wan1c8eb1c2009-04-09 07:29:58 +00002425
zhanyong.wan16cf4732009-05-14 20:55:30 +00002426ACTION_TEMPLATE(InvokeArgument,
2427 HAS_1_TEMPLATE_PARAMS(int, k),
2428 AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)) {
2429 return internal::CallableHelper<return_type>::Call(
2430 ::std::tr1::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7, p8, p9);
2431}
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00002432
2433// Action SaveArg<k>(pointer) saves the k-th (0-based) argument of the
2434// mock function to *pointer.
zhanyong.wan16cf4732009-05-14 20:55:30 +00002435ACTION_TEMPLATE(SaveArg,
2436 HAS_1_TEMPLATE_PARAMS(int, k),
2437 AND_1_VALUE_PARAMS(pointer)) {
2438 *pointer = ::std::tr1::get<k>(args);
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00002439}
2440
2441// Action SetArgReferee<k>(value) assigns 'value' to the variable
2442// referenced by the k-th (0-based) argument of the mock function.
zhanyong.wan16cf4732009-05-14 20:55:30 +00002443ACTION_TEMPLATE(SetArgReferee,
2444 HAS_1_TEMPLATE_PARAMS(int, k),
2445 AND_1_VALUE_PARAMS(value)) {
2446 typedef typename ::std::tr1::tuple_element<k, args_type>::type argk_type;
2447 // Ensures that argument #k is a reference. If you get a compiler
2448 // error on the next line, you are using SetArgReferee<k>(value) in
2449 // a mock function whose k-th (0-based) argument is not a reference.
2450 GMOCK_COMPILE_ASSERT_(internal::is_reference<argk_type>::value,
2451 SetArgReferee_must_be_used_with_a_reference_argument);
2452 ::std::tr1::get<k>(args) = value;
2453}
2454
2455// Action SetArrayArgument<k>(first, last) copies the elements in
2456// source range [first, last) to the array pointed to by the k-th
2457// (0-based) argument, which can be either a pointer or an
2458// iterator. The action does not take ownership of the elements in the
2459// source range.
2460ACTION_TEMPLATE(SetArrayArgument,
2461 HAS_1_TEMPLATE_PARAMS(int, k),
2462 AND_2_VALUE_PARAMS(first, last)) {
2463 // Microsoft compiler deprecates ::std::copy, so we want to suppress warning
2464 // 4996 (Function call with parameters that may be unsafe) there.
2465#ifdef _MSC_VER
2466#pragma warning(push) // Saves the current warning state.
2467#pragma warning(disable:4996) // Temporarily disables warning 4996.
2468#endif
2469 ::std::copy(first, last, ::std::tr1::get<k>(args));
2470#ifdef _MSC_VER
2471#pragma warning(pop) // Restores the warning state.
2472#endif
zhanyong.wan7f4c2c02009-02-19 22:38:27 +00002473}
2474
zhanyong.wan1c8eb1c2009-04-09 07:29:58 +00002475// Various overloads for ReturnNew<T>().
2476//
2477// The ReturnNew<T>(a1, a2, ..., a_k) action returns a pointer to a new
2478// instance of type T, constructed on the heap with constructor arguments
2479// a1, a2, ..., and a_k. The caller assumes ownership of the returned value.
zhanyong.wan16cf4732009-05-14 20:55:30 +00002480ACTION_TEMPLATE(ReturnNew,
2481 HAS_1_TEMPLATE_PARAMS(typename, T),
2482 AND_0_VALUE_PARAMS()) {
2483 return new T();
zhanyong.wan1c8eb1c2009-04-09 07:29:58 +00002484}
2485
zhanyong.wan16cf4732009-05-14 20:55:30 +00002486ACTION_TEMPLATE(ReturnNew,
2487 HAS_1_TEMPLATE_PARAMS(typename, T),
2488 AND_1_VALUE_PARAMS(p0)) {
2489 return new T(p0);
zhanyong.wan1c8eb1c2009-04-09 07:29:58 +00002490}
2491
zhanyong.wan16cf4732009-05-14 20:55:30 +00002492ACTION_TEMPLATE(ReturnNew,
2493 HAS_1_TEMPLATE_PARAMS(typename, T),
2494 AND_2_VALUE_PARAMS(p0, p1)) {
2495 return new T(p0, p1);
zhanyong.wan1c8eb1c2009-04-09 07:29:58 +00002496}
2497
zhanyong.wan16cf4732009-05-14 20:55:30 +00002498ACTION_TEMPLATE(ReturnNew,
2499 HAS_1_TEMPLATE_PARAMS(typename, T),
2500 AND_3_VALUE_PARAMS(p0, p1, p2)) {
2501 return new T(p0, p1, p2);
zhanyong.wan1c8eb1c2009-04-09 07:29:58 +00002502}
2503
zhanyong.wan16cf4732009-05-14 20:55:30 +00002504ACTION_TEMPLATE(ReturnNew,
2505 HAS_1_TEMPLATE_PARAMS(typename, T),
2506 AND_4_VALUE_PARAMS(p0, p1, p2, p3)) {
2507 return new T(p0, p1, p2, p3);
zhanyong.wan1c8eb1c2009-04-09 07:29:58 +00002508}
2509
zhanyong.wan16cf4732009-05-14 20:55:30 +00002510ACTION_TEMPLATE(ReturnNew,
2511 HAS_1_TEMPLATE_PARAMS(typename, T),
2512 AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)) {
2513 return new T(p0, p1, p2, p3, p4);
zhanyong.wan1c8eb1c2009-04-09 07:29:58 +00002514}
2515
zhanyong.wan16cf4732009-05-14 20:55:30 +00002516ACTION_TEMPLATE(ReturnNew,
2517 HAS_1_TEMPLATE_PARAMS(typename, T),
2518 AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)) {
2519 return new T(p0, p1, p2, p3, p4, p5);
zhanyong.wan1c8eb1c2009-04-09 07:29:58 +00002520}
2521
zhanyong.wan16cf4732009-05-14 20:55:30 +00002522ACTION_TEMPLATE(ReturnNew,
2523 HAS_1_TEMPLATE_PARAMS(typename, T),
2524 AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)) {
2525 return new T(p0, p1, p2, p3, p4, p5, p6);
zhanyong.wan1c8eb1c2009-04-09 07:29:58 +00002526}
2527
zhanyong.wan16cf4732009-05-14 20:55:30 +00002528ACTION_TEMPLATE(ReturnNew,
2529 HAS_1_TEMPLATE_PARAMS(typename, T),
2530 AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)) {
2531 return new T(p0, p1, p2, p3, p4, p5, p6, p7);
zhanyong.wan1c8eb1c2009-04-09 07:29:58 +00002532}
2533
zhanyong.wan16cf4732009-05-14 20:55:30 +00002534ACTION_TEMPLATE(ReturnNew,
2535 HAS_1_TEMPLATE_PARAMS(typename, T),
2536 AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8)) {
2537 return new T(p0, p1, p2, p3, p4, p5, p6, p7, p8);
zhanyong.wan1c8eb1c2009-04-09 07:29:58 +00002538}
2539
zhanyong.wan16cf4732009-05-14 20:55:30 +00002540ACTION_TEMPLATE(ReturnNew,
2541 HAS_1_TEMPLATE_PARAMS(typename, T),
2542 AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)) {
2543 return new T(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9);
zhanyong.wan1c8eb1c2009-04-09 07:29:58 +00002544}
2545
2546// Action DeleteArg<k>() deletes the k-th (0-based) argument of the mock
2547// function.
zhanyong.wan16cf4732009-05-14 20:55:30 +00002548ACTION_TEMPLATE(DeleteArg,
2549 HAS_1_TEMPLATE_PARAMS(int, k),
2550 AND_0_VALUE_PARAMS()) {
2551 delete ::std::tr1::get<k>(args);
zhanyong.wan1c8eb1c2009-04-09 07:29:58 +00002552}
2553
zhanyong.wane1cdce52009-02-06 01:09:43 +00002554// Action Throw(exception) can be used in a mock function of any type
2555// to throw the given exception. Any copyable value can be thrown.
2556#if GTEST_HAS_EXCEPTIONS
2557ACTION_P(Throw, exception) { throw exception; }
2558#endif // GTEST_HAS_EXCEPTIONS
2559
2560} // namespace testing
2561
shiqiane35fdd92008-12-10 05:08:54 +00002562#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_