Debian Codegraph @

external/gmock-1.7.0/gmock/gmock.h

raw symbols SCIP
1 // Copyright 2007, Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // Author: [email protected] (Zhanyong Wan)
31
32 // Google Mock - a framework for writing C++ mock classes.
33 //
34 // This is the main header file a user should include.
35
36 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_H_
37 #define GMOCK_INCLUDE_GMOCK_GMOCK_H_
38
39 // This file implements the following syntax:
40 //
41 // ON_CALL(mock_object.Method(...))
42 // .With(...) ?
43 // .WillByDefault(...);
44 //
45 // where With() is optional and WillByDefault() must appear exactly
46 // once.
47 //
48 // EXPECT_CALL(mock_object.Method(...))
49 // .With(...) ?
50 // .Times(...) ?
51 // .InSequence(...) *
52 // .WillOnce(...) *
53 // .WillRepeatedly(...) ?
54 // .RetiresOnSaturation() ? ;
55 //
56 // where all clauses are optional and WillOnce() can be repeated.
57
58 // Copyright 2007, Google Inc.
59 // All rights reserved.
60 //
61 // Redistribution and use in source and binary forms, with or without
62 // modification, are permitted provided that the following conditions are
63 // met:
64 //
65 // * Redistributions of source code must retain the above copyright
66 // notice, this list of conditions and the following disclaimer.
67 // * Redistributions in binary form must reproduce the above
68 // copyright notice, this list of conditions and the following disclaimer
69 // in the documentation and/or other materials provided with the
70 // distribution.
71 // * Neither the name of Google Inc. nor the names of its
72 // contributors may be used to endorse or promote products derived from
73 // this software without specific prior written permission.
74 //
75 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
76 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
77 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
78 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
79 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
80 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
81 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
82 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
83 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
84 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
85 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
86 //
87 // Author: [email protected] (Zhanyong Wan)
88
89 // Google Mock - a framework for writing C++ mock classes.
90 //
91 // This file implements some commonly used actions.
92
93 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
94 #define GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
95
96 #ifndef _WIN32_WCE
97 # include <errno.h>
98 #endif
99
100 #include <algorithm>
101 #include <string>
102
103 // Copyright 2007, Google Inc.
104 // All rights reserved.
105 //
106 // Redistribution and use in source and binary forms, with or without
107 // modification, are permitted provided that the following conditions are
108 // met:
109 //
110 // * Redistributions of source code must retain the above copyright
111 // notice, this list of conditions and the following disclaimer.
112 // * Redistributions in binary form must reproduce the above
113 // copyright notice, this list of conditions and the following disclaimer
114 // in the documentation and/or other materials provided with the
115 // distribution.
116 // * Neither the name of Google Inc. nor the names of its
117 // contributors may be used to endorse or promote products derived from
118 // this software without specific prior written permission.
119 //
120 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
121 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
122 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
123 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
124 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
125 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
126 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
127 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
128 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
129 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
130 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
131 //
132 // Author: [email protected] (Zhanyong Wan)
133
134 // Google Mock - a framework for writing C++ mock classes.
135 //
136 // This file defines some utilities useful for implementing Google
137 // Mock. They are subject to change without notice, so please DO NOT
138 // USE THEM IN USER CODE.
139
140 #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
141 #define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
142
143 #include <stdio.h>
144 #include <ostream> // NOLINT
145 #include <string>
146
147 // This file was GENERATED by command:
148 // pump.py gmock-generated-internal-utils.h.pump
149 // DO NOT EDIT BY HAND!!!
150
151 // Copyright 2007, Google Inc.
152 // All rights reserved.
153 //
154 // Redistribution and use in source and binary forms, with or without
155 // modification, are permitted provided that the following conditions are
156 // met:
157 //
158 // * Redistributions of source code must retain the above copyright
159 // notice, this list of conditions and the following disclaimer.
160 // * Redistributions in binary form must reproduce the above
161 // copyright notice, this list of conditions and the following disclaimer
162 // in the documentation and/or other materials provided with the
163 // distribution.
164 // * Neither the name of Google Inc. nor the names of its
165 // contributors may be used to endorse or promote products derived from
166 // this software without specific prior written permission.
167 //
168 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
169 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
170 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
171 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
172 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
173 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
174 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
175 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
176 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
177 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
178 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
179 //
180 // Author: [email protected] (Zhanyong Wan)
181
182 // Google Mock - a framework for writing C++ mock classes.
183 //
184 // This file contains template meta-programming utility classes needed
185 // for implementing Google Mock.
186
187 #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_
188 #define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_
189
190 // Copyright 2008, Google Inc.
191 // All rights reserved.
192 //
193 // Redistribution and use in source and binary forms, with or without
194 // modification, are permitted provided that the following conditions are
195 // met:
196 //
197 // * Redistributions of source code must retain the above copyright
198 // notice, this list of conditions and the following disclaimer.
199 // * Redistributions in binary form must reproduce the above
200 // copyright notice, this list of conditions and the following disclaimer
201 // in the documentation and/or other materials provided with the
202 // distribution.
203 // * Neither the name of Google Inc. nor the names of its
204 // contributors may be used to endorse or promote products derived from
205 // this software without specific prior written permission.
206 //
207 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
208 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
209 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
210 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
211 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
213 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
214 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
215 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
216 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
217 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
218 //
219 // Author: [email protected] (Vadim Berman)
220 //
221 // Low-level types and utilities for porting Google Mock to various
222 // platforms. They are subject to change without notice. DO NOT USE
223 // THEM IN USER CODE.
224
225 #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_
226 #define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_
227
228 #include <assert.h>
229 #include <stdlib.h>
230 #include <iostream>
231
232 // Most of the types needed for porting Google Mock are also required
233 // for Google Test and are defined in gtest-port.h.
234 #include "gtest/gtest.h"
235
236 // To avoid conditional compilation everywhere, we make it
237 // gmock-port.h's responsibility to #include the header implementing
238 // tr1/tuple. gmock-port.h does this via gtest-port.h, which is
239 // guaranteed to pull in the tuple header.
240
241 // For MS Visual C++, check the compiler version. At least VS 2003 is
242 // required to compile Google Mock.
243 #if defined(_MSC_VER) && _MSC_VER < 1310
244 # error "At least Visual C++ 2003 (7.1) is required to compile Google Mock."
245 #endif
246
247 // Macro for referencing flags. This is public as we want the user to
248 // use this syntax to reference Google Mock flags.
249 #define GMOCK_FLAG(name) FLAGS_gmock_##name
250
251 // Macros for declaring flags.
252 #define GMOCK_DECLARE_bool_(name) extern GTEST_API_ bool GMOCK_FLAG(name)
253 #define GMOCK_DECLARE_int32_(name) \
254 extern GTEST_API_ ::testing::internal::Int32 GMOCK_FLAG(name)
255 #define GMOCK_DECLARE_string_(name) \
256 extern GTEST_API_ ::std::string GMOCK_FLAG(name)
257
258 // Macros for defining flags.
259 #define GMOCK_DEFINE_bool_(name, default_val, doc) \
260 GTEST_API_ bool GMOCK_FLAG(name) = (default_val)
261 #define GMOCK_DEFINE_int32_(name, default_val, doc) \
262 GTEST_API_ ::testing::internal::Int32 GMOCK_FLAG(name) = (default_val)
263 #define GMOCK_DEFINE_string_(name, default_val, doc) \
264 GTEST_API_ ::std::string GMOCK_FLAG(name) = (default_val)
265
266 #endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_
267
268 namespace testing {
269
270 template <typename T>
271 class Matcher;
272
273 namespace internal {
274
275 // An IgnoredValue object can be implicitly constructed from ANY value.
276 // This is used in implementing the IgnoreResult(a) action.
277 class IgnoredValue {
278 public:
279 // This constructor template allows any value to be implicitly
280 // converted to IgnoredValue. The object has no data member and
281 // doesn't try to remember anything about the argument. We
282 // deliberately omit the 'explicit' keyword in order to allow the
283 // conversion to be implicit.
284 template <typename T>
285 IgnoredValue(const T& /* ignored */) {} // NOLINT(runtime/explicit)
286 };
287
288 // MatcherTuple<T>::type is a tuple type where each field is a Matcher
289 // for the corresponding field in tuple type T.
290 template <typename Tuple>
291 struct MatcherTuple;
292
293 template <>
294 struct MatcherTuple< ::std::tr1::tuple<> > {
295 typedef ::std::tr1::tuple< > type;
296 };
297
298 template <typename A1>
299 struct MatcherTuple< ::std::tr1::tuple<A1> > {
300 typedef ::std::tr1::tuple<Matcher<A1> > type;
301 };
302
303 template <typename A1, typename A2>
304 struct MatcherTuple< ::std::tr1::tuple<A1, A2> > {
305 typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2> > type;
306 };
307
308 template <typename A1, typename A2, typename A3>
309 struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3> > {
310 typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3> > type;
311 };
312
313 template <typename A1, typename A2, typename A3, typename A4>
314 struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3, A4> > {
315 typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>,
316 Matcher<A4> > type;
317 };
318
319 template <typename A1, typename A2, typename A3, typename A4, typename A5>
320 struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3, A4, A5> > {
321 typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
322 Matcher<A5> > type;
323 };
324
325 template <typename A1, typename A2, typename A3, typename A4, typename A5,
326 typename A6>
327 struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3, A4, A5, A6> > {
328 typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
329 Matcher<A5>, Matcher<A6> > type;
330 };
331
332 template <typename A1, typename A2, typename A3, typename A4, typename A5,
333 typename A6, typename A7>
334 struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7> > {
335 typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
336 Matcher<A5>, Matcher<A6>, Matcher<A7> > type;
337 };
338
339 template <typename A1, typename A2, typename A3, typename A4, typename A5,
340 typename A6, typename A7, typename A8>
341 struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8> > {
342 typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
343 Matcher<A5>, Matcher<A6>, Matcher<A7>, Matcher<A8> > type;
344 };
345
346 template <typename A1, typename A2, typename A3, typename A4, typename A5,
347 typename A6, typename A7, typename A8, typename A9>
348 struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9> > {
349 typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
350 Matcher<A5>, Matcher<A6>, Matcher<A7>, Matcher<A8>, Matcher<A9> > type;
351 };
352
353 template <typename A1, typename A2, typename A3, typename A4, typename A5,
354 typename A6, typename A7, typename A8, typename A9, typename A10>
355 struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9,
356 A10> > {
357 typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
358 Matcher<A5>, Matcher<A6>, Matcher<A7>, Matcher<A8>, Matcher<A9>,
359 Matcher<A10> > type;
360 };
361
362 // Template struct Function<F>, where F must be a function type, contains
363 // the following typedefs:
364 //
365 // Result: the function's return type.
366 // ArgumentN: the type of the N-th argument, where N starts with 1.
367 // ArgumentTuple: the tuple type consisting of all parameters of F.
368 // ArgumentMatcherTuple: the tuple type consisting of Matchers for all
369 // parameters of F.
370 // MakeResultVoid: the function type obtained by substituting void
371 // for the return type of F.
372 // MakeResultIgnoredValue:
373 // the function type obtained by substituting Something
374 // for the return type of F.
375 template <typename F>
376 struct Function;
377
378 template <typename R>
379 struct Function<R()> {
380 typedef R Result;
381 typedef ::std::tr1::tuple<> ArgumentTuple;
382 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
383 typedef void MakeResultVoid();
384 typedef IgnoredValue MakeResultIgnoredValue();
385 };
386
387 template <typename R, typename A1>
388 struct Function<R(A1)>
389 : Function<R()> {
390 typedef A1 Argument1;
391 typedef ::std::tr1::tuple<A1> ArgumentTuple;
392 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
393 typedef void MakeResultVoid(A1);
394 typedef IgnoredValue MakeResultIgnoredValue(A1);
395 };
396
397 template <typename R, typename A1, typename A2>
398 struct Function<R(A1, A2)>
399 : Function<R(A1)> {
400 typedef A2 Argument2;
401 typedef ::std::tr1::tuple<A1, A2> ArgumentTuple;
402 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
403 typedef void MakeResultVoid(A1, A2);
404 typedef IgnoredValue MakeResultIgnoredValue(A1, A2);
405 };
406
407 template <typename R, typename A1, typename A2, typename A3>
408 struct Function<R(A1, A2, A3)>
409 : Function<R(A1, A2)> {
410 typedef A3 Argument3;
411 typedef ::std::tr1::tuple<A1, A2, A3> ArgumentTuple;
412 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
413 typedef void MakeResultVoid(A1, A2, A3);
414 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3);
415 };
416
417 template <typename R, typename A1, typename A2, typename A3, typename A4>
418 struct Function<R(A1, A2, A3, A4)>
419 : Function<R(A1, A2, A3)> {
420 typedef A4 Argument4;
421 typedef ::std::tr1::tuple<A1, A2, A3, A4> ArgumentTuple;
422 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
423 typedef void MakeResultVoid(A1, A2, A3, A4);
424 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4);
425 };
426
427 template <typename R, typename A1, typename A2, typename A3, typename A4,
428 typename A5>
429 struct Function<R(A1, A2, A3, A4, A5)>
430 : Function<R(A1, A2, A3, A4)> {
431 typedef A5 Argument5;
432 typedef ::std::tr1::tuple<A1, A2, A3, A4, A5> ArgumentTuple;
433 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
434 typedef void MakeResultVoid(A1, A2, A3, A4, A5);
435 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5);
436 };
437
438 template <typename R, typename A1, typename A2, typename A3, typename A4,
439 typename A5, typename A6>
440 struct Function<R(A1, A2, A3, A4, A5, A6)>
441 : Function<R(A1, A2, A3, A4, A5)> {
442 typedef A6 Argument6;
443 typedef ::std::tr1::tuple<A1, A2, A3, A4, A5, A6> ArgumentTuple;
444 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
445 typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6);
446 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6);
447 };
448
449 template <typename R, typename A1, typename A2, typename A3, typename A4,
450 typename A5, typename A6, typename A7>
451 struct Function<R(A1, A2, A3, A4, A5, A6, A7)>
452 : Function<R(A1, A2, A3, A4, A5, A6)> {
453 typedef A7 Argument7;
454 typedef ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7> ArgumentTuple;
455 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
456 typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7);
457 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7);
458 };
459
460 template <typename R, typename A1, typename A2, typename A3, typename A4,
461 typename A5, typename A6, typename A7, typename A8>
462 struct Function<R(A1, A2, A3, A4, A5, A6, A7, A8)>
463 : Function<R(A1, A2, A3, A4, A5, A6, A7)> {
464 typedef A8 Argument8;
465 typedef ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8> ArgumentTuple;
466 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
467 typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7, A8);
468 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7, A8);
469 };
470
471 template <typename R, typename A1, typename A2, typename A3, typename A4,
472 typename A5, typename A6, typename A7, typename A8, typename A9>
473 struct Function<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)>
474 : Function<R(A1, A2, A3, A4, A5, A6, A7, A8)> {
475 typedef A9 Argument9;
476 typedef ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9> ArgumentTuple;
477 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
478 typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7, A8, A9);
479 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7, A8,
480 A9);
481 };
482
483 template <typename R, typename A1, typename A2, typename A3, typename A4,
484 typename A5, typename A6, typename A7, typename A8, typename A9,
485 typename A10>
486 struct Function<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)>
487 : Function<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> {
488 typedef A10 Argument10;
489 typedef ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9,
490 A10> ArgumentTuple;
491 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
492 typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10);
493 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7, A8,
494 A9, A10);
495 };
496
497 } // namespace internal
498
499 } // namespace testing
500
501 #endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_
502
503 namespace testing {
504 namespace internal {
505
506 // Converts an identifier name to a space-separated list of lower-case
507 // words. Each maximum substring of the form [A-Za-z][a-z]*|\d+ is
508 // treated as one word. For example, both "FooBar123" and
509 // "foo_bar_123" are converted to "foo bar 123".
510 GTEST_API_ string ConvertIdentifierNameToWords(const char* id_name);
511
512 // PointeeOf<Pointer>::type is the type of a value pointed to by a
513 // Pointer, which can be either a smart pointer or a raw pointer. The
514 // following default implementation is for the case where Pointer is a
515 // smart pointer.
516 template <typename Pointer>
517 struct PointeeOf {
518 // Smart pointer classes define type element_type as the type of
519 // their pointees.
520 typedef typename Pointer::element_type type;
521 };
522 // This specialization is for the raw pointer case.
523 template <typename T>
524 struct PointeeOf<T*> { typedef T type; }; // NOLINT
525
526 // GetRawPointer(p) returns the raw pointer underlying p when p is a
527 // smart pointer, or returns p itself when p is already a raw pointer.
528 // The following default implementation is for the smart pointer case.
529 template <typename Pointer>
530 inline const typename Pointer::element_type* GetRawPointer(const Pointer& p) {
531 return p.get();
532 }
533 // This overloaded version is for the raw pointer case.
534 template <typename Element>
535 inline Element* GetRawPointer(Element* p) { return p; }
536
537 // This comparator allows linked_ptr to be stored in sets.
538 template <typename T>
539 struct LinkedPtrLessThan {
540 bool operator()(const ::testing::internal::linked_ptr<T>& lhs,
541 const ::testing::internal::linked_ptr<T>& rhs) const {
542 return lhs.get() < rhs.get();
543 }
544 };
545
546 // Symbian compilation can be done with wchar_t being either a native
547 // type or a typedef. Using Google Mock with OpenC without wchar_t
548 // should require the definition of _STLP_NO_WCHAR_T.
549 //
550 // MSVC treats wchar_t as a native type usually, but treats it as the
551 // same as unsigned short when the compiler option /Zc:wchar_t- is
552 // specified. It defines _NATIVE_WCHAR_T_DEFINED symbol when wchar_t
553 // is a native type.
554 #if (GTEST_OS_SYMBIAN && defined(_STLP_NO_WCHAR_T)) || \
555 (defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED))
556 // wchar_t is a typedef.
557 #else
558 # define GMOCK_WCHAR_T_IS_NATIVE_ 1
559 #endif
560
561 // signed wchar_t and unsigned wchar_t are NOT in the C++ standard.
562 // Using them is a bad practice and not portable. So DON'T use them.
563 //
564 // Still, Google Mock is designed to work even if the user uses signed
565 // wchar_t or unsigned wchar_t (obviously, assuming the compiler
566 // supports them).
567 //
568 // To gcc,
569 // wchar_t == signed wchar_t != unsigned wchar_t == unsigned int
570 #ifdef __GNUC__
571 // signed/unsigned wchar_t are valid types.
572 # define GMOCK_HAS_SIGNED_WCHAR_T_ 1
573 #endif
574
575 // In what follows, we use the term "kind" to indicate whether a type
576 // is bool, an integer type (excluding bool), a floating-point type,
577 // or none of them. This categorization is useful for determining
578 // when a matcher argument type can be safely converted to another
579 // type in the implementation of SafeMatcherCast.
580 enum TypeKind {
581 kBool, kInteger, kFloatingPoint, kOther
582 };
583
584 // KindOf<T>::value is the kind of type T.
585 template <typename T> struct KindOf {
586 enum { value = kOther }; // The default kind.
587 };
588
589 // This macro declares that the kind of 'type' is 'kind'.
590 #define GMOCK_DECLARE_KIND_(type, kind) \
591 template <> struct KindOf<type> { enum { value = kind }; }
592
593 GMOCK_DECLARE_KIND_(bool, kBool);
594
595 // All standard integer types.
596 GMOCK_DECLARE_KIND_(char, kInteger);
597 GMOCK_DECLARE_KIND_(signed char, kInteger);
598 GMOCK_DECLARE_KIND_(unsigned char, kInteger);
599 GMOCK_DECLARE_KIND_(short, kInteger); // NOLINT
600 GMOCK_DECLARE_KIND_(unsigned short, kInteger); // NOLINT
601 GMOCK_DECLARE_KIND_(int, kInteger);
602 GMOCK_DECLARE_KIND_(unsigned int, kInteger);
603 GMOCK_DECLARE_KIND_(long, kInteger); // NOLINT
604 GMOCK_DECLARE_KIND_(unsigned long, kInteger); // NOLINT
605
606 #if GMOCK_WCHAR_T_IS_NATIVE_
607 GMOCK_DECLARE_KIND_(wchar_t, kInteger);
608 #endif
609
610 // Non-standard integer types.
611 GMOCK_DECLARE_KIND_(Int64, kInteger);
612 GMOCK_DECLARE_KIND_(UInt64, kInteger);
613
614 // All standard floating-point types.
615 GMOCK_DECLARE_KIND_(float, kFloatingPoint);
616 GMOCK_DECLARE_KIND_(double, kFloatingPoint);
617 GMOCK_DECLARE_KIND_(long double, kFloatingPoint);
618
619 #undef GMOCK_DECLARE_KIND_
620
621 // Evaluates to the kind of 'type'.
622 #define GMOCK_KIND_OF_(type) \
623 static_cast< ::testing::internal::TypeKind>( \
624 ::testing::internal::KindOf<type>::value)
625
626 // Evaluates to true iff integer type T is signed.
627 #define GMOCK_IS_SIGNED_(T) (static_cast<T>(-1) < 0)
628
629 // LosslessArithmeticConvertibleImpl<kFromKind, From, kToKind, To>::value
630 // is true iff arithmetic type From can be losslessly converted to
631 // arithmetic type To.
632 //
633 // It's the user's responsibility to ensure that both From and To are
634 // raw (i.e. has no CV modifier, is not a pointer, and is not a
635 // reference) built-in arithmetic types, kFromKind is the kind of
636 // From, and kToKind is the kind of To; the value is
637 // implementation-defined when the above pre-condition is violated.
638 template <TypeKind kFromKind, typename From, TypeKind kToKind, typename To>
639 struct LosslessArithmeticConvertibleImpl : public false_type {};
640
641 // Converting bool to bool is lossless.
642 template <>
643 struct LosslessArithmeticConvertibleImpl<kBool, bool, kBool, bool>
644 : public true_type {}; // NOLINT
645
646 // Converting bool to any integer type is lossless.
647 template <typename To>
648 struct LosslessArithmeticConvertibleImpl<kBool, bool, kInteger, To>
649 : public true_type {}; // NOLINT
650
651 // Converting bool to any floating-point type is lossless.
652 template <typename To>
653 struct LosslessArithmeticConvertibleImpl<kBool, bool, kFloatingPoint, To>
654 : public true_type {}; // NOLINT
655
656 // Converting an integer to bool is lossy.
657 template <typename From>
658 struct LosslessArithmeticConvertibleImpl<kInteger, From, kBool, bool>
659 : public false_type {}; // NOLINT
660
661 // Converting an integer to another non-bool integer is lossless iff
662 // the target type's range encloses the source type's range.
663 template <typename From, typename To>
664 struct LosslessArithmeticConvertibleImpl<kInteger, From, kInteger, To>
665 : public bool_constant<
666 // When converting from a smaller size to a larger size, we are
667 // fine as long as we are not converting from signed to unsigned.
668 ((sizeof(From) < sizeof(To)) &&
669 (!GMOCK_IS_SIGNED_(From) || GMOCK_IS_SIGNED_(To))) ||
670 // When converting between the same size, the signedness must match.
671 ((sizeof(From) == sizeof(To)) &&
672 (GMOCK_IS_SIGNED_(From) == GMOCK_IS_SIGNED_(To)))> {}; // NOLINT
673
674 #undef GMOCK_IS_SIGNED_
675
676 // Converting an integer to a floating-point type may be lossy, since
677 // the format of a floating-point number is implementation-defined.
678 template <typename From, typename To>
679 struct LosslessArithmeticConvertibleImpl<kInteger, From, kFloatingPoint, To>
680 : public false_type {}; // NOLINT
681
682 // Converting a floating-point to bool is lossy.
683 template <typename From>
684 struct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kBool, bool>
685 : public false_type {}; // NOLINT
686
687 // Converting a floating-point to an integer is lossy.
688 template <typename From, typename To>
689 struct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kInteger, To>
690 : public false_type {}; // NOLINT
691
692 // Converting a floating-point to another floating-point is lossless
693 // iff the target type is at least as big as the source type.
694 template <typename From, typename To>
695 struct LosslessArithmeticConvertibleImpl<
696 kFloatingPoint, From, kFloatingPoint, To>
697 : public bool_constant<sizeof(From) <= sizeof(To)> {}; // NOLINT
698
699 // LosslessArithmeticConvertible<From, To>::value is true iff arithmetic
700 // type From can be losslessly converted to arithmetic type To.
701 //
702 // It's the user's responsibility to ensure that both From and To are
703 // raw (i.e. has no CV modifier, is not a pointer, and is not a
704 // reference) built-in arithmetic types; the value is
705 // implementation-defined when the above pre-condition is violated.
706 template <typename From, typename To>
707 struct LosslessArithmeticConvertible
708 : public LosslessArithmeticConvertibleImpl<
709 GMOCK_KIND_OF_(From), From, GMOCK_KIND_OF_(To), To> {}; // NOLINT
710
711 // This interface knows how to report a Google Mock failure (either
712 // non-fatal or fatal).
713 class FailureReporterInterface {
714 public:
715 // The type of a failure (either non-fatal or fatal).
716 enum FailureType {
717 kNonfatal, kFatal
718 };
719
720 virtual ~FailureReporterInterface() {}
721
722 // Reports a failure that occurred at the given source file location.
723 virtual void ReportFailure(FailureType type, const char* file, int line,
724 const string& message) = 0;
725 };
726
727 // Returns the failure reporter used by Google Mock.
728 GTEST_API_ FailureReporterInterface* GetFailureReporter();
729
730 // Asserts that condition is true; aborts the process with the given
731 // message if condition is false. We cannot use LOG(FATAL) or CHECK()
732 // as Google Mock might be used to mock the log sink itself. We
733 // inline this function to prevent it from showing up in the stack
734 // trace.
735 inline void Assert(bool condition, const char* file, int line,
736 const string& msg) {
737 if (!condition) {
738 GetFailureReporter()->ReportFailure(FailureReporterInterface::kFatal,
739 file, line, msg);
740 }
741 }
742 inline void Assert(bool condition, const char* file, int line) {
743 Assert(condition, file, line, "Assertion failed.");
744 }
745
746 // Verifies that condition is true; generates a non-fatal failure if
747 // condition is false.
748 inline void Expect(bool condition, const char* file, int line,
749 const string& msg) {
750 if (!condition) {
751 GetFailureReporter()->ReportFailure(FailureReporterInterface::kNonfatal,
752 file, line, msg);
753 }
754 }
755 inline void Expect(bool condition, const char* file, int line) {
756 Expect(condition, file, line, "Expectation failed.");
757 }
758
759 // Severity level of a log.
760 enum LogSeverity {
761 kInfo = 0,
762 kWarning = 1
763 };
764
765 // Valid values for the --gmock_verbose flag.
766
767 // All logs (informational and warnings) are printed.
768 const char kInfoVerbosity[] = "info";
769 // Only warnings are printed.
770 const char kWarningVerbosity[] = "warning";
771 // No logs are printed.
772 const char kErrorVerbosity[] = "error";
773
774 // Returns true iff a log with the given severity is visible according
775 // to the --gmock_verbose flag.
776 GTEST_API_ bool LogIsVisible(LogSeverity severity);
777
778 // Prints the given message to stdout iff 'severity' >= the level
779 // specified by the --gmock_verbose flag. If stack_frames_to_skip >=
780 // 0, also prints the stack trace excluding the top
781 // stack_frames_to_skip frames. In opt mode, any positive
782 // stack_frames_to_skip is treated as 0, since we don't know which
783 // function calls will be inlined by the compiler and need to be
784 // conservative.
785 GTEST_API_ void Log(LogSeverity severity,
786 const string& message,
787 int stack_frames_to_skip);
788
789 // TODO([email protected]): group all type utilities together.
790
791 // Type traits.
792
793 // is_reference<T>::value is non-zero iff T is a reference type.
794 template <typename T> struct is_reference : public false_type {};
795 template <typename T> struct is_reference<T&> : public true_type {};
796
797 // type_equals<T1, T2>::value is non-zero iff T1 and T2 are the same type.
798 template <typename T1, typename T2> struct type_equals : public false_type {};
799 template <typename T> struct type_equals<T, T> : public true_type {};
800
801 // remove_reference<T>::type removes the reference from type T, if any.
802 template <typename T> struct remove_reference { typedef T type; }; // NOLINT
803 template <typename T> struct remove_reference<T&> { typedef T type; }; // NOLINT
804
805 // DecayArray<T>::type turns an array type U[N] to const U* and preserves
806 // other types. Useful for saving a copy of a function argument.
807 template <typename T> struct DecayArray { typedef T type; }; // NOLINT
808 template <typename T, size_t N> struct DecayArray<T[N]> {
809 typedef const T* type;
810 };
811 // Sometimes people use arrays whose size is not available at the use site
812 // (e.g. extern const char kNamePrefix[]). This specialization covers that
813 // case.
814 template <typename T> struct DecayArray<T[]> {
815 typedef const T* type;
816 };
817
818 // Invalid<T>() returns an invalid value of type T. This is useful
819 // when a value of type T is needed for compilation, but the statement
820 // will not really be executed (or we don't care if the statement
821 // crashes).
822 template <typename T>
823 inline T Invalid() {
824 return const_cast<typename remove_reference<T>::type&>(
825 *static_cast<volatile typename remove_reference<T>::type*>(NULL));
826 }
827 template <>
828 inline void Invalid<void>() {}
829
830 // Given a raw type (i.e. having no top-level reference or const
831 // modifier) RawContainer that's either an STL-style container or a
832 // native array, class StlContainerView<RawContainer> has the
833 // following members:
834 //
835 // - type is a type that provides an STL-style container view to
836 // (i.e. implements the STL container concept for) RawContainer;
837 // - const_reference is a type that provides a reference to a const
838 // RawContainer;
839 // - ConstReference(raw_container) returns a const reference to an STL-style
840 // container view to raw_container, which is a RawContainer.
841 // - Copy(raw_container) returns an STL-style container view of a
842 // copy of raw_container, which is a RawContainer.
843 //
844 // This generic version is used when RawContainer itself is already an
845 // STL-style container.
846 template <class RawContainer>
847 class StlContainerView {
848 public:
849 typedef RawContainer type;
850 typedef const type& const_reference;
851
852 static const_reference ConstReference(const RawContainer& container) {
853 // Ensures that RawContainer is not a const type.
854 testing::StaticAssertTypeEq<RawContainer,
855 GTEST_REMOVE_CONST_(RawContainer)>();
856 return container;
857 }
858 static type Copy(const RawContainer& container) { return container; }
859 };
860
861 // This specialization is used when RawContainer is a native array type.
862 template <typename Element, size_t N>
863 class StlContainerView<Element[N]> {
864 public:
865 typedef GTEST_REMOVE_CONST_(Element) RawElement;
866 typedef internal::NativeArray<RawElement> type;
867 // NativeArray<T> can represent a native array either by value or by
868 // reference (selected by a constructor argument), so 'const type'
869 // can be used to reference a const native array. We cannot
870 // 'typedef const type& const_reference' here, as that would mean
871 // ConstReference() has to return a reference to a local variable.
872 typedef const type const_reference;
873
874 static const_reference ConstReference(const Element (&array)[N]) {
875 // Ensures that Element is not a const type.
876 testing::StaticAssertTypeEq<Element, RawElement>();
877 #if GTEST_OS_SYMBIAN
878 // The Nokia Symbian compiler confuses itself in template instantiation
879 // for this call without the cast to Element*:
880 // function call '[testing::internal::NativeArray<char *>].NativeArray(
881 // {lval} const char *[4], long, testing::internal::RelationToSource)'
882 // does not match
883 // 'testing::internal::NativeArray<char *>::NativeArray(
884 // char *const *, unsigned int, testing::internal::RelationToSource)'
885 // (instantiating: 'testing::internal::ContainsMatcherImpl
886 // <const char * (&)[4]>::Matches(const char * (&)[4]) const')
887 // (instantiating: 'testing::internal::StlContainerView<char *[4]>::
888 // ConstReference(const char * (&)[4])')
889 // (and though the N parameter type is mismatched in the above explicit
890 // conversion of it doesn't help - only the conversion of the array).
891 return type(const_cast<Element*>(&array[0]), N, kReference);
892 #else
893 return type(array, N, kReference);
894 #endif // GTEST_OS_SYMBIAN
895 }
896 static type Copy(const Element (&array)[N]) {
897 #if GTEST_OS_SYMBIAN
898 return type(const_cast<Element*>(&array[0]), N, kCopy);
899 #else
900 return type(array, N, kCopy);
901 #endif // GTEST_OS_SYMBIAN
902 }
903 };
904
905 // This specialization is used when RawContainer is a native array
906 // represented as a (pointer, size) tuple.
907 template <typename ElementPointer, typename Size>
908 class StlContainerView< ::std::tr1::tuple<ElementPointer, Size> > {
909 public:
910 typedef GTEST_REMOVE_CONST_(
911 typename internal::PointeeOf<ElementPointer>::type) RawElement;
912 typedef internal::NativeArray<RawElement> type;
913 typedef const type const_reference;
914
915 static const_reference ConstReference(
916 const ::std::tr1::tuple<ElementPointer, Size>& array) {
917 using ::std::tr1::get;
918 return type(get<0>(array), get<1>(array), kReference);
919 }
920 static type Copy(const ::std::tr1::tuple<ElementPointer, Size>& array) {
921 using ::std::tr1::get;
922 return type(get<0>(array), get<1>(array), kCopy);
923 }
924 };
925
926 // The following specialization prevents the user from instantiating
927 // StlContainer with a reference type.
928 template <typename T> class StlContainerView<T&>;
929
930 // A type transform to remove constness from the first part of a pair.
931 // Pairs like that are used as the value_type of associative containers,
932 // and this transform produces a similar but assignable pair.
933 template <typename T>
934 struct RemoveConstFromKey {
935 typedef T type;
936 };
937
938 // Partially specialized to remove constness from std::pair<const K, V>.
939 template <typename K, typename V>
940 struct RemoveConstFromKey<std::pair<const K, V> > {
941 typedef std::pair<K, V> type;
942 };
943
944 // Mapping from booleans to types. Similar to boost::bool_<kValue> and
945 // std::integral_constant<bool, kValue>.
946 template <bool kValue>
947 struct BooleanConstant {};
948
949 } // namespace internal
950 } // namespace testing
951
952 #endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
953
954 namespace testing {
955
956 // To implement an action Foo, define:
957 // 1. a class FooAction that implements the ActionInterface interface, and
958 // 2. a factory function that creates an Action object from a
959 // const FooAction*.
960 //
961 // The two-level delegation design follows that of Matcher, providing
962 // consistency for extension developers. It also eases ownership
963 // management as Action objects can now be copied like plain values.
964
965 namespace internal {
966
967 template <typename F1, typename F2>
968 class ActionAdaptor;
969
970 // BuiltInDefaultValue<T>::Get() returns the "built-in" default
971 // value for type T, which is NULL when T is a pointer type, 0 when T
972 // is a numeric type, false when T is bool, or "" when T is string or
973 // std::string. For any other type T, this value is undefined and the
974 // function will abort the process.
975 template <typename T>
976 class BuiltInDefaultValue {
977 public:
978 // This function returns true iff type T has a built-in default value.
979 static bool Exists() { return false; }
980 static T Get() {
981 Assert(false, __FILE__, __LINE__,
982 "Default action undefined for the function return type.");
983 return internal::Invalid<T>();
984 // The above statement will never be reached, but is required in
985 // order for this function to compile.
986 }
987 };
988
989 // This partial specialization says that we use the same built-in
990 // default value for T and const T.
991 template <typename T>
992 class BuiltInDefaultValue<const T> {
993 public:
994 static bool Exists() { return BuiltInDefaultValue<T>::Exists(); }
995 static T Get() { return BuiltInDefaultValue<T>::Get(); }
996 };
997
998 // This partial specialization defines the default values for pointer
999 // types.
1000 template <typename T>
1001 class BuiltInDefaultValue<T*> {
1002 public:
1003 static bool Exists() { return true; }
1004 static T* Get() { return NULL; }
1005 };
1006
1007 // The following specializations define the default values for
1008 // specific types we care about.
1009 #define GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(type, value) \
1010 template <> \
1011 class BuiltInDefaultValue<type> { \
1012 public: \
1013 static bool Exists() { return true; } \
1014 static type Get() { return value; } \
1015 }
1016
1017 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(void, ); // NOLINT
1018 #if GTEST_HAS_GLOBAL_STRING
1019 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(::string, "");
1020 #endif // GTEST_HAS_GLOBAL_STRING
1021 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(::std::string, "");
1022 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(bool, false);
1023 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned char, '\0');
1024 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed char, '\0');
1025 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(char, '\0');
1026
1027 // There's no need for a default action for signed wchar_t, as that
1028 // type is the same as wchar_t for gcc, and invalid for MSVC.
1029 //
1030 // There's also no need for a default action for unsigned wchar_t, as
1031 // that type is the same as unsigned int for gcc, and invalid for
1032 // MSVC.
1033 #if GMOCK_WCHAR_T_IS_NATIVE_
1034 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(wchar_t, 0U); // NOLINT
1035 #endif
1036
1037 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned short, 0U); // NOLINT
1038 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed short, 0); // NOLINT
1039 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned int, 0U);
1040 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed int, 0);
1041 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned long, 0UL); // NOLINT
1042 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed long, 0L); // NOLINT
1043 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(UInt64, 0);
1044 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(Int64, 0);
1045 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(float, 0);
1046 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(double, 0);
1047
1048 #undef GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_
1049
1050 } // namespace internal
1051
1052 // When an unexpected function call is encountered, Google Mock will
1053 // let it return a default value if the user has specified one for its
1054 // return type, or if the return type has a built-in default value;
1055 // otherwise Google Mock won't know what value to return and will have
1056 // to abort the process.
1057 //
1058 // The DefaultValue<T> class allows a user to specify the
1059 // default value for a type T that is both copyable and publicly
1060 // destructible (i.e. anything that can be used as a function return
1061 // type). The usage is:
1062 //
1063 // // Sets the default value for type T to be foo.
1064 // DefaultValue<T>::Set(foo);
1065 template <typename T>
1066 class DefaultValue {
1067 public:
1068 // Sets the default value for type T; requires T to be
1069 // copy-constructable and have a public destructor.
1070 static void Set(T x) {
1071 delete value_;
1072 value_ = new T(x);
1073 }
1074
1075 // Unsets the default value for type T.
1076 static void Clear() {
1077 delete value_;
1078 value_ = NULL;
1079 }
1080
1081 // Returns true iff the user has set the default value for type T.
1082 static bool IsSet() { return value_ != NULL; }
1083
1084 // Returns true if T has a default return value set by the user or there
1085 // exists a built-in default value.
1086 static bool Exists() {
1087 return IsSet() || internal::BuiltInDefaultValue<T>::Exists();
1088 }
1089
1090 // Returns the default value for type T if the user has set one;
1091 // otherwise returns the built-in default value if there is one;
1092 // otherwise aborts the process.
1093 static T Get() {
1094 return value_ == NULL ?
1095 internal::BuiltInDefaultValue<T>::Get() : *value_;
1096 }
1097
1098 private:
1099 static const T* value_;
1100 };
1101
1102 // This partial specialization allows a user to set default values for
1103 // reference types.
1104 template <typename T>
1105 class DefaultValue<T&> {
1106 public:
1107 // Sets the default value for type T&.
1108 static void Set(T& x) { // NOLINT
1109 address_ = &x;
1110 }
1111
1112 // Unsets the default value for type T&.
1113 static void Clear() {
1114 address_ = NULL;
1115 }
1116
1117 // Returns true iff the user has set the default value for type T&.
1118 static bool IsSet() { return address_ != NULL; }
1119
1120 // Returns true if T has a default return value set by the user or there
1121 // exists a built-in default value.
1122 static bool Exists() {
1123 return IsSet() || internal::BuiltInDefaultValue<T&>::Exists();
1124 }
1125
1126 // Returns the default value for type T& if the user has set one;
1127 // otherwise returns the built-in default value if there is one;
1128 // otherwise aborts the process.
1129 static T& Get() {
1130 return address_ == NULL ?
1131 internal::BuiltInDefaultValue<T&>::Get() : *address_;
1132 }
1133
1134 private:
1135 static T* address_;
1136 };
1137
1138 // This specialization allows DefaultValue<void>::Get() to
1139 // compile.
1140 template <>
1141 class DefaultValue<void> {
1142 public:
1143 static bool Exists() { return true; }
1144 static void Get() {}
1145 };
1146
1147 // Points to the user-set default value for type T.
1148 template <typename T>
1149 const T* DefaultValue<T>::value_ = NULL;
1150
1151 // Points to the user-set default value for type T&.
1152 template <typename T>
1153 T* DefaultValue<T&>::address_ = NULL;
1154
1155 // Implement this interface to define an action for function type F.
1156 template <typename F>
1157 class ActionInterface {
1158 public:
1159 typedef typename internal::Function<F>::Result Result;
1160 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
1161
1162 ActionInterface() {}
1163 virtual ~ActionInterface() {}
1164
1165 // Performs the action. This method is not const, as in general an
1166 // action can have side effects and be stateful. For example, a
1167 // get-the-next-element-from-the-collection action will need to
1168 // remember the current element.
1169 virtual Result Perform(const ArgumentTuple& args) = 0;
1170
1171 private:
1172 GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionInterface);
1173 };
1174
1175 // An Action<F> is a copyable and IMMUTABLE (except by assignment)
1176 // object that represents an action to be taken when a mock function
1177 // of type F is called. The implementation of Action<T> is just a
1178 // linked_ptr to const ActionInterface<T>, so copying is fairly cheap.
1179 // Don't inherit from Action!
1180 //
1181 // You can view an object implementing ActionInterface<F> as a
1182 // concrete action (including its current state), and an Action<F>
1183 // object as a handle to it.
1184 template <typename F>
1185 class Action {
1186 public:
1187 typedef typename internal::Function<F>::Result Result;
1188 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
1189
1190 // Constructs a null Action. Needed for storing Action objects in
1191 // STL containers.
1192 Action() : impl_(NULL) {}
1193
1194 // Constructs an Action from its implementation. A NULL impl is
1195 // used to represent the "do-default" action.
1196 explicit Action(ActionInterface<F>* impl) : impl_(impl) {}
1197
1198 // Copy constructor.
1199 Action(const Action& action) : impl_(action.impl_) {}
1200
1201 // This constructor allows us to turn an Action<Func> object into an
1202 // Action<F>, as long as F's arguments can be implicitly converted
1203 // to Func's and Func's return type can be implicitly converted to
1204 // F's.
1205 template <typename Func>
1206 explicit Action(const Action<Func>& action);
1207
1208 // Returns true iff this is the DoDefault() action.
1209 bool IsDoDefault() const { return impl_.get() == NULL; }
1210
1211 // Performs the action. Note that this method is const even though
1212 // the corresponding method in ActionInterface is not. The reason
1213 // is that a const Action<F> means that it cannot be re-bound to
1214 // another concrete action, not that the concrete action it binds to
1215 // cannot change state. (Think of the difference between a const
1216 // pointer and a pointer to const.)
1217 Result Perform(const ArgumentTuple& args) const {
1218 internal::Assert(
1219 !IsDoDefault(), __FILE__, __LINE__,
1220 "You are using DoDefault() inside a composite action like "
1221 "DoAll() or WithArgs(). This is not supported for technical "
1222 "reasons. Please instead spell out the default action, or "
1223 "assign the default action to an Action variable and use "
1224 "the variable in various places.");
1225 return impl_->Perform(args);
1226 }
1227
1228 private:
1229 template <typename F1, typename F2>
1230 friend class internal::ActionAdaptor;
1231
1232 internal::linked_ptr<ActionInterface<F> > impl_;
1233 };
1234
1235 // The PolymorphicAction class template makes it easy to implement a
1236 // polymorphic action (i.e. an action that can be used in mock
1237 // functions of than one type, e.g. Return()).
1238 //
1239 // To define a polymorphic action, a user first provides a COPYABLE
1240 // implementation class that has a Perform() method template:
1241 //
1242 // class FooAction {
1243 // public:
1244 // template <typename Result, typename ArgumentTuple>
1245 // Result Perform(const ArgumentTuple& args) const {
1246 // // Processes the arguments and returns a result, using
1247 // // tr1::get<N>(args) to get the N-th (0-based) argument in the tuple.
1248 // }
1249 // ...
1250 // };
1251 //
1252 // Then the user creates the polymorphic action using
1253 // MakePolymorphicAction(object) where object has type FooAction. See
1254 // the definition of Return(void) and SetArgumentPointee<N>(value) for
1255 // complete examples.
1256 template <typename Impl>
1257 class PolymorphicAction {
1258 public:
1259 explicit PolymorphicAction(const Impl& impl) : impl_(impl) {}
1260
1261 template <typename F>
1262 operator Action<F>() const {
1263 return Action<F>(new MonomorphicImpl<F>(impl_));
1264 }
1265
1266 private:
1267 template <typename F>
1268 class MonomorphicImpl : public ActionInterface<F> {
1269 public:
1270 typedef typename internal::Function<F>::Result Result;
1271 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
1272
1273 explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {}
1274
1275 virtual Result Perform(const ArgumentTuple& args) {
1276 return impl_.template Perform<Result>(args);
1277 }
1278
1279 private:
1280 Impl impl_;
1281
1282 GTEST_DISALLOW_ASSIGN_(MonomorphicImpl);
1283 };
1284
1285 Impl impl_;
1286
1287 GTEST_DISALLOW_ASSIGN_(PolymorphicAction);
1288 };
1289
1290 // Creates an Action from its implementation and returns it. The
1291 // created Action object owns the implementation.
1292 template <typename F>
1293 Action<F> MakeAction(ActionInterface<F>* impl) {
1294 return Action<F>(impl);
1295 }
1296
1297 // Creates a polymorphic action from its implementation. This is
1298 // easier to use than the PolymorphicAction<Impl> constructor as it
1299 // doesn't require you to explicitly write the template argument, e.g.
1300 //
1301 // MakePolymorphicAction(foo);
1302 // vs
1303 // PolymorphicAction<TypeOfFoo>(foo);
1304 template <typename Impl>
1305 inline PolymorphicAction<Impl> MakePolymorphicAction(const Impl& impl) {
1306 return PolymorphicAction<Impl>(impl);
1307 }
1308
1309 namespace internal {
1310
1311 // Allows an Action<F2> object to pose as an Action<F1>, as long as F2
1312 // and F1 are compatible.
1313 template <typename F1, typename F2>
1314 class ActionAdaptor : public ActionInterface<F1> {
1315 public:
1316 typedef typename internal::Function<F1>::Result Result;
1317 typedef typename internal::Function<F1>::ArgumentTuple ArgumentTuple;
1318
1319 explicit ActionAdaptor(const Action<F2>& from) : impl_(from.impl_) {}
1320
1321 virtual Result Perform(const ArgumentTuple& args) {
1322 return impl_->Perform(args);
1323 }
1324
1325 private:
1326 const internal::linked_ptr<ActionInterface<F2> > impl_;
1327
1328 GTEST_DISALLOW_ASSIGN_(ActionAdaptor);
1329 };
1330
1331 // Implements the polymorphic Return(x) action, which can be used in
1332 // any function that returns the type of x, regardless of the argument
1333 // types.
1334 //
1335 // Note: The value passed into Return must be converted into
1336 // Function<F>::Result when this action is cast to Action<F> rather than
1337 // when that action is performed. This is important in scenarios like
1338 //
1339 // MOCK_METHOD1(Method, T(U));
1340 // ...
1341 // {
1342 // Foo foo;
1343 // X x(&foo);
1344 // EXPECT_CALL(mock, Method(_)).WillOnce(Return(x));
1345 // }
1346 //
1347 // In the example above the variable x holds reference to foo which leaves
1348 // scope and gets destroyed. If copying X just copies a reference to foo,
1349 // that copy will be left with a hanging reference. If conversion to T
1350 // makes a copy of foo, the above code is safe. To support that scenario, we
1351 // need to make sure that the type conversion happens inside the EXPECT_CALL
1352 // statement, and conversion of the result of Return to Action<T(U)> is a
1353 // good place for that.
1354 //
1355 template <typename R>
1356 class ReturnAction {
1357 public:
1358 // Constructs a ReturnAction object from the value to be returned.
1359 // 'value' is passed by value instead of by const reference in order
1360 // to allow Return("string literal") to compile.
1361 explicit ReturnAction(R value) : value_(value) {}
1362
1363 // This template type conversion operator allows Return(x) to be
1364 // used in ANY function that returns x's type.
1365 template <typename F>
1366 operator Action<F>() const {
1367 // Assert statement belongs here because this is the best place to verify
1368 // conditions on F. It produces the clearest error messages
1369 // in most compilers.
1370 // Impl really belongs in this scope as a local class but can't
1371 // because MSVC produces duplicate symbols in different translation units
1372 // in this case. Until MS fixes that bug we put Impl into the class scope
1373 // and put the typedef both here (for use in assert statement) and
1374 // in the Impl class. But both definitions must be the same.
1375 typedef typename Function<F>::Result Result;
1376 GTEST_COMPILE_ASSERT_(
1377 !internal::is_reference<Result>::value,
1378 use_ReturnRef_instead_of_Return_to_return_a_reference);
1379 return Action<F>(new Impl<F>(value_));
1380 }
1381
1382 private:
1383 // Implements the Return(x) action for a particular function type F.
1384 template <typename F>
1385 class Impl : public ActionInterface<F> {
1386 public:
1387 typedef typename Function<F>::Result Result;
1388 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
1389
1390 // The implicit cast is necessary when Result has more than one
1391 // single-argument constructor (e.g. Result is std::vector<int>) and R
1392 // has a type conversion operator template. In that case, value_(value)
1393 // won't compile as the compiler doesn't known which constructor of
1394 // Result to call. ImplicitCast_ forces the compiler to convert R to
1395 // Result without considering explicit constructors, thus resolving the
1396 // ambiguity. value_ is then initialized using its copy constructor.
1397 explicit Impl(R value)
1398 : value_(::testing::internal::ImplicitCast_<Result>(value)) {}
1399
1400 virtual Result Perform(const ArgumentTuple&) { return value_; }
1401
1402 private:
1403 GTEST_COMPILE_ASSERT_(!internal::is_reference<Result>::value,
1404 Result_cannot_be_a_reference_type);
1405 Result value_;
1406
1407 GTEST_DISALLOW_ASSIGN_(Impl);
1408 };
1409
1410 R value_;
1411
1412 GTEST_DISALLOW_ASSIGN_(ReturnAction);
1413 };
1414
1415 // Implements the ReturnNull() action.
1416 class ReturnNullAction {
1417 public:
1418 // Allows ReturnNull() to be used in any pointer-returning function.
1419 template <typename Result, typename ArgumentTuple>
1420 static Result Perform(const ArgumentTuple&) {
1421 GTEST_COMPILE_ASSERT_(internal::is_pointer<Result>::value,
1422 ReturnNull_can_be_used_to_return_a_pointer_only);
1423 return NULL;
1424 }
1425 };
1426
1427 // Implements the Return() action.
1428 class ReturnVoidAction {
1429 public:
1430 // Allows Return() to be used in any void-returning function.
1431 template <typename Result, typename ArgumentTuple>
1432 static void Perform(const ArgumentTuple&) {
1433 CompileAssertTypesEqual<void, Result>();
1434 }
1435 };
1436
1437 // Implements the polymorphic ReturnRef(x) action, which can be used
1438 // in any function that returns a reference to the type of x,
1439 // regardless of the argument types.
1440 template <typename T>
1441 class ReturnRefAction {
1442 public:
1443 // Constructs a ReturnRefAction object from the reference to be returned.
1444 explicit ReturnRefAction(T& ref) : ref_(ref) {} // NOLINT
1445
1446 // This template type conversion operator allows ReturnRef(x) to be
1447 // used in ANY function that returns a reference to x's type.
1448 template <typename F>
1449 operator Action<F>() const {
1450 typedef typename Function<F>::Result Result;
1451 // Asserts that the function return type is a reference. This
1452 // catches the user error of using ReturnRef(x) when Return(x)
1453 // should be used, and generates some helpful error message.
1454 GTEST_COMPILE_ASSERT_(internal::is_reference<Result>::value,
1455 use_Return_instead_of_ReturnRef_to_return_a_value);
1456 return Action<F>(new Impl<F>(ref_));
1457 }
1458
1459 private:
1460 // Implements the ReturnRef(x) action for a particular function type F.
1461 template <typename F>
1462 class Impl : public ActionInterface<F> {
1463 public:
1464 typedef typename Function<F>::Result Result;
1465 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
1466
1467 explicit Impl(T& ref) : ref_(ref) {} // NOLINT
1468
1469 virtual Result Perform(const ArgumentTuple&) {
1470 return ref_;
1471 }
1472
1473 private:
1474 T& ref_;
1475
1476 GTEST_DISALLOW_ASSIGN_(Impl);
1477 };
1478
1479 T& ref_;
1480
1481 GTEST_DISALLOW_ASSIGN_(ReturnRefAction);
1482 };
1483
1484 // Implements the polymorphic ReturnRefOfCopy(x) action, which can be
1485 // used in any function that returns a reference to the type of x,
1486 // regardless of the argument types.
1487 template <typename T>
1488 class ReturnRefOfCopyAction {
1489 public:
1490 // Constructs a ReturnRefOfCopyAction object from the reference to
1491 // be returned.
1492 explicit ReturnRefOfCopyAction(const T& value) : value_(value) {} // NOLINT
1493
1494 // This template type conversion operator allows ReturnRefOfCopy(x) to be
1495 // used in ANY function that returns a reference to x's type.
1496 template <typename F>
1497 operator Action<F>() const {
1498 typedef typename Function<F>::Result Result;
1499 // Asserts that the function return type is a reference. This
1500 // catches the user error of using ReturnRefOfCopy(x) when Return(x)
1501 // should be used, and generates some helpful error message.
1502 GTEST_COMPILE_ASSERT_(
1503 internal::is_reference<Result>::value,
1504 use_Return_instead_of_ReturnRefOfCopy_to_return_a_value);
1505 return Action<F>(new Impl<F>(value_));
1506 }
1507
1508 private:
1509 // Implements the ReturnRefOfCopy(x) action for a particular function type F.
1510 template <typename F>
1511 class Impl : public ActionInterface<F> {
1512 public:
1513 typedef typename Function<F>::Result Result;
1514 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
1515
1516 explicit Impl(const T& value) : value_(value) {} // NOLINT
1517
1518 virtual Result Perform(const ArgumentTuple&) {
1519 return value_;
1520 }
1521
1522 private:
1523 T value_;
1524
1525 GTEST_DISALLOW_ASSIGN_(Impl);
1526 };
1527
1528 const T value_;
1529
1530 GTEST_DISALLOW_ASSIGN_(ReturnRefOfCopyAction);
1531 };
1532
1533 // Implements the polymorphic DoDefault() action.
1534 class DoDefaultAction {
1535 public:
1536 // This template type conversion operator allows DoDefault() to be
1537 // used in any function.
1538 template <typename F>
1539 operator Action<F>() const { return Action<F>(NULL); }
1540 };
1541
1542 // Implements the Assign action to set a given pointer referent to a
1543 // particular value.
1544 template <typename T1, typename T2>
1545 class AssignAction {
1546 public:
1547 AssignAction(T1* ptr, T2 value) : ptr_(ptr), value_(value) {}
1548
1549 template <typename Result, typename ArgumentTuple>
1550 void Perform(const ArgumentTuple& /* args */) const {
1551 *ptr_ = value_;
1552 }
1553
1554 private:
1555 T1* const ptr_;
1556 const T2 value_;
1557
1558 GTEST_DISALLOW_ASSIGN_(AssignAction);
1559 };
1560
1561 #if !GTEST_OS_WINDOWS_MOBILE
1562
1563 // Implements the SetErrnoAndReturn action to simulate return from
1564 // various system calls and libc functions.
1565 template <typename T>
1566 class SetErrnoAndReturnAction {
1567 public:
1568 SetErrnoAndReturnAction(int errno_value, T result)
1569 : errno_(errno_value),
1570 result_(result) {}
1571 template <typename Result, typename ArgumentTuple>
1572 Result Perform(const ArgumentTuple& /* args */) const {
1573 errno = errno_;
1574 return result_;
1575 }
1576
1577 private:
1578 const int errno_;
1579 const T result_;
1580
1581 GTEST_DISALLOW_ASSIGN_(SetErrnoAndReturnAction);
1582 };
1583
1584 #endif // !GTEST_OS_WINDOWS_MOBILE
1585
1586 // Implements the SetArgumentPointee<N>(x) action for any function
1587 // whose N-th argument (0-based) is a pointer to x's type. The
1588 // template parameter kIsProto is true iff type A is ProtocolMessage,
1589 // proto2::Message, or a sub-class of those.
1590 template <size_t N, typename A, bool kIsProto>
1591 class SetArgumentPointeeAction {
1592 public:
1593 // Constructs an action that sets the variable pointed to by the
1594 // N-th function argument to 'value'.
1595 explicit SetArgumentPointeeAction(const A& value) : value_(value) {}
1596
1597 template <typename Result, typename ArgumentTuple>
1598 void Perform(const ArgumentTuple& args) const {
1599 CompileAssertTypesEqual<void, Result>();
1600 *::std::tr1::get<N>(args) = value_;
1601 }
1602
1603 private:
1604 const A value_;
1605
1606 GTEST_DISALLOW_ASSIGN_(SetArgumentPointeeAction);
1607 };
1608
1609 template <size_t N, typename Proto>
1610 class SetArgumentPointeeAction<N, Proto, true> {
1611 public:
1612 // Constructs an action that sets the variable pointed to by the
1613 // N-th function argument to 'proto'. Both ProtocolMessage and
1614 // proto2::Message have the CopyFrom() method, so the same
1615 // implementation works for both.
1616 explicit SetArgumentPointeeAction(const Proto& proto) : proto_(new Proto) {
1617 proto_->CopyFrom(proto);
1618 }
1619
1620 template <typename Result, typename ArgumentTuple>
1621 void Perform(const ArgumentTuple& args) const {
1622 CompileAssertTypesEqual<void, Result>();
1623 ::std::tr1::get<N>(args)->CopyFrom(*proto_);
1624 }
1625
1626 private:
1627 const internal::linked_ptr<Proto> proto_;
1628
1629 GTEST_DISALLOW_ASSIGN_(SetArgumentPointeeAction);
1630 };
1631
1632 // Implements the InvokeWithoutArgs(f) action. The template argument
1633 // FunctionImpl is the implementation type of f, which can be either a
1634 // function pointer or a functor. InvokeWithoutArgs(f) can be used as an
1635 // Action<F> as long as f's type is compatible with F (i.e. f can be
1636 // assigned to a tr1::function<F>).
1637 template <typename FunctionImpl>
1638 class InvokeWithoutArgsAction {
1639 public:
1640 // The c'tor makes a copy of function_impl (either a function
1641 // pointer or a functor).
1642 explicit InvokeWithoutArgsAction(FunctionImpl function_impl)
1643 : function_impl_(function_impl) {}
1644
1645 // Allows InvokeWithoutArgs(f) to be used as any action whose type is
1646 // compatible with f.
1647 template <typename Result, typename ArgumentTuple>
1648 Result Perform(const ArgumentTuple&) { return function_impl_(); }
1649
1650 private:
1651 FunctionImpl function_impl_;
1652
1653 GTEST_DISALLOW_ASSIGN_(InvokeWithoutArgsAction);
1654 };
1655
1656 // Implements the InvokeWithoutArgs(object_ptr, &Class::Method) action.
1657 template <class Class, typename MethodPtr>
1658 class InvokeMethodWithoutArgsAction {
1659 public:
1660 InvokeMethodWithoutArgsAction(Class* obj_ptr, MethodPtr method_ptr)
1661 : obj_ptr_(obj_ptr), method_ptr_(method_ptr) {}
1662
1663 template <typename Result, typename ArgumentTuple>
1664 Result Perform(const ArgumentTuple&) const {
1665 return (obj_ptr_->*method_ptr_)();
1666 }
1667
1668 private:
1669 Class* const obj_ptr_;
1670 const MethodPtr method_ptr_;
1671
1672 GTEST_DISALLOW_ASSIGN_(InvokeMethodWithoutArgsAction);
1673 };
1674
1675 // Implements the IgnoreResult(action) action.
1676 template <typename A>
1677 class IgnoreResultAction {
1678 public:
1679 explicit IgnoreResultAction(const A& action) : action_(action) {}
1680
1681 template <typename F>
1682 operator Action<F>() const {
1683 // Assert statement belongs here because this is the best place to verify
1684 // conditions on F. It produces the clearest error messages
1685 // in most compilers.
1686 // Impl really belongs in this scope as a local class but can't
1687 // because MSVC produces duplicate symbols in different translation units
1688 // in this case. Until MS fixes that bug we put Impl into the class scope
1689 // and put the typedef both here (for use in assert statement) and
1690 // in the Impl class. But both definitions must be the same.
1691 typedef typename internal::Function<F>::Result Result;
1692
1693 // Asserts at compile time that F returns void.
1694 CompileAssertTypesEqual<void, Result>();
1695
1696 return Action<F>(new Impl<F>(action_));
1697 }
1698
1699 private:
1700 template <typename F>
1701 class Impl : public ActionInterface<F> {
1702 public:
1703 typedef typename internal::Function<F>::Result Result;
1704 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
1705
1706 explicit Impl(const A& action) : action_(action) {}
1707
1708 virtual void Perform(const ArgumentTuple& args) {
1709 // Performs the action and ignores its result.
1710 action_.Perform(args);
1711 }
1712
1713 private:
1714 // Type OriginalFunction is the same as F except that its return
1715 // type is IgnoredValue.
1716 typedef typename internal::Function<F>::MakeResultIgnoredValue
1717 OriginalFunction;
1718
1719 const Action<OriginalFunction> action_;
1720
1721 GTEST_DISALLOW_ASSIGN_(Impl);
1722 };
1723
1724 const A action_;
1725
1726 GTEST_DISALLOW_ASSIGN_(IgnoreResultAction);
1727 };
1728
1729 // A ReferenceWrapper<T> object represents a reference to type T,
1730 // which can be either const or not. It can be explicitly converted
1731 // from, and implicitly converted to, a T&. Unlike a reference,
1732 // ReferenceWrapper<T> can be copied and can survive template type
1733 // inference. This is used to support by-reference arguments in the
1734 // InvokeArgument<N>(...) action. The idea was from "reference
1735 // wrappers" in tr1, which we don't have in our source tree yet.
1736 template <typename T>
1737 class ReferenceWrapper {
1738 public:
1739 // Constructs a ReferenceWrapper<T> object from a T&.
1740 explicit ReferenceWrapper(T& l_value) : pointer_(&l_value) {} // NOLINT
1741
1742 // Allows a ReferenceWrapper<T> object to be implicitly converted to
1743 // a T&.
1744 operator T&() const { return *pointer_; }
1745 private:
1746 T* pointer_;
1747 };
1748
1749 // Allows the expression ByRef(x) to be printed as a reference to x.
1750 template <typename T>
1751 void PrintTo(const ReferenceWrapper<T>& ref, ::std::ostream* os) {
1752 T& value = ref;
1753 UniversalPrinter<T&>::Print(value, os);
1754 }
1755
1756 // Does two actions sequentially. Used for implementing the DoAll(a1,
1757 // a2, ...) action.
1758 template <typename Action1, typename Action2>
1759 class DoBothAction {
1760 public:
1761 DoBothAction(Action1 action1, Action2 action2)
1762 : action1_(action1), action2_(action2) {}
1763
1764 // This template type conversion operator allows DoAll(a1, ..., a_n)
1765 // to be used in ANY function of compatible type.
1766 template <typename F>
1767 operator Action<F>() const {
1768 return Action<F>(new Impl<F>(action1_, action2_));
1769 }
1770
1771 private:
1772 // Implements the DoAll(...) action for a particular function type F.
1773 template <typename F>
1774 class Impl : public ActionInterface<F> {
1775 public:
1776 typedef typename Function<F>::Result Result;
1777 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
1778 typedef typename Function<F>::MakeResultVoid VoidResult;
1779
1780 Impl(const Action<VoidResult>& action1, const Action<F>& action2)
1781 : action1_(action1), action2_(action2) {}
1782
1783 virtual Result Perform(const ArgumentTuple& args) {
1784 action1_.Perform(args);
1785 return action2_.Perform(args);
1786 }
1787
1788 private:
1789 const Action<VoidResult> action1_;
1790 const Action<F> action2_;
1791
1792 GTEST_DISALLOW_ASSIGN_(Impl);
1793 };
1794
1795 Action1 action1_;
1796 Action2 action2_;
1797
1798 GTEST_DISALLOW_ASSIGN_(DoBothAction);
1799 };
1800
1801 } // namespace internal
1802
1803 // An Unused object can be implicitly constructed from ANY value.
1804 // This is handy when defining actions that ignore some or all of the
1805 // mock function arguments. For example, given
1806 //
1807 // MOCK_METHOD3(Foo, double(const string& label, double x, double y));
1808 // MOCK_METHOD3(Bar, double(int index, double x, double y));
1809 //
1810 // instead of
1811 //
1812 // double DistanceToOriginWithLabel(const string& label, double x, double y) {
1813 // return sqrt(x*x + y*y);
1814 // }
1815 // double DistanceToOriginWithIndex(int index, double x, double y) {
1816 // return sqrt(x*x + y*y);
1817 // }
1818 // ...
1819 // EXEPCT_CALL(mock, Foo("abc", _, _))
1820 // .WillOnce(Invoke(DistanceToOriginWithLabel));
1821 // EXEPCT_CALL(mock, Bar(5, _, _))
1822 // .WillOnce(Invoke(DistanceToOriginWithIndex));
1823 //
1824 // you could write
1825 //
1826 // // We can declare any uninteresting argument as Unused.
1827 // double DistanceToOrigin(Unused, double x, double y) {
1828 // return sqrt(x*x + y*y);
1829 // }
1830 // ...
1831 // EXEPCT_CALL(mock, Foo("abc", _, _)).WillOnce(Invoke(DistanceToOrigin));
1832 // EXEPCT_CALL(mock, Bar(5, _, _)).WillOnce(Invoke(DistanceToOrigin));
1833 typedef internal::IgnoredValue Unused;
1834
1835 // This constructor allows us to turn an Action<From> object into an
1836 // Action<To>, as long as To's arguments can be implicitly converted
1837 // to From's and From's return type cann be implicitly converted to
1838 // To's.
1839 template <typename To>
1840 template <typename From>
1841 Action<To>::Action(const Action<From>& from)
1842 : impl_(new internal::ActionAdaptor<To, From>(from)) {}
1843
1844 // Creates an action that returns 'value'. 'value' is passed by value
1845 // instead of const reference - otherwise Return("string literal")
1846 // will trigger a compiler error about using array as initializer.
1847 template <typename R>
1848 internal::ReturnAction<R> Return(R value) {
1849 return internal::ReturnAction<R>(value);
1850 }
1851
1852 // Creates an action that returns NULL.
1853 inline PolymorphicAction<internal::ReturnNullAction> ReturnNull() {
1854 return MakePolymorphicAction(internal::ReturnNullAction());
1855 }
1856
1857 // Creates an action that returns from a void function.
1858 inline PolymorphicAction<internal::ReturnVoidAction> Return() {
1859 return MakePolymorphicAction(internal::ReturnVoidAction());
1860 }
1861
1862 // Creates an action that returns the reference to a variable.
1863 template <typename R>
1864 inline internal::ReturnRefAction<R> ReturnRef(R& x) { // NOLINT
1865 return internal::ReturnRefAction<R>(x);
1866 }
1867
1868 // Creates an action that returns the reference to a copy of the
1869 // argument. The copy is created when the action is constructed and
1870 // lives as long as the action.
1871 template <typename R>
1872 inline internal::ReturnRefOfCopyAction<R> ReturnRefOfCopy(const R& x) {
1873 return internal::ReturnRefOfCopyAction<R>(x);
1874 }
1875
1876 // Creates an action that does the default action for the give mock function.
1877 inline internal::DoDefaultAction DoDefault() {
1878 return internal::DoDefaultAction();
1879 }
1880
1881 // Creates an action that sets the variable pointed by the N-th
1882 // (0-based) function argument to 'value'.
1883 template <size_t N, typename T>
1884 PolymorphicAction<
1885 internal::SetArgumentPointeeAction<
1886 N, T, internal::IsAProtocolMessage<T>::value> >
1887 SetArgPointee(const T& x) {
1888 return MakePolymorphicAction(internal::SetArgumentPointeeAction<
1889 N, T, internal::IsAProtocolMessage<T>::value>(x));
1890 }
1891
1892 #if !((GTEST_GCC_VER_ && GTEST_GCC_VER_ < 40000) || GTEST_OS_SYMBIAN)
1893 // This overload allows SetArgPointee() to accept a string literal.
1894 // GCC prior to the version 4.0 and Symbian C++ compiler cannot distinguish
1895 // this overload from the templated version and emit a compile error.
1896 template <size_t N>
1897 PolymorphicAction<
1898 internal::SetArgumentPointeeAction<N, const char*, false> >
1899 SetArgPointee(const char* p) {
1900 return MakePolymorphicAction(internal::SetArgumentPointeeAction<
1901 N, const char*, false>(p));
1902 }
1903
1904 template <size_t N>
1905 PolymorphicAction<
1906 internal::SetArgumentPointeeAction<N, const wchar_t*, false> >
1907 SetArgPointee(const wchar_t* p) {
1908 return MakePolymorphicAction(internal::SetArgumentPointeeAction<
1909 N, const wchar_t*, false>(p));
1910 }
1911 #endif
1912
1913 // The following version is DEPRECATED.
1914 template <size_t N, typename T>
1915 PolymorphicAction<
1916 internal::SetArgumentPointeeAction<
1917 N, T, internal::IsAProtocolMessage<T>::value> >
1918 SetArgumentPointee(const T& x) {
1919 return MakePolymorphicAction(internal::SetArgumentPointeeAction<
1920 N, T, internal::IsAProtocolMessage<T>::value>(x));
1921 }
1922
1923 // Creates an action that sets a pointer referent to a given value.
1924 template <typename T1, typename T2>
1925 PolymorphicAction<internal::AssignAction<T1, T2> > Assign(T1* ptr, T2 val) {
1926 return MakePolymorphicAction(internal::AssignAction<T1, T2>(ptr, val));
1927 }
1928
1929 #if !GTEST_OS_WINDOWS_MOBILE
1930
1931 // Creates an action that sets errno and returns the appropriate error.
1932 template <typename T>
1933 PolymorphicAction<internal::SetErrnoAndReturnAction<T> >
1934 SetErrnoAndReturn(int errval, T result) {
1935 return MakePolymorphicAction(
1936 internal::SetErrnoAndReturnAction<T>(errval, result));
1937 }
1938
1939 #endif // !GTEST_OS_WINDOWS_MOBILE
1940
1941 // Various overloads for InvokeWithoutArgs().
1942
1943 // Creates an action that invokes 'function_impl' with no argument.
1944 template <typename FunctionImpl>
1945 PolymorphicAction<internal::InvokeWithoutArgsAction<FunctionImpl> >
1946 InvokeWithoutArgs(FunctionImpl function_impl) {
1947 return MakePolymorphicAction(
1948 internal::InvokeWithoutArgsAction<FunctionImpl>(function_impl));
1949 }
1950
1951 // Creates an action that invokes the given method on the given object
1952 // with no argument.
1953 template <class Class, typename MethodPtr>
1954 PolymorphicAction<internal::InvokeMethodWithoutArgsAction<Class, MethodPtr> >
1955 InvokeWithoutArgs(Class* obj_ptr, MethodPtr method_ptr) {
1956 return MakePolymorphicAction(
1957 internal::InvokeMethodWithoutArgsAction<Class, MethodPtr>(
1958 obj_ptr, method_ptr));
1959 }
1960
1961 // Creates an action that performs an_action and throws away its
1962 // result. In other words, it changes the return type of an_action to
1963 // void. an_action MUST NOT return void, or the code won't compile.
1964 template <typename A>
1965 inline internal::IgnoreResultAction<A> IgnoreResult(const A& an_action) {
1966 return internal::IgnoreResultAction<A>(an_action);
1967 }
1968
1969 // Creates a reference wrapper for the given L-value. If necessary,
1970 // you can explicitly specify the type of the reference. For example,
1971 // suppose 'derived' is an object of type Derived, ByRef(derived)
1972 // would wrap a Derived&. If you want to wrap a const Base& instead,
1973 // where Base is a base class of Derived, just write:
1974 //
1975 // ByRef<const Base>(derived)
1976 template <typename T>
1977 inline internal::ReferenceWrapper<T> ByRef(T& l_value) { // NOLINT
1978 return internal::ReferenceWrapper<T>(l_value);
1979 }
1980
1981 } // namespace testing
1982
1983 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
1984 // Copyright 2007, Google Inc.
1985 // All rights reserved.
1986 //
1987 // Redistribution and use in source and binary forms, with or without
1988 // modification, are permitted provided that the following conditions are
1989 // met:
1990 //
1991 // * Redistributions of source code must retain the above copyright
1992 // notice, this list of conditions and the following disclaimer.
1993 // * Redistributions in binary form must reproduce the above
1994 // copyright notice, this list of conditions and the following disclaimer
1995 // in the documentation and/or other materials provided with the
1996 // distribution.
1997 // * Neither the name of Google Inc. nor the names of its
1998 // contributors may be used to endorse or promote products derived from
1999 // this software without specific prior written permission.
2000 //
2001 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2002 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2003 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2004 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2005 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2006 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2007 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2008 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2009 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2010 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2011 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2012 //
2013 // Author: [email protected] (Zhanyong Wan)
2014
2015 // Google Mock - a framework for writing C++ mock classes.
2016 //
2017 // This file implements some commonly used cardinalities. More
2018 // cardinalities can be defined by the user implementing the
2019 // CardinalityInterface interface if necessary.
2020
2021 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_
2022 #define GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_
2023
2024 #include <limits.h>
2025 #include <ostream> // NOLINT
2026
2027 namespace testing {
2028
2029 // To implement a cardinality Foo, define:
2030 // 1. a class FooCardinality that implements the
2031 // CardinalityInterface interface, and
2032 // 2. a factory function that creates a Cardinality object from a
2033 // const FooCardinality*.
2034 //
2035 // The two-level delegation design follows that of Matcher, providing
2036 // consistency for extension developers. It also eases ownership
2037 // management as Cardinality objects can now be copied like plain values.
2038
2039 // The implementation of a cardinality.
2040 class CardinalityInterface {
2041 public:
2042 virtual ~CardinalityInterface() {}
2043
2044 // Conservative estimate on the lower/upper bound of the number of
2045 // calls allowed.
2046 virtual int ConservativeLowerBound() const { return 0; }
2047 virtual int ConservativeUpperBound() const { return INT_MAX; }
2048
2049 // Returns true iff call_count calls will satisfy this cardinality.
2050 virtual bool IsSatisfiedByCallCount(int call_count) const = 0;
2051
2052 // Returns true iff call_count calls will saturate this cardinality.
2053 virtual bool IsSaturatedByCallCount(int call_count) const = 0;
2054
2055 // Describes self to an ostream.
2056 virtual void DescribeTo(::std::ostream* os) const = 0;
2057 };
2058
2059 // A Cardinality is a copyable and IMMUTABLE (except by assignment)
2060 // object that specifies how many times a mock function is expected to
2061 // be called. The implementation of Cardinality is just a linked_ptr
2062 // to const CardinalityInterface, so copying is fairly cheap.
2063 // Don't inherit from Cardinality!
2064 class GTEST_API_ Cardinality {
2065 public:
2066 // Constructs a null cardinality. Needed for storing Cardinality
2067 // objects in STL containers.
2068 Cardinality() {}
2069
2070 // Constructs a Cardinality from its implementation.
2071 explicit Cardinality(const CardinalityInterface* impl) : impl_(impl) {}
2072
2073 // Conservative estimate on the lower/upper bound of the number of
2074 // calls allowed.
2075 int ConservativeLowerBound() const { return impl_->ConservativeLowerBound(); }
2076 int ConservativeUpperBound() const { return impl_->ConservativeUpperBound(); }
2077
2078 // Returns true iff call_count calls will satisfy this cardinality.
2079 bool IsSatisfiedByCallCount(int call_count) const {
2080 return impl_->IsSatisfiedByCallCount(call_count);
2081 }
2082
2083 // Returns true iff call_count calls will saturate this cardinality.
2084 bool IsSaturatedByCallCount(int call_count) const {
2085 return impl_->IsSaturatedByCallCount(call_count);
2086 }
2087
2088 // Returns true iff call_count calls will over-saturate this
2089 // cardinality, i.e. exceed the maximum number of allowed calls.
2090 bool IsOverSaturatedByCallCount(int call_count) const {
2091 return impl_->IsSaturatedByCallCount(call_count) &&
2092 !impl_->IsSatisfiedByCallCount(call_count);
2093 }
2094
2095 // Describes self to an ostream
2096 void DescribeTo(::std::ostream* os) const { impl_->DescribeTo(os); }
2097
2098 // Describes the given actual call count to an ostream.
2099 static void DescribeActualCallCountTo(int actual_call_count,
2100 ::std::ostream* os);
2101
2102 private:
2103 internal::linked_ptr<const CardinalityInterface> impl_;
2104 };
2105
2106 // Creates a cardinality that allows at least n calls.
2107 GTEST_API_ Cardinality AtLeast(int n);
2108
2109 // Creates a cardinality that allows at most n calls.
2110 GTEST_API_ Cardinality AtMost(int n);
2111
2112 // Creates a cardinality that allows any number of calls.
2113 GTEST_API_ Cardinality AnyNumber();
2114
2115 // Creates a cardinality that allows between min and max calls.
2116 GTEST_API_ Cardinality Between(int min, int max);
2117
2118 // Creates a cardinality that allows exactly n calls.
2119 GTEST_API_ Cardinality Exactly(int n);
2120
2121 // Creates a cardinality from its implementation.
2122 inline Cardinality MakeCardinality(const CardinalityInterface* c) {
2123 return Cardinality(c);
2124 }
2125
2126 } // namespace testing
2127
2128 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_
2129 // This file was GENERATED by a script. DO NOT EDIT BY HAND!!!
2130
2131 // Copyright 2007, Google Inc.
2132 // All rights reserved.
2133 //
2134 // Redistribution and use in source and binary forms, with or without
2135 // modification, are permitted provided that the following conditions are
2136 // met:
2137 //
2138 // * Redistributions of source code must retain the above copyright
2139 // notice, this list of conditions and the following disclaimer.
2140 // * Redistributions in binary form must reproduce the above
2141 // copyright notice, this list of conditions and the following disclaimer
2142 // in the documentation and/or other materials provided with the
2143 // distribution.
2144 // * Neither the name of Google Inc. nor the names of its
2145 // contributors may be used to endorse or promote products derived from
2146 // this software without specific prior written permission.
2147 //
2148 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2149 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2150 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2151 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2152 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2153 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2154 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2155 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2156 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2157 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2158 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2159 //
2160 // Author: [email protected] (Zhanyong Wan)
2161
2162 // Google Mock - a framework for writing C++ mock classes.
2163 //
2164 // This file implements some commonly used variadic actions.
2165
2166 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
2167 #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
2168
2169
2170 namespace testing {
2171 namespace internal {
2172
2173 // InvokeHelper<F> knows how to unpack an N-tuple and invoke an N-ary
2174 // function or method with the unpacked values, where F is a function
2175 // type that takes N arguments.
2176 template <typename Result, typename ArgumentTuple>
2177 class InvokeHelper;
2178
2179 template <typename R>
2180 class InvokeHelper<R, ::std::tr1::tuple<> > {
2181 public:
2182 template <typename Function>
2183 static R Invoke(Function function, const ::std::tr1::tuple<>&) {
2184 return function();
2185 }
2186
2187 template <class Class, typename MethodPtr>
2188 static R InvokeMethod(Class* obj_ptr,
2189 MethodPtr method_ptr,
2190 const ::std::tr1::tuple<>&) {
2191 return (obj_ptr->*method_ptr)();
2192 }
2193 };
2194
2195 template <typename R, typename A1>
2196 class InvokeHelper<R, ::std::tr1::tuple<A1> > {
2197 public:
2198 template <typename Function>
2199 static R Invoke(Function function, const ::std::tr1::tuple<A1>& args) {
2200 using ::std::tr1::get;
2201 return function(get<0>(args));
2202 }
2203
2204 template <class Class, typename MethodPtr>
2205 static R InvokeMethod(Class* obj_ptr,
2206 MethodPtr method_ptr,
2207 const ::std::tr1::tuple<A1>& args) {
2208 using ::std::tr1::get;
2209 return (obj_ptr->*method_ptr)(get<0>(args));
2210 }
2211 };
2212
2213 template <typename R, typename A1, typename A2>
2214 class InvokeHelper<R, ::std::tr1::tuple<A1, A2> > {
2215 public:
2216 template <typename Function>
2217 static R Invoke(Function function, const ::std::tr1::tuple<A1, A2>& args) {
2218 using ::std::tr1::get;
2219 return function(get<0>(args), get<1>(args));
2220 }
2221
2222 template <class Class, typename MethodPtr>
2223 static R InvokeMethod(Class* obj_ptr,
2224 MethodPtr method_ptr,
2225 const ::std::tr1::tuple<A1, A2>& args) {
2226 using ::std::tr1::get;
2227 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args));
2228 }
2229 };
2230
2231 template <typename R, typename A1, typename A2, typename A3>
2232 class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3> > {
2233 public:
2234 template <typename Function>
2235 static R Invoke(Function function, const ::std::tr1::tuple<A1, A2,
2236 A3>& args) {
2237 using ::std::tr1::get;
2238 return function(get<0>(args), get<1>(args), get<2>(args));
2239 }
2240
2241 template <class Class, typename MethodPtr>
2242 static R InvokeMethod(Class* obj_ptr,
2243 MethodPtr method_ptr,
2244 const ::std::tr1::tuple<A1, A2, A3>& args) {
2245 using ::std::tr1::get;
2246 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args));
2247 }
2248 };
2249
2250 template <typename R, typename A1, typename A2, typename A3, typename A4>
2251 class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4> > {
2252 public:
2253 template <typename Function>
2254 static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3,
2255 A4>& args) {
2256 using ::std::tr1::get;
2257 return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args));
2258 }
2259
2260 template <class Class, typename MethodPtr>
2261 static R InvokeMethod(Class* obj_ptr,
2262 MethodPtr method_ptr,
2263 const ::std::tr1::tuple<A1, A2, A3, A4>& args) {
2264 using ::std::tr1::get;
2265 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args),
2266 get<3>(args));
2267 }
2268 };
2269
2270 template <typename R, typename A1, typename A2, typename A3, typename A4,
2271 typename A5>
2272 class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5> > {
2273 public:
2274 template <typename Function>
2275 static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4,
2276 A5>& args) {
2277 using ::std::tr1::get;
2278 return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args),
2279 get<4>(args));
2280 }
2281
2282 template <class Class, typename MethodPtr>
2283 static R InvokeMethod(Class* obj_ptr,
2284 MethodPtr method_ptr,
2285 const ::std::tr1::tuple<A1, A2, A3, A4, A5>& args) {
2286 using ::std::tr1::get;
2287 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args),
2288 get<3>(args), get<4>(args));
2289 }
2290 };
2291
2292 template <typename R, typename A1, typename A2, typename A3, typename A4,
2293 typename A5, typename A6>
2294 class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5, A6> > {
2295 public:
2296 template <typename Function>
2297 static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4,
2298 A5, A6>& args) {
2299 using ::std::tr1::get;
2300 return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args),
2301 get<4>(args), get<5>(args));
2302 }
2303
2304 template <class Class, typename MethodPtr>
2305 static R InvokeMethod(Class* obj_ptr,
2306 MethodPtr method_ptr,
2307 const ::std::tr1::tuple<A1, A2, A3, A4, A5, A6>& args) {
2308 using ::std::tr1::get;
2309 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args),
2310 get<3>(args), get<4>(args), get<5>(args));
2311 }
2312 };
2313
2314 template <typename R, typename A1, typename A2, typename A3, typename A4,
2315 typename A5, typename A6, typename A7>
2316 class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7> > {
2317 public:
2318 template <typename Function>
2319 static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4,
2320 A5, A6, A7>& args) {
2321 using ::std::tr1::get;
2322 return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args),
2323 get<4>(args), get<5>(args), get<6>(args));
2324 }
2325
2326 template <class Class, typename MethodPtr>
2327 static R InvokeMethod(Class* obj_ptr,
2328 MethodPtr method_ptr,
2329 const ::std::tr1::tuple<A1, A2, A3, A4, A5, A6,
2330 A7>& args) {
2331 using ::std::tr1::get;
2332 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args),
2333 get<3>(args), get<4>(args), get<5>(args), get<6>(args));
2334 }
2335 };
2336
2337 template <typename R, typename A1, typename A2, typename A3, typename A4,
2338 typename A5, typename A6, typename A7, typename A8>
2339 class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8> > {
2340 public:
2341 template <typename Function>
2342 static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4,
2343 A5, A6, A7, A8>& args) {
2344 using ::std::tr1::get;
2345 return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args),
2346 get<4>(args), get<5>(args), get<6>(args), get<7>(args));
2347 }
2348
2349 template <class Class, typename MethodPtr>
2350 static R InvokeMethod(Class* obj_ptr,
2351 MethodPtr method_ptr,
2352 const ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7,
2353 A8>& args) {
2354 using ::std::tr1::get;
2355 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args),
2356 get<3>(args), get<4>(args), get<5>(args), get<6>(args), get<7>(args));
2357 }
2358 };
2359
2360 template <typename R, typename A1, typename A2, typename A3, typename A4,
2361 typename A5, typename A6, typename A7, typename A8, typename A9>
2362 class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9> > {
2363 public:
2364 template <typename Function>
2365 static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4,
2366 A5, A6, A7, A8, A9>& args) {
2367 using ::std::tr1::get;
2368 return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args),
2369 get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args));
2370 }
2371
2372 template <class Class, typename MethodPtr>
2373 static R InvokeMethod(Class* obj_ptr,
2374 MethodPtr method_ptr,
2375 const ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8,
2376 A9>& args) {
2377 using ::std::tr1::get;
2378 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args),
2379 get<3>(args), get<4>(args), get<5>(args), get<6>(args), get<7>(args),
2380 get<8>(args));
2381 }
2382 };
2383
2384 template <typename R, typename A1, typename A2, typename A3, typename A4,
2385 typename A5, typename A6, typename A7, typename A8, typename A9,
2386 typename A10>
2387 class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9,
2388 A10> > {
2389 public:
2390 template <typename Function>
2391 static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4,
2392 A5, A6, A7, A8, A9, A10>& args) {
2393 using ::std::tr1::get;
2394 return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args),
2395 get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args),
2396 get<9>(args));
2397 }
2398
2399 template <class Class, typename MethodPtr>
2400 static R InvokeMethod(Class* obj_ptr,
2401 MethodPtr method_ptr,
2402 const ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8,
2403 A9, A10>& args) {
2404 using ::std::tr1::get;
2405 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args),
2406 get<3>(args), get<4>(args), get<5>(args), get<6>(args), get<7>(args),
2407 get<8>(args), get<9>(args));
2408 }
2409 };
2410
2411 // CallableHelper has static methods for invoking "callables",
2412 // i.e. function pointers and functors. It uses overloading to
2413 // provide a uniform interface for invoking different kinds of
2414 // callables. In particular, you can use:
2415 //
2416 // CallableHelper<R>::Call(callable, a1, a2, ..., an)
2417 //
2418 // to invoke an n-ary callable, where R is its return type. If an
2419 // argument, say a2, needs to be passed by reference, you should write
2420 // ByRef(a2) instead of a2 in the above expression.
2421 template <typename R>
2422 class CallableHelper {
2423 public:
2424 // Calls a nullary callable.
2425 template <typename Function>
2426 static R Call(Function function) { return function(); }
2427
2428 // Calls a unary callable.
2429
2430 // We deliberately pass a1 by value instead of const reference here
2431 // in case it is a C-string literal. If we had declared the
2432 // parameter as 'const A1& a1' and write Call(function, "Hi"), the
2433 // compiler would've thought A1 is 'char[3]', which causes trouble
2434 // when you need to copy a value of type A1. By declaring the
2435 // parameter as 'A1 a1', the compiler will correctly infer that A1
2436 // is 'const char*' when it sees Call(function, "Hi").
2437 //
2438 // Since this function is defined inline, the compiler can get rid
2439 // of the copying of the arguments. Therefore the performance won't
2440 // be hurt.
2441 template <typename Function, typename A1>
2442 static R Call(Function function, A1 a1) { return function(a1); }
2443
2444 // Calls a binary callable.
2445 template <typename Function, typename A1, typename A2>
2446 static R Call(Function function, A1 a1, A2 a2) {
2447 return function(a1, a2);
2448 }
2449
2450 // Calls a ternary callable.
2451 template <typename Function, typename A1, typename A2, typename A3>
2452 static R Call(Function function, A1 a1, A2 a2, A3 a3) {
2453 return function(a1, a2, a3);
2454 }
2455
2456 // Calls a 4-ary callable.
2457 template <typename Function, typename A1, typename A2, typename A3,
2458 typename A4>
2459 static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4) {
2460 return function(a1, a2, a3, a4);
2461 }
2462
2463 // Calls a 5-ary callable.
2464 template <typename Function, typename A1, typename A2, typename A3,
2465 typename A4, typename A5>
2466 static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) {
2467 return function(a1, a2, a3, a4, a5);
2468 }
2469
2470 // Calls a 6-ary callable.
2471 template <typename Function, typename A1, typename A2, typename A3,
2472 typename A4, typename A5, typename A6>
2473 static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) {
2474 return function(a1, a2, a3, a4, a5, a6);
2475 }
2476
2477 // Calls a 7-ary callable.
2478 template <typename Function, typename A1, typename A2, typename A3,
2479 typename A4, typename A5, typename A6, typename A7>
2480 static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
2481 A7 a7) {
2482 return function(a1, a2, a3, a4, a5, a6, a7);
2483 }
2484
2485 // Calls a 8-ary callable.
2486 template <typename Function, typename A1, typename A2, typename A3,
2487 typename A4, typename A5, typename A6, typename A7, typename A8>
2488 static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
2489 A7 a7, A8 a8) {
2490 return function(a1, a2, a3, a4, a5, a6, a7, a8);
2491 }
2492
2493 // Calls a 9-ary callable.
2494 template <typename Function, typename A1, typename A2, typename A3,
2495 typename A4, typename A5, typename A6, typename A7, typename A8,
2496 typename A9>
2497 static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
2498 A7 a7, A8 a8, A9 a9) {
2499 return function(a1, a2, a3, a4, a5, a6, a7, a8, a9);
2500 }
2501
2502 // Calls a 10-ary callable.
2503 template <typename Function, typename A1, typename A2, typename A3,
2504 typename A4, typename A5, typename A6, typename A7, typename A8,
2505 typename A9, typename A10>
2506 static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
2507 A7 a7, A8 a8, A9 a9, A10 a10) {
2508 return function(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
2509 }
2510 }; // class CallableHelper
2511
2512 // An INTERNAL macro for extracting the type of a tuple field. It's
2513 // subject to change without notice - DO NOT USE IN USER CODE!
2514 #define GMOCK_FIELD_(Tuple, N) \
2515 typename ::std::tr1::tuple_element<N, Tuple>::type
2516
2517 // SelectArgs<Result, ArgumentTuple, k1, k2, ..., k_n>::type is the
2518 // type of an n-ary function whose i-th (1-based) argument type is the
2519 // k{i}-th (0-based) field of ArgumentTuple, which must be a tuple
2520 // type, and whose return type is Result. For example,
2521 // SelectArgs<int, ::std::tr1::tuple<bool, char, double, long>, 0, 3>::type
2522 // is int(bool, long).
2523 //
2524 // SelectArgs<Result, ArgumentTuple, k1, k2, ..., k_n>::Select(args)
2525 // returns the selected fields (k1, k2, ..., k_n) of args as a tuple.
2526 // For example,
2527 // SelectArgs<int, ::std::tr1::tuple<bool, char, double>, 2, 0>::Select(
2528 // ::std::tr1::make_tuple(true, 'a', 2.5))
2529 // returns ::std::tr1::tuple (2.5, true).
2530 //
2531 // The numbers in list k1, k2, ..., k_n must be >= 0, where n can be
2532 // in the range [0, 10]. Duplicates are allowed and they don't have
2533 // to be in an ascending or descending order.
2534
2535 template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
2536 int k4, int k5, int k6, int k7, int k8, int k9, int k10>
2537 class SelectArgs {
2538 public:
2539 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
2540 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
2541 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5),
2542 GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7),
2543 GMOCK_FIELD_(ArgumentTuple, k8), GMOCK_FIELD_(ArgumentTuple, k9),
2544 GMOCK_FIELD_(ArgumentTuple, k10));
2545 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2546 static SelectedArgs Select(const ArgumentTuple& args) {
2547 using ::std::tr1::get;
2548 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
2549 get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args),
2550 get<k8>(args), get<k9>(args), get<k10>(args));
2551 }
2552 };
2553
2554 template <typename Result, typename ArgumentTuple>
2555 class SelectArgs<Result, ArgumentTuple,
2556 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1> {
2557 public:
2558 typedef Result type();
2559 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2560 static SelectedArgs Select(const ArgumentTuple& /* args */) {
2561 using ::std::tr1::get;
2562 return SelectedArgs();
2563 }
2564 };
2565
2566 template <typename Result, typename ArgumentTuple, int k1>
2567 class SelectArgs<Result, ArgumentTuple,
2568 k1, -1, -1, -1, -1, -1, -1, -1, -1, -1> {
2569 public:
2570 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1));
2571 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2572 static SelectedArgs Select(const ArgumentTuple& args) {
2573 using ::std::tr1::get;
2574 return SelectedArgs(get<k1>(args));
2575 }
2576 };
2577
2578 template <typename Result, typename ArgumentTuple, int k1, int k2>
2579 class SelectArgs<Result, ArgumentTuple,
2580 k1, k2, -1, -1, -1, -1, -1, -1, -1, -1> {
2581 public:
2582 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
2583 GMOCK_FIELD_(ArgumentTuple, k2));
2584 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2585 static SelectedArgs Select(const ArgumentTuple& args) {
2586 using ::std::tr1::get;
2587 return SelectedArgs(get<k1>(args), get<k2>(args));
2588 }
2589 };
2590
2591 template <typename Result, typename ArgumentTuple, int k1, int k2, int k3>
2592 class SelectArgs<Result, ArgumentTuple,
2593 k1, k2, k3, -1, -1, -1, -1, -1, -1, -1> {
2594 public:
2595 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
2596 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3));
2597 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2598 static SelectedArgs Select(const ArgumentTuple& args) {
2599 using ::std::tr1::get;
2600 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args));
2601 }
2602 };
2603
2604 template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
2605 int k4>
2606 class SelectArgs<Result, ArgumentTuple,
2607 k1, k2, k3, k4, -1, -1, -1, -1, -1, -1> {
2608 public:
2609 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
2610 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
2611 GMOCK_FIELD_(ArgumentTuple, k4));
2612 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2613 static SelectedArgs Select(const ArgumentTuple& args) {
2614 using ::std::tr1::get;
2615 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
2616 get<k4>(args));
2617 }
2618 };
2619
2620 template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
2621 int k4, int k5>
2622 class SelectArgs<Result, ArgumentTuple,
2623 k1, k2, k3, k4, k5, -1, -1, -1, -1, -1> {
2624 public:
2625 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
2626 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
2627 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5));
2628 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2629 static SelectedArgs Select(const ArgumentTuple& args) {
2630 using ::std::tr1::get;
2631 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
2632 get<k4>(args), get<k5>(args));
2633 }
2634 };
2635
2636 template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
2637 int k4, int k5, int k6>
2638 class SelectArgs<Result, ArgumentTuple,
2639 k1, k2, k3, k4, k5, k6, -1, -1, -1, -1> {
2640 public:
2641 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
2642 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
2643 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5),
2644 GMOCK_FIELD_(ArgumentTuple, k6));
2645 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2646 static SelectedArgs Select(const ArgumentTuple& args) {
2647 using ::std::tr1::get;
2648 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
2649 get<k4>(args), get<k5>(args), get<k6>(args));
2650 }
2651 };
2652
2653 template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
2654 int k4, int k5, int k6, int k7>
2655 class SelectArgs<Result, ArgumentTuple,
2656 k1, k2, k3, k4, k5, k6, k7, -1, -1, -1> {
2657 public:
2658 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
2659 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
2660 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5),
2661 GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7));
2662 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2663 static SelectedArgs Select(const ArgumentTuple& args) {
2664 using ::std::tr1::get;
2665 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
2666 get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args));
2667 }
2668 };
2669
2670 template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
2671 int k4, int k5, int k6, int k7, int k8>
2672 class SelectArgs<Result, ArgumentTuple,
2673 k1, k2, k3, k4, k5, k6, k7, k8, -1, -1> {
2674 public:
2675 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
2676 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
2677 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5),
2678 GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7),
2679 GMOCK_FIELD_(ArgumentTuple, k8));
2680 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2681 static SelectedArgs Select(const ArgumentTuple& args) {
2682 using ::std::tr1::get;
2683 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
2684 get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args),
2685 get<k8>(args));
2686 }
2687 };
2688
2689 template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
2690 int k4, int k5, int k6, int k7, int k8, int k9>
2691 class SelectArgs<Result, ArgumentTuple,
2692 k1, k2, k3, k4, k5, k6, k7, k8, k9, -1> {
2693 public:
2694 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
2695 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
2696 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5),
2697 GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7),
2698 GMOCK_FIELD_(ArgumentTuple, k8), GMOCK_FIELD_(ArgumentTuple, k9));
2699 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2700 static SelectedArgs Select(const ArgumentTuple& args) {
2701 using ::std::tr1::get;
2702 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
2703 get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args),
2704 get<k8>(args), get<k9>(args));
2705 }
2706 };
2707
2708 #undef GMOCK_FIELD_
2709
2710 // Implements the WithArgs action.
2711 template <typename InnerAction, int k1 = -1, int k2 = -1, int k3 = -1,
2712 int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1, int k8 = -1,
2713 int k9 = -1, int k10 = -1>
2714 class WithArgsAction {
2715 public:
2716 explicit WithArgsAction(const InnerAction& action) : action_(action) {}
2717
2718 template <typename F>
2719 operator Action<F>() const { return MakeAction(new Impl<F>(action_)); }
2720
2721 private:
2722 template <typename F>
2723 class Impl : public ActionInterface<F> {
2724 public:
2725 typedef typename Function<F>::Result Result;
2726 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
2727
2728 explicit Impl(const InnerAction& action) : action_(action) {}
2729
2730 virtual Result Perform(const ArgumentTuple& args) {
2731 return action_.Perform(SelectArgs<Result, ArgumentTuple, k1, k2, k3, k4,
2732 k5, k6, k7, k8, k9, k10>::Select(args));
2733 }
2734
2735 private:
2736 typedef typename SelectArgs<Result, ArgumentTuple,
2737 k1, k2, k3, k4, k5, k6, k7, k8, k9, k10>::type InnerFunctionType;
2738
2739 Action<InnerFunctionType> action_;
2740 };
2741
2742 const InnerAction action_;
2743
2744 GTEST_DISALLOW_ASSIGN_(WithArgsAction);
2745 };
2746
2747 // A macro from the ACTION* family (defined later in this file)
2748 // defines an action that can be used in a mock function. Typically,
2749 // these actions only care about a subset of the arguments of the mock
2750 // function. For example, if such an action only uses the second
2751 // argument, it can be used in any mock function that takes >= 2
2752 // arguments where the type of the second argument is compatible.
2753 //
2754 // Therefore, the action implementation must be prepared to take more
2755 // arguments than it needs. The ExcessiveArg type is used to
2756 // represent those excessive arguments. In order to keep the compiler
2757 // error messages tractable, we define it in the testing namespace
2758 // instead of testing::internal. However, this is an INTERNAL TYPE
2759 // and subject to change without notice, so a user MUST NOT USE THIS
2760 // TYPE DIRECTLY.
2761 struct ExcessiveArg {};
2762
2763 // A helper class needed for implementing the ACTION* macros.
2764 template <typename Result, class Impl>
2765 class ActionHelper {
2766 public:
2767 static Result Perform(Impl* impl, const ::std::tr1::tuple<>& args) {
2768 using ::std::tr1::get;
2769 return impl->template gmock_PerformImpl<>(args, ExcessiveArg(),
2770 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2771 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2772 ExcessiveArg());
2773 }
2774
2775 template <typename A0>
2776 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0>& args) {
2777 using ::std::tr1::get;
2778 return impl->template gmock_PerformImpl<A0>(args, get<0>(args),
2779 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2780 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2781 ExcessiveArg());
2782 }
2783
2784 template <typename A0, typename A1>
2785 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1>& args) {
2786 using ::std::tr1::get;
2787 return impl->template gmock_PerformImpl<A0, A1>(args, get<0>(args),
2788 get<1>(args), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2789 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2790 ExcessiveArg());
2791 }
2792
2793 template <typename A0, typename A1, typename A2>
2794 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2>& args) {
2795 using ::std::tr1::get;
2796 return impl->template gmock_PerformImpl<A0, A1, A2>(args, get<0>(args),
2797 get<1>(args), get<2>(args), ExcessiveArg(), ExcessiveArg(),
2798 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2799 ExcessiveArg());
2800 }
2801
2802 template <typename A0, typename A1, typename A2, typename A3>
2803 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2,
2804 A3>& args) {
2805 using ::std::tr1::get;
2806 return impl->template gmock_PerformImpl<A0, A1, A2, A3>(args, get<0>(args),
2807 get<1>(args), get<2>(args), get<3>(args), ExcessiveArg(),
2808 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2809 ExcessiveArg());
2810 }
2811
2812 template <typename A0, typename A1, typename A2, typename A3, typename A4>
2813 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3,
2814 A4>& args) {
2815 using ::std::tr1::get;
2816 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4>(args,
2817 get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args),
2818 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2819 ExcessiveArg());
2820 }
2821
2822 template <typename A0, typename A1, typename A2, typename A3, typename A4,
2823 typename A5>
2824 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4,
2825 A5>& args) {
2826 using ::std::tr1::get;
2827 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5>(args,
2828 get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args),
2829 get<5>(args), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2830 ExcessiveArg());
2831 }
2832
2833 template <typename A0, typename A1, typename A2, typename A3, typename A4,
2834 typename A5, typename A6>
2835 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4,
2836 A5, A6>& args) {
2837 using ::std::tr1::get;
2838 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6>(args,
2839 get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args),
2840 get<5>(args), get<6>(args), ExcessiveArg(), ExcessiveArg(),
2841 ExcessiveArg());
2842 }
2843
2844 template <typename A0, typename A1, typename A2, typename A3, typename A4,
2845 typename A5, typename A6, typename A7>
2846 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4,
2847 A5, A6, A7>& args) {
2848 using ::std::tr1::get;
2849 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6,
2850 A7>(args, get<0>(args), get<1>(args), get<2>(args), get<3>(args),
2851 get<4>(args), get<5>(args), get<6>(args), get<7>(args), ExcessiveArg(),
2852 ExcessiveArg());
2853 }
2854
2855 template <typename A0, typename A1, typename A2, typename A3, typename A4,
2856 typename A5, typename A6, typename A7, typename A8>
2857 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4,
2858 A5, A6, A7, A8>& args) {
2859 using ::std::tr1::get;
2860 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6, A7,
2861 A8>(args, get<0>(args), get<1>(args), get<2>(args), get<3>(args),
2862 get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args),
2863 ExcessiveArg());
2864 }
2865
2866 template <typename A0, typename A1, typename A2, typename A3, typename A4,
2867 typename A5, typename A6, typename A7, typename A8, typename A9>
2868 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4,
2869 A5, A6, A7, A8, A9>& args) {
2870 using ::std::tr1::get;
2871 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6, A7, A8,
2872 A9>(args, get<0>(args), get<1>(args), get<2>(args), get<3>(args),
2873 get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args),
2874 get<9>(args));
2875 }
2876 };
2877
2878 } // namespace internal
2879
2880 // Various overloads for Invoke().
2881
2882 // WithArgs<N1, N2, ..., Nk>(an_action) creates an action that passes
2883 // the selected arguments of the mock function to an_action and
2884 // performs it. It serves as an adaptor between actions with
2885 // different argument lists. C++ doesn't support default arguments for
2886 // function templates, so we have to overload it.
2887 template <int k1, typename InnerAction>
2888 inline internal::WithArgsAction<InnerAction, k1>
2889 WithArgs(const InnerAction& action) {
2890 return internal::WithArgsAction<InnerAction, k1>(action);
2891 }
2892
2893 template <int k1, int k2, typename InnerAction>
2894 inline internal::WithArgsAction<InnerAction, k1, k2>
2895 WithArgs(const InnerAction& action) {
2896 return internal::WithArgsAction<InnerAction, k1, k2>(action);
2897 }
2898
2899 template <int k1, int k2, int k3, typename InnerAction>
2900 inline internal::WithArgsAction<InnerAction, k1, k2, k3>
2901 WithArgs(const InnerAction& action) {
2902 return internal::WithArgsAction<InnerAction, k1, k2, k3>(action);
2903 }
2904
2905 template <int k1, int k2, int k3, int k4, typename InnerAction>
2906 inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4>
2907 WithArgs(const InnerAction& action) {
2908 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4>(action);
2909 }
2910
2911 template <int k1, int k2, int k3, int k4, int k5, typename InnerAction>
2912 inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5>
2913 WithArgs(const InnerAction& action) {
2914 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5>(action);
2915 }
2916
2917 template <int k1, int k2, int k3, int k4, int k5, int k6, typename InnerAction>
2918 inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6>
2919 WithArgs(const InnerAction& action) {
2920 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6>(action);
2921 }
2922
2923 template <int k1, int k2, int k3, int k4, int k5, int k6, int k7,
2924 typename InnerAction>
2925 inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7>
2926 WithArgs(const InnerAction& action) {
2927 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6,
2928 k7>(action);
2929 }
2930
2931 template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
2932 typename InnerAction>
2933 inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8>
2934 WithArgs(const InnerAction& action) {
2935 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7,
2936 k8>(action);
2937 }
2938
2939 template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
2940 int k9, typename InnerAction>
2941 inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8, k9>
2942 WithArgs(const InnerAction& action) {
2943 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8,
2944 k9>(action);
2945 }
2946
2947 template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
2948 int k9, int k10, typename InnerAction>
2949 inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8,
2950 k9, k10>
2951 WithArgs(const InnerAction& action) {
2952 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8,
2953 k9, k10>(action);
2954 }
2955
2956 // Creates an action that does actions a1, a2, ..., sequentially in
2957 // each invocation.
2958 template <typename Action1, typename Action2>
2959 inline internal::DoBothAction<Action1, Action2>
2960 DoAll(Action1 a1, Action2 a2) {
2961 return internal::DoBothAction<Action1, Action2>(a1, a2);
2962 }
2963
2964 template <typename Action1, typename Action2, typename Action3>
2965 inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
2966 Action3> >
2967 DoAll(Action1 a1, Action2 a2, Action3 a3) {
2968 return DoAll(a1, DoAll(a2, a3));
2969 }
2970
2971 template <typename Action1, typename Action2, typename Action3,
2972 typename Action4>
2973 inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
2974 internal::DoBothAction<Action3, Action4> > >
2975 DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4) {
2976 return DoAll(a1, DoAll(a2, a3, a4));
2977 }
2978
2979 template <typename Action1, typename Action2, typename Action3,
2980 typename Action4, typename Action5>
2981 inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
2982 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
2983 Action5> > > >
2984 DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5) {
2985 return DoAll(a1, DoAll(a2, a3, a4, a5));
2986 }
2987
2988 template <typename Action1, typename Action2, typename Action3,
2989 typename Action4, typename Action5, typename Action6>
2990 inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
2991 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
2992 internal::DoBothAction<Action5, Action6> > > > >
2993 DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6) {
2994 return DoAll(a1, DoAll(a2, a3, a4, a5, a6));
2995 }
2996
2997 template <typename Action1, typename Action2, typename Action3,
2998 typename Action4, typename Action5, typename Action6, typename Action7>
2999 inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
3000 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
3001 internal::DoBothAction<Action5, internal::DoBothAction<Action6,
3002 Action7> > > > > >
3003 DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
3004 Action7 a7) {
3005 return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7));
3006 }
3007
3008 template <typename Action1, typename Action2, typename Action3,
3009 typename Action4, typename Action5, typename Action6, typename Action7,
3010 typename Action8>
3011 inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
3012 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
3013 internal::DoBothAction<Action5, internal::DoBothAction<Action6,
3014 internal::DoBothAction<Action7, Action8> > > > > > >
3015 DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
3016 Action7 a7, Action8 a8) {
3017 return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8));
3018 }
3019
3020 template <typename Action1, typename Action2, typename Action3,
3021 typename Action4, typename Action5, typename Action6, typename Action7,
3022 typename Action8, typename Action9>
3023 inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
3024 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
3025 internal::DoBothAction<Action5, internal::DoBothAction<Action6,
3026 internal::DoBothAction<Action7, internal::DoBothAction<Action8,
3027 Action9> > > > > > > >
3028 DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
3029 Action7 a7, Action8 a8, Action9 a9) {
3030 return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8, a9));
3031 }
3032
3033 template <typename Action1, typename Action2, typename Action3,
3034 typename Action4, typename Action5, typename Action6, typename Action7,
3035 typename Action8, typename Action9, typename Action10>
3036 inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
3037 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
3038 internal::DoBothAction<Action5, internal::DoBothAction<Action6,
3039 internal::DoBothAction<Action7, internal::DoBothAction<Action8,
3040 internal::DoBothAction<Action9, Action10> > > > > > > > >
3041 DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
3042 Action7 a7, Action8 a8, Action9 a9, Action10 a10) {
3043 return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8, a9, a10));
3044 }
3045
3046 } // namespace testing
3047
3048 // The ACTION* family of macros can be used in a namespace scope to
3049 // define custom actions easily. The syntax:
3050 //
3051 // ACTION(name) { statements; }
3052 //
3053 // will define an action with the given name that executes the
3054 // statements. The value returned by the statements will be used as
3055 // the return value of the action. Inside the statements, you can
3056 // refer to the K-th (0-based) argument of the mock function by
3057 // 'argK', and refer to its type by 'argK_type'. For example:
3058 //
3059 // ACTION(IncrementArg1) {
3060 // arg1_type temp = arg1;
3061 // return ++(*temp);
3062 // }
3063 //
3064 // allows you to write
3065 //
3066 // ...WillOnce(IncrementArg1());
3067 //
3068 // You can also refer to the entire argument tuple and its type by
3069 // 'args' and 'args_type', and refer to the mock function type and its
3070 // return type by 'function_type' and 'return_type'.
3071 //
3072 // Note that you don't need to specify the types of the mock function
3073 // arguments. However rest assured that your code is still type-safe:
3074 // you'll get a compiler error if *arg1 doesn't support the ++
3075 // operator, or if the type of ++(*arg1) isn't compatible with the
3076 // mock function's return type, for example.
3077 //
3078 // Sometimes you'll want to parameterize the action. For that you can use
3079 // another macro:
3080 //
3081 // ACTION_P(name, param_name) { statements; }
3082 //
3083 // For example:
3084 //
3085 // ACTION_P(Add, n) { return arg0 + n; }
3086 //
3087 // will allow you to write:
3088 //
3089 // ...WillOnce(Add(5));
3090 //
3091 // Note that you don't need to provide the type of the parameter
3092 // either. If you need to reference the type of a parameter named
3093 // 'foo', you can write 'foo_type'. For example, in the body of
3094 // ACTION_P(Add, n) above, you can write 'n_type' to refer to the type
3095 // of 'n'.
3096 //
3097 // We also provide ACTION_P2, ACTION_P3, ..., up to ACTION_P10 to support
3098 // multi-parameter actions.
3099 //
3100 // For the purpose of typing, you can view
3101 //
3102 // ACTION_Pk(Foo, p1, ..., pk) { ... }
3103 //
3104 // as shorthand for
3105 //
3106 // template <typename p1_type, ..., typename pk_type>
3107 // FooActionPk<p1_type, ..., pk_type> Foo(p1_type p1, ..., pk_type pk) { ... }
3108 //
3109 // In particular, you can provide the template type arguments
3110 // explicitly when invoking Foo(), as in Foo<long, bool>(5, false);
3111 // although usually you can rely on the compiler to infer the types
3112 // for you automatically. You can assign the result of expression
3113 // Foo(p1, ..., pk) to a variable of type FooActionPk<p1_type, ...,
3114 // pk_type>. This can be useful when composing actions.
3115 //
3116 // You can also overload actions with different numbers of parameters:
3117 //
3118 // ACTION_P(Plus, a) { ... }
3119 // ACTION_P2(Plus, a, b) { ... }
3120 //
3121 // While it's tempting to always use the ACTION* macros when defining
3122 // a new action, you should also consider implementing ActionInterface
3123 // or using MakePolymorphicAction() instead, especially if you need to
3124 // use the action a lot. While these approaches require more work,
3125 // they give you more control on the types of the mock function
3126 // arguments and the action parameters, which in general leads to
3127 // better compiler error messages that pay off in the long run. They
3128 // also allow overloading actions based on parameter types (as opposed
3129 // to just based on the number of parameters).
3130 //
3131 // CAVEAT:
3132 //
3133 // ACTION*() can only be used in a namespace scope. The reason is
3134 // that C++ doesn't yet allow function-local types to be used to
3135 // instantiate templates. The up-coming C++0x standard will fix this.
3136 // Once that's done, we'll consider supporting using ACTION*() inside
3137 // a function.
3138 //
3139 // MORE INFORMATION:
3140 //
3141 // To learn more about using these macros, please search for 'ACTION'
3142 // on http://code.google.com/p/googlemock/wiki/CookBook.
3143
3144 // An internal macro needed for implementing ACTION*().
3145 #define GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_\
3146 const args_type& args GTEST_ATTRIBUTE_UNUSED_, \
3147 arg0_type arg0 GTEST_ATTRIBUTE_UNUSED_, \
3148 arg1_type arg1 GTEST_ATTRIBUTE_UNUSED_, \
3149 arg2_type arg2 GTEST_ATTRIBUTE_UNUSED_, \
3150 arg3_type arg3 GTEST_ATTRIBUTE_UNUSED_, \
3151 arg4_type arg4 GTEST_ATTRIBUTE_UNUSED_, \
3152 arg5_type arg5 GTEST_ATTRIBUTE_UNUSED_, \
3153 arg6_type arg6 GTEST_ATTRIBUTE_UNUSED_, \
3154 arg7_type arg7 GTEST_ATTRIBUTE_UNUSED_, \
3155 arg8_type arg8 GTEST_ATTRIBUTE_UNUSED_, \
3156 arg9_type arg9 GTEST_ATTRIBUTE_UNUSED_
3157
3158 // Sometimes you want to give an action explicit template parameters
3159 // that cannot be inferred from its value parameters. ACTION() and
3160 // ACTION_P*() don't support that. ACTION_TEMPLATE() remedies that
3161 // and can be viewed as an extension to ACTION() and ACTION_P*().
3162 //
3163 // The syntax:
3164 //
3165 // ACTION_TEMPLATE(ActionName,
3166 // HAS_m_TEMPLATE_PARAMS(kind1, name1, ..., kind_m, name_m),
3167 // AND_n_VALUE_PARAMS(p1, ..., p_n)) { statements; }
3168 //
3169 // defines an action template that takes m explicit template
3170 // parameters and n value parameters. name_i is the name of the i-th
3171 // template parameter, and kind_i specifies whether it's a typename,
3172 // an integral constant, or a template. p_i is the name of the i-th
3173 // value parameter.
3174 //
3175 // Example:
3176 //
3177 // // DuplicateArg<k, T>(output) converts the k-th argument of the mock
3178 // // function to type T and copies it to *output.
3179 // ACTION_TEMPLATE(DuplicateArg,
3180 // HAS_2_TEMPLATE_PARAMS(int, k, typename, T),
3181 // AND_1_VALUE_PARAMS(output)) {
3182 // *output = T(std::tr1::get<k>(args));
3183 // }
3184 // ...
3185 // int n;
3186 // EXPECT_CALL(mock, Foo(_, _))
3187 // .WillOnce(DuplicateArg<1, unsigned char>(&n));
3188 //
3189 // To create an instance of an action template, write:
3190 //
3191 // ActionName<t1, ..., t_m>(v1, ..., v_n)
3192 //
3193 // where the ts are the template arguments and the vs are the value
3194 // arguments. The value argument types are inferred by the compiler.
3195 // If you want to explicitly specify the value argument types, you can
3196 // provide additional template arguments:
3197 //
3198 // ActionName<t1, ..., t_m, u1, ..., u_k>(v1, ..., v_n)
3199 //
3200 // where u_i is the desired type of v_i.
3201 //
3202 // ACTION_TEMPLATE and ACTION/ACTION_P* can be overloaded on the
3203 // number of value parameters, but not on the number of template
3204 // parameters. Without the restriction, the meaning of the following
3205 // is unclear:
3206 //
3207 // OverloadedAction<int, bool>(x);
3208 //
3209 // Are we using a single-template-parameter action where 'bool' refers
3210 // to the type of x, or are we using a two-template-parameter action
3211 // where the compiler is asked to infer the type of x?
3212 //
3213 // Implementation notes:
3214 //
3215 // GMOCK_INTERNAL_*_HAS_m_TEMPLATE_PARAMS and
3216 // GMOCK_INTERNAL_*_AND_n_VALUE_PARAMS are internal macros for
3217 // implementing ACTION_TEMPLATE. The main trick we use is to create
3218 // new macro invocations when expanding a macro. For example, we have
3219 //
3220 // #define ACTION_TEMPLATE(name, template_params, value_params)
3221 // ... GMOCK_INTERNAL_DECL_##template_params ...
3222 //
3223 // which causes ACTION_TEMPLATE(..., HAS_1_TEMPLATE_PARAMS(typename, T), ...)
3224 // to expand to
3225 //
3226 // ... GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(typename, T) ...
3227 //
3228 // Since GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS is a macro, the
3229 // preprocessor will continue to expand it to
3230 //
3231 // ... typename T ...
3232 //
3233 // This technique conforms to the C++ standard and is portable. It
3234 // allows us to implement action templates using O(N) code, where N is
3235 // the maximum number of template/value parameters supported. Without
3236 // using it, we'd have to devote O(N^2) amount of code to implement all
3237 // combinations of m and n.
3238
3239 // Declares the template parameters.
3240 #define GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(kind0, name0) kind0 name0
3241 #define GMOCK_INTERNAL_DECL_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, \
3242 name1) kind0 name0, kind1 name1
3243 #define GMOCK_INTERNAL_DECL_HAS_3_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3244 kind2, name2) kind0 name0, kind1 name1, kind2 name2
3245 #define GMOCK_INTERNAL_DECL_HAS_4_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3246 kind2, name2, kind3, name3) kind0 name0, kind1 name1, kind2 name2, \
3247 kind3 name3
3248 #define GMOCK_INTERNAL_DECL_HAS_5_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3249 kind2, name2, kind3, name3, kind4, name4) kind0 name0, kind1 name1, \
3250 kind2 name2, kind3 name3, kind4 name4
3251 #define GMOCK_INTERNAL_DECL_HAS_6_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3252 kind2, name2, kind3, name3, kind4, name4, kind5, name5) kind0 name0, \
3253 kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5
3254 #define GMOCK_INTERNAL_DECL_HAS_7_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3255 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
3256 name6) kind0 name0, kind1 name1, kind2 name2, kind3 name3, kind4 name4, \
3257 kind5 name5, kind6 name6
3258 #define GMOCK_INTERNAL_DECL_HAS_8_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3259 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
3260 kind7, name7) kind0 name0, kind1 name1, kind2 name2, kind3 name3, \
3261 kind4 name4, kind5 name5, kind6 name6, kind7 name7
3262 #define GMOCK_INTERNAL_DECL_HAS_9_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3263 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
3264 kind7, name7, kind8, name8) kind0 name0, kind1 name1, kind2 name2, \
3265 kind3 name3, kind4 name4, kind5 name5, kind6 name6, kind7 name7, \
3266 kind8 name8
3267 #define GMOCK_INTERNAL_DECL_HAS_10_TEMPLATE_PARAMS(kind0, name0, kind1, \
3268 name1, kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
3269 name6, kind7, name7, kind8, name8, kind9, name9) kind0 name0, \
3270 kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5, \
3271 kind6 name6, kind7 name7, kind8 name8, kind9 name9
3272
3273 // Lists the template parameters.
3274 #define GMOCK_INTERNAL_LIST_HAS_1_TEMPLATE_PARAMS(kind0, name0) name0
3275 #define GMOCK_INTERNAL_LIST_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, \
3276 name1) name0, name1
3277 #define GMOCK_INTERNAL_LIST_HAS_3_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3278 kind2, name2) name0, name1, name2
3279 #define GMOCK_INTERNAL_LIST_HAS_4_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3280 kind2, name2, kind3, name3) name0, name1, name2, name3
3281 #define GMOCK_INTERNAL_LIST_HAS_5_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3282 kind2, name2, kind3, name3, kind4, name4) name0, name1, name2, name3, \
3283 name4
3284 #define GMOCK_INTERNAL_LIST_HAS_6_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3285 kind2, name2, kind3, name3, kind4, name4, kind5, name5) name0, name1, \
3286 name2, name3, name4, name5
3287 #define GMOCK_INTERNAL_LIST_HAS_7_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3288 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
3289 name6) name0, name1, name2, name3, name4, name5, name6
3290 #define GMOCK_INTERNAL_LIST_HAS_8_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3291 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
3292 kind7, name7) name0, name1, name2, name3, name4, name5, name6, name7
3293 #define GMOCK_INTERNAL_LIST_HAS_9_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3294 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
3295 kind7, name7, kind8, name8) name0, name1, name2, name3, name4, name5, \
3296 name6, name7, name8
3297 #define GMOCK_INTERNAL_LIST_HAS_10_TEMPLATE_PARAMS(kind0, name0, kind1, \
3298 name1, kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
3299 name6, kind7, name7, kind8, name8, kind9, name9) name0, name1, name2, \
3300 name3, name4, name5, name6, name7, name8, name9
3301
3302 // Declares the types of value parameters.
3303 #define GMOCK_INTERNAL_DECL_TYPE_AND_0_VALUE_PARAMS()
3304 #define GMOCK_INTERNAL_DECL_TYPE_AND_1_VALUE_PARAMS(p0) , typename p0##_type
3305 #define GMOCK_INTERNAL_DECL_TYPE_AND_2_VALUE_PARAMS(p0, p1) , \
3306 typename p0##_type, typename p1##_type
3307 #define GMOCK_INTERNAL_DECL_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) , \
3308 typename p0##_type, typename p1##_type, typename p2##_type
3309 #define GMOCK_INTERNAL_DECL_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) , \
3310 typename p0##_type, typename p1##_type, typename p2##_type, \
3311 typename p3##_type
3312 #define GMOCK_INTERNAL_DECL_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) , \
3313 typename p0##_type, typename p1##_type, typename p2##_type, \
3314 typename p3##_type, typename p4##_type
3315 #define GMOCK_INTERNAL_DECL_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) , \
3316 typename p0##_type, typename p1##_type, typename p2##_type, \
3317 typename p3##_type, typename p4##_type, typename p5##_type
3318 #define GMOCK_INTERNAL_DECL_TYPE_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3319 p6) , typename p0##_type, typename p1##_type, typename p2##_type, \
3320 typename p3##_type, typename p4##_type, typename p5##_type, \
3321 typename p6##_type
3322 #define GMOCK_INTERNAL_DECL_TYPE_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3323 p6, p7) , typename p0##_type, typename p1##_type, typename p2##_type, \
3324 typename p3##_type, typename p4##_type, typename p5##_type, \
3325 typename p6##_type, typename p7##_type
3326 #define GMOCK_INTERNAL_DECL_TYPE_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3327 p6, p7, p8) , typename p0##_type, typename p1##_type, typename p2##_type, \
3328 typename p3##_type, typename p4##_type, typename p5##_type, \
3329 typename p6##_type, typename p7##_type, typename p8##_type
3330 #define GMOCK_INTERNAL_DECL_TYPE_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3331 p6, p7, p8, p9) , typename p0##_type, typename p1##_type, \
3332 typename p2##_type, typename p3##_type, typename p4##_type, \
3333 typename p5##_type, typename p6##_type, typename p7##_type, \
3334 typename p8##_type, typename p9##_type
3335
3336 // Initializes the value parameters.
3337 #define GMOCK_INTERNAL_INIT_AND_0_VALUE_PARAMS()\
3338 ()
3339 #define GMOCK_INTERNAL_INIT_AND_1_VALUE_PARAMS(p0)\
3340 (p0##_type gmock_p0) : p0(gmock_p0)
3341 #define GMOCK_INTERNAL_INIT_AND_2_VALUE_PARAMS(p0, p1)\
3342 (p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), p1(gmock_p1)
3343 #define GMOCK_INTERNAL_INIT_AND_3_VALUE_PARAMS(p0, p1, p2)\
3344 (p0##_type gmock_p0, p1##_type gmock_p1, \
3345 p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2)
3346 #define GMOCK_INTERNAL_INIT_AND_4_VALUE_PARAMS(p0, p1, p2, p3)\
3347 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3348 p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
3349 p3(gmock_p3)
3350 #define GMOCK_INTERNAL_INIT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)\
3351 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3352 p3##_type gmock_p3, p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), \
3353 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4)
3354 #define GMOCK_INTERNAL_INIT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)\
3355 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3356 p3##_type gmock_p3, p4##_type gmock_p4, \
3357 p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
3358 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5)
3359 #define GMOCK_INTERNAL_INIT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)\
3360 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3361 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
3362 p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
3363 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6)
3364 #define GMOCK_INTERNAL_INIT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)\
3365 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3366 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
3367 p6##_type gmock_p6, p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), \
3368 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
3369 p7(gmock_p7)
3370 #define GMOCK_INTERNAL_INIT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3371 p7, p8)\
3372 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3373 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
3374 p6##_type gmock_p6, p7##_type gmock_p7, \
3375 p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
3376 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
3377 p8(gmock_p8)
3378 #define GMOCK_INTERNAL_INIT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3379 p7, p8, p9)\
3380 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3381 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
3382 p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
3383 p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
3384 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
3385 p8(gmock_p8), p9(gmock_p9)
3386
3387 // Declares the fields for storing the value parameters.
3388 #define GMOCK_INTERNAL_DEFN_AND_0_VALUE_PARAMS()
3389 #define GMOCK_INTERNAL_DEFN_AND_1_VALUE_PARAMS(p0) p0##_type p0;
3390 #define GMOCK_INTERNAL_DEFN_AND_2_VALUE_PARAMS(p0, p1) p0##_type p0; \
3391 p1##_type p1;
3392 #define GMOCK_INTERNAL_DEFN_AND_3_VALUE_PARAMS(p0, p1, p2) p0##_type p0; \
3393 p1##_type p1; p2##_type p2;
3394 #define GMOCK_INTERNAL_DEFN_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0##_type p0; \
3395 p1##_type p1; p2##_type p2; p3##_type p3;
3396 #define GMOCK_INTERNAL_DEFN_AND_5_VALUE_PARAMS(p0, p1, p2, p3, \
3397 p4) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4;
3398 #define GMOCK_INTERNAL_DEFN_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, \
3399 p5) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \
3400 p5##_type p5;
3401 #define GMOCK_INTERNAL_DEFN_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3402 p6) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \
3403 p5##_type p5; p6##_type p6;
3404 #define GMOCK_INTERNAL_DEFN_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3405 p7) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \
3406 p5##_type p5; p6##_type p6; p7##_type p7;
3407 #define GMOCK_INTERNAL_DEFN_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3408 p7, p8) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; \
3409 p4##_type p4; p5##_type p5; p6##_type p6; p7##_type p7; p8##_type p8;
3410 #define GMOCK_INTERNAL_DEFN_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3411 p7, p8, p9) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; \
3412 p4##_type p4; p5##_type p5; p6##_type p6; p7##_type p7; p8##_type p8; \
3413 p9##_type p9;
3414
3415 // Lists the value parameters.
3416 #define GMOCK_INTERNAL_LIST_AND_0_VALUE_PARAMS()
3417 #define GMOCK_INTERNAL_LIST_AND_1_VALUE_PARAMS(p0) p0
3418 #define GMOCK_INTERNAL_LIST_AND_2_VALUE_PARAMS(p0, p1) p0, p1
3419 #define GMOCK_INTERNAL_LIST_AND_3_VALUE_PARAMS(p0, p1, p2) p0, p1, p2
3420 #define GMOCK_INTERNAL_LIST_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0, p1, p2, p3
3421 #define GMOCK_INTERNAL_LIST_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) p0, p1, \
3422 p2, p3, p4
3423 #define GMOCK_INTERNAL_LIST_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) p0, \
3424 p1, p2, p3, p4, p5
3425 #define GMOCK_INTERNAL_LIST_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3426 p6) p0, p1, p2, p3, p4, p5, p6
3427 #define GMOCK_INTERNAL_LIST_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3428 p7) p0, p1, p2, p3, p4, p5, p6, p7
3429 #define GMOCK_INTERNAL_LIST_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3430 p7, p8) p0, p1, p2, p3, p4, p5, p6, p7, p8
3431 #define GMOCK_INTERNAL_LIST_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3432 p7, p8, p9) p0, p1, p2, p3, p4, p5, p6, p7, p8, p9
3433
3434 // Lists the value parameter types.
3435 #define GMOCK_INTERNAL_LIST_TYPE_AND_0_VALUE_PARAMS()
3436 #define GMOCK_INTERNAL_LIST_TYPE_AND_1_VALUE_PARAMS(p0) , p0##_type
3437 #define GMOCK_INTERNAL_LIST_TYPE_AND_2_VALUE_PARAMS(p0, p1) , p0##_type, \
3438 p1##_type
3439 #define GMOCK_INTERNAL_LIST_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) , p0##_type, \
3440 p1##_type, p2##_type
3441 #define GMOCK_INTERNAL_LIST_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) , \
3442 p0##_type, p1##_type, p2##_type, p3##_type
3443 #define GMOCK_INTERNAL_LIST_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) , \
3444 p0##_type, p1##_type, p2##_type, p3##_type, p4##_type
3445 #define GMOCK_INTERNAL_LIST_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) , \
3446 p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type
3447 #define GMOCK_INTERNAL_LIST_TYPE_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3448 p6) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type, \
3449 p6##_type
3450 #define GMOCK_INTERNAL_LIST_TYPE_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3451 p6, p7) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
3452 p5##_type, p6##_type, p7##_type
3453 #define GMOCK_INTERNAL_LIST_TYPE_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3454 p6, p7, p8) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
3455 p5##_type, p6##_type, p7##_type, p8##_type
3456 #define GMOCK_INTERNAL_LIST_TYPE_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3457 p6, p7, p8, p9) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
3458 p5##_type, p6##_type, p7##_type, p8##_type, p9##_type
3459
3460 // Declares the value parameters.
3461 #define GMOCK_INTERNAL_DECL_AND_0_VALUE_PARAMS()
3462 #define GMOCK_INTERNAL_DECL_AND_1_VALUE_PARAMS(p0) p0##_type p0
3463 #define GMOCK_INTERNAL_DECL_AND_2_VALUE_PARAMS(p0, p1) p0##_type p0, \
3464 p1##_type p1
3465 #define GMOCK_INTERNAL_DECL_AND_3_VALUE_PARAMS(p0, p1, p2) p0##_type p0, \
3466 p1##_type p1, p2##_type p2
3467 #define GMOCK_INTERNAL_DECL_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0##_type p0, \
3468 p1##_type p1, p2##_type p2, p3##_type p3
3469 #define GMOCK_INTERNAL_DECL_AND_5_VALUE_PARAMS(p0, p1, p2, p3, \
3470 p4) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4
3471 #define GMOCK_INTERNAL_DECL_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, \
3472 p5) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \
3473 p5##_type p5
3474 #define GMOCK_INTERNAL_DECL_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3475 p6) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \
3476 p5##_type p5, p6##_type p6
3477 #define GMOCK_INTERNAL_DECL_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3478 p7) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \
3479 p5##_type p5, p6##_type p6, p7##_type p7
3480 #define GMOCK_INTERNAL_DECL_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3481 p7, p8) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
3482 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8
3483 #define GMOCK_INTERNAL_DECL_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3484 p7, p8, p9) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
3485 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \
3486 p9##_type p9
3487
3488 // The suffix of the class template implementing the action template.
3489 #define GMOCK_INTERNAL_COUNT_AND_0_VALUE_PARAMS()
3490 #define GMOCK_INTERNAL_COUNT_AND_1_VALUE_PARAMS(p0) P
3491 #define GMOCK_INTERNAL_COUNT_AND_2_VALUE_PARAMS(p0, p1) P2
3492 #define GMOCK_INTERNAL_COUNT_AND_3_VALUE_PARAMS(p0, p1, p2) P3
3493 #define GMOCK_INTERNAL_COUNT_AND_4_VALUE_PARAMS(p0, p1, p2, p3) P4
3494 #define GMOCK_INTERNAL_COUNT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) P5
3495 #define GMOCK_INTERNAL_COUNT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) P6
3496 #define GMOCK_INTERNAL_COUNT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6) P7
3497 #define GMOCK_INTERNAL_COUNT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3498 p7) P8
3499 #define GMOCK_INTERNAL_COUNT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3500 p7, p8) P9
3501 #define GMOCK_INTERNAL_COUNT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3502 p7, p8, p9) P10
3503
3504 // The name of the class template implementing the action template.
3505 #define GMOCK_ACTION_CLASS_(name, value_params)\
3506 GTEST_CONCAT_TOKEN_(name##Action, GMOCK_INTERNAL_COUNT_##value_params)
3507
3508 #define ACTION_TEMPLATE(name, template_params, value_params)\
3509 template <GMOCK_INTERNAL_DECL_##template_params\
3510 GMOCK_INTERNAL_DECL_TYPE_##value_params>\
3511 class GMOCK_ACTION_CLASS_(name, value_params) {\
3512 public:\
3513 GMOCK_ACTION_CLASS_(name, value_params)\
3514 GMOCK_INTERNAL_INIT_##value_params {}\
3515 template <typename F>\
3516 class gmock_Impl : public ::testing::ActionInterface<F> {\
3517 public:\
3518 typedef F function_type;\
3519 typedef typename ::testing::internal::Function<F>::Result return_type;\
3520 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
3521 args_type;\
3522 explicit gmock_Impl GMOCK_INTERNAL_INIT_##value_params {}\
3523 virtual return_type Perform(const args_type& args) {\
3524 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
3525 Perform(this, args);\
3526 }\
3527 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3528 typename arg3_type, typename arg4_type, typename arg5_type, \
3529 typename arg6_type, typename arg7_type, typename arg8_type, \
3530 typename arg9_type>\
3531 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
3532 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
3533 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
3534 arg9_type arg9) const;\
3535 GMOCK_INTERNAL_DEFN_##value_params\
3536 private:\
3537 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
3538 };\
3539 template <typename F> operator ::testing::Action<F>() const {\
3540 return ::testing::Action<F>(\
3541 new gmock_Impl<F>(GMOCK_INTERNAL_LIST_##value_params));\
3542 }\
3543 GMOCK_INTERNAL_DEFN_##value_params\
3544 private:\
3545 GTEST_DISALLOW_ASSIGN_(GMOCK_ACTION_CLASS_(name, value_params));\
3546 };\
3547 template <GMOCK_INTERNAL_DECL_##template_params\
3548 GMOCK_INTERNAL_DECL_TYPE_##value_params>\
3549 inline GMOCK_ACTION_CLASS_(name, value_params)<\
3550 GMOCK_INTERNAL_LIST_##template_params\
3551 GMOCK_INTERNAL_LIST_TYPE_##value_params> name(\
3552 GMOCK_INTERNAL_DECL_##value_params) {\
3553 return GMOCK_ACTION_CLASS_(name, value_params)<\
3554 GMOCK_INTERNAL_LIST_##template_params\
3555 GMOCK_INTERNAL_LIST_TYPE_##value_params>(\
3556 GMOCK_INTERNAL_LIST_##value_params);\
3557 }\
3558 template <GMOCK_INTERNAL_DECL_##template_params\
3559 GMOCK_INTERNAL_DECL_TYPE_##value_params>\
3560 template <typename F>\
3561 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3562 typename arg3_type, typename arg4_type, typename arg5_type, \
3563 typename arg6_type, typename arg7_type, typename arg8_type, \
3564 typename arg9_type>\
3565 typename ::testing::internal::Function<F>::Result\
3566 GMOCK_ACTION_CLASS_(name, value_params)<\
3567 GMOCK_INTERNAL_LIST_##template_params\
3568 GMOCK_INTERNAL_LIST_TYPE_##value_params>::gmock_Impl<F>::\
3569 gmock_PerformImpl(\
3570 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
3571
3572 #define ACTION(name)\
3573 class name##Action {\
3574 public:\
3575 name##Action() {}\
3576 template <typename F>\
3577 class gmock_Impl : public ::testing::ActionInterface<F> {\
3578 public:\
3579 typedef F function_type;\
3580 typedef typename ::testing::internal::Function<F>::Result return_type;\
3581 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
3582 args_type;\
3583 gmock_Impl() {}\
3584 virtual return_type Perform(const args_type& args) {\
3585 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
3586 Perform(this, args);\
3587 }\
3588 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3589 typename arg3_type, typename arg4_type, typename arg5_type, \
3590 typename arg6_type, typename arg7_type, typename arg8_type, \
3591 typename arg9_type>\
3592 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
3593 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
3594 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
3595 arg9_type arg9) const;\
3596 private:\
3597 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
3598 };\
3599 template <typename F> operator ::testing::Action<F>() const {\
3600 return ::testing::Action<F>(new gmock_Impl<F>());\
3601 }\
3602 private:\
3603 GTEST_DISALLOW_ASSIGN_(name##Action);\
3604 };\
3605 inline name##Action name() {\
3606 return name##Action();\
3607 }\
3608 template <typename F>\
3609 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3610 typename arg3_type, typename arg4_type, typename arg5_type, \
3611 typename arg6_type, typename arg7_type, typename arg8_type, \
3612 typename arg9_type>\
3613 typename ::testing::internal::Function<F>::Result\
3614 name##Action::gmock_Impl<F>::gmock_PerformImpl(\
3615 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
3616
3617 #define ACTION_P(name, p0)\
3618 template <typename p0##_type>\
3619 class name##ActionP {\
3620 public:\
3621 name##ActionP(p0##_type gmock_p0) : p0(gmock_p0) {}\
3622 template <typename F>\
3623 class gmock_Impl : public ::testing::ActionInterface<F> {\
3624 public:\
3625 typedef F function_type;\
3626 typedef typename ::testing::internal::Function<F>::Result return_type;\
3627 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
3628 args_type;\
3629 explicit gmock_Impl(p0##_type gmock_p0) : p0(gmock_p0) {}\
3630 virtual return_type Perform(const args_type& args) {\
3631 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
3632 Perform(this, args);\
3633 }\
3634 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3635 typename arg3_type, typename arg4_type, typename arg5_type, \
3636 typename arg6_type, typename arg7_type, typename arg8_type, \
3637 typename arg9_type>\
3638 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
3639 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
3640 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
3641 arg9_type arg9) const;\
3642 p0##_type p0;\
3643 private:\
3644 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
3645 };\
3646 template <typename F> operator ::testing::Action<F>() const {\
3647 return ::testing::Action<F>(new gmock_Impl<F>(p0));\
3648 }\
3649 p0##_type p0;\
3650 private:\
3651 GTEST_DISALLOW_ASSIGN_(name##ActionP);\
3652 };\
3653 template <typename p0##_type>\
3654 inline name##ActionP<p0##_type> name(p0##_type p0) {\
3655 return name##ActionP<p0##_type>(p0);\
3656 }\
3657 template <typename p0##_type>\
3658 template <typename F>\
3659 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3660 typename arg3_type, typename arg4_type, typename arg5_type, \
3661 typename arg6_type, typename arg7_type, typename arg8_type, \
3662 typename arg9_type>\
3663 typename ::testing::internal::Function<F>::Result\
3664 name##ActionP<p0##_type>::gmock_Impl<F>::gmock_PerformImpl(\
3665 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
3666
3667 #define ACTION_P2(name, p0, p1)\
3668 template <typename p0##_type, typename p1##_type>\
3669 class name##ActionP2 {\
3670 public:\
3671 name##ActionP2(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \
3672 p1(gmock_p1) {}\
3673 template <typename F>\
3674 class gmock_Impl : public ::testing::ActionInterface<F> {\
3675 public:\
3676 typedef F function_type;\
3677 typedef typename ::testing::internal::Function<F>::Result return_type;\
3678 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
3679 args_type;\
3680 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \
3681 p1(gmock_p1) {}\
3682 virtual return_type Perform(const args_type& args) {\
3683 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
3684 Perform(this, args);\
3685 }\
3686 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3687 typename arg3_type, typename arg4_type, typename arg5_type, \
3688 typename arg6_type, typename arg7_type, typename arg8_type, \
3689 typename arg9_type>\
3690 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
3691 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
3692 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
3693 arg9_type arg9) const;\
3694 p0##_type p0;\
3695 p1##_type p1;\
3696 private:\
3697 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
3698 };\
3699 template <typename F> operator ::testing::Action<F>() const {\
3700 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1));\
3701 }\
3702 p0##_type p0;\
3703 p1##_type p1;\
3704 private:\
3705 GTEST_DISALLOW_ASSIGN_(name##ActionP2);\
3706 };\
3707 template <typename p0##_type, typename p1##_type>\
3708 inline name##ActionP2<p0##_type, p1##_type> name(p0##_type p0, \
3709 p1##_type p1) {\
3710 return name##ActionP2<p0##_type, p1##_type>(p0, p1);\
3711 }\
3712 template <typename p0##_type, typename p1##_type>\
3713 template <typename F>\
3714 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3715 typename arg3_type, typename arg4_type, typename arg5_type, \
3716 typename arg6_type, typename arg7_type, typename arg8_type, \
3717 typename arg9_type>\
3718 typename ::testing::internal::Function<F>::Result\
3719 name##ActionP2<p0##_type, p1##_type>::gmock_Impl<F>::gmock_PerformImpl(\
3720 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
3721
3722 #define ACTION_P3(name, p0, p1, p2)\
3723 template <typename p0##_type, typename p1##_type, typename p2##_type>\
3724 class name##ActionP3 {\
3725 public:\
3726 name##ActionP3(p0##_type gmock_p0, p1##_type gmock_p1, \
3727 p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\
3728 template <typename F>\
3729 class gmock_Impl : public ::testing::ActionInterface<F> {\
3730 public:\
3731 typedef F function_type;\
3732 typedef typename ::testing::internal::Function<F>::Result return_type;\
3733 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
3734 args_type;\
3735 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, \
3736 p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\
3737 virtual return_type Perform(const args_type& args) {\
3738 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
3739 Perform(this, args);\
3740 }\
3741 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3742 typename arg3_type, typename arg4_type, typename arg5_type, \
3743 typename arg6_type, typename arg7_type, typename arg8_type, \
3744 typename arg9_type>\
3745 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
3746 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
3747 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
3748 arg9_type arg9) const;\
3749 p0##_type p0;\
3750 p1##_type p1;\
3751 p2##_type p2;\
3752 private:\
3753 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
3754 };\
3755 template <typename F> operator ::testing::Action<F>() const {\
3756 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2));\
3757 }\
3758 p0##_type p0;\
3759 p1##_type p1;\
3760 p2##_type p2;\
3761 private:\
3762 GTEST_DISALLOW_ASSIGN_(name##ActionP3);\
3763 };\
3764 template <typename p0##_type, typename p1##_type, typename p2##_type>\
3765 inline name##ActionP3<p0##_type, p1##_type, p2##_type> name(p0##_type p0, \
3766 p1##_type p1, p2##_type p2) {\
3767 return name##ActionP3<p0##_type, p1##_type, p2##_type>(p0, p1, p2);\
3768 }\
3769 template <typename p0##_type, typename p1##_type, typename p2##_type>\
3770 template <typename F>\
3771 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3772 typename arg3_type, typename arg4_type, typename arg5_type, \
3773 typename arg6_type, typename arg7_type, typename arg8_type, \
3774 typename arg9_type>\
3775 typename ::testing::internal::Function<F>::Result\
3776 name##ActionP3<p0##_type, p1##_type, \
3777 p2##_type>::gmock_Impl<F>::gmock_PerformImpl(\
3778 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
3779
3780 #define ACTION_P4(name, p0, p1, p2, p3)\
3781 template <typename p0##_type, typename p1##_type, typename p2##_type, \
3782 typename p3##_type>\
3783 class name##ActionP4 {\
3784 public:\
3785 name##ActionP4(p0##_type gmock_p0, p1##_type gmock_p1, \
3786 p2##_type gmock_p2, p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), \
3787 p2(gmock_p2), p3(gmock_p3) {}\
3788 template <typename F>\
3789 class gmock_Impl : public ::testing::ActionInterface<F> {\
3790 public:\
3791 typedef F function_type;\
3792 typedef typename ::testing::internal::Function<F>::Result return_type;\
3793 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
3794 args_type;\
3795 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3796 p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
3797 p3(gmock_p3) {}\
3798 virtual return_type Perform(const args_type& args) {\
3799 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
3800 Perform(this, args);\
3801 }\
3802 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3803 typename arg3_type, typename arg4_type, typename arg5_type, \
3804 typename arg6_type, typename arg7_type, typename arg8_type, \
3805 typename arg9_type>\
3806 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
3807 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
3808 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
3809 arg9_type arg9) const;\
3810 p0##_type p0;\
3811 p1##_type p1;\
3812 p2##_type p2;\
3813 p3##_type p3;\
3814 private:\
3815 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
3816 };\
3817 template <typename F> operator ::testing::Action<F>() const {\
3818 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3));\
3819 }\
3820 p0##_type p0;\
3821 p1##_type p1;\
3822 p2##_type p2;\
3823 p3##_type p3;\
3824 private:\
3825 GTEST_DISALLOW_ASSIGN_(name##ActionP4);\
3826 };\
3827 template <typename p0##_type, typename p1##_type, typename p2##_type, \
3828 typename p3##_type>\
3829 inline name##ActionP4<p0##_type, p1##_type, p2##_type, \
3830 p3##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
3831 p3##_type p3) {\
3832 return name##ActionP4<p0##_type, p1##_type, p2##_type, p3##_type>(p0, p1, \
3833 p2, p3);\
3834 }\
3835 template <typename p0##_type, typename p1##_type, typename p2##_type, \
3836 typename p3##_type>\
3837 template <typename F>\
3838 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3839 typename arg3_type, typename arg4_type, typename arg5_type, \
3840 typename arg6_type, typename arg7_type, typename arg8_type, \
3841 typename arg9_type>\
3842 typename ::testing::internal::Function<F>::Result\
3843 name##ActionP4<p0##_type, p1##_type, p2##_type, \
3844 p3##_type>::gmock_Impl<F>::gmock_PerformImpl(\
3845 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
3846
3847 #define ACTION_P5(name, p0, p1, p2, p3, p4)\
3848 template <typename p0##_type, typename p1##_type, typename p2##_type, \
3849 typename p3##_type, typename p4##_type>\
3850 class name##ActionP5 {\
3851 public:\
3852 name##ActionP5(p0##_type gmock_p0, p1##_type gmock_p1, \
3853 p2##_type gmock_p2, p3##_type gmock_p3, \
3854 p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
3855 p3(gmock_p3), p4(gmock_p4) {}\
3856 template <typename F>\
3857 class gmock_Impl : public ::testing::ActionInterface<F> {\
3858 public:\
3859 typedef F function_type;\
3860 typedef typename ::testing::internal::Function<F>::Result return_type;\
3861 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
3862 args_type;\
3863 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3864 p3##_type gmock_p3, p4##_type gmock_p4) : p0(gmock_p0), \
3865 p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), p4(gmock_p4) {}\
3866 virtual return_type Perform(const args_type& args) {\
3867 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
3868 Perform(this, args);\
3869 }\
3870 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3871 typename arg3_type, typename arg4_type, typename arg5_type, \
3872 typename arg6_type, typename arg7_type, typename arg8_type, \
3873 typename arg9_type>\
3874 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
3875 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
3876 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
3877 arg9_type arg9) const;\
3878 p0##_type p0;\
3879 p1##_type p1;\
3880 p2##_type p2;\
3881 p3##_type p3;\
3882 p4##_type p4;\
3883 private:\
3884 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
3885 };\
3886 template <typename F> operator ::testing::Action<F>() const {\
3887 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4));\
3888 }\
3889 p0##_type p0;\
3890 p1##_type p1;\
3891 p2##_type p2;\
3892 p3##_type p3;\
3893 p4##_type p4;\
3894 private:\
3895 GTEST_DISALLOW_ASSIGN_(name##ActionP5);\
3896 };\
3897 template <typename p0##_type, typename p1##_type, typename p2##_type, \
3898 typename p3##_type, typename p4##_type>\
3899 inline name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \
3900 p4##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
3901 p4##_type p4) {\
3902 return name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \
3903 p4##_type>(p0, p1, p2, p3, p4);\
3904 }\
3905 template <typename p0##_type, typename p1##_type, typename p2##_type, \
3906 typename p3##_type, typename p4##_type>\
3907 template <typename F>\
3908 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3909 typename arg3_type, typename arg4_type, typename arg5_type, \
3910 typename arg6_type, typename arg7_type, typename arg8_type, \
3911 typename arg9_type>\
3912 typename ::testing::internal::Function<F>::Result\
3913 name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \
3914 p4##_type>::gmock_Impl<F>::gmock_PerformImpl(\
3915 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
3916
3917 #define ACTION_P6(name, p0, p1, p2, p3, p4, p5)\
3918 template <typename p0##_type, typename p1##_type, typename p2##_type, \
3919 typename p3##_type, typename p4##_type, typename p5##_type>\
3920 class name##ActionP6 {\
3921 public:\
3922 name##ActionP6(p0##_type gmock_p0, p1##_type gmock_p1, \
3923 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
3924 p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
3925 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {}\
3926 template <typename F>\
3927 class gmock_Impl : public ::testing::ActionInterface<F> {\
3928 public:\
3929 typedef F function_type;\
3930 typedef typename ::testing::internal::Function<F>::Result return_type;\
3931 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
3932 args_type;\
3933 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3934 p3##_type gmock_p3, p4##_type gmock_p4, \
3935 p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
3936 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {}\
3937 virtual return_type Perform(const args_type& args) {\
3938 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
3939 Perform(this, args);\
3940 }\
3941 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3942 typename arg3_type, typename arg4_type, typename arg5_type, \
3943 typename arg6_type, typename arg7_type, typename arg8_type, \
3944 typename arg9_type>\
3945 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
3946 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
3947 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
3948 arg9_type arg9) const;\
3949 p0##_type p0;\
3950 p1##_type p1;\
3951 p2##_type p2;\
3952 p3##_type p3;\
3953 p4##_type p4;\
3954 p5##_type p5;\
3955 private:\
3956 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
3957 };\
3958 template <typename F> operator ::testing::Action<F>() const {\
3959 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5));\
3960 }\
3961 p0##_type p0;\
3962 p1##_type p1;\
3963 p2##_type p2;\
3964 p3##_type p3;\
3965 p4##_type p4;\
3966 p5##_type p5;\
3967 private:\
3968 GTEST_DISALLOW_ASSIGN_(name##ActionP6);\
3969 };\
3970 template <typename p0##_type, typename p1##_type, typename p2##_type, \
3971 typename p3##_type, typename p4##_type, typename p5##_type>\
3972 inline name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, \
3973 p4##_type, p5##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
3974 p3##_type p3, p4##_type p4, p5##_type p5) {\
3975 return name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, \
3976 p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5);\
3977 }\
3978 template <typename p0##_type, typename p1##_type, typename p2##_type, \
3979 typename p3##_type, typename p4##_type, typename p5##_type>\
3980 template <typename F>\
3981 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3982 typename arg3_type, typename arg4_type, typename arg5_type, \
3983 typename arg6_type, typename arg7_type, typename arg8_type, \
3984 typename arg9_type>\
3985 typename ::testing::internal::Function<F>::Result\
3986 name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
3987 p5##_type>::gmock_Impl<F>::gmock_PerformImpl(\
3988 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
3989
3990 #define ACTION_P7(name, p0, p1, p2, p3, p4, p5, p6)\
3991 template <typename p0##_type, typename p1##_type, typename p2##_type, \
3992 typename p3##_type, typename p4##_type, typename p5##_type, \
3993 typename p6##_type>\
3994 class name##ActionP7 {\
3995 public:\
3996 name##ActionP7(p0##_type gmock_p0, p1##_type gmock_p1, \
3997 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
3998 p5##_type gmock_p5, p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), \
3999 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), \
4000 p6(gmock_p6) {}\
4001 template <typename F>\
4002 class gmock_Impl : public ::testing::ActionInterface<F> {\
4003 public:\
4004 typedef F function_type;\
4005 typedef typename ::testing::internal::Function<F>::Result return_type;\
4006 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
4007 args_type;\
4008 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
4009 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
4010 p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
4011 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6) {}\
4012 virtual return_type Perform(const args_type& args) {\
4013 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
4014 Perform(this, args);\
4015 }\
4016 template <typename arg0_type, typename arg1_type, typename arg2_type, \
4017 typename arg3_type, typename arg4_type, typename arg5_type, \
4018 typename arg6_type, typename arg7_type, typename arg8_type, \
4019 typename arg9_type>\
4020 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
4021 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
4022 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
4023 arg9_type arg9) const;\
4024 p0##_type p0;\
4025 p1##_type p1;\
4026 p2##_type p2;\
4027 p3##_type p3;\
4028 p4##_type p4;\
4029 p5##_type p5;\
4030 p6##_type p6;\
4031 private:\
4032 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
4033 };\
4034 template <typename F> operator ::testing::Action<F>() const {\
4035 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
4036 p6));\
4037 }\
4038 p0##_type p0;\
4039 p1##_type p1;\
4040 p2##_type p2;\
4041 p3##_type p3;\
4042 p4##_type p4;\
4043 p5##_type p5;\
4044 p6##_type p6;\
4045 private:\
4046 GTEST_DISALLOW_ASSIGN_(name##ActionP7);\
4047 };\
4048 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4049 typename p3##_type, typename p4##_type, typename p5##_type, \
4050 typename p6##_type>\
4051 inline name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, \
4052 p4##_type, p5##_type, p6##_type> name(p0##_type p0, p1##_type p1, \
4053 p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
4054 p6##_type p6) {\
4055 return name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, \
4056 p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, p6);\
4057 }\
4058 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4059 typename p3##_type, typename p4##_type, typename p5##_type, \
4060 typename p6##_type>\
4061 template <typename F>\
4062 template <typename arg0_type, typename arg1_type, typename arg2_type, \
4063 typename arg3_type, typename arg4_type, typename arg5_type, \
4064 typename arg6_type, typename arg7_type, typename arg8_type, \
4065 typename arg9_type>\
4066 typename ::testing::internal::Function<F>::Result\
4067 name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
4068 p5##_type, p6##_type>::gmock_Impl<F>::gmock_PerformImpl(\
4069 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
4070
4071 #define ACTION_P8(name, p0, p1, p2, p3, p4, p5, p6, p7)\
4072 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4073 typename p3##_type, typename p4##_type, typename p5##_type, \
4074 typename p6##_type, typename p7##_type>\
4075 class name##ActionP8 {\
4076 public:\
4077 name##ActionP8(p0##_type gmock_p0, p1##_type gmock_p1, \
4078 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
4079 p5##_type gmock_p5, p6##_type gmock_p6, \
4080 p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
4081 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
4082 p7(gmock_p7) {}\
4083 template <typename F>\
4084 class gmock_Impl : public ::testing::ActionInterface<F> {\
4085 public:\
4086 typedef F function_type;\
4087 typedef typename ::testing::internal::Function<F>::Result return_type;\
4088 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
4089 args_type;\
4090 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
4091 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
4092 p6##_type gmock_p6, p7##_type gmock_p7) : p0(gmock_p0), \
4093 p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), \
4094 p5(gmock_p5), p6(gmock_p6), p7(gmock_p7) {}\
4095 virtual return_type Perform(const args_type& args) {\
4096 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
4097 Perform(this, args);\
4098 }\
4099 template <typename arg0_type, typename arg1_type, typename arg2_type, \
4100 typename arg3_type, typename arg4_type, typename arg5_type, \
4101 typename arg6_type, typename arg7_type, typename arg8_type, \
4102 typename arg9_type>\
4103 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
4104 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
4105 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
4106 arg9_type arg9) const;\
4107 p0##_type p0;\
4108 p1##_type p1;\
4109 p2##_type p2;\
4110 p3##_type p3;\
4111 p4##_type p4;\
4112 p5##_type p5;\
4113 p6##_type p6;\
4114 p7##_type p7;\
4115 private:\
4116 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
4117 };\
4118 template <typename F> operator ::testing::Action<F>() const {\
4119 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
4120 p6, p7));\
4121 }\
4122 p0##_type p0;\
4123 p1##_type p1;\
4124 p2##_type p2;\
4125 p3##_type p3;\
4126 p4##_type p4;\
4127 p5##_type p5;\
4128 p6##_type p6;\
4129 p7##_type p7;\
4130 private:\
4131 GTEST_DISALLOW_ASSIGN_(name##ActionP8);\
4132 };\
4133 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4134 typename p3##_type, typename p4##_type, typename p5##_type, \
4135 typename p6##_type, typename p7##_type>\
4136 inline name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, \
4137 p4##_type, p5##_type, p6##_type, p7##_type> name(p0##_type p0, \
4138 p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
4139 p6##_type p6, p7##_type p7) {\
4140 return name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, \
4141 p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, p3, p4, p5, \
4142 p6, p7);\
4143 }\
4144 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4145 typename p3##_type, typename p4##_type, typename p5##_type, \
4146 typename p6##_type, typename p7##_type>\
4147 template <typename F>\
4148 template <typename arg0_type, typename arg1_type, typename arg2_type, \
4149 typename arg3_type, typename arg4_type, typename arg5_type, \
4150 typename arg6_type, typename arg7_type, typename arg8_type, \
4151 typename arg9_type>\
4152 typename ::testing::internal::Function<F>::Result\
4153 name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
4154 p5##_type, p6##_type, \
4155 p7##_type>::gmock_Impl<F>::gmock_PerformImpl(\
4156 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
4157
4158 #define ACTION_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8)\
4159 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4160 typename p3##_type, typename p4##_type, typename p5##_type, \
4161 typename p6##_type, typename p7##_type, typename p8##_type>\
4162 class name##ActionP9 {\
4163 public:\
4164 name##ActionP9(p0##_type gmock_p0, p1##_type gmock_p1, \
4165 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
4166 p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
4167 p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
4168 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
4169 p8(gmock_p8) {}\
4170 template <typename F>\
4171 class gmock_Impl : public ::testing::ActionInterface<F> {\
4172 public:\
4173 typedef F function_type;\
4174 typedef typename ::testing::internal::Function<F>::Result return_type;\
4175 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
4176 args_type;\
4177 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
4178 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
4179 p6##_type gmock_p6, p7##_type gmock_p7, \
4180 p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
4181 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
4182 p7(gmock_p7), p8(gmock_p8) {}\
4183 virtual return_type Perform(const args_type& args) {\
4184 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
4185 Perform(this, args);\
4186 }\
4187 template <typename arg0_type, typename arg1_type, typename arg2_type, \
4188 typename arg3_type, typename arg4_type, typename arg5_type, \
4189 typename arg6_type, typename arg7_type, typename arg8_type, \
4190 typename arg9_type>\
4191 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
4192 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
4193 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
4194 arg9_type arg9) const;\
4195 p0##_type p0;\
4196 p1##_type p1;\
4197 p2##_type p2;\
4198 p3##_type p3;\
4199 p4##_type p4;\
4200 p5##_type p5;\
4201 p6##_type p6;\
4202 p7##_type p7;\
4203 p8##_type p8;\
4204 private:\
4205 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
4206 };\
4207 template <typename F> operator ::testing::Action<F>() const {\
4208 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
4209 p6, p7, p8));\
4210 }\
4211 p0##_type p0;\
4212 p1##_type p1;\
4213 p2##_type p2;\
4214 p3##_type p3;\
4215 p4##_type p4;\
4216 p5##_type p5;\
4217 p6##_type p6;\
4218 p7##_type p7;\
4219 p8##_type p8;\
4220 private:\
4221 GTEST_DISALLOW_ASSIGN_(name##ActionP9);\
4222 };\
4223 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4224 typename p3##_type, typename p4##_type, typename p5##_type, \
4225 typename p6##_type, typename p7##_type, typename p8##_type>\
4226 inline name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, \
4227 p4##_type, p5##_type, p6##_type, p7##_type, \
4228 p8##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
4229 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, \
4230 p8##_type p8) {\
4231 return name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, \
4232 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type>(p0, p1, p2, \
4233 p3, p4, p5, p6, p7, p8);\
4234 }\
4235 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4236 typename p3##_type, typename p4##_type, typename p5##_type, \
4237 typename p6##_type, typename p7##_type, typename p8##_type>\
4238 template <typename F>\
4239 template <typename arg0_type, typename arg1_type, typename arg2_type, \
4240 typename arg3_type, typename arg4_type, typename arg5_type, \
4241 typename arg6_type, typename arg7_type, typename arg8_type, \
4242 typename arg9_type>\
4243 typename ::testing::internal::Function<F>::Result\
4244 name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
4245 p5##_type, p6##_type, p7##_type, \
4246 p8##_type>::gmock_Impl<F>::gmock_PerformImpl(\
4247 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
4248
4249 #define ACTION_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)\
4250 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4251 typename p3##_type, typename p4##_type, typename p5##_type, \
4252 typename p6##_type, typename p7##_type, typename p8##_type, \
4253 typename p9##_type>\
4254 class name##ActionP10 {\
4255 public:\
4256 name##ActionP10(p0##_type gmock_p0, p1##_type gmock_p1, \
4257 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
4258 p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
4259 p8##_type gmock_p8, p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), \
4260 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
4261 p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {}\
4262 template <typename F>\
4263 class gmock_Impl : public ::testing::ActionInterface<F> {\
4264 public:\
4265 typedef F function_type;\
4266 typedef typename ::testing::internal::Function<F>::Result return_type;\
4267 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
4268 args_type;\
4269 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
4270 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
4271 p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
4272 p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
4273 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
4274 p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {}\
4275 virtual return_type Perform(const args_type& args) {\
4276 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
4277 Perform(this, args);\
4278 }\
4279 template <typename arg0_type, typename arg1_type, typename arg2_type, \
4280 typename arg3_type, typename arg4_type, typename arg5_type, \
4281 typename arg6_type, typename arg7_type, typename arg8_type, \
4282 typename arg9_type>\
4283 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
4284 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
4285 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
4286 arg9_type arg9) const;\
4287 p0##_type p0;\
4288 p1##_type p1;\
4289 p2##_type p2;\
4290 p3##_type p3;\
4291 p4##_type p4;\
4292 p5##_type p5;\
4293 p6##_type p6;\
4294 p7##_type p7;\
4295 p8##_type p8;\
4296 p9##_type p9;\
4297 private:\
4298 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
4299 };\
4300 template <typename F> operator ::testing::Action<F>() const {\
4301 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
4302 p6, p7, p8, p9));\
4303 }\
4304 p0##_type p0;\
4305 p1##_type p1;\
4306 p2##_type p2;\
4307 p3##_type p3;\
4308 p4##_type p4;\
4309 p5##_type p5;\
4310 p6##_type p6;\
4311 p7##_type p7;\
4312 p8##_type p8;\
4313 p9##_type p9;\
4314 private:\
4315 GTEST_DISALLOW_ASSIGN_(name##ActionP10);\
4316 };\
4317 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4318 typename p3##_type, typename p4##_type, typename p5##_type, \
4319 typename p6##_type, typename p7##_type, typename p8##_type, \
4320 typename p9##_type>\
4321 inline name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, \
4322 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
4323 p9##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
4324 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \
4325 p9##_type p9) {\
4326 return name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, \
4327 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, p9##_type>(p0, \
4328 p1, p2, p3, p4, p5, p6, p7, p8, p9);\
4329 }\
4330 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4331 typename p3##_type, typename p4##_type, typename p5##_type, \
4332 typename p6##_type, typename p7##_type, typename p8##_type, \
4333 typename p9##_type>\
4334 template <typename F>\
4335 template <typename arg0_type, typename arg1_type, typename arg2_type, \
4336 typename arg3_type, typename arg4_type, typename arg5_type, \
4337 typename arg6_type, typename arg7_type, typename arg8_type, \
4338 typename arg9_type>\
4339 typename ::testing::internal::Function<F>::Result\
4340 name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
4341 p5##_type, p6##_type, p7##_type, p8##_type, \
4342 p9##_type>::gmock_Impl<F>::gmock_PerformImpl(\
4343 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
4344
4345 namespace testing {
4346
4347 // The ACTION*() macros trigger warning C4100 (unreferenced formal
4348 // parameter) in MSVC with -W4. Unfortunately they cannot be fixed in
4349 // the macro definition, as the warnings are generated when the macro
4350 // is expanded and macro expansion cannot contain #pragma. Therefore
4351 // we suppress them here.
4352 #ifdef _MSC_VER
4353 # pragma warning(push)
4354 # pragma warning(disable:4100)
4355 #endif
4356
4357 // Various overloads for InvokeArgument<N>().
4358 //
4359 // The InvokeArgument<N>(a1, a2, ..., a_k) action invokes the N-th
4360 // (0-based) argument, which must be a k-ary callable, of the mock
4361 // function, with arguments a1, a2, ..., a_k.
4362 //
4363 // Notes:
4364 //
4365 // 1. The arguments are passed by value by default. If you need to
4366 // pass an argument by reference, wrap it inside ByRef(). For
4367 // example,
4368 //
4369 // InvokeArgument<1>(5, string("Hello"), ByRef(foo))
4370 //
4371 // passes 5 and string("Hello") by value, and passes foo by
4372 // reference.
4373 //
4374 // 2. If the callable takes an argument by reference but ByRef() is
4375 // not used, it will receive the reference to a copy of the value,
4376 // instead of the original value. For example, when the 0-th
4377 // argument of the mock function takes a const string&, the action
4378 //
4379 // InvokeArgument<0>(string("Hello"))
4380 //
4381 // makes a copy of the temporary string("Hello") object and passes a
4382 // reference of the copy, instead of the original temporary object,
4383 // to the callable. This makes it easy for a user to define an
4384 // InvokeArgument action from temporary values and have it performed
4385 // later.
4386
4387 ACTION_TEMPLATE(InvokeArgument,
4388 HAS_1_TEMPLATE_PARAMS(int, k),
4389 AND_0_VALUE_PARAMS()) {
4390 return internal::CallableHelper<return_type>::Call(
4391 ::std::tr1::get<k>(args));
4392 }
4393
4394 ACTION_TEMPLATE(InvokeArgument,
4395 HAS_1_TEMPLATE_PARAMS(int, k),
4396 AND_1_VALUE_PARAMS(p0)) {
4397 return internal::CallableHelper<return_type>::Call(
4398 ::std::tr1::get<k>(args), p0);
4399 }
4400
4401 ACTION_TEMPLATE(InvokeArgument,
4402 HAS_1_TEMPLATE_PARAMS(int, k),
4403 AND_2_VALUE_PARAMS(p0, p1)) {
4404 return internal::CallableHelper<return_type>::Call(
4405 ::std::tr1::get<k>(args), p0, p1);
4406 }
4407
4408 ACTION_TEMPLATE(InvokeArgument,
4409 HAS_1_TEMPLATE_PARAMS(int, k),
4410 AND_3_VALUE_PARAMS(p0, p1, p2)) {
4411 return internal::CallableHelper<return_type>::Call(
4412 ::std::tr1::get<k>(args), p0, p1, p2);
4413 }
4414
4415 ACTION_TEMPLATE(InvokeArgument,
4416 HAS_1_TEMPLATE_PARAMS(int, k),
4417 AND_4_VALUE_PARAMS(p0, p1, p2, p3)) {
4418 return internal::CallableHelper<return_type>::Call(
4419 ::std::tr1::get<k>(args), p0, p1, p2, p3);
4420 }
4421
4422 ACTION_TEMPLATE(InvokeArgument,
4423 HAS_1_TEMPLATE_PARAMS(int, k),
4424 AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)) {
4425 return internal::CallableHelper<return_type>::Call(
4426 ::std::tr1::get<k>(args), p0, p1, p2, p3, p4);
4427 }
4428
4429 ACTION_TEMPLATE(InvokeArgument,
4430 HAS_1_TEMPLATE_PARAMS(int, k),
4431 AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)) {
4432 return internal::CallableHelper<return_type>::Call(
4433 ::std::tr1::get<k>(args), p0, p1, p2, p3, p4, p5);
4434 }
4435
4436 ACTION_TEMPLATE(InvokeArgument,
4437 HAS_1_TEMPLATE_PARAMS(int, k),
4438 AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)) {
4439 return internal::CallableHelper<return_type>::Call(
4440 ::std::tr1::get<k>(args), p0, p1, p2, p3, p4, p5, p6);
4441 }
4442
4443 ACTION_TEMPLATE(InvokeArgument,
4444 HAS_1_TEMPLATE_PARAMS(int, k),
4445 AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)) {
4446 return internal::CallableHelper<return_type>::Call(
4447 ::std::tr1::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7);
4448 }
4449
4450 ACTION_TEMPLATE(InvokeArgument,
4451 HAS_1_TEMPLATE_PARAMS(int, k),
4452 AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8)) {
4453 return internal::CallableHelper<return_type>::Call(
4454 ::std::tr1::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7, p8);
4455 }
4456
4457 ACTION_TEMPLATE(InvokeArgument,
4458 HAS_1_TEMPLATE_PARAMS(int, k),
4459 AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)) {
4460 return internal::CallableHelper<return_type>::Call(
4461 ::std::tr1::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7, p8, p9);
4462 }
4463
4464 // Various overloads for ReturnNew<T>().
4465 //
4466 // The ReturnNew<T>(a1, a2, ..., a_k) action returns a pointer to a new
4467 // instance of type T, constructed on the heap with constructor arguments
4468 // a1, a2, ..., and a_k. The caller assumes ownership of the returned value.
4469 ACTION_TEMPLATE(ReturnNew,
4470 HAS_1_TEMPLATE_PARAMS(typename, T),
4471 AND_0_VALUE_PARAMS()) {
4472 return new T();
4473 }
4474
4475 ACTION_TEMPLATE(ReturnNew,
4476 HAS_1_TEMPLATE_PARAMS(typename, T),
4477 AND_1_VALUE_PARAMS(p0)) {
4478 return new T(p0);
4479 }
4480
4481 ACTION_TEMPLATE(ReturnNew,
4482 HAS_1_TEMPLATE_PARAMS(typename, T),
4483 AND_2_VALUE_PARAMS(p0, p1)) {
4484 return new T(p0, p1);
4485 }
4486
4487 ACTION_TEMPLATE(ReturnNew,
4488 HAS_1_TEMPLATE_PARAMS(typename, T),
4489 AND_3_VALUE_PARAMS(p0, p1, p2)) {
4490 return new T(p0, p1, p2);
4491 }
4492
4493 ACTION_TEMPLATE(ReturnNew,
4494 HAS_1_TEMPLATE_PARAMS(typename, T),
4495 AND_4_VALUE_PARAMS(p0, p1, p2, p3)) {
4496 return new T(p0, p1, p2, p3);
4497 }
4498
4499 ACTION_TEMPLATE(ReturnNew,
4500 HAS_1_TEMPLATE_PARAMS(typename, T),
4501 AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)) {
4502 return new T(p0, p1, p2, p3, p4);
4503 }
4504
4505 ACTION_TEMPLATE(ReturnNew,
4506 HAS_1_TEMPLATE_PARAMS(typename, T),
4507 AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)) {
4508 return new T(p0, p1, p2, p3, p4, p5);
4509 }
4510
4511 ACTION_TEMPLATE(ReturnNew,
4512 HAS_1_TEMPLATE_PARAMS(typename, T),
4513 AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)) {
4514 return new T(p0, p1, p2, p3, p4, p5, p6);
4515 }
4516
4517 ACTION_TEMPLATE(ReturnNew,
4518 HAS_1_TEMPLATE_PARAMS(typename, T),
4519 AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)) {
4520 return new T(p0, p1, p2, p3, p4, p5, p6, p7);
4521 }
4522
4523 ACTION_TEMPLATE(ReturnNew,
4524 HAS_1_TEMPLATE_PARAMS(typename, T),
4525 AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8)) {
4526 return new T(p0, p1, p2, p3, p4, p5, p6, p7, p8);
4527 }
4528
4529 ACTION_TEMPLATE(ReturnNew,
4530 HAS_1_TEMPLATE_PARAMS(typename, T),
4531 AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)) {
4532 return new T(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9);
4533 }
4534
4535 #ifdef _MSC_VER
4536 # pragma warning(pop)
4537 #endif
4538
4539 } // namespace testing
4540
4541 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
4542 // This file was GENERATED by command:
4543 // pump.py gmock-generated-function-mockers.h.pump
4544 // DO NOT EDIT BY HAND!!!
4545
4546 // Copyright 2007, Google Inc.
4547 // All rights reserved.
4548 //
4549 // Redistribution and use in source and binary forms, with or without
4550 // modification, are permitted provided that the following conditions are
4551 // met:
4552 //
4553 // * Redistributions of source code must retain the above copyright
4554 // notice, this list of conditions and the following disclaimer.
4555 // * Redistributions in binary form must reproduce the above
4556 // copyright notice, this list of conditions and the following disclaimer
4557 // in the documentation and/or other materials provided with the
4558 // distribution.
4559 // * Neither the name of Google Inc. nor the names of its
4560 // contributors may be used to endorse or promote products derived from
4561 // this software without specific prior written permission.
4562 //
4563 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4564 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
4565 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
4566 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
4567 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
4568 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
4569 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
4570 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
4571 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
4572 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
4573 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4574 //
4575 // Author: [email protected] (Zhanyong Wan)
4576
4577 // Google Mock - a framework for writing C++ mock classes.
4578 //
4579 // This file implements function mockers of various arities.
4580
4581 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
4582 #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
4583
4584 // Copyright 2007, Google Inc.
4585 // All rights reserved.
4586 //
4587 // Redistribution and use in source and binary forms, with or without
4588 // modification, are permitted provided that the following conditions are
4589 // met:
4590 //
4591 // * Redistributions of source code must retain the above copyright
4592 // notice, this list of conditions and the following disclaimer.
4593 // * Redistributions in binary form must reproduce the above
4594 // copyright notice, this list of conditions and the following disclaimer
4595 // in the documentation and/or other materials provided with the
4596 // distribution.
4597 // * Neither the name of Google Inc. nor the names of its
4598 // contributors may be used to endorse or promote products derived from
4599 // this software without specific prior written permission.
4600 //
4601 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4602 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
4603 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
4604 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
4605 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
4606 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
4607 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
4608 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
4609 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
4610 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
4611 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4612 //
4613 // Author: [email protected] (Zhanyong Wan)
4614
4615 // Google Mock - a framework for writing C++ mock classes.
4616 //
4617 // This file implements the ON_CALL() and EXPECT_CALL() macros.
4618 //
4619 // A user can use the ON_CALL() macro to specify the default action of
4620 // a mock method. The syntax is:
4621 //
4622 // ON_CALL(mock_object, Method(argument-matchers))
4623 // .With(multi-argument-matcher)
4624 // .WillByDefault(action);
4625 //
4626 // where the .With() clause is optional.
4627 //
4628 // A user can use the EXPECT_CALL() macro to specify an expectation on
4629 // a mock method. The syntax is:
4630 //
4631 // EXPECT_CALL(mock_object, Method(argument-matchers))
4632 // .With(multi-argument-matchers)
4633 // .Times(cardinality)
4634 // .InSequence(sequences)
4635 // .After(expectations)
4636 // .WillOnce(action)
4637 // .WillRepeatedly(action)
4638 // .RetiresOnSaturation();
4639 //
4640 // where all clauses are optional, and .InSequence()/.After()/
4641 // .WillOnce() can appear any number of times.
4642
4643 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_
4644 #define GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_
4645
4646 #include <map>
4647 #include <set>
4648 #include <sstream>
4649 #include <string>
4650 #include <vector>
4651
4652 #if GTEST_HAS_EXCEPTIONS
4653 # include <stdexcept> // NOLINT
4654 #endif
4655
4656 // Copyright 2007, Google Inc.
4657 // All rights reserved.
4658 //
4659 // Redistribution and use in source and binary forms, with or without
4660 // modification, are permitted provided that the following conditions are
4661 // met:
4662 //
4663 // * Redistributions of source code must retain the above copyright
4664 // notice, this list of conditions and the following disclaimer.
4665 // * Redistributions in binary form must reproduce the above
4666 // copyright notice, this list of conditions and the following disclaimer
4667 // in the documentation and/or other materials provided with the
4668 // distribution.
4669 // * Neither the name of Google Inc. nor the names of its
4670 // contributors may be used to endorse or promote products derived from
4671 // this software without specific prior written permission.
4672 //
4673 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4674 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
4675 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
4676 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
4677 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
4678 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
4679 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
4680 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
4681 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
4682 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
4683 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4684 //
4685 // Author: [email protected] (Zhanyong Wan)
4686
4687 // Google Mock - a framework for writing C++ mock classes.
4688 //
4689 // This file implements some commonly used argument matchers. More
4690 // matchers can be defined by the user implementing the
4691 // MatcherInterface<T> interface if necessary.
4692
4693 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
4694 #define GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
4695
4696 #include <math.h>
4697 #include <algorithm>
4698 #include <iterator>
4699 #include <limits>
4700 #include <ostream> // NOLINT
4701 #include <sstream>
4702 #include <string>
4703 #include <utility>
4704 #include <vector>
4705
4706
4707 #if GTEST_LANG_CXX11
4708 #include <initializer_list> // NOLINT -- must be after gtest.h
4709 #endif
4710
4711 namespace testing {
4712
4713 // To implement a matcher Foo for type T, define:
4714 // 1. a class FooMatcherImpl that implements the
4715 // MatcherInterface<T> interface, and
4716 // 2. a factory function that creates a Matcher<T> object from a
4717 // FooMatcherImpl*.
4718 //
4719 // The two-level delegation design makes it possible to allow a user
4720 // to write "v" instead of "Eq(v)" where a Matcher is expected, which
4721 // is impossible if we pass matchers by pointers. It also eases
4722 // ownership management as Matcher objects can now be copied like
4723 // plain values.
4724
4725 // MatchResultListener is an abstract class. Its << operator can be
4726 // used by a matcher to explain why a value matches or doesn't match.
4727 //
4728 // TODO([email protected]): add method
4729 // bool InterestedInWhy(bool result) const;
4730 // to indicate whether the listener is interested in why the match
4731 // result is 'result'.
4732 class MatchResultListener {
4733 public:
4734 // Creates a listener object with the given underlying ostream. The
4735 // listener does not own the ostream, and does not dereference it
4736 // in the constructor or destructor.
4737 explicit MatchResultListener(::std::ostream* os) : stream_(os) {}
4738 virtual ~MatchResultListener() = 0; // Makes this class abstract.
4739
4740 // Streams x to the underlying ostream; does nothing if the ostream
4741 // is NULL.
4742 template <typename T>
4743 MatchResultListener& operator<<(const T& x) {
4744 if (stream_ != NULL)
4745 *stream_ << x;
4746 return *this;
4747 }
4748
4749 // Returns the underlying ostream.
4750 ::std::ostream* stream() { return stream_; }
4751
4752 // Returns true iff the listener is interested in an explanation of
4753 // the match result. A matcher's MatchAndExplain() method can use
4754 // this information to avoid generating the explanation when no one
4755 // intends to hear it.
4756 bool IsInterested() const { return stream_ != NULL; }
4757
4758 private:
4759 ::std::ostream* const stream_;
4760
4761 GTEST_DISALLOW_COPY_AND_ASSIGN_(MatchResultListener);
4762 };
4763
4764 inline MatchResultListener::~MatchResultListener() {
4765 }
4766
4767 // An instance of a subclass of this knows how to describe itself as a
4768 // matcher.
4769 class MatcherDescriberInterface {
4770 public:
4771 virtual ~MatcherDescriberInterface() {}
4772
4773 // Describes this matcher to an ostream. The function should print
4774 // a verb phrase that describes the property a value matching this
4775 // matcher should have. The subject of the verb phrase is the value
4776 // being matched. For example, the DescribeTo() method of the Gt(7)
4777 // matcher prints "is greater than 7".
4778 virtual void DescribeTo(::std::ostream* os) const = 0;
4779
4780 // Describes the negation of this matcher to an ostream. For
4781 // example, if the description of this matcher is "is greater than
4782 // 7", the negated description could be "is not greater than 7".
4783 // You are not required to override this when implementing
4784 // MatcherInterface, but it is highly advised so that your matcher
4785 // can produce good error messages.
4786 virtual void DescribeNegationTo(::std::ostream* os) const {
4787 *os << "not (";
4788 DescribeTo(os);
4789 *os << ")";
4790 }
4791 };
4792
4793 // The implementation of a matcher.
4794 template <typename T>
4795 class MatcherInterface : public MatcherDescriberInterface {
4796 public:
4797 // Returns true iff the matcher matches x; also explains the match
4798 // result to 'listener' if necessary (see the next paragraph), in
4799 // the form of a non-restrictive relative clause ("which ...",
4800 // "whose ...", etc) that describes x. For example, the
4801 // MatchAndExplain() method of the Pointee(...) matcher should
4802 // generate an explanation like "which points to ...".
4803 //
4804 // Implementations of MatchAndExplain() should add an explanation of
4805 // the match result *if and only if* they can provide additional
4806 // information that's not already present (or not obvious) in the
4807 // print-out of x and the matcher's description. Whether the match
4808 // succeeds is not a factor in deciding whether an explanation is
4809 // needed, as sometimes the caller needs to print a failure message
4810 // when the match succeeds (e.g. when the matcher is used inside
4811 // Not()).
4812 //
4813 // For example, a "has at least 10 elements" matcher should explain
4814 // what the actual element count is, regardless of the match result,
4815 // as it is useful information to the reader; on the other hand, an
4816 // "is empty" matcher probably only needs to explain what the actual
4817 // size is when the match fails, as it's redundant to say that the
4818 // size is 0 when the value is already known to be empty.
4819 //
4820 // You should override this method when defining a new matcher.
4821 //
4822 // It's the responsibility of the caller (Google Mock) to guarantee
4823 // that 'listener' is not NULL. This helps to simplify a matcher's
4824 // implementation when it doesn't care about the performance, as it
4825 // can talk to 'listener' without checking its validity first.
4826 // However, in order to implement dummy listeners efficiently,
4827 // listener->stream() may be NULL.
4828 virtual bool MatchAndExplain(T x, MatchResultListener* listener) const = 0;
4829
4830 // Inherits these methods from MatcherDescriberInterface:
4831 // virtual void DescribeTo(::std::ostream* os) const = 0;
4832 // virtual void DescribeNegationTo(::std::ostream* os) const;
4833 };
4834
4835 // A match result listener that stores the explanation in a string.
4836 class StringMatchResultListener : public MatchResultListener {
4837 public:
4838 StringMatchResultListener() : MatchResultListener(&ss_) {}
4839
4840 // Returns the explanation accumulated so far.
4841 internal::string str() const { return ss_.str(); }
4842
4843 // Clears the explanation accumulated so far.
4844 void Clear() { ss_.str(""); }
4845
4846 private:
4847 ::std::stringstream ss_;
4848
4849 GTEST_DISALLOW_COPY_AND_ASSIGN_(StringMatchResultListener);
4850 };
4851
4852 namespace internal {
4853
4854 // A match result listener that ignores the explanation.
4855 class DummyMatchResultListener : public MatchResultListener {
4856 public:
4857 DummyMatchResultListener() : MatchResultListener(NULL) {}
4858
4859 private:
4860 GTEST_DISALLOW_COPY_AND_ASSIGN_(DummyMatchResultListener);
4861 };
4862
4863 // A match result listener that forwards the explanation to a given
4864 // ostream. The difference between this and MatchResultListener is
4865 // that the former is concrete.
4866 class StreamMatchResultListener : public MatchResultListener {
4867 public:
4868 explicit StreamMatchResultListener(::std::ostream* os)
4869 : MatchResultListener(os) {}
4870
4871 private:
4872 GTEST_DISALLOW_COPY_AND_ASSIGN_(StreamMatchResultListener);
4873 };
4874
4875 // An internal class for implementing Matcher<T>, which will derive
4876 // from it. We put functionalities common to all Matcher<T>
4877 // specializations here to avoid code duplication.
4878 template <typename T>
4879 class MatcherBase {
4880 public:
4881 // Returns true iff the matcher matches x; also explains the match
4882 // result to 'listener'.
4883 bool MatchAndExplain(T x, MatchResultListener* listener) const {
4884 return impl_->MatchAndExplain(x, listener);
4885 }
4886
4887 // Returns true iff this matcher matches x.
4888 bool Matches(T x) const {
4889 DummyMatchResultListener dummy;
4890 return MatchAndExplain(x, &dummy);
4891 }
4892
4893 // Describes this matcher to an ostream.
4894 void DescribeTo(::std::ostream* os) const { impl_->DescribeTo(os); }
4895
4896 // Describes the negation of this matcher to an ostream.
4897 void DescribeNegationTo(::std::ostream* os) const {
4898 impl_->DescribeNegationTo(os);
4899 }
4900
4901 // Explains why x matches, or doesn't match, the matcher.
4902 void ExplainMatchResultTo(T x, ::std::ostream* os) const {
4903 StreamMatchResultListener listener(os);
4904 MatchAndExplain(x, &listener);
4905 }
4906
4907 // Returns the describer for this matcher object; retains ownership
4908 // of the describer, which is only guaranteed to be alive when
4909 // this matcher object is alive.
4910 const MatcherDescriberInterface* GetDescriber() const {
4911 return impl_.get();
4912 }
4913
4914 protected:
4915 MatcherBase() {}
4916
4917 // Constructs a matcher from its implementation.
4918 explicit MatcherBase(const MatcherInterface<T>* impl)
4919 : impl_(impl) {}
4920
4921 virtual ~MatcherBase() {}
4922
4923 private:
4924 // shared_ptr (util/gtl/shared_ptr.h) and linked_ptr have similar
4925 // interfaces. The former dynamically allocates a chunk of memory
4926 // to hold the reference count, while the latter tracks all
4927 // references using a circular linked list without allocating
4928 // memory. It has been observed that linked_ptr performs better in
4929 // typical scenarios. However, shared_ptr can out-perform
4930 // linked_ptr when there are many more uses of the copy constructor
4931 // than the default constructor.
4932 //
4933 // If performance becomes a problem, we should see if using
4934 // shared_ptr helps.
4935 ::testing::internal::linked_ptr<const MatcherInterface<T> > impl_;
4936 };
4937
4938 } // namespace internal
4939
4940 // A Matcher<T> is a copyable and IMMUTABLE (except by assignment)
4941 // object that can check whether a value of type T matches. The
4942 // implementation of Matcher<T> is just a linked_ptr to const
4943 // MatcherInterface<T>, so copying is fairly cheap. Don't inherit
4944 // from Matcher!
4945 template <typename T>
4946 class Matcher : public internal::MatcherBase<T> {
4947 public:
4948 // Constructs a null matcher. Needed for storing Matcher objects in STL
4949 // containers. A default-constructed matcher is not yet initialized. You
4950 // cannot use it until a valid value has been assigned to it.
4951 Matcher() {}
4952
4953 // Constructs a matcher from its implementation.
4954 explicit Matcher(const MatcherInterface<T>* impl)
4955 : internal::MatcherBase<T>(impl) {}
4956
4957 // Implicit constructor here allows people to write
4958 // EXPECT_CALL(foo, Bar(5)) instead of EXPECT_CALL(foo, Bar(Eq(5))) sometimes
4959 Matcher(T value); // NOLINT
4960 };
4961
4962 // The following two specializations allow the user to write str
4963 // instead of Eq(str) and "foo" instead of Eq("foo") when a string
4964 // matcher is expected.
4965 template <>
4966 class GTEST_API_ Matcher<const internal::string&>
4967 : public internal::MatcherBase<const internal::string&> {
4968 public:
4969 Matcher() {}
4970
4971 explicit Matcher(const MatcherInterface<const internal::string&>* impl)
4972 : internal::MatcherBase<const internal::string&>(impl) {}
4973
4974 // Allows the user to write str instead of Eq(str) sometimes, where
4975 // str is a string object.
4976 Matcher(const internal::string& s); // NOLINT
4977
4978 // Allows the user to write "foo" instead of Eq("foo") sometimes.
4979 Matcher(const char* s); // NOLINT
4980 };
4981
4982 template <>
4983 class GTEST_API_ Matcher<internal::string>
4984 : public internal::MatcherBase<internal::string> {
4985 public:
4986 Matcher() {}
4987
4988 explicit Matcher(const MatcherInterface<internal::string>* impl)
4989 : internal::MatcherBase<internal::string>(impl) {}
4990
4991 // Allows the user to write str instead of Eq(str) sometimes, where
4992 // str is a string object.
4993 Matcher(const internal::string& s); // NOLINT
4994
4995 // Allows the user to write "foo" instead of Eq("foo") sometimes.
4996 Matcher(const char* s); // NOLINT
4997 };
4998
4999 #if GTEST_HAS_STRING_PIECE_
5000 // The following two specializations allow the user to write str
5001 // instead of Eq(str) and "foo" instead of Eq("foo") when a StringPiece
5002 // matcher is expected.
5003 template <>
5004 class GTEST_API_ Matcher<const StringPiece&>
5005 : public internal::MatcherBase<const StringPiece&> {
5006 public:
5007 Matcher() {}
5008
5009 explicit Matcher(const MatcherInterface<const StringPiece&>* impl)
5010 : internal::MatcherBase<const StringPiece&>(impl) {}
5011
5012 // Allows the user to write str instead of Eq(str) sometimes, where
5013 // str is a string object.
5014 Matcher(const internal::string& s); // NOLINT
5015
5016 // Allows the user to write "foo" instead of Eq("foo") sometimes.
5017 Matcher(const char* s); // NOLINT
5018
5019 // Allows the user to pass StringPieces directly.
5020 Matcher(StringPiece s); // NOLINT
5021 };
5022
5023 template <>
5024 class GTEST_API_ Matcher<StringPiece>
5025 : public internal::MatcherBase<StringPiece> {
5026 public:
5027 Matcher() {}
5028
5029 explicit Matcher(const MatcherInterface<StringPiece>* impl)
5030 : internal::MatcherBase<StringPiece>(impl) {}
5031
5032 // Allows the user to write str instead of Eq(str) sometimes, where
5033 // str is a string object.
5034 Matcher(const internal::string& s); // NOLINT
5035
5036 // Allows the user to write "foo" instead of Eq("foo") sometimes.
5037 Matcher(const char* s); // NOLINT
5038
5039 // Allows the user to pass StringPieces directly.
5040 Matcher(StringPiece s); // NOLINT
5041 };
5042 #endif // GTEST_HAS_STRING_PIECE_
5043
5044 // The PolymorphicMatcher class template makes it easy to implement a
5045 // polymorphic matcher (i.e. a matcher that can match values of more
5046 // than one type, e.g. Eq(n) and NotNull()).
5047 //
5048 // To define a polymorphic matcher, a user should provide an Impl
5049 // class that has a DescribeTo() method and a DescribeNegationTo()
5050 // method, and define a member function (or member function template)
5051 //
5052 // bool MatchAndExplain(const Value& value,
5053 // MatchResultListener* listener) const;
5054 //
5055 // See the definition of NotNull() for a complete example.
5056 template <class Impl>
5057 class PolymorphicMatcher {
5058 public:
5059 explicit PolymorphicMatcher(const Impl& an_impl) : impl_(an_impl) {}
5060
5061 // Returns a mutable reference to the underlying matcher
5062 // implementation object.
5063 Impl& mutable_impl() { return impl_; }
5064
5065 // Returns an immutable reference to the underlying matcher
5066 // implementation object.
5067 const Impl& impl() const { return impl_; }
5068
5069 template <typename T>
5070 operator Matcher<T>() const {
5071 return Matcher<T>(new MonomorphicImpl<T>(impl_));
5072 }
5073
5074 private:
5075 template <typename T>
5076 class MonomorphicImpl : public MatcherInterface<T> {
5077 public:
5078 explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {}
5079
5080 virtual void DescribeTo(::std::ostream* os) const {
5081 impl_.DescribeTo(os);
5082 }
5083
5084 virtual void DescribeNegationTo(::std::ostream* os) const {
5085 impl_.DescribeNegationTo(os);
5086 }
5087
5088 virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
5089 return impl_.MatchAndExplain(x, listener);
5090 }
5091
5092 private:
5093 const Impl impl_;
5094
5095 GTEST_DISALLOW_ASSIGN_(MonomorphicImpl);
5096 };
5097
5098 Impl impl_;
5099
5100 GTEST_DISALLOW_ASSIGN_(PolymorphicMatcher);
5101 };
5102
5103 // Creates a matcher from its implementation. This is easier to use
5104 // than the Matcher<T> constructor as it doesn't require you to
5105 // explicitly write the template argument, e.g.
5106 //
5107 // MakeMatcher(foo);
5108 // vs
5109 // Matcher<const string&>(foo);
5110 template <typename T>
5111 inline Matcher<T> MakeMatcher(const MatcherInterface<T>* impl) {
5112 return Matcher<T>(impl);
5113 }
5114
5115 // Creates a polymorphic matcher from its implementation. This is
5116 // easier to use than the PolymorphicMatcher<Impl> constructor as it
5117 // doesn't require you to explicitly write the template argument, e.g.
5118 //
5119 // MakePolymorphicMatcher(foo);
5120 // vs
5121 // PolymorphicMatcher<TypeOfFoo>(foo);
5122 template <class Impl>
5123 inline PolymorphicMatcher<Impl> MakePolymorphicMatcher(const Impl& impl) {
5124 return PolymorphicMatcher<Impl>(impl);
5125 }
5126
5127 // Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION
5128 // and MUST NOT BE USED IN USER CODE!!!
5129 namespace internal {
5130
5131 // The MatcherCastImpl class template is a helper for implementing
5132 // MatcherCast(). We need this helper in order to partially
5133 // specialize the implementation of MatcherCast() (C++ allows
5134 // class/struct templates to be partially specialized, but not
5135 // function templates.).
5136
5137 // This general version is used when MatcherCast()'s argument is a
5138 // polymorphic matcher (i.e. something that can be converted to a
5139 // Matcher but is not one yet; for example, Eq(value)) or a value (for
5140 // example, "hello").
5141 template <typename T, typename M>
5142 class MatcherCastImpl {
5143 public:
5144 static Matcher<T> Cast(M polymorphic_matcher_or_value) {
5145 // M can be a polymorhic matcher, in which case we want to use
5146 // its conversion operator to create Matcher<T>. Or it can be a value
5147 // that should be passed to the Matcher<T>'s constructor.
5148 //
5149 // We can't call Matcher<T>(polymorphic_matcher_or_value) when M is a
5150 // polymorphic matcher because it'll be ambiguous if T has an implicit
5151 // constructor from M (this usually happens when T has an implicit
5152 // constructor from any type).
5153 //
5154 // It won't work to unconditionally implict_cast
5155 // polymorphic_matcher_or_value to Matcher<T> because it won't trigger
5156 // a user-defined conversion from M to T if one exists (assuming M is
5157 // a value).
5158 return CastImpl(
5159 polymorphic_matcher_or_value,
5160 BooleanConstant<
5161 internal::ImplicitlyConvertible<M, Matcher<T> >::value>());
5162 }
5163
5164 private:
5165 static Matcher<T> CastImpl(M value, BooleanConstant<false>) {
5166 // M can't be implicitly converted to Matcher<T>, so M isn't a polymorphic
5167 // matcher. It must be a value then. Use direct initialization to create
5168 // a matcher.
5169 return Matcher<T>(ImplicitCast_<T>(value));
5170 }
5171
5172 static Matcher<T> CastImpl(M polymorphic_matcher_or_value,
5173 BooleanConstant<true>) {
5174 // M is implicitly convertible to Matcher<T>, which means that either
5175 // M is a polymorhpic matcher or Matcher<T> has an implicit constructor
5176 // from M. In both cases using the implicit conversion will produce a
5177 // matcher.
5178 //
5179 // Even if T has an implicit constructor from M, it won't be called because
5180 // creating Matcher<T> would require a chain of two user-defined conversions
5181 // (first to create T from M and then to create Matcher<T> from T).
5182 return polymorphic_matcher_or_value;
5183 }
5184 };
5185
5186 // This more specialized version is used when MatcherCast()'s argument
5187 // is already a Matcher. This only compiles when type T can be
5188 // statically converted to type U.
5189 template <typename T, typename U>
5190 class MatcherCastImpl<T, Matcher<U> > {
5191 public:
5192 static Matcher<T> Cast(const Matcher<U>& source_matcher) {
5193 return Matcher<T>(new Impl(source_matcher));
5194 }
5195
5196 private:
5197 class Impl : public MatcherInterface<T> {
5198 public:
5199 explicit Impl(const Matcher<U>& source_matcher)
5200 : source_matcher_(source_matcher) {}
5201
5202 // We delegate the matching logic to the source matcher.
5203 virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
5204 return source_matcher_.MatchAndExplain(static_cast<U>(x), listener);
5205 }
5206
5207 virtual void DescribeTo(::std::ostream* os) const {
5208 source_matcher_.DescribeTo(os);
5209 }
5210
5211 virtual void DescribeNegationTo(::std::ostream* os) const {
5212 source_matcher_.DescribeNegationTo(os);
5213 }
5214
5215 private:
5216 const Matcher<U> source_matcher_;
5217
5218 GTEST_DISALLOW_ASSIGN_(Impl);
5219 };
5220 };
5221
5222 // This even more specialized version is used for efficiently casting
5223 // a matcher to its own type.
5224 template <typename T>
5225 class MatcherCastImpl<T, Matcher<T> > {
5226 public:
5227 static Matcher<T> Cast(const Matcher<T>& matcher) { return matcher; }
5228 };
5229
5230 } // namespace internal
5231
5232 // In order to be safe and clear, casting between different matcher
5233 // types is done explicitly via MatcherCast<T>(m), which takes a
5234 // matcher m and returns a Matcher<T>. It compiles only when T can be
5235 // statically converted to the argument type of m.
5236 template <typename T, typename M>
5237 inline Matcher<T> MatcherCast(M matcher) {
5238 return internal::MatcherCastImpl<T, M>::Cast(matcher);
5239 }
5240
5241 // Implements SafeMatcherCast().
5242 //
5243 // We use an intermediate class to do the actual safe casting as Nokia's
5244 // Symbian compiler cannot decide between
5245 // template <T, M> ... (M) and
5246 // template <T, U> ... (const Matcher<U>&)
5247 // for function templates but can for member function templates.
5248 template <typename T>
5249 class SafeMatcherCastImpl {
5250 public:
5251 // This overload handles polymorphic matchers and values only since
5252 // monomorphic matchers are handled by the next one.
5253 template <typename M>
5254 static inline Matcher<T> Cast(M polymorphic_matcher_or_value) {
5255 return internal::MatcherCastImpl<T, M>::Cast(polymorphic_matcher_or_value);
5256 }
5257
5258 // This overload handles monomorphic matchers.
5259 //
5260 // In general, if type T can be implicitly converted to type U, we can
5261 // safely convert a Matcher<U> to a Matcher<T> (i.e. Matcher is
5262 // contravariant): just keep a copy of the original Matcher<U>, convert the
5263 // argument from type T to U, and then pass it to the underlying Matcher<U>.
5264 // The only exception is when U is a reference and T is not, as the
5265 // underlying Matcher<U> may be interested in the argument's address, which
5266 // is not preserved in the conversion from T to U.
5267 template <typename U>
5268 static inline Matcher<T> Cast(const Matcher<U>& matcher) {
5269 // Enforce that T can be implicitly converted to U.
5270 GTEST_COMPILE_ASSERT_((internal::ImplicitlyConvertible<T, U>::value),
5271 T_must_be_implicitly_convertible_to_U);
5272 // Enforce that we are not converting a non-reference type T to a reference
5273 // type U.
5274 GTEST_COMPILE_ASSERT_(
5275 internal::is_reference<T>::value || !internal::is_reference<U>::value,
5276 cannot_convert_non_referentce_arg_to_reference);
5277 // In case both T and U are arithmetic types, enforce that the
5278 // conversion is not lossy.
5279 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(T) RawT;
5280 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(U) RawU;
5281 const bool kTIsOther = GMOCK_KIND_OF_(RawT) == internal::kOther;
5282 const bool kUIsOther = GMOCK_KIND_OF_(RawU) == internal::kOther;
5283 GTEST_COMPILE_ASSERT_(
5284 kTIsOther || kUIsOther ||
5285 (internal::LosslessArithmeticConvertible<RawT, RawU>::value),
5286 conversion_of_arithmetic_types_must_be_lossless);
5287 return MatcherCast<T>(matcher);
5288 }
5289 };
5290
5291 template <typename T, typename M>
5292 inline Matcher<T> SafeMatcherCast(const M& polymorphic_matcher) {
5293 return SafeMatcherCastImpl<T>::Cast(polymorphic_matcher);
5294 }
5295
5296 // A<T>() returns a matcher that matches any value of type T.
5297 template <typename T>
5298 Matcher<T> A();
5299
5300 // Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION
5301 // and MUST NOT BE USED IN USER CODE!!!
5302 namespace internal {
5303
5304 // If the explanation is not empty, prints it to the ostream.
5305 inline void PrintIfNotEmpty(const internal::string& explanation,
5306 ::std::ostream* os) {
5307 if (explanation != "" && os != NULL) {
5308 *os << ", " << explanation;
5309 }
5310 }
5311
5312 // Returns true if the given type name is easy to read by a human.
5313 // This is used to decide whether printing the type of a value might
5314 // be helpful.
5315 inline bool IsReadableTypeName(const string& type_name) {
5316 // We consider a type name readable if it's short or doesn't contain
5317 // a template or function type.
5318 return (type_name.length() <= 20 ||
5319 type_name.find_first_of("<(") == string::npos);
5320 }
5321
5322 // Matches the value against the given matcher, prints the value and explains
5323 // the match result to the listener. Returns the match result.
5324 // 'listener' must not be NULL.
5325 // Value cannot be passed by const reference, because some matchers take a
5326 // non-const argument.
5327 template <typename Value, typename T>
5328 bool MatchPrintAndExplain(Value& value, const Matcher<T>& matcher,
5329 MatchResultListener* listener) {
5330 if (!listener->IsInterested()) {
5331 // If the listener is not interested, we do not need to construct the
5332 // inner explanation.
5333 return matcher.Matches(value);
5334 }
5335
5336 StringMatchResultListener inner_listener;
5337 const bool match = matcher.MatchAndExplain(value, &inner_listener);
5338
5339 UniversalPrint(value, listener->stream());
5340 #if GTEST_HAS_RTTI
5341 const string& type_name = GetTypeName<Value>();
5342 if (IsReadableTypeName(type_name))
5343 *listener->stream() << " (of type " << type_name << ")";
5344 #endif
5345 PrintIfNotEmpty(inner_listener.str(), listener->stream());
5346
5347 return match;
5348 }
5349
5350 // An internal helper class for doing compile-time loop on a tuple's
5351 // fields.
5352 template <size_t N>
5353 class TuplePrefix {
5354 public:
5355 // TuplePrefix<N>::Matches(matcher_tuple, value_tuple) returns true
5356 // iff the first N fields of matcher_tuple matches the first N
5357 // fields of value_tuple, respectively.
5358 template <typename MatcherTuple, typename ValueTuple>
5359 static bool Matches(const MatcherTuple& matcher_tuple,
5360 const ValueTuple& value_tuple) {
5361 using ::std::tr1::get;
5362 return TuplePrefix<N - 1>::Matches(matcher_tuple, value_tuple)
5363 && get<N - 1>(matcher_tuple).Matches(get<N - 1>(value_tuple));
5364 }
5365
5366 // TuplePrefix<N>::ExplainMatchFailuresTo(matchers, values, os)
5367 // describes failures in matching the first N fields of matchers
5368 // against the first N fields of values. If there is no failure,
5369 // nothing will be streamed to os.
5370 template <typename MatcherTuple, typename ValueTuple>
5371 static void ExplainMatchFailuresTo(const MatcherTuple& matchers,
5372 const ValueTuple& values,
5373 ::std::ostream* os) {
5374 using ::std::tr1::tuple_element;
5375 using ::std::tr1::get;
5376
5377 // First, describes failures in the first N - 1 fields.
5378 TuplePrefix<N - 1>::ExplainMatchFailuresTo(matchers, values, os);
5379
5380 // Then describes the failure (if any) in the (N - 1)-th (0-based)
5381 // field.
5382 typename tuple_element<N - 1, MatcherTuple>::type matcher =
5383 get<N - 1>(matchers);
5384 typedef typename tuple_element<N - 1, ValueTuple>::type Value;
5385 Value value = get<N - 1>(values);
5386 StringMatchResultListener listener;
5387 if (!matcher.MatchAndExplain(value, &listener)) {
5388 // TODO(wan): include in the message the name of the parameter
5389 // as used in MOCK_METHOD*() when possible.
5390 *os << " Expected arg #" << N - 1 << ": ";
5391 get<N - 1>(matchers).DescribeTo(os);
5392 *os << "\n Actual: ";
5393 // We remove the reference in type Value to prevent the
5394 // universal printer from printing the address of value, which
5395 // isn't interesting to the user most of the time. The
5396 // matcher's MatchAndExplain() method handles the case when
5397 // the address is interesting.
5398 internal::UniversalPrint(value, os);
5399 PrintIfNotEmpty(listener.str(), os);
5400 *os << "\n";
5401 }
5402 }
5403 };
5404
5405 // The base case.
5406 template <>
5407 class TuplePrefix<0> {
5408 public:
5409 template <typename MatcherTuple, typename ValueTuple>
5410 static bool Matches(const MatcherTuple& /* matcher_tuple */,
5411 const ValueTuple& /* value_tuple */) {
5412 return true;
5413 }
5414
5415 template <typename MatcherTuple, typename ValueTuple>
5416 static void ExplainMatchFailuresTo(const MatcherTuple& /* matchers */,
5417 const ValueTuple& /* values */,
5418 ::std::ostream* /* os */) {}
5419 };
5420
5421 // TupleMatches(matcher_tuple, value_tuple) returns true iff all
5422 // matchers in matcher_tuple match the corresponding fields in
5423 // value_tuple. It is a compiler error if matcher_tuple and
5424 // value_tuple have different number of fields or incompatible field
5425 // types.
5426 template <typename MatcherTuple, typename ValueTuple>
5427 bool TupleMatches(const MatcherTuple& matcher_tuple,
5428 const ValueTuple& value_tuple) {
5429 using ::std::tr1::tuple_size;
5430 // Makes sure that matcher_tuple and value_tuple have the same
5431 // number of fields.
5432 GTEST_COMPILE_ASSERT_(tuple_size<MatcherTuple>::value ==
5433 tuple_size<ValueTuple>::value,
5434 matcher_and_value_have_different_numbers_of_fields);
5435 return TuplePrefix<tuple_size<ValueTuple>::value>::
5436 Matches(matcher_tuple, value_tuple);
5437 }
5438
5439 // Describes failures in matching matchers against values. If there
5440 // is no failure, nothing will be streamed to os.
5441 template <typename MatcherTuple, typename ValueTuple>
5442 void ExplainMatchFailureTupleTo(const MatcherTuple& matchers,
5443 const ValueTuple& values,
5444 ::std::ostream* os) {
5445 using ::std::tr1::tuple_size;
5446 TuplePrefix<tuple_size<MatcherTuple>::value>::ExplainMatchFailuresTo(
5447 matchers, values, os);
5448 }
5449
5450 // TransformTupleValues and its helper.
5451 //
5452 // TransformTupleValuesHelper hides the internal machinery that
5453 // TransformTupleValues uses to implement a tuple traversal.
5454 template <typename Tuple, typename Func, typename OutIter>
5455 class TransformTupleValuesHelper {
5456 private:
5457 typedef typename ::std::tr1::tuple_size<Tuple> TupleSize;
5458
5459 public:
5460 // For each member of tuple 't', taken in order, evaluates '*out++ = f(t)'.
5461 // Returns the final value of 'out' in case the caller needs it.
5462 static OutIter Run(Func f, const Tuple& t, OutIter out) {
5463 return IterateOverTuple<Tuple, TupleSize::value>()(f, t, out);
5464 }
5465
5466 private:
5467 template <typename Tup, size_t kRemainingSize>
5468 struct IterateOverTuple {
5469 OutIter operator() (Func f, const Tup& t, OutIter out) const {
5470 *out++ = f(::std::tr1::get<TupleSize::value - kRemainingSize>(t));
5471 return IterateOverTuple<Tup, kRemainingSize - 1>()(f, t, out);
5472 }
5473 };
5474 template <typename Tup>
5475 struct IterateOverTuple<Tup, 0> {
5476 OutIter operator() (Func /* f */, const Tup& /* t */, OutIter out) const {
5477 return out;
5478 }
5479 };
5480 };
5481
5482 // Successively invokes 'f(element)' on each element of the tuple 't',
5483 // appending each result to the 'out' iterator. Returns the final value
5484 // of 'out'.
5485 template <typename Tuple, typename Func, typename OutIter>
5486 OutIter TransformTupleValues(Func f, const Tuple& t, OutIter out) {
5487 return TransformTupleValuesHelper<Tuple, Func, OutIter>::Run(f, t, out);
5488 }
5489
5490 // Implements A<T>().
5491 template <typename T>
5492 class AnyMatcherImpl : public MatcherInterface<T> {
5493 public:
5494 virtual bool MatchAndExplain(
5495 T /* x */, MatchResultListener* /* listener */) const { return true; }
5496 virtual void DescribeTo(::std::ostream* os) const { *os << "is anything"; }
5497 virtual void DescribeNegationTo(::std::ostream* os) const {
5498 // This is mostly for completeness' safe, as it's not very useful
5499 // to write Not(A<bool>()). However we cannot completely rule out
5500 // such a possibility, and it doesn't hurt to be prepared.
5501 *os << "never matches";
5502 }
5503 };
5504
5505 // Implements _, a matcher that matches any value of any
5506 // type. This is a polymorphic matcher, so we need a template type
5507 // conversion operator to make it appearing as a Matcher<T> for any
5508 // type T.
5509 class AnythingMatcher {
5510 public:
5511 template <typename T>
5512 operator Matcher<T>() const { return A<T>(); }
5513 };
5514
5515 // Implements a matcher that compares a given value with a
5516 // pre-supplied value using one of the ==, <=, <, etc, operators. The
5517 // two values being compared don't have to have the same type.
5518 //
5519 // The matcher defined here is polymorphic (for example, Eq(5) can be
5520 // used to match an int, a short, a double, etc). Therefore we use
5521 // a template type conversion operator in the implementation.
5522 //
5523 // We define this as a macro in order to eliminate duplicated source
5524 // code.
5525 //
5526 // The following template definition assumes that the Rhs parameter is
5527 // a "bare" type (i.e. neither 'const T' nor 'T&').
5528 #define GMOCK_IMPLEMENT_COMPARISON_MATCHER_( \
5529 name, op, relation, negated_relation) \
5530 template <typename Rhs> class name##Matcher { \
5531 public: \
5532 explicit name##Matcher(const Rhs& rhs) : rhs_(rhs) {} \
5533 template <typename Lhs> \
5534 operator Matcher<Lhs>() const { \
5535 return MakeMatcher(new Impl<Lhs>(rhs_)); \
5536 } \
5537 private: \
5538 template <typename Lhs> \
5539 class Impl : public MatcherInterface<Lhs> { \
5540 public: \
5541 explicit Impl(const Rhs& rhs) : rhs_(rhs) {} \
5542 virtual bool MatchAndExplain(\
5543 Lhs lhs, MatchResultListener* /* listener */) const { \
5544 return lhs op rhs_; \
5545 } \
5546 virtual void DescribeTo(::std::ostream* os) const { \
5547 *os << relation " "; \
5548 UniversalPrint(rhs_, os); \
5549 } \
5550 virtual void DescribeNegationTo(::std::ostream* os) const { \
5551 *os << negated_relation " "; \
5552 UniversalPrint(rhs_, os); \
5553 } \
5554 private: \
5555 Rhs rhs_; \
5556 GTEST_DISALLOW_ASSIGN_(Impl); \
5557 }; \
5558 Rhs rhs_; \
5559 GTEST_DISALLOW_ASSIGN_(name##Matcher); \
5560 }
5561
5562 // Implements Eq(v), Ge(v), Gt(v), Le(v), Lt(v), and Ne(v)
5563 // respectively.
5564 GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Eq, ==, "is equal to", "isn't equal to");
5565 GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Ge, >=, "is >=", "isn't >=");
5566 GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Gt, >, "is >", "isn't >");
5567 GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Le, <=, "is <=", "isn't <=");
5568 GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Lt, <, "is <", "isn't <");
5569 GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Ne, !=, "isn't equal to", "is equal to");
5570
5571 #undef GMOCK_IMPLEMENT_COMPARISON_MATCHER_
5572
5573 // Implements the polymorphic IsNull() matcher, which matches any raw or smart
5574 // pointer that is NULL.
5575 class IsNullMatcher {
5576 public:
5577 template <typename Pointer>
5578 bool MatchAndExplain(const Pointer& p,
5579 MatchResultListener* /* listener */) const {
5580 return GetRawPointer(p) == NULL;
5581 }
5582
5583 void DescribeTo(::std::ostream* os) const { *os << "is NULL"; }
5584 void DescribeNegationTo(::std::ostream* os) const {
5585 *os << "isn't NULL";
5586 }
5587 };
5588
5589 // Implements the polymorphic NotNull() matcher, which matches any raw or smart
5590 // pointer that is not NULL.
5591 class NotNullMatcher {
5592 public:
5593 template <typename Pointer>
5594 bool MatchAndExplain(const Pointer& p,
5595 MatchResultListener* /* listener */) const {
5596 return GetRawPointer(p) != NULL;
5597 }
5598
5599 void DescribeTo(::std::ostream* os) const { *os << "isn't NULL"; }
5600 void DescribeNegationTo(::std::ostream* os) const {
5601 *os << "is NULL";
5602 }
5603 };
5604
5605 // Ref(variable) matches any argument that is a reference to
5606 // 'variable'. This matcher is polymorphic as it can match any
5607 // super type of the type of 'variable'.
5608 //
5609 // The RefMatcher template class implements Ref(variable). It can
5610 // only be instantiated with a reference type. This prevents a user
5611 // from mistakenly using Ref(x) to match a non-reference function
5612 // argument. For example, the following will righteously cause a
5613 // compiler error:
5614 //
5615 // int n;
5616 // Matcher<int> m1 = Ref(n); // This won't compile.
5617 // Matcher<int&> m2 = Ref(n); // This will compile.
5618 template <typename T>
5619 class RefMatcher;
5620
5621 template <typename T>
5622 class RefMatcher<T&> {
5623 // Google Mock is a generic framework and thus needs to support
5624 // mocking any function types, including those that take non-const
5625 // reference arguments. Therefore the template parameter T (and
5626 // Super below) can be instantiated to either a const type or a
5627 // non-const type.
5628 public:
5629 // RefMatcher() takes a T& instead of const T&, as we want the
5630 // compiler to catch using Ref(const_value) as a matcher for a
5631 // non-const reference.
5632 explicit RefMatcher(T& x) : object_(x) {} // NOLINT
5633
5634 template <typename Super>
5635 operator Matcher<Super&>() const {
5636 // By passing object_ (type T&) to Impl(), which expects a Super&,
5637 // we make sure that Super is a super type of T. In particular,
5638 // this catches using Ref(const_value) as a matcher for a
5639 // non-const reference, as you cannot implicitly convert a const
5640 // reference to a non-const reference.
5641 return MakeMatcher(new Impl<Super>(object_));
5642 }
5643
5644 private:
5645 template <typename Super>
5646 class Impl : public MatcherInterface<Super&> {
5647 public:
5648 explicit Impl(Super& x) : object_(x) {} // NOLINT
5649
5650 // MatchAndExplain() takes a Super& (as opposed to const Super&)
5651 // in order to match the interface MatcherInterface<Super&>.
5652 virtual bool MatchAndExplain(
5653 Super& x, MatchResultListener* listener) const {
5654 *listener << "which is located @" << static_cast<const void*>(&x);
5655 return &x == &object_;
5656 }
5657
5658 virtual void DescribeTo(::std::ostream* os) const {
5659 *os << "references the variable ";
5660 UniversalPrinter<Super&>::Print(object_, os);
5661 }
5662
5663 virtual void DescribeNegationTo(::std::ostream* os) const {
5664 *os << "does not reference the variable ";
5665 UniversalPrinter<Super&>::Print(object_, os);
5666 }
5667
5668 private:
5669 const Super& object_;
5670
5671 GTEST_DISALLOW_ASSIGN_(Impl);
5672 };
5673
5674 T& object_;
5675
5676 GTEST_DISALLOW_ASSIGN_(RefMatcher);
5677 };
5678
5679 // Polymorphic helper functions for narrow and wide string matchers.
5680 inline bool CaseInsensitiveCStringEquals(const char* lhs, const char* rhs) {
5681 return String::CaseInsensitiveCStringEquals(lhs, rhs);
5682 }
5683
5684 inline bool CaseInsensitiveCStringEquals(const wchar_t* lhs,
5685 const wchar_t* rhs) {
5686 return String::CaseInsensitiveWideCStringEquals(lhs, rhs);
5687 }
5688
5689 // String comparison for narrow or wide strings that can have embedded NUL
5690 // characters.
5691 template <typename StringType>
5692 bool CaseInsensitiveStringEquals(const StringType& s1,
5693 const StringType& s2) {
5694 // Are the heads equal?
5695 if (!CaseInsensitiveCStringEquals(s1.c_str(), s2.c_str())) {
5696 return false;
5697 }
5698
5699 // Skip the equal heads.
5700 const typename StringType::value_type nul = 0;
5701 const size_t i1 = s1.find(nul), i2 = s2.find(nul);
5702
5703 // Are we at the end of either s1 or s2?
5704 if (i1 == StringType::npos || i2 == StringType::npos) {
5705 return i1 == i2;
5706 }
5707
5708 // Are the tails equal?
5709 return CaseInsensitiveStringEquals(s1.substr(i1 + 1), s2.substr(i2 + 1));
5710 }
5711
5712 // String matchers.
5713
5714 // Implements equality-based string matchers like StrEq, StrCaseNe, and etc.
5715 template <typename StringType>
5716 class StrEqualityMatcher {
5717 public:
5718 StrEqualityMatcher(const StringType& str, bool expect_eq,
5719 bool case_sensitive)
5720 : string_(str), expect_eq_(expect_eq), case_sensitive_(case_sensitive) {}
5721
5722 // Accepts pointer types, particularly:
5723 // const char*
5724 // char*
5725 // const wchar_t*
5726 // wchar_t*
5727 template <typename CharType>
5728 bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
5729 if (s == NULL) {
5730 return !expect_eq_;
5731 }
5732 return MatchAndExplain(StringType(s), listener);
5733 }
5734
5735 // Matches anything that can convert to StringType.
5736 //
5737 // This is a template, not just a plain function with const StringType&,
5738 // because StringPiece has some interfering non-explicit constructors.
5739 template <typename MatcheeStringType>
5740 bool MatchAndExplain(const MatcheeStringType& s,
5741 MatchResultListener* /* listener */) const {
5742 const StringType& s2(s);
5743 const bool eq = case_sensitive_ ? s2 == string_ :
5744 CaseInsensitiveStringEquals(s2, string_);
5745 return expect_eq_ == eq;
5746 }
5747
5748 void DescribeTo(::std::ostream* os) const {
5749 DescribeToHelper(expect_eq_, os);
5750 }
5751
5752 void DescribeNegationTo(::std::ostream* os) const {
5753 DescribeToHelper(!expect_eq_, os);
5754 }
5755
5756 private:
5757 void DescribeToHelper(bool expect_eq, ::std::ostream* os) const {
5758 *os << (expect_eq ? "is " : "isn't ");
5759 *os << "equal to ";
5760 if (!case_sensitive_) {
5761 *os << "(ignoring case) ";
5762 }
5763 UniversalPrint(string_, os);
5764 }
5765
5766 const StringType string_;
5767 const bool expect_eq_;
5768 const bool case_sensitive_;
5769
5770 GTEST_DISALLOW_ASSIGN_(StrEqualityMatcher);
5771 };
5772
5773 // Implements the polymorphic HasSubstr(substring) matcher, which
5774 // can be used as a Matcher<T> as long as T can be converted to a
5775 // string.
5776 template <typename StringType>
5777 class HasSubstrMatcher {
5778 public:
5779 explicit HasSubstrMatcher(const StringType& substring)
5780 : substring_(substring) {}
5781
5782 // Accepts pointer types, particularly:
5783 // const char*
5784 // char*
5785 // const wchar_t*
5786 // wchar_t*
5787 template <typename CharType>
5788 bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
5789 return s != NULL && MatchAndExplain(StringType(s), listener);
5790 }
5791
5792 // Matches anything that can convert to StringType.
5793 //
5794 // This is a template, not just a plain function with const StringType&,
5795 // because StringPiece has some interfering non-explicit constructors.
5796 template <typename MatcheeStringType>
5797 bool MatchAndExplain(const MatcheeStringType& s,
5798 MatchResultListener* /* listener */) const {
5799 const StringType& s2(s);
5800 return s2.find(substring_) != StringType::npos;
5801 }
5802
5803 // Describes what this matcher matches.
5804 void DescribeTo(::std::ostream* os) const {
5805 *os << "has substring ";
5806 UniversalPrint(substring_, os);
5807 }
5808
5809 void DescribeNegationTo(::std::ostream* os) const {
5810 *os << "has no substring ";
5811 UniversalPrint(substring_, os);
5812 }
5813
5814 private:
5815 const StringType substring_;
5816
5817 GTEST_DISALLOW_ASSIGN_(HasSubstrMatcher);
5818 };
5819
5820 // Implements the polymorphic StartsWith(substring) matcher, which
5821 // can be used as a Matcher<T> as long as T can be converted to a
5822 // string.
5823 template <typename StringType>
5824 class StartsWithMatcher {
5825 public:
5826 explicit StartsWithMatcher(const StringType& prefix) : prefix_(prefix) {
5827 }
5828
5829 // Accepts pointer types, particularly:
5830 // const char*
5831 // char*
5832 // const wchar_t*
5833 // wchar_t*
5834 template <typename CharType>
5835 bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
5836 return s != NULL && MatchAndExplain(StringType(s), listener);
5837 }
5838
5839 // Matches anything that can convert to StringType.
5840 //
5841 // This is a template, not just a plain function with const StringType&,
5842 // because StringPiece has some interfering non-explicit constructors.
5843 template <typename MatcheeStringType>
5844 bool MatchAndExplain(const MatcheeStringType& s,
5845 MatchResultListener* /* listener */) const {
5846 const StringType& s2(s);
5847 return s2.length() >= prefix_.length() &&
5848 s2.substr(0, prefix_.length()) == prefix_;
5849 }
5850
5851 void DescribeTo(::std::ostream* os) const {
5852 *os << "starts with ";
5853 UniversalPrint(prefix_, os);
5854 }
5855
5856 void DescribeNegationTo(::std::ostream* os) const {
5857 *os << "doesn't start with ";
5858 UniversalPrint(prefix_, os);
5859 }
5860
5861 private:
5862 const StringType prefix_;
5863
5864 GTEST_DISALLOW_ASSIGN_(StartsWithMatcher);
5865 };
5866
5867 // Implements the polymorphic EndsWith(substring) matcher, which
5868 // can be used as a Matcher<T> as long as T can be converted to a
5869 // string.
5870 template <typename StringType>
5871 class EndsWithMatcher {
5872 public:
5873 explicit EndsWithMatcher(const StringType& suffix) : suffix_(suffix) {}
5874
5875 // Accepts pointer types, particularly:
5876 // const char*
5877 // char*
5878 // const wchar_t*
5879 // wchar_t*
5880 template <typename CharType>
5881 bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
5882 return s != NULL && MatchAndExplain(StringType(s), listener);
5883 }
5884
5885 // Matches anything that can convert to StringType.
5886 //
5887 // This is a template, not just a plain function with const StringType&,
5888 // because StringPiece has some interfering non-explicit constructors.
5889 template <typename MatcheeStringType>
5890 bool MatchAndExplain(const MatcheeStringType& s,
5891 MatchResultListener* /* listener */) const {
5892 const StringType& s2(s);
5893 return s2.length() >= suffix_.length() &&
5894 s2.substr(s2.length() - suffix_.length()) == suffix_;
5895 }
5896
5897 void DescribeTo(::std::ostream* os) const {
5898 *os << "ends with ";
5899 UniversalPrint(suffix_, os);
5900 }
5901
5902 void DescribeNegationTo(::std::ostream* os) const {
5903 *os << "doesn't end with ";
5904 UniversalPrint(suffix_, os);
5905 }
5906
5907 private:
5908 const StringType suffix_;
5909
5910 GTEST_DISALLOW_ASSIGN_(EndsWithMatcher);
5911 };
5912
5913 // Implements polymorphic matchers MatchesRegex(regex) and
5914 // ContainsRegex(regex), which can be used as a Matcher<T> as long as
5915 // T can be converted to a string.
5916 class MatchesRegexMatcher {
5917 public:
5918 MatchesRegexMatcher(const RE* regex, bool full_match)
5919 : regex_(regex), full_match_(full_match) {}
5920
5921 // Accepts pointer types, particularly:
5922 // const char*
5923 // char*
5924 // const wchar_t*
5925 // wchar_t*
5926 template <typename CharType>
5927 bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
5928 return s != NULL && MatchAndExplain(internal::string(s), listener);
5929 }
5930
5931 // Matches anything that can convert to internal::string.
5932 //
5933 // This is a template, not just a plain function with const internal::string&,
5934 // because StringPiece has some interfering non-explicit constructors.
5935 template <class MatcheeStringType>
5936 bool MatchAndExplain(const MatcheeStringType& s,
5937 MatchResultListener* /* listener */) const {
5938 const internal::string& s2(s);
5939 return full_match_ ? RE::FullMatch(s2, *regex_) :
5940 RE::PartialMatch(s2, *regex_);
5941 }
5942
5943 void DescribeTo(::std::ostream* os) const {
5944 *os << (full_match_ ? "matches" : "contains")
5945 << " regular expression ";
5946 UniversalPrinter<internal::string>::Print(regex_->pattern(), os);
5947 }
5948
5949 void DescribeNegationTo(::std::ostream* os) const {
5950 *os << "doesn't " << (full_match_ ? "match" : "contain")
5951 << " regular expression ";
5952 UniversalPrinter<internal::string>::Print(regex_->pattern(), os);
5953 }
5954
5955 private:
5956 const internal::linked_ptr<const RE> regex_;
5957 const bool full_match_;
5958
5959 GTEST_DISALLOW_ASSIGN_(MatchesRegexMatcher);
5960 };
5961
5962 // Implements a matcher that compares the two fields of a 2-tuple
5963 // using one of the ==, <=, <, etc, operators. The two fields being
5964 // compared don't have to have the same type.
5965 //
5966 // The matcher defined here is polymorphic (for example, Eq() can be
5967 // used to match a tuple<int, short>, a tuple<const long&, double>,
5968 // etc). Therefore we use a template type conversion operator in the
5969 // implementation.
5970 //
5971 // We define this as a macro in order to eliminate duplicated source
5972 // code.
5973 #define GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(name, op, relation) \
5974 class name##2Matcher { \
5975 public: \
5976 template <typename T1, typename T2> \
5977 operator Matcher< ::std::tr1::tuple<T1, T2> >() const { \
5978 return MakeMatcher(new Impl< ::std::tr1::tuple<T1, T2> >); \
5979 } \
5980 template <typename T1, typename T2> \
5981 operator Matcher<const ::std::tr1::tuple<T1, T2>&>() const { \
5982 return MakeMatcher(new Impl<const ::std::tr1::tuple<T1, T2>&>); \
5983 } \
5984 private: \
5985 template <typename Tuple> \
5986 class Impl : public MatcherInterface<Tuple> { \
5987 public: \
5988 virtual bool MatchAndExplain( \
5989 Tuple args, \
5990 MatchResultListener* /* listener */) const { \
5991 return ::std::tr1::get<0>(args) op ::std::tr1::get<1>(args); \
5992 } \
5993 virtual void DescribeTo(::std::ostream* os) const { \
5994 *os << "are " relation; \
5995 } \
5996 virtual void DescribeNegationTo(::std::ostream* os) const { \
5997 *os << "aren't " relation; \
5998 } \
5999 }; \
6000 }
6001
6002 // Implements Eq(), Ge(), Gt(), Le(), Lt(), and Ne() respectively.
6003 GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(Eq, ==, "an equal pair");
6004 GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(
6005 Ge, >=, "a pair where the first >= the second");
6006 GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(
6007 Gt, >, "a pair where the first > the second");
6008 GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(
6009 Le, <=, "a pair where the first <= the second");
6010 GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(
6011 Lt, <, "a pair where the first < the second");
6012 GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(Ne, !=, "an unequal pair");
6013
6014 #undef GMOCK_IMPLEMENT_COMPARISON2_MATCHER_
6015
6016 // Implements the Not(...) matcher for a particular argument type T.
6017 // We do not nest it inside the NotMatcher class template, as that
6018 // will prevent different instantiations of NotMatcher from sharing
6019 // the same NotMatcherImpl<T> class.
6020 template <typename T>
6021 class NotMatcherImpl : public MatcherInterface<T> {
6022 public:
6023 explicit NotMatcherImpl(const Matcher<T>& matcher)
6024 : matcher_(matcher) {}
6025
6026 virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
6027 return !matcher_.MatchAndExplain(x, listener);
6028 }
6029
6030 virtual void DescribeTo(::std::ostream* os) const {
6031 matcher_.DescribeNegationTo(os);
6032 }
6033
6034 virtual void DescribeNegationTo(::std::ostream* os) const {
6035 matcher_.DescribeTo(os);
6036 }
6037
6038 private:
6039 const Matcher<T> matcher_;
6040
6041 GTEST_DISALLOW_ASSIGN_(NotMatcherImpl);
6042 };
6043
6044 // Implements the Not(m) matcher, which matches a value that doesn't
6045 // match matcher m.
6046 template <typename InnerMatcher>
6047 class NotMatcher {
6048 public:
6049 explicit NotMatcher(InnerMatcher matcher) : matcher_(matcher) {}
6050
6051 // This template type conversion operator allows Not(m) to be used
6052 // to match any type m can match.
6053 template <typename T>
6054 operator Matcher<T>() const {
6055 return Matcher<T>(new NotMatcherImpl<T>(SafeMatcherCast<T>(matcher_)));
6056 }
6057
6058 private:
6059 InnerMatcher matcher_;
6060
6061 GTEST_DISALLOW_ASSIGN_(NotMatcher);
6062 };
6063
6064 // Implements the AllOf(m1, m2) matcher for a particular argument type
6065 // T. We do not nest it inside the BothOfMatcher class template, as
6066 // that will prevent different instantiations of BothOfMatcher from
6067 // sharing the same BothOfMatcherImpl<T> class.
6068 template <typename T>
6069 class BothOfMatcherImpl : public MatcherInterface<T> {
6070 public:
6071 BothOfMatcherImpl(const Matcher<T>& matcher1, const Matcher<T>& matcher2)
6072 : matcher1_(matcher1), matcher2_(matcher2) {}
6073
6074 virtual void DescribeTo(::std::ostream* os) const {
6075 *os << "(";
6076 matcher1_.DescribeTo(os);
6077 *os << ") and (";
6078 matcher2_.DescribeTo(os);
6079 *os << ")";
6080 }
6081
6082 virtual void DescribeNegationTo(::std::ostream* os) const {
6083 *os << "(";
6084 matcher1_.DescribeNegationTo(os);
6085 *os << ") or (";
6086 matcher2_.DescribeNegationTo(os);
6087 *os << ")";
6088 }
6089
6090 virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
6091 // If either matcher1_ or matcher2_ doesn't match x, we only need
6092 // to explain why one of them fails.
6093 StringMatchResultListener listener1;
6094 if (!matcher1_.MatchAndExplain(x, &listener1)) {
6095 *listener << listener1.str();
6096 return false;
6097 }
6098
6099 StringMatchResultListener listener2;
6100 if (!matcher2_.MatchAndExplain(x, &listener2)) {
6101 *listener << listener2.str();
6102 return false;
6103 }
6104
6105 // Otherwise we need to explain why *both* of them match.
6106 const internal::string s1 = listener1.str();
6107 const internal::string s2 = listener2.str();
6108
6109 if (s1 == "") {
6110 *listener << s2;
6111 } else {
6112 *listener << s1;
6113 if (s2 != "") {
6114 *listener << ", and " << s2;
6115 }
6116 }
6117 return true;
6118 }
6119
6120 private:
6121 const Matcher<T> matcher1_;
6122 const Matcher<T> matcher2_;
6123
6124 GTEST_DISALLOW_ASSIGN_(BothOfMatcherImpl);
6125 };
6126
6127 #if GTEST_LANG_CXX11
6128 // MatcherList provides mechanisms for storing a variable number of matchers in
6129 // a list structure (ListType) and creating a combining matcher from such a
6130 // list.
6131 // The template is defined recursively using the following template paramters:
6132 // * kSize is the length of the MatcherList.
6133 // * Head is the type of the first matcher of the list.
6134 // * Tail denotes the types of the remaining matchers of the list.
6135 template <int kSize, typename Head, typename... Tail>
6136 struct MatcherList {
6137 typedef MatcherList<kSize - 1, Tail...> MatcherListTail;
6138 typedef ::std::pair<Head, typename MatcherListTail::ListType> ListType;
6139
6140 // BuildList stores variadic type values in a nested pair structure.
6141 // Example:
6142 // MatcherList<3, int, string, float>::BuildList(5, "foo", 2.0) will return
6143 // the corresponding result of type pair<int, pair<string, float>>.
6144 static ListType BuildList(const Head& matcher, const Tail&... tail) {
6145 return ListType(matcher, MatcherListTail::BuildList(tail...));
6146 }
6147
6148 // CreateMatcher<T> creates a Matcher<T> from a given list of matchers (built
6149 // by BuildList()). CombiningMatcher<T> is used to combine the matchers of the
6150 // list. CombiningMatcher<T> must implement MatcherInterface<T> and have a
6151 // constructor taking two Matcher<T>s as input.
6152 template <typename T, template <typename /* T */> class CombiningMatcher>
6153 static Matcher<T> CreateMatcher(const ListType& matchers) {
6154 return Matcher<T>(new CombiningMatcher<T>(
6155 SafeMatcherCast<T>(matchers.first),
6156 MatcherListTail::template CreateMatcher<T, CombiningMatcher>(
6157 matchers.second)));
6158 }
6159 };
6160
6161 // The following defines the base case for the recursive definition of
6162 // MatcherList.
6163 template <typename Matcher1, typename Matcher2>
6164 struct MatcherList<2, Matcher1, Matcher2> {
6165 typedef ::std::pair<Matcher1, Matcher2> ListType;
6166
6167 static ListType BuildList(const Matcher1& matcher1,
6168 const Matcher2& matcher2) {
6169 return ::std::pair<Matcher1, Matcher2>(matcher1, matcher2);
6170 }
6171
6172 template <typename T, template <typename /* T */> class CombiningMatcher>
6173 static Matcher<T> CreateMatcher(const ListType& matchers) {
6174 return Matcher<T>(new CombiningMatcher<T>(
6175 SafeMatcherCast<T>(matchers.first),
6176 SafeMatcherCast<T>(matchers.second)));
6177 }
6178 };
6179
6180 // VariadicMatcher is used for the variadic implementation of
6181 // AllOf(m_1, m_2, ...) and AnyOf(m_1, m_2, ...).
6182 // CombiningMatcher<T> is used to recursively combine the provided matchers
6183 // (of type Args...).
6184 template <template <typename T> class CombiningMatcher, typename... Args>
6185 class VariadicMatcher {
6186 public:
6187 VariadicMatcher(const Args&... matchers) // NOLINT
6188 : matchers_(MatcherListType::BuildList(matchers...)) {}
6189
6190 // This template type conversion operator allows an
6191 // VariadicMatcher<Matcher1, Matcher2...> object to match any type that
6192 // all of the provided matchers (Matcher1, Matcher2, ...) can match.
6193 template <typename T>
6194 operator Matcher<T>() const {
6195 return MatcherListType::template CreateMatcher<T, CombiningMatcher>(
6196 matchers_);
6197 }
6198
6199 private:
6200 typedef MatcherList<sizeof...(Args), Args...> MatcherListType;
6201
6202 const typename MatcherListType::ListType matchers_;
6203
6204 GTEST_DISALLOW_ASSIGN_(VariadicMatcher);
6205 };
6206
6207 template <typename... Args>
6208 using AllOfMatcher = VariadicMatcher<BothOfMatcherImpl, Args...>;
6209
6210 #endif // GTEST_LANG_CXX11
6211
6212 // Used for implementing the AllOf(m_1, ..., m_n) matcher, which
6213 // matches a value that matches all of the matchers m_1, ..., and m_n.
6214 template <typename Matcher1, typename Matcher2>
6215 class BothOfMatcher {
6216 public:
6217 BothOfMatcher(Matcher1 matcher1, Matcher2 matcher2)
6218 : matcher1_(matcher1), matcher2_(matcher2) {}
6219
6220 // This template type conversion operator allows a
6221 // BothOfMatcher<Matcher1, Matcher2> object to match any type that
6222 // both Matcher1 and Matcher2 can match.
6223 template <typename T>
6224 operator Matcher<T>() const {
6225 return Matcher<T>(new BothOfMatcherImpl<T>(SafeMatcherCast<T>(matcher1_),
6226 SafeMatcherCast<T>(matcher2_)));
6227 }
6228
6229 private:
6230 Matcher1 matcher1_;
6231 Matcher2 matcher2_;
6232
6233 GTEST_DISALLOW_ASSIGN_(BothOfMatcher);
6234 };
6235
6236 // Implements the AnyOf(m1, m2) matcher for a particular argument type
6237 // T. We do not nest it inside the AnyOfMatcher class template, as
6238 // that will prevent different instantiations of AnyOfMatcher from
6239 // sharing the same EitherOfMatcherImpl<T> class.
6240 template <typename T>
6241 class EitherOfMatcherImpl : public MatcherInterface<T> {
6242 public:
6243 EitherOfMatcherImpl(const Matcher<T>& matcher1, const Matcher<T>& matcher2)
6244 : matcher1_(matcher1), matcher2_(matcher2) {}
6245
6246 virtual void DescribeTo(::std::ostream* os) const {
6247 *os << "(";
6248 matcher1_.DescribeTo(os);
6249 *os << ") or (";
6250 matcher2_.DescribeTo(os);
6251 *os << ")";
6252 }
6253
6254 virtual void DescribeNegationTo(::std::ostream* os) const {
6255 *os << "(";
6256 matcher1_.DescribeNegationTo(os);
6257 *os << ") and (";
6258 matcher2_.DescribeNegationTo(os);
6259 *os << ")";
6260 }
6261
6262 virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
6263 // If either matcher1_ or matcher2_ matches x, we just need to
6264 // explain why *one* of them matches.
6265 StringMatchResultListener listener1;
6266 if (matcher1_.MatchAndExplain(x, &listener1)) {
6267 *listener << listener1.str();
6268 return true;
6269 }
6270
6271 StringMatchResultListener listener2;
6272 if (matcher2_.MatchAndExplain(x, &listener2)) {
6273 *listener << listener2.str();
6274 return true;
6275 }
6276
6277 // Otherwise we need to explain why *both* of them fail.
6278 const internal::string s1 = listener1.str();
6279 const internal::string s2 = listener2.str();
6280
6281 if (s1 == "") {
6282 *listener << s2;
6283 } else {
6284 *listener << s1;
6285 if (s2 != "") {
6286 *listener << ", and " << s2;
6287 }
6288 }
6289 return false;
6290 }
6291
6292 private:
6293 const Matcher<T> matcher1_;
6294 const Matcher<T> matcher2_;
6295
6296 GTEST_DISALLOW_ASSIGN_(EitherOfMatcherImpl);
6297 };
6298
6299 #if GTEST_LANG_CXX11
6300 // AnyOfMatcher is used for the variadic implementation of AnyOf(m_1, m_2, ...).
6301 template <typename... Args>
6302 using AnyOfMatcher = VariadicMatcher<EitherOfMatcherImpl, Args...>;
6303
6304 #endif // GTEST_LANG_CXX11
6305
6306 // Used for implementing the AnyOf(m_1, ..., m_n) matcher, which
6307 // matches a value that matches at least one of the matchers m_1, ...,
6308 // and m_n.
6309 template <typename Matcher1, typename Matcher2>
6310 class EitherOfMatcher {
6311 public:
6312 EitherOfMatcher(Matcher1 matcher1, Matcher2 matcher2)
6313 : matcher1_(matcher1), matcher2_(matcher2) {}
6314
6315 // This template type conversion operator allows a
6316 // EitherOfMatcher<Matcher1, Matcher2> object to match any type that
6317 // both Matcher1 and Matcher2 can match.
6318 template <typename T>
6319 operator Matcher<T>() const {
6320 return Matcher<T>(new EitherOfMatcherImpl<T>(
6321 SafeMatcherCast<T>(matcher1_), SafeMatcherCast<T>(matcher2_)));
6322 }
6323
6324 private:
6325 Matcher1 matcher1_;
6326 Matcher2 matcher2_;
6327
6328 GTEST_DISALLOW_ASSIGN_(EitherOfMatcher);
6329 };
6330
6331 // Used for implementing Truly(pred), which turns a predicate into a
6332 // matcher.
6333 template <typename Predicate>
6334 class TrulyMatcher {
6335 public:
6336 explicit TrulyMatcher(Predicate pred) : predicate_(pred) {}
6337
6338 // This method template allows Truly(pred) to be used as a matcher
6339 // for type T where T is the argument type of predicate 'pred'. The
6340 // argument is passed by reference as the predicate may be
6341 // interested in the address of the argument.
6342 template <typename T>
6343 bool MatchAndExplain(T& x, // NOLINT
6344 MatchResultListener* /* listener */) const {
6345 // Without the if-statement, MSVC sometimes warns about converting
6346 // a value to bool (warning 4800).
6347 //
6348 // We cannot write 'return !!predicate_(x);' as that doesn't work
6349 // when predicate_(x) returns a class convertible to bool but
6350 // having no operator!().
6351 if (predicate_(x))
6352 return true;
6353 return false;
6354 }
6355
6356 void DescribeTo(::std::ostream* os) const {
6357 *os << "satisfies the given predicate";
6358 }
6359
6360 void DescribeNegationTo(::std::ostream* os) const {
6361 *os << "doesn't satisfy the given predicate";
6362 }
6363
6364 private:
6365 Predicate predicate_;
6366
6367 GTEST_DISALLOW_ASSIGN_(TrulyMatcher);
6368 };
6369
6370 // Used for implementing Matches(matcher), which turns a matcher into
6371 // a predicate.
6372 template <typename M>
6373 class MatcherAsPredicate {
6374 public:
6375 explicit MatcherAsPredicate(M matcher) : matcher_(matcher) {}
6376
6377 // This template operator() allows Matches(m) to be used as a
6378 // predicate on type T where m is a matcher on type T.
6379 //
6380 // The argument x is passed by reference instead of by value, as
6381 // some matcher may be interested in its address (e.g. as in
6382 // Matches(Ref(n))(x)).
6383 template <typename T>
6384 bool operator()(const T& x) const {
6385 // We let matcher_ commit to a particular type here instead of
6386 // when the MatcherAsPredicate object was constructed. This
6387 // allows us to write Matches(m) where m is a polymorphic matcher
6388 // (e.g. Eq(5)).
6389 //
6390 // If we write Matcher<T>(matcher_).Matches(x) here, it won't
6391 // compile when matcher_ has type Matcher<const T&>; if we write
6392 // Matcher<const T&>(matcher_).Matches(x) here, it won't compile
6393 // when matcher_ has type Matcher<T>; if we just write
6394 // matcher_.Matches(x), it won't compile when matcher_ is
6395 // polymorphic, e.g. Eq(5).
6396 //
6397 // MatcherCast<const T&>() is necessary for making the code work
6398 // in all of the above situations.
6399 return MatcherCast<const T&>(matcher_).Matches(x);
6400 }
6401
6402 private:
6403 M matcher_;
6404
6405 GTEST_DISALLOW_ASSIGN_(MatcherAsPredicate);
6406 };
6407
6408 // For implementing ASSERT_THAT() and EXPECT_THAT(). The template
6409 // argument M must be a type that can be converted to a matcher.
6410 template <typename M>
6411 class PredicateFormatterFromMatcher {
6412 public:
6413 explicit PredicateFormatterFromMatcher(const M& m) : matcher_(m) {}
6414
6415 // This template () operator allows a PredicateFormatterFromMatcher
6416 // object to act as a predicate-formatter suitable for using with
6417 // Google Test's EXPECT_PRED_FORMAT1() macro.
6418 template <typename T>
6419 AssertionResult operator()(const char* value_text, const T& x) const {
6420 // We convert matcher_ to a Matcher<const T&> *now* instead of
6421 // when the PredicateFormatterFromMatcher object was constructed,
6422 // as matcher_ may be polymorphic (e.g. NotNull()) and we won't
6423 // know which type to instantiate it to until we actually see the
6424 // type of x here.
6425 //
6426 // We write SafeMatcherCast<const T&>(matcher_) instead of
6427 // Matcher<const T&>(matcher_), as the latter won't compile when
6428 // matcher_ has type Matcher<T> (e.g. An<int>()).
6429 // We don't write MatcherCast<const T&> either, as that allows
6430 // potentially unsafe downcasting of the matcher argument.
6431 const Matcher<const T&> matcher = SafeMatcherCast<const T&>(matcher_);
6432 StringMatchResultListener listener;
6433 if (MatchPrintAndExplain(x, matcher, &listener))
6434 return AssertionSuccess();
6435
6436 ::std::stringstream ss;
6437 ss << "Value of: " << value_text << "\n"
6438 << "Expected: ";
6439 matcher.DescribeTo(&ss);
6440 ss << "\n Actual: " << listener.str();
6441 return AssertionFailure() << ss.str();
6442 }
6443
6444 private:
6445 const M matcher_;
6446
6447 GTEST_DISALLOW_ASSIGN_(PredicateFormatterFromMatcher);
6448 };
6449
6450 // A helper function for converting a matcher to a predicate-formatter
6451 // without the user needing to explicitly write the type. This is
6452 // used for implementing ASSERT_THAT() and EXPECT_THAT().
6453 template <typename M>
6454 inline PredicateFormatterFromMatcher<M>
6455 MakePredicateFormatterFromMatcher(const M& matcher) {
6456 return PredicateFormatterFromMatcher<M>(matcher);
6457 }
6458
6459 // Implements the polymorphic floating point equality matcher, which matches
6460 // two float values using ULP-based approximation or, optionally, a
6461 // user-specified epsilon. The template is meant to be instantiated with
6462 // FloatType being either float or double.
6463 template <typename FloatType>
6464 class FloatingEqMatcher {
6465 public:
6466 // Constructor for FloatingEqMatcher.
6467 // The matcher's input will be compared with rhs. The matcher treats two
6468 // NANs as equal if nan_eq_nan is true. Otherwise, under IEEE standards,
6469 // equality comparisons between NANs will always return false. We specify a
6470 // negative max_abs_error_ term to indicate that ULP-based approximation will
6471 // be used for comparison.
6472 FloatingEqMatcher(FloatType rhs, bool nan_eq_nan) :
6473 rhs_(rhs), nan_eq_nan_(nan_eq_nan), max_abs_error_(-1) {
6474 }
6475
6476 // Constructor that supports a user-specified max_abs_error that will be used
6477 // for comparison instead of ULP-based approximation. The max absolute
6478 // should be non-negative.
6479 FloatingEqMatcher(FloatType rhs, bool nan_eq_nan, FloatType max_abs_error) :
6480 rhs_(rhs), nan_eq_nan_(nan_eq_nan), max_abs_error_(max_abs_error) {
6481 GTEST_CHECK_(max_abs_error >= 0)
6482 << ", where max_abs_error is" << max_abs_error;
6483 }
6484
6485 // Implements floating point equality matcher as a Matcher<T>.
6486 template <typename T>
6487 class Impl : public MatcherInterface<T> {
6488 public:
6489 Impl(FloatType rhs, bool nan_eq_nan, FloatType max_abs_error) :
6490 rhs_(rhs), nan_eq_nan_(nan_eq_nan), max_abs_error_(max_abs_error) {}
6491
6492 virtual bool MatchAndExplain(T value,
6493 MatchResultListener* /* listener */) const {
6494 const FloatingPoint<FloatType> lhs(value), rhs(rhs_);
6495
6496 // Compares NaNs first, if nan_eq_nan_ is true.
6497 if (lhs.is_nan() || rhs.is_nan()) {
6498 if (lhs.is_nan() && rhs.is_nan()) {
6499 return nan_eq_nan_;
6500 }
6501 // One is nan; the other is not nan.
6502 return false;
6503 }
6504 if (HasMaxAbsError()) {
6505 // We perform an equality check so that inf will match inf, regardless
6506 // of error bounds. If the result of value - rhs_ would result in
6507 // overflow or if either value is inf, the default result is infinity,
6508 // which should only match if max_abs_error_ is also infinity.
6509 return value == rhs_ || fabs(value - rhs_) <= max_abs_error_;
6510 } else {
6511 return lhs.AlmostEquals(rhs);
6512 }
6513 }
6514
6515 virtual void DescribeTo(::std::ostream* os) const {
6516 // os->precision() returns the previously set precision, which we
6517 // store to restore the ostream to its original configuration
6518 // after outputting.
6519 const ::std::streamsize old_precision = os->precision(
6520 ::std::numeric_limits<FloatType>::digits10 + 2);
6521 if (FloatingPoint<FloatType>(rhs_).is_nan()) {
6522 if (nan_eq_nan_) {
6523 *os << "is NaN";
6524 } else {
6525 *os << "never matches";
6526 }
6527 } else {
6528 *os << "is approximately " << rhs_;
6529 if (HasMaxAbsError()) {
6530 *os << " (absolute error <= " << max_abs_error_ << ")";
6531 }
6532 }
6533 os->precision(old_precision);
6534 }
6535
6536 virtual void DescribeNegationTo(::std::ostream* os) const {
6537 // As before, get original precision.
6538 const ::std::streamsize old_precision = os->precision(
6539 ::std::numeric_limits<FloatType>::digits10 + 2);
6540 if (FloatingPoint<FloatType>(rhs_).is_nan()) {
6541 if (nan_eq_nan_) {
6542 *os << "isn't NaN";
6543 } else {
6544 *os << "is anything";
6545 }
6546 } else {
6547 *os << "isn't approximately " << rhs_;
6548 if (HasMaxAbsError()) {
6549 *os << " (absolute error > " << max_abs_error_ << ")";
6550 }
6551 }
6552 // Restore original precision.
6553 os->precision(old_precision);
6554 }
6555
6556 private:
6557 bool HasMaxAbsError() const {
6558 return max_abs_error_ >= 0;
6559 }
6560
6561 const FloatType rhs_;
6562 const bool nan_eq_nan_;
6563 // max_abs_error will be used for value comparison when >= 0.
6564 const FloatType max_abs_error_;
6565
6566 GTEST_DISALLOW_ASSIGN_(Impl);
6567 };
6568
6569 // The following 3 type conversion operators allow FloatEq(rhs) and
6570 // NanSensitiveFloatEq(rhs) to be used as a Matcher<float>, a
6571 // Matcher<const float&>, or a Matcher<float&>, but nothing else.
6572 // (While Google's C++ coding style doesn't allow arguments passed
6573 // by non-const reference, we may see them in code not conforming to
6574 // the style. Therefore Google Mock needs to support them.)
6575 operator Matcher<FloatType>() const {
6576 return MakeMatcher(new Impl<FloatType>(rhs_, nan_eq_nan_, max_abs_error_));
6577 }
6578
6579 operator Matcher<const FloatType&>() const {
6580 return MakeMatcher(
6581 new Impl<const FloatType&>(rhs_, nan_eq_nan_, max_abs_error_));
6582 }
6583
6584 operator Matcher<FloatType&>() const {
6585 return MakeMatcher(new Impl<FloatType&>(rhs_, nan_eq_nan_, max_abs_error_));
6586 }
6587
6588 private:
6589 const FloatType rhs_;
6590 const bool nan_eq_nan_;
6591 // max_abs_error will be used for value comparison when >= 0.
6592 const FloatType max_abs_error_;
6593
6594 GTEST_DISALLOW_ASSIGN_(FloatingEqMatcher);
6595 };
6596
6597 // Implements the Pointee(m) matcher for matching a pointer whose
6598 // pointee matches matcher m. The pointer can be either raw or smart.
6599 template <typename InnerMatcher>
6600 class PointeeMatcher {
6601 public:
6602 explicit PointeeMatcher(const InnerMatcher& matcher) : matcher_(matcher) {}
6603
6604 // This type conversion operator template allows Pointee(m) to be
6605 // used as a matcher for any pointer type whose pointee type is
6606 // compatible with the inner matcher, where type Pointer can be
6607 // either a raw pointer or a smart pointer.
6608 //
6609 // The reason we do this instead of relying on
6610 // MakePolymorphicMatcher() is that the latter is not flexible
6611 // enough for implementing the DescribeTo() method of Pointee().
6612 template <typename Pointer>
6613 operator Matcher<Pointer>() const {
6614 return MakeMatcher(new Impl<Pointer>(matcher_));
6615 }
6616
6617 private:
6618 // The monomorphic implementation that works for a particular pointer type.
6619 template <typename Pointer>
6620 class Impl : public MatcherInterface<Pointer> {
6621 public:
6622 typedef typename PointeeOf<GTEST_REMOVE_CONST_( // NOLINT
6623 GTEST_REMOVE_REFERENCE_(Pointer))>::type Pointee;
6624
6625 explicit Impl(const InnerMatcher& matcher)
6626 : matcher_(MatcherCast<const Pointee&>(matcher)) {}
6627
6628 virtual void DescribeTo(::std::ostream* os) const {
6629 *os << "points to a value that ";
6630 matcher_.DescribeTo(os);
6631 }
6632
6633 virtual void DescribeNegationTo(::std::ostream* os) const {
6634 *os << "does not point to a value that ";
6635 matcher_.DescribeTo(os);
6636 }
6637
6638 virtual bool MatchAndExplain(Pointer pointer,
6639 MatchResultListener* listener) const {
6640 if (GetRawPointer(pointer) == NULL)
6641 return false;
6642
6643 *listener << "which points to ";
6644 return MatchPrintAndExplain(*pointer, matcher_, listener);
6645 }
6646
6647 private:
6648 const Matcher<const Pointee&> matcher_;
6649
6650 GTEST_DISALLOW_ASSIGN_(Impl);
6651 };
6652
6653 const InnerMatcher matcher_;
6654
6655 GTEST_DISALLOW_ASSIGN_(PointeeMatcher);
6656 };
6657
6658 // Implements the Field() matcher for matching a field (i.e. member
6659 // variable) of an object.
6660 template <typename Class, typename FieldType>
6661 class FieldMatcher {
6662 public:
6663 FieldMatcher(FieldType Class::*field,
6664 const Matcher<const FieldType&>& matcher)
6665 : field_(field), matcher_(matcher) {}
6666
6667 void DescribeTo(::std::ostream* os) const {
6668 *os << "is an object whose given field ";
6669 matcher_.DescribeTo(os);
6670 }
6671
6672 void DescribeNegationTo(::std::ostream* os) const {
6673 *os << "is an object whose given field ";
6674 matcher_.DescribeNegationTo(os);
6675 }
6676
6677 template <typename T>
6678 bool MatchAndExplain(const T& value, MatchResultListener* listener) const {
6679 return MatchAndExplainImpl(
6680 typename ::testing::internal::
6681 is_pointer<GTEST_REMOVE_CONST_(T)>::type(),
6682 value, listener);
6683 }
6684
6685 private:
6686 // The first argument of MatchAndExplainImpl() is needed to help
6687 // Symbian's C++ compiler choose which overload to use. Its type is
6688 // true_type iff the Field() matcher is used to match a pointer.
6689 bool MatchAndExplainImpl(false_type /* is_not_pointer */, const Class& obj,
6690 MatchResultListener* listener) const {
6691 *listener << "whose given field is ";
6692 return MatchPrintAndExplain(obj.*field_, matcher_, listener);
6693 }
6694
6695 bool MatchAndExplainImpl(true_type /* is_pointer */, const Class* p,
6696 MatchResultListener* listener) const {
6697 if (p == NULL)
6698 return false;
6699
6700 *listener << "which points to an object ";
6701 // Since *p has a field, it must be a class/struct/union type and
6702 // thus cannot be a pointer. Therefore we pass false_type() as
6703 // the first argument.
6704 return MatchAndExplainImpl(false_type(), *p, listener);
6705 }
6706
6707 const FieldType Class::*field_;
6708 const Matcher<const FieldType&> matcher_;
6709
6710 GTEST_DISALLOW_ASSIGN_(FieldMatcher);
6711 };
6712
6713 // Implements the Property() matcher for matching a property
6714 // (i.e. return value of a getter method) of an object.
6715 template <typename Class, typename PropertyType>
6716 class PropertyMatcher {
6717 public:
6718 // The property may have a reference type, so 'const PropertyType&'
6719 // may cause double references and fail to compile. That's why we
6720 // need GTEST_REFERENCE_TO_CONST, which works regardless of
6721 // PropertyType being a reference or not.
6722 typedef GTEST_REFERENCE_TO_CONST_(PropertyType) RefToConstProperty;
6723
6724 PropertyMatcher(PropertyType (Class::*property)() const,
6725 const Matcher<RefToConstProperty>& matcher)
6726 : property_(property), matcher_(matcher) {}
6727
6728 void DescribeTo(::std::ostream* os) const {
6729 *os << "is an object whose given property ";
6730 matcher_.DescribeTo(os);
6731 }
6732
6733 void DescribeNegationTo(::std::ostream* os) const {
6734 *os << "is an object whose given property ";
6735 matcher_.DescribeNegationTo(os);
6736 }
6737
6738 template <typename T>
6739 bool MatchAndExplain(const T&value, MatchResultListener* listener) const {
6740 return MatchAndExplainImpl(
6741 typename ::testing::internal::
6742 is_pointer<GTEST_REMOVE_CONST_(T)>::type(),
6743 value, listener);
6744 }
6745
6746 private:
6747 // The first argument of MatchAndExplainImpl() is needed to help
6748 // Symbian's C++ compiler choose which overload to use. Its type is
6749 // true_type iff the Property() matcher is used to match a pointer.
6750 bool MatchAndExplainImpl(false_type /* is_not_pointer */, const Class& obj,
6751 MatchResultListener* listener) const {
6752 *listener << "whose given property is ";
6753 // Cannot pass the return value (for example, int) to MatchPrintAndExplain,
6754 // which takes a non-const reference as argument.
6755 RefToConstProperty result = (obj.*property_)();
6756 return MatchPrintAndExplain(result, matcher_, listener);
6757 }
6758
6759 bool MatchAndExplainImpl(true_type /* is_pointer */, const Class* p,
6760 MatchResultListener* listener) const {
6761 if (p == NULL)
6762 return false;
6763
6764 *listener << "which points to an object ";
6765 // Since *p has a property method, it must be a class/struct/union
6766 // type and thus cannot be a pointer. Therefore we pass
6767 // false_type() as the first argument.
6768 return MatchAndExplainImpl(false_type(), *p, listener);
6769 }
6770
6771 PropertyType (Class::*property_)() const;
6772 const Matcher<RefToConstProperty> matcher_;
6773
6774 GTEST_DISALLOW_ASSIGN_(PropertyMatcher);
6775 };
6776
6777 // Type traits specifying various features of different functors for ResultOf.
6778 // The default template specifies features for functor objects.
6779 // Functor classes have to typedef argument_type and result_type
6780 // to be compatible with ResultOf.
6781 template <typename Functor>
6782 struct CallableTraits {
6783 typedef typename Functor::result_type ResultType;
6784 typedef Functor StorageType;
6785
6786 static void CheckIsValid(Functor /* functor */) {}
6787 template <typename T>
6788 static ResultType Invoke(Functor f, T arg) { return f(arg); }
6789 };
6790
6791 // Specialization for function pointers.
6792 template <typename ArgType, typename ResType>
6793 struct CallableTraits<ResType(*)(ArgType)> {
6794 typedef ResType ResultType;
6795 typedef ResType(*StorageType)(ArgType);
6796
6797 static void CheckIsValid(ResType(*f)(ArgType)) {
6798 GTEST_CHECK_(f != NULL)
6799 << "NULL function pointer is passed into ResultOf().";
6800 }
6801 template <typename T>
6802 static ResType Invoke(ResType(*f)(ArgType), T arg) {
6803 return (*f)(arg);
6804 }
6805 };
6806
6807 // Implements the ResultOf() matcher for matching a return value of a
6808 // unary function of an object.
6809 template <typename Callable>
6810 class ResultOfMatcher {
6811 public:
6812 typedef typename CallableTraits<Callable>::ResultType ResultType;
6813
6814 ResultOfMatcher(Callable callable, const Matcher<ResultType>& matcher)
6815 : callable_(callable), matcher_(matcher) {
6816 CallableTraits<Callable>::CheckIsValid(callable_);
6817 }
6818
6819 template <typename T>
6820 operator Matcher<T>() const {
6821 return Matcher<T>(new Impl<T>(callable_, matcher_));
6822 }
6823
6824 private:
6825 typedef typename CallableTraits<Callable>::StorageType CallableStorageType;
6826
6827 template <typename T>
6828 class Impl : public MatcherInterface<T> {
6829 public:
6830 Impl(CallableStorageType callable, const Matcher<ResultType>& matcher)
6831 : callable_(callable), matcher_(matcher) {}
6832
6833 virtual void DescribeTo(::std::ostream* os) const {
6834 *os << "is mapped by the given callable to a value that ";
6835 matcher_.DescribeTo(os);
6836 }
6837
6838 virtual void DescribeNegationTo(::std::ostream* os) const {
6839 *os << "is mapped by the given callable to a value that ";
6840 matcher_.DescribeNegationTo(os);
6841 }
6842
6843 virtual bool MatchAndExplain(T obj, MatchResultListener* listener) const {
6844 *listener << "which is mapped by the given callable to ";
6845 // Cannot pass the return value (for example, int) to
6846 // MatchPrintAndExplain, which takes a non-const reference as argument.
6847 ResultType result =
6848 CallableTraits<Callable>::template Invoke<T>(callable_, obj);
6849 return MatchPrintAndExplain(result, matcher_, listener);
6850 }
6851
6852 private:
6853 // Functors often define operator() as non-const method even though
6854 // they are actualy stateless. But we need to use them even when
6855 // 'this' is a const pointer. It's the user's responsibility not to
6856 // use stateful callables with ResultOf(), which does't guarantee
6857 // how many times the callable will be invoked.
6858 mutable CallableStorageType callable_;
6859 const Matcher<ResultType> matcher_;
6860
6861 GTEST_DISALLOW_ASSIGN_(Impl);
6862 }; // class Impl
6863
6864 const CallableStorageType callable_;
6865 const Matcher<ResultType> matcher_;
6866
6867 GTEST_DISALLOW_ASSIGN_(ResultOfMatcher);
6868 };
6869
6870 // Implements a matcher that checks the size of an STL-style container.
6871 template <typename SizeMatcher>
6872 class SizeIsMatcher {
6873 public:
6874 explicit SizeIsMatcher(const SizeMatcher& size_matcher)
6875 : size_matcher_(size_matcher) {
6876 }
6877
6878 template <typename Container>
6879 operator Matcher<Container>() const {
6880 return MakeMatcher(new Impl<Container>(size_matcher_));
6881 }
6882
6883 template <typename Container>
6884 class Impl : public MatcherInterface<Container> {
6885 public:
6886 typedef internal::StlContainerView<
6887 GTEST_REMOVE_REFERENCE_AND_CONST_(Container)> ContainerView;
6888 typedef typename ContainerView::type::size_type SizeType;
6889 explicit Impl(const SizeMatcher& size_matcher)
6890 : size_matcher_(MatcherCast<SizeType>(size_matcher)) {}
6891
6892 virtual void DescribeTo(::std::ostream* os) const {
6893 *os << "size ";
6894 size_matcher_.DescribeTo(os);
6895 }
6896 virtual void DescribeNegationTo(::std::ostream* os) const {
6897 *os << "size ";
6898 size_matcher_.DescribeNegationTo(os);
6899 }
6900
6901 virtual bool MatchAndExplain(Container container,
6902 MatchResultListener* listener) const {
6903 SizeType size = container.size();
6904 StringMatchResultListener size_listener;
6905 const bool result = size_matcher_.MatchAndExplain(size, &size_listener);
6906 *listener
6907 << "whose size " << size << (result ? " matches" : " doesn't match");
6908 PrintIfNotEmpty(size_listener.str(), listener->stream());
6909 return result;
6910 }
6911
6912 private:
6913 const Matcher<SizeType> size_matcher_;
6914 GTEST_DISALLOW_ASSIGN_(Impl);
6915 };
6916
6917 private:
6918 const SizeMatcher size_matcher_;
6919 GTEST_DISALLOW_ASSIGN_(SizeIsMatcher);
6920 };
6921
6922 // Implements an equality matcher for any STL-style container whose elements
6923 // support ==. This matcher is like Eq(), but its failure explanations provide
6924 // more detailed information that is useful when the container is used as a set.
6925 // The failure message reports elements that are in one of the operands but not
6926 // the other. The failure messages do not report duplicate or out-of-order
6927 // elements in the containers (which don't properly matter to sets, but can
6928 // occur if the containers are vectors or lists, for example).
6929 //
6930 // Uses the container's const_iterator, value_type, operator ==,
6931 // begin(), and end().
6932 template <typename Container>
6933 class ContainerEqMatcher {
6934 public:
6935 typedef internal::StlContainerView<Container> View;
6936 typedef typename View::type StlContainer;
6937 typedef typename View::const_reference StlContainerReference;
6938
6939 // We make a copy of rhs in case the elements in it are modified
6940 // after this matcher is created.
6941 explicit ContainerEqMatcher(const Container& rhs) : rhs_(View::Copy(rhs)) {
6942 // Makes sure the user doesn't instantiate this class template
6943 // with a const or reference type.
6944 (void)testing::StaticAssertTypeEq<Container,
6945 GTEST_REMOVE_REFERENCE_AND_CONST_(Container)>();
6946 }
6947
6948 void DescribeTo(::std::ostream* os) const {
6949 *os << "equals ";
6950 UniversalPrint(rhs_, os);
6951 }
6952 void DescribeNegationTo(::std::ostream* os) const {
6953 *os << "does not equal ";
6954 UniversalPrint(rhs_, os);
6955 }
6956
6957 template <typename LhsContainer>
6958 bool MatchAndExplain(const LhsContainer& lhs,
6959 MatchResultListener* listener) const {
6960 // GTEST_REMOVE_CONST_() is needed to work around an MSVC 8.0 bug
6961 // that causes LhsContainer to be a const type sometimes.
6962 typedef internal::StlContainerView<GTEST_REMOVE_CONST_(LhsContainer)>
6963 LhsView;
6964 typedef typename LhsView::type LhsStlContainer;
6965 StlContainerReference lhs_stl_container = LhsView::ConstReference(lhs);
6966 if (lhs_stl_container == rhs_)
6967 return true;
6968
6969 ::std::ostream* const os = listener->stream();
6970 if (os != NULL) {
6971 // Something is different. Check for extra values first.
6972 bool printed_header = false;
6973 for (typename LhsStlContainer::const_iterator it =
6974 lhs_stl_container.begin();
6975 it != lhs_stl_container.end(); ++it) {
6976 if (internal::ArrayAwareFind(rhs_.begin(), rhs_.end(), *it) ==
6977 rhs_.end()) {
6978 if (printed_header) {
6979 *os << ", ";
6980 } else {
6981 *os << "which has these unexpected elements: ";
6982 printed_header = true;
6983 }
6984 UniversalPrint(*it, os);
6985 }
6986 }
6987
6988 // Now check for missing values.
6989 bool printed_header2 = false;
6990 for (typename StlContainer::const_iterator it = rhs_.begin();
6991 it != rhs_.end(); ++it) {
6992 if (internal::ArrayAwareFind(
6993 lhs_stl_container.begin(), lhs_stl_container.end(), *it) ==
6994 lhs_stl_container.end()) {
6995 if (printed_header2) {
6996 *os << ", ";
6997 } else {
6998 *os << (printed_header ? ",\nand" : "which")
6999 << " doesn't have these expected elements: ";
7000 printed_header2 = true;
7001 }
7002 UniversalPrint(*it, os);
7003 }
7004 }
7005 }
7006
7007 return false;
7008 }
7009
7010 private:
7011 const StlContainer rhs_;
7012
7013 GTEST_DISALLOW_ASSIGN_(ContainerEqMatcher);
7014 };
7015
7016 // A comparator functor that uses the < operator to compare two values.
7017 struct LessComparator {
7018 template <typename T, typename U>
7019 bool operator()(const T& lhs, const U& rhs) const { return lhs < rhs; }
7020 };
7021
7022 // Implements WhenSortedBy(comparator, container_matcher).
7023 template <typename Comparator, typename ContainerMatcher>
7024 class WhenSortedByMatcher {
7025 public:
7026 WhenSortedByMatcher(const Comparator& comparator,
7027 const ContainerMatcher& matcher)
7028 : comparator_(comparator), matcher_(matcher) {}
7029
7030 template <typename LhsContainer>
7031 operator Matcher<LhsContainer>() const {
7032 return MakeMatcher(new Impl<LhsContainer>(comparator_, matcher_));
7033 }
7034
7035 template <typename LhsContainer>
7036 class Impl : public MatcherInterface<LhsContainer> {
7037 public:
7038 typedef internal::StlContainerView<
7039 GTEST_REMOVE_REFERENCE_AND_CONST_(LhsContainer)> LhsView;
7040 typedef typename LhsView::type LhsStlContainer;
7041 typedef typename LhsView::const_reference LhsStlContainerReference;
7042 // Transforms std::pair<const Key, Value> into std::pair<Key, Value>
7043 // so that we can match associative containers.
7044 typedef typename RemoveConstFromKey<
7045 typename LhsStlContainer::value_type>::type LhsValue;
7046
7047 Impl(const Comparator& comparator, const ContainerMatcher& matcher)
7048 : comparator_(comparator), matcher_(matcher) {}
7049
7050 virtual void DescribeTo(::std::ostream* os) const {
7051 *os << "(when sorted) ";
7052 matcher_.DescribeTo(os);
7053 }
7054
7055 virtual void DescribeNegationTo(::std::ostream* os) const {
7056 *os << "(when sorted) ";
7057 matcher_.DescribeNegationTo(os);
7058 }
7059
7060 virtual bool MatchAndExplain(LhsContainer lhs,
7061 MatchResultListener* listener) const {
7062 LhsStlContainerReference lhs_stl_container = LhsView::ConstReference(lhs);
7063 ::std::vector<LhsValue> sorted_container(lhs_stl_container.begin(),
7064 lhs_stl_container.end());
7065 ::std::sort(
7066 sorted_container.begin(), sorted_container.end(), comparator_);
7067
7068 if (!listener->IsInterested()) {
7069 // If the listener is not interested, we do not need to
7070 // construct the inner explanation.
7071 return matcher_.Matches(sorted_container);
7072 }
7073
7074 *listener << "which is ";
7075 UniversalPrint(sorted_container, listener->stream());
7076 *listener << " when sorted";
7077
7078 StringMatchResultListener inner_listener;
7079 const bool match = matcher_.MatchAndExplain(sorted_container,
7080 &inner_listener);
7081 PrintIfNotEmpty(inner_listener.str(), listener->stream());
7082 return match;
7083 }
7084
7085 private:
7086 const Comparator comparator_;
7087 const Matcher<const ::std::vector<LhsValue>&> matcher_;
7088
7089 GTEST_DISALLOW_COPY_AND_ASSIGN_(Impl);
7090 };
7091
7092 private:
7093 const Comparator comparator_;
7094 const ContainerMatcher matcher_;
7095
7096 GTEST_DISALLOW_ASSIGN_(WhenSortedByMatcher);
7097 };
7098
7099 // Implements Pointwise(tuple_matcher, rhs_container). tuple_matcher
7100 // must be able to be safely cast to Matcher<tuple<const T1&, const
7101 // T2&> >, where T1 and T2 are the types of elements in the LHS
7102 // container and the RHS container respectively.
7103 template <typename TupleMatcher, typename RhsContainer>
7104 class PointwiseMatcher {
7105 public:
7106 typedef internal::StlContainerView<RhsContainer> RhsView;
7107 typedef typename RhsView::type RhsStlContainer;
7108 typedef typename RhsStlContainer::value_type RhsValue;
7109
7110 // Like ContainerEq, we make a copy of rhs in case the elements in
7111 // it are modified after this matcher is created.
7112 PointwiseMatcher(const TupleMatcher& tuple_matcher, const RhsContainer& rhs)
7113 : tuple_matcher_(tuple_matcher), rhs_(RhsView::Copy(rhs)) {
7114 // Makes sure the user doesn't instantiate this class template
7115 // with a const or reference type.
7116 (void)testing::StaticAssertTypeEq<RhsContainer,
7117 GTEST_REMOVE_REFERENCE_AND_CONST_(RhsContainer)>();
7118 }
7119
7120 template <typename LhsContainer>
7121 operator Matcher<LhsContainer>() const {
7122 return MakeMatcher(new Impl<LhsContainer>(tuple_matcher_, rhs_));
7123 }
7124
7125 template <typename LhsContainer>
7126 class Impl : public MatcherInterface<LhsContainer> {
7127 public:
7128 typedef internal::StlContainerView<
7129 GTEST_REMOVE_REFERENCE_AND_CONST_(LhsContainer)> LhsView;
7130 typedef typename LhsView::type LhsStlContainer;
7131 typedef typename LhsView::const_reference LhsStlContainerReference;
7132 typedef typename LhsStlContainer::value_type LhsValue;
7133 // We pass the LHS value and the RHS value to the inner matcher by
7134 // reference, as they may be expensive to copy. We must use tuple
7135 // instead of pair here, as a pair cannot hold references (C++ 98,
7136 // 20.2.2 [lib.pairs]).
7137 typedef ::std::tr1::tuple<const LhsValue&, const RhsValue&> InnerMatcherArg;
7138
7139 Impl(const TupleMatcher& tuple_matcher, const RhsStlContainer& rhs)
7140 // mono_tuple_matcher_ holds a monomorphic version of the tuple matcher.
7141 : mono_tuple_matcher_(SafeMatcherCast<InnerMatcherArg>(tuple_matcher)),
7142 rhs_(rhs) {}
7143
7144 virtual void DescribeTo(::std::ostream* os) const {
7145 *os << "contains " << rhs_.size()
7146 << " values, where each value and its corresponding value in ";
7147 UniversalPrinter<RhsStlContainer>::Print(rhs_, os);
7148 *os << " ";
7149 mono_tuple_matcher_.DescribeTo(os);
7150 }
7151 virtual void DescribeNegationTo(::std::ostream* os) const {
7152 *os << "doesn't contain exactly " << rhs_.size()
7153 << " values, or contains a value x at some index i"
7154 << " where x and the i-th value of ";
7155 UniversalPrint(rhs_, os);
7156 *os << " ";
7157 mono_tuple_matcher_.DescribeNegationTo(os);
7158 }
7159
7160 virtual bool MatchAndExplain(LhsContainer lhs,
7161 MatchResultListener* listener) const {
7162 LhsStlContainerReference lhs_stl_container = LhsView::ConstReference(lhs);
7163 const size_t actual_size = lhs_stl_container.size();
7164 if (actual_size != rhs_.size()) {
7165 *listener << "which contains " << actual_size << " values";
7166 return false;
7167 }
7168
7169 typename LhsStlContainer::const_iterator left = lhs_stl_container.begin();
7170 typename RhsStlContainer::const_iterator right = rhs_.begin();
7171 for (size_t i = 0; i != actual_size; ++i, ++left, ++right) {
7172 const InnerMatcherArg value_pair(*left, *right);
7173
7174 if (listener->IsInterested()) {
7175 StringMatchResultListener inner_listener;
7176 if (!mono_tuple_matcher_.MatchAndExplain(
7177 value_pair, &inner_listener)) {
7178 *listener << "where the value pair (";
7179 UniversalPrint(*left, listener->stream());
7180 *listener << ", ";
7181 UniversalPrint(*right, listener->stream());
7182 *listener << ") at index #" << i << " don't match";
7183 PrintIfNotEmpty(inner_listener.str(), listener->stream());
7184 return false;
7185 }
7186 } else {
7187 if (!mono_tuple_matcher_.Matches(value_pair))
7188 return false;
7189 }
7190 }
7191
7192 return true;
7193 }
7194
7195 private:
7196 const Matcher<InnerMatcherArg> mono_tuple_matcher_;
7197 const RhsStlContainer rhs_;
7198
7199 GTEST_DISALLOW_ASSIGN_(Impl);
7200 };
7201
7202 private:
7203 const TupleMatcher tuple_matcher_;
7204 const RhsStlContainer rhs_;
7205
7206 GTEST_DISALLOW_ASSIGN_(PointwiseMatcher);
7207 };
7208
7209 // Holds the logic common to ContainsMatcherImpl and EachMatcherImpl.
7210 template <typename Container>
7211 class QuantifierMatcherImpl : public MatcherInterface<Container> {
7212 public:
7213 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
7214 typedef StlContainerView<RawContainer> View;
7215 typedef typename View::type StlContainer;
7216 typedef typename View::const_reference StlContainerReference;
7217 typedef typename StlContainer::value_type Element;
7218
7219 template <typename InnerMatcher>
7220 explicit QuantifierMatcherImpl(InnerMatcher inner_matcher)
7221 : inner_matcher_(
7222 testing::SafeMatcherCast<const Element&>(inner_matcher)) {}
7223
7224 // Checks whether:
7225 // * All elements in the container match, if all_elements_should_match.
7226 // * Any element in the container matches, if !all_elements_should_match.
7227 bool MatchAndExplainImpl(bool all_elements_should_match,
7228 Container container,
7229 MatchResultListener* listener) const {
7230 StlContainerReference stl_container = View::ConstReference(container);
7231 size_t i = 0;
7232 for (typename StlContainer::const_iterator it = stl_container.begin();
7233 it != stl_container.end(); ++it, ++i) {
7234 StringMatchResultListener inner_listener;
7235 const bool matches = inner_matcher_.MatchAndExplain(*it, &inner_listener);
7236
7237 if (matches != all_elements_should_match) {
7238 *listener << "whose element #" << i
7239 << (matches ? " matches" : " doesn't match");
7240 PrintIfNotEmpty(inner_listener.str(), listener->stream());
7241 return !all_elements_should_match;
7242 }
7243 }
7244 return all_elements_should_match;
7245 }
7246
7247 protected:
7248 const Matcher<const Element&> inner_matcher_;
7249
7250 GTEST_DISALLOW_ASSIGN_(QuantifierMatcherImpl);
7251 };
7252
7253 // Implements Contains(element_matcher) for the given argument type Container.
7254 // Symmetric to EachMatcherImpl.
7255 template <typename Container>
7256 class ContainsMatcherImpl : public QuantifierMatcherImpl<Container> {
7257 public:
7258 template <typename InnerMatcher>
7259 explicit ContainsMatcherImpl(InnerMatcher inner_matcher)
7260 : QuantifierMatcherImpl<Container>(inner_matcher) {}
7261
7262 // Describes what this matcher does.
7263 virtual void DescribeTo(::std::ostream* os) const {
7264 *os << "contains at least one element that ";
7265 this->inner_matcher_.DescribeTo(os);
7266 }
7267
7268 virtual void DescribeNegationTo(::std::ostream* os) const {
7269 *os << "doesn't contain any element that ";
7270 this->inner_matcher_.DescribeTo(os);
7271 }
7272
7273 virtual bool MatchAndExplain(Container container,
7274 MatchResultListener* listener) const {
7275 return this->MatchAndExplainImpl(false, container, listener);
7276 }
7277
7278 private:
7279 GTEST_DISALLOW_ASSIGN_(ContainsMatcherImpl);
7280 };
7281
7282 // Implements Each(element_matcher) for the given argument type Container.
7283 // Symmetric to ContainsMatcherImpl.
7284 template <typename Container>
7285 class EachMatcherImpl : public QuantifierMatcherImpl<Container> {
7286 public:
7287 template <typename InnerMatcher>
7288 explicit EachMatcherImpl(InnerMatcher inner_matcher)
7289 : QuantifierMatcherImpl<Container>(inner_matcher) {}
7290
7291 // Describes what this matcher does.
7292 virtual void DescribeTo(::std::ostream* os) const {
7293 *os << "only contains elements that ";
7294 this->inner_matcher_.DescribeTo(os);
7295 }
7296
7297 virtual void DescribeNegationTo(::std::ostream* os) const {
7298 *os << "contains some element that ";
7299 this->inner_matcher_.DescribeNegationTo(os);
7300 }
7301
7302 virtual bool MatchAndExplain(Container container,
7303 MatchResultListener* listener) const {
7304 return this->MatchAndExplainImpl(true, container, listener);
7305 }
7306
7307 private:
7308 GTEST_DISALLOW_ASSIGN_(EachMatcherImpl);
7309 };
7310
7311 // Implements polymorphic Contains(element_matcher).
7312 template <typename M>
7313 class ContainsMatcher {
7314 public:
7315 explicit ContainsMatcher(M m) : inner_matcher_(m) {}
7316
7317 template <typename Container>
7318 operator Matcher<Container>() const {
7319 return MakeMatcher(new ContainsMatcherImpl<Container>(inner_matcher_));
7320 }
7321
7322 private:
7323 const M inner_matcher_;
7324
7325 GTEST_DISALLOW_ASSIGN_(ContainsMatcher);
7326 };
7327
7328 // Implements polymorphic Each(element_matcher).
7329 template <typename M>
7330 class EachMatcher {
7331 public:
7332 explicit EachMatcher(M m) : inner_matcher_(m) {}
7333
7334 template <typename Container>
7335 operator Matcher<Container>() const {
7336 return MakeMatcher(new EachMatcherImpl<Container>(inner_matcher_));
7337 }
7338
7339 private:
7340 const M inner_matcher_;
7341
7342 GTEST_DISALLOW_ASSIGN_(EachMatcher);
7343 };
7344
7345 // Implements Key(inner_matcher) for the given argument pair type.
7346 // Key(inner_matcher) matches an std::pair whose 'first' field matches
7347 // inner_matcher. For example, Contains(Key(Ge(5))) can be used to match an
7348 // std::map that contains at least one element whose key is >= 5.
7349 template <typename PairType>
7350 class KeyMatcherImpl : public MatcherInterface<PairType> {
7351 public:
7352 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(PairType) RawPairType;
7353 typedef typename RawPairType::first_type KeyType;
7354
7355 template <typename InnerMatcher>
7356 explicit KeyMatcherImpl(InnerMatcher inner_matcher)
7357 : inner_matcher_(
7358 testing::SafeMatcherCast<const KeyType&>(inner_matcher)) {
7359 }
7360
7361 // Returns true iff 'key_value.first' (the key) matches the inner matcher.
7362 virtual bool MatchAndExplain(PairType key_value,
7363 MatchResultListener* listener) const {
7364 StringMatchResultListener inner_listener;
7365 const bool match = inner_matcher_.MatchAndExplain(key_value.first,
7366 &inner_listener);
7367 const internal::string explanation = inner_listener.str();
7368 if (explanation != "") {
7369 *listener << "whose first field is a value " << explanation;
7370 }
7371 return match;
7372 }
7373
7374 // Describes what this matcher does.
7375 virtual void DescribeTo(::std::ostream* os) const {
7376 *os << "has a key that ";
7377 inner_matcher_.DescribeTo(os);
7378 }
7379
7380 // Describes what the negation of this matcher does.
7381 virtual void DescribeNegationTo(::std::ostream* os) const {
7382 *os << "doesn't have a key that ";
7383 inner_matcher_.DescribeTo(os);
7384 }
7385
7386 private:
7387 const Matcher<const KeyType&> inner_matcher_;
7388
7389 GTEST_DISALLOW_ASSIGN_(KeyMatcherImpl);
7390 };
7391
7392 // Implements polymorphic Key(matcher_for_key).
7393 template <typename M>
7394 class KeyMatcher {
7395 public:
7396 explicit KeyMatcher(M m) : matcher_for_key_(m) {}
7397
7398 template <typename PairType>
7399 operator Matcher<PairType>() const {
7400 return MakeMatcher(new KeyMatcherImpl<PairType>(matcher_for_key_));
7401 }
7402
7403 private:
7404 const M matcher_for_key_;
7405
7406 GTEST_DISALLOW_ASSIGN_(KeyMatcher);
7407 };
7408
7409 // Implements Pair(first_matcher, second_matcher) for the given argument pair
7410 // type with its two matchers. See Pair() function below.
7411 template <typename PairType>
7412 class PairMatcherImpl : public MatcherInterface<PairType> {
7413 public:
7414 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(PairType) RawPairType;
7415 typedef typename RawPairType::first_type FirstType;
7416 typedef typename RawPairType::second_type SecondType;
7417
7418 template <typename FirstMatcher, typename SecondMatcher>
7419 PairMatcherImpl(FirstMatcher first_matcher, SecondMatcher second_matcher)
7420 : first_matcher_(
7421 testing::SafeMatcherCast<const FirstType&>(first_matcher)),
7422 second_matcher_(
7423 testing::SafeMatcherCast<const SecondType&>(second_matcher)) {
7424 }
7425
7426 // Describes what this matcher does.
7427 virtual void DescribeTo(::std::ostream* os) const {
7428 *os << "has a first field that ";
7429 first_matcher_.DescribeTo(os);
7430 *os << ", and has a second field that ";
7431 second_matcher_.DescribeTo(os);
7432 }
7433
7434 // Describes what the negation of this matcher does.
7435 virtual void DescribeNegationTo(::std::ostream* os) const {
7436 *os << "has a first field that ";
7437 first_matcher_.DescribeNegationTo(os);
7438 *os << ", or has a second field that ";
7439 second_matcher_.DescribeNegationTo(os);
7440 }
7441
7442 // Returns true iff 'a_pair.first' matches first_matcher and 'a_pair.second'
7443 // matches second_matcher.
7444 virtual bool MatchAndExplain(PairType a_pair,
7445 MatchResultListener* listener) const {
7446 if (!listener->IsInterested()) {
7447 // If the listener is not interested, we don't need to construct the
7448 // explanation.
7449 return first_matcher_.Matches(a_pair.first) &&
7450 second_matcher_.Matches(a_pair.second);
7451 }
7452 StringMatchResultListener first_inner_listener;
7453 if (!first_matcher_.MatchAndExplain(a_pair.first,
7454 &first_inner_listener)) {
7455 *listener << "whose first field does not match";
7456 PrintIfNotEmpty(first_inner_listener.str(), listener->stream());
7457 return false;
7458 }
7459 StringMatchResultListener second_inner_listener;
7460 if (!second_matcher_.MatchAndExplain(a_pair.second,
7461 &second_inner_listener)) {
7462 *listener << "whose second field does not match";
7463 PrintIfNotEmpty(second_inner_listener.str(), listener->stream());
7464 return false;
7465 }
7466 ExplainSuccess(first_inner_listener.str(), second_inner_listener.str(),
7467 listener);
7468 return true;
7469 }
7470
7471 private:
7472 void ExplainSuccess(const internal::string& first_explanation,
7473 const internal::string& second_explanation,
7474 MatchResultListener* listener) const {
7475 *listener << "whose both fields match";
7476 if (first_explanation != "") {
7477 *listener << ", where the first field is a value " << first_explanation;
7478 }
7479 if (second_explanation != "") {
7480 *listener << ", ";
7481 if (first_explanation != "") {
7482 *listener << "and ";
7483 } else {
7484 *listener << "where ";
7485 }
7486 *listener << "the second field is a value " << second_explanation;
7487 }
7488 }
7489
7490 const Matcher<const FirstType&> first_matcher_;
7491 const Matcher<const SecondType&> second_matcher_;
7492
7493 GTEST_DISALLOW_ASSIGN_(PairMatcherImpl);
7494 };
7495
7496 // Implements polymorphic Pair(first_matcher, second_matcher).
7497 template <typename FirstMatcher, typename SecondMatcher>
7498 class PairMatcher {
7499 public:
7500 PairMatcher(FirstMatcher first_matcher, SecondMatcher second_matcher)
7501 : first_matcher_(first_matcher), second_matcher_(second_matcher) {}
7502
7503 template <typename PairType>
7504 operator Matcher<PairType> () const {
7505 return MakeMatcher(
7506 new PairMatcherImpl<PairType>(
7507 first_matcher_, second_matcher_));
7508 }
7509
7510 private:
7511 const FirstMatcher first_matcher_;
7512 const SecondMatcher second_matcher_;
7513
7514 GTEST_DISALLOW_ASSIGN_(PairMatcher);
7515 };
7516
7517 // Implements ElementsAre() and ElementsAreArray().
7518 template <typename Container>
7519 class ElementsAreMatcherImpl : public MatcherInterface<Container> {
7520 public:
7521 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
7522 typedef internal::StlContainerView<RawContainer> View;
7523 typedef typename View::type StlContainer;
7524 typedef typename View::const_reference StlContainerReference;
7525 typedef typename StlContainer::value_type Element;
7526
7527 // Constructs the matcher from a sequence of element values or
7528 // element matchers.
7529 template <typename InputIter>
7530 ElementsAreMatcherImpl(InputIter first, InputIter last) {
7531 while (first != last) {
7532 matchers_.push_back(MatcherCast<const Element&>(*first++));
7533 }
7534 }
7535
7536 // Describes what this matcher does.
7537 virtual void DescribeTo(::std::ostream* os) const {
7538 if (count() == 0) {
7539 *os << "is empty";
7540 } else if (count() == 1) {
7541 *os << "has 1 element that ";
7542 matchers_[0].DescribeTo(os);
7543 } else {
7544 *os << "has " << Elements(count()) << " where\n";
7545 for (size_t i = 0; i != count(); ++i) {
7546 *os << "element #" << i << " ";
7547 matchers_[i].DescribeTo(os);
7548 if (i + 1 < count()) {
7549 *os << ",\n";
7550 }
7551 }
7552 }
7553 }
7554
7555 // Describes what the negation of this matcher does.
7556 virtual void DescribeNegationTo(::std::ostream* os) const {
7557 if (count() == 0) {
7558 *os << "isn't empty";
7559 return;
7560 }
7561
7562 *os << "doesn't have " << Elements(count()) << ", or\n";
7563 for (size_t i = 0; i != count(); ++i) {
7564 *os << "element #" << i << " ";
7565 matchers_[i].DescribeNegationTo(os);
7566 if (i + 1 < count()) {
7567 *os << ", or\n";
7568 }
7569 }
7570 }
7571
7572 virtual bool MatchAndExplain(Container container,
7573 MatchResultListener* listener) const {
7574 // To work with stream-like "containers", we must only walk
7575 // through the elements in one pass.
7576
7577 const bool listener_interested = listener->IsInterested();
7578
7579 // explanations[i] is the explanation of the element at index i.
7580 ::std::vector<internal::string> explanations(count());
7581 StlContainerReference stl_container = View::ConstReference(container);
7582 typename StlContainer::const_iterator it = stl_container.begin();
7583 size_t exam_pos = 0;
7584 bool mismatch_found = false; // Have we found a mismatched element yet?
7585
7586 // Go through the elements and matchers in pairs, until we reach
7587 // the end of either the elements or the matchers, or until we find a
7588 // mismatch.
7589 for (; it != stl_container.end() && exam_pos != count(); ++it, ++exam_pos) {
7590 bool match; // Does the current element match the current matcher?
7591 if (listener_interested) {
7592 StringMatchResultListener s;
7593 match = matchers_[exam_pos].MatchAndExplain(*it, &s);
7594 explanations[exam_pos] = s.str();
7595 } else {
7596 match = matchers_[exam_pos].Matches(*it);
7597 }
7598
7599 if (!match) {
7600 mismatch_found = true;
7601 break;
7602 }
7603 }
7604 // If mismatch_found is true, 'exam_pos' is the index of the mismatch.
7605
7606 // Find how many elements the actual container has. We avoid
7607 // calling size() s.t. this code works for stream-like "containers"
7608 // that don't define size().
7609 size_t actual_count = exam_pos;
7610 for (; it != stl_container.end(); ++it) {
7611 ++actual_count;
7612 }
7613
7614 if (actual_count != count()) {
7615 // The element count doesn't match. If the container is empty,
7616 // there's no need to explain anything as Google Mock already
7617 // prints the empty container. Otherwise we just need to show
7618 // how many elements there actually are.
7619 if (listener_interested && (actual_count != 0)) {
7620 *listener << "which has " << Elements(actual_count);
7621 }
7622 return false;
7623 }
7624
7625 if (mismatch_found) {
7626 // The element count matches, but the exam_pos-th element doesn't match.
7627 if (listener_interested) {
7628 *listener << "whose element #" << exam_pos << " doesn't match";
7629 PrintIfNotEmpty(explanations[exam_pos], listener->stream());
7630 }
7631 return false;
7632 }
7633
7634 // Every element matches its expectation. We need to explain why
7635 // (the obvious ones can be skipped).
7636 if (listener_interested) {
7637 bool reason_printed = false;
7638 for (size_t i = 0; i != count(); ++i) {
7639 const internal::string& s = explanations[i];
7640 if (!s.empty()) {
7641 if (reason_printed) {
7642 *listener << ",\nand ";
7643 }
7644 *listener << "whose element #" << i << " matches, " << s;
7645 reason_printed = true;
7646 }
7647 }
7648 }
7649 return true;
7650 }
7651
7652 private:
7653 static Message Elements(size_t count) {
7654 return Message() << count << (count == 1 ? " element" : " elements");
7655 }
7656
7657 size_t count() const { return matchers_.size(); }
7658
7659 ::std::vector<Matcher<const Element&> > matchers_;
7660
7661 GTEST_DISALLOW_ASSIGN_(ElementsAreMatcherImpl);
7662 };
7663
7664 // Connectivity matrix of (elements X matchers), in element-major order.
7665 // Initially, there are no edges.
7666 // Use NextGraph() to iterate over all possible edge configurations.
7667 // Use Randomize() to generate a random edge configuration.
7668 class GTEST_API_ MatchMatrix {
7669 public:
7670 MatchMatrix(size_t num_elements, size_t num_matchers)
7671 : num_elements_(num_elements),
7672 num_matchers_(num_matchers),
7673 matched_(num_elements_* num_matchers_, 0) {
7674 }
7675
7676 size_t LhsSize() const { return num_elements_; }
7677 size_t RhsSize() const { return num_matchers_; }
7678 bool HasEdge(size_t ilhs, size_t irhs) const {
7679 return matched_[SpaceIndex(ilhs, irhs)] == 1;
7680 }
7681 void SetEdge(size_t ilhs, size_t irhs, bool b) {
7682 matched_[SpaceIndex(ilhs, irhs)] = b ? 1 : 0;
7683 }
7684
7685 // Treating the connectivity matrix as a (LhsSize()*RhsSize())-bit number,
7686 // adds 1 to that number; returns false if incrementing the graph left it
7687 // empty.
7688 bool NextGraph();
7689
7690 void Randomize();
7691
7692 string DebugString() const;
7693
7694 private:
7695 size_t SpaceIndex(size_t ilhs, size_t irhs) const {
7696 return ilhs * num_matchers_ + irhs;
7697 }
7698
7699 size_t num_elements_;
7700 size_t num_matchers_;
7701
7702 // Each element is a char interpreted as bool. They are stored as a
7703 // flattened array in lhs-major order, use 'SpaceIndex()' to translate
7704 // a (ilhs, irhs) matrix coordinate into an offset.
7705 ::std::vector<char> matched_;
7706 };
7707
7708 typedef ::std::pair<size_t, size_t> ElementMatcherPair;
7709 typedef ::std::vector<ElementMatcherPair> ElementMatcherPairs;
7710
7711 // Returns a maximum bipartite matching for the specified graph 'g'.
7712 // The matching is represented as a vector of {element, matcher} pairs.
7713 GTEST_API_ ElementMatcherPairs
7714 FindMaxBipartiteMatching(const MatchMatrix& g);
7715
7716 GTEST_API_ bool FindPairing(const MatchMatrix& matrix,
7717 MatchResultListener* listener);
7718
7719 // Untyped base class for implementing UnorderedElementsAre. By
7720 // putting logic that's not specific to the element type here, we
7721 // reduce binary bloat and increase compilation speed.
7722 class GTEST_API_ UnorderedElementsAreMatcherImplBase {
7723 protected:
7724 // A vector of matcher describers, one for each element matcher.
7725 // Does not own the describers (and thus can be used only when the
7726 // element matchers are alive).
7727 typedef ::std::vector<const MatcherDescriberInterface*> MatcherDescriberVec;
7728
7729 // Describes this UnorderedElementsAre matcher.
7730 void DescribeToImpl(::std::ostream* os) const;
7731
7732 // Describes the negation of this UnorderedElementsAre matcher.
7733 void DescribeNegationToImpl(::std::ostream* os) const;
7734
7735 bool VerifyAllElementsAndMatchersAreMatched(
7736 const ::std::vector<string>& element_printouts,
7737 const MatchMatrix& matrix,
7738 MatchResultListener* listener) const;
7739
7740 MatcherDescriberVec& matcher_describers() {
7741 return matcher_describers_;
7742 }
7743
7744 static Message Elements(size_t n) {
7745 return Message() << n << " element" << (n == 1 ? "" : "s");
7746 }
7747
7748 private:
7749 MatcherDescriberVec matcher_describers_;
7750
7751 GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreMatcherImplBase);
7752 };
7753
7754 // Implements unordered ElementsAre and unordered ElementsAreArray.
7755 template <typename Container>
7756 class UnorderedElementsAreMatcherImpl
7757 : public MatcherInterface<Container>,
7758 public UnorderedElementsAreMatcherImplBase {
7759 public:
7760 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
7761 typedef internal::StlContainerView<RawContainer> View;
7762 typedef typename View::type StlContainer;
7763 typedef typename View::const_reference StlContainerReference;
7764 typedef typename StlContainer::const_iterator StlContainerConstIterator;
7765 typedef typename StlContainer::value_type Element;
7766
7767 // Constructs the matcher from a sequence of element values or
7768 // element matchers.
7769 template <typename InputIter>
7770 UnorderedElementsAreMatcherImpl(InputIter first, InputIter last) {
7771 for (; first != last; ++first) {
7772 matchers_.push_back(MatcherCast<const Element&>(*first));
7773 matcher_describers().push_back(matchers_.back().GetDescriber());
7774 }
7775 }
7776
7777 // Describes what this matcher does.
7778 virtual void DescribeTo(::std::ostream* os) const {
7779 return UnorderedElementsAreMatcherImplBase::DescribeToImpl(os);
7780 }
7781
7782 // Describes what the negation of this matcher does.
7783 virtual void DescribeNegationTo(::std::ostream* os) const {
7784 return UnorderedElementsAreMatcherImplBase::DescribeNegationToImpl(os);
7785 }
7786
7787 virtual bool MatchAndExplain(Container container,
7788 MatchResultListener* listener) const {
7789 StlContainerReference stl_container = View::ConstReference(container);
7790 ::std::vector<string> element_printouts;
7791 MatchMatrix matrix = AnalyzeElements(stl_container.begin(),
7792 stl_container.end(),
7793 &element_printouts,
7794 listener);
7795
7796 const size_t actual_count = matrix.LhsSize();
7797 if (actual_count == 0 && matchers_.empty()) {
7798 return true;
7799 }
7800 if (actual_count != matchers_.size()) {
7801 // The element count doesn't match. If the container is empty,
7802 // there's no need to explain anything as Google Mock already
7803 // prints the empty container. Otherwise we just need to show
7804 // how many elements there actually are.
7805 if (actual_count != 0 && listener->IsInterested()) {
7806 *listener << "which has " << Elements(actual_count);
7807 }
7808 return false;
7809 }
7810
7811 return VerifyAllElementsAndMatchersAreMatched(element_printouts,
7812 matrix, listener) &&
7813 FindPairing(matrix, listener);
7814 }
7815
7816 private:
7817 typedef ::std::vector<Matcher<const Element&> > MatcherVec;
7818
7819 template <typename ElementIter>
7820 MatchMatrix AnalyzeElements(ElementIter elem_first, ElementIter elem_last,
7821 ::std::vector<string>* element_printouts,
7822 MatchResultListener* listener) const {
7823 element_printouts->clear();
7824 ::std::vector<char> did_match;
7825 size_t num_elements = 0;
7826 for (; elem_first != elem_last; ++num_elements, ++elem_first) {
7827 if (listener->IsInterested()) {
7828 element_printouts->push_back(PrintToString(*elem_first));
7829 }
7830 for (size_t irhs = 0; irhs != matchers_.size(); ++irhs) {
7831 did_match.push_back(Matches(matchers_[irhs])(*elem_first));
7832 }
7833 }
7834
7835 MatchMatrix matrix(num_elements, matchers_.size());
7836 ::std::vector<char>::const_iterator did_match_iter = did_match.begin();
7837 for (size_t ilhs = 0; ilhs != num_elements; ++ilhs) {
7838 for (size_t irhs = 0; irhs != matchers_.size(); ++irhs) {
7839 matrix.SetEdge(ilhs, irhs, *did_match_iter++ != 0);
7840 }
7841 }
7842 return matrix;
7843 }
7844
7845 MatcherVec matchers_;
7846
7847 GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreMatcherImpl);
7848 };
7849
7850 // Functor for use in TransformTuple.
7851 // Performs MatcherCast<Target> on an input argument of any type.
7852 template <typename Target>
7853 struct CastAndAppendTransform {
7854 template <typename Arg>
7855 Matcher<Target> operator()(const Arg& a) const {
7856 return MatcherCast<Target>(a);
7857 }
7858 };
7859
7860 // Implements UnorderedElementsAre.
7861 template <typename MatcherTuple>
7862 class UnorderedElementsAreMatcher {
7863 public:
7864 explicit UnorderedElementsAreMatcher(const MatcherTuple& args)
7865 : matchers_(args) {}
7866
7867 template <typename Container>
7868 operator Matcher<Container>() const {
7869 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
7870 typedef typename internal::StlContainerView<RawContainer>::type View;
7871 typedef typename View::value_type Element;
7872 typedef ::std::vector<Matcher<const Element&> > MatcherVec;
7873 MatcherVec matchers;
7874 matchers.reserve(::std::tr1::tuple_size<MatcherTuple>::value);
7875 TransformTupleValues(CastAndAppendTransform<const Element&>(), matchers_,
7876 ::std::back_inserter(matchers));
7877 return MakeMatcher(new UnorderedElementsAreMatcherImpl<Container>(
7878 matchers.begin(), matchers.end()));
7879 }
7880
7881 private:
7882 const MatcherTuple matchers_;
7883 GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreMatcher);
7884 };
7885
7886 // Implements ElementsAre.
7887 template <typename MatcherTuple>
7888 class ElementsAreMatcher {
7889 public:
7890 explicit ElementsAreMatcher(const MatcherTuple& args) : matchers_(args) {}
7891
7892 template <typename Container>
7893 operator Matcher<Container>() const {
7894 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
7895 typedef typename internal::StlContainerView<RawContainer>::type View;
7896 typedef typename View::value_type Element;
7897 typedef ::std::vector<Matcher<const Element&> > MatcherVec;
7898 MatcherVec matchers;
7899 matchers.reserve(::std::tr1::tuple_size<MatcherTuple>::value);
7900 TransformTupleValues(CastAndAppendTransform<const Element&>(), matchers_,
7901 ::std::back_inserter(matchers));
7902 return MakeMatcher(new ElementsAreMatcherImpl<Container>(
7903 matchers.begin(), matchers.end()));
7904 }
7905
7906 private:
7907 const MatcherTuple matchers_;
7908 GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher);
7909 };
7910
7911 // Implements UnorderedElementsAreArray().
7912 template <typename T>
7913 class UnorderedElementsAreArrayMatcher {
7914 public:
7915 UnorderedElementsAreArrayMatcher() {}
7916
7917 template <typename Iter>
7918 UnorderedElementsAreArrayMatcher(Iter first, Iter last)
7919 : matchers_(first, last) {}
7920
7921 template <typename Container>
7922 operator Matcher<Container>() const {
7923 return MakeMatcher(
7924 new UnorderedElementsAreMatcherImpl<Container>(matchers_.begin(),
7925 matchers_.end()));
7926 }
7927
7928 private:
7929 ::std::vector<T> matchers_;
7930
7931 GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreArrayMatcher);
7932 };
7933
7934 // Implements ElementsAreArray().
7935 template <typename T>
7936 class ElementsAreArrayMatcher {
7937 public:
7938 template <typename Iter>
7939 ElementsAreArrayMatcher(Iter first, Iter last) : matchers_(first, last) {}
7940
7941 template <typename Container>
7942 operator Matcher<Container>() const {
7943 return MakeMatcher(new ElementsAreMatcherImpl<Container>(
7944 matchers_.begin(), matchers_.end()));
7945 }
7946
7947 private:
7948 const ::std::vector<T> matchers_;
7949
7950 GTEST_DISALLOW_ASSIGN_(ElementsAreArrayMatcher);
7951 };
7952
7953 // Returns the description for a matcher defined using the MATCHER*()
7954 // macro where the user-supplied description string is "", if
7955 // 'negation' is false; otherwise returns the description of the
7956 // negation of the matcher. 'param_values' contains a list of strings
7957 // that are the print-out of the matcher's parameters.
7958 GTEST_API_ string FormatMatcherDescription(bool negation,
7959 const char* matcher_name,
7960 const Strings& param_values);
7961
7962 } // namespace internal
7963
7964 // ElementsAreArray(first, last)
7965 // ElementsAreArray(pointer, count)
7966 // ElementsAreArray(array)
7967 // ElementsAreArray(vector)
7968 // ElementsAreArray({ e1, e2, ..., en })
7969 //
7970 // The ElementsAreArray() functions are like ElementsAre(...), except
7971 // that they are given a homogeneous sequence rather than taking each
7972 // element as a function argument. The sequence can be specified as an
7973 // array, a pointer and count, a vector, an initializer list, or an
7974 // STL iterator range. In each of these cases, the underlying sequence
7975 // can be either a sequence of values or a sequence of matchers.
7976 //
7977 // All forms of ElementsAreArray() make a copy of the input matcher sequence.
7978
7979 template <typename Iter>
7980 inline internal::ElementsAreArrayMatcher<
7981 typename ::std::iterator_traits<Iter>::value_type>
7982 ElementsAreArray(Iter first, Iter last) {
7983 typedef typename ::std::iterator_traits<Iter>::value_type T;
7984 return internal::ElementsAreArrayMatcher<T>(first, last);
7985 }
7986
7987 template <typename T>
7988 inline internal::ElementsAreArrayMatcher<T> ElementsAreArray(
7989 const T* pointer, size_t count) {
7990 return ElementsAreArray(pointer, pointer + count);
7991 }
7992
7993 template <typename T, size_t N>
7994 inline internal::ElementsAreArrayMatcher<T> ElementsAreArray(
7995 const T (&array)[N]) {
7996 return ElementsAreArray(array, N);
7997 }
7998
7999 template <typename T, typename A>
8000 inline internal::ElementsAreArrayMatcher<T> ElementsAreArray(
8001 const ::std::vector<T, A>& vec) {
8002 return ElementsAreArray(vec.begin(), vec.end());
8003 }
8004
8005 #if GTEST_LANG_CXX11
8006 template <typename T>
8007 inline internal::ElementsAreArrayMatcher<T>
8008 ElementsAreArray(::std::initializer_list<T> xs) {
8009 return ElementsAreArray(xs.begin(), xs.end());
8010 }
8011 #endif
8012
8013 // UnorderedElementsAreArray(first, last)
8014 // UnorderedElementsAreArray(pointer, count)
8015 // UnorderedElementsAreArray(array)
8016 // UnorderedElementsAreArray(vector)
8017 // UnorderedElementsAreArray({ e1, e2, ..., en })
8018 //
8019 // The UnorderedElementsAreArray() functions are like
8020 // ElementsAreArray(...), but allow matching the elements in any order.
8021 template <typename Iter>
8022 inline internal::UnorderedElementsAreArrayMatcher<
8023 typename ::std::iterator_traits<Iter>::value_type>
8024 UnorderedElementsAreArray(Iter first, Iter last) {
8025 typedef typename ::std::iterator_traits<Iter>::value_type T;
8026 return internal::UnorderedElementsAreArrayMatcher<T>(first, last);
8027 }
8028
8029 template <typename T>
8030 inline internal::UnorderedElementsAreArrayMatcher<T>
8031 UnorderedElementsAreArray(const T* pointer, size_t count) {
8032 return UnorderedElementsAreArray(pointer, pointer + count);
8033 }
8034
8035 template <typename T, size_t N>
8036 inline internal::UnorderedElementsAreArrayMatcher<T>
8037 UnorderedElementsAreArray(const T (&array)[N]) {
8038 return UnorderedElementsAreArray(array, N);
8039 }
8040
8041 template <typename T, typename A>
8042 inline internal::UnorderedElementsAreArrayMatcher<T>
8043 UnorderedElementsAreArray(const ::std::vector<T, A>& vec) {
8044 return UnorderedElementsAreArray(vec.begin(), vec.end());
8045 }
8046
8047 #if GTEST_LANG_CXX11
8048 template <typename T>
8049 inline internal::UnorderedElementsAreArrayMatcher<T>
8050 UnorderedElementsAreArray(::std::initializer_list<T> xs) {
8051 return UnorderedElementsAreArray(xs.begin(), xs.end());
8052 }
8053 #endif
8054
8055 // _ is a matcher that matches anything of any type.
8056 //
8057 // This definition is fine as:
8058 //
8059 // 1. The C++ standard permits using the name _ in a namespace that
8060 // is not the global namespace or ::std.
8061 // 2. The AnythingMatcher class has no data member or constructor,
8062 // so it's OK to create global variables of this type.
8063 // 3. c-style has approved of using _ in this case.
8064 const internal::AnythingMatcher _ = {};
8065 // Creates a matcher that matches any value of the given type T.
8066 template <typename T>
8067 inline Matcher<T> A() { return MakeMatcher(new internal::AnyMatcherImpl<T>()); }
8068
8069 // Creates a matcher that matches any value of the given type T.
8070 template <typename T>
8071 inline Matcher<T> An() { return A<T>(); }
8072
8073 // Creates a polymorphic matcher that matches anything equal to x.
8074 // Note: if the parameter of Eq() were declared as const T&, Eq("foo")
8075 // wouldn't compile.
8076 template <typename T>
8077 inline internal::EqMatcher<T> Eq(T x) { return internal::EqMatcher<T>(x); }
8078
8079 // Constructs a Matcher<T> from a 'value' of type T. The constructed
8080 // matcher matches any value that's equal to 'value'.
8081 template <typename T>
8082 Matcher<T>::Matcher(T value) { *this = Eq(value); }
8083
8084 // Creates a monomorphic matcher that matches anything with type Lhs
8085 // and equal to rhs. A user may need to use this instead of Eq(...)
8086 // in order to resolve an overloading ambiguity.
8087 //
8088 // TypedEq<T>(x) is just a convenient short-hand for Matcher<T>(Eq(x))
8089 // or Matcher<T>(x), but more readable than the latter.
8090 //
8091 // We could define similar monomorphic matchers for other comparison
8092 // operations (e.g. TypedLt, TypedGe, and etc), but decided not to do
8093 // it yet as those are used much less than Eq() in practice. A user
8094 // can always write Matcher<T>(Lt(5)) to be explicit about the type,
8095 // for example.
8096 template <typename Lhs, typename Rhs>
8097 inline Matcher<Lhs> TypedEq(const Rhs& rhs) { return Eq(rhs); }
8098
8099 // Creates a polymorphic matcher that matches anything >= x.
8100 template <typename Rhs>
8101 inline internal::GeMatcher<Rhs> Ge(Rhs x) {
8102 return internal::GeMatcher<Rhs>(x);
8103 }
8104
8105 // Creates a polymorphic matcher that matches anything > x.
8106 template <typename Rhs>
8107 inline internal::GtMatcher<Rhs> Gt(Rhs x) {
8108 return internal::GtMatcher<Rhs>(x);
8109 }
8110
8111 // Creates a polymorphic matcher that matches anything <= x.
8112 template <typename Rhs>
8113 inline internal::LeMatcher<Rhs> Le(Rhs x) {
8114 return internal::LeMatcher<Rhs>(x);
8115 }
8116
8117 // Creates a polymorphic matcher that matches anything < x.
8118 template <typename Rhs>
8119 inline internal::LtMatcher<Rhs> Lt(Rhs x) {
8120 return internal::LtMatcher<Rhs>(x);
8121 }
8122
8123 // Creates a polymorphic matcher that matches anything != x.
8124 template <typename Rhs>
8125 inline internal::NeMatcher<Rhs> Ne(Rhs x) {
8126 return internal::NeMatcher<Rhs>(x);
8127 }
8128
8129 // Creates a polymorphic matcher that matches any NULL pointer.
8130 inline PolymorphicMatcher<internal::IsNullMatcher > IsNull() {
8131 return MakePolymorphicMatcher(internal::IsNullMatcher());
8132 }
8133
8134 // Creates a polymorphic matcher that matches any non-NULL pointer.
8135 // This is convenient as Not(NULL) doesn't compile (the compiler
8136 // thinks that that expression is comparing a pointer with an integer).
8137 inline PolymorphicMatcher<internal::NotNullMatcher > NotNull() {
8138 return MakePolymorphicMatcher(internal::NotNullMatcher());
8139 }
8140
8141 // Creates a polymorphic matcher that matches any argument that
8142 // references variable x.
8143 template <typename T>
8144 inline internal::RefMatcher<T&> Ref(T& x) { // NOLINT
8145 return internal::RefMatcher<T&>(x);
8146 }
8147
8148 // Creates a matcher that matches any double argument approximately
8149 // equal to rhs, where two NANs are considered unequal.
8150 inline internal::FloatingEqMatcher<double> DoubleEq(double rhs) {
8151 return internal::FloatingEqMatcher<double>(rhs, false);
8152 }
8153
8154 // Creates a matcher that matches any double argument approximately
8155 // equal to rhs, including NaN values when rhs is NaN.
8156 inline internal::FloatingEqMatcher<double> NanSensitiveDoubleEq(double rhs) {
8157 return internal::FloatingEqMatcher<double>(rhs, true);
8158 }
8159
8160 // Creates a matcher that matches any double argument approximately equal to
8161 // rhs, up to the specified max absolute error bound, where two NANs are
8162 // considered unequal. The max absolute error bound must be non-negative.
8163 inline internal::FloatingEqMatcher<double> DoubleNear(
8164 double rhs, double max_abs_error) {
8165 return internal::FloatingEqMatcher<double>(rhs, false, max_abs_error);
8166 }
8167
8168 // Creates a matcher that matches any double argument approximately equal to
8169 // rhs, up to the specified max absolute error bound, including NaN values when
8170 // rhs is NaN. The max absolute error bound must be non-negative.
8171 inline internal::FloatingEqMatcher<double> NanSensitiveDoubleNear(
8172 double rhs, double max_abs_error) {
8173 return internal::FloatingEqMatcher<double>(rhs, true, max_abs_error);
8174 }
8175
8176 // Creates a matcher that matches any float argument approximately
8177 // equal to rhs, where two NANs are considered unequal.
8178 inline internal::FloatingEqMatcher<float> FloatEq(float rhs) {
8179 return internal::FloatingEqMatcher<float>(rhs, false);
8180 }
8181
8182 // Creates a matcher that matches any float argument approximately
8183 // equal to rhs, including NaN values when rhs is NaN.
8184 inline internal::FloatingEqMatcher<float> NanSensitiveFloatEq(float rhs) {
8185 return internal::FloatingEqMatcher<float>(rhs, true);
8186 }
8187
8188 // Creates a matcher that matches any float argument approximately equal to
8189 // rhs, up to the specified max absolute error bound, where two NANs are
8190 // considered unequal. The max absolute error bound must be non-negative.
8191 inline internal::FloatingEqMatcher<float> FloatNear(
8192 float rhs, float max_abs_error) {
8193 return internal::FloatingEqMatcher<float>(rhs, false, max_abs_error);
8194 }
8195
8196 // Creates a matcher that matches any float argument approximately equal to
8197 // rhs, up to the specified max absolute error bound, including NaN values when
8198 // rhs is NaN. The max absolute error bound must be non-negative.
8199 inline internal::FloatingEqMatcher<float> NanSensitiveFloatNear(
8200 float rhs, float max_abs_error) {
8201 return internal::FloatingEqMatcher<float>(rhs, true, max_abs_error);
8202 }
8203
8204 // Creates a matcher that matches a pointer (raw or smart) that points
8205 // to a value that matches inner_matcher.
8206 template <typename InnerMatcher>
8207 inline internal::PointeeMatcher<InnerMatcher> Pointee(
8208 const InnerMatcher& inner_matcher) {
8209 return internal::PointeeMatcher<InnerMatcher>(inner_matcher);
8210 }
8211
8212 // Creates a matcher that matches an object whose given field matches
8213 // 'matcher'. For example,
8214 // Field(&Foo::number, Ge(5))
8215 // matches a Foo object x iff x.number >= 5.
8216 template <typename Class, typename FieldType, typename FieldMatcher>
8217 inline PolymorphicMatcher<
8218 internal::FieldMatcher<Class, FieldType> > Field(
8219 FieldType Class::*field, const FieldMatcher& matcher) {
8220 return MakePolymorphicMatcher(
8221 internal::FieldMatcher<Class, FieldType>(
8222 field, MatcherCast<const FieldType&>(matcher)));
8223 // The call to MatcherCast() is required for supporting inner
8224 // matchers of compatible types. For example, it allows
8225 // Field(&Foo::bar, m)
8226 // to compile where bar is an int32 and m is a matcher for int64.
8227 }
8228
8229 // Creates a matcher that matches an object whose given property
8230 // matches 'matcher'. For example,
8231 // Property(&Foo::str, StartsWith("hi"))
8232 // matches a Foo object x iff x.str() starts with "hi".
8233 template <typename Class, typename PropertyType, typename PropertyMatcher>
8234 inline PolymorphicMatcher<
8235 internal::PropertyMatcher<Class, PropertyType> > Property(
8236 PropertyType (Class::*property)() const, const PropertyMatcher& matcher) {
8237 return MakePolymorphicMatcher(
8238 internal::PropertyMatcher<Class, PropertyType>(
8239 property,
8240 MatcherCast<GTEST_REFERENCE_TO_CONST_(PropertyType)>(matcher)));
8241 // The call to MatcherCast() is required for supporting inner
8242 // matchers of compatible types. For example, it allows
8243 // Property(&Foo::bar, m)
8244 // to compile where bar() returns an int32 and m is a matcher for int64.
8245 }
8246
8247 // Creates a matcher that matches an object iff the result of applying
8248 // a callable to x matches 'matcher'.
8249 // For example,
8250 // ResultOf(f, StartsWith("hi"))
8251 // matches a Foo object x iff f(x) starts with "hi".
8252 // callable parameter can be a function, function pointer, or a functor.
8253 // Callable has to satisfy the following conditions:
8254 // * It is required to keep no state affecting the results of
8255 // the calls on it and make no assumptions about how many calls
8256 // will be made. Any state it keeps must be protected from the
8257 // concurrent access.
8258 // * If it is a function object, it has to define type result_type.
8259 // We recommend deriving your functor classes from std::unary_function.
8260 template <typename Callable, typename ResultOfMatcher>
8261 internal::ResultOfMatcher<Callable> ResultOf(
8262 Callable callable, const ResultOfMatcher& matcher) {
8263 return internal::ResultOfMatcher<Callable>(
8264 callable,
8265 MatcherCast<typename internal::CallableTraits<Callable>::ResultType>(
8266 matcher));
8267 // The call to MatcherCast() is required for supporting inner
8268 // matchers of compatible types. For example, it allows
8269 // ResultOf(Function, m)
8270 // to compile where Function() returns an int32 and m is a matcher for int64.
8271 }
8272
8273 // String matchers.
8274
8275 // Matches a string equal to str.
8276 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> >
8277 StrEq(const internal::string& str) {
8278 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>(
8279 str, true, true));
8280 }
8281
8282 // Matches a string not equal to str.
8283 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> >
8284 StrNe(const internal::string& str) {
8285 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>(
8286 str, false, true));
8287 }
8288
8289 // Matches a string equal to str, ignoring case.
8290 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> >
8291 StrCaseEq(const internal::string& str) {
8292 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>(
8293 str, true, false));
8294 }
8295
8296 // Matches a string not equal to str, ignoring case.
8297 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> >
8298 StrCaseNe(const internal::string& str) {
8299 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>(
8300 str, false, false));
8301 }
8302
8303 // Creates a matcher that matches any string, std::string, or C string
8304 // that contains the given substring.
8305 inline PolymorphicMatcher<internal::HasSubstrMatcher<internal::string> >
8306 HasSubstr(const internal::string& substring) {
8307 return MakePolymorphicMatcher(internal::HasSubstrMatcher<internal::string>(
8308 substring));
8309 }
8310
8311 // Matches a string that starts with 'prefix' (case-sensitive).
8312 inline PolymorphicMatcher<internal::StartsWithMatcher<internal::string> >
8313 StartsWith(const internal::string& prefix) {
8314 return MakePolymorphicMatcher(internal::StartsWithMatcher<internal::string>(
8315 prefix));
8316 }
8317
8318 // Matches a string that ends with 'suffix' (case-sensitive).
8319 inline PolymorphicMatcher<internal::EndsWithMatcher<internal::string> >
8320 EndsWith(const internal::string& suffix) {
8321 return MakePolymorphicMatcher(internal::EndsWithMatcher<internal::string>(
8322 suffix));
8323 }
8324
8325 // Matches a string that fully matches regular expression 'regex'.
8326 // The matcher takes ownership of 'regex'.
8327 inline PolymorphicMatcher<internal::MatchesRegexMatcher> MatchesRegex(
8328 const internal::RE* regex) {
8329 return MakePolymorphicMatcher(internal::MatchesRegexMatcher(regex, true));
8330 }
8331 inline PolymorphicMatcher<internal::MatchesRegexMatcher> MatchesRegex(
8332 const internal::string& regex) {
8333 return MatchesRegex(new internal::RE(regex));
8334 }
8335
8336 // Matches a string that contains regular expression 'regex'.
8337 // The matcher takes ownership of 'regex'.
8338 inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex(
8339 const internal::RE* regex) {
8340 return MakePolymorphicMatcher(internal::MatchesRegexMatcher(regex, false));
8341 }
8342 inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex(
8343 const internal::string& regex) {
8344 return ContainsRegex(new internal::RE(regex));
8345 }
8346
8347 #if GTEST_HAS_GLOBAL_WSTRING || GTEST_HAS_STD_WSTRING
8348 // Wide string matchers.
8349
8350 // Matches a string equal to str.
8351 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> >
8352 StrEq(const internal::wstring& str) {
8353 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstring>(
8354 str, true, true));
8355 }
8356
8357 // Matches a string not equal to str.
8358 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> >
8359 StrNe(const internal::wstring& str) {
8360 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstring>(
8361 str, false, true));
8362 }
8363
8364 // Matches a string equal to str, ignoring case.
8365 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> >
8366 StrCaseEq(const internal::wstring& str) {
8367 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstring>(
8368 str, true, false));
8369 }
8370
8371 // Matches a string not equal to str, ignoring case.
8372 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> >
8373 StrCaseNe(const internal::wstring& str) {
8374 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstring>(
8375 str, false, false));
8376 }
8377
8378 // Creates a matcher that matches any wstring, std::wstring, or C wide string
8379 // that contains the given substring.
8380 inline PolymorphicMatcher<internal::HasSubstrMatcher<internal::wstring> >
8381 HasSubstr(const internal::wstring& substring) {
8382 return MakePolymorphicMatcher(internal::HasSubstrMatcher<internal::wstring>(
8383 substring));
8384 }
8385
8386 // Matches a string that starts with 'prefix' (case-sensitive).
8387 inline PolymorphicMatcher<internal::StartsWithMatcher<internal::wstring> >
8388 StartsWith(const internal::wstring& prefix) {
8389 return MakePolymorphicMatcher(internal::StartsWithMatcher<internal::wstring>(
8390 prefix));
8391 }
8392
8393 // Matches a string that ends with 'suffix' (case-sensitive).
8394 inline PolymorphicMatcher<internal::EndsWithMatcher<internal::wstring> >
8395 EndsWith(const internal::wstring& suffix) {
8396 return MakePolymorphicMatcher(internal::EndsWithMatcher<internal::wstring>(
8397 suffix));
8398 }
8399
8400 #endif // GTEST_HAS_GLOBAL_WSTRING || GTEST_HAS_STD_WSTRING
8401
8402 // Creates a polymorphic matcher that matches a 2-tuple where the
8403 // first field == the second field.
8404 inline internal::Eq2Matcher Eq() { return internal::Eq2Matcher(); }
8405
8406 // Creates a polymorphic matcher that matches a 2-tuple where the
8407 // first field >= the second field.
8408 inline internal::Ge2Matcher Ge() { return internal::Ge2Matcher(); }
8409
8410 // Creates a polymorphic matcher that matches a 2-tuple where the
8411 // first field > the second field.
8412 inline internal::Gt2Matcher Gt() { return internal::Gt2Matcher(); }
8413
8414 // Creates a polymorphic matcher that matches a 2-tuple where the
8415 // first field <= the second field.
8416 inline internal::Le2Matcher Le() { return internal::Le2Matcher(); }
8417
8418 // Creates a polymorphic matcher that matches a 2-tuple where the
8419 // first field < the second field.
8420 inline internal::Lt2Matcher Lt() { return internal::Lt2Matcher(); }
8421
8422 // Creates a polymorphic matcher that matches a 2-tuple where the
8423 // first field != the second field.
8424 inline internal::Ne2Matcher Ne() { return internal::Ne2Matcher(); }
8425
8426 // Creates a matcher that matches any value of type T that m doesn't
8427 // match.
8428 template <typename InnerMatcher>
8429 inline internal::NotMatcher<InnerMatcher> Not(InnerMatcher m) {
8430 return internal::NotMatcher<InnerMatcher>(m);
8431 }
8432
8433 // Returns a matcher that matches anything that satisfies the given
8434 // predicate. The predicate can be any unary function or functor
8435 // whose return type can be implicitly converted to bool.
8436 template <typename Predicate>
8437 inline PolymorphicMatcher<internal::TrulyMatcher<Predicate> >
8438 Truly(Predicate pred) {
8439 return MakePolymorphicMatcher(internal::TrulyMatcher<Predicate>(pred));
8440 }
8441
8442 // Returns a matcher that matches the container size. The container must
8443 // support both size() and size_type which all STL-like containers provide.
8444 // Note that the parameter 'size' can be a value of type size_type as well as
8445 // matcher. For instance:
8446 // EXPECT_THAT(container, SizeIs(2)); // Checks container has 2 elements.
8447 // EXPECT_THAT(container, SizeIs(Le(2)); // Checks container has at most 2.
8448 template <typename SizeMatcher>
8449 inline internal::SizeIsMatcher<SizeMatcher>
8450 SizeIs(const SizeMatcher& size_matcher) {
8451 return internal::SizeIsMatcher<SizeMatcher>(size_matcher);
8452 }
8453
8454 // Returns a matcher that matches an equal container.
8455 // This matcher behaves like Eq(), but in the event of mismatch lists the
8456 // values that are included in one container but not the other. (Duplicate
8457 // values and order differences are not explained.)
8458 template <typename Container>
8459 inline PolymorphicMatcher<internal::ContainerEqMatcher< // NOLINT
8460 GTEST_REMOVE_CONST_(Container)> >
8461 ContainerEq(const Container& rhs) {
8462 // This following line is for working around a bug in MSVC 8.0,
8463 // which causes Container to be a const type sometimes.
8464 typedef GTEST_REMOVE_CONST_(Container) RawContainer;
8465 return MakePolymorphicMatcher(
8466 internal::ContainerEqMatcher<RawContainer>(rhs));
8467 }
8468
8469 // Returns a matcher that matches a container that, when sorted using
8470 // the given comparator, matches container_matcher.
8471 template <typename Comparator, typename ContainerMatcher>
8472 inline internal::WhenSortedByMatcher<Comparator, ContainerMatcher>
8473 WhenSortedBy(const Comparator& comparator,
8474 const ContainerMatcher& container_matcher) {
8475 return internal::WhenSortedByMatcher<Comparator, ContainerMatcher>(
8476 comparator, container_matcher);
8477 }
8478
8479 // Returns a matcher that matches a container that, when sorted using
8480 // the < operator, matches container_matcher.
8481 template <typename ContainerMatcher>
8482 inline internal::WhenSortedByMatcher<internal::LessComparator, ContainerMatcher>
8483 WhenSorted(const ContainerMatcher& container_matcher) {
8484 return
8485 internal::WhenSortedByMatcher<internal::LessComparator, ContainerMatcher>(
8486 internal::LessComparator(), container_matcher);
8487 }
8488
8489 // Matches an STL-style container or a native array that contains the
8490 // same number of elements as in rhs, where its i-th element and rhs's
8491 // i-th element (as a pair) satisfy the given pair matcher, for all i.
8492 // TupleMatcher must be able to be safely cast to Matcher<tuple<const
8493 // T1&, const T2&> >, where T1 and T2 are the types of elements in the
8494 // LHS container and the RHS container respectively.
8495 template <typename TupleMatcher, typename Container>
8496 inline internal::PointwiseMatcher<TupleMatcher,
8497 GTEST_REMOVE_CONST_(Container)>
8498 Pointwise(const TupleMatcher& tuple_matcher, const Container& rhs) {
8499 // This following line is for working around a bug in MSVC 8.0,
8500 // which causes Container to be a const type sometimes.
8501 typedef GTEST_REMOVE_CONST_(Container) RawContainer;
8502 return internal::PointwiseMatcher<TupleMatcher, RawContainer>(
8503 tuple_matcher, rhs);
8504 }
8505
8506 // Matches an STL-style container or a native array that contains at
8507 // least one element matching the given value or matcher.
8508 //
8509 // Examples:
8510 // ::std::set<int> page_ids;
8511 // page_ids.insert(3);
8512 // page_ids.insert(1);
8513 // EXPECT_THAT(page_ids, Contains(1));
8514 // EXPECT_THAT(page_ids, Contains(Gt(2)));
8515 // EXPECT_THAT(page_ids, Not(Contains(4)));
8516 //
8517 // ::std::map<int, size_t> page_lengths;
8518 // page_lengths[1] = 100;
8519 // EXPECT_THAT(page_lengths,
8520 // Contains(::std::pair<const int, size_t>(1, 100)));
8521 //
8522 // const char* user_ids[] = { "joe", "mike", "tom" };
8523 // EXPECT_THAT(user_ids, Contains(Eq(::std::string("tom"))));
8524 template <typename M>
8525 inline internal::ContainsMatcher<M> Contains(M matcher) {
8526 return internal::ContainsMatcher<M>(matcher);
8527 }
8528
8529 // Matches an STL-style container or a native array that contains only
8530 // elements matching the given value or matcher.
8531 //
8532 // Each(m) is semantically equivalent to Not(Contains(Not(m))). Only
8533 // the messages are different.
8534 //
8535 // Examples:
8536 // ::std::set<int> page_ids;
8537 // // Each(m) matches an empty container, regardless of what m is.
8538 // EXPECT_THAT(page_ids, Each(Eq(1)));
8539 // EXPECT_THAT(page_ids, Each(Eq(77)));
8540 //
8541 // page_ids.insert(3);
8542 // EXPECT_THAT(page_ids, Each(Gt(0)));
8543 // EXPECT_THAT(page_ids, Not(Each(Gt(4))));
8544 // page_ids.insert(1);
8545 // EXPECT_THAT(page_ids, Not(Each(Lt(2))));
8546 //
8547 // ::std::map<int, size_t> page_lengths;
8548 // page_lengths[1] = 100;
8549 // page_lengths[2] = 200;
8550 // page_lengths[3] = 300;
8551 // EXPECT_THAT(page_lengths, Not(Each(Pair(1, 100))));
8552 // EXPECT_THAT(page_lengths, Each(Key(Le(3))));
8553 //
8554 // const char* user_ids[] = { "joe", "mike", "tom" };
8555 // EXPECT_THAT(user_ids, Not(Each(Eq(::std::string("tom")))));
8556 template <typename M>
8557 inline internal::EachMatcher<M> Each(M matcher) {
8558 return internal::EachMatcher<M>(matcher);
8559 }
8560
8561 // Key(inner_matcher) matches an std::pair whose 'first' field matches
8562 // inner_matcher. For example, Contains(Key(Ge(5))) can be used to match an
8563 // std::map that contains at least one element whose key is >= 5.
8564 template <typename M>
8565 inline internal::KeyMatcher<M> Key(M inner_matcher) {
8566 return internal::KeyMatcher<M>(inner_matcher);
8567 }
8568
8569 // Pair(first_matcher, second_matcher) matches a std::pair whose 'first' field
8570 // matches first_matcher and whose 'second' field matches second_matcher. For
8571 // example, EXPECT_THAT(map_type, ElementsAre(Pair(Ge(5), "foo"))) can be used
8572 // to match a std::map<int, string> that contains exactly one element whose key
8573 // is >= 5 and whose value equals "foo".
8574 template <typename FirstMatcher, typename SecondMatcher>
8575 inline internal::PairMatcher<FirstMatcher, SecondMatcher>
8576 Pair(FirstMatcher first_matcher, SecondMatcher second_matcher) {
8577 return internal::PairMatcher<FirstMatcher, SecondMatcher>(
8578 first_matcher, second_matcher);
8579 }
8580
8581 // Returns a predicate that is satisfied by anything that matches the
8582 // given matcher.
8583 template <typename M>
8584 inline internal::MatcherAsPredicate<M> Matches(M matcher) {
8585 return internal::MatcherAsPredicate<M>(matcher);
8586 }
8587
8588 // Returns true iff the value matches the matcher.
8589 template <typename T, typename M>
8590 inline bool Value(const T& value, M matcher) {
8591 return testing::Matches(matcher)(value);
8592 }
8593
8594 // Matches the value against the given matcher and explains the match
8595 // result to listener.
8596 template <typename T, typename M>
8597 inline bool ExplainMatchResult(
8598 M matcher, const T& value, MatchResultListener* listener) {
8599 return SafeMatcherCast<const T&>(matcher).MatchAndExplain(value, listener);
8600 }
8601
8602 #if GTEST_LANG_CXX11
8603 // Define variadic matcher versions. They are overloaded in
8604 // gmock-generated-matchers.h for the cases supported by pre C++11 compilers.
8605 template <typename... Args>
8606 inline internal::AllOfMatcher<Args...> AllOf(const Args&... matchers) {
8607 return internal::AllOfMatcher<Args...>(matchers...);
8608 }
8609
8610 template <typename... Args>
8611 inline internal::AnyOfMatcher<Args...> AnyOf(const Args&... matchers) {
8612 return internal::AnyOfMatcher<Args...>(matchers...);
8613 }
8614
8615 #endif // GTEST_LANG_CXX11
8616
8617 // AllArgs(m) is a synonym of m. This is useful in
8618 //
8619 // EXPECT_CALL(foo, Bar(_, _)).With(AllArgs(Eq()));
8620 //
8621 // which is easier to read than
8622 //
8623 // EXPECT_CALL(foo, Bar(_, _)).With(Eq());
8624 template <typename InnerMatcher>
8625 inline InnerMatcher AllArgs(const InnerMatcher& matcher) { return matcher; }
8626
8627 // These macros allow using matchers to check values in Google Test
8628 // tests. ASSERT_THAT(value, matcher) and EXPECT_THAT(value, matcher)
8629 // succeed iff the value matches the matcher. If the assertion fails,
8630 // the value and the description of the matcher will be printed.
8631 #define ASSERT_THAT(value, matcher) ASSERT_PRED_FORMAT1(\
8632 ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value)
8633 #define EXPECT_THAT(value, matcher) EXPECT_PRED_FORMAT1(\
8634 ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value)
8635
8636 } // namespace testing
8637
8638 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
8639
8640 namespace testing {
8641
8642 // An abstract handle of an expectation.
8643 class Expectation;
8644
8645 // A set of expectation handles.
8646 class ExpectationSet;
8647
8648 // Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION
8649 // and MUST NOT BE USED IN USER CODE!!!
8650 namespace internal {
8651
8652 // Implements a mock function.
8653 template <typename F> class FunctionMocker;
8654
8655 // Base class for expectations.
8656 class ExpectationBase;
8657
8658 // Implements an expectation.
8659 template <typename F> class TypedExpectation;
8660
8661 // Helper class for testing the Expectation class template.
8662 class ExpectationTester;
8663
8664 // Base class for function mockers.
8665 template <typename F> class FunctionMockerBase;
8666
8667 // Protects the mock object registry (in class Mock), all function
8668 // mockers, and all expectations.
8669 //
8670 // The reason we don't use more fine-grained protection is: when a
8671 // mock function Foo() is called, it needs to consult its expectations
8672 // to see which one should be picked. If another thread is allowed to
8673 // call a mock function (either Foo() or a different one) at the same
8674 // time, it could affect the "retired" attributes of Foo()'s
8675 // expectations when InSequence() is used, and thus affect which
8676 // expectation gets picked. Therefore, we sequence all mock function
8677 // calls to ensure the integrity of the mock objects' states.
8678 GTEST_API_ GTEST_DECLARE_STATIC_MUTEX_(g_gmock_mutex);
8679
8680 // Untyped base class for ActionResultHolder<R>.
8681 class UntypedActionResultHolderBase;
8682
8683 // Abstract base class of FunctionMockerBase. This is the
8684 // type-agnostic part of the function mocker interface. Its pure
8685 // virtual methods are implemented by FunctionMockerBase.
8686 class GTEST_API_ UntypedFunctionMockerBase {
8687 public:
8688 UntypedFunctionMockerBase();
8689 virtual ~UntypedFunctionMockerBase();
8690
8691 // Verifies that all expectations on this mock function have been
8692 // satisfied. Reports one or more Google Test non-fatal failures
8693 // and returns false if not.
8694 bool VerifyAndClearExpectationsLocked()
8695 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
8696
8697 // Clears the ON_CALL()s set on this mock function.
8698 virtual void ClearDefaultActionsLocked()
8699 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) = 0;
8700
8701 // In all of the following Untyped* functions, it's the caller's
8702 // responsibility to guarantee the correctness of the arguments'
8703 // types.
8704
8705 // Performs the default action with the given arguments and returns
8706 // the action's result. The call description string will be used in
8707 // the error message to describe the call in the case the default
8708 // action fails.
8709 // L = *
8710 virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction(
8711 const void* untyped_args,
8712 const string& call_description) const = 0;
8713
8714 // Performs the given action with the given arguments and returns
8715 // the action's result.
8716 // L = *
8717 virtual UntypedActionResultHolderBase* UntypedPerformAction(
8718 const void* untyped_action,
8719 const void* untyped_args) const = 0;
8720
8721 // Writes a message that the call is uninteresting (i.e. neither
8722 // explicitly expected nor explicitly unexpected) to the given
8723 // ostream.
8724 virtual void UntypedDescribeUninterestingCall(
8725 const void* untyped_args,
8726 ::std::ostream* os) const
8727 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) = 0;
8728
8729 // Returns the expectation that matches the given function arguments
8730 // (or NULL is there's no match); when a match is found,
8731 // untyped_action is set to point to the action that should be
8732 // performed (or NULL if the action is "do default"), and
8733 // is_excessive is modified to indicate whether the call exceeds the
8734 // expected number.
8735 virtual const ExpectationBase* UntypedFindMatchingExpectation(
8736 const void* untyped_args,
8737 const void** untyped_action, bool* is_excessive,
8738 ::std::ostream* what, ::std::ostream* why)
8739 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) = 0;
8740
8741 // Prints the given function arguments to the ostream.
8742 virtual void UntypedPrintArgs(const void* untyped_args,
8743 ::std::ostream* os) const = 0;
8744
8745 // Sets the mock object this mock method belongs to, and registers
8746 // this information in the global mock registry. Will be called
8747 // whenever an EXPECT_CALL() or ON_CALL() is executed on this mock
8748 // method.
8749 // TODO([email protected]): rename to SetAndRegisterOwner().
8750 void RegisterOwner(const void* mock_obj)
8751 GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
8752
8753 // Sets the mock object this mock method belongs to, and sets the
8754 // name of the mock function. Will be called upon each invocation
8755 // of this mock function.
8756 void SetOwnerAndName(const void* mock_obj, const char* name)
8757 GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
8758
8759 // Returns the mock object this mock method belongs to. Must be
8760 // called after RegisterOwner() or SetOwnerAndName() has been
8761 // called.
8762 const void* MockObject() const
8763 GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
8764
8765 // Returns the name of this mock method. Must be called after
8766 // SetOwnerAndName() has been called.
8767 const char* Name() const
8768 GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
8769
8770 // Returns the result of invoking this mock function with the given
8771 // arguments. This function can be safely called from multiple
8772 // threads concurrently. The caller is responsible for deleting the
8773 // result.
8774 const UntypedActionResultHolderBase* UntypedInvokeWith(
8775 const void* untyped_args)
8776 GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
8777
8778 protected:
8779 typedef std::vector<const void*> UntypedOnCallSpecs;
8780
8781 typedef std::vector<internal::linked_ptr<ExpectationBase> >
8782 UntypedExpectations;
8783
8784 // Returns an Expectation object that references and co-owns exp,
8785 // which must be an expectation on this mock function.
8786 Expectation GetHandleOf(ExpectationBase* exp);
8787
8788 // Address of the mock object this mock method belongs to. Only
8789 // valid after this mock method has been called or
8790 // ON_CALL/EXPECT_CALL has been invoked on it.
8791 const void* mock_obj_; // Protected by g_gmock_mutex.
8792
8793 // Name of the function being mocked. Only valid after this mock
8794 // method has been called.
8795 const char* name_; // Protected by g_gmock_mutex.
8796
8797 // All default action specs for this function mocker.
8798 UntypedOnCallSpecs untyped_on_call_specs_;
8799
8800 // All expectations for this function mocker.
8801 UntypedExpectations untyped_expectations_;
8802 }; // class UntypedFunctionMockerBase
8803
8804 // Untyped base class for OnCallSpec<F>.
8805 class UntypedOnCallSpecBase {
8806 public:
8807 // The arguments are the location of the ON_CALL() statement.
8808 UntypedOnCallSpecBase(const char* a_file, int a_line)
8809 : file_(a_file), line_(a_line), last_clause_(kNone) {}
8810
8811 // Where in the source file was the default action spec defined?
8812 const char* file() const { return file_; }
8813 int line() const { return line_; }
8814
8815 protected:
8816 // Gives each clause in the ON_CALL() statement a name.
8817 enum Clause {
8818 // Do not change the order of the enum members! The run-time
8819 // syntax checking relies on it.
8820 kNone,
8821 kWith,
8822 kWillByDefault
8823 };
8824
8825 // Asserts that the ON_CALL() statement has a certain property.
8826 void AssertSpecProperty(bool property, const string& failure_message) const {
8827 Assert(property, file_, line_, failure_message);
8828 }
8829
8830 // Expects that the ON_CALL() statement has a certain property.
8831 void ExpectSpecProperty(bool property, const string& failure_message) const {
8832 Expect(property, file_, line_, failure_message);
8833 }
8834
8835 const char* file_;
8836 int line_;
8837
8838 // The last clause in the ON_CALL() statement as seen so far.
8839 // Initially kNone and changes as the statement is parsed.
8840 Clause last_clause_;
8841 }; // class UntypedOnCallSpecBase
8842
8843 // This template class implements an ON_CALL spec.
8844 template <typename F>
8845 class OnCallSpec : public UntypedOnCallSpecBase {
8846 public:
8847 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
8848 typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple;
8849
8850 // Constructs an OnCallSpec object from the information inside
8851 // the parenthesis of an ON_CALL() statement.
8852 OnCallSpec(const char* a_file, int a_line,
8853 const ArgumentMatcherTuple& matchers)
8854 : UntypedOnCallSpecBase(a_file, a_line),
8855 matchers_(matchers),
8856 // By default, extra_matcher_ should match anything. However,
8857 // we cannot initialize it with _ as that triggers a compiler
8858 // bug in Symbian's C++ compiler (cannot decide between two
8859 // overloaded constructors of Matcher<const ArgumentTuple&>).
8860 extra_matcher_(A<const ArgumentTuple&>()) {
8861 }
8862
8863 // Implements the .With() clause.
8864 OnCallSpec& With(const Matcher<const ArgumentTuple&>& m) {
8865 // Makes sure this is called at most once.
8866 ExpectSpecProperty(last_clause_ < kWith,
8867 ".With() cannot appear "
8868 "more than once in an ON_CALL().");
8869 last_clause_ = kWith;
8870
8871 extra_matcher_ = m;
8872 return *this;
8873 }
8874
8875 // Implements the .WillByDefault() clause.
8876 OnCallSpec& WillByDefault(const Action<F>& action) {
8877 ExpectSpecProperty(last_clause_ < kWillByDefault,
8878 ".WillByDefault() must appear "
8879 "exactly once in an ON_CALL().");
8880 last_clause_ = kWillByDefault;
8881
8882 ExpectSpecProperty(!action.IsDoDefault(),
8883 "DoDefault() cannot be used in ON_CALL().");
8884 action_ = action;
8885 return *this;
8886 }
8887
8888 // Returns true iff the given arguments match the matchers.
8889 bool Matches(const ArgumentTuple& args) const {
8890 return TupleMatches(matchers_, args) && extra_matcher_.Matches(args);
8891 }
8892
8893 // Returns the action specified by the user.
8894 const Action<F>& GetAction() const {
8895 AssertSpecProperty(last_clause_ == kWillByDefault,
8896 ".WillByDefault() must appear exactly "
8897 "once in an ON_CALL().");
8898 return action_;
8899 }
8900
8901 private:
8902 // The information in statement
8903 //
8904 // ON_CALL(mock_object, Method(matchers))
8905 // .With(multi-argument-matcher)
8906 // .WillByDefault(action);
8907 //
8908 // is recorded in the data members like this:
8909 //
8910 // source file that contains the statement => file_
8911 // line number of the statement => line_
8912 // matchers => matchers_
8913 // multi-argument-matcher => extra_matcher_
8914 // action => action_
8915 ArgumentMatcherTuple matchers_;
8916 Matcher<const ArgumentTuple&> extra_matcher_;
8917 Action<F> action_;
8918 }; // class OnCallSpec
8919
8920 // Possible reactions on uninteresting calls.
8921 enum CallReaction {
8922 kAllow,
8923 kWarn,
8924 kFail,
8925 kDefault = kWarn // By default, warn about uninteresting calls.
8926 };
8927
8928 } // namespace internal
8929
8930 // Utilities for manipulating mock objects.
8931 class GTEST_API_ Mock {
8932 public:
8933 // The following public methods can be called concurrently.
8934
8935 // Tells Google Mock to ignore mock_obj when checking for leaked
8936 // mock objects.
8937 static void AllowLeak(const void* mock_obj)
8938 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
8939
8940 // Verifies and clears all expectations on the given mock object.
8941 // If the expectations aren't satisfied, generates one or more
8942 // Google Test non-fatal failures and returns false.
8943 static bool VerifyAndClearExpectations(void* mock_obj)
8944 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
8945
8946 // Verifies all expectations on the given mock object and clears its
8947 // default actions and expectations. Returns true iff the
8948 // verification was successful.
8949 static bool VerifyAndClear(void* mock_obj)
8950 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
8951
8952 private:
8953 friend class internal::UntypedFunctionMockerBase;
8954
8955 // Needed for a function mocker to register itself (so that we know
8956 // how to clear a mock object).
8957 template <typename F>
8958 friend class internal::FunctionMockerBase;
8959
8960 template <typename M>
8961 friend class NiceMock;
8962
8963 template <typename M>
8964 friend class NaggyMock;
8965
8966 template <typename M>
8967 friend class StrictMock;
8968
8969 // Tells Google Mock to allow uninteresting calls on the given mock
8970 // object.
8971 static void AllowUninterestingCalls(const void* mock_obj)
8972 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
8973
8974 // Tells Google Mock to warn the user about uninteresting calls on
8975 // the given mock object.
8976 static void WarnUninterestingCalls(const void* mock_obj)
8977 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
8978
8979 // Tells Google Mock to fail uninteresting calls on the given mock
8980 // object.
8981 static void FailUninterestingCalls(const void* mock_obj)
8982 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
8983
8984 // Tells Google Mock the given mock object is being destroyed and
8985 // its entry in the call-reaction table should be removed.
8986 static void UnregisterCallReaction(const void* mock_obj)
8987 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
8988
8989 // Returns the reaction Google Mock will have on uninteresting calls
8990 // made on the given mock object.
8991 static internal::CallReaction GetReactionOnUninterestingCalls(
8992 const void* mock_obj)
8993 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
8994
8995 // Verifies that all expectations on the given mock object have been
8996 // satisfied. Reports one or more Google Test non-fatal failures
8997 // and returns false if not.
8998 static bool VerifyAndClearExpectationsLocked(void* mock_obj)
8999 GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex);
9000
9001 // Clears all ON_CALL()s set on the given mock object.
9002 static void ClearDefaultActionsLocked(void* mock_obj)
9003 GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex);
9004
9005 // Registers a mock object and a mock method it owns.
9006 static void Register(
9007 const void* mock_obj,
9008 internal::UntypedFunctionMockerBase* mocker)
9009 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
9010
9011 // Tells Google Mock where in the source code mock_obj is used in an
9012 // ON_CALL or EXPECT_CALL. In case mock_obj is leaked, this
9013 // information helps the user identify which object it is.
9014 static void RegisterUseByOnCallOrExpectCall(
9015 const void* mock_obj, const char* file, int line)
9016 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
9017
9018 // Unregisters a mock method; removes the owning mock object from
9019 // the registry when the last mock method associated with it has
9020 // been unregistered. This is called only in the destructor of
9021 // FunctionMockerBase.
9022 static void UnregisterLocked(internal::UntypedFunctionMockerBase* mocker)
9023 GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex);
9024 }; // class Mock
9025
9026 // An abstract handle of an expectation. Useful in the .After()
9027 // clause of EXPECT_CALL() for setting the (partial) order of
9028 // expectations. The syntax:
9029 //
9030 // Expectation e1 = EXPECT_CALL(...)...;
9031 // EXPECT_CALL(...).After(e1)...;
9032 //
9033 // sets two expectations where the latter can only be matched after
9034 // the former has been satisfied.
9035 //
9036 // Notes:
9037 // - This class is copyable and has value semantics.
9038 // - Constness is shallow: a const Expectation object itself cannot
9039 // be modified, but the mutable methods of the ExpectationBase
9040 // object it references can be called via expectation_base().
9041 // - The constructors and destructor are defined out-of-line because
9042 // the Symbian WINSCW compiler wants to otherwise instantiate them
9043 // when it sees this class definition, at which point it doesn't have
9044 // ExpectationBase available yet, leading to incorrect destruction
9045 // in the linked_ptr (or compilation errors if using a checking
9046 // linked_ptr).
9047 class GTEST_API_ Expectation {
9048 public:
9049 // Constructs a null object that doesn't reference any expectation.
9050 Expectation();
9051
9052 ~Expectation();
9053
9054 // This single-argument ctor must not be explicit, in order to support the
9055 // Expectation e = EXPECT_CALL(...);
9056 // syntax.
9057 //
9058 // A TypedExpectation object stores its pre-requisites as
9059 // Expectation objects, and needs to call the non-const Retire()
9060 // method on the ExpectationBase objects they reference. Therefore
9061 // Expectation must receive a *non-const* reference to the
9062 // ExpectationBase object.
9063 Expectation(internal::ExpectationBase& exp); // NOLINT
9064
9065 // The compiler-generated copy ctor and operator= work exactly as
9066 // intended, so we don't need to define our own.
9067
9068 // Returns true iff rhs references the same expectation as this object does.
9069 bool operator==(const Expectation& rhs) const {
9070 return expectation_base_ == rhs.expectation_base_;
9071 }
9072
9073 bool operator!=(const Expectation& rhs) const { return !(*this == rhs); }
9074
9075 private:
9076 friend class ExpectationSet;
9077 friend class Sequence;
9078 friend class ::testing::internal::ExpectationBase;
9079 friend class ::testing::internal::UntypedFunctionMockerBase;
9080
9081 template <typename F>
9082 friend class ::testing::internal::FunctionMockerBase;
9083
9084 template <typename F>
9085 friend class ::testing::internal::TypedExpectation;
9086
9087 // This comparator is needed for putting Expectation objects into a set.
9088 class Less {
9089 public:
9090 bool operator()(const Expectation& lhs, const Expectation& rhs) const {
9091 return lhs.expectation_base_.get() < rhs.expectation_base_.get();
9092 }
9093 };
9094
9095 typedef ::std::set<Expectation, Less> Set;
9096
9097 Expectation(
9098 const internal::linked_ptr<internal::ExpectationBase>& expectation_base);
9099
9100 // Returns the expectation this object references.
9101 const internal::linked_ptr<internal::ExpectationBase>&
9102 expectation_base() const {
9103 return expectation_base_;
9104 }
9105
9106 // A linked_ptr that co-owns the expectation this handle references.
9107 internal::linked_ptr<internal::ExpectationBase> expectation_base_;
9108 };
9109
9110 // A set of expectation handles. Useful in the .After() clause of
9111 // EXPECT_CALL() for setting the (partial) order of expectations. The
9112 // syntax:
9113 //
9114 // ExpectationSet es;
9115 // es += EXPECT_CALL(...)...;
9116 // es += EXPECT_CALL(...)...;
9117 // EXPECT_CALL(...).After(es)...;
9118 //
9119 // sets three expectations where the last one can only be matched
9120 // after the first two have both been satisfied.
9121 //
9122 // This class is copyable and has value semantics.
9123 class ExpectationSet {
9124 public:
9125 // A bidirectional iterator that can read a const element in the set.
9126 typedef Expectation::Set::const_iterator const_iterator;
9127
9128 // An object stored in the set. This is an alias of Expectation.
9129 typedef Expectation::Set::value_type value_type;
9130
9131 // Constructs an empty set.
9132 ExpectationSet() {}
9133
9134 // This single-argument ctor must not be explicit, in order to support the
9135 // ExpectationSet es = EXPECT_CALL(...);
9136 // syntax.
9137 ExpectationSet(internal::ExpectationBase& exp) { // NOLINT
9138 *this += Expectation(exp);
9139 }
9140
9141 // This single-argument ctor implements implicit conversion from
9142 // Expectation and thus must not be explicit. This allows either an
9143 // Expectation or an ExpectationSet to be used in .After().
9144 ExpectationSet(const Expectation& e) { // NOLINT
9145 *this += e;
9146 }
9147
9148 // The compiler-generator ctor and operator= works exactly as
9149 // intended, so we don't need to define our own.
9150
9151 // Returns true iff rhs contains the same set of Expectation objects
9152 // as this does.
9153 bool operator==(const ExpectationSet& rhs) const {
9154 return expectations_ == rhs.expectations_;
9155 }
9156
9157 bool operator!=(const ExpectationSet& rhs) const { return !(*this == rhs); }
9158
9159 // Implements the syntax
9160 // expectation_set += EXPECT_CALL(...);
9161 ExpectationSet& operator+=(const Expectation& e) {
9162 expectations_.insert(e);
9163 return *this;
9164 }
9165
9166 int size() const { return static_cast<int>(expectations_.size()); }
9167
9168 const_iterator begin() const { return expectations_.begin(); }
9169 const_iterator end() const { return expectations_.end(); }
9170
9171 private:
9172 Expectation::Set expectations_;
9173 };
9174
9175
9176 // Sequence objects are used by a user to specify the relative order
9177 // in which the expectations should match. They are copyable (we rely
9178 // on the compiler-defined copy constructor and assignment operator).
9179 class GTEST_API_ Sequence {
9180 public:
9181 // Constructs an empty sequence.
9182 Sequence() : last_expectation_(new Expectation) {}
9183
9184 // Adds an expectation to this sequence. The caller must ensure
9185 // that no other thread is accessing this Sequence object.
9186 void AddExpectation(const Expectation& expectation) const;
9187
9188 private:
9189 // The last expectation in this sequence. We use a linked_ptr here
9190 // because Sequence objects are copyable and we want the copies to
9191 // be aliases. The linked_ptr allows the copies to co-own and share
9192 // the same Expectation object.
9193 internal::linked_ptr<Expectation> last_expectation_;
9194 }; // class Sequence
9195
9196 // An object of this type causes all EXPECT_CALL() statements
9197 // encountered in its scope to be put in an anonymous sequence. The
9198 // work is done in the constructor and destructor. You should only
9199 // create an InSequence object on the stack.
9200 //
9201 // The sole purpose for this class is to support easy definition of
9202 // sequential expectations, e.g.
9203 //
9204 // {
9205 // InSequence dummy; // The name of the object doesn't matter.
9206 //
9207 // // The following expectations must match in the order they appear.
9208 // EXPECT_CALL(a, Bar())...;
9209 // EXPECT_CALL(a, Baz())...;
9210 // ...
9211 // EXPECT_CALL(b, Xyz())...;
9212 // }
9213 //
9214 // You can create InSequence objects in multiple threads, as long as
9215 // they are used to affect different mock objects. The idea is that
9216 // each thread can create and set up its own mocks as if it's the only
9217 // thread. However, for clarity of your tests we recommend you to set
9218 // up mocks in the main thread unless you have a good reason not to do
9219 // so.
9220 class GTEST_API_ InSequence {
9221 public:
9222 InSequence();
9223 ~InSequence();
9224 private:
9225 bool sequence_created_;
9226
9227 GTEST_DISALLOW_COPY_AND_ASSIGN_(InSequence); // NOLINT
9228 } GTEST_ATTRIBUTE_UNUSED_;
9229
9230 namespace internal {
9231
9232 // Points to the implicit sequence introduced by a living InSequence
9233 // object (if any) in the current thread or NULL.
9234 GTEST_API_ extern ThreadLocal<Sequence*> g_gmock_implicit_sequence;
9235
9236 // Base class for implementing expectations.
9237 //
9238 // There are two reasons for having a type-agnostic base class for
9239 // Expectation:
9240 //
9241 // 1. We need to store collections of expectations of different
9242 // types (e.g. all pre-requisites of a particular expectation, all
9243 // expectations in a sequence). Therefore these expectation objects
9244 // must share a common base class.
9245 //
9246 // 2. We can avoid binary code bloat by moving methods not depending
9247 // on the template argument of Expectation to the base class.
9248 //
9249 // This class is internal and mustn't be used by user code directly.
9250 class GTEST_API_ ExpectationBase {
9251 public:
9252 // source_text is the EXPECT_CALL(...) source that created this Expectation.
9253 ExpectationBase(const char* file, int line, const string& source_text);
9254
9255 virtual ~ExpectationBase();
9256
9257 // Where in the source file was the expectation spec defined?
9258 const char* file() const { return file_; }
9259 int line() const { return line_; }
9260 const char* source_text() const { return source_text_.c_str(); }
9261 // Returns the cardinality specified in the expectation spec.
9262 const Cardinality& cardinality() const { return cardinality_; }
9263
9264 // Describes the source file location of this expectation.
9265 void DescribeLocationTo(::std::ostream* os) const {
9266 *os << FormatFileLocation(file(), line()) << " ";
9267 }
9268
9269 // Describes how many times a function call matching this
9270 // expectation has occurred.
9271 void DescribeCallCountTo(::std::ostream* os) const
9272 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
9273
9274 // If this mock method has an extra matcher (i.e. .With(matcher)),
9275 // describes it to the ostream.
9276 virtual void MaybeDescribeExtraMatcherTo(::std::ostream* os) = 0;
9277
9278 protected:
9279 friend class ::testing::Expectation;
9280 friend class UntypedFunctionMockerBase;
9281
9282 enum Clause {
9283 // Don't change the order of the enum members!
9284 kNone,
9285 kWith,
9286 kTimes,
9287 kInSequence,
9288 kAfter,
9289 kWillOnce,
9290 kWillRepeatedly,
9291 kRetiresOnSaturation
9292 };
9293
9294 typedef std::vector<const void*> UntypedActions;
9295
9296 // Returns an Expectation object that references and co-owns this
9297 // expectation.
9298 virtual Expectation GetHandle() = 0;
9299
9300 // Asserts that the EXPECT_CALL() statement has the given property.
9301 void AssertSpecProperty(bool property, const string& failure_message) const {
9302 Assert(property, file_, line_, failure_message);
9303 }
9304
9305 // Expects that the EXPECT_CALL() statement has the given property.
9306 void ExpectSpecProperty(bool property, const string& failure_message) const {
9307 Expect(property, file_, line_, failure_message);
9308 }
9309
9310 // Explicitly specifies the cardinality of this expectation. Used
9311 // by the subclasses to implement the .Times() clause.
9312 void SpecifyCardinality(const Cardinality& cardinality);
9313
9314 // Returns true iff the user specified the cardinality explicitly
9315 // using a .Times().
9316 bool cardinality_specified() const { return cardinality_specified_; }
9317
9318 // Sets the cardinality of this expectation spec.
9319 void set_cardinality(const Cardinality& a_cardinality) {
9320 cardinality_ = a_cardinality;
9321 }
9322
9323 // The following group of methods should only be called after the
9324 // EXPECT_CALL() statement, and only when g_gmock_mutex is held by
9325 // the current thread.
9326
9327 // Retires all pre-requisites of this expectation.
9328 void RetireAllPreRequisites()
9329 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
9330
9331 // Returns true iff this expectation is retired.
9332 bool is_retired() const
9333 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9334 g_gmock_mutex.AssertHeld();
9335 return retired_;
9336 }
9337
9338 // Retires this expectation.
9339 void Retire()
9340 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9341 g_gmock_mutex.AssertHeld();
9342 retired_ = true;
9343 }
9344
9345 // Returns true iff this expectation is satisfied.
9346 bool IsSatisfied() const
9347 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9348 g_gmock_mutex.AssertHeld();
9349 return cardinality().IsSatisfiedByCallCount(call_count_);
9350 }
9351
9352 // Returns true iff this expectation is saturated.
9353 bool IsSaturated() const
9354 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9355 g_gmock_mutex.AssertHeld();
9356 return cardinality().IsSaturatedByCallCount(call_count_);
9357 }
9358
9359 // Returns true iff this expectation is over-saturated.
9360 bool IsOverSaturated() const
9361 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9362 g_gmock_mutex.AssertHeld();
9363 return cardinality().IsOverSaturatedByCallCount(call_count_);
9364 }
9365
9366 // Returns true iff all pre-requisites of this expectation are satisfied.
9367 bool AllPrerequisitesAreSatisfied() const
9368 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
9369
9370 // Adds unsatisfied pre-requisites of this expectation to 'result'.
9371 void FindUnsatisfiedPrerequisites(ExpectationSet* result) const
9372 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
9373
9374 // Returns the number this expectation has been invoked.
9375 int call_count() const
9376 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9377 g_gmock_mutex.AssertHeld();
9378 return call_count_;
9379 }
9380
9381 // Increments the number this expectation has been invoked.
9382 void IncrementCallCount()
9383 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9384 g_gmock_mutex.AssertHeld();
9385 call_count_++;
9386 }
9387
9388 // Checks the action count (i.e. the number of WillOnce() and
9389 // WillRepeatedly() clauses) against the cardinality if this hasn't
9390 // been done before. Prints a warning if there are too many or too
9391 // few actions.
9392 void CheckActionCountIfNotDone() const
9393 GTEST_LOCK_EXCLUDED_(mutex_);
9394
9395 friend class ::testing::Sequence;
9396 friend class ::testing::internal::ExpectationTester;
9397
9398 template <typename Function>
9399 friend class TypedExpectation;
9400
9401 // Implements the .Times() clause.
9402 void UntypedTimes(const Cardinality& a_cardinality);
9403
9404 // This group of fields are part of the spec and won't change after
9405 // an EXPECT_CALL() statement finishes.
9406 const char* file_; // The file that contains the expectation.
9407 int line_; // The line number of the expectation.
9408 const string source_text_; // The EXPECT_CALL(...) source text.
9409 // True iff the cardinality is specified explicitly.
9410 bool cardinality_specified_;
9411 Cardinality cardinality_; // The cardinality of the expectation.
9412 // The immediate pre-requisites (i.e. expectations that must be
9413 // satisfied before this expectation can be matched) of this
9414 // expectation. We use linked_ptr in the set because we want an
9415 // Expectation object to be co-owned by its FunctionMocker and its
9416 // successors. This allows multiple mock objects to be deleted at
9417 // different times.
9418 ExpectationSet immediate_prerequisites_;
9419
9420 // This group of fields are the current state of the expectation,
9421 // and can change as the mock function is called.
9422 int call_count_; // How many times this expectation has been invoked.
9423 bool retired_; // True iff this expectation has retired.
9424 UntypedActions untyped_actions_;
9425 bool extra_matcher_specified_;
9426 bool repeated_action_specified_; // True if a WillRepeatedly() was specified.
9427 bool retires_on_saturation_;
9428 Clause last_clause_;
9429 mutable bool action_count_checked_; // Under mutex_.
9430 mutable Mutex mutex_; // Protects action_count_checked_.
9431
9432 GTEST_DISALLOW_ASSIGN_(ExpectationBase);
9433 }; // class ExpectationBase
9434
9435 // Impements an expectation for the given function type.
9436 template <typename F>
9437 class TypedExpectation : public ExpectationBase {
9438 public:
9439 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
9440 typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple;
9441 typedef typename Function<F>::Result Result;
9442
9443 TypedExpectation(FunctionMockerBase<F>* owner,
9444 const char* a_file, int a_line, const string& a_source_text,
9445 const ArgumentMatcherTuple& m)
9446 : ExpectationBase(a_file, a_line, a_source_text),
9447 owner_(owner),
9448 matchers_(m),
9449 // By default, extra_matcher_ should match anything. However,
9450 // we cannot initialize it with _ as that triggers a compiler
9451 // bug in Symbian's C++ compiler (cannot decide between two
9452 // overloaded constructors of Matcher<const ArgumentTuple&>).
9453 extra_matcher_(A<const ArgumentTuple&>()),
9454 repeated_action_(DoDefault()) {}
9455
9456 virtual ~TypedExpectation() {
9457 // Check the validity of the action count if it hasn't been done
9458 // yet (for example, if the expectation was never used).
9459 CheckActionCountIfNotDone();
9460 for (UntypedActions::const_iterator it = untyped_actions_.begin();
9461 it != untyped_actions_.end(); ++it) {
9462 delete static_cast<const Action<F>*>(*it);
9463 }
9464 }
9465
9466 // Implements the .With() clause.
9467 TypedExpectation& With(const Matcher<const ArgumentTuple&>& m) {
9468 if (last_clause_ == kWith) {
9469 ExpectSpecProperty(false,
9470 ".With() cannot appear "
9471 "more than once in an EXPECT_CALL().");
9472 } else {
9473 ExpectSpecProperty(last_clause_ < kWith,
9474 ".With() must be the first "
9475 "clause in an EXPECT_CALL().");
9476 }
9477 last_clause_ = kWith;
9478
9479 extra_matcher_ = m;
9480 extra_matcher_specified_ = true;
9481 return *this;
9482 }
9483
9484 // Implements the .Times() clause.
9485 TypedExpectation& Times(const Cardinality& a_cardinality) {
9486 ExpectationBase::UntypedTimes(a_cardinality);
9487 return *this;
9488 }
9489
9490 // Implements the .Times() clause.
9491 TypedExpectation& Times(int n) {
9492 return Times(Exactly(n));
9493 }
9494
9495 // Implements the .InSequence() clause.
9496 TypedExpectation& InSequence(const Sequence& s) {
9497 ExpectSpecProperty(last_clause_ <= kInSequence,
9498 ".InSequence() cannot appear after .After(),"
9499 " .WillOnce(), .WillRepeatedly(), or "
9500 ".RetiresOnSaturation().");
9501 last_clause_ = kInSequence;
9502
9503 s.AddExpectation(GetHandle());
9504 return *this;
9505 }
9506 TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2) {
9507 return InSequence(s1).InSequence(s2);
9508 }
9509 TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2,
9510 const Sequence& s3) {
9511 return InSequence(s1, s2).InSequence(s3);
9512 }
9513 TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2,
9514 const Sequence& s3, const Sequence& s4) {
9515 return InSequence(s1, s2, s3).InSequence(s4);
9516 }
9517 TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2,
9518 const Sequence& s3, const Sequence& s4,
9519 const Sequence& s5) {
9520 return InSequence(s1, s2, s3, s4).InSequence(s5);
9521 }
9522
9523 // Implements that .After() clause.
9524 TypedExpectation& After(const ExpectationSet& s) {
9525 ExpectSpecProperty(last_clause_ <= kAfter,
9526 ".After() cannot appear after .WillOnce(),"
9527 " .WillRepeatedly(), or "
9528 ".RetiresOnSaturation().");
9529 last_clause_ = kAfter;
9530
9531 for (ExpectationSet::const_iterator it = s.begin(); it != s.end(); ++it) {
9532 immediate_prerequisites_ += *it;
9533 }
9534 return *this;
9535 }
9536 TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2) {
9537 return After(s1).After(s2);
9538 }
9539 TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2,
9540 const ExpectationSet& s3) {
9541 return After(s1, s2).After(s3);
9542 }
9543 TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2,
9544 const ExpectationSet& s3, const ExpectationSet& s4) {
9545 return After(s1, s2, s3).After(s4);
9546 }
9547 TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2,
9548 const ExpectationSet& s3, const ExpectationSet& s4,
9549 const ExpectationSet& s5) {
9550 return After(s1, s2, s3, s4).After(s5);
9551 }
9552
9553 // Implements the .WillOnce() clause.
9554 TypedExpectation& WillOnce(const Action<F>& action) {
9555 ExpectSpecProperty(last_clause_ <= kWillOnce,
9556 ".WillOnce() cannot appear after "
9557 ".WillRepeatedly() or .RetiresOnSaturation().");
9558 last_clause_ = kWillOnce;
9559
9560 untyped_actions_.push_back(new Action<F>(action));
9561 if (!cardinality_specified()) {
9562 set_cardinality(Exactly(static_cast<int>(untyped_actions_.size())));
9563 }
9564 return *this;
9565 }
9566
9567 // Implements the .WillRepeatedly() clause.
9568 TypedExpectation& WillRepeatedly(const Action<F>& action) {
9569 if (last_clause_ == kWillRepeatedly) {
9570 ExpectSpecProperty(false,
9571 ".WillRepeatedly() cannot appear "
9572 "more than once in an EXPECT_CALL().");
9573 } else {
9574 ExpectSpecProperty(last_clause_ < kWillRepeatedly,
9575 ".WillRepeatedly() cannot appear "
9576 "after .RetiresOnSaturation().");
9577 }
9578 last_clause_ = kWillRepeatedly;
9579 repeated_action_specified_ = true;
9580
9581 repeated_action_ = action;
9582 if (!cardinality_specified()) {
9583 set_cardinality(AtLeast(static_cast<int>(untyped_actions_.size())));
9584 }
9585
9586 // Now that no more action clauses can be specified, we check
9587 // whether their count makes sense.
9588 CheckActionCountIfNotDone();
9589 return *this;
9590 }
9591
9592 // Implements the .RetiresOnSaturation() clause.
9593 TypedExpectation& RetiresOnSaturation() {
9594 ExpectSpecProperty(last_clause_ < kRetiresOnSaturation,
9595 ".RetiresOnSaturation() cannot appear "
9596 "more than once.");
9597 last_clause_ = kRetiresOnSaturation;
9598 retires_on_saturation_ = true;
9599
9600 // Now that no more action clauses can be specified, we check
9601 // whether their count makes sense.
9602 CheckActionCountIfNotDone();
9603 return *this;
9604 }
9605
9606 // Returns the matchers for the arguments as specified inside the
9607 // EXPECT_CALL() macro.
9608 const ArgumentMatcherTuple& matchers() const {
9609 return matchers_;
9610 }
9611
9612 // Returns the matcher specified by the .With() clause.
9613 const Matcher<const ArgumentTuple&>& extra_matcher() const {
9614 return extra_matcher_;
9615 }
9616
9617 // Returns the action specified by the .WillRepeatedly() clause.
9618 const Action<F>& repeated_action() const { return repeated_action_; }
9619
9620 // If this mock method has an extra matcher (i.e. .With(matcher)),
9621 // describes it to the ostream.
9622 virtual void MaybeDescribeExtraMatcherTo(::std::ostream* os) {
9623 if (extra_matcher_specified_) {
9624 *os << " Expected args: ";
9625 extra_matcher_.DescribeTo(os);
9626 *os << "\n";
9627 }
9628 }
9629
9630 private:
9631 template <typename Function>
9632 friend class FunctionMockerBase;
9633
9634 // Returns an Expectation object that references and co-owns this
9635 // expectation.
9636 virtual Expectation GetHandle() {
9637 return owner_->GetHandleOf(this);
9638 }
9639
9640 // The following methods will be called only after the EXPECT_CALL()
9641 // statement finishes and when the current thread holds
9642 // g_gmock_mutex.
9643
9644 // Returns true iff this expectation matches the given arguments.
9645 bool Matches(const ArgumentTuple& args) const
9646 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9647 g_gmock_mutex.AssertHeld();
9648 return TupleMatches(matchers_, args) && extra_matcher_.Matches(args);
9649 }
9650
9651 // Returns true iff this expectation should handle the given arguments.
9652 bool ShouldHandleArguments(const ArgumentTuple& args) const
9653 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9654 g_gmock_mutex.AssertHeld();
9655
9656 // In case the action count wasn't checked when the expectation
9657 // was defined (e.g. if this expectation has no WillRepeatedly()
9658 // or RetiresOnSaturation() clause), we check it when the
9659 // expectation is used for the first time.
9660 CheckActionCountIfNotDone();
9661 return !is_retired() && AllPrerequisitesAreSatisfied() && Matches(args);
9662 }
9663
9664 // Describes the result of matching the arguments against this
9665 // expectation to the given ostream.
9666 void ExplainMatchResultTo(
9667 const ArgumentTuple& args,
9668 ::std::ostream* os) const
9669 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9670 g_gmock_mutex.AssertHeld();
9671
9672 if (is_retired()) {
9673 *os << " Expected: the expectation is active\n"
9674 << " Actual: it is retired\n";
9675 } else if (!Matches(args)) {
9676 if (!TupleMatches(matchers_, args)) {
9677 ExplainMatchFailureTupleTo(matchers_, args, os);
9678 }
9679 StringMatchResultListener listener;
9680 if (!extra_matcher_.MatchAndExplain(args, &listener)) {
9681 *os << " Expected args: ";
9682 extra_matcher_.DescribeTo(os);
9683 *os << "\n Actual: don't match";
9684
9685 internal::PrintIfNotEmpty(listener.str(), os);
9686 *os << "\n";
9687 }
9688 } else if (!AllPrerequisitesAreSatisfied()) {
9689 *os << " Expected: all pre-requisites are satisfied\n"
9690 << " Actual: the following immediate pre-requisites "
9691 << "are not satisfied:\n";
9692 ExpectationSet unsatisfied_prereqs;
9693 FindUnsatisfiedPrerequisites(&unsatisfied_prereqs);
9694 int i = 0;
9695 for (ExpectationSet::const_iterator it = unsatisfied_prereqs.begin();
9696 it != unsatisfied_prereqs.end(); ++it) {
9697 it->expectation_base()->DescribeLocationTo(os);
9698 *os << "pre-requisite #" << i++ << "\n";
9699 }
9700 *os << " (end of pre-requisites)\n";
9701 } else {
9702 // This line is here just for completeness' sake. It will never
9703 // be executed as currently the ExplainMatchResultTo() function
9704 // is called only when the mock function call does NOT match the
9705 // expectation.
9706 *os << "The call matches the expectation.\n";
9707 }
9708 }
9709
9710 // Returns the action that should be taken for the current invocation.
9711 const Action<F>& GetCurrentAction(
9712 const FunctionMockerBase<F>* mocker,
9713 const ArgumentTuple& args) const
9714 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9715 g_gmock_mutex.AssertHeld();
9716 const int count = call_count();
9717 Assert(count >= 1, __FILE__, __LINE__,
9718 "call_count() is <= 0 when GetCurrentAction() is "
9719 "called - this should never happen.");
9720
9721 const int action_count = static_cast<int>(untyped_actions_.size());
9722 if (action_count > 0 && !repeated_action_specified_ &&
9723 count > action_count) {
9724 // If there is at least one WillOnce() and no WillRepeatedly(),
9725 // we warn the user when the WillOnce() clauses ran out.
9726 ::std::stringstream ss;
9727 DescribeLocationTo(&ss);
9728 ss << "Actions ran out in " << source_text() << "...\n"
9729 << "Called " << count << " times, but only "
9730 << action_count << " WillOnce()"
9731 << (action_count == 1 ? " is" : "s are") << " specified - ";
9732 mocker->DescribeDefaultActionTo(args, &ss);
9733 Log(kWarning, ss.str(), 1);
9734 }
9735
9736 return count <= action_count ?
9737 *static_cast<const Action<F>*>(untyped_actions_[count - 1]) :
9738 repeated_action();
9739 }
9740
9741 // Given the arguments of a mock function call, if the call will
9742 // over-saturate this expectation, returns the default action;
9743 // otherwise, returns the next action in this expectation. Also
9744 // describes *what* happened to 'what', and explains *why* Google
9745 // Mock does it to 'why'. This method is not const as it calls
9746 // IncrementCallCount(). A return value of NULL means the default
9747 // action.
9748 const Action<F>* GetActionForArguments(
9749 const FunctionMockerBase<F>* mocker,
9750 const ArgumentTuple& args,
9751 ::std::ostream* what,
9752 ::std::ostream* why)
9753 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9754 g_gmock_mutex.AssertHeld();
9755 if (IsSaturated()) {
9756 // We have an excessive call.
9757 IncrementCallCount();
9758 *what << "Mock function called more times than expected - ";
9759 mocker->DescribeDefaultActionTo(args, what);
9760 DescribeCallCountTo(why);
9761
9762 // TODO([email protected]): allow the user to control whether
9763 // unexpected calls should fail immediately or continue using a
9764 // flag --gmock_unexpected_calls_are_fatal.
9765 return NULL;
9766 }
9767
9768 IncrementCallCount();
9769 RetireAllPreRequisites();
9770
9771 if (retires_on_saturation_ && IsSaturated()) {
9772 Retire();
9773 }
9774
9775 // Must be done after IncrementCount()!
9776 *what << "Mock function call matches " << source_text() <<"...\n";
9777 return &(GetCurrentAction(mocker, args));
9778 }
9779
9780 // All the fields below won't change once the EXPECT_CALL()
9781 // statement finishes.
9782 FunctionMockerBase<F>* const owner_;
9783 ArgumentMatcherTuple matchers_;
9784 Matcher<const ArgumentTuple&> extra_matcher_;
9785 Action<F> repeated_action_;
9786
9787 GTEST_DISALLOW_COPY_AND_ASSIGN_(TypedExpectation);
9788 }; // class TypedExpectation
9789
9790 // A MockSpec object is used by ON_CALL() or EXPECT_CALL() for
9791 // specifying the default behavior of, or expectation on, a mock
9792 // function.
9793
9794 // Note: class MockSpec really belongs to the ::testing namespace.
9795 // However if we define it in ::testing, MSVC will complain when
9796 // classes in ::testing::internal declare it as a friend class
9797 // template. To workaround this compiler bug, we define MockSpec in
9798 // ::testing::internal and import it into ::testing.
9799
9800 // Logs a message including file and line number information.
9801 GTEST_API_ void LogWithLocation(testing::internal::LogSeverity severity,
9802 const char* file, int line,
9803 const string& message);
9804
9805 template <typename F>
9806 class MockSpec {
9807 public:
9808 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
9809 typedef typename internal::Function<F>::ArgumentMatcherTuple
9810 ArgumentMatcherTuple;
9811
9812 // Constructs a MockSpec object, given the function mocker object
9813 // that the spec is associated with.
9814 explicit MockSpec(internal::FunctionMockerBase<F>* function_mocker)
9815 : function_mocker_(function_mocker) {}
9816
9817 // Adds a new default action spec to the function mocker and returns
9818 // the newly created spec.
9819 internal::OnCallSpec<F>& InternalDefaultActionSetAt(
9820 const char* file, int line, const char* obj, const char* call) {
9821 LogWithLocation(internal::kInfo, file, line,
9822 string("ON_CALL(") + obj + ", " + call + ") invoked");
9823 return function_mocker_->AddNewOnCallSpec(file, line, matchers_);
9824 }
9825
9826 // Adds a new expectation spec to the function mocker and returns
9827 // the newly created spec.
9828 internal::TypedExpectation<F>& InternalExpectedAt(
9829 const char* file, int line, const char* obj, const char* call) {
9830 const string source_text(string("EXPECT_CALL(") + obj + ", " + call + ")");
9831 LogWithLocation(internal::kInfo, file, line, source_text + " invoked");
9832 return function_mocker_->AddNewExpectation(
9833 file, line, source_text, matchers_);
9834 }
9835
9836 private:
9837 template <typename Function>
9838 friend class internal::FunctionMocker;
9839
9840 void SetMatchers(const ArgumentMatcherTuple& matchers) {
9841 matchers_ = matchers;
9842 }
9843
9844 // The function mocker that owns this spec.
9845 internal::FunctionMockerBase<F>* const function_mocker_;
9846 // The argument matchers specified in the spec.
9847 ArgumentMatcherTuple matchers_;
9848
9849 GTEST_DISALLOW_ASSIGN_(MockSpec);
9850 }; // class MockSpec
9851
9852 // MSVC warns about using 'this' in base member initializer list, so
9853 // we need to temporarily disable the warning. We have to do it for
9854 // the entire class to suppress the warning, even though it's about
9855 // the constructor only.
9856
9857 #ifdef _MSC_VER
9858 # pragma warning(push) // Saves the current warning state.
9859 # pragma warning(disable:4355) // Temporarily disables warning 4355.
9860 #endif // _MSV_VER
9861
9862 // C++ treats the void type specially. For example, you cannot define
9863 // a void-typed variable or pass a void value to a function.
9864 // ActionResultHolder<T> holds a value of type T, where T must be a
9865 // copyable type or void (T doesn't need to be default-constructable).
9866 // It hides the syntactic difference between void and other types, and
9867 // is used to unify the code for invoking both void-returning and
9868 // non-void-returning mock functions.
9869
9870 // Untyped base class for ActionResultHolder<T>.
9871 class UntypedActionResultHolderBase {
9872 public:
9873 virtual ~UntypedActionResultHolderBase() {}
9874
9875 // Prints the held value as an action's result to os.
9876 virtual void PrintAsActionResult(::std::ostream* os) const = 0;
9877 };
9878
9879 // This generic definition is used when T is not void.
9880 template <typename T>
9881 class ActionResultHolder : public UntypedActionResultHolderBase {
9882 public:
9883 explicit ActionResultHolder(T a_value) : value_(a_value) {}
9884
9885 // The compiler-generated copy constructor and assignment operator
9886 // are exactly what we need, so we don't need to define them.
9887
9888 // Returns the held value and deletes this object.
9889 T GetValueAndDelete() const {
9890 T retval(value_);
9891 delete this;
9892 return retval;
9893 }
9894
9895 // Prints the held value as an action's result to os.
9896 virtual void PrintAsActionResult(::std::ostream* os) const {
9897 *os << "\n Returns: ";
9898 // T may be a reference type, so we don't use UniversalPrint().
9899 UniversalPrinter<T>::Print(value_, os);
9900 }
9901
9902 // Performs the given mock function's default action and returns the
9903 // result in a new-ed ActionResultHolder.
9904 template <typename F>
9905 static ActionResultHolder* PerformDefaultAction(
9906 const FunctionMockerBase<F>* func_mocker,
9907 const typename Function<F>::ArgumentTuple& args,
9908 const string& call_description) {
9909 return new ActionResultHolder(
9910 func_mocker->PerformDefaultAction(args, call_description));
9911 }
9912
9913 // Performs the given action and returns the result in a new-ed
9914 // ActionResultHolder.
9915 template <typename F>
9916 static ActionResultHolder*
9917 PerformAction(const Action<F>& action,
9918 const typename Function<F>::ArgumentTuple& args) {
9919 return new ActionResultHolder(action.Perform(args));
9920 }
9921
9922 private:
9923 T value_;
9924
9925 // T could be a reference type, so = isn't supported.
9926 GTEST_DISALLOW_ASSIGN_(ActionResultHolder);
9927 };
9928
9929 // Specialization for T = void.
9930 template <>
9931 class ActionResultHolder<void> : public UntypedActionResultHolderBase {
9932 public:
9933 void GetValueAndDelete() const { delete this; }
9934
9935 virtual void PrintAsActionResult(::std::ostream* /* os */) const {}
9936
9937 // Performs the given mock function's default action and returns NULL;
9938 template <typename F>
9939 static ActionResultHolder* PerformDefaultAction(
9940 const FunctionMockerBase<F>* func_mocker,
9941 const typename Function<F>::ArgumentTuple& args,
9942 const string& call_description) {
9943 func_mocker->PerformDefaultAction(args, call_description);
9944 return NULL;
9945 }
9946
9947 // Performs the given action and returns NULL.
9948 template <typename F>
9949 static ActionResultHolder* PerformAction(
9950 const Action<F>& action,
9951 const typename Function<F>::ArgumentTuple& args) {
9952 action.Perform(args);
9953 return NULL;
9954 }
9955 };
9956
9957 // The base of the function mocker class for the given function type.
9958 // We put the methods in this class instead of its child to avoid code
9959 // bloat.
9960 template <typename F>
9961 class FunctionMockerBase : public UntypedFunctionMockerBase {
9962 public:
9963 typedef typename Function<F>::Result Result;
9964 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
9965 typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple;
9966
9967 FunctionMockerBase() : current_spec_(this) {}
9968
9969 // The destructor verifies that all expectations on this mock
9970 // function have been satisfied. If not, it will report Google Test
9971 // non-fatal failures for the violations.
9972 virtual ~FunctionMockerBase()
9973 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
9974 MutexLock l(&g_gmock_mutex);
9975 VerifyAndClearExpectationsLocked();
9976 Mock::UnregisterLocked(this);
9977 ClearDefaultActionsLocked();
9978 }
9979
9980 // Returns the ON_CALL spec that matches this mock function with the
9981 // given arguments; returns NULL if no matching ON_CALL is found.
9982 // L = *
9983 const OnCallSpec<F>* FindOnCallSpec(
9984 const ArgumentTuple& args) const {
9985 for (UntypedOnCallSpecs::const_reverse_iterator it
9986 = untyped_on_call_specs_.rbegin();
9987 it != untyped_on_call_specs_.rend(); ++it) {
9988 const OnCallSpec<F>* spec = static_cast<const OnCallSpec<F>*>(*it);
9989 if (spec->Matches(args))
9990 return spec;
9991 }
9992
9993 return NULL;
9994 }
9995
9996 // Performs the default action of this mock function on the given
9997 // arguments and returns the result. Asserts (or throws if
9998 // exceptions are enabled) with a helpful call descrption if there
9999 // is no valid return value. This method doesn't depend on the
10000 // mutable state of this object, and thus can be called concurrently
10001 // without locking.
10002 // L = *
10003 Result PerformDefaultAction(const ArgumentTuple& args,
10004 const string& call_description) const {
10005 const OnCallSpec<F>* const spec =
10006 this->FindOnCallSpec(args);
10007 if (spec != NULL) {
10008 return spec->GetAction().Perform(args);
10009 }
10010 const string message = call_description +
10011 "\n The mock function has no default action "
10012 "set, and its return type has no default value set.";
10013 #if GTEST_HAS_EXCEPTIONS
10014 if (!DefaultValue<Result>::Exists()) {
10015 throw std::runtime_error(message);
10016 }
10017 #else
10018 Assert(DefaultValue<Result>::Exists(), "", -1, message);
10019 #endif
10020 return DefaultValue<Result>::Get();
10021 }
10022
10023 // Performs the default action with the given arguments and returns
10024 // the action's result. The call description string will be used in
10025 // the error message to describe the call in the case the default
10026 // action fails. The caller is responsible for deleting the result.
10027 // L = *
10028 virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction(
10029 const void* untyped_args, // must point to an ArgumentTuple
10030 const string& call_description) const {
10031 const ArgumentTuple& args =
10032 *static_cast<const ArgumentTuple*>(untyped_args);
10033 return ResultHolder::PerformDefaultAction(this, args, call_description);
10034 }
10035
10036 // Performs the given action with the given arguments and returns
10037 // the action's result. The caller is responsible for deleting the
10038 // result.
10039 // L = *
10040 virtual UntypedActionResultHolderBase* UntypedPerformAction(
10041 const void* untyped_action, const void* untyped_args) const {
10042 // Make a copy of the action before performing it, in case the
10043 // action deletes the mock object (and thus deletes itself).
10044 const Action<F> action = *static_cast<const Action<F>*>(untyped_action);
10045 const ArgumentTuple& args =
10046 *static_cast<const ArgumentTuple*>(untyped_args);
10047 return ResultHolder::PerformAction(action, args);
10048 }
10049
10050 // Implements UntypedFunctionMockerBase::ClearDefaultActionsLocked():
10051 // clears the ON_CALL()s set on this mock function.
10052 virtual void ClearDefaultActionsLocked()
10053 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
10054 g_gmock_mutex.AssertHeld();
10055
10056 // Deleting our default actions may trigger other mock objects to be
10057 // deleted, for example if an action contains a reference counted smart
10058 // pointer to that mock object, and that is the last reference. So if we
10059 // delete our actions within the context of the global mutex we may deadlock
10060 // when this method is called again. Instead, make a copy of the set of
10061 // actions to delete, clear our set within the mutex, and then delete the
10062 // actions outside of the mutex.
10063 UntypedOnCallSpecs specs_to_delete;
10064 untyped_on_call_specs_.swap(specs_to_delete);
10065
10066 g_gmock_mutex.Unlock();
10067 for (UntypedOnCallSpecs::const_iterator it =
10068 specs_to_delete.begin();
10069 it != specs_to_delete.end(); ++it) {
10070 delete static_cast<const OnCallSpec<F>*>(*it);
10071 }
10072
10073 // Lock the mutex again, since the caller expects it to be locked when we
10074 // return.
10075 g_gmock_mutex.Lock();
10076 }
10077
10078 protected:
10079 template <typename Function>
10080 friend class MockSpec;
10081
10082 typedef ActionResultHolder<Result> ResultHolder;
10083
10084 // Returns the result of invoking this mock function with the given
10085 // arguments. This function can be safely called from multiple
10086 // threads concurrently.
10087 Result InvokeWith(const ArgumentTuple& args)
10088 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
10089 return static_cast<const ResultHolder*>(
10090 this->UntypedInvokeWith(&args))->GetValueAndDelete();
10091 }
10092
10093 // Adds and returns a default action spec for this mock function.
10094 OnCallSpec<F>& AddNewOnCallSpec(
10095 const char* file, int line,
10096 const ArgumentMatcherTuple& m)
10097 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
10098 Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line);
10099 OnCallSpec<F>* const on_call_spec = new OnCallSpec<F>(file, line, m);
10100 untyped_on_call_specs_.push_back(on_call_spec);
10101 return *on_call_spec;
10102 }
10103
10104 // Adds and returns an expectation spec for this mock function.
10105 TypedExpectation<F>& AddNewExpectation(
10106 const char* file,
10107 int line,
10108 const string& source_text,
10109 const ArgumentMatcherTuple& m)
10110 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
10111 Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line);
10112 TypedExpectation<F>* const expectation =
10113 new TypedExpectation<F>(this, file, line, source_text, m);
10114 const linked_ptr<ExpectationBase> untyped_expectation(expectation);
10115 untyped_expectations_.push_back(untyped_expectation);
10116
10117 // Adds this expectation into the implicit sequence if there is one.
10118 Sequence* const implicit_sequence = g_gmock_implicit_sequence.get();
10119 if (implicit_sequence != NULL) {
10120 implicit_sequence->AddExpectation(Expectation(untyped_expectation));
10121 }
10122
10123 return *expectation;
10124 }
10125
10126 // The current spec (either default action spec or expectation spec)
10127 // being described on this function mocker.
10128 MockSpec<F>& current_spec() { return current_spec_; }
10129
10130 private:
10131 template <typename Func> friend class TypedExpectation;
10132
10133 // Some utilities needed for implementing UntypedInvokeWith().
10134
10135 // Describes what default action will be performed for the given
10136 // arguments.
10137 // L = *
10138 void DescribeDefaultActionTo(const ArgumentTuple& args,
10139 ::std::ostream* os) const {
10140 const OnCallSpec<F>* const spec = FindOnCallSpec(args);
10141
10142 if (spec == NULL) {
10143 *os << (internal::type_equals<Result, void>::value ?
10144 "returning directly.\n" :
10145 "returning default value.\n");
10146 } else {
10147 *os << "taking default action specified at:\n"
10148 << FormatFileLocation(spec->file(), spec->line()) << "\n";
10149 }
10150 }
10151
10152 // Writes a message that the call is uninteresting (i.e. neither
10153 // explicitly expected nor explicitly unexpected) to the given
10154 // ostream.
10155 virtual void UntypedDescribeUninterestingCall(
10156 const void* untyped_args,
10157 ::std::ostream* os) const
10158 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
10159 const ArgumentTuple& args =
10160 *static_cast<const ArgumentTuple*>(untyped_args);
10161 *os << "Uninteresting mock function call - ";
10162 DescribeDefaultActionTo(args, os);
10163 *os << " Function call: " << Name();
10164 UniversalPrint(args, os);
10165 }
10166
10167 // Returns the expectation that matches the given function arguments
10168 // (or NULL is there's no match); when a match is found,
10169 // untyped_action is set to point to the action that should be
10170 // performed (or NULL if the action is "do default"), and
10171 // is_excessive is modified to indicate whether the call exceeds the
10172 // expected number.
10173 //
10174 // Critical section: We must find the matching expectation and the
10175 // corresponding action that needs to be taken in an ATOMIC
10176 // transaction. Otherwise another thread may call this mock
10177 // method in the middle and mess up the state.
10178 //
10179 // However, performing the action has to be left out of the critical
10180 // section. The reason is that we have no control on what the
10181 // action does (it can invoke an arbitrary user function or even a
10182 // mock function) and excessive locking could cause a dead lock.
10183 virtual const ExpectationBase* UntypedFindMatchingExpectation(
10184 const void* untyped_args,
10185 const void** untyped_action, bool* is_excessive,
10186 ::std::ostream* what, ::std::ostream* why)
10187 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
10188 const ArgumentTuple& args =
10189 *static_cast<const ArgumentTuple*>(untyped_args);
10190 MutexLock l(&g_gmock_mutex);
10191 TypedExpectation<F>* exp = this->FindMatchingExpectationLocked(args);
10192 if (exp == NULL) { // A match wasn't found.
10193 this->FormatUnexpectedCallMessageLocked(args, what, why);
10194 return NULL;
10195 }
10196
10197 // This line must be done before calling GetActionForArguments(),
10198 // which will increment the call count for *exp and thus affect
10199 // its saturation status.
10200 *is_excessive = exp->IsSaturated();
10201 const Action<F>* action = exp->GetActionForArguments(this, args, what, why);
10202 if (action != NULL && action->IsDoDefault())
10203 action = NULL; // Normalize "do default" to NULL.
10204 *untyped_action = action;
10205 return exp;
10206 }
10207
10208 // Prints the given function arguments to the ostream.
10209 virtual void UntypedPrintArgs(const void* untyped_args,
10210 ::std::ostream* os) const {
10211 const ArgumentTuple& args =
10212 *static_cast<const ArgumentTuple*>(untyped_args);
10213 UniversalPrint(args, os);
10214 }
10215
10216 // Returns the expectation that matches the arguments, or NULL if no
10217 // expectation matches them.
10218 TypedExpectation<F>* FindMatchingExpectationLocked(
10219 const ArgumentTuple& args) const
10220 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
10221 g_gmock_mutex.AssertHeld();
10222 for (typename UntypedExpectations::const_reverse_iterator it =
10223 untyped_expectations_.rbegin();
10224 it != untyped_expectations_.rend(); ++it) {
10225 TypedExpectation<F>* const exp =
10226 static_cast<TypedExpectation<F>*>(it->get());
10227 if (exp->ShouldHandleArguments(args)) {
10228 return exp;
10229 }
10230 }
10231 return NULL;
10232 }
10233
10234 // Returns a message that the arguments don't match any expectation.
10235 void FormatUnexpectedCallMessageLocked(
10236 const ArgumentTuple& args,
10237 ::std::ostream* os,
10238 ::std::ostream* why) const
10239 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
10240 g_gmock_mutex.AssertHeld();
10241 *os << "\nUnexpected mock function call - ";
10242 DescribeDefaultActionTo(args, os);
10243 PrintTriedExpectationsLocked(args, why);
10244 }
10245
10246 // Prints a list of expectations that have been tried against the
10247 // current mock function call.
10248 void PrintTriedExpectationsLocked(
10249 const ArgumentTuple& args,
10250 ::std::ostream* why) const
10251 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
10252 g_gmock_mutex.AssertHeld();
10253 const int count = static_cast<int>(untyped_expectations_.size());
10254 *why << "Google Mock tried the following " << count << " "
10255 << (count == 1 ? "expectation, but it didn't match" :
10256 "expectations, but none matched")
10257 << ":\n";
10258 for (int i = 0; i < count; i++) {
10259 TypedExpectation<F>* const expectation =
10260 static_cast<TypedExpectation<F>*>(untyped_expectations_[i].get());
10261 *why << "\n";
10262 expectation->DescribeLocationTo(why);
10263 if (count > 1) {
10264 *why << "tried expectation #" << i << ": ";
10265 }
10266 *why << expectation->source_text() << "...\n";
10267 expectation->ExplainMatchResultTo(args, why);
10268 expectation->DescribeCallCountTo(why);
10269 }
10270 }
10271
10272 // The current spec (either default action spec or expectation spec)
10273 // being described on this function mocker.
10274 MockSpec<F> current_spec_;
10275
10276 // There is no generally useful and implementable semantics of
10277 // copying a mock object, so copying a mock is usually a user error.
10278 // Thus we disallow copying function mockers. If the user really
10279 // wants to copy a mock object, he should implement his own copy
10280 // operation, for example:
10281 //
10282 // class MockFoo : public Foo {
10283 // public:
10284 // // Defines a copy constructor explicitly.
10285 // MockFoo(const MockFoo& src) {}
10286 // ...
10287 // };
10288 GTEST_DISALLOW_COPY_AND_ASSIGN_(FunctionMockerBase);
10289 }; // class FunctionMockerBase
10290
10291 #ifdef _MSC_VER
10292 # pragma warning(pop) // Restores the warning state.
10293 #endif // _MSV_VER
10294
10295 // Implements methods of FunctionMockerBase.
10296
10297 // Verifies that all expectations on this mock function have been
10298 // satisfied. Reports one or more Google Test non-fatal failures and
10299 // returns false if not.
10300
10301 // Reports an uninteresting call (whose description is in msg) in the
10302 // manner specified by 'reaction'.
10303 void ReportUninterestingCall(CallReaction reaction, const string& msg);
10304
10305 } // namespace internal
10306
10307 // The style guide prohibits "using" statements in a namespace scope
10308 // inside a header file. However, the MockSpec class template is
10309 // meant to be defined in the ::testing namespace. The following line
10310 // is just a trick for working around a bug in MSVC 8.0, which cannot
10311 // handle it if we define MockSpec in ::testing.
10312 using internal::MockSpec;
10313
10314 // Const(x) is a convenient function for obtaining a const reference
10315 // to x. This is useful for setting expectations on an overloaded
10316 // const mock method, e.g.
10317 //
10318 // class MockFoo : public FooInterface {
10319 // public:
10320 // MOCK_METHOD0(Bar, int());
10321 // MOCK_CONST_METHOD0(Bar, int&());
10322 // };
10323 //
10324 // MockFoo foo;
10325 // // Expects a call to non-const MockFoo::Bar().
10326 // EXPECT_CALL(foo, Bar());
10327 // // Expects a call to const MockFoo::Bar().
10328 // EXPECT_CALL(Const(foo), Bar());
10329 template <typename T>
10330 inline const T& Const(const T& x) { return x; }
10331
10332 // Constructs an Expectation object that references and co-owns exp.
10333 inline Expectation::Expectation(internal::ExpectationBase& exp) // NOLINT
10334 : expectation_base_(exp.GetHandle().expectation_base()) {}
10335
10336 } // namespace testing
10337
10338 // A separate macro is required to avoid compile errors when the name
10339 // of the method used in call is a result of macro expansion.
10340 // See CompilesWithMethodNameExpandedFromMacro tests in
10341 // internal/gmock-spec-builders_test.cc for more details.
10342 #define GMOCK_ON_CALL_IMPL_(obj, call) \
10343 ((obj).gmock_##call).InternalDefaultActionSetAt(__FILE__, __LINE__, \
10344 #obj, #call)
10345 #define ON_CALL(obj, call) GMOCK_ON_CALL_IMPL_(obj, call)
10346
10347 #define GMOCK_EXPECT_CALL_IMPL_(obj, call) \
10348 ((obj).gmock_##call).InternalExpectedAt(__FILE__, __LINE__, #obj, #call)
10349 #define EXPECT_CALL(obj, call) GMOCK_EXPECT_CALL_IMPL_(obj, call)
10350
10351 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_
10352
10353 namespace testing {
10354 namespace internal {
10355
10356 template <typename F>
10357 class FunctionMockerBase;
10358
10359 // Note: class FunctionMocker really belongs to the ::testing
10360 // namespace. However if we define it in ::testing, MSVC will
10361 // complain when classes in ::testing::internal declare it as a
10362 // friend class template. To workaround this compiler bug, we define
10363 // FunctionMocker in ::testing::internal and import it into ::testing.
10364 template <typename F>
10365 class FunctionMocker;
10366
10367 template <typename R>
10368 class FunctionMocker<R()> : public
10369 internal::FunctionMockerBase<R()> {
10370 public:
10371 typedef R F();
10372 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
10373
10374 MockSpec<F>& With() {
10375 return this->current_spec();
10376 }
10377
10378 R Invoke() {
10379 // Even though gcc and MSVC don't enforce it, 'this->' is required
10380 // by the C++ standard [14.6.4] here, as the base class type is
10381 // dependent on the template argument (and thus shouldn't be
10382 // looked into when resolving InvokeWith).
10383 return this->InvokeWith(ArgumentTuple());
10384 }
10385 };
10386
10387 template <typename R, typename A1>
10388 class FunctionMocker<R(A1)> : public
10389 internal::FunctionMockerBase<R(A1)> {
10390 public:
10391 typedef R F(A1);
10392 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
10393
10394 MockSpec<F>& With(const Matcher<A1>& m1) {
10395 this->current_spec().SetMatchers(::std::tr1::make_tuple(m1));
10396 return this->current_spec();
10397 }
10398
10399 R Invoke(A1 a1) {
10400 // Even though gcc and MSVC don't enforce it, 'this->' is required
10401 // by the C++ standard [14.6.4] here, as the base class type is
10402 // dependent on the template argument (and thus shouldn't be
10403 // looked into when resolving InvokeWith).
10404 return this->InvokeWith(ArgumentTuple(a1));
10405 }
10406 };
10407
10408 template <typename R, typename A1, typename A2>
10409 class FunctionMocker<R(A1, A2)> : public
10410 internal::FunctionMockerBase<R(A1, A2)> {
10411 public:
10412 typedef R F(A1, A2);
10413 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
10414
10415 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2) {
10416 this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2));
10417 return this->current_spec();
10418 }
10419
10420 R Invoke(A1 a1, A2 a2) {
10421 // Even though gcc and MSVC don't enforce it, 'this->' is required
10422 // by the C++ standard [14.6.4] here, as the base class type is
10423 // dependent on the template argument (and thus shouldn't be
10424 // looked into when resolving InvokeWith).
10425 return this->InvokeWith(ArgumentTuple(a1, a2));
10426 }
10427 };
10428
10429 template <typename R, typename A1, typename A2, typename A3>
10430 class FunctionMocker<R(A1, A2, A3)> : public
10431 internal::FunctionMockerBase<R(A1, A2, A3)> {
10432 public:
10433 typedef R F(A1, A2, A3);
10434 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
10435
10436 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
10437 const Matcher<A3>& m3) {
10438 this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3));
10439 return this->current_spec();
10440 }
10441
10442 R Invoke(A1 a1, A2 a2, A3 a3) {
10443 // Even though gcc and MSVC don't enforce it, 'this->' is required
10444 // by the C++ standard [14.6.4] here, as the base class type is
10445 // dependent on the template argument (and thus shouldn't be
10446 // looked into when resolving InvokeWith).
10447 return this->InvokeWith(ArgumentTuple(a1, a2, a3));
10448 }
10449 };
10450
10451 template <typename R, typename A1, typename A2, typename A3, typename A4>
10452 class FunctionMocker<R(A1, A2, A3, A4)> : public
10453 internal::FunctionMockerBase<R(A1, A2, A3, A4)> {
10454 public:
10455 typedef R F(A1, A2, A3, A4);
10456 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
10457
10458 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
10459 const Matcher<A3>& m3, const Matcher<A4>& m4) {
10460 this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4));
10461 return this->current_spec();
10462 }
10463
10464 R Invoke(A1 a1, A2 a2, A3 a3, A4 a4) {
10465 // Even though gcc and MSVC don't enforce it, 'this->' is required
10466 // by the C++ standard [14.6.4] here, as the base class type is
10467 // dependent on the template argument (and thus shouldn't be
10468 // looked into when resolving InvokeWith).
10469 return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4));
10470 }
10471 };
10472
10473 template <typename R, typename A1, typename A2, typename A3, typename A4,
10474 typename A5>
10475 class FunctionMocker<R(A1, A2, A3, A4, A5)> : public
10476 internal::FunctionMockerBase<R(A1, A2, A3, A4, A5)> {
10477 public:
10478 typedef R F(A1, A2, A3, A4, A5);
10479 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
10480
10481 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
10482 const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5) {
10483 this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4,
10484 m5));
10485 return this->current_spec();
10486 }
10487
10488 R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) {
10489 // Even though gcc and MSVC don't enforce it, 'this->' is required
10490 // by the C++ standard [14.6.4] here, as the base class type is
10491 // dependent on the template argument (and thus shouldn't be
10492 // looked into when resolving InvokeWith).
10493 return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5));
10494 }
10495 };
10496
10497 template <typename R, typename A1, typename A2, typename A3, typename A4,
10498 typename A5, typename A6>
10499 class FunctionMocker<R(A1, A2, A3, A4, A5, A6)> : public
10500 internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6)> {
10501 public:
10502 typedef R F(A1, A2, A3, A4, A5, A6);
10503 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
10504
10505 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
10506 const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5,
10507 const Matcher<A6>& m6) {
10508 this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5,
10509 m6));
10510 return this->current_spec();
10511 }
10512
10513 R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) {
10514 // Even though gcc and MSVC don't enforce it, 'this->' is required
10515 // by the C++ standard [14.6.4] here, as the base class type is
10516 // dependent on the template argument (and thus shouldn't be
10517 // looked into when resolving InvokeWith).
10518 return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6));
10519 }
10520 };
10521
10522 template <typename R, typename A1, typename A2, typename A3, typename A4,
10523 typename A5, typename A6, typename A7>
10524 class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7)> : public
10525 internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6, A7)> {
10526 public:
10527 typedef R F(A1, A2, A3, A4, A5, A6, A7);
10528 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
10529
10530 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
10531 const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5,
10532 const Matcher<A6>& m6, const Matcher<A7>& m7) {
10533 this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5,
10534 m6, m7));
10535 return this->current_spec();
10536 }
10537
10538 R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) {
10539 // Even though gcc and MSVC don't enforce it, 'this->' is required
10540 // by the C++ standard [14.6.4] here, as the base class type is
10541 // dependent on the template argument (and thus shouldn't be
10542 // looked into when resolving InvokeWith).
10543 return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7));
10544 }
10545 };
10546
10547 template <typename R, typename A1, typename A2, typename A3, typename A4,
10548 typename A5, typename A6, typename A7, typename A8>
10549 class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8)> : public
10550 internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6, A7, A8)> {
10551 public:
10552 typedef R F(A1, A2, A3, A4, A5, A6, A7, A8);
10553 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
10554
10555 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
10556 const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5,
10557 const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8) {
10558 this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5,
10559 m6, m7, m8));
10560 return this->current_spec();
10561 }
10562
10563 R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) {
10564 // Even though gcc and MSVC don't enforce it, 'this->' is required
10565 // by the C++ standard [14.6.4] here, as the base class type is
10566 // dependent on the template argument (and thus shouldn't be
10567 // looked into when resolving InvokeWith).
10568 return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8));
10569 }
10570 };
10571
10572 template <typename R, typename A1, typename A2, typename A3, typename A4,
10573 typename A5, typename A6, typename A7, typename A8, typename A9>
10574 class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> : public
10575 internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> {
10576 public:
10577 typedef R F(A1, A2, A3, A4, A5, A6, A7, A8, A9);
10578 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
10579
10580 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
10581 const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5,
10582 const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8,
10583 const Matcher<A9>& m9) {
10584 this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5,
10585 m6, m7, m8, m9));
10586 return this->current_spec();
10587 }
10588
10589 R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) {
10590 // Even though gcc and MSVC don't enforce it, 'this->' is required
10591 // by the C++ standard [14.6.4] here, as the base class type is
10592 // dependent on the template argument (and thus shouldn't be
10593 // looked into when resolving InvokeWith).
10594 return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8, a9));
10595 }
10596 };
10597
10598 template <typename R, typename A1, typename A2, typename A3, typename A4,
10599 typename A5, typename A6, typename A7, typename A8, typename A9,
10600 typename A10>
10601 class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> : public
10602 internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> {
10603 public:
10604 typedef R F(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10);
10605 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
10606
10607 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
10608 const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5,
10609 const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8,
10610 const Matcher<A9>& m9, const Matcher<A10>& m10) {
10611 this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5,
10612 m6, m7, m8, m9, m10));
10613 return this->current_spec();
10614 }
10615
10616 R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9,
10617 A10 a10) {
10618 // Even though gcc and MSVC don't enforce it, 'this->' is required
10619 // by the C++ standard [14.6.4] here, as the base class type is
10620 // dependent on the template argument (and thus shouldn't be
10621 // looked into when resolving InvokeWith).
10622 return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8, a9,
10623 a10));
10624 }
10625 };
10626
10627 } // namespace internal
10628
10629 // The style guide prohibits "using" statements in a namespace scope
10630 // inside a header file. However, the FunctionMocker class template
10631 // is meant to be defined in the ::testing namespace. The following
10632 // line is just a trick for working around a bug in MSVC 8.0, which
10633 // cannot handle it if we define FunctionMocker in ::testing.
10634 using internal::FunctionMocker;
10635
10636 // GMOCK_RESULT_(tn, F) expands to the result type of function type F.
10637 // We define this as a variadic macro in case F contains unprotected
10638 // commas (the same reason that we use variadic macros in other places
10639 // in this file).
10640 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10641 #define GMOCK_RESULT_(tn, ...) \
10642 tn ::testing::internal::Function<__VA_ARGS__>::Result
10643
10644 // The type of argument N of the given function type.
10645 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10646 #define GMOCK_ARG_(tn, N, ...) \
10647 tn ::testing::internal::Function<__VA_ARGS__>::Argument##N
10648
10649 // The matcher type for argument N of the given function type.
10650 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10651 #define GMOCK_MATCHER_(tn, N, ...) \
10652 const ::testing::Matcher<GMOCK_ARG_(tn, N, __VA_ARGS__)>&
10653
10654 // The variable for mocking the given method.
10655 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10656 #define GMOCK_MOCKER_(arity, constness, Method) \
10657 GTEST_CONCAT_TOKEN_(gmock##constness##arity##_##Method##_, __LINE__)
10658
10659 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10660 #define GMOCK_METHOD0_(tn, constness, ct, Method, ...) \
10661 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
10662 ) constness { \
10663 GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \
10664 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
10665 == 0), \
10666 this_method_does_not_take_0_arguments); \
10667 GMOCK_MOCKER_(0, constness, Method).SetOwnerAndName(this, #Method); \
10668 return GMOCK_MOCKER_(0, constness, Method).Invoke(); \
10669 } \
10670 ::testing::MockSpec<__VA_ARGS__>& \
10671 gmock_##Method() constness { \
10672 GMOCK_MOCKER_(0, constness, Method).RegisterOwner(this); \
10673 return GMOCK_MOCKER_(0, constness, Method).With(); \
10674 } \
10675 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(0, constness, \
10676 Method)
10677
10678 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10679 #define GMOCK_METHOD1_(tn, constness, ct, Method, ...) \
10680 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
10681 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1) constness { \
10682 GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \
10683 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
10684 == 1), \
10685 this_method_does_not_take_1_argument); \
10686 GMOCK_MOCKER_(1, constness, Method).SetOwnerAndName(this, #Method); \
10687 return GMOCK_MOCKER_(1, constness, Method).Invoke(gmock_a1); \
10688 } \
10689 ::testing::MockSpec<__VA_ARGS__>& \
10690 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1) constness { \
10691 GMOCK_MOCKER_(1, constness, Method).RegisterOwner(this); \
10692 return GMOCK_MOCKER_(1, constness, Method).With(gmock_a1); \
10693 } \
10694 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(1, constness, \
10695 Method)
10696
10697 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10698 #define GMOCK_METHOD2_(tn, constness, ct, Method, ...) \
10699 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
10700 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
10701 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2) constness { \
10702 GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \
10703 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
10704 == 2), \
10705 this_method_does_not_take_2_arguments); \
10706 GMOCK_MOCKER_(2, constness, Method).SetOwnerAndName(this, #Method); \
10707 return GMOCK_MOCKER_(2, constness, Method).Invoke(gmock_a1, gmock_a2); \
10708 } \
10709 ::testing::MockSpec<__VA_ARGS__>& \
10710 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
10711 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2) constness { \
10712 GMOCK_MOCKER_(2, constness, Method).RegisterOwner(this); \
10713 return GMOCK_MOCKER_(2, constness, Method).With(gmock_a1, gmock_a2); \
10714 } \
10715 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(2, constness, \
10716 Method)
10717
10718 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10719 #define GMOCK_METHOD3_(tn, constness, ct, Method, ...) \
10720 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
10721 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
10722 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
10723 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3) constness { \
10724 GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \
10725 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
10726 == 3), \
10727 this_method_does_not_take_3_arguments); \
10728 GMOCK_MOCKER_(3, constness, Method).SetOwnerAndName(this, #Method); \
10729 return GMOCK_MOCKER_(3, constness, Method).Invoke(gmock_a1, gmock_a2, \
10730 gmock_a3); \
10731 } \
10732 ::testing::MockSpec<__VA_ARGS__>& \
10733 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
10734 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
10735 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3) constness { \
10736 GMOCK_MOCKER_(3, constness, Method).RegisterOwner(this); \
10737 return GMOCK_MOCKER_(3, constness, Method).With(gmock_a1, gmock_a2, \
10738 gmock_a3); \
10739 } \
10740 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(3, constness, \
10741 Method)
10742
10743 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10744 #define GMOCK_METHOD4_(tn, constness, ct, Method, ...) \
10745 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
10746 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
10747 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
10748 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
10749 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4) constness { \
10750 GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \
10751 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
10752 == 4), \
10753 this_method_does_not_take_4_arguments); \
10754 GMOCK_MOCKER_(4, constness, Method).SetOwnerAndName(this, #Method); \
10755 return GMOCK_MOCKER_(4, constness, Method).Invoke(gmock_a1, gmock_a2, \
10756 gmock_a3, gmock_a4); \
10757 } \
10758 ::testing::MockSpec<__VA_ARGS__>& \
10759 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
10760 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
10761 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
10762 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4) constness { \
10763 GMOCK_MOCKER_(4, constness, Method).RegisterOwner(this); \
10764 return GMOCK_MOCKER_(4, constness, Method).With(gmock_a1, gmock_a2, \
10765 gmock_a3, gmock_a4); \
10766 } \
10767 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(4, constness, \
10768 Method)
10769
10770 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10771 #define GMOCK_METHOD5_(tn, constness, ct, Method, ...) \
10772 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
10773 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
10774 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
10775 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
10776 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \
10777 GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5) constness { \
10778 GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \
10779 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
10780 == 5), \
10781 this_method_does_not_take_5_arguments); \
10782 GMOCK_MOCKER_(5, constness, Method).SetOwnerAndName(this, #Method); \
10783 return GMOCK_MOCKER_(5, constness, Method).Invoke(gmock_a1, gmock_a2, \
10784 gmock_a3, gmock_a4, gmock_a5); \
10785 } \
10786 ::testing::MockSpec<__VA_ARGS__>& \
10787 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
10788 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
10789 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
10790 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
10791 GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5) constness { \
10792 GMOCK_MOCKER_(5, constness, Method).RegisterOwner(this); \
10793 return GMOCK_MOCKER_(5, constness, Method).With(gmock_a1, gmock_a2, \
10794 gmock_a3, gmock_a4, gmock_a5); \
10795 } \
10796 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(5, constness, \
10797 Method)
10798
10799 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10800 #define GMOCK_METHOD6_(tn, constness, ct, Method, ...) \
10801 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
10802 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
10803 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
10804 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
10805 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \
10806 GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \
10807 GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6) constness { \
10808 GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \
10809 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
10810 == 6), \
10811 this_method_does_not_take_6_arguments); \
10812 GMOCK_MOCKER_(6, constness, Method).SetOwnerAndName(this, #Method); \
10813 return GMOCK_MOCKER_(6, constness, Method).Invoke(gmock_a1, gmock_a2, \
10814 gmock_a3, gmock_a4, gmock_a5, gmock_a6); \
10815 } \
10816 ::testing::MockSpec<__VA_ARGS__>& \
10817 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
10818 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
10819 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
10820 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
10821 GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \
10822 GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6) constness { \
10823 GMOCK_MOCKER_(6, constness, Method).RegisterOwner(this); \
10824 return GMOCK_MOCKER_(6, constness, Method).With(gmock_a1, gmock_a2, \
10825 gmock_a3, gmock_a4, gmock_a5, gmock_a6); \
10826 } \
10827 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(6, constness, \
10828 Method)
10829
10830 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10831 #define GMOCK_METHOD7_(tn, constness, ct, Method, ...) \
10832 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
10833 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
10834 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
10835 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
10836 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \
10837 GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \
10838 GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
10839 GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7) constness { \
10840 GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \
10841 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
10842 == 7), \
10843 this_method_does_not_take_7_arguments); \
10844 GMOCK_MOCKER_(7, constness, Method).SetOwnerAndName(this, #Method); \
10845 return GMOCK_MOCKER_(7, constness, Method).Invoke(gmock_a1, gmock_a2, \
10846 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7); \
10847 } \
10848 ::testing::MockSpec<__VA_ARGS__>& \
10849 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
10850 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
10851 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
10852 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
10853 GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \
10854 GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \
10855 GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7) constness { \
10856 GMOCK_MOCKER_(7, constness, Method).RegisterOwner(this); \
10857 return GMOCK_MOCKER_(7, constness, Method).With(gmock_a1, gmock_a2, \
10858 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7); \
10859 } \
10860 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(7, constness, \
10861 Method)
10862
10863 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10864 #define GMOCK_METHOD8_(tn, constness, ct, Method, ...) \
10865 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
10866 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
10867 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
10868 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
10869 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \
10870 GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \
10871 GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
10872 GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \
10873 GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8) constness { \
10874 GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \
10875 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
10876 == 8), \
10877 this_method_does_not_take_8_arguments); \
10878 GMOCK_MOCKER_(8, constness, Method).SetOwnerAndName(this, #Method); \
10879 return GMOCK_MOCKER_(8, constness, Method).Invoke(gmock_a1, gmock_a2, \
10880 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8); \
10881 } \
10882 ::testing::MockSpec<__VA_ARGS__>& \
10883 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
10884 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
10885 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
10886 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
10887 GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \
10888 GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \
10889 GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \
10890 GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8) constness { \
10891 GMOCK_MOCKER_(8, constness, Method).RegisterOwner(this); \
10892 return GMOCK_MOCKER_(8, constness, Method).With(gmock_a1, gmock_a2, \
10893 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8); \
10894 } \
10895 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(8, constness, \
10896 Method)
10897
10898 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10899 #define GMOCK_METHOD9_(tn, constness, ct, Method, ...) \
10900 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
10901 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
10902 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
10903 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
10904 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \
10905 GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \
10906 GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
10907 GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \
10908 GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8, \
10909 GMOCK_ARG_(tn, 9, __VA_ARGS__) gmock_a9) constness { \
10910 GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \
10911 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
10912 == 9), \
10913 this_method_does_not_take_9_arguments); \
10914 GMOCK_MOCKER_(9, constness, Method).SetOwnerAndName(this, #Method); \
10915 return GMOCK_MOCKER_(9, constness, Method).Invoke(gmock_a1, gmock_a2, \
10916 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, \
10917 gmock_a9); \
10918 } \
10919 ::testing::MockSpec<__VA_ARGS__>& \
10920 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
10921 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
10922 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
10923 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
10924 GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \
10925 GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \
10926 GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \
10927 GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8, \
10928 GMOCK_MATCHER_(tn, 9, __VA_ARGS__) gmock_a9) constness { \
10929 GMOCK_MOCKER_(9, constness, Method).RegisterOwner(this); \
10930 return GMOCK_MOCKER_(9, constness, Method).With(gmock_a1, gmock_a2, \
10931 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, \
10932 gmock_a9); \
10933 } \
10934 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(9, constness, \
10935 Method)
10936
10937 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10938 #define GMOCK_METHOD10_(tn, constness, ct, Method, ...) \
10939 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
10940 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
10941 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
10942 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
10943 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \
10944 GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \
10945 GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
10946 GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \
10947 GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8, \
10948 GMOCK_ARG_(tn, 9, __VA_ARGS__) gmock_a9, \
10949 GMOCK_ARG_(tn, 10, __VA_ARGS__) gmock_a10) constness { \
10950 GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \
10951 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
10952 == 10), \
10953 this_method_does_not_take_10_arguments); \
10954 GMOCK_MOCKER_(10, constness, Method).SetOwnerAndName(this, #Method); \
10955 return GMOCK_MOCKER_(10, constness, Method).Invoke(gmock_a1, gmock_a2, \
10956 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, gmock_a9, \
10957 gmock_a10); \
10958 } \
10959 ::testing::MockSpec<__VA_ARGS__>& \
10960 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
10961 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
10962 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
10963 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
10964 GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \
10965 GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \
10966 GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \
10967 GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8, \
10968 GMOCK_MATCHER_(tn, 9, __VA_ARGS__) gmock_a9, \
10969 GMOCK_MATCHER_(tn, 10, \
10970 __VA_ARGS__) gmock_a10) constness { \
10971 GMOCK_MOCKER_(10, constness, Method).RegisterOwner(this); \
10972 return GMOCK_MOCKER_(10, constness, Method).With(gmock_a1, gmock_a2, \
10973 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, gmock_a9, \
10974 gmock_a10); \
10975 } \
10976 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(10, constness, \
10977 Method)
10978
10979 #define MOCK_METHOD0(m, ...) GMOCK_METHOD0_(, , , m, __VA_ARGS__)
10980 #define MOCK_METHOD1(m, ...) GMOCK_METHOD1_(, , , m, __VA_ARGS__)
10981 #define MOCK_METHOD2(m, ...) GMOCK_METHOD2_(, , , m, __VA_ARGS__)
10982 #define MOCK_METHOD3(m, ...) GMOCK_METHOD3_(, , , m, __VA_ARGS__)
10983 #define MOCK_METHOD4(m, ...) GMOCK_METHOD4_(, , , m, __VA_ARGS__)
10984 #define MOCK_METHOD5(m, ...) GMOCK_METHOD5_(, , , m, __VA_ARGS__)
10985 #define MOCK_METHOD6(m, ...) GMOCK_METHOD6_(, , , m, __VA_ARGS__)
10986 #define MOCK_METHOD7(m, ...) GMOCK_METHOD7_(, , , m, __VA_ARGS__)
10987 #define MOCK_METHOD8(m, ...) GMOCK_METHOD8_(, , , m, __VA_ARGS__)
10988 #define MOCK_METHOD9(m, ...) GMOCK_METHOD9_(, , , m, __VA_ARGS__)
10989 #define MOCK_METHOD10(m, ...) GMOCK_METHOD10_(, , , m, __VA_ARGS__)
10990
10991 #define MOCK_CONST_METHOD0(m, ...) GMOCK_METHOD0_(, const, , m, __VA_ARGS__)
10992 #define MOCK_CONST_METHOD1(m, ...) GMOCK_METHOD1_(, const, , m, __VA_ARGS__)
10993 #define MOCK_CONST_METHOD2(m, ...) GMOCK_METHOD2_(, const, , m, __VA_ARGS__)
10994 #define MOCK_CONST_METHOD3(m, ...) GMOCK_METHOD3_(, const, , m, __VA_ARGS__)
10995 #define MOCK_CONST_METHOD4(m, ...) GMOCK_METHOD4_(, const, , m, __VA_ARGS__)
10996 #define MOCK_CONST_METHOD5(m, ...) GMOCK_METHOD5_(, const, , m, __VA_ARGS__)
10997 #define MOCK_CONST_METHOD6(m, ...) GMOCK_METHOD6_(, const, , m, __VA_ARGS__)
10998 #define MOCK_CONST_METHOD7(m, ...) GMOCK_METHOD7_(, const, , m, __VA_ARGS__)
10999 #define MOCK_CONST_METHOD8(m, ...) GMOCK_METHOD8_(, const, , m, __VA_ARGS__)
11000 #define MOCK_CONST_METHOD9(m, ...) GMOCK_METHOD9_(, const, , m, __VA_ARGS__)
11001 #define MOCK_CONST_METHOD10(m, ...) GMOCK_METHOD10_(, const, , m, __VA_ARGS__)
11002
11003 #define MOCK_METHOD0_T(m, ...) GMOCK_METHOD0_(typename, , , m, __VA_ARGS__)
11004 #define MOCK_METHOD1_T(m, ...) GMOCK_METHOD1_(typename, , , m, __VA_ARGS__)
11005 #define MOCK_METHOD2_T(m, ...) GMOCK_METHOD2_(typename, , , m, __VA_ARGS__)
11006 #define MOCK_METHOD3_T(m, ...) GMOCK_METHOD3_(typename, , , m, __VA_ARGS__)
11007 #define MOCK_METHOD4_T(m, ...) GMOCK_METHOD4_(typename, , , m, __VA_ARGS__)
11008 #define MOCK_METHOD5_T(m, ...) GMOCK_METHOD5_(typename, , , m, __VA_ARGS__)
11009 #define MOCK_METHOD6_T(m, ...) GMOCK_METHOD6_(typename, , , m, __VA_ARGS__)
11010 #define MOCK_METHOD7_T(m, ...) GMOCK_METHOD7_(typename, , , m, __VA_ARGS__)
11011 #define MOCK_METHOD8_T(m, ...) GMOCK_METHOD8_(typename, , , m, __VA_ARGS__)
11012 #define MOCK_METHOD9_T(m, ...) GMOCK_METHOD9_(typename, , , m, __VA_ARGS__)
11013 #define MOCK_METHOD10_T(m, ...) GMOCK_METHOD10_(typename, , , m, __VA_ARGS__)
11014
11015 #define MOCK_CONST_METHOD0_T(m, ...) \
11016 GMOCK_METHOD0_(typename, const, , m, __VA_ARGS__)
11017 #define MOCK_CONST_METHOD1_T(m, ...) \
11018 GMOCK_METHOD1_(typename, const, , m, __VA_ARGS__)
11019 #define MOCK_CONST_METHOD2_T(m, ...) \
11020 GMOCK_METHOD2_(typename, const, , m, __VA_ARGS__)
11021 #define MOCK_CONST_METHOD3_T(m, ...) \
11022 GMOCK_METHOD3_(typename, const, , m, __VA_ARGS__)
11023 #define MOCK_CONST_METHOD4_T(m, ...) \
11024 GMOCK_METHOD4_(typename, const, , m, __VA_ARGS__)
11025 #define MOCK_CONST_METHOD5_T(m, ...) \
11026 GMOCK_METHOD5_(typename, const, , m, __VA_ARGS__)
11027 #define MOCK_CONST_METHOD6_T(m, ...) \
11028 GMOCK_METHOD6_(typename, const, , m, __VA_ARGS__)
11029 #define MOCK_CONST_METHOD7_T(m, ...) \
11030 GMOCK_METHOD7_(typename, const, , m, __VA_ARGS__)
11031 #define MOCK_CONST_METHOD8_T(m, ...) \
11032 GMOCK_METHOD8_(typename, const, , m, __VA_ARGS__)
11033 #define MOCK_CONST_METHOD9_T(m, ...) \
11034 GMOCK_METHOD9_(typename, const, , m, __VA_ARGS__)
11035 #define MOCK_CONST_METHOD10_T(m, ...) \
11036 GMOCK_METHOD10_(typename, const, , m, __VA_ARGS__)
11037
11038 #define MOCK_METHOD0_WITH_CALLTYPE(ct, m, ...) \
11039 GMOCK_METHOD0_(, , ct, m, __VA_ARGS__)
11040 #define MOCK_METHOD1_WITH_CALLTYPE(ct, m, ...) \
11041 GMOCK_METHOD1_(, , ct, m, __VA_ARGS__)
11042 #define MOCK_METHOD2_WITH_CALLTYPE(ct, m, ...) \
11043 GMOCK_METHOD2_(, , ct, m, __VA_ARGS__)
11044 #define MOCK_METHOD3_WITH_CALLTYPE(ct, m, ...) \
11045 GMOCK_METHOD3_(, , ct, m, __VA_ARGS__)
11046 #define MOCK_METHOD4_WITH_CALLTYPE(ct, m, ...) \
11047 GMOCK_METHOD4_(, , ct, m, __VA_ARGS__)
11048 #define MOCK_METHOD5_WITH_CALLTYPE(ct, m, ...) \
11049 GMOCK_METHOD5_(, , ct, m, __VA_ARGS__)
11050 #define MOCK_METHOD6_WITH_CALLTYPE(ct, m, ...) \
11051 GMOCK_METHOD6_(, , ct, m, __VA_ARGS__)
11052 #define MOCK_METHOD7_WITH_CALLTYPE(ct, m, ...) \
11053 GMOCK_METHOD7_(, , ct, m, __VA_ARGS__)
11054 #define MOCK_METHOD8_WITH_CALLTYPE(ct, m, ...) \
11055 GMOCK_METHOD8_(, , ct, m, __VA_ARGS__)
11056 #define MOCK_METHOD9_WITH_CALLTYPE(ct, m, ...) \
11057 GMOCK_METHOD9_(, , ct, m, __VA_ARGS__)
11058 #define MOCK_METHOD10_WITH_CALLTYPE(ct, m, ...) \
11059 GMOCK_METHOD10_(, , ct, m, __VA_ARGS__)
11060
11061 #define MOCK_CONST_METHOD0_WITH_CALLTYPE(ct, m, ...) \
11062 GMOCK_METHOD0_(, const, ct, m, __VA_ARGS__)
11063 #define MOCK_CONST_METHOD1_WITH_CALLTYPE(ct, m, ...) \
11064 GMOCK_METHOD1_(, const, ct, m, __VA_ARGS__)
11065 #define MOCK_CONST_METHOD2_WITH_CALLTYPE(ct, m, ...) \
11066 GMOCK_METHOD2_(, const, ct, m, __VA_ARGS__)
11067 #define MOCK_CONST_METHOD3_WITH_CALLTYPE(ct, m, ...) \
11068 GMOCK_METHOD3_(, const, ct, m, __VA_ARGS__)
11069 #define MOCK_CONST_METHOD4_WITH_CALLTYPE(ct, m, ...) \
11070 GMOCK_METHOD4_(, const, ct, m, __VA_ARGS__)
11071 #define MOCK_CONST_METHOD5_WITH_CALLTYPE(ct, m, ...) \
11072 GMOCK_METHOD5_(, const, ct, m, __VA_ARGS__)
11073 #define MOCK_CONST_METHOD6_WITH_CALLTYPE(ct, m, ...) \
11074 GMOCK_METHOD6_(, const, ct, m, __VA_ARGS__)
11075 #define MOCK_CONST_METHOD7_WITH_CALLTYPE(ct, m, ...) \
11076 GMOCK_METHOD7_(, const, ct, m, __VA_ARGS__)
11077 #define MOCK_CONST_METHOD8_WITH_CALLTYPE(ct, m, ...) \
11078 GMOCK_METHOD8_(, const, ct, m, __VA_ARGS__)
11079 #define MOCK_CONST_METHOD9_WITH_CALLTYPE(ct, m, ...) \
11080 GMOCK_METHOD9_(, const, ct, m, __VA_ARGS__)
11081 #define MOCK_CONST_METHOD10_WITH_CALLTYPE(ct, m, ...) \
11082 GMOCK_METHOD10_(, const, ct, m, __VA_ARGS__)
11083
11084 #define MOCK_METHOD0_T_WITH_CALLTYPE(ct, m, ...) \
11085 GMOCK_METHOD0_(typename, , ct, m, __VA_ARGS__)
11086 #define MOCK_METHOD1_T_WITH_CALLTYPE(ct, m, ...) \
11087 GMOCK_METHOD1_(typename, , ct, m, __VA_ARGS__)
11088 #define MOCK_METHOD2_T_WITH_CALLTYPE(ct, m, ...) \
11089 GMOCK_METHOD2_(typename, , ct, m, __VA_ARGS__)
11090 #define MOCK_METHOD3_T_WITH_CALLTYPE(ct, m, ...) \
11091 GMOCK_METHOD3_(typename, , ct, m, __VA_ARGS__)
11092 #define MOCK_METHOD4_T_WITH_CALLTYPE(ct, m, ...) \
11093 GMOCK_METHOD4_(typename, , ct, m, __VA_ARGS__)
11094 #define MOCK_METHOD5_T_WITH_CALLTYPE(ct, m, ...) \
11095 GMOCK_METHOD5_(typename, , ct, m, __VA_ARGS__)
11096 #define MOCK_METHOD6_T_WITH_CALLTYPE(ct, m, ...) \
11097 GMOCK_METHOD6_(typename, , ct, m, __VA_ARGS__)
11098 #define MOCK_METHOD7_T_WITH_CALLTYPE(ct, m, ...) \
11099 GMOCK_METHOD7_(typename, , ct, m, __VA_ARGS__)
11100 #define MOCK_METHOD8_T_WITH_CALLTYPE(ct, m, ...) \
11101 GMOCK_METHOD8_(typename, , ct, m, __VA_ARGS__)
11102 #define MOCK_METHOD9_T_WITH_CALLTYPE(ct, m, ...) \
11103 GMOCK_METHOD9_(typename, , ct, m, __VA_ARGS__)
11104 #define MOCK_METHOD10_T_WITH_CALLTYPE(ct, m, ...) \
11105 GMOCK_METHOD10_(typename, , ct, m, __VA_ARGS__)
11106
11107 #define MOCK_CONST_METHOD0_T_WITH_CALLTYPE(ct, m, ...) \
11108 GMOCK_METHOD0_(typename, const, ct, m, __VA_ARGS__)
11109 #define MOCK_CONST_METHOD1_T_WITH_CALLTYPE(ct, m, ...) \
11110 GMOCK_METHOD1_(typename, const, ct, m, __VA_ARGS__)
11111 #define MOCK_CONST_METHOD2_T_WITH_CALLTYPE(ct, m, ...) \
11112 GMOCK_METHOD2_(typename, const, ct, m, __VA_ARGS__)
11113 #define MOCK_CONST_METHOD3_T_WITH_CALLTYPE(ct, m, ...) \
11114 GMOCK_METHOD3_(typename, const, ct, m, __VA_ARGS__)
11115 #define MOCK_CONST_METHOD4_T_WITH_CALLTYPE(ct, m, ...) \
11116 GMOCK_METHOD4_(typename, const, ct, m, __VA_ARGS__)
11117 #define MOCK_CONST_METHOD5_T_WITH_CALLTYPE(ct, m, ...) \
11118 GMOCK_METHOD5_(typename, const, ct, m, __VA_ARGS__)
11119 #define MOCK_CONST_METHOD6_T_WITH_CALLTYPE(ct, m, ...) \
11120 GMOCK_METHOD6_(typename, const, ct, m, __VA_ARGS__)
11121 #define MOCK_CONST_METHOD7_T_WITH_CALLTYPE(ct, m, ...) \
11122 GMOCK_METHOD7_(typename, const, ct, m, __VA_ARGS__)
11123 #define MOCK_CONST_METHOD8_T_WITH_CALLTYPE(ct, m, ...) \
11124 GMOCK_METHOD8_(typename, const, ct, m, __VA_ARGS__)
11125 #define MOCK_CONST_METHOD9_T_WITH_CALLTYPE(ct, m, ...) \
11126 GMOCK_METHOD9_(typename, const, ct, m, __VA_ARGS__)
11127 #define MOCK_CONST_METHOD10_T_WITH_CALLTYPE(ct, m, ...) \
11128 GMOCK_METHOD10_(typename, const, ct, m, __VA_ARGS__)
11129
11130 // A MockFunction<F> class has one mock method whose type is F. It is
11131 // useful when you just want your test code to emit some messages and
11132 // have Google Mock verify the right messages are sent (and perhaps at
11133 // the right times). For example, if you are exercising code:
11134 //
11135 // Foo(1);
11136 // Foo(2);
11137 // Foo(3);
11138 //
11139 // and want to verify that Foo(1) and Foo(3) both invoke
11140 // mock.Bar("a"), but Foo(2) doesn't invoke anything, you can write:
11141 //
11142 // TEST(FooTest, InvokesBarCorrectly) {
11143 // MyMock mock;
11144 // MockFunction<void(string check_point_name)> check;
11145 // {
11146 // InSequence s;
11147 //
11148 // EXPECT_CALL(mock, Bar("a"));
11149 // EXPECT_CALL(check, Call("1"));
11150 // EXPECT_CALL(check, Call("2"));
11151 // EXPECT_CALL(mock, Bar("a"));
11152 // }
11153 // Foo(1);
11154 // check.Call("1");
11155 // Foo(2);
11156 // check.Call("2");
11157 // Foo(3);
11158 // }
11159 //
11160 // The expectation spec says that the first Bar("a") must happen
11161 // before check point "1", the second Bar("a") must happen after check
11162 // point "2", and nothing should happen between the two check
11163 // points. The explicit check points make it easy to tell which
11164 // Bar("a") is called by which call to Foo().
11165 template <typename F>
11166 class MockFunction;
11167
11168 template <typename R>
11169 class MockFunction<R()> {
11170 public:
11171 MockFunction() {}
11172
11173 MOCK_METHOD0_T(Call, R());
11174
11175 private:
11176 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11177 };
11178
11179 template <typename R, typename A0>
11180 class MockFunction<R(A0)> {
11181 public:
11182 MockFunction() {}
11183
11184 MOCK_METHOD1_T(Call, R(A0));
11185
11186 private:
11187 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11188 };
11189
11190 template <typename R, typename A0, typename A1>
11191 class MockFunction<R(A0, A1)> {
11192 public:
11193 MockFunction() {}
11194
11195 MOCK_METHOD2_T(Call, R(A0, A1));
11196
11197 private:
11198 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11199 };
11200
11201 template <typename R, typename A0, typename A1, typename A2>
11202 class MockFunction<R(A0, A1, A2)> {
11203 public:
11204 MockFunction() {}
11205
11206 MOCK_METHOD3_T(Call, R(A0, A1, A2));
11207
11208 private:
11209 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11210 };
11211
11212 template <typename R, typename A0, typename A1, typename A2, typename A3>
11213 class MockFunction<R(A0, A1, A2, A3)> {
11214 public:
11215 MockFunction() {}
11216
11217 MOCK_METHOD4_T(Call, R(A0, A1, A2, A3));
11218
11219 private:
11220 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11221 };
11222
11223 template <typename R, typename A0, typename A1, typename A2, typename A3,
11224 typename A4>
11225 class MockFunction<R(A0, A1, A2, A3, A4)> {
11226 public:
11227 MockFunction() {}
11228
11229 MOCK_METHOD5_T(Call, R(A0, A1, A2, A3, A4));
11230
11231 private:
11232 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11233 };
11234
11235 template <typename R, typename A0, typename A1, typename A2, typename A3,
11236 typename A4, typename A5>
11237 class MockFunction<R(A0, A1, A2, A3, A4, A5)> {
11238 public:
11239 MockFunction() {}
11240
11241 MOCK_METHOD6_T(Call, R(A0, A1, A2, A3, A4, A5));
11242
11243 private:
11244 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11245 };
11246
11247 template <typename R, typename A0, typename A1, typename A2, typename A3,
11248 typename A4, typename A5, typename A6>
11249 class MockFunction<R(A0, A1, A2, A3, A4, A5, A6)> {
11250 public:
11251 MockFunction() {}
11252
11253 MOCK_METHOD7_T(Call, R(A0, A1, A2, A3, A4, A5, A6));
11254
11255 private:
11256 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11257 };
11258
11259 template <typename R, typename A0, typename A1, typename A2, typename A3,
11260 typename A4, typename A5, typename A6, typename A7>
11261 class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7)> {
11262 public:
11263 MockFunction() {}
11264
11265 MOCK_METHOD8_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7));
11266
11267 private:
11268 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11269 };
11270
11271 template <typename R, typename A0, typename A1, typename A2, typename A3,
11272 typename A4, typename A5, typename A6, typename A7, typename A8>
11273 class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7, A8)> {
11274 public:
11275 MockFunction() {}
11276
11277 MOCK_METHOD9_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7, A8));
11278
11279 private:
11280 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11281 };
11282
11283 template <typename R, typename A0, typename A1, typename A2, typename A3,
11284 typename A4, typename A5, typename A6, typename A7, typename A8,
11285 typename A9>
11286 class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9)> {
11287 public:
11288 MockFunction() {}
11289
11290 MOCK_METHOD10_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9));
11291
11292 private:
11293 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11294 };
11295
11296 } // namespace testing
11297
11298 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
11299 // This file was GENERATED by command:
11300 // pump.py gmock-generated-nice-strict.h.pump
11301 // DO NOT EDIT BY HAND!!!
11302
11303 // Copyright 2008, Google Inc.
11304 // All rights reserved.
11305 //
11306 // Redistribution and use in source and binary forms, with or without
11307 // modification, are permitted provided that the following conditions are
11308 // met:
11309 //
11310 // * Redistributions of source code must retain the above copyright
11311 // notice, this list of conditions and the following disclaimer.
11312 // * Redistributions in binary form must reproduce the above
11313 // copyright notice, this list of conditions and the following disclaimer
11314 // in the documentation and/or other materials provided with the
11315 // distribution.
11316 // * Neither the name of Google Inc. nor the names of its
11317 // contributors may be used to endorse or promote products derived from
11318 // this software without specific prior written permission.
11319 //
11320 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
11321 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
11322 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
11323 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
11324 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
11325 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11326 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11327 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11328 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
11329 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
11330 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11331 //
11332 // Author: [email protected] (Zhanyong Wan)
11333
11334 // Implements class templates NiceMock, NaggyMock, and StrictMock.
11335 //
11336 // Given a mock class MockFoo that is created using Google Mock,
11337 // NiceMock<MockFoo> is a subclass of MockFoo that allows
11338 // uninteresting calls (i.e. calls to mock methods that have no
11339 // EXPECT_CALL specs), NaggyMock<MockFoo> is a subclass of MockFoo
11340 // that prints a warning when an uninteresting call occurs, and
11341 // StrictMock<MockFoo> is a subclass of MockFoo that treats all
11342 // uninteresting calls as errors.
11343 //
11344 // Currently a mock is naggy by default, so MockFoo and
11345 // NaggyMock<MockFoo> behave like the same. However, we will soon
11346 // switch the default behavior of mocks to be nice, as that in general
11347 // leads to more maintainable tests. When that happens, MockFoo will
11348 // stop behaving like NaggyMock<MockFoo> and start behaving like
11349 // NiceMock<MockFoo>.
11350 //
11351 // NiceMock, NaggyMock, and StrictMock "inherit" the constructors of
11352 // their respective base class, with up-to 10 arguments. Therefore
11353 // you can write NiceMock<MockFoo>(5, "a") to construct a nice mock
11354 // where MockFoo has a constructor that accepts (int, const char*),
11355 // for example.
11356 //
11357 // A known limitation is that NiceMock<MockFoo>, NaggyMock<MockFoo>,
11358 // and StrictMock<MockFoo> only works for mock methods defined using
11359 // the MOCK_METHOD* family of macros DIRECTLY in the MockFoo class.
11360 // If a mock method is defined in a base class of MockFoo, the "nice"
11361 // or "strict" modifier may not affect it, depending on the compiler.
11362 // In particular, nesting NiceMock, NaggyMock, and StrictMock is NOT
11363 // supported.
11364 //
11365 // Another known limitation is that the constructors of the base mock
11366 // cannot have arguments passed by non-const reference, which are
11367 // banned by the Google C++ style guide anyway.
11368
11369 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
11370 #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
11371
11372
11373 namespace testing {
11374
11375 template <class MockClass>
11376 class NiceMock : public MockClass {
11377 public:
11378 // We don't factor out the constructor body to a common method, as
11379 // we have to avoid a possible clash with members of MockClass.
11380 NiceMock() {
11381 ::testing::Mock::AllowUninterestingCalls(
11382 internal::ImplicitCast_<MockClass*>(this));
11383 }
11384
11385 // C++ doesn't (yet) allow inheritance of constructors, so we have
11386 // to define it for each arity.
11387 template <typename A1>
11388 explicit NiceMock(const A1& a1) : MockClass(a1) {
11389 ::testing::Mock::AllowUninterestingCalls(
11390 internal::ImplicitCast_<MockClass*>(this));
11391 }
11392 template <typename A1, typename A2>
11393 NiceMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {
11394 ::testing::Mock::AllowUninterestingCalls(
11395 internal::ImplicitCast_<MockClass*>(this));
11396 }
11397
11398 template <typename A1, typename A2, typename A3>
11399 NiceMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {
11400 ::testing::Mock::AllowUninterestingCalls(
11401 internal::ImplicitCast_<MockClass*>(this));
11402 }
11403
11404 template <typename A1, typename A2, typename A3, typename A4>
11405 NiceMock(const A1& a1, const A2& a2, const A3& a3,
11406 const A4& a4) : MockClass(a1, a2, a3, a4) {
11407 ::testing::Mock::AllowUninterestingCalls(
11408 internal::ImplicitCast_<MockClass*>(this));
11409 }
11410
11411 template <typename A1, typename A2, typename A3, typename A4, typename A5>
11412 NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11413 const A5& a5) : MockClass(a1, a2, a3, a4, a5) {
11414 ::testing::Mock::AllowUninterestingCalls(
11415 internal::ImplicitCast_<MockClass*>(this));
11416 }
11417
11418 template <typename A1, typename A2, typename A3, typename A4, typename A5,
11419 typename A6>
11420 NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11421 const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {
11422 ::testing::Mock::AllowUninterestingCalls(
11423 internal::ImplicitCast_<MockClass*>(this));
11424 }
11425
11426 template <typename A1, typename A2, typename A3, typename A4, typename A5,
11427 typename A6, typename A7>
11428 NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11429 const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5,
11430 a6, a7) {
11431 ::testing::Mock::AllowUninterestingCalls(
11432 internal::ImplicitCast_<MockClass*>(this));
11433 }
11434
11435 template <typename A1, typename A2, typename A3, typename A4, typename A5,
11436 typename A6, typename A7, typename A8>
11437 NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11438 const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1,
11439 a2, a3, a4, a5, a6, a7, a8) {
11440 ::testing::Mock::AllowUninterestingCalls(
11441 internal::ImplicitCast_<MockClass*>(this));
11442 }
11443
11444 template <typename A1, typename A2, typename A3, typename A4, typename A5,
11445 typename A6, typename A7, typename A8, typename A9>
11446 NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11447 const A5& a5, const A6& a6, const A7& a7, const A8& a8,
11448 const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
11449 ::testing::Mock::AllowUninterestingCalls(
11450 internal::ImplicitCast_<MockClass*>(this));
11451 }
11452
11453 template <typename A1, typename A2, typename A3, typename A4, typename A5,
11454 typename A6, typename A7, typename A8, typename A9, typename A10>
11455 NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11456 const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9,
11457 const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {
11458 ::testing::Mock::AllowUninterestingCalls(
11459 internal::ImplicitCast_<MockClass*>(this));
11460 }
11461
11462 virtual ~NiceMock() {
11463 ::testing::Mock::UnregisterCallReaction(
11464 internal::ImplicitCast_<MockClass*>(this));
11465 }
11466
11467 private:
11468 GTEST_DISALLOW_COPY_AND_ASSIGN_(NiceMock);
11469 };
11470
11471 template <class MockClass>
11472 class NaggyMock : public MockClass {
11473 public:
11474 // We don't factor out the constructor body to a common method, as
11475 // we have to avoid a possible clash with members of MockClass.
11476 NaggyMock() {
11477 ::testing::Mock::WarnUninterestingCalls(
11478 internal::ImplicitCast_<MockClass*>(this));
11479 }
11480
11481 // C++ doesn't (yet) allow inheritance of constructors, so we have
11482 // to define it for each arity.
11483 template <typename A1>
11484 explicit NaggyMock(const A1& a1) : MockClass(a1) {
11485 ::testing::Mock::WarnUninterestingCalls(
11486 internal::ImplicitCast_<MockClass*>(this));
11487 }
11488 template <typename A1, typename A2>
11489 NaggyMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {
11490 ::testing::Mock::WarnUninterestingCalls(
11491 internal::ImplicitCast_<MockClass*>(this));
11492 }
11493
11494 template <typename A1, typename A2, typename A3>
11495 NaggyMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {
11496 ::testing::Mock::WarnUninterestingCalls(
11497 internal::ImplicitCast_<MockClass*>(this));
11498 }
11499
11500 template <typename A1, typename A2, typename A3, typename A4>
11501 NaggyMock(const A1& a1, const A2& a2, const A3& a3,
11502 const A4& a4) : MockClass(a1, a2, a3, a4) {
11503 ::testing::Mock::WarnUninterestingCalls(
11504 internal::ImplicitCast_<MockClass*>(this));
11505 }
11506
11507 template <typename A1, typename A2, typename A3, typename A4, typename A5>
11508 NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11509 const A5& a5) : MockClass(a1, a2, a3, a4, a5) {
11510 ::testing::Mock::WarnUninterestingCalls(
11511 internal::ImplicitCast_<MockClass*>(this));
11512 }
11513
11514 template <typename A1, typename A2, typename A3, typename A4, typename A5,
11515 typename A6>
11516 NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11517 const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {
11518 ::testing::Mock::WarnUninterestingCalls(
11519 internal::ImplicitCast_<MockClass*>(this));
11520 }
11521
11522 template <typename A1, typename A2, typename A3, typename A4, typename A5,
11523 typename A6, typename A7>
11524 NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11525 const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5,
11526 a6, a7) {
11527 ::testing::Mock::WarnUninterestingCalls(
11528 internal::ImplicitCast_<MockClass*>(this));
11529 }
11530
11531 template <typename A1, typename A2, typename A3, typename A4, typename A5,
11532 typename A6, typename A7, typename A8>
11533 NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11534 const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1,
11535 a2, a3, a4, a5, a6, a7, a8) {
11536 ::testing::Mock::WarnUninterestingCalls(
11537 internal::ImplicitCast_<MockClass*>(this));
11538 }
11539
11540 template <typename A1, typename A2, typename A3, typename A4, typename A5,
11541 typename A6, typename A7, typename A8, typename A9>
11542 NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11543 const A5& a5, const A6& a6, const A7& a7, const A8& a8,
11544 const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
11545 ::testing::Mock::WarnUninterestingCalls(
11546 internal::ImplicitCast_<MockClass*>(this));
11547 }
11548
11549 template <typename A1, typename A2, typename A3, typename A4, typename A5,
11550 typename A6, typename A7, typename A8, typename A9, typename A10>
11551 NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11552 const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9,
11553 const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {
11554 ::testing::Mock::WarnUninterestingCalls(
11555 internal::ImplicitCast_<MockClass*>(this));
11556 }
11557
11558 virtual ~NaggyMock() {
11559 ::testing::Mock::UnregisterCallReaction(
11560 internal::ImplicitCast_<MockClass*>(this));
11561 }
11562
11563 private:
11564 GTEST_DISALLOW_COPY_AND_ASSIGN_(NaggyMock);
11565 };
11566
11567 template <class MockClass>
11568 class StrictMock : public MockClass {
11569 public:
11570 // We don't factor out the constructor body to a common method, as
11571 // we have to avoid a possible clash with members of MockClass.
11572 StrictMock() {
11573 ::testing::Mock::FailUninterestingCalls(
11574 internal::ImplicitCast_<MockClass*>(this));
11575 }
11576
11577 // C++ doesn't (yet) allow inheritance of constructors, so we have
11578 // to define it for each arity.
11579 template <typename A1>
11580 explicit StrictMock(const A1& a1) : MockClass(a1) {
11581 ::testing::Mock::FailUninterestingCalls(
11582 internal::ImplicitCast_<MockClass*>(this));
11583 }
11584 template <typename A1, typename A2>
11585 StrictMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {
11586 ::testing::Mock::FailUninterestingCalls(
11587 internal::ImplicitCast_<MockClass*>(this));
11588 }
11589
11590 template <typename A1, typename A2, typename A3>
11591 StrictMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {
11592 ::testing::Mock::FailUninterestingCalls(
11593 internal::ImplicitCast_<MockClass*>(this));
11594 }
11595
11596 template <typename A1, typename A2, typename A3, typename A4>
11597 StrictMock(const A1& a1, const A2& a2, const A3& a3,
11598 const A4& a4) : MockClass(a1, a2, a3, a4) {
11599 ::testing::Mock::FailUninterestingCalls(
11600 internal::ImplicitCast_<MockClass*>(this));
11601 }
11602
11603 template <typename A1, typename A2, typename A3, typename A4, typename A5>
11604 StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11605 const A5& a5) : MockClass(a1, a2, a3, a4, a5) {
11606 ::testing::Mock::FailUninterestingCalls(
11607 internal::ImplicitCast_<MockClass*>(this));
11608 }
11609
11610 template <typename A1, typename A2, typename A3, typename A4, typename A5,
11611 typename A6>
11612 StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11613 const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {
11614 ::testing::Mock::FailUninterestingCalls(
11615 internal::ImplicitCast_<MockClass*>(this));
11616 }
11617
11618 template <typename A1, typename A2, typename A3, typename A4, typename A5,
11619 typename A6, typename A7>
11620 StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11621 const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5,
11622 a6, a7) {
11623 ::testing::Mock::FailUninterestingCalls(
11624 internal::ImplicitCast_<MockClass*>(this));
11625 }
11626
11627 template <typename A1, typename A2, typename A3, typename A4, typename A5,
11628 typename A6, typename A7, typename A8>
11629 StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11630 const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1,
11631 a2, a3, a4, a5, a6, a7, a8) {
11632 ::testing::Mock::FailUninterestingCalls(
11633 internal::ImplicitCast_<MockClass*>(this));
11634 }
11635
11636 template <typename A1, typename A2, typename A3, typename A4, typename A5,
11637 typename A6, typename A7, typename A8, typename A9>
11638 StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11639 const A5& a5, const A6& a6, const A7& a7, const A8& a8,
11640 const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
11641 ::testing::Mock::FailUninterestingCalls(
11642 internal::ImplicitCast_<MockClass*>(this));
11643 }
11644
11645 template <typename A1, typename A2, typename A3, typename A4, typename A5,
11646 typename A6, typename A7, typename A8, typename A9, typename A10>
11647 StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11648 const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9,
11649 const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {
11650 ::testing::Mock::FailUninterestingCalls(
11651 internal::ImplicitCast_<MockClass*>(this));
11652 }
11653
11654 virtual ~StrictMock() {
11655 ::testing::Mock::UnregisterCallReaction(
11656 internal::ImplicitCast_<MockClass*>(this));
11657 }
11658
11659 private:
11660 GTEST_DISALLOW_COPY_AND_ASSIGN_(StrictMock);
11661 };
11662
11663 // The following specializations catch some (relatively more common)
11664 // user errors of nesting nice and strict mocks. They do NOT catch
11665 // all possible errors.
11666
11667 // These specializations are declared but not defined, as NiceMock,
11668 // NaggyMock, and StrictMock cannot be nested.
11669
11670 template <typename MockClass>
11671 class NiceMock<NiceMock<MockClass> >;
11672 template <typename MockClass>
11673 class NiceMock<NaggyMock<MockClass> >;
11674 template <typename MockClass>
11675 class NiceMock<StrictMock<MockClass> >;
11676
11677 template <typename MockClass>
11678 class NaggyMock<NiceMock<MockClass> >;
11679 template <typename MockClass>
11680 class NaggyMock<NaggyMock<MockClass> >;
11681 template <typename MockClass>
11682 class NaggyMock<StrictMock<MockClass> >;
11683
11684 template <typename MockClass>
11685 class StrictMock<NiceMock<MockClass> >;
11686 template <typename MockClass>
11687 class StrictMock<NaggyMock<MockClass> >;
11688 template <typename MockClass>
11689 class StrictMock<StrictMock<MockClass> >;
11690
11691 } // namespace testing
11692
11693 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
11694 // This file was GENERATED by command:
11695 // pump.py gmock-generated-matchers.h.pump
11696 // DO NOT EDIT BY HAND!!!
11697
11698 // Copyright 2008, Google Inc.
11699 // All rights reserved.
11700 //
11701 // Redistribution and use in source and binary forms, with or without
11702 // modification, are permitted provided that the following conditions are
11703 // met:
11704 //
11705 // * Redistributions of source code must retain the above copyright
11706 // notice, this list of conditions and the following disclaimer.
11707 // * Redistributions in binary form must reproduce the above
11708 // copyright notice, this list of conditions and the following disclaimer
11709 // in the documentation and/or other materials provided with the
11710 // distribution.
11711 // * Neither the name of Google Inc. nor the names of its
11712 // contributors may be used to endorse or promote products derived from
11713 // this software without specific prior written permission.
11714 //
11715 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
11716 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
11717 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
11718 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
11719 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
11720 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11721 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11722 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11723 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
11724 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
11725 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11726
11727 // Google Mock - a framework for writing C++ mock classes.
11728 //
11729 // This file implements some commonly used variadic matchers.
11730
11731 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
11732 #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
11733
11734 #include <iterator>
11735 #include <sstream>
11736 #include <string>
11737 #include <vector>
11738
11739 namespace testing {
11740 namespace internal {
11741
11742 // The type of the i-th (0-based) field of Tuple.
11743 #define GMOCK_FIELD_TYPE_(Tuple, i) \
11744 typename ::std::tr1::tuple_element<i, Tuple>::type
11745
11746 // TupleFields<Tuple, k0, ..., kn> is for selecting fields from a
11747 // tuple of type Tuple. It has two members:
11748 //
11749 // type: a tuple type whose i-th field is the ki-th field of Tuple.
11750 // GetSelectedFields(t): returns fields k0, ..., and kn of t as a tuple.
11751 //
11752 // For example, in class TupleFields<tuple<bool, char, int>, 2, 0>, we have:
11753 //
11754 // type is tuple<int, bool>, and
11755 // GetSelectedFields(make_tuple(true, 'a', 42)) is (42, true).
11756
11757 template <class Tuple, int k0 = -1, int k1 = -1, int k2 = -1, int k3 = -1,
11758 int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1, int k8 = -1,
11759 int k9 = -1>
11760 class TupleFields;
11761
11762 // This generic version is used when there are 10 selectors.
11763 template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6,
11764 int k7, int k8, int k9>
11765 class TupleFields {
11766 public:
11767 typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
11768 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
11769 GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4),
11770 GMOCK_FIELD_TYPE_(Tuple, k5), GMOCK_FIELD_TYPE_(Tuple, k6),
11771 GMOCK_FIELD_TYPE_(Tuple, k7), GMOCK_FIELD_TYPE_(Tuple, k8),
11772 GMOCK_FIELD_TYPE_(Tuple, k9)> type;
11773 static type GetSelectedFields(const Tuple& t) {
11774 using ::std::tr1::get;
11775 return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t),
11776 get<k5>(t), get<k6>(t), get<k7>(t), get<k8>(t), get<k9>(t));
11777 }
11778 };
11779
11780 // The following specialization is used for 0 ~ 9 selectors.
11781
11782 template <class Tuple>
11783 class TupleFields<Tuple, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1> {
11784 public:
11785 typedef ::std::tr1::tuple<> type;
11786 static type GetSelectedFields(const Tuple& /* t */) {
11787 using ::std::tr1::get;
11788 return type();
11789 }
11790 };
11791
11792 template <class Tuple, int k0>
11793 class TupleFields<Tuple, k0, -1, -1, -1, -1, -1, -1, -1, -1, -1> {
11794 public:
11795 typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0)> type;
11796 static type GetSelectedFields(const Tuple& t) {
11797 using ::std::tr1::get;
11798 return type(get<k0>(t));
11799 }
11800 };
11801
11802 template <class Tuple, int k0, int k1>
11803 class TupleFields<Tuple, k0, k1, -1, -1, -1, -1, -1, -1, -1, -1> {
11804 public:
11805 typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
11806 GMOCK_FIELD_TYPE_(Tuple, k1)> type;
11807 static type GetSelectedFields(const Tuple& t) {
11808 using ::std::tr1::get;
11809 return type(get<k0>(t), get<k1>(t));
11810 }
11811 };
11812
11813 template <class Tuple, int k0, int k1, int k2>
11814 class TupleFields<Tuple, k0, k1, k2, -1, -1, -1, -1, -1, -1, -1> {
11815 public:
11816 typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
11817 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2)> type;
11818 static type GetSelectedFields(const Tuple& t) {
11819 using ::std::tr1::get;
11820 return type(get<k0>(t), get<k1>(t), get<k2>(t));
11821 }
11822 };
11823
11824 template <class Tuple, int k0, int k1, int k2, int k3>
11825 class TupleFields<Tuple, k0, k1, k2, k3, -1, -1, -1, -1, -1, -1> {
11826 public:
11827 typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
11828 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
11829 GMOCK_FIELD_TYPE_(Tuple, k3)> type;
11830 static type GetSelectedFields(const Tuple& t) {
11831 using ::std::tr1::get;
11832 return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t));
11833 }
11834 };
11835
11836 template <class Tuple, int k0, int k1, int k2, int k3, int k4>
11837 class TupleFields<Tuple, k0, k1, k2, k3, k4, -1, -1, -1, -1, -1> {
11838 public:
11839 typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
11840 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
11841 GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4)> type;
11842 static type GetSelectedFields(const Tuple& t) {
11843 using ::std::tr1::get;
11844 return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t));
11845 }
11846 };
11847
11848 template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5>
11849 class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, -1, -1, -1, -1> {
11850 public:
11851 typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
11852 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
11853 GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4),
11854 GMOCK_FIELD_TYPE_(Tuple, k5)> type;
11855 static type GetSelectedFields(const Tuple& t) {
11856 using ::std::tr1::get;
11857 return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t),
11858 get<k5>(t));
11859 }
11860 };
11861
11862 template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6>
11863 class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, k6, -1, -1, -1> {
11864 public:
11865 typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
11866 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
11867 GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4),
11868 GMOCK_FIELD_TYPE_(Tuple, k5), GMOCK_FIELD_TYPE_(Tuple, k6)> type;
11869 static type GetSelectedFields(const Tuple& t) {
11870 using ::std::tr1::get;
11871 return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t),
11872 get<k5>(t), get<k6>(t));
11873 }
11874 };
11875
11876 template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6,
11877 int k7>
11878 class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, k6, k7, -1, -1> {
11879 public:
11880 typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
11881 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
11882 GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4),
11883 GMOCK_FIELD_TYPE_(Tuple, k5), GMOCK_FIELD_TYPE_(Tuple, k6),
11884 GMOCK_FIELD_TYPE_(Tuple, k7)> type;
11885 static type GetSelectedFields(const Tuple& t) {
11886 using ::std::tr1::get;
11887 return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t),
11888 get<k5>(t), get<k6>(t), get<k7>(t));
11889 }
11890 };
11891
11892 template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6,
11893 int k7, int k8>
11894 class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, k6, k7, k8, -1> {
11895 public:
11896 typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
11897 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
11898 GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4),
11899 GMOCK_FIELD_TYPE_(Tuple, k5), GMOCK_FIELD_TYPE_(Tuple, k6),
11900 GMOCK_FIELD_TYPE_(Tuple, k7), GMOCK_FIELD_TYPE_(Tuple, k8)> type;
11901 static type GetSelectedFields(const Tuple& t) {
11902 using ::std::tr1::get;
11903 return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t),
11904 get<k5>(t), get<k6>(t), get<k7>(t), get<k8>(t));
11905 }
11906 };
11907
11908 #undef GMOCK_FIELD_TYPE_
11909
11910 // Implements the Args() matcher.
11911 template <class ArgsTuple, int k0 = -1, int k1 = -1, int k2 = -1, int k3 = -1,
11912 int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1, int k8 = -1,
11913 int k9 = -1>
11914 class ArgsMatcherImpl : public MatcherInterface<ArgsTuple> {
11915 public:
11916 // ArgsTuple may have top-level const or reference modifiers.
11917 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(ArgsTuple) RawArgsTuple;
11918 typedef typename internal::TupleFields<RawArgsTuple, k0, k1, k2, k3, k4, k5,
11919 k6, k7, k8, k9>::type SelectedArgs;
11920 typedef Matcher<const SelectedArgs&> MonomorphicInnerMatcher;
11921
11922 template <typename InnerMatcher>
11923 explicit ArgsMatcherImpl(const InnerMatcher& inner_matcher)
11924 : inner_matcher_(SafeMatcherCast<const SelectedArgs&>(inner_matcher)) {}
11925
11926 virtual bool MatchAndExplain(ArgsTuple args,
11927 MatchResultListener* listener) const {
11928 const SelectedArgs& selected_args = GetSelectedArgs(args);
11929 if (!listener->IsInterested())
11930 return inner_matcher_.Matches(selected_args);
11931
11932 PrintIndices(listener->stream());
11933 *listener << "are " << PrintToString(selected_args);
11934
11935 StringMatchResultListener inner_listener;
11936 const bool match = inner_matcher_.MatchAndExplain(selected_args,
11937 &inner_listener);
11938 PrintIfNotEmpty(inner_listener.str(), listener->stream());
11939 return match;
11940 }
11941
11942 virtual void DescribeTo(::std::ostream* os) const {
11943 *os << "are a tuple ";
11944 PrintIndices(os);
11945 inner_matcher_.DescribeTo(os);
11946 }
11947
11948 virtual void DescribeNegationTo(::std::ostream* os) const {
11949 *os << "are a tuple ";
11950 PrintIndices(os);
11951 inner_matcher_.DescribeNegationTo(os);
11952 }
11953
11954 private:
11955 static SelectedArgs GetSelectedArgs(ArgsTuple args) {
11956 return TupleFields<RawArgsTuple, k0, k1, k2, k3, k4, k5, k6, k7, k8,
11957 k9>::GetSelectedFields(args);
11958 }
11959
11960 // Prints the indices of the selected fields.
11961 static void PrintIndices(::std::ostream* os) {
11962 *os << "whose fields (";
11963 const int indices[10] = { k0, k1, k2, k3, k4, k5, k6, k7, k8, k9 };
11964 for (int i = 0; i < 10; i++) {
11965 if (indices[i] < 0)
11966 break;
11967
11968 if (i >= 1)
11969 *os << ", ";
11970
11971 *os << "#" << indices[i];
11972 }
11973 *os << ") ";
11974 }
11975
11976 const MonomorphicInnerMatcher inner_matcher_;
11977
11978 GTEST_DISALLOW_ASSIGN_(ArgsMatcherImpl);
11979 };
11980
11981 template <class InnerMatcher, int k0 = -1, int k1 = -1, int k2 = -1,
11982 int k3 = -1, int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1,
11983 int k8 = -1, int k9 = -1>
11984 class ArgsMatcher {
11985 public:
11986 explicit ArgsMatcher(const InnerMatcher& inner_matcher)
11987 : inner_matcher_(inner_matcher) {}
11988
11989 template <typename ArgsTuple>
11990 operator Matcher<ArgsTuple>() const {
11991 return MakeMatcher(new ArgsMatcherImpl<ArgsTuple, k0, k1, k2, k3, k4, k5,
11992 k6, k7, k8, k9>(inner_matcher_));
11993 }
11994
11995 private:
11996 const InnerMatcher inner_matcher_;
11997
11998 GTEST_DISALLOW_ASSIGN_(ArgsMatcher);
11999 };
12000
12001 // A set of metafunctions for computing the result type of AllOf.
12002 // AllOf(m1, ..., mN) returns
12003 // AllOfResultN<decltype(m1), ..., decltype(mN)>::type.
12004
12005 // Although AllOf isn't defined for one argument, AllOfResult1 is defined
12006 // to simplify the implementation.
12007 template <typename M1>
12008 struct AllOfResult1 {
12009 typedef M1 type;
12010 };
12011
12012 template <typename M1, typename M2>
12013 struct AllOfResult2 {
12014 typedef BothOfMatcher<
12015 typename AllOfResult1<M1>::type,
12016 typename AllOfResult1<M2>::type
12017 > type;
12018 };
12019
12020 template <typename M1, typename M2, typename M3>
12021 struct AllOfResult3 {
12022 typedef BothOfMatcher<
12023 typename AllOfResult1<M1>::type,
12024 typename AllOfResult2<M2, M3>::type
12025 > type;
12026 };
12027
12028 template <typename M1, typename M2, typename M3, typename M4>
12029 struct AllOfResult4 {
12030 typedef BothOfMatcher<
12031 typename AllOfResult2<M1, M2>::type,
12032 typename AllOfResult2<M3, M4>::type
12033 > type;
12034 };
12035
12036 template <typename M1, typename M2, typename M3, typename M4, typename M5>
12037 struct AllOfResult5 {
12038 typedef BothOfMatcher<
12039 typename AllOfResult2<M1, M2>::type,
12040 typename AllOfResult3<M3, M4, M5>::type
12041 > type;
12042 };
12043
12044 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12045 typename M6>
12046 struct AllOfResult6 {
12047 typedef BothOfMatcher<
12048 typename AllOfResult3<M1, M2, M3>::type,
12049 typename AllOfResult3<M4, M5, M6>::type
12050 > type;
12051 };
12052
12053 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12054 typename M6, typename M7>
12055 struct AllOfResult7 {
12056 typedef BothOfMatcher<
12057 typename AllOfResult3<M1, M2, M3>::type,
12058 typename AllOfResult4<M4, M5, M6, M7>::type
12059 > type;
12060 };
12061
12062 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12063 typename M6, typename M7, typename M8>
12064 struct AllOfResult8 {
12065 typedef BothOfMatcher<
12066 typename AllOfResult4<M1, M2, M3, M4>::type,
12067 typename AllOfResult4<M5, M6, M7, M8>::type
12068 > type;
12069 };
12070
12071 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12072 typename M6, typename M7, typename M8, typename M9>
12073 struct AllOfResult9 {
12074 typedef BothOfMatcher<
12075 typename AllOfResult4<M1, M2, M3, M4>::type,
12076 typename AllOfResult5<M5, M6, M7, M8, M9>::type
12077 > type;
12078 };
12079
12080 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12081 typename M6, typename M7, typename M8, typename M9, typename M10>
12082 struct AllOfResult10 {
12083 typedef BothOfMatcher<
12084 typename AllOfResult5<M1, M2, M3, M4, M5>::type,
12085 typename AllOfResult5<M6, M7, M8, M9, M10>::type
12086 > type;
12087 };
12088
12089 // A set of metafunctions for computing the result type of AnyOf.
12090 // AnyOf(m1, ..., mN) returns
12091 // AnyOfResultN<decltype(m1), ..., decltype(mN)>::type.
12092
12093 // Although AnyOf isn't defined for one argument, AnyOfResult1 is defined
12094 // to simplify the implementation.
12095 template <typename M1>
12096 struct AnyOfResult1 {
12097 typedef M1 type;
12098 };
12099
12100 template <typename M1, typename M2>
12101 struct AnyOfResult2 {
12102 typedef EitherOfMatcher<
12103 typename AnyOfResult1<M1>::type,
12104 typename AnyOfResult1<M2>::type
12105 > type;
12106 };
12107
12108 template <typename M1, typename M2, typename M3>
12109 struct AnyOfResult3 {
12110 typedef EitherOfMatcher<
12111 typename AnyOfResult1<M1>::type,
12112 typename AnyOfResult2<M2, M3>::type
12113 > type;
12114 };
12115
12116 template <typename M1, typename M2, typename M3, typename M4>
12117 struct AnyOfResult4 {
12118 typedef EitherOfMatcher<
12119 typename AnyOfResult2<M1, M2>::type,
12120 typename AnyOfResult2<M3, M4>::type
12121 > type;
12122 };
12123
12124 template <typename M1, typename M2, typename M3, typename M4, typename M5>
12125 struct AnyOfResult5 {
12126 typedef EitherOfMatcher<
12127 typename AnyOfResult2<M1, M2>::type,
12128 typename AnyOfResult3<M3, M4, M5>::type
12129 > type;
12130 };
12131
12132 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12133 typename M6>
12134 struct AnyOfResult6 {
12135 typedef EitherOfMatcher<
12136 typename AnyOfResult3<M1, M2, M3>::type,
12137 typename AnyOfResult3<M4, M5, M6>::type
12138 > type;
12139 };
12140
12141 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12142 typename M6, typename M7>
12143 struct AnyOfResult7 {
12144 typedef EitherOfMatcher<
12145 typename AnyOfResult3<M1, M2, M3>::type,
12146 typename AnyOfResult4<M4, M5, M6, M7>::type
12147 > type;
12148 };
12149
12150 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12151 typename M6, typename M7, typename M8>
12152 struct AnyOfResult8 {
12153 typedef EitherOfMatcher<
12154 typename AnyOfResult4<M1, M2, M3, M4>::type,
12155 typename AnyOfResult4<M5, M6, M7, M8>::type
12156 > type;
12157 };
12158
12159 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12160 typename M6, typename M7, typename M8, typename M9>
12161 struct AnyOfResult9 {
12162 typedef EitherOfMatcher<
12163 typename AnyOfResult4<M1, M2, M3, M4>::type,
12164 typename AnyOfResult5<M5, M6, M7, M8, M9>::type
12165 > type;
12166 };
12167
12168 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12169 typename M6, typename M7, typename M8, typename M9, typename M10>
12170 struct AnyOfResult10 {
12171 typedef EitherOfMatcher<
12172 typename AnyOfResult5<M1, M2, M3, M4, M5>::type,
12173 typename AnyOfResult5<M6, M7, M8, M9, M10>::type
12174 > type;
12175 };
12176
12177 } // namespace internal
12178
12179 // Args<N1, N2, ..., Nk>(a_matcher) matches a tuple if the selected
12180 // fields of it matches a_matcher. C++ doesn't support default
12181 // arguments for function templates, so we have to overload it.
12182 template <typename InnerMatcher>
12183 inline internal::ArgsMatcher<InnerMatcher>
12184 Args(const InnerMatcher& matcher) {
12185 return internal::ArgsMatcher<InnerMatcher>(matcher);
12186 }
12187
12188 template <int k1, typename InnerMatcher>
12189 inline internal::ArgsMatcher<InnerMatcher, k1>
12190 Args(const InnerMatcher& matcher) {
12191 return internal::ArgsMatcher<InnerMatcher, k1>(matcher);
12192 }
12193
12194 template <int k1, int k2, typename InnerMatcher>
12195 inline internal::ArgsMatcher<InnerMatcher, k1, k2>
12196 Args(const InnerMatcher& matcher) {
12197 return internal::ArgsMatcher<InnerMatcher, k1, k2>(matcher);
12198 }
12199
12200 template <int k1, int k2, int k3, typename InnerMatcher>
12201 inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3>
12202 Args(const InnerMatcher& matcher) {
12203 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3>(matcher);
12204 }
12205
12206 template <int k1, int k2, int k3, int k4, typename InnerMatcher>
12207 inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4>
12208 Args(const InnerMatcher& matcher) {
12209 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4>(matcher);
12210 }
12211
12212 template <int k1, int k2, int k3, int k4, int k5, typename InnerMatcher>
12213 inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5>
12214 Args(const InnerMatcher& matcher) {
12215 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5>(matcher);
12216 }
12217
12218 template <int k1, int k2, int k3, int k4, int k5, int k6, typename InnerMatcher>
12219 inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6>
12220 Args(const InnerMatcher& matcher) {
12221 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6>(matcher);
12222 }
12223
12224 template <int k1, int k2, int k3, int k4, int k5, int k6, int k7,
12225 typename InnerMatcher>
12226 inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7>
12227 Args(const InnerMatcher& matcher) {
12228 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6,
12229 k7>(matcher);
12230 }
12231
12232 template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
12233 typename InnerMatcher>
12234 inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8>
12235 Args(const InnerMatcher& matcher) {
12236 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7,
12237 k8>(matcher);
12238 }
12239
12240 template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
12241 int k9, typename InnerMatcher>
12242 inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8, k9>
12243 Args(const InnerMatcher& matcher) {
12244 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8,
12245 k9>(matcher);
12246 }
12247
12248 template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
12249 int k9, int k10, typename InnerMatcher>
12250 inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8, k9,
12251 k10>
12252 Args(const InnerMatcher& matcher) {
12253 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8,
12254 k9, k10>(matcher);
12255 }
12256
12257 // ElementsAre(e_1, e_2, ... e_n) matches an STL-style container with
12258 // n elements, where the i-th element in the container must
12259 // match the i-th argument in the list. Each argument of
12260 // ElementsAre() can be either a value or a matcher. We support up to
12261 // 10 arguments.
12262 //
12263 // The use of DecayArray in the implementation allows ElementsAre()
12264 // to accept string literals, whose type is const char[N], but we
12265 // want to treat them as const char*.
12266 //
12267 // NOTE: Since ElementsAre() cares about the order of the elements, it
12268 // must not be used with containers whose elements's order is
12269 // undefined (e.g. hash_map).
12270
12271 inline internal::ElementsAreMatcher<
12272 std::tr1::tuple<> >
12273 ElementsAre() {
12274 typedef std::tr1::tuple<> Args;
12275 return internal::ElementsAreMatcher<Args>(Args());
12276 }
12277
12278 template <typename T1>
12279 inline internal::ElementsAreMatcher<
12280 std::tr1::tuple<
12281 typename internal::DecayArray<T1>::type> >
12282 ElementsAre(const T1& e1) {
12283 typedef std::tr1::tuple<
12284 typename internal::DecayArray<T1>::type> Args;
12285 return internal::ElementsAreMatcher<Args>(Args(e1));
12286 }
12287
12288 template <typename T1, typename T2>
12289 inline internal::ElementsAreMatcher<
12290 std::tr1::tuple<
12291 typename internal::DecayArray<T1>::type,
12292 typename internal::DecayArray<T2>::type> >
12293 ElementsAre(const T1& e1, const T2& e2) {
12294 typedef std::tr1::tuple<
12295 typename internal::DecayArray<T1>::type,
12296 typename internal::DecayArray<T2>::type> Args;
12297 return internal::ElementsAreMatcher<Args>(Args(e1, e2));
12298 }
12299
12300 template <typename T1, typename T2, typename T3>
12301 inline internal::ElementsAreMatcher<
12302 std::tr1::tuple<
12303 typename internal::DecayArray<T1>::type,
12304 typename internal::DecayArray<T2>::type,
12305 typename internal::DecayArray<T3>::type> >
12306 ElementsAre(const T1& e1, const T2& e2, const T3& e3) {
12307 typedef std::tr1::tuple<
12308 typename internal::DecayArray<T1>::type,
12309 typename internal::DecayArray<T2>::type,
12310 typename internal::DecayArray<T3>::type> Args;
12311 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3));
12312 }
12313
12314 template <typename T1, typename T2, typename T3, typename T4>
12315 inline internal::ElementsAreMatcher<
12316 std::tr1::tuple<
12317 typename internal::DecayArray<T1>::type,
12318 typename internal::DecayArray<T2>::type,
12319 typename internal::DecayArray<T3>::type,
12320 typename internal::DecayArray<T4>::type> >
12321 ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4) {
12322 typedef std::tr1::tuple<
12323 typename internal::DecayArray<T1>::type,
12324 typename internal::DecayArray<T2>::type,
12325 typename internal::DecayArray<T3>::type,
12326 typename internal::DecayArray<T4>::type> Args;
12327 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4));
12328 }
12329
12330 template <typename T1, typename T2, typename T3, typename T4, typename T5>
12331 inline internal::ElementsAreMatcher<
12332 std::tr1::tuple<
12333 typename internal::DecayArray<T1>::type,
12334 typename internal::DecayArray<T2>::type,
12335 typename internal::DecayArray<T3>::type,
12336 typename internal::DecayArray<T4>::type,
12337 typename internal::DecayArray<T5>::type> >
12338 ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
12339 const T5& e5) {
12340 typedef std::tr1::tuple<
12341 typename internal::DecayArray<T1>::type,
12342 typename internal::DecayArray<T2>::type,
12343 typename internal::DecayArray<T3>::type,
12344 typename internal::DecayArray<T4>::type,
12345 typename internal::DecayArray<T5>::type> Args;
12346 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5));
12347 }
12348
12349 template <typename T1, typename T2, typename T3, typename T4, typename T5,
12350 typename T6>
12351 inline internal::ElementsAreMatcher<
12352 std::tr1::tuple<
12353 typename internal::DecayArray<T1>::type,
12354 typename internal::DecayArray<T2>::type,
12355 typename internal::DecayArray<T3>::type,
12356 typename internal::DecayArray<T4>::type,
12357 typename internal::DecayArray<T5>::type,
12358 typename internal::DecayArray<T6>::type> >
12359 ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
12360 const T5& e5, const T6& e6) {
12361 typedef std::tr1::tuple<
12362 typename internal::DecayArray<T1>::type,
12363 typename internal::DecayArray<T2>::type,
12364 typename internal::DecayArray<T3>::type,
12365 typename internal::DecayArray<T4>::type,
12366 typename internal::DecayArray<T5>::type,
12367 typename internal::DecayArray<T6>::type> Args;
12368 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, e6));
12369 }
12370
12371 template <typename T1, typename T2, typename T3, typename T4, typename T5,
12372 typename T6, typename T7>
12373 inline internal::ElementsAreMatcher<
12374 std::tr1::tuple<
12375 typename internal::DecayArray<T1>::type,
12376 typename internal::DecayArray<T2>::type,
12377 typename internal::DecayArray<T3>::type,
12378 typename internal::DecayArray<T4>::type,
12379 typename internal::DecayArray<T5>::type,
12380 typename internal::DecayArray<T6>::type,
12381 typename internal::DecayArray<T7>::type> >
12382 ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
12383 const T5& e5, const T6& e6, const T7& e7) {
12384 typedef std::tr1::tuple<
12385 typename internal::DecayArray<T1>::type,
12386 typename internal::DecayArray<T2>::type,
12387 typename internal::DecayArray<T3>::type,
12388 typename internal::DecayArray<T4>::type,
12389 typename internal::DecayArray<T5>::type,
12390 typename internal::DecayArray<T6>::type,
12391 typename internal::DecayArray<T7>::type> Args;
12392 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, e6, e7));
12393 }
12394
12395 template <typename T1, typename T2, typename T3, typename T4, typename T5,
12396 typename T6, typename T7, typename T8>
12397 inline internal::ElementsAreMatcher<
12398 std::tr1::tuple<
12399 typename internal::DecayArray<T1>::type,
12400 typename internal::DecayArray<T2>::type,
12401 typename internal::DecayArray<T3>::type,
12402 typename internal::DecayArray<T4>::type,
12403 typename internal::DecayArray<T5>::type,
12404 typename internal::DecayArray<T6>::type,
12405 typename internal::DecayArray<T7>::type,
12406 typename internal::DecayArray<T8>::type> >
12407 ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
12408 const T5& e5, const T6& e6, const T7& e7, const T8& e8) {
12409 typedef std::tr1::tuple<
12410 typename internal::DecayArray<T1>::type,
12411 typename internal::DecayArray<T2>::type,
12412 typename internal::DecayArray<T3>::type,
12413 typename internal::DecayArray<T4>::type,
12414 typename internal::DecayArray<T5>::type,
12415 typename internal::DecayArray<T6>::type,
12416 typename internal::DecayArray<T7>::type,
12417 typename internal::DecayArray<T8>::type> Args;
12418 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, e6, e7,
12419 e8));
12420 }
12421
12422 template <typename T1, typename T2, typename T3, typename T4, typename T5,
12423 typename T6, typename T7, typename T8, typename T9>
12424 inline internal::ElementsAreMatcher<
12425 std::tr1::tuple<
12426 typename internal::DecayArray<T1>::type,
12427 typename internal::DecayArray<T2>::type,
12428 typename internal::DecayArray<T3>::type,
12429 typename internal::DecayArray<T4>::type,
12430 typename internal::DecayArray<T5>::type,
12431 typename internal::DecayArray<T6>::type,
12432 typename internal::DecayArray<T7>::type,
12433 typename internal::DecayArray<T8>::type,
12434 typename internal::DecayArray<T9>::type> >
12435 ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
12436 const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9) {
12437 typedef std::tr1::tuple<
12438 typename internal::DecayArray<T1>::type,
12439 typename internal::DecayArray<T2>::type,
12440 typename internal::DecayArray<T3>::type,
12441 typename internal::DecayArray<T4>::type,
12442 typename internal::DecayArray<T5>::type,
12443 typename internal::DecayArray<T6>::type,
12444 typename internal::DecayArray<T7>::type,
12445 typename internal::DecayArray<T8>::type,
12446 typename internal::DecayArray<T9>::type> Args;
12447 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, e6, e7,
12448 e8, e9));
12449 }
12450
12451 template <typename T1, typename T2, typename T3, typename T4, typename T5,
12452 typename T6, typename T7, typename T8, typename T9, typename T10>
12453 inline internal::ElementsAreMatcher<
12454 std::tr1::tuple<
12455 typename internal::DecayArray<T1>::type,
12456 typename internal::DecayArray<T2>::type,
12457 typename internal::DecayArray<T3>::type,
12458 typename internal::DecayArray<T4>::type,
12459 typename internal::DecayArray<T5>::type,
12460 typename internal::DecayArray<T6>::type,
12461 typename internal::DecayArray<T7>::type,
12462 typename internal::DecayArray<T8>::type,
12463 typename internal::DecayArray<T9>::type,
12464 typename internal::DecayArray<T10>::type> >
12465 ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
12466 const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9,
12467 const T10& e10) {
12468 typedef std::tr1::tuple<
12469 typename internal::DecayArray<T1>::type,
12470 typename internal::DecayArray<T2>::type,
12471 typename internal::DecayArray<T3>::type,
12472 typename internal::DecayArray<T4>::type,
12473 typename internal::DecayArray<T5>::type,
12474 typename internal::DecayArray<T6>::type,
12475 typename internal::DecayArray<T7>::type,
12476 typename internal::DecayArray<T8>::type,
12477 typename internal::DecayArray<T9>::type,
12478 typename internal::DecayArray<T10>::type> Args;
12479 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, e6, e7,
12480 e8, e9, e10));
12481 }
12482
12483 // UnorderedElementsAre(e_1, e_2, ..., e_n) is an ElementsAre extension
12484 // that matches n elements in any order. We support up to n=10 arguments.
12485
12486 inline internal::UnorderedElementsAreMatcher<
12487 std::tr1::tuple<> >
12488 UnorderedElementsAre() {
12489 typedef std::tr1::tuple<> Args;
12490 return internal::UnorderedElementsAreMatcher<Args>(Args());
12491 }
12492
12493 template <typename T1>
12494 inline internal::UnorderedElementsAreMatcher<
12495 std::tr1::tuple<
12496 typename internal::DecayArray<T1>::type> >
12497 UnorderedElementsAre(const T1& e1) {
12498 typedef std::tr1::tuple<
12499 typename internal::DecayArray<T1>::type> Args;
12500 return internal::UnorderedElementsAreMatcher<Args>(Args(e1));
12501 }
12502
12503 template <typename T1, typename T2>
12504 inline internal::UnorderedElementsAreMatcher<
12505 std::tr1::tuple<
12506 typename internal::DecayArray<T1>::type,
12507 typename internal::DecayArray<T2>::type> >
12508 UnorderedElementsAre(const T1& e1, const T2& e2) {
12509 typedef std::tr1::tuple<
12510 typename internal::DecayArray<T1>::type,
12511 typename internal::DecayArray<T2>::type> Args;
12512 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2));
12513 }
12514
12515 template <typename T1, typename T2, typename T3>
12516 inline internal::UnorderedElementsAreMatcher<
12517 std::tr1::tuple<
12518 typename internal::DecayArray<T1>::type,
12519 typename internal::DecayArray<T2>::type,
12520 typename internal::DecayArray<T3>::type> >
12521 UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3) {
12522 typedef std::tr1::tuple<
12523 typename internal::DecayArray<T1>::type,
12524 typename internal::DecayArray<T2>::type,
12525 typename internal::DecayArray<T3>::type> Args;
12526 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3));
12527 }
12528
12529 template <typename T1, typename T2, typename T3, typename T4>
12530 inline internal::UnorderedElementsAreMatcher<
12531 std::tr1::tuple<
12532 typename internal::DecayArray<T1>::type,
12533 typename internal::DecayArray<T2>::type,
12534 typename internal::DecayArray<T3>::type,
12535 typename internal::DecayArray<T4>::type> >
12536 UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4) {
12537 typedef std::tr1::tuple<
12538 typename internal::DecayArray<T1>::type,
12539 typename internal::DecayArray<T2>::type,
12540 typename internal::DecayArray<T3>::type,
12541 typename internal::DecayArray<T4>::type> Args;
12542 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4));
12543 }
12544
12545 template <typename T1, typename T2, typename T3, typename T4, typename T5>
12546 inline internal::UnorderedElementsAreMatcher<
12547 std::tr1::tuple<
12548 typename internal::DecayArray<T1>::type,
12549 typename internal::DecayArray<T2>::type,
12550 typename internal::DecayArray<T3>::type,
12551 typename internal::DecayArray<T4>::type,
12552 typename internal::DecayArray<T5>::type> >
12553 UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
12554 const T5& e5) {
12555 typedef std::tr1::tuple<
12556 typename internal::DecayArray<T1>::type,
12557 typename internal::DecayArray<T2>::type,
12558 typename internal::DecayArray<T3>::type,
12559 typename internal::DecayArray<T4>::type,
12560 typename internal::DecayArray<T5>::type> Args;
12561 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5));
12562 }
12563
12564 template <typename T1, typename T2, typename T3, typename T4, typename T5,
12565 typename T6>
12566 inline internal::UnorderedElementsAreMatcher<
12567 std::tr1::tuple<
12568 typename internal::DecayArray<T1>::type,
12569 typename internal::DecayArray<T2>::type,
12570 typename internal::DecayArray<T3>::type,
12571 typename internal::DecayArray<T4>::type,
12572 typename internal::DecayArray<T5>::type,
12573 typename internal::DecayArray<T6>::type> >
12574 UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
12575 const T5& e5, const T6& e6) {
12576 typedef std::tr1::tuple<
12577 typename internal::DecayArray<T1>::type,
12578 typename internal::DecayArray<T2>::type,
12579 typename internal::DecayArray<T3>::type,
12580 typename internal::DecayArray<T4>::type,
12581 typename internal::DecayArray<T5>::type,
12582 typename internal::DecayArray<T6>::type> Args;
12583 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5,
12584 e6));
12585 }
12586
12587 template <typename T1, typename T2, typename T3, typename T4, typename T5,
12588 typename T6, typename T7>
12589 inline internal::UnorderedElementsAreMatcher<
12590 std::tr1::tuple<
12591 typename internal::DecayArray<T1>::type,
12592 typename internal::DecayArray<T2>::type,
12593 typename internal::DecayArray<T3>::type,
12594 typename internal::DecayArray<T4>::type,
12595 typename internal::DecayArray<T5>::type,
12596 typename internal::DecayArray<T6>::type,
12597 typename internal::DecayArray<T7>::type> >
12598 UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
12599 const T5& e5, const T6& e6, const T7& e7) {
12600 typedef std::tr1::tuple<
12601 typename internal::DecayArray<T1>::type,
12602 typename internal::DecayArray<T2>::type,
12603 typename internal::DecayArray<T3>::type,
12604 typename internal::DecayArray<T4>::type,
12605 typename internal::DecayArray<T5>::type,
12606 typename internal::DecayArray<T6>::type,
12607 typename internal::DecayArray<T7>::type> Args;
12608 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5,
12609 e6, e7));
12610 }
12611
12612 template <typename T1, typename T2, typename T3, typename T4, typename T5,
12613 typename T6, typename T7, typename T8>
12614 inline internal::UnorderedElementsAreMatcher<
12615 std::tr1::tuple<
12616 typename internal::DecayArray<T1>::type,
12617 typename internal::DecayArray<T2>::type,
12618 typename internal::DecayArray<T3>::type,
12619 typename internal::DecayArray<T4>::type,
12620 typename internal::DecayArray<T5>::type,
12621 typename internal::DecayArray<T6>::type,
12622 typename internal::DecayArray<T7>::type,
12623 typename internal::DecayArray<T8>::type> >
12624 UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
12625 const T5& e5, const T6& e6, const T7& e7, const T8& e8) {
12626 typedef std::tr1::tuple<
12627 typename internal::DecayArray<T1>::type,
12628 typename internal::DecayArray<T2>::type,
12629 typename internal::DecayArray<T3>::type,
12630 typename internal::DecayArray<T4>::type,
12631 typename internal::DecayArray<T5>::type,
12632 typename internal::DecayArray<T6>::type,
12633 typename internal::DecayArray<T7>::type,
12634 typename internal::DecayArray<T8>::type> Args;
12635 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5,
12636 e6, e7, e8));
12637 }
12638
12639 template <typename T1, typename T2, typename T3, typename T4, typename T5,
12640 typename T6, typename T7, typename T8, typename T9>
12641 inline internal::UnorderedElementsAreMatcher<
12642 std::tr1::tuple<
12643 typename internal::DecayArray<T1>::type,
12644 typename internal::DecayArray<T2>::type,
12645 typename internal::DecayArray<T3>::type,
12646 typename internal::DecayArray<T4>::type,
12647 typename internal::DecayArray<T5>::type,
12648 typename internal::DecayArray<T6>::type,
12649 typename internal::DecayArray<T7>::type,
12650 typename internal::DecayArray<T8>::type,
12651 typename internal::DecayArray<T9>::type> >
12652 UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
12653 const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9) {
12654 typedef std::tr1::tuple<
12655 typename internal::DecayArray<T1>::type,
12656 typename internal::DecayArray<T2>::type,
12657 typename internal::DecayArray<T3>::type,
12658 typename internal::DecayArray<T4>::type,
12659 typename internal::DecayArray<T5>::type,
12660 typename internal::DecayArray<T6>::type,
12661 typename internal::DecayArray<T7>::type,
12662 typename internal::DecayArray<T8>::type,
12663 typename internal::DecayArray<T9>::type> Args;
12664 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5,
12665 e6, e7, e8, e9));
12666 }
12667
12668 template <typename T1, typename T2, typename T3, typename T4, typename T5,
12669 typename T6, typename T7, typename T8, typename T9, typename T10>
12670 inline internal::UnorderedElementsAreMatcher<
12671 std::tr1::tuple<
12672 typename internal::DecayArray<T1>::type,
12673 typename internal::DecayArray<T2>::type,
12674 typename internal::DecayArray<T3>::type,
12675 typename internal::DecayArray<T4>::type,
12676 typename internal::DecayArray<T5>::type,
12677 typename internal::DecayArray<T6>::type,
12678 typename internal::DecayArray<T7>::type,
12679 typename internal::DecayArray<T8>::type,
12680 typename internal::DecayArray<T9>::type,
12681 typename internal::DecayArray<T10>::type> >
12682 UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
12683 const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9,
12684 const T10& e10) {
12685 typedef std::tr1::tuple<
12686 typename internal::DecayArray<T1>::type,
12687 typename internal::DecayArray<T2>::type,
12688 typename internal::DecayArray<T3>::type,
12689 typename internal::DecayArray<T4>::type,
12690 typename internal::DecayArray<T5>::type,
12691 typename internal::DecayArray<T6>::type,
12692 typename internal::DecayArray<T7>::type,
12693 typename internal::DecayArray<T8>::type,
12694 typename internal::DecayArray<T9>::type,
12695 typename internal::DecayArray<T10>::type> Args;
12696 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5,
12697 e6, e7, e8, e9, e10));
12698 }
12699
12700 // AllOf(m1, m2, ..., mk) matches any value that matches all of the given
12701 // sub-matchers. AllOf is called fully qualified to prevent ADL from firing.
12702
12703 template <typename M1, typename M2>
12704 inline typename internal::AllOfResult2<M1, M2>::type
12705 AllOf(M1 m1, M2 m2) {
12706 return typename internal::AllOfResult2<M1, M2>::type(
12707 m1,
12708 m2);
12709 }
12710
12711 template <typename M1, typename M2, typename M3>
12712 inline typename internal::AllOfResult3<M1, M2, M3>::type
12713 AllOf(M1 m1, M2 m2, M3 m3) {
12714 return typename internal::AllOfResult3<M1, M2, M3>::type(
12715 m1,
12716 ::testing::AllOf(m2, m3));
12717 }
12718
12719 template <typename M1, typename M2, typename M3, typename M4>
12720 inline typename internal::AllOfResult4<M1, M2, M3, M4>::type
12721 AllOf(M1 m1, M2 m2, M3 m3, M4 m4) {
12722 return typename internal::AllOfResult4<M1, M2, M3, M4>::type(
12723 ::testing::AllOf(m1, m2),
12724 ::testing::AllOf(m3, m4));
12725 }
12726
12727 template <typename M1, typename M2, typename M3, typename M4, typename M5>
12728 inline typename internal::AllOfResult5<M1, M2, M3, M4, M5>::type
12729 AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5) {
12730 return typename internal::AllOfResult5<M1, M2, M3, M4, M5>::type(
12731 ::testing::AllOf(m1, m2),
12732 ::testing::AllOf(m3, m4, m5));
12733 }
12734
12735 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12736 typename M6>
12737 inline typename internal::AllOfResult6<M1, M2, M3, M4, M5, M6>::type
12738 AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6) {
12739 return typename internal::AllOfResult6<M1, M2, M3, M4, M5, M6>::type(
12740 ::testing::AllOf(m1, m2, m3),
12741 ::testing::AllOf(m4, m5, m6));
12742 }
12743
12744 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12745 typename M6, typename M7>
12746 inline typename internal::AllOfResult7<M1, M2, M3, M4, M5, M6, M7>::type
12747 AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7) {
12748 return typename internal::AllOfResult7<M1, M2, M3, M4, M5, M6, M7>::type(
12749 ::testing::AllOf(m1, m2, m3),
12750 ::testing::AllOf(m4, m5, m6, m7));
12751 }
12752
12753 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12754 typename M6, typename M7, typename M8>
12755 inline typename internal::AllOfResult8<M1, M2, M3, M4, M5, M6, M7, M8>::type
12756 AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8) {
12757 return typename internal::AllOfResult8<M1, M2, M3, M4, M5, M6, M7, M8>::type(
12758 ::testing::AllOf(m1, m2, m3, m4),
12759 ::testing::AllOf(m5, m6, m7, m8));
12760 }
12761
12762 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12763 typename M6, typename M7, typename M8, typename M9>
12764 inline typename internal::AllOfResult9<M1, M2, M3, M4, M5, M6, M7, M8, M9>::type
12765 AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9) {
12766 return typename internal::AllOfResult9<M1, M2, M3, M4, M5, M6, M7, M8,
12767 M9>::type(
12768 ::testing::AllOf(m1, m2, m3, m4),
12769 ::testing::AllOf(m5, m6, m7, m8, m9));
12770 }
12771
12772 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12773 typename M6, typename M7, typename M8, typename M9, typename M10>
12774 inline typename internal::AllOfResult10<M1, M2, M3, M4, M5, M6, M7, M8, M9,
12775 M10>::type
12776 AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
12777 return typename internal::AllOfResult10<M1, M2, M3, M4, M5, M6, M7, M8, M9,
12778 M10>::type(
12779 ::testing::AllOf(m1, m2, m3, m4, m5),
12780 ::testing::AllOf(m6, m7, m8, m9, m10));
12781 }
12782
12783 // AnyOf(m1, m2, ..., mk) matches any value that matches any of the given
12784 // sub-matchers. AnyOf is called fully qualified to prevent ADL from firing.
12785
12786 template <typename M1, typename M2>
12787 inline typename internal::AnyOfResult2<M1, M2>::type
12788 AnyOf(M1 m1, M2 m2) {
12789 return typename internal::AnyOfResult2<M1, M2>::type(
12790 m1,
12791 m2);
12792 }
12793
12794 template <typename M1, typename M2, typename M3>
12795 inline typename internal::AnyOfResult3<M1, M2, M3>::type
12796 AnyOf(M1 m1, M2 m2, M3 m3) {
12797 return typename internal::AnyOfResult3<M1, M2, M3>::type(
12798 m1,
12799 ::testing::AnyOf(m2, m3));
12800 }
12801
12802 template <typename M1, typename M2, typename M3, typename M4>
12803 inline typename internal::AnyOfResult4<M1, M2, M3, M4>::type
12804 AnyOf(M1 m1, M2 m2, M3 m3, M4 m4) {
12805 return typename internal::AnyOfResult4<M1, M2, M3, M4>::type(
12806 ::testing::AnyOf(m1, m2),
12807 ::testing::AnyOf(m3, m4));
12808 }
12809
12810 template <typename M1, typename M2, typename M3, typename M4, typename M5>
12811 inline typename internal::AnyOfResult5<M1, M2, M3, M4, M5>::type
12812 AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5) {
12813 return typename internal::AnyOfResult5<M1, M2, M3, M4, M5>::type(
12814 ::testing::AnyOf(m1, m2),
12815 ::testing::AnyOf(m3, m4, m5));
12816 }
12817
12818 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12819 typename M6>
12820 inline typename internal::AnyOfResult6<M1, M2, M3, M4, M5, M6>::type
12821 AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6) {
12822 return typename internal::AnyOfResult6<M1, M2, M3, M4, M5, M6>::type(
12823 ::testing::AnyOf(m1, m2, m3),
12824 ::testing::AnyOf(m4, m5, m6));
12825 }
12826
12827 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12828 typename M6, typename M7>
12829 inline typename internal::AnyOfResult7<M1, M2, M3, M4, M5, M6, M7>::type
12830 AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7) {
12831 return typename internal::AnyOfResult7<M1, M2, M3, M4, M5, M6, M7>::type(
12832 ::testing::AnyOf(m1, m2, m3),
12833 ::testing::AnyOf(m4, m5, m6, m7));
12834 }
12835
12836 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12837 typename M6, typename M7, typename M8>
12838 inline typename internal::AnyOfResult8<M1, M2, M3, M4, M5, M6, M7, M8>::type
12839 AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8) {
12840 return typename internal::AnyOfResult8<M1, M2, M3, M4, M5, M6, M7, M8>::type(
12841 ::testing::AnyOf(m1, m2, m3, m4),
12842 ::testing::AnyOf(m5, m6, m7, m8));
12843 }
12844
12845 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12846 typename M6, typename M7, typename M8, typename M9>
12847 inline typename internal::AnyOfResult9<M1, M2, M3, M4, M5, M6, M7, M8, M9>::type
12848 AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9) {
12849 return typename internal::AnyOfResult9<M1, M2, M3, M4, M5, M6, M7, M8,
12850 M9>::type(
12851 ::testing::AnyOf(m1, m2, m3, m4),
12852 ::testing::AnyOf(m5, m6, m7, m8, m9));
12853 }
12854
12855 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12856 typename M6, typename M7, typename M8, typename M9, typename M10>
12857 inline typename internal::AnyOfResult10<M1, M2, M3, M4, M5, M6, M7, M8, M9,
12858 M10>::type
12859 AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
12860 return typename internal::AnyOfResult10<M1, M2, M3, M4, M5, M6, M7, M8, M9,
12861 M10>::type(
12862 ::testing::AnyOf(m1, m2, m3, m4, m5),
12863 ::testing::AnyOf(m6, m7, m8, m9, m10));
12864 }
12865
12866 } // namespace testing
12867
12868
12869 // The MATCHER* family of macros can be used in a namespace scope to
12870 // define custom matchers easily.
12871 //
12872 // Basic Usage
12873 // ===========
12874 //
12875 // The syntax
12876 //
12877 // MATCHER(name, description_string) { statements; }
12878 //
12879 // defines a matcher with the given name that executes the statements,
12880 // which must return a bool to indicate if the match succeeds. Inside
12881 // the statements, you can refer to the value being matched by 'arg',
12882 // and refer to its type by 'arg_type'.
12883 //
12884 // The description string documents what the matcher does, and is used
12885 // to generate the failure message when the match fails. Since a
12886 // MATCHER() is usually defined in a header file shared by multiple
12887 // C++ source files, we require the description to be a C-string
12888 // literal to avoid possible side effects. It can be empty, in which
12889 // case we'll use the sequence of words in the matcher name as the
12890 // description.
12891 //
12892 // For example:
12893 //
12894 // MATCHER(IsEven, "") { return (arg % 2) == 0; }
12895 //
12896 // allows you to write
12897 //
12898 // // Expects mock_foo.Bar(n) to be called where n is even.
12899 // EXPECT_CALL(mock_foo, Bar(IsEven()));
12900 //
12901 // or,
12902 //
12903 // // Verifies that the value of some_expression is even.
12904 // EXPECT_THAT(some_expression, IsEven());
12905 //
12906 // If the above assertion fails, it will print something like:
12907 //
12908 // Value of: some_expression
12909 // Expected: is even
12910 // Actual: 7
12911 //
12912 // where the description "is even" is automatically calculated from the
12913 // matcher name IsEven.
12914 //
12915 // Argument Type
12916 // =============
12917 //
12918 // Note that the type of the value being matched (arg_type) is
12919 // determined by the context in which you use the matcher and is
12920 // supplied to you by the compiler, so you don't need to worry about
12921 // declaring it (nor can you). This allows the matcher to be
12922 // polymorphic. For example, IsEven() can be used to match any type
12923 // where the value of "(arg % 2) == 0" can be implicitly converted to
12924 // a bool. In the "Bar(IsEven())" example above, if method Bar()
12925 // takes an int, 'arg_type' will be int; if it takes an unsigned long,
12926 // 'arg_type' will be unsigned long; and so on.
12927 //
12928 // Parameterizing Matchers
12929 // =======================
12930 //
12931 // Sometimes you'll want to parameterize the matcher. For that you
12932 // can use another macro:
12933 //
12934 // MATCHER_P(name, param_name, description_string) { statements; }
12935 //
12936 // For example:
12937 //
12938 // MATCHER_P(HasAbsoluteValue, value, "") { return abs(arg) == value; }
12939 //
12940 // will allow you to write:
12941 //
12942 // EXPECT_THAT(Blah("a"), HasAbsoluteValue(n));
12943 //
12944 // which may lead to this message (assuming n is 10):
12945 //
12946 // Value of: Blah("a")
12947 // Expected: has absolute value 10
12948 // Actual: -9
12949 //
12950 // Note that both the matcher description and its parameter are
12951 // printed, making the message human-friendly.
12952 //
12953 // In the matcher definition body, you can write 'foo_type' to
12954 // reference the type of a parameter named 'foo'. For example, in the
12955 // body of MATCHER_P(HasAbsoluteValue, value) above, you can write
12956 // 'value_type' to refer to the type of 'value'.
12957 //
12958 // We also provide MATCHER_P2, MATCHER_P3, ..., up to MATCHER_P10 to
12959 // support multi-parameter matchers.
12960 //
12961 // Describing Parameterized Matchers
12962 // =================================
12963 //
12964 // The last argument to MATCHER*() is a string-typed expression. The
12965 // expression can reference all of the matcher's parameters and a
12966 // special bool-typed variable named 'negation'. When 'negation' is
12967 // false, the expression should evaluate to the matcher's description;
12968 // otherwise it should evaluate to the description of the negation of
12969 // the matcher. For example,
12970 //
12971 // using testing::PrintToString;
12972 //
12973 // MATCHER_P2(InClosedRange, low, hi,
12974 // string(negation ? "is not" : "is") + " in range [" +
12975 // PrintToString(low) + ", " + PrintToString(hi) + "]") {
12976 // return low <= arg && arg <= hi;
12977 // }
12978 // ...
12979 // EXPECT_THAT(3, InClosedRange(4, 6));
12980 // EXPECT_THAT(3, Not(InClosedRange(2, 4)));
12981 //
12982 // would generate two failures that contain the text:
12983 //
12984 // Expected: is in range [4, 6]
12985 // ...
12986 // Expected: is not in range [2, 4]
12987 //
12988 // If you specify "" as the description, the failure message will
12989 // contain the sequence of words in the matcher name followed by the
12990 // parameter values printed as a tuple. For example,
12991 //
12992 // MATCHER_P2(InClosedRange, low, hi, "") { ... }
12993 // ...
12994 // EXPECT_THAT(3, InClosedRange(4, 6));
12995 // EXPECT_THAT(3, Not(InClosedRange(2, 4)));
12996 //
12997 // would generate two failures that contain the text:
12998 //
12999 // Expected: in closed range (4, 6)
13000 // ...
13001 // Expected: not (in closed range (2, 4))
13002 //
13003 // Types of Matcher Parameters
13004 // ===========================
13005 //
13006 // For the purpose of typing, you can view
13007 //
13008 // MATCHER_Pk(Foo, p1, ..., pk, description_string) { ... }
13009 //
13010 // as shorthand for
13011 //
13012 // template <typename p1_type, ..., typename pk_type>
13013 // FooMatcherPk<p1_type, ..., pk_type>
13014 // Foo(p1_type p1, ..., pk_type pk) { ... }
13015 //
13016 // When you write Foo(v1, ..., vk), the compiler infers the types of
13017 // the parameters v1, ..., and vk for you. If you are not happy with
13018 // the result of the type inference, you can specify the types by
13019 // explicitly instantiating the template, as in Foo<long, bool>(5,
13020 // false). As said earlier, you don't get to (or need to) specify
13021 // 'arg_type' as that's determined by the context in which the matcher
13022 // is used. You can assign the result of expression Foo(p1, ..., pk)
13023 // to a variable of type FooMatcherPk<p1_type, ..., pk_type>. This
13024 // can be useful when composing matchers.
13025 //
13026 // While you can instantiate a matcher template with reference types,
13027 // passing the parameters by pointer usually makes your code more
13028 // readable. If, however, you still want to pass a parameter by
13029 // reference, be aware that in the failure message generated by the
13030 // matcher you will see the value of the referenced object but not its
13031 // address.
13032 //
13033 // Explaining Match Results
13034 // ========================
13035 //
13036 // Sometimes the matcher description alone isn't enough to explain why
13037 // the match has failed or succeeded. For example, when expecting a
13038 // long string, it can be very helpful to also print the diff between
13039 // the expected string and the actual one. To achieve that, you can
13040 // optionally stream additional information to a special variable
13041 // named result_listener, whose type is a pointer to class
13042 // MatchResultListener:
13043 //
13044 // MATCHER_P(EqualsLongString, str, "") {
13045 // if (arg == str) return true;
13046 //
13047 // *result_listener << "the difference: "
13048 /// << DiffStrings(str, arg);
13049 // return false;
13050 // }
13051 //
13052 // Overloading Matchers
13053 // ====================
13054 //
13055 // You can overload matchers with different numbers of parameters:
13056 //
13057 // MATCHER_P(Blah, a, description_string1) { ... }
13058 // MATCHER_P2(Blah, a, b, description_string2) { ... }
13059 //
13060 // Caveats
13061 // =======
13062 //
13063 // When defining a new matcher, you should also consider implementing
13064 // MatcherInterface or using MakePolymorphicMatcher(). These
13065 // approaches require more work than the MATCHER* macros, but also
13066 // give you more control on the types of the value being matched and
13067 // the matcher parameters, which may leads to better compiler error
13068 // messages when the matcher is used wrong. They also allow
13069 // overloading matchers based on parameter types (as opposed to just
13070 // based on the number of parameters).
13071 //
13072 // MATCHER*() can only be used in a namespace scope. The reason is
13073 // that C++ doesn't yet allow function-local types to be used to
13074 // instantiate templates. The up-coming C++0x standard will fix this.
13075 // Once that's done, we'll consider supporting using MATCHER*() inside
13076 // a function.
13077 //
13078 // More Information
13079 // ================
13080 //
13081 // To learn more about using these macros, please search for 'MATCHER'
13082 // on http://code.google.com/p/googlemock/wiki/CookBook.
13083
13084 #define MATCHER(name, description)\
13085 class name##Matcher {\
13086 public:\
13087 template <typename arg_type>\
13088 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13089 public:\
13090 gmock_Impl()\
13091 {}\
13092 virtual bool MatchAndExplain(\
13093 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13094 virtual void DescribeTo(::std::ostream* gmock_os) const {\
13095 *gmock_os << FormatDescription(false);\
13096 }\
13097 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13098 *gmock_os << FormatDescription(true);\
13099 }\
13100 private:\
13101 ::testing::internal::string FormatDescription(bool negation) const {\
13102 const ::testing::internal::string gmock_description = (description);\
13103 if (!gmock_description.empty())\
13104 return gmock_description;\
13105 return ::testing::internal::FormatMatcherDescription(\
13106 negation, #name, \
13107 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13108 ::std::tr1::tuple<>()));\
13109 }\
13110 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13111 };\
13112 template <typename arg_type>\
13113 operator ::testing::Matcher<arg_type>() const {\
13114 return ::testing::Matcher<arg_type>(\
13115 new gmock_Impl<arg_type>());\
13116 }\
13117 name##Matcher() {\
13118 }\
13119 private:\
13120 GTEST_DISALLOW_ASSIGN_(name##Matcher);\
13121 };\
13122 inline name##Matcher name() {\
13123 return name##Matcher();\
13124 }\
13125 template <typename arg_type>\
13126 bool name##Matcher::gmock_Impl<arg_type>::MatchAndExplain(\
13127 arg_type arg, \
13128 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13129 const
13130
13131 #define MATCHER_P(name, p0, description)\
13132 template <typename p0##_type>\
13133 class name##MatcherP {\
13134 public:\
13135 template <typename arg_type>\
13136 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13137 public:\
13138 explicit gmock_Impl(p0##_type gmock_p0)\
13139 : p0(gmock_p0) {}\
13140 virtual bool MatchAndExplain(\
13141 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13142 virtual void DescribeTo(::std::ostream* gmock_os) const {\
13143 *gmock_os << FormatDescription(false);\
13144 }\
13145 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13146 *gmock_os << FormatDescription(true);\
13147 }\
13148 p0##_type p0;\
13149 private:\
13150 ::testing::internal::string FormatDescription(bool negation) const {\
13151 const ::testing::internal::string gmock_description = (description);\
13152 if (!gmock_description.empty())\
13153 return gmock_description;\
13154 return ::testing::internal::FormatMatcherDescription(\
13155 negation, #name, \
13156 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13157 ::std::tr1::tuple<p0##_type>(p0)));\
13158 }\
13159 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13160 };\
13161 template <typename arg_type>\
13162 operator ::testing::Matcher<arg_type>() const {\
13163 return ::testing::Matcher<arg_type>(\
13164 new gmock_Impl<arg_type>(p0));\
13165 }\
13166 name##MatcherP(p0##_type gmock_p0) : p0(gmock_p0) {\
13167 }\
13168 p0##_type p0;\
13169 private:\
13170 GTEST_DISALLOW_ASSIGN_(name##MatcherP);\
13171 };\
13172 template <typename p0##_type>\
13173 inline name##MatcherP<p0##_type> name(p0##_type p0) {\
13174 return name##MatcherP<p0##_type>(p0);\
13175 }\
13176 template <typename p0##_type>\
13177 template <typename arg_type>\
13178 bool name##MatcherP<p0##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
13179 arg_type arg, \
13180 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13181 const
13182
13183 #define MATCHER_P2(name, p0, p1, description)\
13184 template <typename p0##_type, typename p1##_type>\
13185 class name##MatcherP2 {\
13186 public:\
13187 template <typename arg_type>\
13188 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13189 public:\
13190 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1)\
13191 : p0(gmock_p0), p1(gmock_p1) {}\
13192 virtual bool MatchAndExplain(\
13193 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13194 virtual void DescribeTo(::std::ostream* gmock_os) const {\
13195 *gmock_os << FormatDescription(false);\
13196 }\
13197 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13198 *gmock_os << FormatDescription(true);\
13199 }\
13200 p0##_type p0;\
13201 p1##_type p1;\
13202 private:\
13203 ::testing::internal::string FormatDescription(bool negation) const {\
13204 const ::testing::internal::string gmock_description = (description);\
13205 if (!gmock_description.empty())\
13206 return gmock_description;\
13207 return ::testing::internal::FormatMatcherDescription(\
13208 negation, #name, \
13209 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13210 ::std::tr1::tuple<p0##_type, p1##_type>(p0, p1)));\
13211 }\
13212 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13213 };\
13214 template <typename arg_type>\
13215 operator ::testing::Matcher<arg_type>() const {\
13216 return ::testing::Matcher<arg_type>(\
13217 new gmock_Impl<arg_type>(p0, p1));\
13218 }\
13219 name##MatcherP2(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \
13220 p1(gmock_p1) {\
13221 }\
13222 p0##_type p0;\
13223 p1##_type p1;\
13224 private:\
13225 GTEST_DISALLOW_ASSIGN_(name##MatcherP2);\
13226 };\
13227 template <typename p0##_type, typename p1##_type>\
13228 inline name##MatcherP2<p0##_type, p1##_type> name(p0##_type p0, \
13229 p1##_type p1) {\
13230 return name##MatcherP2<p0##_type, p1##_type>(p0, p1);\
13231 }\
13232 template <typename p0##_type, typename p1##_type>\
13233 template <typename arg_type>\
13234 bool name##MatcherP2<p0##_type, \
13235 p1##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
13236 arg_type arg, \
13237 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13238 const
13239
13240 #define MATCHER_P3(name, p0, p1, p2, description)\
13241 template <typename p0##_type, typename p1##_type, typename p2##_type>\
13242 class name##MatcherP3 {\
13243 public:\
13244 template <typename arg_type>\
13245 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13246 public:\
13247 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2)\
13248 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\
13249 virtual bool MatchAndExplain(\
13250 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13251 virtual void DescribeTo(::std::ostream* gmock_os) const {\
13252 *gmock_os << FormatDescription(false);\
13253 }\
13254 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13255 *gmock_os << FormatDescription(true);\
13256 }\
13257 p0##_type p0;\
13258 p1##_type p1;\
13259 p2##_type p2;\
13260 private:\
13261 ::testing::internal::string FormatDescription(bool negation) const {\
13262 const ::testing::internal::string gmock_description = (description);\
13263 if (!gmock_description.empty())\
13264 return gmock_description;\
13265 return ::testing::internal::FormatMatcherDescription(\
13266 negation, #name, \
13267 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13268 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type>(p0, p1, \
13269 p2)));\
13270 }\
13271 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13272 };\
13273 template <typename arg_type>\
13274 operator ::testing::Matcher<arg_type>() const {\
13275 return ::testing::Matcher<arg_type>(\
13276 new gmock_Impl<arg_type>(p0, p1, p2));\
13277 }\
13278 name##MatcherP3(p0##_type gmock_p0, p1##_type gmock_p1, \
13279 p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {\
13280 }\
13281 p0##_type p0;\
13282 p1##_type p1;\
13283 p2##_type p2;\
13284 private:\
13285 GTEST_DISALLOW_ASSIGN_(name##MatcherP3);\
13286 };\
13287 template <typename p0##_type, typename p1##_type, typename p2##_type>\
13288 inline name##MatcherP3<p0##_type, p1##_type, p2##_type> name(p0##_type p0, \
13289 p1##_type p1, p2##_type p2) {\
13290 return name##MatcherP3<p0##_type, p1##_type, p2##_type>(p0, p1, p2);\
13291 }\
13292 template <typename p0##_type, typename p1##_type, typename p2##_type>\
13293 template <typename arg_type>\
13294 bool name##MatcherP3<p0##_type, p1##_type, \
13295 p2##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
13296 arg_type arg, \
13297 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13298 const
13299
13300 #define MATCHER_P4(name, p0, p1, p2, p3, description)\
13301 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13302 typename p3##_type>\
13303 class name##MatcherP4 {\
13304 public:\
13305 template <typename arg_type>\
13306 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13307 public:\
13308 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
13309 p3##_type gmock_p3)\
13310 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3) {}\
13311 virtual bool MatchAndExplain(\
13312 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13313 virtual void DescribeTo(::std::ostream* gmock_os) const {\
13314 *gmock_os << FormatDescription(false);\
13315 }\
13316 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13317 *gmock_os << FormatDescription(true);\
13318 }\
13319 p0##_type p0;\
13320 p1##_type p1;\
13321 p2##_type p2;\
13322 p3##_type p3;\
13323 private:\
13324 ::testing::internal::string FormatDescription(bool negation) const {\
13325 const ::testing::internal::string gmock_description = (description);\
13326 if (!gmock_description.empty())\
13327 return gmock_description;\
13328 return ::testing::internal::FormatMatcherDescription(\
13329 negation, #name, \
13330 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13331 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, \
13332 p3##_type>(p0, p1, p2, p3)));\
13333 }\
13334 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13335 };\
13336 template <typename arg_type>\
13337 operator ::testing::Matcher<arg_type>() const {\
13338 return ::testing::Matcher<arg_type>(\
13339 new gmock_Impl<arg_type>(p0, p1, p2, p3));\
13340 }\
13341 name##MatcherP4(p0##_type gmock_p0, p1##_type gmock_p1, \
13342 p2##_type gmock_p2, p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), \
13343 p2(gmock_p2), p3(gmock_p3) {\
13344 }\
13345 p0##_type p0;\
13346 p1##_type p1;\
13347 p2##_type p2;\
13348 p3##_type p3;\
13349 private:\
13350 GTEST_DISALLOW_ASSIGN_(name##MatcherP4);\
13351 };\
13352 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13353 typename p3##_type>\
13354 inline name##MatcherP4<p0##_type, p1##_type, p2##_type, \
13355 p3##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
13356 p3##_type p3) {\
13357 return name##MatcherP4<p0##_type, p1##_type, p2##_type, p3##_type>(p0, \
13358 p1, p2, p3);\
13359 }\
13360 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13361 typename p3##_type>\
13362 template <typename arg_type>\
13363 bool name##MatcherP4<p0##_type, p1##_type, p2##_type, \
13364 p3##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
13365 arg_type arg, \
13366 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13367 const
13368
13369 #define MATCHER_P5(name, p0, p1, p2, p3, p4, description)\
13370 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13371 typename p3##_type, typename p4##_type>\
13372 class name##MatcherP5 {\
13373 public:\
13374 template <typename arg_type>\
13375 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13376 public:\
13377 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
13378 p3##_type gmock_p3, p4##_type gmock_p4)\
13379 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
13380 p4(gmock_p4) {}\
13381 virtual bool MatchAndExplain(\
13382 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13383 virtual void DescribeTo(::std::ostream* gmock_os) const {\
13384 *gmock_os << FormatDescription(false);\
13385 }\
13386 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13387 *gmock_os << FormatDescription(true);\
13388 }\
13389 p0##_type p0;\
13390 p1##_type p1;\
13391 p2##_type p2;\
13392 p3##_type p3;\
13393 p4##_type p4;\
13394 private:\
13395 ::testing::internal::string FormatDescription(bool negation) const {\
13396 const ::testing::internal::string gmock_description = (description);\
13397 if (!gmock_description.empty())\
13398 return gmock_description;\
13399 return ::testing::internal::FormatMatcherDescription(\
13400 negation, #name, \
13401 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13402 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
13403 p4##_type>(p0, p1, p2, p3, p4)));\
13404 }\
13405 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13406 };\
13407 template <typename arg_type>\
13408 operator ::testing::Matcher<arg_type>() const {\
13409 return ::testing::Matcher<arg_type>(\
13410 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4));\
13411 }\
13412 name##MatcherP5(p0##_type gmock_p0, p1##_type gmock_p1, \
13413 p2##_type gmock_p2, p3##_type gmock_p3, \
13414 p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
13415 p3(gmock_p3), p4(gmock_p4) {\
13416 }\
13417 p0##_type p0;\
13418 p1##_type p1;\
13419 p2##_type p2;\
13420 p3##_type p3;\
13421 p4##_type p4;\
13422 private:\
13423 GTEST_DISALLOW_ASSIGN_(name##MatcherP5);\
13424 };\
13425 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13426 typename p3##_type, typename p4##_type>\
13427 inline name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \
13428 p4##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
13429 p4##_type p4) {\
13430 return name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \
13431 p4##_type>(p0, p1, p2, p3, p4);\
13432 }\
13433 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13434 typename p3##_type, typename p4##_type>\
13435 template <typename arg_type>\
13436 bool name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \
13437 p4##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
13438 arg_type arg, \
13439 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13440 const
13441
13442 #define MATCHER_P6(name, p0, p1, p2, p3, p4, p5, description)\
13443 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13444 typename p3##_type, typename p4##_type, typename p5##_type>\
13445 class name##MatcherP6 {\
13446 public:\
13447 template <typename arg_type>\
13448 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13449 public:\
13450 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
13451 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5)\
13452 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
13453 p4(gmock_p4), p5(gmock_p5) {}\
13454 virtual bool MatchAndExplain(\
13455 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13456 virtual void DescribeTo(::std::ostream* gmock_os) const {\
13457 *gmock_os << FormatDescription(false);\
13458 }\
13459 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13460 *gmock_os << FormatDescription(true);\
13461 }\
13462 p0##_type p0;\
13463 p1##_type p1;\
13464 p2##_type p2;\
13465 p3##_type p3;\
13466 p4##_type p4;\
13467 p5##_type p5;\
13468 private:\
13469 ::testing::internal::string FormatDescription(bool negation) const {\
13470 const ::testing::internal::string gmock_description = (description);\
13471 if (!gmock_description.empty())\
13472 return gmock_description;\
13473 return ::testing::internal::FormatMatcherDescription(\
13474 negation, #name, \
13475 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13476 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
13477 p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5)));\
13478 }\
13479 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13480 };\
13481 template <typename arg_type>\
13482 operator ::testing::Matcher<arg_type>() const {\
13483 return ::testing::Matcher<arg_type>(\
13484 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5));\
13485 }\
13486 name##MatcherP6(p0##_type gmock_p0, p1##_type gmock_p1, \
13487 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
13488 p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
13489 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {\
13490 }\
13491 p0##_type p0;\
13492 p1##_type p1;\
13493 p2##_type p2;\
13494 p3##_type p3;\
13495 p4##_type p4;\
13496 p5##_type p5;\
13497 private:\
13498 GTEST_DISALLOW_ASSIGN_(name##MatcherP6);\
13499 };\
13500 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13501 typename p3##_type, typename p4##_type, typename p5##_type>\
13502 inline name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, \
13503 p4##_type, p5##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
13504 p3##_type p3, p4##_type p4, p5##_type p5) {\
13505 return name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, \
13506 p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5);\
13507 }\
13508 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13509 typename p3##_type, typename p4##_type, typename p5##_type>\
13510 template <typename arg_type>\
13511 bool name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
13512 p5##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
13513 arg_type arg, \
13514 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13515 const
13516
13517 #define MATCHER_P7(name, p0, p1, p2, p3, p4, p5, p6, description)\
13518 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13519 typename p3##_type, typename p4##_type, typename p5##_type, \
13520 typename p6##_type>\
13521 class name##MatcherP7 {\
13522 public:\
13523 template <typename arg_type>\
13524 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13525 public:\
13526 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
13527 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
13528 p6##_type gmock_p6)\
13529 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
13530 p4(gmock_p4), p5(gmock_p5), p6(gmock_p6) {}\
13531 virtual bool MatchAndExplain(\
13532 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13533 virtual void DescribeTo(::std::ostream* gmock_os) const {\
13534 *gmock_os << FormatDescription(false);\
13535 }\
13536 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13537 *gmock_os << FormatDescription(true);\
13538 }\
13539 p0##_type p0;\
13540 p1##_type p1;\
13541 p2##_type p2;\
13542 p3##_type p3;\
13543 p4##_type p4;\
13544 p5##_type p5;\
13545 p6##_type p6;\
13546 private:\
13547 ::testing::internal::string FormatDescription(bool negation) const {\
13548 const ::testing::internal::string gmock_description = (description);\
13549 if (!gmock_description.empty())\
13550 return gmock_description;\
13551 return ::testing::internal::FormatMatcherDescription(\
13552 negation, #name, \
13553 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13554 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
13555 p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, \
13556 p6)));\
13557 }\
13558 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13559 };\
13560 template <typename arg_type>\
13561 operator ::testing::Matcher<arg_type>() const {\
13562 return ::testing::Matcher<arg_type>(\
13563 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6));\
13564 }\
13565 name##MatcherP7(p0##_type gmock_p0, p1##_type gmock_p1, \
13566 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
13567 p5##_type gmock_p5, p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), \
13568 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), \
13569 p6(gmock_p6) {\
13570 }\
13571 p0##_type p0;\
13572 p1##_type p1;\
13573 p2##_type p2;\
13574 p3##_type p3;\
13575 p4##_type p4;\
13576 p5##_type p5;\
13577 p6##_type p6;\
13578 private:\
13579 GTEST_DISALLOW_ASSIGN_(name##MatcherP7);\
13580 };\
13581 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13582 typename p3##_type, typename p4##_type, typename p5##_type, \
13583 typename p6##_type>\
13584 inline name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, \
13585 p4##_type, p5##_type, p6##_type> name(p0##_type p0, p1##_type p1, \
13586 p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
13587 p6##_type p6) {\
13588 return name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, \
13589 p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, p6);\
13590 }\
13591 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13592 typename p3##_type, typename p4##_type, typename p5##_type, \
13593 typename p6##_type>\
13594 template <typename arg_type>\
13595 bool name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
13596 p5##_type, p6##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
13597 arg_type arg, \
13598 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13599 const
13600
13601 #define MATCHER_P8(name, p0, p1, p2, p3, p4, p5, p6, p7, description)\
13602 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13603 typename p3##_type, typename p4##_type, typename p5##_type, \
13604 typename p6##_type, typename p7##_type>\
13605 class name##MatcherP8 {\
13606 public:\
13607 template <typename arg_type>\
13608 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13609 public:\
13610 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
13611 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
13612 p6##_type gmock_p6, p7##_type gmock_p7)\
13613 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
13614 p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7) {}\
13615 virtual bool MatchAndExplain(\
13616 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13617 virtual void DescribeTo(::std::ostream* gmock_os) const {\
13618 *gmock_os << FormatDescription(false);\
13619 }\
13620 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13621 *gmock_os << FormatDescription(true);\
13622 }\
13623 p0##_type p0;\
13624 p1##_type p1;\
13625 p2##_type p2;\
13626 p3##_type p3;\
13627 p4##_type p4;\
13628 p5##_type p5;\
13629 p6##_type p6;\
13630 p7##_type p7;\
13631 private:\
13632 ::testing::internal::string FormatDescription(bool negation) const {\
13633 const ::testing::internal::string gmock_description = (description);\
13634 if (!gmock_description.empty())\
13635 return gmock_description;\
13636 return ::testing::internal::FormatMatcherDescription(\
13637 negation, #name, \
13638 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13639 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
13640 p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, \
13641 p3, p4, p5, p6, p7)));\
13642 }\
13643 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13644 };\
13645 template <typename arg_type>\
13646 operator ::testing::Matcher<arg_type>() const {\
13647 return ::testing::Matcher<arg_type>(\
13648 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7));\
13649 }\
13650 name##MatcherP8(p0##_type gmock_p0, p1##_type gmock_p1, \
13651 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
13652 p5##_type gmock_p5, p6##_type gmock_p6, \
13653 p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
13654 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
13655 p7(gmock_p7) {\
13656 }\
13657 p0##_type p0;\
13658 p1##_type p1;\
13659 p2##_type p2;\
13660 p3##_type p3;\
13661 p4##_type p4;\
13662 p5##_type p5;\
13663 p6##_type p6;\
13664 p7##_type p7;\
13665 private:\
13666 GTEST_DISALLOW_ASSIGN_(name##MatcherP8);\
13667 };\
13668 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13669 typename p3##_type, typename p4##_type, typename p5##_type, \
13670 typename p6##_type, typename p7##_type>\
13671 inline name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, \
13672 p4##_type, p5##_type, p6##_type, p7##_type> name(p0##_type p0, \
13673 p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
13674 p6##_type p6, p7##_type p7) {\
13675 return name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, \
13676 p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, p3, p4, p5, \
13677 p6, p7);\
13678 }\
13679 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13680 typename p3##_type, typename p4##_type, typename p5##_type, \
13681 typename p6##_type, typename p7##_type>\
13682 template <typename arg_type>\
13683 bool name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
13684 p5##_type, p6##_type, \
13685 p7##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
13686 arg_type arg, \
13687 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13688 const
13689
13690 #define MATCHER_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, description)\
13691 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13692 typename p3##_type, typename p4##_type, typename p5##_type, \
13693 typename p6##_type, typename p7##_type, typename p8##_type>\
13694 class name##MatcherP9 {\
13695 public:\
13696 template <typename arg_type>\
13697 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13698 public:\
13699 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
13700 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
13701 p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8)\
13702 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
13703 p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
13704 p8(gmock_p8) {}\
13705 virtual bool MatchAndExplain(\
13706 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13707 virtual void DescribeTo(::std::ostream* gmock_os) const {\
13708 *gmock_os << FormatDescription(false);\
13709 }\
13710 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13711 *gmock_os << FormatDescription(true);\
13712 }\
13713 p0##_type p0;\
13714 p1##_type p1;\
13715 p2##_type p2;\
13716 p3##_type p3;\
13717 p4##_type p4;\
13718 p5##_type p5;\
13719 p6##_type p6;\
13720 p7##_type p7;\
13721 p8##_type p8;\
13722 private:\
13723 ::testing::internal::string FormatDescription(bool negation) const {\
13724 const ::testing::internal::string gmock_description = (description);\
13725 if (!gmock_description.empty())\
13726 return gmock_description;\
13727 return ::testing::internal::FormatMatcherDescription(\
13728 negation, #name, \
13729 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13730 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
13731 p4##_type, p5##_type, p6##_type, p7##_type, \
13732 p8##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8)));\
13733 }\
13734 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13735 };\
13736 template <typename arg_type>\
13737 operator ::testing::Matcher<arg_type>() const {\
13738 return ::testing::Matcher<arg_type>(\
13739 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8));\
13740 }\
13741 name##MatcherP9(p0##_type gmock_p0, p1##_type gmock_p1, \
13742 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
13743 p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
13744 p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
13745 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
13746 p8(gmock_p8) {\
13747 }\
13748 p0##_type p0;\
13749 p1##_type p1;\
13750 p2##_type p2;\
13751 p3##_type p3;\
13752 p4##_type p4;\
13753 p5##_type p5;\
13754 p6##_type p6;\
13755 p7##_type p7;\
13756 p8##_type p8;\
13757 private:\
13758 GTEST_DISALLOW_ASSIGN_(name##MatcherP9);\
13759 };\
13760 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13761 typename p3##_type, typename p4##_type, typename p5##_type, \
13762 typename p6##_type, typename p7##_type, typename p8##_type>\
13763 inline name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, \
13764 p4##_type, p5##_type, p6##_type, p7##_type, \
13765 p8##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
13766 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, \
13767 p8##_type p8) {\
13768 return name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, \
13769 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type>(p0, p1, p2, \
13770 p3, p4, p5, p6, p7, p8);\
13771 }\
13772 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13773 typename p3##_type, typename p4##_type, typename p5##_type, \
13774 typename p6##_type, typename p7##_type, typename p8##_type>\
13775 template <typename arg_type>\
13776 bool name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
13777 p5##_type, p6##_type, p7##_type, \
13778 p8##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
13779 arg_type arg, \
13780 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13781 const
13782
13783 #define MATCHER_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, description)\
13784 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13785 typename p3##_type, typename p4##_type, typename p5##_type, \
13786 typename p6##_type, typename p7##_type, typename p8##_type, \
13787 typename p9##_type>\
13788 class name##MatcherP10 {\
13789 public:\
13790 template <typename arg_type>\
13791 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13792 public:\
13793 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
13794 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
13795 p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
13796 p9##_type gmock_p9)\
13797 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
13798 p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
13799 p8(gmock_p8), p9(gmock_p9) {}\
13800 virtual bool MatchAndExplain(\
13801 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13802 virtual void DescribeTo(::std::ostream* gmock_os) const {\
13803 *gmock_os << FormatDescription(false);\
13804 }\
13805 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13806 *gmock_os << FormatDescription(true);\
13807 }\
13808 p0##_type p0;\
13809 p1##_type p1;\
13810 p2##_type p2;\
13811 p3##_type p3;\
13812 p4##_type p4;\
13813 p5##_type p5;\
13814 p6##_type p6;\
13815 p7##_type p7;\
13816 p8##_type p8;\
13817 p9##_type p9;\
13818 private:\
13819 ::testing::internal::string FormatDescription(bool negation) const {\
13820 const ::testing::internal::string gmock_description = (description);\
13821 if (!gmock_description.empty())\
13822 return gmock_description;\
13823 return ::testing::internal::FormatMatcherDescription(\
13824 negation, #name, \
13825 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13826 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
13827 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
13828 p9##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)));\
13829 }\
13830 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13831 };\
13832 template <typename arg_type>\
13833 operator ::testing::Matcher<arg_type>() const {\
13834 return ::testing::Matcher<arg_type>(\
13835 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9));\
13836 }\
13837 name##MatcherP10(p0##_type gmock_p0, p1##_type gmock_p1, \
13838 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
13839 p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
13840 p8##_type gmock_p8, p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), \
13841 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
13842 p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {\
13843 }\
13844 p0##_type p0;\
13845 p1##_type p1;\
13846 p2##_type p2;\
13847 p3##_type p3;\
13848 p4##_type p4;\
13849 p5##_type p5;\
13850 p6##_type p6;\
13851 p7##_type p7;\
13852 p8##_type p8;\
13853 p9##_type p9;\
13854 private:\
13855 GTEST_DISALLOW_ASSIGN_(name##MatcherP10);\
13856 };\
13857 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13858 typename p3##_type, typename p4##_type, typename p5##_type, \
13859 typename p6##_type, typename p7##_type, typename p8##_type, \
13860 typename p9##_type>\
13861 inline name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \
13862 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
13863 p9##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
13864 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \
13865 p9##_type p9) {\
13866 return name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \
13867 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, p9##_type>(p0, \
13868 p1, p2, p3, p4, p5, p6, p7, p8, p9);\
13869 }\
13870 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13871 typename p3##_type, typename p4##_type, typename p5##_type, \
13872 typename p6##_type, typename p7##_type, typename p8##_type, \
13873 typename p9##_type>\
13874 template <typename arg_type>\
13875 bool name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \
13876 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
13877 p9##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
13878 arg_type arg, \
13879 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13880 const
13881
13882 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
13883 // Copyright 2007, Google Inc.
13884 // All rights reserved.
13885 //
13886 // Redistribution and use in source and binary forms, with or without
13887 // modification, are permitted provided that the following conditions are
13888 // met:
13889 //
13890 // * Redistributions of source code must retain the above copyright
13891 // notice, this list of conditions and the following disclaimer.
13892 // * Redistributions in binary form must reproduce the above
13893 // copyright notice, this list of conditions and the following disclaimer
13894 // in the documentation and/or other materials provided with the
13895 // distribution.
13896 // * Neither the name of Google Inc. nor the names of its
13897 // contributors may be used to endorse or promote products derived from
13898 // this software without specific prior written permission.
13899 //
13900 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13901 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
13902 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
13903 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
13904 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
13905 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
13906 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
13907 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13908 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13909 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13910 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13911 //
13912 // Author: [email protected] (Zhanyong Wan)
13913
13914 // Google Mock - a framework for writing C++ mock classes.
13915 //
13916 // This file implements some actions that depend on gmock-generated-actions.h.
13917
13918 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
13919 #define GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
13920
13921 #include <algorithm>
13922
13923
13924 namespace testing {
13925 namespace internal {
13926
13927 // Implements the Invoke(f) action. The template argument
13928 // FunctionImpl is the implementation type of f, which can be either a
13929 // function pointer or a functor. Invoke(f) can be used as an
13930 // Action<F> as long as f's type is compatible with F (i.e. f can be
13931 // assigned to a tr1::function<F>).
13932 template <typename FunctionImpl>
13933 class InvokeAction {
13934 public:
13935 // The c'tor makes a copy of function_impl (either a function
13936 // pointer or a functor).
13937 explicit InvokeAction(FunctionImpl function_impl)
13938 : function_impl_(function_impl) {}
13939
13940 template <typename Result, typename ArgumentTuple>
13941 Result Perform(const ArgumentTuple& args) {
13942 return InvokeHelper<Result, ArgumentTuple>::Invoke(function_impl_, args);
13943 }
13944
13945 private:
13946 FunctionImpl function_impl_;
13947
13948 GTEST_DISALLOW_ASSIGN_(InvokeAction);
13949 };
13950
13951 // Implements the Invoke(object_ptr, &Class::Method) action.
13952 template <class Class, typename MethodPtr>
13953 class InvokeMethodAction {
13954 public:
13955 InvokeMethodAction(Class* obj_ptr, MethodPtr method_ptr)
13956 : obj_ptr_(obj_ptr), method_ptr_(method_ptr) {}
13957
13958 template <typename Result, typename ArgumentTuple>
13959 Result Perform(const ArgumentTuple& args) const {
13960 return InvokeHelper<Result, ArgumentTuple>::InvokeMethod(
13961 obj_ptr_, method_ptr_, args);
13962 }
13963
13964 private:
13965 Class* const obj_ptr_;
13966 const MethodPtr method_ptr_;
13967
13968 GTEST_DISALLOW_ASSIGN_(InvokeMethodAction);
13969 };
13970
13971 } // namespace internal
13972
13973 // Various overloads for Invoke().
13974
13975 // Creates an action that invokes 'function_impl' with the mock
13976 // function's arguments.
13977 template <typename FunctionImpl>
13978 PolymorphicAction<internal::InvokeAction<FunctionImpl> > Invoke(
13979 FunctionImpl function_impl) {
13980 return MakePolymorphicAction(
13981 internal::InvokeAction<FunctionImpl>(function_impl));
13982 }
13983
13984 // Creates an action that invokes the given method on the given object
13985 // with the mock function's arguments.
13986 template <class Class, typename MethodPtr>
13987 PolymorphicAction<internal::InvokeMethodAction<Class, MethodPtr> > Invoke(
13988 Class* obj_ptr, MethodPtr method_ptr) {
13989 return MakePolymorphicAction(
13990 internal::InvokeMethodAction<Class, MethodPtr>(obj_ptr, method_ptr));
13991 }
13992
13993 // WithoutArgs(inner_action) can be used in a mock function with a
13994 // non-empty argument list to perform inner_action, which takes no
13995 // argument. In other words, it adapts an action accepting no
13996 // argument to one that accepts (and ignores) arguments.
13997 template <typename InnerAction>
13998 inline internal::WithArgsAction<InnerAction>
13999 WithoutArgs(const InnerAction& action) {
14000 return internal::WithArgsAction<InnerAction>(action);
14001 }
14002
14003 // WithArg<k>(an_action) creates an action that passes the k-th
14004 // (0-based) argument of the mock function to an_action and performs
14005 // it. It adapts an action accepting one argument to one that accepts
14006 // multiple arguments. For convenience, we also provide
14007 // WithArgs<k>(an_action) (defined below) as a synonym.
14008 template <int k, typename InnerAction>
14009 inline internal::WithArgsAction<InnerAction, k>
14010 WithArg(const InnerAction& action) {
14011 return internal::WithArgsAction<InnerAction, k>(action);
14012 }
14013
14014 // The ACTION*() macros trigger warning C4100 (unreferenced formal
14015 // parameter) in MSVC with -W4. Unfortunately they cannot be fixed in
14016 // the macro definition, as the warnings are generated when the macro
14017 // is expanded and macro expansion cannot contain #pragma. Therefore
14018 // we suppress them here.
14019 #ifdef _MSC_VER
14020 # pragma warning(push)
14021 # pragma warning(disable:4100)
14022 #endif
14023
14024 // Action ReturnArg<k>() returns the k-th argument of the mock function.
14025 ACTION_TEMPLATE(ReturnArg,
14026 HAS_1_TEMPLATE_PARAMS(int, k),
14027 AND_0_VALUE_PARAMS()) {
14028 return std::tr1::get<k>(args);
14029 }
14030
14031 // Action SaveArg<k>(pointer) saves the k-th (0-based) argument of the
14032 // mock function to *pointer.
14033 ACTION_TEMPLATE(SaveArg,
14034 HAS_1_TEMPLATE_PARAMS(int, k),
14035 AND_1_VALUE_PARAMS(pointer)) {
14036 *pointer = ::std::tr1::get<k>(args);
14037 }
14038
14039 // Action SaveArgPointee<k>(pointer) saves the value pointed to
14040 // by the k-th (0-based) argument of the mock function to *pointer.
14041 ACTION_TEMPLATE(SaveArgPointee,
14042 HAS_1_TEMPLATE_PARAMS(int, k),
14043 AND_1_VALUE_PARAMS(pointer)) {
14044 *pointer = *::std::tr1::get<k>(args);
14045 }
14046
14047 // Action SetArgReferee<k>(value) assigns 'value' to the variable
14048 // referenced by the k-th (0-based) argument of the mock function.
14049 ACTION_TEMPLATE(SetArgReferee,
14050 HAS_1_TEMPLATE_PARAMS(int, k),
14051 AND_1_VALUE_PARAMS(value)) {
14052 typedef typename ::std::tr1::tuple_element<k, args_type>::type argk_type;
14053 // Ensures that argument #k is a reference. If you get a compiler
14054 // error on the next line, you are using SetArgReferee<k>(value) in
14055 // a mock function whose k-th (0-based) argument is not a reference.
14056 GTEST_COMPILE_ASSERT_(internal::is_reference<argk_type>::value,
14057 SetArgReferee_must_be_used_with_a_reference_argument);
14058 ::std::tr1::get<k>(args) = value;
14059 }
14060
14061 // Action SetArrayArgument<k>(first, last) copies the elements in
14062 // source range [first, last) to the array pointed to by the k-th
14063 // (0-based) argument, which can be either a pointer or an
14064 // iterator. The action does not take ownership of the elements in the
14065 // source range.
14066 ACTION_TEMPLATE(SetArrayArgument,
14067 HAS_1_TEMPLATE_PARAMS(int, k),
14068 AND_2_VALUE_PARAMS(first, last)) {
14069 // Microsoft compiler deprecates ::std::copy, so we want to suppress warning
14070 // 4996 (Function call with parameters that may be unsafe) there.
14071 #ifdef _MSC_VER
14072 # pragma warning(push) // Saves the current warning state.
14073 # pragma warning(disable:4996) // Temporarily disables warning 4996.
14074 #endif
14075 ::std::copy(first, last, ::std::tr1::get<k>(args));
14076 #ifdef _MSC_VER
14077 # pragma warning(pop) // Restores the warning state.
14078 #endif
14079 }
14080
14081 // Action DeleteArg<k>() deletes the k-th (0-based) argument of the mock
14082 // function.
14083 ACTION_TEMPLATE(DeleteArg,
14084 HAS_1_TEMPLATE_PARAMS(int, k),
14085 AND_0_VALUE_PARAMS()) {
14086 delete ::std::tr1::get<k>(args);
14087 }
14088
14089 // This action returns the value pointed to by 'pointer'.
14090 ACTION_P(ReturnPointee, pointer) { return *pointer; }
14091
14092 // Action Throw(exception) can be used in a mock function of any type
14093 // to throw the given exception. Any copyable value can be thrown.
14094 #if GTEST_HAS_EXCEPTIONS
14095
14096 // Suppresses the 'unreachable code' warning that VC generates in opt modes.
14097 # ifdef _MSC_VER
14098 # pragma warning(push) // Saves the current warning state.
14099 # pragma warning(disable:4702) // Temporarily disables warning 4702.
14100 # endif
14101 ACTION_P(Throw, exception) { throw exception; }
14102 # ifdef _MSC_VER
14103 # pragma warning(pop) // Restores the warning state.
14104 # endif
14105
14106 #endif // GTEST_HAS_EXCEPTIONS
14107
14108 #ifdef _MSC_VER
14109 # pragma warning(pop)
14110 #endif
14111
14112 } // namespace testing
14113
14114 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
14115 // Copyright 2013, Google Inc.
14116 // All rights reserved.
14117 //
14118 // Redistribution and use in source and binary forms, with or without
14119 // modification, are permitted provided that the following conditions are
14120 // met:
14121 //
14122 // * Redistributions of source code must retain the above copyright
14123 // notice, this list of conditions and the following disclaimer.
14124 // * Redistributions in binary form must reproduce the above
14125 // copyright notice, this list of conditions and the following disclaimer
14126 // in the documentation and/or other materials provided with the
14127 // distribution.
14128 // * Neither the name of Google Inc. nor the names of its
14129 // contributors may be used to endorse or promote products derived from
14130 // this software without specific prior written permission.
14131 //
14132 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14133 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14134 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
14135 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
14136 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
14137 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
14138 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
14139 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
14140 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14141 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14142 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14143 //
14144 // Author: [email protected] (Marcus Boerger)
14145
14146 // Google Mock - a framework for writing C++ mock classes.
14147 //
14148 // This file implements some matchers that depend on gmock-generated-matchers.h.
14149 //
14150 // Note that tests are implemented in gmock-matchers_test.cc rather than
14151 // gmock-more-matchers-test.cc.
14152
14153 #ifndef GMOCK_GMOCK_MORE_MATCHERS_H_
14154 #define GMOCK_GMOCK_MORE_MATCHERS_H_
14155
14156
14157 namespace testing {
14158
14159 // Defines a matcher that matches an empty container. The container must
14160 // support both size() and empty(), which all STL-like containers provide.
14161 MATCHER(IsEmpty, negation ? "isn't empty" : "is empty") {
14162 if (arg.empty()) {
14163 return true;
14164 }
14165 *result_listener << "whose size is " << arg.size();
14166 return false;
14167 }
14168
14169 } // namespace testing
14170
14171 #endif // GMOCK_GMOCK_MORE_MATCHERS_H_
14172
14173 namespace testing {
14174
14175 // Declares Google Mock flags that we want a user to use programmatically.
14176 GMOCK_DECLARE_bool_(catch_leaked_mocks);
14177 GMOCK_DECLARE_string_(verbose);
14178
14179 // Initializes Google Mock. This must be called before running the
14180 // tests. In particular, it parses the command line for the flags
14181 // that Google Mock recognizes. Whenever a Google Mock flag is seen,
14182 // it is removed from argv, and *argc is decremented.
14183 //
14184 // No value is returned. Instead, the Google Mock flag variables are
14185 // updated.
14186 //
14187 // Since Google Test is needed for Google Mock to work, this function
14188 // also initializes Google Test and parses its flags, if that hasn't
14189 // been done.
14190 GTEST_API_ void InitGoogleMock(int* argc, char** argv);
14191
14192 // This overloaded version can be used in Windows programs compiled in
14193 // UNICODE mode.
14194 GTEST_API_ void InitGoogleMock(int* argc, wchar_t** argv);
14195
14196 } // namespace testing
14197
14198 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_H_