]> git.proxmox.com Git - ceph.git/blame - ceph/src/fmt/test/gmock/gmock.h
buildsys: switch source download to quincy
[ceph.git] / ceph / src / fmt / test / gmock / gmock.h
CommitLineData
11fdf7f2
TL
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: wan@google.com (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#ifdef __clang__
40# pragma clang diagnostic ignored "-Wc99-extensions"
41#endif
42
43// This file implements the following syntax:
44//
45// ON_CALL(mock_object.Method(...))
46// .With(...) ?
47// .WillByDefault(...);
48//
49// where With() is optional and WillByDefault() must appear exactly
50// once.
51//
52// EXPECT_CALL(mock_object.Method(...))
53// .With(...) ?
54// .Times(...) ?
55// .InSequence(...) *
56// .WillOnce(...) *
57// .WillRepeatedly(...) ?
58// .RetiresOnSaturation() ? ;
59//
60// where all clauses are optional and WillOnce() can be repeated.
61
62// Copyright 2007, Google Inc.
63// All rights reserved.
64//
65// Redistribution and use in source and binary forms, with or without
66// modification, are permitted provided that the following conditions are
67// met:
68//
69// * Redistributions of source code must retain the above copyright
70// notice, this list of conditions and the following disclaimer.
71// * Redistributions in binary form must reproduce the above
72// copyright notice, this list of conditions and the following disclaimer
73// in the documentation and/or other materials provided with the
74// distribution.
75// * Neither the name of Google Inc. nor the names of its
76// contributors may be used to endorse or promote products derived from
77// this software without specific prior written permission.
78//
79// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
80// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
81// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
82// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
83// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
84// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
85// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
86// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
87// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
88// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
89// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
90//
91// Author: wan@google.com (Zhanyong Wan)
92
93// Google Mock - a framework for writing C++ mock classes.
94//
95// This file implements some commonly used actions.
96
97#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
98#define GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
99
100#ifndef _WIN32_WCE
101# include <errno.h>
102#endif
103
104#include <algorithm>
105#include <string>
106
107// Copyright 2007, Google Inc.
108// All rights reserved.
109//
110// Redistribution and use in source and binary forms, with or without
111// modification, are permitted provided that the following conditions are
112// met:
113//
114// * Redistributions of source code must retain the above copyright
115// notice, this list of conditions and the following disclaimer.
116// * Redistributions in binary form must reproduce the above
117// copyright notice, this list of conditions and the following disclaimer
118// in the documentation and/or other materials provided with the
119// distribution.
120// * Neither the name of Google Inc. nor the names of its
121// contributors may be used to endorse or promote products derived from
122// this software without specific prior written permission.
123//
124// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
125// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
126// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
127// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
128// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
129// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
130// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
131// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
132// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
133// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
134// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
135//
136// Author: wan@google.com (Zhanyong Wan)
137
138// Google Mock - a framework for writing C++ mock classes.
139//
140// This file defines some utilities useful for implementing Google
141// Mock. They are subject to change without notice, so please DO NOT
142// USE THEM IN USER CODE.
143
144#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
145#define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
146
147#include <stdio.h>
148#include <ostream> // NOLINT
149#include <string>
150
151// This file was GENERATED by command:
152// pump.py gmock-generated-internal-utils.h.pump
153// DO NOT EDIT BY HAND!!!
154
155// Copyright 2007, Google Inc.
156// All rights reserved.
157//
158// Redistribution and use in source and binary forms, with or without
159// modification, are permitted provided that the following conditions are
160// met:
161//
162// * Redistributions of source code must retain the above copyright
163// notice, this list of conditions and the following disclaimer.
164// * Redistributions in binary form must reproduce the above
165// copyright notice, this list of conditions and the following disclaimer
166// in the documentation and/or other materials provided with the
167// distribution.
168// * Neither the name of Google Inc. nor the names of its
169// contributors may be used to endorse or promote products derived from
170// this software without specific prior written permission.
171//
172// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
173// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
174// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
175// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
176// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
177// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
178// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
179// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
180// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
181// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
182// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
183//
184// Author: wan@google.com (Zhanyong Wan)
185
186// Google Mock - a framework for writing C++ mock classes.
187//
188// This file contains template meta-programming utility classes needed
189// for implementing Google Mock.
190
191#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_
192#define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_
193
194// Copyright 2008, Google Inc.
195// All rights reserved.
196//
197// Redistribution and use in source and binary forms, with or without
198// modification, are permitted provided that the following conditions are
199// met:
200//
201// * Redistributions of source code must retain the above copyright
202// notice, this list of conditions and the following disclaimer.
203// * Redistributions in binary form must reproduce the above
204// copyright notice, this list of conditions and the following disclaimer
205// in the documentation and/or other materials provided with the
206// distribution.
207// * Neither the name of Google Inc. nor the names of its
208// contributors may be used to endorse or promote products derived from
209// this software without specific prior written permission.
210//
211// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
212// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
213// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
214// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
215// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
217// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
218// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
219// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
220// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
221// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
222//
223// Author: vadimb@google.com (Vadim Berman)
224//
225// Low-level types and utilities for porting Google Mock to various
226// platforms. They are subject to change without notice. DO NOT USE
227// THEM IN USER CODE.
228
229#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_
230#define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_
231
232#include <assert.h>
233#include <stdlib.h>
234#include <iostream>
235
236// Most of the types needed for porting Google Mock are also required
237// for Google Test and are defined in gtest-port.h.
238#include "gtest.h"
239
240// To avoid conditional compilation everywhere, we make it
241// gmock-port.h's responsibility to #include the header implementing
242// tr1/tuple. gmock-port.h does this via gtest-port.h, which is
243// guaranteed to pull in the tuple header.
244
245// For MS Visual C++, check the compiler version. At least VS 2003 is
246// required to compile Google Mock.
247#if defined(_MSC_VER) && _MSC_VER < 1310
248# error "At least Visual C++ 2003 (7.1) is required to compile Google Mock."
249#endif
250
251// Macro for referencing flags. This is public as we want the user to
252// use this syntax to reference Google Mock flags.
253#define GMOCK_FLAG(name) FLAGS_gmock_##name
254
255// Macros for declaring flags.
256#define GMOCK_DECLARE_bool_(name) extern GTEST_API_ bool GMOCK_FLAG(name)
257#define GMOCK_DECLARE_int32_(name) \
258 extern GTEST_API_ ::testing::internal::Int32 GMOCK_FLAG(name)
259#define GMOCK_DECLARE_string_(name) \
260 extern GTEST_API_ ::std::string GMOCK_FLAG(name)
261
262// Macros for defining flags.
263#define GMOCK_DEFINE_bool_(name, default_val, doc) \
264 GTEST_API_ bool GMOCK_FLAG(name) = (default_val)
265#define GMOCK_DEFINE_int32_(name, default_val, doc) \
266 GTEST_API_ ::testing::internal::Int32 GMOCK_FLAG(name) = (default_val)
267#define GMOCK_DEFINE_string_(name, default_val, doc) \
268 GTEST_API_ ::std::string GMOCK_FLAG(name) = (default_val)
269
270#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_
271
272namespace testing {
273
274template <typename T>
275class Matcher;
276
277namespace internal {
278
279// An IgnoredValue object can be implicitly constructed from ANY value.
280// This is used in implementing the IgnoreResult(a) action.
281class IgnoredValue {
282 public:
283 // This constructor template allows any value to be implicitly
284 // converted to IgnoredValue. The object has no data member and
285 // doesn't try to remember anything about the argument. We
286 // deliberately omit the 'explicit' keyword in order to allow the
287 // conversion to be implicit.
288 template <typename T>
289 IgnoredValue(const T& /* ignored */) {} // NOLINT(runtime/explicit)
290};
291
292// MatcherTuple<T>::type is a tuple type where each field is a Matcher
293// for the corresponding field in tuple type T.
294template <typename Tuple>
295struct MatcherTuple;
296
297template <>
298struct MatcherTuple< ::std::tr1::tuple<> > {
299 typedef ::std::tr1::tuple< > type;
300};
301
302template <typename A1>
303struct MatcherTuple< ::std::tr1::tuple<A1> > {
304 typedef ::std::tr1::tuple<Matcher<A1> > type;
305};
306
307template <typename A1, typename A2>
308struct MatcherTuple< ::std::tr1::tuple<A1, A2> > {
309 typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2> > type;
310};
311
312template <typename A1, typename A2, typename A3>
313struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3> > {
314 typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3> > type;
315};
316
317template <typename A1, typename A2, typename A3, typename A4>
318struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3, A4> > {
319 typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>,
320 Matcher<A4> > type;
321};
322
323template <typename A1, typename A2, typename A3, typename A4, typename A5>
324struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3, A4, A5> > {
325 typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
326 Matcher<A5> > type;
327};
328
329template <typename A1, typename A2, typename A3, typename A4, typename A5,
330 typename A6>
331struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3, A4, A5, A6> > {
332 typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
333 Matcher<A5>, Matcher<A6> > type;
334};
335
336template <typename A1, typename A2, typename A3, typename A4, typename A5,
337 typename A6, typename A7>
338struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7> > {
339 typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
340 Matcher<A5>, Matcher<A6>, Matcher<A7> > type;
341};
342
343template <typename A1, typename A2, typename A3, typename A4, typename A5,
344 typename A6, typename A7, typename A8>
345struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8> > {
346 typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
347 Matcher<A5>, Matcher<A6>, Matcher<A7>, Matcher<A8> > type;
348};
349
350template <typename A1, typename A2, typename A3, typename A4, typename A5,
351 typename A6, typename A7, typename A8, typename A9>
352struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9> > {
353 typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
354 Matcher<A5>, Matcher<A6>, Matcher<A7>, Matcher<A8>, Matcher<A9> > type;
355};
356
357template <typename A1, typename A2, typename A3, typename A4, typename A5,
358 typename A6, typename A7, typename A8, typename A9, typename A10>
359struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9,
360 A10> > {
361 typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
362 Matcher<A5>, Matcher<A6>, Matcher<A7>, Matcher<A8>, Matcher<A9>,
363 Matcher<A10> > type;
364};
365
366// Template struct Function<F>, where F must be a function type, contains
367// the following typedefs:
368//
369// Result: the function's return type.
370// ArgumentN: the type of the N-th argument, where N starts with 1.
371// ArgumentTuple: the tuple type consisting of all parameters of F.
372// ArgumentMatcherTuple: the tuple type consisting of Matchers for all
373// parameters of F.
374// MakeResultVoid: the function type obtained by substituting void
375// for the return type of F.
376// MakeResultIgnoredValue:
377// the function type obtained by substituting Something
378// for the return type of F.
379template <typename F>
380struct Function;
381
382template <typename R>
383struct Function<R()> {
384 typedef R Result;
385 typedef ::std::tr1::tuple<> ArgumentTuple;
386 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
387 typedef void MakeResultVoid();
388 typedef IgnoredValue MakeResultIgnoredValue();
389};
390
391template <typename R, typename A1>
392struct Function<R(A1)>
393 : Function<R()> {
394 typedef A1 Argument1;
395 typedef ::std::tr1::tuple<A1> ArgumentTuple;
396 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
397 typedef void MakeResultVoid(A1);
398 typedef IgnoredValue MakeResultIgnoredValue(A1);
399};
400
401template <typename R, typename A1, typename A2>
402struct Function<R(A1, A2)>
403 : Function<R(A1)> {
404 typedef A2 Argument2;
405 typedef ::std::tr1::tuple<A1, A2> ArgumentTuple;
406 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
407 typedef void MakeResultVoid(A1, A2);
408 typedef IgnoredValue MakeResultIgnoredValue(A1, A2);
409};
410
411template <typename R, typename A1, typename A2, typename A3>
412struct Function<R(A1, A2, A3)>
413 : Function<R(A1, A2)> {
414 typedef A3 Argument3;
415 typedef ::std::tr1::tuple<A1, A2, A3> ArgumentTuple;
416 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
417 typedef void MakeResultVoid(A1, A2, A3);
418 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3);
419};
420
421template <typename R, typename A1, typename A2, typename A3, typename A4>
422struct Function<R(A1, A2, A3, A4)>
423 : Function<R(A1, A2, A3)> {
424 typedef A4 Argument4;
425 typedef ::std::tr1::tuple<A1, A2, A3, A4> ArgumentTuple;
426 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
427 typedef void MakeResultVoid(A1, A2, A3, A4);
428 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4);
429};
430
431template <typename R, typename A1, typename A2, typename A3, typename A4,
432 typename A5>
433struct Function<R(A1, A2, A3, A4, A5)>
434 : Function<R(A1, A2, A3, A4)> {
435 typedef A5 Argument5;
436 typedef ::std::tr1::tuple<A1, A2, A3, A4, A5> ArgumentTuple;
437 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
438 typedef void MakeResultVoid(A1, A2, A3, A4, A5);
439 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5);
440};
441
442template <typename R, typename A1, typename A2, typename A3, typename A4,
443 typename A5, typename A6>
444struct Function<R(A1, A2, A3, A4, A5, A6)>
445 : Function<R(A1, A2, A3, A4, A5)> {
446 typedef A6 Argument6;
447 typedef ::std::tr1::tuple<A1, A2, A3, A4, A5, A6> ArgumentTuple;
448 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
449 typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6);
450 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6);
451};
452
453template <typename R, typename A1, typename A2, typename A3, typename A4,
454 typename A5, typename A6, typename A7>
455struct Function<R(A1, A2, A3, A4, A5, A6, A7)>
456 : Function<R(A1, A2, A3, A4, A5, A6)> {
457 typedef A7 Argument7;
458 typedef ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7> ArgumentTuple;
459 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
460 typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7);
461 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7);
462};
463
464template <typename R, typename A1, typename A2, typename A3, typename A4,
465 typename A5, typename A6, typename A7, typename A8>
466struct Function<R(A1, A2, A3, A4, A5, A6, A7, A8)>
467 : Function<R(A1, A2, A3, A4, A5, A6, A7)> {
468 typedef A8 Argument8;
469 typedef ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8> ArgumentTuple;
470 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
471 typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7, A8);
472 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7, A8);
473};
474
475template <typename R, typename A1, typename A2, typename A3, typename A4,
476 typename A5, typename A6, typename A7, typename A8, typename A9>
477struct Function<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)>
478 : Function<R(A1, A2, A3, A4, A5, A6, A7, A8)> {
479 typedef A9 Argument9;
480 typedef ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9> ArgumentTuple;
481 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
482 typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7, A8, A9);
483 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7, A8,
484 A9);
485};
486
487template <typename R, typename A1, typename A2, typename A3, typename A4,
488 typename A5, typename A6, typename A7, typename A8, typename A9,
489 typename A10>
490struct Function<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)>
491 : Function<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> {
492 typedef A10 Argument10;
493 typedef ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9,
494 A10> ArgumentTuple;
495 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
496 typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10);
497 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7, A8,
498 A9, A10);
499};
500
501} // namespace internal
502
503} // namespace testing
504
505#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_
506
507namespace testing {
508namespace internal {
509
510// Converts an identifier name to a space-separated list of lower-case
511// words. Each maximum substring of the form [A-Za-z][a-z]*|\d+ is
512// treated as one word. For example, both "FooBar123" and
513// "foo_bar_123" are converted to "foo bar 123".
514GTEST_API_ string ConvertIdentifierNameToWords(const char* id_name);
515
516// PointeeOf<Pointer>::type is the type of a value pointed to by a
517// Pointer, which can be either a smart pointer or a raw pointer. The
518// following default implementation is for the case where Pointer is a
519// smart pointer.
520template <typename Pointer>
521struct PointeeOf {
522 // Smart pointer classes define type element_type as the type of
523 // their pointees.
524 typedef typename Pointer::element_type type;
525};
526// This specialization is for the raw pointer case.
527template <typename T>
528struct PointeeOf<T*> { typedef T type; }; // NOLINT
529
530// GetRawPointer(p) returns the raw pointer underlying p when p is a
531// smart pointer, or returns p itself when p is already a raw pointer.
532// The following default implementation is for the smart pointer case.
533template <typename Pointer>
534inline const typename Pointer::element_type* GetRawPointer(const Pointer& p) {
535 return p.get();
536}
537// This overloaded version is for the raw pointer case.
538template <typename Element>
539inline Element* GetRawPointer(Element* p) { return p; }
540
541// This comparator allows linked_ptr to be stored in sets.
542template <typename T>
543struct LinkedPtrLessThan {
544 bool operator()(const ::testing::internal::linked_ptr<T>& lhs,
545 const ::testing::internal::linked_ptr<T>& rhs) const {
546 return lhs.get() < rhs.get();
547 }
548};
549
550// Symbian compilation can be done with wchar_t being either a native
551// type or a typedef. Using Google Mock with OpenC without wchar_t
552// should require the definition of _STLP_NO_WCHAR_T.
553//
554// MSVC treats wchar_t as a native type usually, but treats it as the
555// same as unsigned short when the compiler option /Zc:wchar_t- is
556// specified. It defines _NATIVE_WCHAR_T_DEFINED symbol when wchar_t
557// is a native type.
558#if (GTEST_OS_SYMBIAN && defined(_STLP_NO_WCHAR_T)) || \
559 (defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED))
560// wchar_t is a typedef.
561#else
562# define GMOCK_WCHAR_T_IS_NATIVE_ 1
563#endif
564
565// signed wchar_t and unsigned wchar_t are NOT in the C++ standard.
566// Using them is a bad practice and not portable. So DON'T use them.
567//
568// Still, Google Mock is designed to work even if the user uses signed
569// wchar_t or unsigned wchar_t (obviously, assuming the compiler
570// supports them).
571//
572// To gcc,
573// wchar_t == signed wchar_t != unsigned wchar_t == unsigned int
574#ifdef __GNUC__
575// signed/unsigned wchar_t are valid types.
576# define GMOCK_HAS_SIGNED_WCHAR_T_ 1
577#endif
578
579// In what follows, we use the term "kind" to indicate whether a type
580// is bool, an integer type (excluding bool), a floating-point type,
581// or none of them. This categorization is useful for determining
582// when a matcher argument type can be safely converted to another
583// type in the implementation of SafeMatcherCast.
584enum TypeKind {
585 kBool, kInteger, kFloatingPoint, kOther
586};
587
588// KindOf<T>::value is the kind of type T.
589template <typename T> struct KindOf {
590 enum { value = kOther }; // The default kind.
591};
592
593// This macro declares that the kind of 'type' is 'kind'.
594#define GMOCK_DECLARE_KIND_(type, kind) \
595 template <> struct KindOf<type> { enum { value = kind }; }
596
597GMOCK_DECLARE_KIND_(bool, kBool);
598
599// All standard integer types.
600GMOCK_DECLARE_KIND_(char, kInteger);
601GMOCK_DECLARE_KIND_(signed char, kInteger);
602GMOCK_DECLARE_KIND_(unsigned char, kInteger);
603GMOCK_DECLARE_KIND_(short, kInteger); // NOLINT
604GMOCK_DECLARE_KIND_(unsigned short, kInteger); // NOLINT
605GMOCK_DECLARE_KIND_(int, kInteger);
606GMOCK_DECLARE_KIND_(unsigned int, kInteger);
607GMOCK_DECLARE_KIND_(long, kInteger); // NOLINT
608GMOCK_DECLARE_KIND_(unsigned long, kInteger); // NOLINT
609
610#if GMOCK_WCHAR_T_IS_NATIVE_
611GMOCK_DECLARE_KIND_(wchar_t, kInteger);
612#endif
613
614// Non-standard integer types.
615GMOCK_DECLARE_KIND_(Int64, kInteger);
616GMOCK_DECLARE_KIND_(UInt64, kInteger);
617
618// All standard floating-point types.
619GMOCK_DECLARE_KIND_(float, kFloatingPoint);
620GMOCK_DECLARE_KIND_(double, kFloatingPoint);
621GMOCK_DECLARE_KIND_(long double, kFloatingPoint);
622
623#undef GMOCK_DECLARE_KIND_
624
625// Evaluates to the kind of 'type'.
626#define GMOCK_KIND_OF_(type) \
627 static_cast< ::testing::internal::TypeKind>( \
628 ::testing::internal::KindOf<type>::value)
629
630// Evaluates to true iff integer type T is signed.
631#define GMOCK_IS_SIGNED_(T) (static_cast<T>(-1) < 0)
632
633// LosslessArithmeticConvertibleImpl<kFromKind, From, kToKind, To>::value
634// is true iff arithmetic type From can be losslessly converted to
635// arithmetic type To.
636//
637// It's the user's responsibility to ensure that both From and To are
638// raw (i.e. has no CV modifier, is not a pointer, and is not a
639// reference) built-in arithmetic types, kFromKind is the kind of
640// From, and kToKind is the kind of To; the value is
641// implementation-defined when the above pre-condition is violated.
642template <TypeKind kFromKind, typename From, TypeKind kToKind, typename To>
643struct LosslessArithmeticConvertibleImpl : public false_type {};
644
645// Converting bool to bool is lossless.
646template <>
647struct LosslessArithmeticConvertibleImpl<kBool, bool, kBool, bool>
648 : public true_type {}; // NOLINT
649
650// Converting bool to any integer type is lossless.
651template <typename To>
652struct LosslessArithmeticConvertibleImpl<kBool, bool, kInteger, To>
653 : public true_type {}; // NOLINT
654
655// Converting bool to any floating-point type is lossless.
656template <typename To>
657struct LosslessArithmeticConvertibleImpl<kBool, bool, kFloatingPoint, To>
658 : public true_type {}; // NOLINT
659
660// Converting an integer to bool is lossy.
661template <typename From>
662struct LosslessArithmeticConvertibleImpl<kInteger, From, kBool, bool>
663 : public false_type {}; // NOLINT
664
665// Converting an integer to another non-bool integer is lossless iff
666// the target type's range encloses the source type's range.
667template <typename From, typename To>
668struct LosslessArithmeticConvertibleImpl<kInteger, From, kInteger, To>
669 : public bool_constant<
670 // When converting from a smaller size to a larger size, we are
671 // fine as long as we are not converting from signed to unsigned.
672 ((sizeof(From) < sizeof(To)) &&
673 (!GMOCK_IS_SIGNED_(From) || GMOCK_IS_SIGNED_(To))) ||
674 // When converting between the same size, the signedness must match.
675 ((sizeof(From) == sizeof(To)) &&
676 (GMOCK_IS_SIGNED_(From) == GMOCK_IS_SIGNED_(To)))> {}; // NOLINT
677
678#undef GMOCK_IS_SIGNED_
679
680// Converting an integer to a floating-point type may be lossy, since
681// the format of a floating-point number is implementation-defined.
682template <typename From, typename To>
683struct LosslessArithmeticConvertibleImpl<kInteger, From, kFloatingPoint, To>
684 : public false_type {}; // NOLINT
685
686// Converting a floating-point to bool is lossy.
687template <typename From>
688struct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kBool, bool>
689 : public false_type {}; // NOLINT
690
691// Converting a floating-point to an integer is lossy.
692template <typename From, typename To>
693struct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kInteger, To>
694 : public false_type {}; // NOLINT
695
696// Converting a floating-point to another floating-point is lossless
697// iff the target type is at least as big as the source type.
698template <typename From, typename To>
699struct LosslessArithmeticConvertibleImpl<
700 kFloatingPoint, From, kFloatingPoint, To>
701 : public bool_constant<sizeof(From) <= sizeof(To)> {}; // NOLINT
702
703// LosslessArithmeticConvertible<From, To>::value is true iff arithmetic
704// type From can be losslessly converted to arithmetic type To.
705//
706// It's the user's responsibility to ensure that both From and To are
707// raw (i.e. has no CV modifier, is not a pointer, and is not a
708// reference) built-in arithmetic types; the value is
709// implementation-defined when the above pre-condition is violated.
710template <typename From, typename To>
711struct LosslessArithmeticConvertible
712 : public LosslessArithmeticConvertibleImpl<
713 GMOCK_KIND_OF_(From), From, GMOCK_KIND_OF_(To), To> {}; // NOLINT
714
715// This interface knows how to report a Google Mock failure (either
716// non-fatal or fatal).
717class FailureReporterInterface {
718 public:
719 // The type of a failure (either non-fatal or fatal).
720 enum FailureType {
721 kNonfatal, kFatal
722 };
723
724 virtual ~FailureReporterInterface() {}
725
726 // Reports a failure that occurred at the given source file location.
727 virtual void ReportFailure(FailureType type, const char* file, int line,
728 const string& message) = 0;
729};
730
731// Returns the failure reporter used by Google Mock.
732GTEST_API_ FailureReporterInterface* GetFailureReporter();
733
734// Asserts that condition is true; aborts the process with the given
735// message if condition is false. We cannot use LOG(FATAL) or CHECK()
736// as Google Mock might be used to mock the log sink itself. We
737// inline this function to prevent it from showing up in the stack
738// trace.
739inline void Assert(bool condition, const char* file, int line,
740 const string& msg) {
741 if (!condition) {
742 GetFailureReporter()->ReportFailure(FailureReporterInterface::kFatal,
743 file, line, msg);
744 }
745}
746inline void Assert(bool condition, const char* file, int line) {
747 Assert(condition, file, line, "Assertion failed.");
748}
749
750// Verifies that condition is true; generates a non-fatal failure if
751// condition is false.
752inline void Expect(bool condition, const char* file, int line,
753 const string& msg) {
754 if (!condition) {
755 GetFailureReporter()->ReportFailure(FailureReporterInterface::kNonfatal,
756 file, line, msg);
757 }
758}
759inline void Expect(bool condition, const char* file, int line) {
760 Expect(condition, file, line, "Expectation failed.");
761}
762
763// Severity level of a log.
764enum LogSeverity {
765 kInfo = 0,
766 kWarning = 1
767};
768
769// Valid values for the --gmock_verbose flag.
770
771// All logs (informational and warnings) are printed.
772const char kInfoVerbosity[] = "info";
773// Only warnings are printed.
774const char kWarningVerbosity[] = "warning";
775// No logs are printed.
776const char kErrorVerbosity[] = "error";
777
778// Returns true iff a log with the given severity is visible according
779// to the --gmock_verbose flag.
780GTEST_API_ bool LogIsVisible(LogSeverity severity);
781
782// Prints the given message to stdout iff 'severity' >= the level
783// specified by the --gmock_verbose flag. If stack_frames_to_skip >=
784// 0, also prints the stack trace excluding the top
785// stack_frames_to_skip frames. In opt mode, any positive
786// stack_frames_to_skip is treated as 0, since we don't know which
787// function calls will be inlined by the compiler and need to be
788// conservative.
789GTEST_API_ void Log(LogSeverity severity,
790 const string& message,
791 int stack_frames_to_skip);
792
793// TODO(wan@google.com): group all type utilities together.
794
795// Type traits.
796
797// is_reference<T>::value is non-zero iff T is a reference type.
798template <typename T> struct is_reference : public false_type {};
799template <typename T> struct is_reference<T&> : public true_type {};
800
801// type_equals<T1, T2>::value is non-zero iff T1 and T2 are the same type.
802template <typename T1, typename T2> struct type_equals : public false_type {};
803template <typename T> struct type_equals<T, T> : public true_type {};
804
805// remove_reference<T>::type removes the reference from type T, if any.
806template <typename T> struct remove_reference { typedef T type; }; // NOLINT
807template <typename T> struct remove_reference<T&> { typedef T type; }; // NOLINT
808
809// DecayArray<T>::type turns an array type U[N] to const U* and preserves
810// other types. Useful for saving a copy of a function argument.
811template <typename T> struct DecayArray { typedef T type; }; // NOLINT
812template <typename T, size_t N> struct DecayArray<T[N]> {
813 typedef const T* type;
814};
815// Sometimes people use arrays whose size is not available at the use site
816// (e.g. extern const char kNamePrefix[]). This specialization covers that
817// case.
818template <typename T> struct DecayArray<T[]> {
819 typedef const T* type;
820};
821
822// Invalid<T>() returns an invalid value of type T. This is useful
823// when a value of type T is needed for compilation, but the statement
824// will not really be executed (or we don't care if the statement
825// crashes).
826template <typename T>
827inline T Invalid() {
828 void *p = NULL;
829 return const_cast<typename remove_reference<T>::type&>(
830 *static_cast<volatile typename remove_reference<T>::type*>(p));
831}
832template <>
833inline void Invalid<void>() {}
834
835// Given a raw type (i.e. having no top-level reference or const
836// modifier) RawContainer that's either an STL-style container or a
837// native array, class StlContainerView<RawContainer> has the
838// following members:
839//
840// - type is a type that provides an STL-style container view to
841// (i.e. implements the STL container concept for) RawContainer;
842// - const_reference is a type that provides a reference to a const
843// RawContainer;
844// - ConstReference(raw_container) returns a const reference to an STL-style
845// container view to raw_container, which is a RawContainer.
846// - Copy(raw_container) returns an STL-style container view of a
847// copy of raw_container, which is a RawContainer.
848//
849// This generic version is used when RawContainer itself is already an
850// STL-style container.
851template <class RawContainer>
852class StlContainerView {
853 public:
854 typedef RawContainer type;
855 typedef const type& const_reference;
856
857 static const_reference ConstReference(const RawContainer& container) {
858 // Ensures that RawContainer is not a const type.
859 testing::StaticAssertTypeEq<RawContainer,
860 GTEST_REMOVE_CONST_(RawContainer)>();
861 return container;
862 }
863 static type Copy(const RawContainer& container) { return container; }
864};
865
866// This specialization is used when RawContainer is a native array type.
867template <typename Element, size_t N>
868class StlContainerView<Element[N]> {
869 public:
870 typedef GTEST_REMOVE_CONST_(Element) RawElement;
871 typedef internal::NativeArray<RawElement> type;
872 // NativeArray<T> can represent a native array either by value or by
873 // reference (selected by a constructor argument), so 'const type'
874 // can be used to reference a const native array. We cannot
875 // 'typedef const type& const_reference' here, as that would mean
876 // ConstReference() has to return a reference to a local variable.
877 typedef const type const_reference;
878
879 static const_reference ConstReference(const Element (&array)[N]) {
880 // Ensures that Element is not a const type.
881 testing::StaticAssertTypeEq<Element, RawElement>();
882#if GTEST_OS_SYMBIAN
883 // The Nokia Symbian compiler confuses itself in template instantiation
884 // for this call without the cast to Element*:
885 // function call '[testing::internal::NativeArray<char *>].NativeArray(
886 // {lval} const char *[4], long, testing::internal::RelationToSource)'
887 // does not match
888 // 'testing::internal::NativeArray<char *>::NativeArray(
889 // char *const *, unsigned int, testing::internal::RelationToSource)'
890 // (instantiating: 'testing::internal::ContainsMatcherImpl
891 // <const char * (&)[4]>::Matches(const char * (&)[4]) const')
892 // (instantiating: 'testing::internal::StlContainerView<char *[4]>::
893 // ConstReference(const char * (&)[4])')
894 // (and though the N parameter type is mismatched in the above explicit
895 // conversion of it doesn't help - only the conversion of the array).
896 return type(const_cast<Element*>(&array[0]), N, kReference);
897#else
898 return type(array, N, kReference);
899#endif // GTEST_OS_SYMBIAN
900 }
901 static type Copy(const Element (&array)[N]) {
902#if GTEST_OS_SYMBIAN
903 return type(const_cast<Element*>(&array[0]), N, kCopy);
904#else
905 return type(array, N, kCopy);
906#endif // GTEST_OS_SYMBIAN
907 }
908};
909
910// This specialization is used when RawContainer is a native array
911// represented as a (pointer, size) tuple.
912template <typename ElementPointer, typename Size>
913class StlContainerView< ::std::tr1::tuple<ElementPointer, Size> > {
914 public:
915 typedef GTEST_REMOVE_CONST_(
916 typename internal::PointeeOf<ElementPointer>::type) RawElement;
917 typedef internal::NativeArray<RawElement> type;
918 typedef const type const_reference;
919
920 static const_reference ConstReference(
921 const ::std::tr1::tuple<ElementPointer, Size>& array) {
922 using ::std::tr1::get;
923 return type(get<0>(array), get<1>(array), kReference);
924 }
925 static type Copy(const ::std::tr1::tuple<ElementPointer, Size>& array) {
926 using ::std::tr1::get;
927 return type(get<0>(array), get<1>(array), kCopy);
928 }
929};
930
931// The following specialization prevents the user from instantiating
932// StlContainer with a reference type.
933template <typename T> class StlContainerView<T&>;
934
935// A type transform to remove constness from the first part of a pair.
936// Pairs like that are used as the value_type of associative containers,
937// and this transform produces a similar but assignable pair.
938template <typename T>
939struct RemoveConstFromKey {
940 typedef T type;
941};
942
943// Partially specialized to remove constness from std::pair<const K, V>.
944template <typename K, typename V>
945struct RemoveConstFromKey<std::pair<const K, V> > {
946 typedef std::pair<K, V> type;
947};
948
949// Mapping from booleans to types. Similar to boost::bool_<kValue> and
950// std::integral_constant<bool, kValue>.
951template <bool kValue>
952struct BooleanConstant {};
953
954} // namespace internal
955} // namespace testing
956
957#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
958
959namespace testing {
960
961// To implement an action Foo, define:
962// 1. a class FooAction that implements the ActionInterface interface, and
963// 2. a factory function that creates an Action object from a
964// const FooAction*.
965//
966// The two-level delegation design follows that of Matcher, providing
967// consistency for extension developers. It also eases ownership
968// management as Action objects can now be copied like plain values.
969
970namespace internal {
971
972template <typename F1, typename F2>
973class ActionAdaptor;
974
975// BuiltInDefaultValue<T>::Get() returns the "built-in" default
976// value for type T, which is NULL when T is a pointer type, 0 when T
977// is a numeric type, false when T is bool, or "" when T is string or
978// std::string. For any other type T, this value is undefined and the
979// function will abort the process.
980template <typename T>
981class BuiltInDefaultValue {
982 public:
983 // This function returns true iff type T has a built-in default value.
984 static bool Exists() { return false; }
985 static T Get() {
986 Assert(false, __FILE__, __LINE__,
987 "Default action undefined for the function return type.");
988 return internal::Invalid<T>();
989 // The above statement will never be reached, but is required in
990 // order for this function to compile.
991 }
992};
993
994// This partial specialization says that we use the same built-in
995// default value for T and const T.
996template <typename T>
997class BuiltInDefaultValue<const T> {
998 public:
999 static bool Exists() { return BuiltInDefaultValue<T>::Exists(); }
1000 static T Get() { return BuiltInDefaultValue<T>::Get(); }
1001};
1002
1003// This partial specialization defines the default values for pointer
1004// types.
1005template <typename T>
1006class BuiltInDefaultValue<T*> {
1007 public:
1008 static bool Exists() { return true; }
1009 static T* Get() { return NULL; }
1010};
1011
1012// The following specializations define the default values for
1013// specific types we care about.
1014#define GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(type, value) \
1015 template <> \
1016 class BuiltInDefaultValue<type> { \
1017 public: \
1018 static bool Exists() { return true; } \
1019 static type Get() { return value; } \
1020 }
1021
1022GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(void, ); // NOLINT
1023#if GTEST_HAS_GLOBAL_STRING
1024GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(::string, "");
1025#endif // GTEST_HAS_GLOBAL_STRING
1026GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(::std::string, "");
1027GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(bool, false);
1028GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned char, '\0');
1029GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed char, '\0');
1030GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(char, '\0');
1031
1032// There's no need for a default action for signed wchar_t, as that
1033// type is the same as wchar_t for gcc, and invalid for MSVC.
1034//
1035// There's also no need for a default action for unsigned wchar_t, as
1036// that type is the same as unsigned int for gcc, and invalid for
1037// MSVC.
1038#if GMOCK_WCHAR_T_IS_NATIVE_
1039GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(wchar_t, 0U); // NOLINT
1040#endif
1041
1042GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned short, 0U); // NOLINT
1043GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed short, 0); // NOLINT
1044GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned int, 0U);
1045GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed int, 0);
1046GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned long, 0UL); // NOLINT
1047GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed long, 0L); // NOLINT
1048GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(UInt64, 0);
1049GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(Int64, 0);
1050GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(float, 0);
1051GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(double, 0);
1052
1053#undef GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_
1054
1055} // namespace internal
1056
1057// When an unexpected function call is encountered, Google Mock will
1058// let it return a default value if the user has specified one for its
1059// return type, or if the return type has a built-in default value;
1060// otherwise Google Mock won't know what value to return and will have
1061// to abort the process.
1062//
1063// The DefaultValue<T> class allows a user to specify the
1064// default value for a type T that is both copyable and publicly
1065// destructible (i.e. anything that can be used as a function return
1066// type). The usage is:
1067//
1068// // Sets the default value for type T to be foo.
1069// DefaultValue<T>::Set(foo);
1070template <typename T>
1071class DefaultValue {
1072 public:
1073 // Sets the default value for type T; requires T to be
1074 // copy-constructable and have a public destructor.
1075 static void Set(T x) {
1076 delete value_;
1077 value_ = new T(x);
1078 }
1079
1080 // Unsets the default value for type T.
1081 static void Clear() {
1082 delete value_;
1083 value_ = NULL;
1084 }
1085
1086 // Returns true iff the user has set the default value for type T.
1087 static bool IsSet() { return value_ != NULL; }
1088
1089 // Returns true if T has a default return value set by the user or there
1090 // exists a built-in default value.
1091 static bool Exists() {
1092 return IsSet() || internal::BuiltInDefaultValue<T>::Exists();
1093 }
1094
1095 // Returns the default value for type T if the user has set one;
1096 // otherwise returns the built-in default value if there is one;
1097 // otherwise aborts the process.
1098 static T Get() {
1099 return value_ == NULL ?
1100 internal::BuiltInDefaultValue<T>::Get() : *value_;
1101 }
1102
1103 private:
1104 static const T* value_;
1105};
1106
1107// This partial specialization allows a user to set default values for
1108// reference types.
1109template <typename T>
1110class DefaultValue<T&> {
1111 public:
1112 // Sets the default value for type T&.
1113 static void Set(T& x) { // NOLINT
1114 address_ = &x;
1115 }
1116
1117 // Unsets the default value for type T&.
1118 static void Clear() {
1119 address_ = NULL;
1120 }
1121
1122 // Returns true iff the user has set the default value for type T&.
1123 static bool IsSet() { return address_ != NULL; }
1124
1125 // Returns true if T has a default return value set by the user or there
1126 // exists a built-in default value.
1127 static bool Exists() {
1128 return IsSet() || internal::BuiltInDefaultValue<T&>::Exists();
1129 }
1130
1131 // Returns the default value for type T& if the user has set one;
1132 // otherwise returns the built-in default value if there is one;
1133 // otherwise aborts the process.
1134 static T& Get() {
1135 return address_ == NULL ?
1136 internal::BuiltInDefaultValue<T&>::Get() : *address_;
1137 }
1138
1139 private:
1140 static T* address_;
1141};
1142
1143// This specialization allows DefaultValue<void>::Get() to
1144// compile.
1145template <>
1146class DefaultValue<void> {
1147 public:
1148 static bool Exists() { return true; }
1149 static void Get() {}
1150};
1151
1152// Points to the user-set default value for type T.
1153template <typename T>
1154const T* DefaultValue<T>::value_ = NULL;
1155
1156// Points to the user-set default value for type T&.
1157template <typename T>
1158T* DefaultValue<T&>::address_ = NULL;
1159
1160// Implement this interface to define an action for function type F.
1161template <typename F>
1162class ActionInterface {
1163 public:
1164 typedef typename internal::Function<F>::Result Result;
1165 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
1166
1167 ActionInterface() {}
1168 virtual ~ActionInterface() {}
1169
1170 // Performs the action. This method is not const, as in general an
1171 // action can have side effects and be stateful. For example, a
1172 // get-the-next-element-from-the-collection action will need to
1173 // remember the current element.
1174 virtual Result Perform(const ArgumentTuple& args) = 0;
1175
1176 private:
1177 GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionInterface);
1178};
1179
1180// An Action<F> is a copyable and IMMUTABLE (except by assignment)
1181// object that represents an action to be taken when a mock function
1182// of type F is called. The implementation of Action<T> is just a
1183// linked_ptr to const ActionInterface<T>, so copying is fairly cheap.
1184// Don't inherit from Action!
1185//
1186// You can view an object implementing ActionInterface<F> as a
1187// concrete action (including its current state), and an Action<F>
1188// object as a handle to it.
1189template <typename F>
1190class Action {
1191 public:
1192 typedef typename internal::Function<F>::Result Result;
1193 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
1194
1195 // Constructs a null Action. Needed for storing Action objects in
1196 // STL containers.
1197 Action() : impl_(NULL) {}
1198
1199 // Constructs an Action from its implementation. A NULL impl is
1200 // used to represent the "do-default" action.
1201 explicit Action(ActionInterface<F>* impl) : impl_(impl) {}
1202
1203 // Copy constructor.
1204 Action(const Action& action) : impl_(action.impl_) {}
1205
1206 // This constructor allows us to turn an Action<Func> object into an
1207 // Action<F>, as long as F's arguments can be implicitly converted
1208 // to Func's and Func's return type can be implicitly converted to
1209 // F's.
1210 template <typename Func>
1211 explicit Action(const Action<Func>& action);
1212
1213 // Returns true iff this is the DoDefault() action.
1214 bool IsDoDefault() const { return impl_.get() == NULL; }
1215
1216 // Performs the action. Note that this method is const even though
1217 // the corresponding method in ActionInterface is not. The reason
1218 // is that a const Action<F> means that it cannot be re-bound to
1219 // another concrete action, not that the concrete action it binds to
1220 // cannot change state. (Think of the difference between a const
1221 // pointer and a pointer to const.)
1222 Result Perform(const ArgumentTuple& args) const {
1223 internal::Assert(
1224 !IsDoDefault(), __FILE__, __LINE__,
1225 "You are using DoDefault() inside a composite action like "
1226 "DoAll() or WithArgs(). This is not supported for technical "
1227 "reasons. Please instead spell out the default action, or "
1228 "assign the default action to an Action variable and use "
1229 "the variable in various places.");
1230 return impl_->Perform(args);
1231 }
1232
1233 private:
1234 template <typename F1, typename F2>
1235 friend class internal::ActionAdaptor;
1236
1237 internal::linked_ptr<ActionInterface<F> > impl_;
1238};
1239
1240// The PolymorphicAction class template makes it easy to implement a
1241// polymorphic action (i.e. an action that can be used in mock
1242// functions of than one type, e.g. Return()).
1243//
1244// To define a polymorphic action, a user first provides a COPYABLE
1245// implementation class that has a Perform() method template:
1246//
1247// class FooAction {
1248// public:
1249// template <typename Result, typename ArgumentTuple>
1250// Result Perform(const ArgumentTuple& args) const {
1251// // Processes the arguments and returns a result, using
1252// // tr1::get<N>(args) to get the N-th (0-based) argument in the tuple.
1253// }
1254// ...
1255// };
1256//
1257// Then the user creates the polymorphic action using
1258// MakePolymorphicAction(object) where object has type FooAction. See
1259// the definition of Return(void) and SetArgumentPointee<N>(value) for
1260// complete examples.
1261template <typename Impl>
1262class PolymorphicAction {
1263 public:
1264 explicit PolymorphicAction(const Impl& impl) : impl_(impl) {}
1265
1266 template <typename F>
1267 operator Action<F>() const {
1268 return Action<F>(new MonomorphicImpl<F>(impl_));
1269 }
1270
1271 private:
1272 template <typename F>
1273 class MonomorphicImpl : public ActionInterface<F> {
1274 public:
1275 typedef typename internal::Function<F>::Result Result;
1276 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
1277
1278 explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {}
1279
1280 virtual Result Perform(const ArgumentTuple& args) {
1281 return impl_.template Perform<Result>(args);
1282 }
1283
1284 private:
1285 Impl impl_;
1286
1287 GTEST_DISALLOW_ASSIGN_(MonomorphicImpl);
1288 };
1289
1290 Impl impl_;
1291
1292 GTEST_DISALLOW_ASSIGN_(PolymorphicAction);
1293};
1294
1295// Creates an Action from its implementation and returns it. The
1296// created Action object owns the implementation.
1297template <typename F>
1298Action<F> MakeAction(ActionInterface<F>* impl) {
1299 return Action<F>(impl);
1300}
1301
1302// Creates a polymorphic action from its implementation. This is
1303// easier to use than the PolymorphicAction<Impl> constructor as it
1304// doesn't require you to explicitly write the template argument, e.g.
1305//
1306// MakePolymorphicAction(foo);
1307// vs
1308// PolymorphicAction<TypeOfFoo>(foo);
1309template <typename Impl>
1310inline PolymorphicAction<Impl> MakePolymorphicAction(const Impl& impl) {
1311 return PolymorphicAction<Impl>(impl);
1312}
1313
1314namespace internal {
1315
1316// Allows an Action<F2> object to pose as an Action<F1>, as long as F2
1317// and F1 are compatible.
1318template <typename F1, typename F2>
1319class ActionAdaptor : public ActionInterface<F1> {
1320 public:
1321 typedef typename internal::Function<F1>::Result Result;
1322 typedef typename internal::Function<F1>::ArgumentTuple ArgumentTuple;
1323
1324 explicit ActionAdaptor(const Action<F2>& from) : impl_(from.impl_) {}
1325
1326 virtual Result Perform(const ArgumentTuple& args) {
1327 return impl_->Perform(args);
1328 }
1329
1330 private:
1331 const internal::linked_ptr<ActionInterface<F2> > impl_;
1332
1333 GTEST_DISALLOW_ASSIGN_(ActionAdaptor);
1334};
1335
1336// Implements the polymorphic Return(x) action, which can be used in
1337// any function that returns the type of x, regardless of the argument
1338// types.
1339//
1340// Note: The value passed into Return must be converted into
1341// Function<F>::Result when this action is cast to Action<F> rather than
1342// when that action is performed. This is important in scenarios like
1343//
1344// MOCK_METHOD1(Method, T(U));
1345// ...
1346// {
1347// Foo foo;
1348// X x(&foo);
1349// EXPECT_CALL(mock, Method(_)).WillOnce(Return(x));
1350// }
1351//
1352// In the example above the variable x holds reference to foo which leaves
1353// scope and gets destroyed. If copying X just copies a reference to foo,
1354// that copy will be left with a hanging reference. If conversion to T
1355// makes a copy of foo, the above code is safe. To support that scenario, we
1356// need to make sure that the type conversion happens inside the EXPECT_CALL
1357// statement, and conversion of the result of Return to Action<T(U)> is a
1358// good place for that.
1359//
1360template <typename R>
1361class ReturnAction {
1362 public:
1363 // Constructs a ReturnAction object from the value to be returned.
1364 // 'value' is passed by value instead of by const reference in order
1365 // to allow Return("string literal") to compile.
1366 explicit ReturnAction(R value) : value_(value) {}
1367
1368 // This template type conversion operator allows Return(x) to be
1369 // used in ANY function that returns x's type.
1370 template <typename F>
1371 operator Action<F>() const {
1372 // Assert statement belongs here because this is the best place to verify
1373 // conditions on F. It produces the clearest error messages
1374 // in most compilers.
1375 // Impl really belongs in this scope as a local class but can't
1376 // because MSVC produces duplicate symbols in different translation units
1377 // in this case. Until MS fixes that bug we put Impl into the class scope
1378 // and put the typedef both here (for use in assert statement) and
1379 // in the Impl class. But both definitions must be the same.
1380 typedef typename Function<F>::Result Result;
1381 GTEST_COMPILE_ASSERT_(
1382 !internal::is_reference<Result>::value,
1383 use_ReturnRef_instead_of_Return_to_return_a_reference);
1384 return Action<F>(new Impl<F>(value_));
1385 }
1386
1387 private:
1388 // Implements the Return(x) action for a particular function type F.
1389 template <typename F>
1390 class Impl : public ActionInterface<F> {
1391 public:
1392 typedef typename Function<F>::Result Result;
1393 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
1394
1395 // The implicit cast is necessary when Result has more than one
1396 // single-argument constructor (e.g. Result is std::vector<int>) and R
1397 // has a type conversion operator template. In that case, value_(value)
1398 // won't compile as the compiler doesn't known which constructor of
1399 // Result to call. ImplicitCast_ forces the compiler to convert R to
1400 // Result without considering explicit constructors, thus resolving the
1401 // ambiguity. value_ is then initialized using its copy constructor.
1402 explicit Impl(R value)
1403 : value_(::testing::internal::ImplicitCast_<Result>(value)) {}
1404
1405 virtual Result Perform(const ArgumentTuple&) { return value_; }
1406
1407 private:
1408 GTEST_COMPILE_ASSERT_(!internal::is_reference<Result>::value,
1409 Result_cannot_be_a_reference_type);
1410 Result value_;
1411
1412 GTEST_DISALLOW_ASSIGN_(Impl);
1413 };
1414
1415 R value_;
1416
1417 GTEST_DISALLOW_ASSIGN_(ReturnAction);
1418};
1419
1420// Implements the ReturnNull() action.
1421class ReturnNullAction {
1422 public:
1423 // Allows ReturnNull() to be used in any pointer-returning function.
1424 template <typename Result, typename ArgumentTuple>
1425 static Result Perform(const ArgumentTuple&) {
1426 GTEST_COMPILE_ASSERT_(internal::is_pointer<Result>::value,
1427 ReturnNull_can_be_used_to_return_a_pointer_only);
1428 return NULL;
1429 }
1430};
1431
1432// Implements the Return() action.
1433class ReturnVoidAction {
1434 public:
1435 // Allows Return() to be used in any void-returning function.
1436 template <typename Result, typename ArgumentTuple>
1437 static void Perform(const ArgumentTuple&) {
1438 CompileAssertTypesEqual<void, Result>();
1439 }
1440};
1441
1442// Implements the polymorphic ReturnRef(x) action, which can be used
1443// in any function that returns a reference to the type of x,
1444// regardless of the argument types.
1445template <typename T>
1446class ReturnRefAction {
1447 public:
1448 // Constructs a ReturnRefAction object from the reference to be returned.
1449 explicit ReturnRefAction(T& ref) : ref_(ref) {} // NOLINT
1450
1451 // This template type conversion operator allows ReturnRef(x) to be
1452 // used in ANY function that returns a reference to x's type.
1453 template <typename F>
1454 operator Action<F>() const {
1455 typedef typename Function<F>::Result Result;
1456 // Asserts that the function return type is a reference. This
1457 // catches the user error of using ReturnRef(x) when Return(x)
1458 // should be used, and generates some helpful error message.
1459 GTEST_COMPILE_ASSERT_(internal::is_reference<Result>::value,
1460 use_Return_instead_of_ReturnRef_to_return_a_value);
1461 return Action<F>(new Impl<F>(ref_));
1462 }
1463
1464 private:
1465 // Implements the ReturnRef(x) action for a particular function type F.
1466 template <typename F>
1467 class Impl : public ActionInterface<F> {
1468 public:
1469 typedef typename Function<F>::Result Result;
1470 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
1471
1472 explicit Impl(T& ref) : ref_(ref) {} // NOLINT
1473
1474 virtual Result Perform(const ArgumentTuple&) {
1475 return ref_;
1476 }
1477
1478 private:
1479 T& ref_;
1480
1481 GTEST_DISALLOW_ASSIGN_(Impl);
1482 };
1483
1484 T& ref_;
1485
1486 GTEST_DISALLOW_ASSIGN_(ReturnRefAction);
1487};
1488
1489// Implements the polymorphic ReturnRefOfCopy(x) action, which can be
1490// used in any function that returns a reference to the type of x,
1491// regardless of the argument types.
1492template <typename T>
1493class ReturnRefOfCopyAction {
1494 public:
1495 // Constructs a ReturnRefOfCopyAction object from the reference to
1496 // be returned.
1497 explicit ReturnRefOfCopyAction(const T& value) : value_(value) {} // NOLINT
1498
1499 // This template type conversion operator allows ReturnRefOfCopy(x) to be
1500 // used in ANY function that returns a reference to x's type.
1501 template <typename F>
1502 operator Action<F>() const {
1503 typedef typename Function<F>::Result Result;
1504 // Asserts that the function return type is a reference. This
1505 // catches the user error of using ReturnRefOfCopy(x) when Return(x)
1506 // should be used, and generates some helpful error message.
1507 GTEST_COMPILE_ASSERT_(
1508 internal::is_reference<Result>::value,
1509 use_Return_instead_of_ReturnRefOfCopy_to_return_a_value);
1510 return Action<F>(new Impl<F>(value_));
1511 }
1512
1513 private:
1514 // Implements the ReturnRefOfCopy(x) action for a particular function type F.
1515 template <typename F>
1516 class Impl : public ActionInterface<F> {
1517 public:
1518 typedef typename Function<F>::Result Result;
1519 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
1520
1521 explicit Impl(const T& value) : value_(value) {} // NOLINT
1522
1523 virtual Result Perform(const ArgumentTuple&) {
1524 return value_;
1525 }
1526
1527 private:
1528 T value_;
1529
1530 GTEST_DISALLOW_ASSIGN_(Impl);
1531 };
1532
1533 const T value_;
1534
1535 GTEST_DISALLOW_ASSIGN_(ReturnRefOfCopyAction);
1536};
1537
1538// Implements the polymorphic DoDefault() action.
1539class DoDefaultAction {
1540 public:
1541 // This template type conversion operator allows DoDefault() to be
1542 // used in any function.
1543 template <typename F>
1544 operator Action<F>() const { return Action<F>(NULL); }
1545};
1546
1547// Implements the Assign action to set a given pointer referent to a
1548// particular value.
1549template <typename T1, typename T2>
1550class AssignAction {
1551 public:
1552 AssignAction(T1* ptr, T2 value) : ptr_(ptr), value_(value) {}
1553
1554 template <typename Result, typename ArgumentTuple>
1555 void Perform(const ArgumentTuple& /* args */) const {
1556 *ptr_ = value_;
1557 }
1558
1559 private:
1560 T1* const ptr_;
1561 const T2 value_;
1562
1563 GTEST_DISALLOW_ASSIGN_(AssignAction);
1564};
1565
1566#if !GTEST_OS_WINDOWS_MOBILE
1567
1568// Implements the SetErrnoAndReturn action to simulate return from
1569// various system calls and libc functions.
1570template <typename T>
1571class SetErrnoAndReturnAction {
1572 public:
1573 SetErrnoAndReturnAction(int errno_value, T result)
1574 : errno_(errno_value),
1575 result_(result) {}
1576 template <typename Result, typename ArgumentTuple>
1577 Result Perform(const ArgumentTuple& /* args */) const {
1578 errno = errno_;
1579 return result_;
1580 }
1581
1582 private:
1583 const int errno_;
1584 const T result_;
1585
1586 GTEST_DISALLOW_ASSIGN_(SetErrnoAndReturnAction);
1587};
1588
1589#endif // !GTEST_OS_WINDOWS_MOBILE
1590
1591// Implements the SetArgumentPointee<N>(x) action for any function
1592// whose N-th argument (0-based) is a pointer to x's type. The
1593// template parameter kIsProto is true iff type A is ProtocolMessage,
1594// proto2::Message, or a sub-class of those.
1595template <size_t N, typename A, bool kIsProto>
1596class SetArgumentPointeeAction {
1597 public:
1598 // Constructs an action that sets the variable pointed to by the
1599 // N-th function argument to 'value'.
1600 explicit SetArgumentPointeeAction(const A& value) : value_(value) {}
1601
1602 template <typename Result, typename ArgumentTuple>
1603 void Perform(const ArgumentTuple& args) const {
1604 CompileAssertTypesEqual<void, Result>();
1605 *::std::tr1::get<N>(args) = value_;
1606 }
1607
1608 private:
1609 const A value_;
1610
1611 GTEST_DISALLOW_ASSIGN_(SetArgumentPointeeAction);
1612};
1613
1614template <size_t N, typename Proto>
1615class SetArgumentPointeeAction<N, Proto, true> {
1616 public:
1617 // Constructs an action that sets the variable pointed to by the
1618 // N-th function argument to 'proto'. Both ProtocolMessage and
1619 // proto2::Message have the CopyFrom() method, so the same
1620 // implementation works for both.
1621 explicit SetArgumentPointeeAction(const Proto& proto) : proto_(new Proto) {
1622 proto_->CopyFrom(proto);
1623 }
1624
1625 template <typename Result, typename ArgumentTuple>
1626 void Perform(const ArgumentTuple& args) const {
1627 CompileAssertTypesEqual<void, Result>();
1628 ::std::tr1::get<N>(args)->CopyFrom(*proto_);
1629 }
1630
1631 private:
1632 const internal::linked_ptr<Proto> proto_;
1633
1634 GTEST_DISALLOW_ASSIGN_(SetArgumentPointeeAction);
1635};
1636
1637// Implements the InvokeWithoutArgs(f) action. The template argument
1638// FunctionImpl is the implementation type of f, which can be either a
1639// function pointer or a functor. InvokeWithoutArgs(f) can be used as an
1640// Action<F> as long as f's type is compatible with F (i.e. f can be
1641// assigned to a tr1::function<F>).
1642template <typename FunctionImpl>
1643class InvokeWithoutArgsAction {
1644 public:
1645 // The c'tor makes a copy of function_impl (either a function
1646 // pointer or a functor).
1647 explicit InvokeWithoutArgsAction(FunctionImpl function_impl)
1648 : function_impl_(function_impl) {}
1649
1650 // Allows InvokeWithoutArgs(f) to be used as any action whose type is
1651 // compatible with f.
1652 template <typename Result, typename ArgumentTuple>
1653 Result Perform(const ArgumentTuple&) { return function_impl_(); }
1654
1655 private:
1656 FunctionImpl function_impl_;
1657
1658 GTEST_DISALLOW_ASSIGN_(InvokeWithoutArgsAction);
1659};
1660
1661// Implements the InvokeWithoutArgs(object_ptr, &Class::Method) action.
1662template <class Class, typename MethodPtr>
1663class InvokeMethodWithoutArgsAction {
1664 public:
1665 InvokeMethodWithoutArgsAction(Class* obj_ptr, MethodPtr method_ptr)
1666 : obj_ptr_(obj_ptr), method_ptr_(method_ptr) {}
1667
1668 template <typename Result, typename ArgumentTuple>
1669 Result Perform(const ArgumentTuple&) const {
1670 return (obj_ptr_->*method_ptr_)();
1671 }
1672
1673 private:
1674 Class* const obj_ptr_;
1675 const MethodPtr method_ptr_;
1676
1677 GTEST_DISALLOW_ASSIGN_(InvokeMethodWithoutArgsAction);
1678};
1679
1680// Implements the IgnoreResult(action) action.
1681template <typename A>
1682class IgnoreResultAction {
1683 public:
1684 explicit IgnoreResultAction(const A& action) : action_(action) {}
1685
1686 template <typename F>
1687 operator Action<F>() const {
1688 // Assert statement belongs here because this is the best place to verify
1689 // conditions on F. It produces the clearest error messages
1690 // in most compilers.
1691 // Impl really belongs in this scope as a local class but can't
1692 // because MSVC produces duplicate symbols in different translation units
1693 // in this case. Until MS fixes that bug we put Impl into the class scope
1694 // and put the typedef both here (for use in assert statement) and
1695 // in the Impl class. But both definitions must be the same.
1696 typedef typename internal::Function<F>::Result Result;
1697
1698 // Asserts at compile time that F returns void.
1699 CompileAssertTypesEqual<void, Result>();
1700
1701 return Action<F>(new Impl<F>(action_));
1702 }
1703
1704 private:
1705 template <typename F>
1706 class Impl : public ActionInterface<F> {
1707 public:
1708 typedef typename internal::Function<F>::Result Result;
1709 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
1710
1711 explicit Impl(const A& action) : action_(action) {}
1712
1713 virtual void Perform(const ArgumentTuple& args) {
1714 // Performs the action and ignores its result.
1715 action_.Perform(args);
1716 }
1717
1718 private:
1719 // Type OriginalFunction is the same as F except that its return
1720 // type is IgnoredValue.
1721 typedef typename internal::Function<F>::MakeResultIgnoredValue
1722 OriginalFunction;
1723
1724 const Action<OriginalFunction> action_;
1725
1726 GTEST_DISALLOW_ASSIGN_(Impl);
1727 };
1728
1729 const A action_;
1730
1731 GTEST_DISALLOW_ASSIGN_(IgnoreResultAction);
1732};
1733
1734// A ReferenceWrapper<T> object represents a reference to type T,
1735// which can be either const or not. It can be explicitly converted
1736// from, and implicitly converted to, a T&. Unlike a reference,
1737// ReferenceWrapper<T> can be copied and can survive template type
1738// inference. This is used to support by-reference arguments in the
1739// InvokeArgument<N>(...) action. The idea was from "reference
1740// wrappers" in tr1, which we don't have in our source tree yet.
1741template <typename T>
1742class ReferenceWrapper {
1743 public:
1744 // Constructs a ReferenceWrapper<T> object from a T&.
1745 explicit ReferenceWrapper(T& l_value) : pointer_(&l_value) {} // NOLINT
1746
1747 // Allows a ReferenceWrapper<T> object to be implicitly converted to
1748 // a T&.
1749 operator T&() const { return *pointer_; }
1750 private:
1751 T* pointer_;
1752};
1753
1754// Allows the expression ByRef(x) to be printed as a reference to x.
1755template <typename T>
1756void PrintTo(const ReferenceWrapper<T>& ref, ::std::ostream* os) {
1757 T& value = ref;
1758 UniversalPrinter<T&>::Print(value, os);
1759}
1760
1761// Does two actions sequentially. Used for implementing the DoAll(a1,
1762// a2, ...) action.
1763template <typename Action1, typename Action2>
1764class DoBothAction {
1765 public:
1766 DoBothAction(Action1 action1, Action2 action2)
1767 : action1_(action1), action2_(action2) {}
1768
1769 // This template type conversion operator allows DoAll(a1, ..., a_n)
1770 // to be used in ANY function of compatible type.
1771 template <typename F>
1772 operator Action<F>() const {
1773 return Action<F>(new Impl<F>(action1_, action2_));
1774 }
1775
1776 private:
1777 // Implements the DoAll(...) action for a particular function type F.
1778 template <typename F>
1779 class Impl : public ActionInterface<F> {
1780 public:
1781 typedef typename Function<F>::Result Result;
1782 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
1783 typedef typename Function<F>::MakeResultVoid VoidResult;
1784
1785 Impl(const Action<VoidResult>& action1, const Action<F>& action2)
1786 : action1_(action1), action2_(action2) {}
1787
1788 virtual Result Perform(const ArgumentTuple& args) {
1789 action1_.Perform(args);
1790 return action2_.Perform(args);
1791 }
1792
1793 private:
1794 const Action<VoidResult> action1_;
1795 const Action<F> action2_;
1796
1797 GTEST_DISALLOW_ASSIGN_(Impl);
1798 };
1799
1800 Action1 action1_;
1801 Action2 action2_;
1802
1803 GTEST_DISALLOW_ASSIGN_(DoBothAction);
1804};
1805
1806} // namespace internal
1807
1808// An Unused object can be implicitly constructed from ANY value.
1809// This is handy when defining actions that ignore some or all of the
1810// mock function arguments. For example, given
1811//
1812// MOCK_METHOD3(Foo, double(const string& label, double x, double y));
1813// MOCK_METHOD3(Bar, double(int index, double x, double y));
1814//
1815// instead of
1816//
1817// double DistanceToOriginWithLabel(const string& label, double x, double y) {
1818// return sqrt(x*x + y*y);
1819// }
1820// double DistanceToOriginWithIndex(int index, double x, double y) {
1821// return sqrt(x*x + y*y);
1822// }
1823// ...
1824// EXEPCT_CALL(mock, Foo("abc", _, _))
1825// .WillOnce(Invoke(DistanceToOriginWithLabel));
1826// EXEPCT_CALL(mock, Bar(5, _, _))
1827// .WillOnce(Invoke(DistanceToOriginWithIndex));
1828//
1829// you could write
1830//
1831// // We can declare any uninteresting argument as Unused.
1832// double DistanceToOrigin(Unused, double x, double y) {
1833// return sqrt(x*x + y*y);
1834// }
1835// ...
1836// EXEPCT_CALL(mock, Foo("abc", _, _)).WillOnce(Invoke(DistanceToOrigin));
1837// EXEPCT_CALL(mock, Bar(5, _, _)).WillOnce(Invoke(DistanceToOrigin));
1838typedef internal::IgnoredValue Unused;
1839
1840// This constructor allows us to turn an Action<From> object into an
1841// Action<To>, as long as To's arguments can be implicitly converted
1842// to From's and From's return type cann be implicitly converted to
1843// To's.
1844template <typename To>
1845template <typename From>
1846Action<To>::Action(const Action<From>& from)
1847 : impl_(new internal::ActionAdaptor<To, From>(from)) {}
1848
1849// Creates an action that returns 'value'. 'value' is passed by value
1850// instead of const reference - otherwise Return("string literal")
1851// will trigger a compiler error about using array as initializer.
1852template <typename R>
1853internal::ReturnAction<R> Return(R value) {
1854 return internal::ReturnAction<R>(value);
1855}
1856
1857// Creates an action that returns NULL.
1858inline PolymorphicAction<internal::ReturnNullAction> ReturnNull() {
1859 return MakePolymorphicAction(internal::ReturnNullAction());
1860}
1861
1862// Creates an action that returns from a void function.
1863inline PolymorphicAction<internal::ReturnVoidAction> Return() {
1864 return MakePolymorphicAction(internal::ReturnVoidAction());
1865}
1866
1867// Creates an action that returns the reference to a variable.
1868template <typename R>
1869inline internal::ReturnRefAction<R> ReturnRef(R& x) { // NOLINT
1870 return internal::ReturnRefAction<R>(x);
1871}
1872
1873// Creates an action that returns the reference to a copy of the
1874// argument. The copy is created when the action is constructed and
1875// lives as long as the action.
1876template <typename R>
1877inline internal::ReturnRefOfCopyAction<R> ReturnRefOfCopy(const R& x) {
1878 return internal::ReturnRefOfCopyAction<R>(x);
1879}
1880
1881// Creates an action that does the default action for the give mock function.
1882inline internal::DoDefaultAction DoDefault() {
1883 return internal::DoDefaultAction();
1884}
1885
1886// Creates an action that sets the variable pointed by the N-th
1887// (0-based) function argument to 'value'.
1888template <size_t N, typename T>
1889PolymorphicAction<
1890 internal::SetArgumentPointeeAction<
1891 N, T, internal::IsAProtocolMessage<T>::value> >
1892SetArgPointee(const T& x) {
1893 return MakePolymorphicAction(internal::SetArgumentPointeeAction<
1894 N, T, internal::IsAProtocolMessage<T>::value>(x));
1895}
1896
1897#if !((GTEST_GCC_VER_ && GTEST_GCC_VER_ < 40000) || GTEST_OS_SYMBIAN)
1898// This overload allows SetArgPointee() to accept a string literal.
1899// GCC prior to the version 4.0 and Symbian C++ compiler cannot distinguish
1900// this overload from the templated version and emit a compile error.
1901template <size_t N>
1902PolymorphicAction<
1903 internal::SetArgumentPointeeAction<N, const char*, false> >
1904SetArgPointee(const char* p) {
1905 return MakePolymorphicAction(internal::SetArgumentPointeeAction<
1906 N, const char*, false>(p));
1907}
1908
1909template <size_t N>
1910PolymorphicAction<
1911 internal::SetArgumentPointeeAction<N, const wchar_t*, false> >
1912SetArgPointee(const wchar_t* p) {
1913 return MakePolymorphicAction(internal::SetArgumentPointeeAction<
1914 N, const wchar_t*, false>(p));
1915}
1916#endif
1917
1918// The following version is DEPRECATED.
1919template <size_t N, typename T>
1920PolymorphicAction<
1921 internal::SetArgumentPointeeAction<
1922 N, T, internal::IsAProtocolMessage<T>::value> >
1923SetArgumentPointee(const T& x) {
1924 return MakePolymorphicAction(internal::SetArgumentPointeeAction<
1925 N, T, internal::IsAProtocolMessage<T>::value>(x));
1926}
1927
1928// Creates an action that sets a pointer referent to a given value.
1929template <typename T1, typename T2>
1930PolymorphicAction<internal::AssignAction<T1, T2> > Assign(T1* ptr, T2 val) {
1931 return MakePolymorphicAction(internal::AssignAction<T1, T2>(ptr, val));
1932}
1933
1934#if !GTEST_OS_WINDOWS_MOBILE
1935
1936// Creates an action that sets errno and returns the appropriate error.
1937template <typename T>
1938PolymorphicAction<internal::SetErrnoAndReturnAction<T> >
1939SetErrnoAndReturn(int errval, T result) {
1940 return MakePolymorphicAction(
1941 internal::SetErrnoAndReturnAction<T>(errval, result));
1942}
1943
1944#endif // !GTEST_OS_WINDOWS_MOBILE
1945
1946// Various overloads for InvokeWithoutArgs().
1947
1948// Creates an action that invokes 'function_impl' with no argument.
1949template <typename FunctionImpl>
1950PolymorphicAction<internal::InvokeWithoutArgsAction<FunctionImpl> >
1951InvokeWithoutArgs(FunctionImpl function_impl) {
1952 return MakePolymorphicAction(
1953 internal::InvokeWithoutArgsAction<FunctionImpl>(function_impl));
1954}
1955
1956// Creates an action that invokes the given method on the given object
1957// with no argument.
1958template <class Class, typename MethodPtr>
1959PolymorphicAction<internal::InvokeMethodWithoutArgsAction<Class, MethodPtr> >
1960InvokeWithoutArgs(Class* obj_ptr, MethodPtr method_ptr) {
1961 return MakePolymorphicAction(
1962 internal::InvokeMethodWithoutArgsAction<Class, MethodPtr>(
1963 obj_ptr, method_ptr));
1964}
1965
1966// Creates an action that performs an_action and throws away its
1967// result. In other words, it changes the return type of an_action to
1968// void. an_action MUST NOT return void, or the code won't compile.
1969template <typename A>
1970inline internal::IgnoreResultAction<A> IgnoreResult(const A& an_action) {
1971 return internal::IgnoreResultAction<A>(an_action);
1972}
1973
1974// Creates a reference wrapper for the given L-value. If necessary,
1975// you can explicitly specify the type of the reference. For example,
1976// suppose 'derived' is an object of type Derived, ByRef(derived)
1977// would wrap a Derived&. If you want to wrap a const Base& instead,
1978// where Base is a base class of Derived, just write:
1979//
1980// ByRef<const Base>(derived)
1981template <typename T>
1982inline internal::ReferenceWrapper<T> ByRef(T& l_value) { // NOLINT
1983 return internal::ReferenceWrapper<T>(l_value);
1984}
1985
1986} // namespace testing
1987
1988#endif // GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
1989// Copyright 2007, Google Inc.
1990// All rights reserved.
1991//
1992// Redistribution and use in source and binary forms, with or without
1993// modification, are permitted provided that the following conditions are
1994// met:
1995//
1996// * Redistributions of source code must retain the above copyright
1997// notice, this list of conditions and the following disclaimer.
1998// * Redistributions in binary form must reproduce the above
1999// copyright notice, this list of conditions and the following disclaimer
2000// in the documentation and/or other materials provided with the
2001// distribution.
2002// * Neither the name of Google Inc. nor the names of its
2003// contributors may be used to endorse or promote products derived from
2004// this software without specific prior written permission.
2005//
2006// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2007// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2008// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2009// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2010// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2011// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2012// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2013// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2014// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2015// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2016// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2017//
2018// Author: wan@google.com (Zhanyong Wan)
2019
2020// Google Mock - a framework for writing C++ mock classes.
2021//
2022// This file implements some commonly used cardinalities. More
2023// cardinalities can be defined by the user implementing the
2024// CardinalityInterface interface if necessary.
2025
2026#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_
2027#define GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_
2028
2029#include <limits.h>
2030#include <ostream> // NOLINT
2031
2032namespace testing {
2033
2034// To implement a cardinality Foo, define:
2035// 1. a class FooCardinality that implements the
2036// CardinalityInterface interface, and
2037// 2. a factory function that creates a Cardinality object from a
2038// const FooCardinality*.
2039//
2040// The two-level delegation design follows that of Matcher, providing
2041// consistency for extension developers. It also eases ownership
2042// management as Cardinality objects can now be copied like plain values.
2043
2044// The implementation of a cardinality.
2045class CardinalityInterface {
2046 public:
2047 virtual ~CardinalityInterface() {}
2048
2049 // Conservative estimate on the lower/upper bound of the number of
2050 // calls allowed.
2051 virtual int ConservativeLowerBound() const { return 0; }
2052 virtual int ConservativeUpperBound() const { return INT_MAX; }
2053
2054 // Returns true iff call_count calls will satisfy this cardinality.
2055 virtual bool IsSatisfiedByCallCount(int call_count) const = 0;
2056
2057 // Returns true iff call_count calls will saturate this cardinality.
2058 virtual bool IsSaturatedByCallCount(int call_count) const = 0;
2059
2060 // Describes self to an ostream.
2061 virtual void DescribeTo(::std::ostream* os) const = 0;
2062};
2063
2064// A Cardinality is a copyable and IMMUTABLE (except by assignment)
2065// object that specifies how many times a mock function is expected to
2066// be called. The implementation of Cardinality is just a linked_ptr
2067// to const CardinalityInterface, so copying is fairly cheap.
2068// Don't inherit from Cardinality!
2069class GTEST_API_ Cardinality {
2070 public:
2071 // Constructs a null cardinality. Needed for storing Cardinality
2072 // objects in STL containers.
2073 Cardinality() {}
2074
2075 // Constructs a Cardinality from its implementation.
2076 explicit Cardinality(const CardinalityInterface* impl) : impl_(impl) {}
2077
2078 // Conservative estimate on the lower/upper bound of the number of
2079 // calls allowed.
2080 int ConservativeLowerBound() const { return impl_->ConservativeLowerBound(); }
2081 int ConservativeUpperBound() const { return impl_->ConservativeUpperBound(); }
2082
2083 // Returns true iff call_count calls will satisfy this cardinality.
2084 bool IsSatisfiedByCallCount(int call_count) const {
2085 return impl_->IsSatisfiedByCallCount(call_count);
2086 }
2087
2088 // Returns true iff call_count calls will saturate this cardinality.
2089 bool IsSaturatedByCallCount(int call_count) const {
2090 return impl_->IsSaturatedByCallCount(call_count);
2091 }
2092
2093 // Returns true iff call_count calls will over-saturate this
2094 // cardinality, i.e. exceed the maximum number of allowed calls.
2095 bool IsOverSaturatedByCallCount(int call_count) const {
2096 return impl_->IsSaturatedByCallCount(call_count) &&
2097 !impl_->IsSatisfiedByCallCount(call_count);
2098 }
2099
2100 // Describes self to an ostream
2101 void DescribeTo(::std::ostream* os) const { impl_->DescribeTo(os); }
2102
2103 // Describes the given actual call count to an ostream.
2104 static void DescribeActualCallCountTo(int actual_call_count,
2105 ::std::ostream* os);
2106
2107 private:
2108 internal::linked_ptr<const CardinalityInterface> impl_;
2109};
2110
2111// Creates a cardinality that allows at least n calls.
2112GTEST_API_ Cardinality AtLeast(int n);
2113
2114// Creates a cardinality that allows at most n calls.
2115GTEST_API_ Cardinality AtMost(int n);
2116
2117// Creates a cardinality that allows any number of calls.
2118GTEST_API_ Cardinality AnyNumber();
2119
2120// Creates a cardinality that allows between min and max calls.
2121GTEST_API_ Cardinality Between(int min, int max);
2122
2123// Creates a cardinality that allows exactly n calls.
2124GTEST_API_ Cardinality Exactly(int n);
2125
2126// Creates a cardinality from its implementation.
2127inline Cardinality MakeCardinality(const CardinalityInterface* c) {
2128 return Cardinality(c);
2129}
2130
2131} // namespace testing
2132
2133#endif // GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_
2134// This file was GENERATED by a script. DO NOT EDIT BY HAND!!!
2135
2136// Copyright 2007, Google Inc.
2137// All rights reserved.
2138//
2139// Redistribution and use in source and binary forms, with or without
2140// modification, are permitted provided that the following conditions are
2141// met:
2142//
2143// * Redistributions of source code must retain the above copyright
2144// notice, this list of conditions and the following disclaimer.
2145// * Redistributions in binary form must reproduce the above
2146// copyright notice, this list of conditions and the following disclaimer
2147// in the documentation and/or other materials provided with the
2148// distribution.
2149// * Neither the name of Google Inc. nor the names of its
2150// contributors may be used to endorse or promote products derived from
2151// this software without specific prior written permission.
2152//
2153// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2154// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2155// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2156// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2157// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2158// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2159// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2160// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2161// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2162// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2163// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2164//
2165// Author: wan@google.com (Zhanyong Wan)
2166
2167// Google Mock - a framework for writing C++ mock classes.
2168//
2169// This file implements some commonly used variadic actions.
2170
2171#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
2172#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
2173
2174
2175namespace testing {
2176namespace internal {
2177
2178// InvokeHelper<F> knows how to unpack an N-tuple and invoke an N-ary
2179// function or method with the unpacked values, where F is a function
2180// type that takes N arguments.
2181template <typename Result, typename ArgumentTuple>
2182class InvokeHelper;
2183
2184template <typename R>
2185class InvokeHelper<R, ::std::tr1::tuple<> > {
2186 public:
2187 template <typename Function>
2188 static R Invoke(Function function, const ::std::tr1::tuple<>&) {
2189 return function();
2190 }
2191
2192 template <class Class, typename MethodPtr>
2193 static R InvokeMethod(Class* obj_ptr,
2194 MethodPtr method_ptr,
2195 const ::std::tr1::tuple<>&) {
2196 return (obj_ptr->*method_ptr)();
2197 }
2198};
2199
2200template <typename R, typename A1>
2201class InvokeHelper<R, ::std::tr1::tuple<A1> > {
2202 public:
2203 template <typename Function>
2204 static R Invoke(Function function, const ::std::tr1::tuple<A1>& args) {
2205 using ::std::tr1::get;
2206 return function(get<0>(args));
2207 }
2208
2209 template <class Class, typename MethodPtr>
2210 static R InvokeMethod(Class* obj_ptr,
2211 MethodPtr method_ptr,
2212 const ::std::tr1::tuple<A1>& args) {
2213 using ::std::tr1::get;
2214 return (obj_ptr->*method_ptr)(get<0>(args));
2215 }
2216};
2217
2218template <typename R, typename A1, typename A2>
2219class InvokeHelper<R, ::std::tr1::tuple<A1, A2> > {
2220 public:
2221 template <typename Function>
2222 static R Invoke(Function function, const ::std::tr1::tuple<A1, A2>& args) {
2223 using ::std::tr1::get;
2224 return function(get<0>(args), get<1>(args));
2225 }
2226
2227 template <class Class, typename MethodPtr>
2228 static R InvokeMethod(Class* obj_ptr,
2229 MethodPtr method_ptr,
2230 const ::std::tr1::tuple<A1, A2>& args) {
2231 using ::std::tr1::get;
2232 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args));
2233 }
2234};
2235
2236template <typename R, typename A1, typename A2, typename A3>
2237class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3> > {
2238 public:
2239 template <typename Function>
2240 static R Invoke(Function function, const ::std::tr1::tuple<A1, A2,
2241 A3>& args) {
2242 using ::std::tr1::get;
2243 return function(get<0>(args), get<1>(args), get<2>(args));
2244 }
2245
2246 template <class Class, typename MethodPtr>
2247 static R InvokeMethod(Class* obj_ptr,
2248 MethodPtr method_ptr,
2249 const ::std::tr1::tuple<A1, A2, A3>& args) {
2250 using ::std::tr1::get;
2251 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args));
2252 }
2253};
2254
2255template <typename R, typename A1, typename A2, typename A3, typename A4>
2256class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4> > {
2257 public:
2258 template <typename Function>
2259 static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3,
2260 A4>& args) {
2261 using ::std::tr1::get;
2262 return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args));
2263 }
2264
2265 template <class Class, typename MethodPtr>
2266 static R InvokeMethod(Class* obj_ptr,
2267 MethodPtr method_ptr,
2268 const ::std::tr1::tuple<A1, A2, A3, A4>& args) {
2269 using ::std::tr1::get;
2270 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args),
2271 get<3>(args));
2272 }
2273};
2274
2275template <typename R, typename A1, typename A2, typename A3, typename A4,
2276 typename A5>
2277class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5> > {
2278 public:
2279 template <typename Function>
2280 static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4,
2281 A5>& args) {
2282 using ::std::tr1::get;
2283 return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args),
2284 get<4>(args));
2285 }
2286
2287 template <class Class, typename MethodPtr>
2288 static R InvokeMethod(Class* obj_ptr,
2289 MethodPtr method_ptr,
2290 const ::std::tr1::tuple<A1, A2, A3, A4, A5>& args) {
2291 using ::std::tr1::get;
2292 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args),
2293 get<3>(args), get<4>(args));
2294 }
2295};
2296
2297template <typename R, typename A1, typename A2, typename A3, typename A4,
2298 typename A5, typename A6>
2299class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5, A6> > {
2300 public:
2301 template <typename Function>
2302 static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4,
2303 A5, A6>& args) {
2304 using ::std::tr1::get;
2305 return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args),
2306 get<4>(args), get<5>(args));
2307 }
2308
2309 template <class Class, typename MethodPtr>
2310 static R InvokeMethod(Class* obj_ptr,
2311 MethodPtr method_ptr,
2312 const ::std::tr1::tuple<A1, A2, A3, A4, A5, A6>& args) {
2313 using ::std::tr1::get;
2314 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args),
2315 get<3>(args), get<4>(args), get<5>(args));
2316 }
2317};
2318
2319template <typename R, typename A1, typename A2, typename A3, typename A4,
2320 typename A5, typename A6, typename A7>
2321class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7> > {
2322 public:
2323 template <typename Function>
2324 static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4,
2325 A5, A6, A7>& args) {
2326 using ::std::tr1::get;
2327 return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args),
2328 get<4>(args), get<5>(args), get<6>(args));
2329 }
2330
2331 template <class Class, typename MethodPtr>
2332 static R InvokeMethod(Class* obj_ptr,
2333 MethodPtr method_ptr,
2334 const ::std::tr1::tuple<A1, A2, A3, A4, A5, A6,
2335 A7>& args) {
2336 using ::std::tr1::get;
2337 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args),
2338 get<3>(args), get<4>(args), get<5>(args), get<6>(args));
2339 }
2340};
2341
2342template <typename R, typename A1, typename A2, typename A3, typename A4,
2343 typename A5, typename A6, typename A7, typename A8>
2344class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8> > {
2345 public:
2346 template <typename Function>
2347 static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4,
2348 A5, A6, A7, A8>& args) {
2349 using ::std::tr1::get;
2350 return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args),
2351 get<4>(args), get<5>(args), get<6>(args), get<7>(args));
2352 }
2353
2354 template <class Class, typename MethodPtr>
2355 static R InvokeMethod(Class* obj_ptr,
2356 MethodPtr method_ptr,
2357 const ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7,
2358 A8>& args) {
2359 using ::std::tr1::get;
2360 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args),
2361 get<3>(args), get<4>(args), get<5>(args), get<6>(args), get<7>(args));
2362 }
2363};
2364
2365template <typename R, typename A1, typename A2, typename A3, typename A4,
2366 typename A5, typename A6, typename A7, typename A8, typename A9>
2367class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9> > {
2368 public:
2369 template <typename Function>
2370 static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4,
2371 A5, A6, A7, A8, A9>& args) {
2372 using ::std::tr1::get;
2373 return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args),
2374 get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args));
2375 }
2376
2377 template <class Class, typename MethodPtr>
2378 static R InvokeMethod(Class* obj_ptr,
2379 MethodPtr method_ptr,
2380 const ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8,
2381 A9>& args) {
2382 using ::std::tr1::get;
2383 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args),
2384 get<3>(args), get<4>(args), get<5>(args), get<6>(args), get<7>(args),
2385 get<8>(args));
2386 }
2387};
2388
2389template <typename R, typename A1, typename A2, typename A3, typename A4,
2390 typename A5, typename A6, typename A7, typename A8, typename A9,
2391 typename A10>
2392class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9,
2393 A10> > {
2394 public:
2395 template <typename Function>
2396 static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4,
2397 A5, A6, A7, A8, A9, A10>& args) {
2398 using ::std::tr1::get;
2399 return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args),
2400 get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args),
2401 get<9>(args));
2402 }
2403
2404 template <class Class, typename MethodPtr>
2405 static R InvokeMethod(Class* obj_ptr,
2406 MethodPtr method_ptr,
2407 const ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8,
2408 A9, A10>& args) {
2409 using ::std::tr1::get;
2410 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args),
2411 get<3>(args), get<4>(args), get<5>(args), get<6>(args), get<7>(args),
2412 get<8>(args), get<9>(args));
2413 }
2414};
2415
2416// CallableHelper has static methods for invoking "callables",
2417// i.e. function pointers and functors. It uses overloading to
2418// provide a uniform interface for invoking different kinds of
2419// callables. In particular, you can use:
2420//
2421// CallableHelper<R>::Call(callable, a1, a2, ..., an)
2422//
2423// to invoke an n-ary callable, where R is its return type. If an
2424// argument, say a2, needs to be passed by reference, you should write
2425// ByRef(a2) instead of a2 in the above expression.
2426template <typename R>
2427class CallableHelper {
2428 public:
2429 // Calls a nullary callable.
2430 template <typename Function>
2431 static R Call(Function function) { return function(); }
2432
2433 // Calls a unary callable.
2434
2435 // We deliberately pass a1 by value instead of const reference here
2436 // in case it is a C-string literal. If we had declared the
2437 // parameter as 'const A1& a1' and write Call(function, "Hi"), the
2438 // compiler would've thought A1 is 'char[3]', which causes trouble
2439 // when you need to copy a value of type A1. By declaring the
2440 // parameter as 'A1 a1', the compiler will correctly infer that A1
2441 // is 'const char*' when it sees Call(function, "Hi").
2442 //
2443 // Since this function is defined inline, the compiler can get rid
2444 // of the copying of the arguments. Therefore the performance won't
2445 // be hurt.
2446 template <typename Function, typename A1>
2447 static R Call(Function function, A1 a1) { return function(a1); }
2448
2449 // Calls a binary callable.
2450 template <typename Function, typename A1, typename A2>
2451 static R Call(Function function, A1 a1, A2 a2) {
2452 return function(a1, a2);
2453 }
2454
2455 // Calls a ternary callable.
2456 template <typename Function, typename A1, typename A2, typename A3>
2457 static R Call(Function function, A1 a1, A2 a2, A3 a3) {
2458 return function(a1, a2, a3);
2459 }
2460
2461 // Calls a 4-ary callable.
2462 template <typename Function, typename A1, typename A2, typename A3,
2463 typename A4>
2464 static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4) {
2465 return function(a1, a2, a3, a4);
2466 }
2467
2468 // Calls a 5-ary callable.
2469 template <typename Function, typename A1, typename A2, typename A3,
2470 typename A4, typename A5>
2471 static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) {
2472 return function(a1, a2, a3, a4, a5);
2473 }
2474
2475 // Calls a 6-ary callable.
2476 template <typename Function, typename A1, typename A2, typename A3,
2477 typename A4, typename A5, typename A6>
2478 static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) {
2479 return function(a1, a2, a3, a4, a5, a6);
2480 }
2481
2482 // Calls a 7-ary callable.
2483 template <typename Function, typename A1, typename A2, typename A3,
2484 typename A4, typename A5, typename A6, typename A7>
2485 static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
2486 A7 a7) {
2487 return function(a1, a2, a3, a4, a5, a6, a7);
2488 }
2489
2490 // Calls a 8-ary callable.
2491 template <typename Function, typename A1, typename A2, typename A3,
2492 typename A4, typename A5, typename A6, typename A7, typename A8>
2493 static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
2494 A7 a7, A8 a8) {
2495 return function(a1, a2, a3, a4, a5, a6, a7, a8);
2496 }
2497
2498 // Calls a 9-ary callable.
2499 template <typename Function, typename A1, typename A2, typename A3,
2500 typename A4, typename A5, typename A6, typename A7, typename A8,
2501 typename A9>
2502 static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
2503 A7 a7, A8 a8, A9 a9) {
2504 return function(a1, a2, a3, a4, a5, a6, a7, a8, a9);
2505 }
2506
2507 // Calls a 10-ary callable.
2508 template <typename Function, typename A1, typename A2, typename A3,
2509 typename A4, typename A5, typename A6, typename A7, typename A8,
2510 typename A9, typename A10>
2511 static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
2512 A7 a7, A8 a8, A9 a9, A10 a10) {
2513 return function(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
2514 }
2515}; // class CallableHelper
2516
2517// An INTERNAL macro for extracting the type of a tuple field. It's
2518// subject to change without notice - DO NOT USE IN USER CODE!
2519#define GMOCK_FIELD_(Tuple, N) \
2520 typename ::std::tr1::tuple_element<N, Tuple>::type
2521
2522// SelectArgs<Result, ArgumentTuple, k1, k2, ..., k_n>::type is the
2523// type of an n-ary function whose i-th (1-based) argument type is the
2524// k{i}-th (0-based) field of ArgumentTuple, which must be a tuple
2525// type, and whose return type is Result. For example,
2526// SelectArgs<int, ::std::tr1::tuple<bool, char, double, long>, 0, 3>::type
2527// is int(bool, long).
2528//
2529// SelectArgs<Result, ArgumentTuple, k1, k2, ..., k_n>::Select(args)
2530// returns the selected fields (k1, k2, ..., k_n) of args as a tuple.
2531// For example,
2532// SelectArgs<int, ::std::tr1::tuple<bool, char, double>, 2, 0>::Select(
2533// ::std::tr1::make_tuple(true, 'a', 2.5))
2534// returns ::std::tr1::tuple (2.5, true).
2535//
2536// The numbers in list k1, k2, ..., k_n must be >= 0, where n can be
2537// in the range [0, 10]. Duplicates are allowed and they don't have
2538// to be in an ascending or descending order.
2539
2540template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
2541 int k4, int k5, int k6, int k7, int k8, int k9, int k10>
2542class SelectArgs {
2543 public:
2544 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
2545 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
2546 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5),
2547 GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7),
2548 GMOCK_FIELD_(ArgumentTuple, k8), GMOCK_FIELD_(ArgumentTuple, k9),
2549 GMOCK_FIELD_(ArgumentTuple, k10));
2550 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2551 static SelectedArgs Select(const ArgumentTuple& args) {
2552 using ::std::tr1::get;
2553 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
2554 get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args),
2555 get<k8>(args), get<k9>(args), get<k10>(args));
2556 }
2557};
2558
2559template <typename Result, typename ArgumentTuple>
2560class SelectArgs<Result, ArgumentTuple,
2561 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1> {
2562 public:
2563 typedef Result type();
2564 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2565 static SelectedArgs Select(const ArgumentTuple& /* args */) {
2566 using ::std::tr1::get;
2567 return SelectedArgs();
2568 }
2569};
2570
2571template <typename Result, typename ArgumentTuple, int k1>
2572class SelectArgs<Result, ArgumentTuple,
2573 k1, -1, -1, -1, -1, -1, -1, -1, -1, -1> {
2574 public:
2575 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1));
2576 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2577 static SelectedArgs Select(const ArgumentTuple& args) {
2578 using ::std::tr1::get;
2579 return SelectedArgs(get<k1>(args));
2580 }
2581};
2582
2583template <typename Result, typename ArgumentTuple, int k1, int k2>
2584class SelectArgs<Result, ArgumentTuple,
2585 k1, k2, -1, -1, -1, -1, -1, -1, -1, -1> {
2586 public:
2587 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
2588 GMOCK_FIELD_(ArgumentTuple, k2));
2589 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2590 static SelectedArgs Select(const ArgumentTuple& args) {
2591 using ::std::tr1::get;
2592 return SelectedArgs(get<k1>(args), get<k2>(args));
2593 }
2594};
2595
2596template <typename Result, typename ArgumentTuple, int k1, int k2, int k3>
2597class SelectArgs<Result, ArgumentTuple,
2598 k1, k2, k3, -1, -1, -1, -1, -1, -1, -1> {
2599 public:
2600 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
2601 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3));
2602 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2603 static SelectedArgs Select(const ArgumentTuple& args) {
2604 using ::std::tr1::get;
2605 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args));
2606 }
2607};
2608
2609template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
2610 int k4>
2611class SelectArgs<Result, ArgumentTuple,
2612 k1, k2, k3, k4, -1, -1, -1, -1, -1, -1> {
2613 public:
2614 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
2615 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
2616 GMOCK_FIELD_(ArgumentTuple, k4));
2617 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2618 static SelectedArgs Select(const ArgumentTuple& args) {
2619 using ::std::tr1::get;
2620 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
2621 get<k4>(args));
2622 }
2623};
2624
2625template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
2626 int k4, int k5>
2627class SelectArgs<Result, ArgumentTuple,
2628 k1, k2, k3, k4, k5, -1, -1, -1, -1, -1> {
2629 public:
2630 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
2631 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
2632 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5));
2633 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2634 static SelectedArgs Select(const ArgumentTuple& args) {
2635 using ::std::tr1::get;
2636 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
2637 get<k4>(args), get<k5>(args));
2638 }
2639};
2640
2641template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
2642 int k4, int k5, int k6>
2643class SelectArgs<Result, ArgumentTuple,
2644 k1, k2, k3, k4, k5, k6, -1, -1, -1, -1> {
2645 public:
2646 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
2647 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
2648 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5),
2649 GMOCK_FIELD_(ArgumentTuple, k6));
2650 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2651 static SelectedArgs Select(const ArgumentTuple& args) {
2652 using ::std::tr1::get;
2653 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
2654 get<k4>(args), get<k5>(args), get<k6>(args));
2655 }
2656};
2657
2658template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
2659 int k4, int k5, int k6, int k7>
2660class SelectArgs<Result, ArgumentTuple,
2661 k1, k2, k3, k4, k5, k6, k7, -1, -1, -1> {
2662 public:
2663 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
2664 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
2665 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5),
2666 GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7));
2667 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2668 static SelectedArgs Select(const ArgumentTuple& args) {
2669 using ::std::tr1::get;
2670 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
2671 get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args));
2672 }
2673};
2674
2675template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
2676 int k4, int k5, int k6, int k7, int k8>
2677class SelectArgs<Result, ArgumentTuple,
2678 k1, k2, k3, k4, k5, k6, k7, k8, -1, -1> {
2679 public:
2680 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
2681 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
2682 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5),
2683 GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7),
2684 GMOCK_FIELD_(ArgumentTuple, k8));
2685 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2686 static SelectedArgs Select(const ArgumentTuple& args) {
2687 using ::std::tr1::get;
2688 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
2689 get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args),
2690 get<k8>(args));
2691 }
2692};
2693
2694template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
2695 int k4, int k5, int k6, int k7, int k8, int k9>
2696class SelectArgs<Result, ArgumentTuple,
2697 k1, k2, k3, k4, k5, k6, k7, k8, k9, -1> {
2698 public:
2699 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
2700 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
2701 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5),
2702 GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7),
2703 GMOCK_FIELD_(ArgumentTuple, k8), GMOCK_FIELD_(ArgumentTuple, k9));
2704 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2705 static SelectedArgs Select(const ArgumentTuple& args) {
2706 using ::std::tr1::get;
2707 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
2708 get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args),
2709 get<k8>(args), get<k9>(args));
2710 }
2711};
2712
2713#undef GMOCK_FIELD_
2714
2715// Implements the WithArgs action.
2716template <typename InnerAction, int k1 = -1, int k2 = -1, int k3 = -1,
2717 int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1, int k8 = -1,
2718 int k9 = -1, int k10 = -1>
2719class WithArgsAction {
2720 public:
2721 explicit WithArgsAction(const InnerAction& action) : action_(action) {}
2722
2723 template <typename F>
2724 operator Action<F>() const { return MakeAction(new Impl<F>(action_)); }
2725
2726 private:
2727 template <typename F>
2728 class Impl : public ActionInterface<F> {
2729 public:
2730 typedef typename Function<F>::Result Result;
2731 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
2732
2733 explicit Impl(const InnerAction& action) : action_(action) {}
2734
2735 virtual Result Perform(const ArgumentTuple& args) {
2736 return action_.Perform(SelectArgs<Result, ArgumentTuple, k1, k2, k3, k4,
2737 k5, k6, k7, k8, k9, k10>::Select(args));
2738 }
2739
2740 private:
2741 typedef typename SelectArgs<Result, ArgumentTuple,
2742 k1, k2, k3, k4, k5, k6, k7, k8, k9, k10>::type InnerFunctionType;
2743
2744 Action<InnerFunctionType> action_;
2745 };
2746
2747 const InnerAction action_;
2748
2749 GTEST_DISALLOW_ASSIGN_(WithArgsAction);
2750};
2751
2752// A macro from the ACTION* family (defined later in this file)
2753// defines an action that can be used in a mock function. Typically,
2754// these actions only care about a subset of the arguments of the mock
2755// function. For example, if such an action only uses the second
2756// argument, it can be used in any mock function that takes >= 2
2757// arguments where the type of the second argument is compatible.
2758//
2759// Therefore, the action implementation must be prepared to take more
2760// arguments than it needs. The ExcessiveArg type is used to
2761// represent those excessive arguments. In order to keep the compiler
2762// error messages tractable, we define it in the testing namespace
2763// instead of testing::internal. However, this is an INTERNAL TYPE
2764// and subject to change without notice, so a user MUST NOT USE THIS
2765// TYPE DIRECTLY.
2766struct ExcessiveArg {};
2767
2768// A helper class needed for implementing the ACTION* macros.
2769template <typename Result, class Impl>
2770class ActionHelper {
2771 public:
2772 static Result Perform(Impl* impl, const ::std::tr1::tuple<>& args) {
2773 using ::std::tr1::get;
2774 return impl->template gmock_PerformImpl<>(args, ExcessiveArg(),
2775 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2776 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2777 ExcessiveArg());
2778 }
2779
2780 template <typename A0>
2781 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0>& args) {
2782 using ::std::tr1::get;
2783 return impl->template gmock_PerformImpl<A0>(args, get<0>(args),
2784 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2785 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2786 ExcessiveArg());
2787 }
2788
2789 template <typename A0, typename A1>
2790 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1>& args) {
2791 using ::std::tr1::get;
2792 return impl->template gmock_PerformImpl<A0, A1>(args, get<0>(args),
2793 get<1>(args), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2794 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2795 ExcessiveArg());
2796 }
2797
2798 template <typename A0, typename A1, typename A2>
2799 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2>& args) {
2800 using ::std::tr1::get;
2801 return impl->template gmock_PerformImpl<A0, A1, A2>(args, get<0>(args),
2802 get<1>(args), get<2>(args), ExcessiveArg(), ExcessiveArg(),
2803 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2804 ExcessiveArg());
2805 }
2806
2807 template <typename A0, typename A1, typename A2, typename A3>
2808 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2,
2809 A3>& args) {
2810 using ::std::tr1::get;
2811 return impl->template gmock_PerformImpl<A0, A1, A2, A3>(args, get<0>(args),
2812 get<1>(args), get<2>(args), get<3>(args), ExcessiveArg(),
2813 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2814 ExcessiveArg());
2815 }
2816
2817 template <typename A0, typename A1, typename A2, typename A3, typename A4>
2818 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3,
2819 A4>& args) {
2820 using ::std::tr1::get;
2821 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4>(args,
2822 get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args),
2823 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2824 ExcessiveArg());
2825 }
2826
2827 template <typename A0, typename A1, typename A2, typename A3, typename A4,
2828 typename A5>
2829 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4,
2830 A5>& args) {
2831 using ::std::tr1::get;
2832 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5>(args,
2833 get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args),
2834 get<5>(args), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2835 ExcessiveArg());
2836 }
2837
2838 template <typename A0, typename A1, typename A2, typename A3, typename A4,
2839 typename A5, typename A6>
2840 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4,
2841 A5, A6>& args) {
2842 using ::std::tr1::get;
2843 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6>(args,
2844 get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args),
2845 get<5>(args), get<6>(args), ExcessiveArg(), ExcessiveArg(),
2846 ExcessiveArg());
2847 }
2848
2849 template <typename A0, typename A1, typename A2, typename A3, typename A4,
2850 typename A5, typename A6, typename A7>
2851 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4,
2852 A5, A6, A7>& args) {
2853 using ::std::tr1::get;
2854 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6,
2855 A7>(args, get<0>(args), get<1>(args), get<2>(args), get<3>(args),
2856 get<4>(args), get<5>(args), get<6>(args), get<7>(args), ExcessiveArg(),
2857 ExcessiveArg());
2858 }
2859
2860 template <typename A0, typename A1, typename A2, typename A3, typename A4,
2861 typename A5, typename A6, typename A7, typename A8>
2862 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4,
2863 A5, A6, A7, A8>& args) {
2864 using ::std::tr1::get;
2865 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6, A7,
2866 A8>(args, get<0>(args), get<1>(args), get<2>(args), get<3>(args),
2867 get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args),
2868 ExcessiveArg());
2869 }
2870
2871 template <typename A0, typename A1, typename A2, typename A3, typename A4,
2872 typename A5, typename A6, typename A7, typename A8, typename A9>
2873 static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4,
2874 A5, A6, A7, A8, A9>& args) {
2875 using ::std::tr1::get;
2876 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6, A7, A8,
2877 A9>(args, get<0>(args), get<1>(args), get<2>(args), get<3>(args),
2878 get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args),
2879 get<9>(args));
2880 }
2881};
2882
2883} // namespace internal
2884
2885// Various overloads for Invoke().
2886
2887// WithArgs<N1, N2, ..., Nk>(an_action) creates an action that passes
2888// the selected arguments of the mock function to an_action and
2889// performs it. It serves as an adaptor between actions with
2890// different argument lists. C++ doesn't support default arguments for
2891// function templates, so we have to overload it.
2892template <int k1, typename InnerAction>
2893inline internal::WithArgsAction<InnerAction, k1>
2894WithArgs(const InnerAction& action) {
2895 return internal::WithArgsAction<InnerAction, k1>(action);
2896}
2897
2898template <int k1, int k2, typename InnerAction>
2899inline internal::WithArgsAction<InnerAction, k1, k2>
2900WithArgs(const InnerAction& action) {
2901 return internal::WithArgsAction<InnerAction, k1, k2>(action);
2902}
2903
2904template <int k1, int k2, int k3, typename InnerAction>
2905inline internal::WithArgsAction<InnerAction, k1, k2, k3>
2906WithArgs(const InnerAction& action) {
2907 return internal::WithArgsAction<InnerAction, k1, k2, k3>(action);
2908}
2909
2910template <int k1, int k2, int k3, int k4, typename InnerAction>
2911inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4>
2912WithArgs(const InnerAction& action) {
2913 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4>(action);
2914}
2915
2916template <int k1, int k2, int k3, int k4, int k5, typename InnerAction>
2917inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5>
2918WithArgs(const InnerAction& action) {
2919 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5>(action);
2920}
2921
2922template <int k1, int k2, int k3, int k4, int k5, int k6, typename InnerAction>
2923inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6>
2924WithArgs(const InnerAction& action) {
2925 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6>(action);
2926}
2927
2928template <int k1, int k2, int k3, int k4, int k5, int k6, int k7,
2929 typename InnerAction>
2930inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7>
2931WithArgs(const InnerAction& action) {
2932 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6,
2933 k7>(action);
2934}
2935
2936template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
2937 typename InnerAction>
2938inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8>
2939WithArgs(const InnerAction& action) {
2940 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7,
2941 k8>(action);
2942}
2943
2944template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
2945 int k9, typename InnerAction>
2946inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8, k9>
2947WithArgs(const InnerAction& action) {
2948 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8,
2949 k9>(action);
2950}
2951
2952template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
2953 int k9, int k10, typename InnerAction>
2954inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8,
2955 k9, k10>
2956WithArgs(const InnerAction& action) {
2957 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8,
2958 k9, k10>(action);
2959}
2960
2961// Creates an action that does actions a1, a2, ..., sequentially in
2962// each invocation.
2963template <typename Action1, typename Action2>
2964inline internal::DoBothAction<Action1, Action2>
2965DoAll(Action1 a1, Action2 a2) {
2966 return internal::DoBothAction<Action1, Action2>(a1, a2);
2967}
2968
2969template <typename Action1, typename Action2, typename Action3>
2970inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
2971 Action3> >
2972DoAll(Action1 a1, Action2 a2, Action3 a3) {
2973 return DoAll(a1, DoAll(a2, a3));
2974}
2975
2976template <typename Action1, typename Action2, typename Action3,
2977 typename Action4>
2978inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
2979 internal::DoBothAction<Action3, Action4> > >
2980DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4) {
2981 return DoAll(a1, DoAll(a2, a3, a4));
2982}
2983
2984template <typename Action1, typename Action2, typename Action3,
2985 typename Action4, typename Action5>
2986inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
2987 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
2988 Action5> > > >
2989DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5) {
2990 return DoAll(a1, DoAll(a2, a3, a4, a5));
2991}
2992
2993template <typename Action1, typename Action2, typename Action3,
2994 typename Action4, typename Action5, typename Action6>
2995inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
2996 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
2997 internal::DoBothAction<Action5, Action6> > > > >
2998DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6) {
2999 return DoAll(a1, DoAll(a2, a3, a4, a5, a6));
3000}
3001
3002template <typename Action1, typename Action2, typename Action3,
3003 typename Action4, typename Action5, typename Action6, typename Action7>
3004inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
3005 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
3006 internal::DoBothAction<Action5, internal::DoBothAction<Action6,
3007 Action7> > > > > >
3008DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
3009 Action7 a7) {
3010 return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7));
3011}
3012
3013template <typename Action1, typename Action2, typename Action3,
3014 typename Action4, typename Action5, typename Action6, typename Action7,
3015 typename Action8>
3016inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
3017 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
3018 internal::DoBothAction<Action5, internal::DoBothAction<Action6,
3019 internal::DoBothAction<Action7, Action8> > > > > > >
3020DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
3021 Action7 a7, Action8 a8) {
3022 return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8));
3023}
3024
3025template <typename Action1, typename Action2, typename Action3,
3026 typename Action4, typename Action5, typename Action6, typename Action7,
3027 typename Action8, typename Action9>
3028inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
3029 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
3030 internal::DoBothAction<Action5, internal::DoBothAction<Action6,
3031 internal::DoBothAction<Action7, internal::DoBothAction<Action8,
3032 Action9> > > > > > > >
3033DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
3034 Action7 a7, Action8 a8, Action9 a9) {
3035 return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8, a9));
3036}
3037
3038template <typename Action1, typename Action2, typename Action3,
3039 typename Action4, typename Action5, typename Action6, typename Action7,
3040 typename Action8, typename Action9, typename Action10>
3041inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
3042 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
3043 internal::DoBothAction<Action5, internal::DoBothAction<Action6,
3044 internal::DoBothAction<Action7, internal::DoBothAction<Action8,
3045 internal::DoBothAction<Action9, Action10> > > > > > > > >
3046DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
3047 Action7 a7, Action8 a8, Action9 a9, Action10 a10) {
3048 return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8, a9, a10));
3049}
3050
3051} // namespace testing
3052
3053// The ACTION* family of macros can be used in a namespace scope to
3054// define custom actions easily. The syntax:
3055//
3056// ACTION(name) { statements; }
3057//
3058// will define an action with the given name that executes the
3059// statements. The value returned by the statements will be used as
3060// the return value of the action. Inside the statements, you can
3061// refer to the K-th (0-based) argument of the mock function by
3062// 'argK', and refer to its type by 'argK_type'. For example:
3063//
3064// ACTION(IncrementArg1) {
3065// arg1_type temp = arg1;
3066// return ++(*temp);
3067// }
3068//
3069// allows you to write
3070//
3071// ...WillOnce(IncrementArg1());
3072//
3073// You can also refer to the entire argument tuple and its type by
3074// 'args' and 'args_type', and refer to the mock function type and its
3075// return type by 'function_type' and 'return_type'.
3076//
3077// Note that you don't need to specify the types of the mock function
3078// arguments. However rest assured that your code is still type-safe:
3079// you'll get a compiler error if *arg1 doesn't support the ++
3080// operator, or if the type of ++(*arg1) isn't compatible with the
3081// mock function's return type, for example.
3082//
3083// Sometimes you'll want to parameterize the action. For that you can use
3084// another macro:
3085//
3086// ACTION_P(name, param_name) { statements; }
3087//
3088// For example:
3089//
3090// ACTION_P(Add, n) { return arg0 + n; }
3091//
3092// will allow you to write:
3093//
3094// ...WillOnce(Add(5));
3095//
3096// Note that you don't need to provide the type of the parameter
3097// either. If you need to reference the type of a parameter named
3098// 'foo', you can write 'foo_type'. For example, in the body of
3099// ACTION_P(Add, n) above, you can write 'n_type' to refer to the type
3100// of 'n'.
3101//
3102// We also provide ACTION_P2, ACTION_P3, ..., up to ACTION_P10 to support
3103// multi-parameter actions.
3104//
3105// For the purpose of typing, you can view
3106//
3107// ACTION_Pk(Foo, p1, ..., pk) { ... }
3108//
3109// as shorthand for
3110//
3111// template <typename p1_type, ..., typename pk_type>
3112// FooActionPk<p1_type, ..., pk_type> Foo(p1_type p1, ..., pk_type pk) { ... }
3113//
3114// In particular, you can provide the template type arguments
3115// explicitly when invoking Foo(), as in Foo<long, bool>(5, false);
3116// although usually you can rely on the compiler to infer the types
3117// for you automatically. You can assign the result of expression
3118// Foo(p1, ..., pk) to a variable of type FooActionPk<p1_type, ...,
3119// pk_type>. This can be useful when composing actions.
3120//
3121// You can also overload actions with different numbers of parameters:
3122//
3123// ACTION_P(Plus, a) { ... }
3124// ACTION_P2(Plus, a, b) { ... }
3125//
3126// While it's tempting to always use the ACTION* macros when defining
3127// a new action, you should also consider implementing ActionInterface
3128// or using MakePolymorphicAction() instead, especially if you need to
3129// use the action a lot. While these approaches require more work,
3130// they give you more control on the types of the mock function
3131// arguments and the action parameters, which in general leads to
3132// better compiler error messages that pay off in the long run. They
3133// also allow overloading actions based on parameter types (as opposed
3134// to just based on the number of parameters).
3135//
3136// CAVEAT:
3137//
3138// ACTION*() can only be used in a namespace scope. The reason is
3139// that C++ doesn't yet allow function-local types to be used to
3140// instantiate templates. The up-coming C++0x standard will fix this.
3141// Once that's done, we'll consider supporting using ACTION*() inside
3142// a function.
3143//
3144// MORE INFORMATION:
3145//
3146// To learn more about using these macros, please search for 'ACTION'
3147// on http://code.google.com/p/googlemock/wiki/CookBook.
3148
3149// An internal macro needed for implementing ACTION*().
3150#define GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_\
3151 const args_type& args GTEST_ATTRIBUTE_UNUSED_, \
3152 arg0_type arg0 GTEST_ATTRIBUTE_UNUSED_, \
3153 arg1_type arg1 GTEST_ATTRIBUTE_UNUSED_, \
3154 arg2_type arg2 GTEST_ATTRIBUTE_UNUSED_, \
3155 arg3_type arg3 GTEST_ATTRIBUTE_UNUSED_, \
3156 arg4_type arg4 GTEST_ATTRIBUTE_UNUSED_, \
3157 arg5_type arg5 GTEST_ATTRIBUTE_UNUSED_, \
3158 arg6_type arg6 GTEST_ATTRIBUTE_UNUSED_, \
3159 arg7_type arg7 GTEST_ATTRIBUTE_UNUSED_, \
3160 arg8_type arg8 GTEST_ATTRIBUTE_UNUSED_, \
3161 arg9_type arg9 GTEST_ATTRIBUTE_UNUSED_
3162
3163// Sometimes you want to give an action explicit template parameters
3164// that cannot be inferred from its value parameters. ACTION() and
3165// ACTION_P*() don't support that. ACTION_TEMPLATE() remedies that
3166// and can be viewed as an extension to ACTION() and ACTION_P*().
3167//
3168// The syntax:
3169//
3170// ACTION_TEMPLATE(ActionName,
3171// HAS_m_TEMPLATE_PARAMS(kind1, name1, ..., kind_m, name_m),
3172// AND_n_VALUE_PARAMS(p1, ..., p_n)) { statements; }
3173//
3174// defines an action template that takes m explicit template
3175// parameters and n value parameters. name_i is the name of the i-th
3176// template parameter, and kind_i specifies whether it's a typename,
3177// an integral constant, or a template. p_i is the name of the i-th
3178// value parameter.
3179//
3180// Example:
3181//
3182// // DuplicateArg<k, T>(output) converts the k-th argument of the mock
3183// // function to type T and copies it to *output.
3184// ACTION_TEMPLATE(DuplicateArg,
3185// HAS_2_TEMPLATE_PARAMS(int, k, typename, T),
3186// AND_1_VALUE_PARAMS(output)) {
3187// *output = T(std::tr1::get<k>(args));
3188// }
3189// ...
3190// int n;
3191// EXPECT_CALL(mock, Foo(_, _))
3192// .WillOnce(DuplicateArg<1, unsigned char>(&n));
3193//
3194// To create an instance of an action template, write:
3195//
3196// ActionName<t1, ..., t_m>(v1, ..., v_n)
3197//
3198// where the ts are the template arguments and the vs are the value
3199// arguments. The value argument types are inferred by the compiler.
3200// If you want to explicitly specify the value argument types, you can
3201// provide additional template arguments:
3202//
3203// ActionName<t1, ..., t_m, u1, ..., u_k>(v1, ..., v_n)
3204//
3205// where u_i is the desired type of v_i.
3206//
3207// ACTION_TEMPLATE and ACTION/ACTION_P* can be overloaded on the
3208// number of value parameters, but not on the number of template
3209// parameters. Without the restriction, the meaning of the following
3210// is unclear:
3211//
3212// OverloadedAction<int, bool>(x);
3213//
3214// Are we using a single-template-parameter action where 'bool' refers
3215// to the type of x, or are we using a two-template-parameter action
3216// where the compiler is asked to infer the type of x?
3217//
3218// Implementation notes:
3219//
3220// GMOCK_INTERNAL_*_HAS_m_TEMPLATE_PARAMS and
3221// GMOCK_INTERNAL_*_AND_n_VALUE_PARAMS are internal macros for
3222// implementing ACTION_TEMPLATE. The main trick we use is to create
3223// new macro invocations when expanding a macro. For example, we have
3224//
3225// #define ACTION_TEMPLATE(name, template_params, value_params)
3226// ... GMOCK_INTERNAL_DECL_##template_params ...
3227//
3228// which causes ACTION_TEMPLATE(..., HAS_1_TEMPLATE_PARAMS(typename, T), ...)
3229// to expand to
3230//
3231// ... GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(typename, T) ...
3232//
3233// Since GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS is a macro, the
3234// preprocessor will continue to expand it to
3235//
3236// ... typename T ...
3237//
3238// This technique conforms to the C++ standard and is portable. It
3239// allows us to implement action templates using O(N) code, where N is
3240// the maximum number of template/value parameters supported. Without
3241// using it, we'd have to devote O(N^2) amount of code to implement all
3242// combinations of m and n.
3243
3244// Declares the template parameters.
3245#define GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(kind0, name0) kind0 name0
3246#define GMOCK_INTERNAL_DECL_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, \
3247 name1) kind0 name0, kind1 name1
3248#define GMOCK_INTERNAL_DECL_HAS_3_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3249 kind2, name2) kind0 name0, kind1 name1, kind2 name2
3250#define GMOCK_INTERNAL_DECL_HAS_4_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3251 kind2, name2, kind3, name3) kind0 name0, kind1 name1, kind2 name2, \
3252 kind3 name3
3253#define GMOCK_INTERNAL_DECL_HAS_5_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3254 kind2, name2, kind3, name3, kind4, name4) kind0 name0, kind1 name1, \
3255 kind2 name2, kind3 name3, kind4 name4
3256#define GMOCK_INTERNAL_DECL_HAS_6_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3257 kind2, name2, kind3, name3, kind4, name4, kind5, name5) kind0 name0, \
3258 kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5
3259#define GMOCK_INTERNAL_DECL_HAS_7_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3260 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
3261 name6) kind0 name0, kind1 name1, kind2 name2, kind3 name3, kind4 name4, \
3262 kind5 name5, kind6 name6
3263#define GMOCK_INTERNAL_DECL_HAS_8_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3264 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
3265 kind7, name7) kind0 name0, kind1 name1, kind2 name2, kind3 name3, \
3266 kind4 name4, kind5 name5, kind6 name6, kind7 name7
3267#define GMOCK_INTERNAL_DECL_HAS_9_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3268 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
3269 kind7, name7, kind8, name8) kind0 name0, kind1 name1, kind2 name2, \
3270 kind3 name3, kind4 name4, kind5 name5, kind6 name6, kind7 name7, \
3271 kind8 name8
3272#define GMOCK_INTERNAL_DECL_HAS_10_TEMPLATE_PARAMS(kind0, name0, kind1, \
3273 name1, kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
3274 name6, kind7, name7, kind8, name8, kind9, name9) kind0 name0, \
3275 kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5, \
3276 kind6 name6, kind7 name7, kind8 name8, kind9 name9
3277
3278// Lists the template parameters.
3279#define GMOCK_INTERNAL_LIST_HAS_1_TEMPLATE_PARAMS(kind0, name0) name0
3280#define GMOCK_INTERNAL_LIST_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, \
3281 name1) name0, name1
3282#define GMOCK_INTERNAL_LIST_HAS_3_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3283 kind2, name2) name0, name1, name2
3284#define GMOCK_INTERNAL_LIST_HAS_4_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3285 kind2, name2, kind3, name3) name0, name1, name2, name3
3286#define GMOCK_INTERNAL_LIST_HAS_5_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3287 kind2, name2, kind3, name3, kind4, name4) name0, name1, name2, name3, \
3288 name4
3289#define GMOCK_INTERNAL_LIST_HAS_6_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3290 kind2, name2, kind3, name3, kind4, name4, kind5, name5) name0, name1, \
3291 name2, name3, name4, name5
3292#define GMOCK_INTERNAL_LIST_HAS_7_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3293 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
3294 name6) name0, name1, name2, name3, name4, name5, name6
3295#define GMOCK_INTERNAL_LIST_HAS_8_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3296 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
3297 kind7, name7) name0, name1, name2, name3, name4, name5, name6, name7
3298#define GMOCK_INTERNAL_LIST_HAS_9_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3299 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
3300 kind7, name7, kind8, name8) name0, name1, name2, name3, name4, name5, \
3301 name6, name7, name8
3302#define GMOCK_INTERNAL_LIST_HAS_10_TEMPLATE_PARAMS(kind0, name0, kind1, \
3303 name1, kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
3304 name6, kind7, name7, kind8, name8, kind9, name9) name0, name1, name2, \
3305 name3, name4, name5, name6, name7, name8, name9
3306
3307// Declares the types of value parameters.
3308#define GMOCK_INTERNAL_DECL_TYPE_AND_0_VALUE_PARAMS()
3309#define GMOCK_INTERNAL_DECL_TYPE_AND_1_VALUE_PARAMS(p0) , typename p0##_type
3310#define GMOCK_INTERNAL_DECL_TYPE_AND_2_VALUE_PARAMS(p0, p1) , \
3311 typename p0##_type, typename p1##_type
3312#define GMOCK_INTERNAL_DECL_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) , \
3313 typename p0##_type, typename p1##_type, typename p2##_type
3314#define GMOCK_INTERNAL_DECL_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) , \
3315 typename p0##_type, typename p1##_type, typename p2##_type, \
3316 typename p3##_type
3317#define GMOCK_INTERNAL_DECL_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) , \
3318 typename p0##_type, typename p1##_type, typename p2##_type, \
3319 typename p3##_type, typename p4##_type
3320#define GMOCK_INTERNAL_DECL_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) , \
3321 typename p0##_type, typename p1##_type, typename p2##_type, \
3322 typename p3##_type, typename p4##_type, typename p5##_type
3323#define GMOCK_INTERNAL_DECL_TYPE_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3324 p6) , typename p0##_type, typename p1##_type, typename p2##_type, \
3325 typename p3##_type, typename p4##_type, typename p5##_type, \
3326 typename p6##_type
3327#define GMOCK_INTERNAL_DECL_TYPE_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3328 p6, p7) , typename p0##_type, typename p1##_type, typename p2##_type, \
3329 typename p3##_type, typename p4##_type, typename p5##_type, \
3330 typename p6##_type, typename p7##_type
3331#define GMOCK_INTERNAL_DECL_TYPE_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3332 p6, p7, p8) , typename p0##_type, typename p1##_type, typename p2##_type, \
3333 typename p3##_type, typename p4##_type, typename p5##_type, \
3334 typename p6##_type, typename p7##_type, typename p8##_type
3335#define GMOCK_INTERNAL_DECL_TYPE_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3336 p6, p7, p8, p9) , typename p0##_type, typename p1##_type, \
3337 typename p2##_type, typename p3##_type, typename p4##_type, \
3338 typename p5##_type, typename p6##_type, typename p7##_type, \
3339 typename p8##_type, typename p9##_type
3340
3341// Initializes the value parameters.
3342#define GMOCK_INTERNAL_INIT_AND_0_VALUE_PARAMS()\
3343 ()
3344#define GMOCK_INTERNAL_INIT_AND_1_VALUE_PARAMS(p0)\
3345 (p0##_type gmock_p0) : p0(gmock_p0)
3346#define GMOCK_INTERNAL_INIT_AND_2_VALUE_PARAMS(p0, p1)\
3347 (p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), p1(gmock_p1)
3348#define GMOCK_INTERNAL_INIT_AND_3_VALUE_PARAMS(p0, p1, p2)\
3349 (p0##_type gmock_p0, p1##_type gmock_p1, \
3350 p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2)
3351#define GMOCK_INTERNAL_INIT_AND_4_VALUE_PARAMS(p0, p1, p2, p3)\
3352 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3353 p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
3354 p3(gmock_p3)
3355#define GMOCK_INTERNAL_INIT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)\
3356 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3357 p3##_type gmock_p3, p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), \
3358 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4)
3359#define GMOCK_INTERNAL_INIT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)\
3360 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3361 p3##_type gmock_p3, p4##_type gmock_p4, \
3362 p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
3363 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5)
3364#define GMOCK_INTERNAL_INIT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)\
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) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
3368 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6)
3369#define GMOCK_INTERNAL_INIT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)\
3370 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3371 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
3372 p6##_type gmock_p6, p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), \
3373 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
3374 p7(gmock_p7)
3375#define GMOCK_INTERNAL_INIT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3376 p7, p8)\
3377 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3378 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
3379 p6##_type gmock_p6, p7##_type gmock_p7, \
3380 p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
3381 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
3382 p8(gmock_p8)
3383#define GMOCK_INTERNAL_INIT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3384 p7, p8, p9)\
3385 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3386 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
3387 p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
3388 p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
3389 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
3390 p8(gmock_p8), p9(gmock_p9)
3391
3392// Declares the fields for storing the value parameters.
3393#define GMOCK_INTERNAL_DEFN_AND_0_VALUE_PARAMS()
3394#define GMOCK_INTERNAL_DEFN_AND_1_VALUE_PARAMS(p0) p0##_type p0;
3395#define GMOCK_INTERNAL_DEFN_AND_2_VALUE_PARAMS(p0, p1) p0##_type p0; \
3396 p1##_type p1;
3397#define GMOCK_INTERNAL_DEFN_AND_3_VALUE_PARAMS(p0, p1, p2) p0##_type p0; \
3398 p1##_type p1; p2##_type p2;
3399#define GMOCK_INTERNAL_DEFN_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0##_type p0; \
3400 p1##_type p1; p2##_type p2; p3##_type p3;
3401#define GMOCK_INTERNAL_DEFN_AND_5_VALUE_PARAMS(p0, p1, p2, p3, \
3402 p4) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4;
3403#define GMOCK_INTERNAL_DEFN_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, \
3404 p5) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \
3405 p5##_type p5;
3406#define GMOCK_INTERNAL_DEFN_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3407 p6) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \
3408 p5##_type p5; p6##_type p6;
3409#define GMOCK_INTERNAL_DEFN_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3410 p7) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \
3411 p5##_type p5; p6##_type p6; p7##_type p7;
3412#define GMOCK_INTERNAL_DEFN_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3413 p7, p8) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; \
3414 p4##_type p4; p5##_type p5; p6##_type p6; p7##_type p7; p8##_type p8;
3415#define GMOCK_INTERNAL_DEFN_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3416 p7, p8, p9) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; \
3417 p4##_type p4; p5##_type p5; p6##_type p6; p7##_type p7; p8##_type p8; \
3418 p9##_type p9;
3419
3420// Lists the value parameters.
3421#define GMOCK_INTERNAL_LIST_AND_0_VALUE_PARAMS()
3422#define GMOCK_INTERNAL_LIST_AND_1_VALUE_PARAMS(p0) p0
3423#define GMOCK_INTERNAL_LIST_AND_2_VALUE_PARAMS(p0, p1) p0, p1
3424#define GMOCK_INTERNAL_LIST_AND_3_VALUE_PARAMS(p0, p1, p2) p0, p1, p2
3425#define GMOCK_INTERNAL_LIST_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0, p1, p2, p3
3426#define GMOCK_INTERNAL_LIST_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) p0, p1, \
3427 p2, p3, p4
3428#define GMOCK_INTERNAL_LIST_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) p0, \
3429 p1, p2, p3, p4, p5
3430#define GMOCK_INTERNAL_LIST_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3431 p6) p0, p1, p2, p3, p4, p5, p6
3432#define GMOCK_INTERNAL_LIST_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3433 p7) p0, p1, p2, p3, p4, p5, p6, p7
3434#define GMOCK_INTERNAL_LIST_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3435 p7, p8) p0, p1, p2, p3, p4, p5, p6, p7, p8
3436#define GMOCK_INTERNAL_LIST_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3437 p7, p8, p9) p0, p1, p2, p3, p4, p5, p6, p7, p8, p9
3438
3439// Lists the value parameter types.
3440#define GMOCK_INTERNAL_LIST_TYPE_AND_0_VALUE_PARAMS()
3441#define GMOCK_INTERNAL_LIST_TYPE_AND_1_VALUE_PARAMS(p0) , p0##_type
3442#define GMOCK_INTERNAL_LIST_TYPE_AND_2_VALUE_PARAMS(p0, p1) , p0##_type, \
3443 p1##_type
3444#define GMOCK_INTERNAL_LIST_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) , p0##_type, \
3445 p1##_type, p2##_type
3446#define GMOCK_INTERNAL_LIST_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) , \
3447 p0##_type, p1##_type, p2##_type, p3##_type
3448#define GMOCK_INTERNAL_LIST_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) , \
3449 p0##_type, p1##_type, p2##_type, p3##_type, p4##_type
3450#define GMOCK_INTERNAL_LIST_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) , \
3451 p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type
3452#define GMOCK_INTERNAL_LIST_TYPE_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3453 p6) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type, \
3454 p6##_type
3455#define GMOCK_INTERNAL_LIST_TYPE_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3456 p6, p7) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
3457 p5##_type, p6##_type, p7##_type
3458#define GMOCK_INTERNAL_LIST_TYPE_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3459 p6, p7, p8) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
3460 p5##_type, p6##_type, p7##_type, p8##_type
3461#define GMOCK_INTERNAL_LIST_TYPE_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3462 p6, p7, p8, p9) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
3463 p5##_type, p6##_type, p7##_type, p8##_type, p9##_type
3464
3465// Declares the value parameters.
3466#define GMOCK_INTERNAL_DECL_AND_0_VALUE_PARAMS()
3467#define GMOCK_INTERNAL_DECL_AND_1_VALUE_PARAMS(p0) p0##_type p0
3468#define GMOCK_INTERNAL_DECL_AND_2_VALUE_PARAMS(p0, p1) p0##_type p0, \
3469 p1##_type p1
3470#define GMOCK_INTERNAL_DECL_AND_3_VALUE_PARAMS(p0, p1, p2) p0##_type p0, \
3471 p1##_type p1, p2##_type p2
3472#define GMOCK_INTERNAL_DECL_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0##_type p0, \
3473 p1##_type p1, p2##_type p2, p3##_type p3
3474#define GMOCK_INTERNAL_DECL_AND_5_VALUE_PARAMS(p0, p1, p2, p3, \
3475 p4) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4
3476#define GMOCK_INTERNAL_DECL_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, \
3477 p5) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \
3478 p5##_type p5
3479#define GMOCK_INTERNAL_DECL_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3480 p6) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \
3481 p5##_type p5, p6##_type p6
3482#define GMOCK_INTERNAL_DECL_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3483 p7) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \
3484 p5##_type p5, p6##_type p6, p7##_type p7
3485#define GMOCK_INTERNAL_DECL_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3486 p7, p8) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
3487 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8
3488#define GMOCK_INTERNAL_DECL_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3489 p7, p8, p9) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
3490 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \
3491 p9##_type p9
3492
3493// The suffix of the class template implementing the action template.
3494#define GMOCK_INTERNAL_COUNT_AND_0_VALUE_PARAMS()
3495#define GMOCK_INTERNAL_COUNT_AND_1_VALUE_PARAMS(p0) P
3496#define GMOCK_INTERNAL_COUNT_AND_2_VALUE_PARAMS(p0, p1) P2
3497#define GMOCK_INTERNAL_COUNT_AND_3_VALUE_PARAMS(p0, p1, p2) P3
3498#define GMOCK_INTERNAL_COUNT_AND_4_VALUE_PARAMS(p0, p1, p2, p3) P4
3499#define GMOCK_INTERNAL_COUNT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) P5
3500#define GMOCK_INTERNAL_COUNT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) P6
3501#define GMOCK_INTERNAL_COUNT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6) P7
3502#define GMOCK_INTERNAL_COUNT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3503 p7) P8
3504#define GMOCK_INTERNAL_COUNT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3505 p7, p8) P9
3506#define GMOCK_INTERNAL_COUNT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3507 p7, p8, p9) P10
3508
3509// The name of the class template implementing the action template.
3510#define GMOCK_ACTION_CLASS_(name, value_params)\
3511 GTEST_CONCAT_TOKEN_(name##Action, GMOCK_INTERNAL_COUNT_##value_params)
3512
3513#define ACTION_TEMPLATE(name, template_params, value_params)\
3514 template <GMOCK_INTERNAL_DECL_##template_params\
3515 GMOCK_INTERNAL_DECL_TYPE_##value_params>\
3516 class GMOCK_ACTION_CLASS_(name, value_params) {\
3517 public:\
3518 GMOCK_ACTION_CLASS_(name, value_params)\
3519 GMOCK_INTERNAL_INIT_##value_params {}\
3520 template <typename F>\
3521 class gmock_Impl : public ::testing::ActionInterface<F> {\
3522 public:\
3523 typedef F function_type;\
3524 typedef typename ::testing::internal::Function<F>::Result return_type;\
3525 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
3526 args_type;\
3527 explicit gmock_Impl GMOCK_INTERNAL_INIT_##value_params {}\
3528 virtual return_type Perform(const args_type& args) {\
3529 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
3530 Perform(this, args);\
3531 }\
3532 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3533 typename arg3_type, typename arg4_type, typename arg5_type, \
3534 typename arg6_type, typename arg7_type, typename arg8_type, \
3535 typename arg9_type>\
3536 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
3537 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
3538 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
3539 arg9_type arg9) const;\
3540 GMOCK_INTERNAL_DEFN_##value_params\
3541 private:\
3542 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
3543 };\
3544 template <typename F> operator ::testing::Action<F>() const {\
3545 return ::testing::Action<F>(\
3546 new gmock_Impl<F>(GMOCK_INTERNAL_LIST_##value_params));\
3547 }\
3548 GMOCK_INTERNAL_DEFN_##value_params\
3549 private:\
3550 GTEST_DISALLOW_ASSIGN_(GMOCK_ACTION_CLASS_(name, value_params));\
3551 };\
3552 template <GMOCK_INTERNAL_DECL_##template_params\
3553 GMOCK_INTERNAL_DECL_TYPE_##value_params>\
3554 inline GMOCK_ACTION_CLASS_(name, value_params)<\
3555 GMOCK_INTERNAL_LIST_##template_params\
3556 GMOCK_INTERNAL_LIST_TYPE_##value_params> name(\
3557 GMOCK_INTERNAL_DECL_##value_params) {\
3558 return GMOCK_ACTION_CLASS_(name, value_params)<\
3559 GMOCK_INTERNAL_LIST_##template_params\
3560 GMOCK_INTERNAL_LIST_TYPE_##value_params>(\
3561 GMOCK_INTERNAL_LIST_##value_params);\
3562 }\
3563 template <GMOCK_INTERNAL_DECL_##template_params\
3564 GMOCK_INTERNAL_DECL_TYPE_##value_params>\
3565 template <typename F>\
3566 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3567 typename arg3_type, typename arg4_type, typename arg5_type, \
3568 typename arg6_type, typename arg7_type, typename arg8_type, \
3569 typename arg9_type>\
3570 typename ::testing::internal::Function<F>::Result\
3571 GMOCK_ACTION_CLASS_(name, value_params)<\
3572 GMOCK_INTERNAL_LIST_##template_params\
3573 GMOCK_INTERNAL_LIST_TYPE_##value_params>::gmock_Impl<F>::\
3574 gmock_PerformImpl(\
3575 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
3576
3577#define ACTION(name)\
3578 class name##Action {\
3579 public:\
3580 name##Action() {}\
3581 template <typename F>\
3582 class gmock_Impl : public ::testing::ActionInterface<F> {\
3583 public:\
3584 typedef F function_type;\
3585 typedef typename ::testing::internal::Function<F>::Result return_type;\
3586 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
3587 args_type;\
3588 gmock_Impl() {}\
3589 virtual return_type Perform(const args_type& args) {\
3590 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
3591 Perform(this, args);\
3592 }\
3593 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3594 typename arg3_type, typename arg4_type, typename arg5_type, \
3595 typename arg6_type, typename arg7_type, typename arg8_type, \
3596 typename arg9_type>\
3597 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
3598 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
3599 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
3600 arg9_type arg9) const;\
3601 private:\
3602 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
3603 };\
3604 template <typename F> operator ::testing::Action<F>() const {\
3605 return ::testing::Action<F>(new gmock_Impl<F>());\
3606 }\
3607 private:\
3608 GTEST_DISALLOW_ASSIGN_(name##Action);\
3609 };\
3610 inline name##Action name() {\
3611 return name##Action();\
3612 }\
3613 template <typename F>\
3614 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3615 typename arg3_type, typename arg4_type, typename arg5_type, \
3616 typename arg6_type, typename arg7_type, typename arg8_type, \
3617 typename arg9_type>\
3618 typename ::testing::internal::Function<F>::Result\
3619 name##Action::gmock_Impl<F>::gmock_PerformImpl(\
3620 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
3621
3622#define ACTION_P(name, p0)\
3623 template <typename p0##_type>\
3624 class name##ActionP {\
3625 public:\
3626 name##ActionP(p0##_type gmock_p0) : p0(gmock_p0) {}\
3627 template <typename F>\
3628 class gmock_Impl : public ::testing::ActionInterface<F> {\
3629 public:\
3630 typedef F function_type;\
3631 typedef typename ::testing::internal::Function<F>::Result return_type;\
3632 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
3633 args_type;\
3634 explicit gmock_Impl(p0##_type gmock_p0) : p0(gmock_p0) {}\
3635 virtual return_type Perform(const args_type& args) {\
3636 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
3637 Perform(this, args);\
3638 }\
3639 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3640 typename arg3_type, typename arg4_type, typename arg5_type, \
3641 typename arg6_type, typename arg7_type, typename arg8_type, \
3642 typename arg9_type>\
3643 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
3644 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
3645 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
3646 arg9_type arg9) const;\
3647 p0##_type p0;\
3648 private:\
3649 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
3650 };\
3651 template <typename F> operator ::testing::Action<F>() const {\
3652 return ::testing::Action<F>(new gmock_Impl<F>(p0));\
3653 }\
3654 p0##_type p0;\
3655 private:\
3656 GTEST_DISALLOW_ASSIGN_(name##ActionP);\
3657 };\
3658 template <typename p0##_type>\
3659 inline name##ActionP<p0##_type> name(p0##_type p0) {\
3660 return name##ActionP<p0##_type>(p0);\
3661 }\
3662 template <typename p0##_type>\
3663 template <typename F>\
3664 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3665 typename arg3_type, typename arg4_type, typename arg5_type, \
3666 typename arg6_type, typename arg7_type, typename arg8_type, \
3667 typename arg9_type>\
3668 typename ::testing::internal::Function<F>::Result\
3669 name##ActionP<p0##_type>::gmock_Impl<F>::gmock_PerformImpl(\
3670 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
3671
3672#define ACTION_P2(name, p0, p1)\
3673 template <typename p0##_type, typename p1##_type>\
3674 class name##ActionP2 {\
3675 public:\
3676 name##ActionP2(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \
3677 p1(gmock_p1) {}\
3678 template <typename F>\
3679 class gmock_Impl : public ::testing::ActionInterface<F> {\
3680 public:\
3681 typedef F function_type;\
3682 typedef typename ::testing::internal::Function<F>::Result return_type;\
3683 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
3684 args_type;\
3685 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \
3686 p1(gmock_p1) {}\
3687 virtual return_type Perform(const args_type& args) {\
3688 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
3689 Perform(this, args);\
3690 }\
3691 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3692 typename arg3_type, typename arg4_type, typename arg5_type, \
3693 typename arg6_type, typename arg7_type, typename arg8_type, \
3694 typename arg9_type>\
3695 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
3696 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
3697 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
3698 arg9_type arg9) const;\
3699 p0##_type p0;\
3700 p1##_type p1;\
3701 private:\
3702 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
3703 };\
3704 template <typename F> operator ::testing::Action<F>() const {\
3705 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1));\
3706 }\
3707 p0##_type p0;\
3708 p1##_type p1;\
3709 private:\
3710 GTEST_DISALLOW_ASSIGN_(name##ActionP2);\
3711 };\
3712 template <typename p0##_type, typename p1##_type>\
3713 inline name##ActionP2<p0##_type, p1##_type> name(p0##_type p0, \
3714 p1##_type p1) {\
3715 return name##ActionP2<p0##_type, p1##_type>(p0, p1);\
3716 }\
3717 template <typename p0##_type, typename p1##_type>\
3718 template <typename F>\
3719 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3720 typename arg3_type, typename arg4_type, typename arg5_type, \
3721 typename arg6_type, typename arg7_type, typename arg8_type, \
3722 typename arg9_type>\
3723 typename ::testing::internal::Function<F>::Result\
3724 name##ActionP2<p0##_type, p1##_type>::gmock_Impl<F>::gmock_PerformImpl(\
3725 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
3726
3727#define ACTION_P3(name, p0, p1, p2)\
3728 template <typename p0##_type, typename p1##_type, typename p2##_type>\
3729 class name##ActionP3 {\
3730 public:\
3731 name##ActionP3(p0##_type gmock_p0, p1##_type gmock_p1, \
3732 p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\
3733 template <typename F>\
3734 class gmock_Impl : public ::testing::ActionInterface<F> {\
3735 public:\
3736 typedef F function_type;\
3737 typedef typename ::testing::internal::Function<F>::Result return_type;\
3738 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
3739 args_type;\
3740 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, \
3741 p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\
3742 virtual return_type Perform(const args_type& args) {\
3743 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
3744 Perform(this, args);\
3745 }\
3746 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3747 typename arg3_type, typename arg4_type, typename arg5_type, \
3748 typename arg6_type, typename arg7_type, typename arg8_type, \
3749 typename arg9_type>\
3750 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
3751 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
3752 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
3753 arg9_type arg9) const;\
3754 p0##_type p0;\
3755 p1##_type p1;\
3756 p2##_type p2;\
3757 private:\
3758 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
3759 };\
3760 template <typename F> operator ::testing::Action<F>() const {\
3761 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2));\
3762 }\
3763 p0##_type p0;\
3764 p1##_type p1;\
3765 p2##_type p2;\
3766 private:\
3767 GTEST_DISALLOW_ASSIGN_(name##ActionP3);\
3768 };\
3769 template <typename p0##_type, typename p1##_type, typename p2##_type>\
3770 inline name##ActionP3<p0##_type, p1##_type, p2##_type> name(p0##_type p0, \
3771 p1##_type p1, p2##_type p2) {\
3772 return name##ActionP3<p0##_type, p1##_type, p2##_type>(p0, p1, p2);\
3773 }\
3774 template <typename p0##_type, typename p1##_type, typename p2##_type>\
3775 template <typename F>\
3776 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3777 typename arg3_type, typename arg4_type, typename arg5_type, \
3778 typename arg6_type, typename arg7_type, typename arg8_type, \
3779 typename arg9_type>\
3780 typename ::testing::internal::Function<F>::Result\
3781 name##ActionP3<p0##_type, p1##_type, \
3782 p2##_type>::gmock_Impl<F>::gmock_PerformImpl(\
3783 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
3784
3785#define ACTION_P4(name, p0, p1, p2, p3)\
3786 template <typename p0##_type, typename p1##_type, typename p2##_type, \
3787 typename p3##_type>\
3788 class name##ActionP4 {\
3789 public:\
3790 name##ActionP4(p0##_type gmock_p0, p1##_type gmock_p1, \
3791 p2##_type gmock_p2, p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), \
3792 p2(gmock_p2), p3(gmock_p3) {}\
3793 template <typename F>\
3794 class gmock_Impl : public ::testing::ActionInterface<F> {\
3795 public:\
3796 typedef F function_type;\
3797 typedef typename ::testing::internal::Function<F>::Result return_type;\
3798 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
3799 args_type;\
3800 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3801 p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
3802 p3(gmock_p3) {}\
3803 virtual return_type Perform(const args_type& args) {\
3804 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
3805 Perform(this, args);\
3806 }\
3807 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3808 typename arg3_type, typename arg4_type, typename arg5_type, \
3809 typename arg6_type, typename arg7_type, typename arg8_type, \
3810 typename arg9_type>\
3811 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
3812 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
3813 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
3814 arg9_type arg9) const;\
3815 p0##_type p0;\
3816 p1##_type p1;\
3817 p2##_type p2;\
3818 p3##_type p3;\
3819 private:\
3820 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
3821 };\
3822 template <typename F> operator ::testing::Action<F>() const {\
3823 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3));\
3824 }\
3825 p0##_type p0;\
3826 p1##_type p1;\
3827 p2##_type p2;\
3828 p3##_type p3;\
3829 private:\
3830 GTEST_DISALLOW_ASSIGN_(name##ActionP4);\
3831 };\
3832 template <typename p0##_type, typename p1##_type, typename p2##_type, \
3833 typename p3##_type>\
3834 inline name##ActionP4<p0##_type, p1##_type, p2##_type, \
3835 p3##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
3836 p3##_type p3) {\
3837 return name##ActionP4<p0##_type, p1##_type, p2##_type, p3##_type>(p0, p1, \
3838 p2, p3);\
3839 }\
3840 template <typename p0##_type, typename p1##_type, typename p2##_type, \
3841 typename p3##_type>\
3842 template <typename F>\
3843 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3844 typename arg3_type, typename arg4_type, typename arg5_type, \
3845 typename arg6_type, typename arg7_type, typename arg8_type, \
3846 typename arg9_type>\
3847 typename ::testing::internal::Function<F>::Result\
3848 name##ActionP4<p0##_type, p1##_type, p2##_type, \
3849 p3##_type>::gmock_Impl<F>::gmock_PerformImpl(\
3850 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
3851
3852#define ACTION_P5(name, p0, p1, p2, p3, p4)\
3853 template <typename p0##_type, typename p1##_type, typename p2##_type, \
3854 typename p3##_type, typename p4##_type>\
3855 class name##ActionP5 {\
3856 public:\
3857 name##ActionP5(p0##_type gmock_p0, p1##_type gmock_p1, \
3858 p2##_type gmock_p2, p3##_type gmock_p3, \
3859 p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
3860 p3(gmock_p3), p4(gmock_p4) {}\
3861 template <typename F>\
3862 class gmock_Impl : public ::testing::ActionInterface<F> {\
3863 public:\
3864 typedef F function_type;\
3865 typedef typename ::testing::internal::Function<F>::Result return_type;\
3866 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
3867 args_type;\
3868 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3869 p3##_type gmock_p3, p4##_type gmock_p4) : p0(gmock_p0), \
3870 p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), p4(gmock_p4) {}\
3871 virtual return_type Perform(const args_type& args) {\
3872 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
3873 Perform(this, args);\
3874 }\
3875 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3876 typename arg3_type, typename arg4_type, typename arg5_type, \
3877 typename arg6_type, typename arg7_type, typename arg8_type, \
3878 typename arg9_type>\
3879 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
3880 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
3881 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
3882 arg9_type arg9) const;\
3883 p0##_type p0;\
3884 p1##_type p1;\
3885 p2##_type p2;\
3886 p3##_type p3;\
3887 p4##_type p4;\
3888 private:\
3889 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
3890 };\
3891 template <typename F> operator ::testing::Action<F>() const {\
3892 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4));\
3893 }\
3894 p0##_type p0;\
3895 p1##_type p1;\
3896 p2##_type p2;\
3897 p3##_type p3;\
3898 p4##_type p4;\
3899 private:\
3900 GTEST_DISALLOW_ASSIGN_(name##ActionP5);\
3901 };\
3902 template <typename p0##_type, typename p1##_type, typename p2##_type, \
3903 typename p3##_type, typename p4##_type>\
3904 inline name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \
3905 p4##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
3906 p4##_type p4) {\
3907 return name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \
3908 p4##_type>(p0, p1, p2, p3, p4);\
3909 }\
3910 template <typename p0##_type, typename p1##_type, typename p2##_type, \
3911 typename p3##_type, typename p4##_type>\
3912 template <typename F>\
3913 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3914 typename arg3_type, typename arg4_type, typename arg5_type, \
3915 typename arg6_type, typename arg7_type, typename arg8_type, \
3916 typename arg9_type>\
3917 typename ::testing::internal::Function<F>::Result\
3918 name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \
3919 p4##_type>::gmock_Impl<F>::gmock_PerformImpl(\
3920 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
3921
3922#define ACTION_P6(name, p0, p1, p2, p3, p4, p5)\
3923 template <typename p0##_type, typename p1##_type, typename p2##_type, \
3924 typename p3##_type, typename p4##_type, typename p5##_type>\
3925 class name##ActionP6 {\
3926 public:\
3927 name##ActionP6(p0##_type gmock_p0, p1##_type gmock_p1, \
3928 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
3929 p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
3930 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {}\
3931 template <typename F>\
3932 class gmock_Impl : public ::testing::ActionInterface<F> {\
3933 public:\
3934 typedef F function_type;\
3935 typedef typename ::testing::internal::Function<F>::Result return_type;\
3936 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
3937 args_type;\
3938 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3939 p3##_type gmock_p3, p4##_type gmock_p4, \
3940 p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
3941 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {}\
3942 virtual return_type Perform(const args_type& args) {\
3943 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
3944 Perform(this, args);\
3945 }\
3946 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3947 typename arg3_type, typename arg4_type, typename arg5_type, \
3948 typename arg6_type, typename arg7_type, typename arg8_type, \
3949 typename arg9_type>\
3950 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
3951 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
3952 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
3953 arg9_type arg9) const;\
3954 p0##_type p0;\
3955 p1##_type p1;\
3956 p2##_type p2;\
3957 p3##_type p3;\
3958 p4##_type p4;\
3959 p5##_type p5;\
3960 private:\
3961 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
3962 };\
3963 template <typename F> operator ::testing::Action<F>() const {\
3964 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5));\
3965 }\
3966 p0##_type p0;\
3967 p1##_type p1;\
3968 p2##_type p2;\
3969 p3##_type p3;\
3970 p4##_type p4;\
3971 p5##_type p5;\
3972 private:\
3973 GTEST_DISALLOW_ASSIGN_(name##ActionP6);\
3974 };\
3975 template <typename p0##_type, typename p1##_type, typename p2##_type, \
3976 typename p3##_type, typename p4##_type, typename p5##_type>\
3977 inline name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, \
3978 p4##_type, p5##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
3979 p3##_type p3, p4##_type p4, p5##_type p5) {\
3980 return name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, \
3981 p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5);\
3982 }\
3983 template <typename p0##_type, typename p1##_type, typename p2##_type, \
3984 typename p3##_type, typename p4##_type, typename p5##_type>\
3985 template <typename F>\
3986 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3987 typename arg3_type, typename arg4_type, typename arg5_type, \
3988 typename arg6_type, typename arg7_type, typename arg8_type, \
3989 typename arg9_type>\
3990 typename ::testing::internal::Function<F>::Result\
3991 name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
3992 p5##_type>::gmock_Impl<F>::gmock_PerformImpl(\
3993 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
3994
3995#define ACTION_P7(name, p0, p1, p2, p3, p4, p5, p6)\
3996 template <typename p0##_type, typename p1##_type, typename p2##_type, \
3997 typename p3##_type, typename p4##_type, typename p5##_type, \
3998 typename p6##_type>\
3999 class name##ActionP7 {\
4000 public:\
4001 name##ActionP7(p0##_type gmock_p0, p1##_type gmock_p1, \
4002 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
4003 p5##_type gmock_p5, p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), \
4004 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), \
4005 p6(gmock_p6) {}\
4006 template <typename F>\
4007 class gmock_Impl : public ::testing::ActionInterface<F> {\
4008 public:\
4009 typedef F function_type;\
4010 typedef typename ::testing::internal::Function<F>::Result return_type;\
4011 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
4012 args_type;\
4013 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
4014 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
4015 p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
4016 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6) {}\
4017 virtual return_type Perform(const args_type& args) {\
4018 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
4019 Perform(this, args);\
4020 }\
4021 template <typename arg0_type, typename arg1_type, typename arg2_type, \
4022 typename arg3_type, typename arg4_type, typename arg5_type, \
4023 typename arg6_type, typename arg7_type, typename arg8_type, \
4024 typename arg9_type>\
4025 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
4026 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
4027 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
4028 arg9_type arg9) const;\
4029 p0##_type p0;\
4030 p1##_type p1;\
4031 p2##_type p2;\
4032 p3##_type p3;\
4033 p4##_type p4;\
4034 p5##_type p5;\
4035 p6##_type p6;\
4036 private:\
4037 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
4038 };\
4039 template <typename F> operator ::testing::Action<F>() const {\
4040 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
4041 p6));\
4042 }\
4043 p0##_type p0;\
4044 p1##_type p1;\
4045 p2##_type p2;\
4046 p3##_type p3;\
4047 p4##_type p4;\
4048 p5##_type p5;\
4049 p6##_type p6;\
4050 private:\
4051 GTEST_DISALLOW_ASSIGN_(name##ActionP7);\
4052 };\
4053 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4054 typename p3##_type, typename p4##_type, typename p5##_type, \
4055 typename p6##_type>\
4056 inline name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, \
4057 p4##_type, p5##_type, p6##_type> name(p0##_type p0, p1##_type p1, \
4058 p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
4059 p6##_type p6) {\
4060 return name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, \
4061 p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, p6);\
4062 }\
4063 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4064 typename p3##_type, typename p4##_type, typename p5##_type, \
4065 typename p6##_type>\
4066 template <typename F>\
4067 template <typename arg0_type, typename arg1_type, typename arg2_type, \
4068 typename arg3_type, typename arg4_type, typename arg5_type, \
4069 typename arg6_type, typename arg7_type, typename arg8_type, \
4070 typename arg9_type>\
4071 typename ::testing::internal::Function<F>::Result\
4072 name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
4073 p5##_type, p6##_type>::gmock_Impl<F>::gmock_PerformImpl(\
4074 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
4075
4076#define ACTION_P8(name, p0, p1, p2, p3, p4, p5, p6, p7)\
4077 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4078 typename p3##_type, typename p4##_type, typename p5##_type, \
4079 typename p6##_type, typename p7##_type>\
4080 class name##ActionP8 {\
4081 public:\
4082 name##ActionP8(p0##_type gmock_p0, p1##_type gmock_p1, \
4083 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
4084 p5##_type gmock_p5, p6##_type gmock_p6, \
4085 p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
4086 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
4087 p7(gmock_p7) {}\
4088 template <typename F>\
4089 class gmock_Impl : public ::testing::ActionInterface<F> {\
4090 public:\
4091 typedef F function_type;\
4092 typedef typename ::testing::internal::Function<F>::Result return_type;\
4093 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
4094 args_type;\
4095 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
4096 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
4097 p6##_type gmock_p6, p7##_type gmock_p7) : p0(gmock_p0), \
4098 p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), \
4099 p5(gmock_p5), p6(gmock_p6), p7(gmock_p7) {}\
4100 virtual return_type Perform(const args_type& args) {\
4101 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
4102 Perform(this, args);\
4103 }\
4104 template <typename arg0_type, typename arg1_type, typename arg2_type, \
4105 typename arg3_type, typename arg4_type, typename arg5_type, \
4106 typename arg6_type, typename arg7_type, typename arg8_type, \
4107 typename arg9_type>\
4108 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
4109 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
4110 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
4111 arg9_type arg9) const;\
4112 p0##_type p0;\
4113 p1##_type p1;\
4114 p2##_type p2;\
4115 p3##_type p3;\
4116 p4##_type p4;\
4117 p5##_type p5;\
4118 p6##_type p6;\
4119 p7##_type p7;\
4120 private:\
4121 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
4122 };\
4123 template <typename F> operator ::testing::Action<F>() const {\
4124 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
4125 p6, p7));\
4126 }\
4127 p0##_type p0;\
4128 p1##_type p1;\
4129 p2##_type p2;\
4130 p3##_type p3;\
4131 p4##_type p4;\
4132 p5##_type p5;\
4133 p6##_type p6;\
4134 p7##_type p7;\
4135 private:\
4136 GTEST_DISALLOW_ASSIGN_(name##ActionP8);\
4137 };\
4138 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4139 typename p3##_type, typename p4##_type, typename p5##_type, \
4140 typename p6##_type, typename p7##_type>\
4141 inline name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, \
4142 p4##_type, p5##_type, p6##_type, p7##_type> name(p0##_type p0, \
4143 p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
4144 p6##_type p6, p7##_type p7) {\
4145 return name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, \
4146 p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, p3, p4, p5, \
4147 p6, p7);\
4148 }\
4149 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4150 typename p3##_type, typename p4##_type, typename p5##_type, \
4151 typename p6##_type, typename p7##_type>\
4152 template <typename F>\
4153 template <typename arg0_type, typename arg1_type, typename arg2_type, \
4154 typename arg3_type, typename arg4_type, typename arg5_type, \
4155 typename arg6_type, typename arg7_type, typename arg8_type, \
4156 typename arg9_type>\
4157 typename ::testing::internal::Function<F>::Result\
4158 name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
4159 p5##_type, p6##_type, \
4160 p7##_type>::gmock_Impl<F>::gmock_PerformImpl(\
4161 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
4162
4163#define ACTION_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8)\
4164 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4165 typename p3##_type, typename p4##_type, typename p5##_type, \
4166 typename p6##_type, typename p7##_type, typename p8##_type>\
4167 class name##ActionP9 {\
4168 public:\
4169 name##ActionP9(p0##_type gmock_p0, p1##_type gmock_p1, \
4170 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
4171 p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
4172 p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
4173 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
4174 p8(gmock_p8) {}\
4175 template <typename F>\
4176 class gmock_Impl : public ::testing::ActionInterface<F> {\
4177 public:\
4178 typedef F function_type;\
4179 typedef typename ::testing::internal::Function<F>::Result return_type;\
4180 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
4181 args_type;\
4182 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
4183 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
4184 p6##_type gmock_p6, p7##_type gmock_p7, \
4185 p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
4186 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
4187 p7(gmock_p7), p8(gmock_p8) {}\
4188 virtual return_type Perform(const args_type& args) {\
4189 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
4190 Perform(this, args);\
4191 }\
4192 template <typename arg0_type, typename arg1_type, typename arg2_type, \
4193 typename arg3_type, typename arg4_type, typename arg5_type, \
4194 typename arg6_type, typename arg7_type, typename arg8_type, \
4195 typename arg9_type>\
4196 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
4197 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
4198 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
4199 arg9_type arg9) const;\
4200 p0##_type p0;\
4201 p1##_type p1;\
4202 p2##_type p2;\
4203 p3##_type p3;\
4204 p4##_type p4;\
4205 p5##_type p5;\
4206 p6##_type p6;\
4207 p7##_type p7;\
4208 p8##_type p8;\
4209 private:\
4210 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
4211 };\
4212 template <typename F> operator ::testing::Action<F>() const {\
4213 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
4214 p6, p7, p8));\
4215 }\
4216 p0##_type p0;\
4217 p1##_type p1;\
4218 p2##_type p2;\
4219 p3##_type p3;\
4220 p4##_type p4;\
4221 p5##_type p5;\
4222 p6##_type p6;\
4223 p7##_type p7;\
4224 p8##_type p8;\
4225 private:\
4226 GTEST_DISALLOW_ASSIGN_(name##ActionP9);\
4227 };\
4228 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4229 typename p3##_type, typename p4##_type, typename p5##_type, \
4230 typename p6##_type, typename p7##_type, typename p8##_type>\
4231 inline name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, \
4232 p4##_type, p5##_type, p6##_type, p7##_type, \
4233 p8##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
4234 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, \
4235 p8##_type p8) {\
4236 return name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, \
4237 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type>(p0, p1, p2, \
4238 p3, p4, p5, p6, p7, p8);\
4239 }\
4240 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4241 typename p3##_type, typename p4##_type, typename p5##_type, \
4242 typename p6##_type, typename p7##_type, typename p8##_type>\
4243 template <typename F>\
4244 template <typename arg0_type, typename arg1_type, typename arg2_type, \
4245 typename arg3_type, typename arg4_type, typename arg5_type, \
4246 typename arg6_type, typename arg7_type, typename arg8_type, \
4247 typename arg9_type>\
4248 typename ::testing::internal::Function<F>::Result\
4249 name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
4250 p5##_type, p6##_type, p7##_type, \
4251 p8##_type>::gmock_Impl<F>::gmock_PerformImpl(\
4252 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
4253
4254#define ACTION_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)\
4255 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4256 typename p3##_type, typename p4##_type, typename p5##_type, \
4257 typename p6##_type, typename p7##_type, typename p8##_type, \
4258 typename p9##_type>\
4259 class name##ActionP10 {\
4260 public:\
4261 name##ActionP10(p0##_type gmock_p0, p1##_type gmock_p1, \
4262 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
4263 p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
4264 p8##_type gmock_p8, p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), \
4265 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
4266 p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {}\
4267 template <typename F>\
4268 class gmock_Impl : public ::testing::ActionInterface<F> {\
4269 public:\
4270 typedef F function_type;\
4271 typedef typename ::testing::internal::Function<F>::Result return_type;\
4272 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
4273 args_type;\
4274 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
4275 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
4276 p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
4277 p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
4278 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
4279 p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {}\
4280 virtual return_type Perform(const args_type& args) {\
4281 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
4282 Perform(this, args);\
4283 }\
4284 template <typename arg0_type, typename arg1_type, typename arg2_type, \
4285 typename arg3_type, typename arg4_type, typename arg5_type, \
4286 typename arg6_type, typename arg7_type, typename arg8_type, \
4287 typename arg9_type>\
4288 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
4289 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
4290 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
4291 arg9_type arg9) const;\
4292 p0##_type p0;\
4293 p1##_type p1;\
4294 p2##_type p2;\
4295 p3##_type p3;\
4296 p4##_type p4;\
4297 p5##_type p5;\
4298 p6##_type p6;\
4299 p7##_type p7;\
4300 p8##_type p8;\
4301 p9##_type p9;\
4302 private:\
4303 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
4304 };\
4305 template <typename F> operator ::testing::Action<F>() const {\
4306 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
4307 p6, p7, p8, p9));\
4308 }\
4309 p0##_type p0;\
4310 p1##_type p1;\
4311 p2##_type p2;\
4312 p3##_type p3;\
4313 p4##_type p4;\
4314 p5##_type p5;\
4315 p6##_type p6;\
4316 p7##_type p7;\
4317 p8##_type p8;\
4318 p9##_type p9;\
4319 private:\
4320 GTEST_DISALLOW_ASSIGN_(name##ActionP10);\
4321 };\
4322 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4323 typename p3##_type, typename p4##_type, typename p5##_type, \
4324 typename p6##_type, typename p7##_type, typename p8##_type, \
4325 typename p9##_type>\
4326 inline name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, \
4327 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
4328 p9##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
4329 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \
4330 p9##_type p9) {\
4331 return name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, \
4332 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, p9##_type>(p0, \
4333 p1, p2, p3, p4, p5, p6, p7, p8, p9);\
4334 }\
4335 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4336 typename p3##_type, typename p4##_type, typename p5##_type, \
4337 typename p6##_type, typename p7##_type, typename p8##_type, \
4338 typename p9##_type>\
4339 template <typename F>\
4340 template <typename arg0_type, typename arg1_type, typename arg2_type, \
4341 typename arg3_type, typename arg4_type, typename arg5_type, \
4342 typename arg6_type, typename arg7_type, typename arg8_type, \
4343 typename arg9_type>\
4344 typename ::testing::internal::Function<F>::Result\
4345 name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
4346 p5##_type, p6##_type, p7##_type, p8##_type, \
4347 p9##_type>::gmock_Impl<F>::gmock_PerformImpl(\
4348 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
4349
4350namespace testing {
4351
4352// The ACTION*() macros trigger warning C4100 (unreferenced formal
4353// parameter) in MSVC with -W4. Unfortunately they cannot be fixed in
4354// the macro definition, as the warnings are generated when the macro
4355// is expanded and macro expansion cannot contain #pragma. Therefore
4356// we suppress them here.
4357#ifdef _MSC_VER
4358# pragma warning(push)
4359# pragma warning(disable:4100)
4360#endif
4361
4362// Various overloads for InvokeArgument<N>().
4363//
4364// The InvokeArgument<N>(a1, a2, ..., a_k) action invokes the N-th
4365// (0-based) argument, which must be a k-ary callable, of the mock
4366// function, with arguments a1, a2, ..., a_k.
4367//
4368// Notes:
4369//
4370// 1. The arguments are passed by value by default. If you need to
4371// pass an argument by reference, wrap it inside ByRef(). For
4372// example,
4373//
4374// InvokeArgument<1>(5, string("Hello"), ByRef(foo))
4375//
4376// passes 5 and string("Hello") by value, and passes foo by
4377// reference.
4378//
4379// 2. If the callable takes an argument by reference but ByRef() is
4380// not used, it will receive the reference to a copy of the value,
4381// instead of the original value. For example, when the 0-th
4382// argument of the mock function takes a const string&, the action
4383//
4384// InvokeArgument<0>(string("Hello"))
4385//
4386// makes a copy of the temporary string("Hello") object and passes a
4387// reference of the copy, instead of the original temporary object,
4388// to the callable. This makes it easy for a user to define an
4389// InvokeArgument action from temporary values and have it performed
4390// later.
4391
4392ACTION_TEMPLATE(InvokeArgument,
4393 HAS_1_TEMPLATE_PARAMS(int, k),
4394 AND_0_VALUE_PARAMS()) {
4395 return internal::CallableHelper<return_type>::Call(
4396 ::std::tr1::get<k>(args));
4397}
4398
4399ACTION_TEMPLATE(InvokeArgument,
4400 HAS_1_TEMPLATE_PARAMS(int, k),
4401 AND_1_VALUE_PARAMS(p0)) {
4402 return internal::CallableHelper<return_type>::Call(
4403 ::std::tr1::get<k>(args), p0);
4404}
4405
4406ACTION_TEMPLATE(InvokeArgument,
4407 HAS_1_TEMPLATE_PARAMS(int, k),
4408 AND_2_VALUE_PARAMS(p0, p1)) {
4409 return internal::CallableHelper<return_type>::Call(
4410 ::std::tr1::get<k>(args), p0, p1);
4411}
4412
4413ACTION_TEMPLATE(InvokeArgument,
4414 HAS_1_TEMPLATE_PARAMS(int, k),
4415 AND_3_VALUE_PARAMS(p0, p1, p2)) {
4416 return internal::CallableHelper<return_type>::Call(
4417 ::std::tr1::get<k>(args), p0, p1, p2);
4418}
4419
4420ACTION_TEMPLATE(InvokeArgument,
4421 HAS_1_TEMPLATE_PARAMS(int, k),
4422 AND_4_VALUE_PARAMS(p0, p1, p2, p3)) {
4423 return internal::CallableHelper<return_type>::Call(
4424 ::std::tr1::get<k>(args), p0, p1, p2, p3);
4425}
4426
4427ACTION_TEMPLATE(InvokeArgument,
4428 HAS_1_TEMPLATE_PARAMS(int, k),
4429 AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)) {
4430 return internal::CallableHelper<return_type>::Call(
4431 ::std::tr1::get<k>(args), p0, p1, p2, p3, p4);
4432}
4433
4434ACTION_TEMPLATE(InvokeArgument,
4435 HAS_1_TEMPLATE_PARAMS(int, k),
4436 AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)) {
4437 return internal::CallableHelper<return_type>::Call(
4438 ::std::tr1::get<k>(args), p0, p1, p2, p3, p4, p5);
4439}
4440
4441ACTION_TEMPLATE(InvokeArgument,
4442 HAS_1_TEMPLATE_PARAMS(int, k),
4443 AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)) {
4444 return internal::CallableHelper<return_type>::Call(
4445 ::std::tr1::get<k>(args), p0, p1, p2, p3, p4, p5, p6);
4446}
4447
4448ACTION_TEMPLATE(InvokeArgument,
4449 HAS_1_TEMPLATE_PARAMS(int, k),
4450 AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)) {
4451 return internal::CallableHelper<return_type>::Call(
4452 ::std::tr1::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7);
4453}
4454
4455ACTION_TEMPLATE(InvokeArgument,
4456 HAS_1_TEMPLATE_PARAMS(int, k),
4457 AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8)) {
4458 return internal::CallableHelper<return_type>::Call(
4459 ::std::tr1::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7, p8);
4460}
4461
4462ACTION_TEMPLATE(InvokeArgument,
4463 HAS_1_TEMPLATE_PARAMS(int, k),
4464 AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)) {
4465 return internal::CallableHelper<return_type>::Call(
4466 ::std::tr1::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7, p8, p9);
4467}
4468
4469// Various overloads for ReturnNew<T>().
4470//
4471// The ReturnNew<T>(a1, a2, ..., a_k) action returns a pointer to a new
4472// instance of type T, constructed on the heap with constructor arguments
4473// a1, a2, ..., and a_k. The caller assumes ownership of the returned value.
4474ACTION_TEMPLATE(ReturnNew,
4475 HAS_1_TEMPLATE_PARAMS(typename, T),
4476 AND_0_VALUE_PARAMS()) {
4477 return new T();
4478}
4479
4480ACTION_TEMPLATE(ReturnNew,
4481 HAS_1_TEMPLATE_PARAMS(typename, T),
4482 AND_1_VALUE_PARAMS(p0)) {
4483 return new T(p0);
4484}
4485
4486ACTION_TEMPLATE(ReturnNew,
4487 HAS_1_TEMPLATE_PARAMS(typename, T),
4488 AND_2_VALUE_PARAMS(p0, p1)) {
4489 return new T(p0, p1);
4490}
4491
4492ACTION_TEMPLATE(ReturnNew,
4493 HAS_1_TEMPLATE_PARAMS(typename, T),
4494 AND_3_VALUE_PARAMS(p0, p1, p2)) {
4495 return new T(p0, p1, p2);
4496}
4497
4498ACTION_TEMPLATE(ReturnNew,
4499 HAS_1_TEMPLATE_PARAMS(typename, T),
4500 AND_4_VALUE_PARAMS(p0, p1, p2, p3)) {
4501 return new T(p0, p1, p2, p3);
4502}
4503
4504ACTION_TEMPLATE(ReturnNew,
4505 HAS_1_TEMPLATE_PARAMS(typename, T),
4506 AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)) {
4507 return new T(p0, p1, p2, p3, p4);
4508}
4509
4510ACTION_TEMPLATE(ReturnNew,
4511 HAS_1_TEMPLATE_PARAMS(typename, T),
4512 AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)) {
4513 return new T(p0, p1, p2, p3, p4, p5);
4514}
4515
4516ACTION_TEMPLATE(ReturnNew,
4517 HAS_1_TEMPLATE_PARAMS(typename, T),
4518 AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)) {
4519 return new T(p0, p1, p2, p3, p4, p5, p6);
4520}
4521
4522ACTION_TEMPLATE(ReturnNew,
4523 HAS_1_TEMPLATE_PARAMS(typename, T),
4524 AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)) {
4525 return new T(p0, p1, p2, p3, p4, p5, p6, p7);
4526}
4527
4528ACTION_TEMPLATE(ReturnNew,
4529 HAS_1_TEMPLATE_PARAMS(typename, T),
4530 AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8)) {
4531 return new T(p0, p1, p2, p3, p4, p5, p6, p7, p8);
4532}
4533
4534ACTION_TEMPLATE(ReturnNew,
4535 HAS_1_TEMPLATE_PARAMS(typename, T),
4536 AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)) {
4537 return new T(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9);
4538}
4539
4540#ifdef _MSC_VER
4541# pragma warning(pop)
4542#endif
4543
4544} // namespace testing
4545
4546#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
4547// This file was GENERATED by command:
4548// pump.py gmock-generated-function-mockers.h.pump
4549// DO NOT EDIT BY HAND!!!
4550
4551// Copyright 2007, Google Inc.
4552// All rights reserved.
4553//
4554// Redistribution and use in source and binary forms, with or without
4555// modification, are permitted provided that the following conditions are
4556// met:
4557//
4558// * Redistributions of source code must retain the above copyright
4559// notice, this list of conditions and the following disclaimer.
4560// * Redistributions in binary form must reproduce the above
4561// copyright notice, this list of conditions and the following disclaimer
4562// in the documentation and/or other materials provided with the
4563// distribution.
4564// * Neither the name of Google Inc. nor the names of its
4565// contributors may be used to endorse or promote products derived from
4566// this software without specific prior written permission.
4567//
4568// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4569// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
4570// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
4571// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
4572// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
4573// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
4574// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
4575// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
4576// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
4577// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
4578// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4579//
4580// Author: wan@google.com (Zhanyong Wan)
4581
4582// Google Mock - a framework for writing C++ mock classes.
4583//
4584// This file implements function mockers of various arities.
4585
4586#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
4587#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
4588
4589// Copyright 2007, Google Inc.
4590// All rights reserved.
4591//
4592// Redistribution and use in source and binary forms, with or without
4593// modification, are permitted provided that the following conditions are
4594// met:
4595//
4596// * Redistributions of source code must retain the above copyright
4597// notice, this list of conditions and the following disclaimer.
4598// * Redistributions in binary form must reproduce the above
4599// copyright notice, this list of conditions and the following disclaimer
4600// in the documentation and/or other materials provided with the
4601// distribution.
4602// * Neither the name of Google Inc. nor the names of its
4603// contributors may be used to endorse or promote products derived from
4604// this software without specific prior written permission.
4605//
4606// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4607// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
4608// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
4609// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
4610// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
4611// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
4612// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
4613// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
4614// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
4615// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
4616// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4617//
4618// Author: wan@google.com (Zhanyong Wan)
4619
4620// Google Mock - a framework for writing C++ mock classes.
4621//
4622// This file implements the ON_CALL() and EXPECT_CALL() macros.
4623//
4624// A user can use the ON_CALL() macro to specify the default action of
4625// a mock method. The syntax is:
4626//
4627// ON_CALL(mock_object, Method(argument-matchers))
4628// .With(multi-argument-matcher)
4629// .WillByDefault(action);
4630//
4631// where the .With() clause is optional.
4632//
4633// A user can use the EXPECT_CALL() macro to specify an expectation on
4634// a mock method. The syntax is:
4635//
4636// EXPECT_CALL(mock_object, Method(argument-matchers))
4637// .With(multi-argument-matchers)
4638// .Times(cardinality)
4639// .InSequence(sequences)
4640// .After(expectations)
4641// .WillOnce(action)
4642// .WillRepeatedly(action)
4643// .RetiresOnSaturation();
4644//
4645// where all clauses are optional, and .InSequence()/.After()/
4646// .WillOnce() can appear any number of times.
4647
4648#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_
4649#define GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_
4650
4651#include <map>
4652#include <set>
4653#include <sstream>
4654#include <string>
4655#include <vector>
4656
4657#if GTEST_HAS_EXCEPTIONS
4658# include <stdexcept> // NOLINT
4659#endif
4660
4661// Copyright 2007, Google Inc.
4662// All rights reserved.
4663//
4664// Redistribution and use in source and binary forms, with or without
4665// modification, are permitted provided that the following conditions are
4666// met:
4667//
4668// * Redistributions of source code must retain the above copyright
4669// notice, this list of conditions and the following disclaimer.
4670// * Redistributions in binary form must reproduce the above
4671// copyright notice, this list of conditions and the following disclaimer
4672// in the documentation and/or other materials provided with the
4673// distribution.
4674// * Neither the name of Google Inc. nor the names of its
4675// contributors may be used to endorse or promote products derived from
4676// this software without specific prior written permission.
4677//
4678// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4679// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
4680// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
4681// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
4682// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
4683// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
4684// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
4685// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
4686// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
4687// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
4688// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4689//
4690// Author: wan@google.com (Zhanyong Wan)
4691
4692// Google Mock - a framework for writing C++ mock classes.
4693//
4694// This file implements some commonly used argument matchers. More
4695// matchers can be defined by the user implementing the
4696// MatcherInterface<T> interface if necessary.
4697
4698#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
4699#define GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
4700
4701#include <math.h>
4702#include <algorithm>
4703#include <iterator>
4704#include <limits>
4705#include <ostream> // NOLINT
4706#include <sstream>
4707#include <string>
4708#include <utility>
4709#include <vector>
4710
4711
4712#if GTEST_LANG_CXX11
4713#include <initializer_list> // NOLINT -- must be after gtest.h
4714#endif
4715
4716namespace testing {
4717
4718// To implement a matcher Foo for type T, define:
4719// 1. a class FooMatcherImpl that implements the
4720// MatcherInterface<T> interface, and
4721// 2. a factory function that creates a Matcher<T> object from a
4722// FooMatcherImpl*.
4723//
4724// The two-level delegation design makes it possible to allow a user
4725// to write "v" instead of "Eq(v)" where a Matcher is expected, which
4726// is impossible if we pass matchers by pointers. It also eases
4727// ownership management as Matcher objects can now be copied like
4728// plain values.
4729
4730// MatchResultListener is an abstract class. Its << operator can be
4731// used by a matcher to explain why a value matches or doesn't match.
4732//
4733// TODO(wan@google.com): add method
4734// bool InterestedInWhy(bool result) const;
4735// to indicate whether the listener is interested in why the match
4736// result is 'result'.
4737class MatchResultListener {
4738 public:
4739 // Creates a listener object with the given underlying ostream. The
4740 // listener does not own the ostream, and does not dereference it
4741 // in the constructor or destructor.
4742 explicit MatchResultListener(::std::ostream* os) : stream_(os) {}
4743 virtual ~MatchResultListener() = 0; // Makes this class abstract.
4744
4745 // Streams x to the underlying ostream; does nothing if the ostream
4746 // is NULL.
4747 template <typename T>
4748 MatchResultListener& operator<<(const T& x) {
4749 if (stream_ != NULL)
4750 *stream_ << x;
4751 return *this;
4752 }
4753
4754 // Returns the underlying ostream.
4755 ::std::ostream* stream() { return stream_; }
4756
4757 // Returns true iff the listener is interested in an explanation of
4758 // the match result. A matcher's MatchAndExplain() method can use
4759 // this information to avoid generating the explanation when no one
4760 // intends to hear it.
4761 bool IsInterested() const { return stream_ != NULL; }
4762
4763 private:
4764 ::std::ostream* const stream_;
4765
4766 GTEST_DISALLOW_COPY_AND_ASSIGN_(MatchResultListener);
4767};
4768
4769inline MatchResultListener::~MatchResultListener() {
4770}
4771
4772// An instance of a subclass of this knows how to describe itself as a
4773// matcher.
4774class MatcherDescriberInterface {
4775 public:
4776 virtual ~MatcherDescriberInterface() {}
4777
4778 // Describes this matcher to an ostream. The function should print
4779 // a verb phrase that describes the property a value matching this
4780 // matcher should have. The subject of the verb phrase is the value
4781 // being matched. For example, the DescribeTo() method of the Gt(7)
4782 // matcher prints "is greater than 7".
4783 virtual void DescribeTo(::std::ostream* os) const = 0;
4784
4785 // Describes the negation of this matcher to an ostream. For
4786 // example, if the description of this matcher is "is greater than
4787 // 7", the negated description could be "is not greater than 7".
4788 // You are not required to override this when implementing
4789 // MatcherInterface, but it is highly advised so that your matcher
4790 // can produce good error messages.
4791 virtual void DescribeNegationTo(::std::ostream* os) const {
4792 *os << "not (";
4793 DescribeTo(os);
4794 *os << ")";
4795 }
4796};
4797
4798// The implementation of a matcher.
4799template <typename T>
4800class MatcherInterface : public MatcherDescriberInterface {
4801 public:
4802 // Returns true iff the matcher matches x; also explains the match
4803 // result to 'listener' if necessary (see the next paragraph), in
4804 // the form of a non-restrictive relative clause ("which ...",
4805 // "whose ...", etc) that describes x. For example, the
4806 // MatchAndExplain() method of the Pointee(...) matcher should
4807 // generate an explanation like "which points to ...".
4808 //
4809 // Implementations of MatchAndExplain() should add an explanation of
4810 // the match result *if and only if* they can provide additional
4811 // information that's not already present (or not obvious) in the
4812 // print-out of x and the matcher's description. Whether the match
4813 // succeeds is not a factor in deciding whether an explanation is
4814 // needed, as sometimes the caller needs to print a failure message
4815 // when the match succeeds (e.g. when the matcher is used inside
4816 // Not()).
4817 //
4818 // For example, a "has at least 10 elements" matcher should explain
4819 // what the actual element count is, regardless of the match result,
4820 // as it is useful information to the reader; on the other hand, an
4821 // "is empty" matcher probably only needs to explain what the actual
4822 // size is when the match fails, as it's redundant to say that the
4823 // size is 0 when the value is already known to be empty.
4824 //
4825 // You should override this method when defining a new matcher.
4826 //
4827 // It's the responsibility of the caller (Google Mock) to guarantee
4828 // that 'listener' is not NULL. This helps to simplify a matcher's
4829 // implementation when it doesn't care about the performance, as it
4830 // can talk to 'listener' without checking its validity first.
4831 // However, in order to implement dummy listeners efficiently,
4832 // listener->stream() may be NULL.
4833 virtual bool MatchAndExplain(T x, MatchResultListener* listener) const = 0;
4834
4835 // Inherits these methods from MatcherDescriberInterface:
4836 // virtual void DescribeTo(::std::ostream* os) const = 0;
4837 // virtual void DescribeNegationTo(::std::ostream* os) const;
4838};
4839
4840// A match result listener that stores the explanation in a string.
4841class StringMatchResultListener : public MatchResultListener {
4842 public:
4843 StringMatchResultListener() : MatchResultListener(&ss_) {}
4844
4845 // Returns the explanation accumulated so far.
4846 internal::string str() const { return ss_.str(); }
4847
4848 // Clears the explanation accumulated so far.
4849 void Clear() { ss_.str(""); }
4850
4851 private:
4852 ::std::stringstream ss_;
4853
4854 GTEST_DISALLOW_COPY_AND_ASSIGN_(StringMatchResultListener);
4855};
4856
4857namespace internal {
4858
4859// A match result listener that ignores the explanation.
4860class DummyMatchResultListener : public MatchResultListener {
4861 public:
4862 DummyMatchResultListener() : MatchResultListener(NULL) {}
4863
4864 private:
4865 GTEST_DISALLOW_COPY_AND_ASSIGN_(DummyMatchResultListener);
4866};
4867
4868// A match result listener that forwards the explanation to a given
4869// ostream. The difference between this and MatchResultListener is
4870// that the former is concrete.
4871class StreamMatchResultListener : public MatchResultListener {
4872 public:
4873 explicit StreamMatchResultListener(::std::ostream* os)
4874 : MatchResultListener(os) {}
4875
4876 private:
4877 GTEST_DISALLOW_COPY_AND_ASSIGN_(StreamMatchResultListener);
4878};
4879
4880// An internal class for implementing Matcher<T>, which will derive
4881// from it. We put functionalities common to all Matcher<T>
4882// specializations here to avoid code duplication.
4883template <typename T>
4884class MatcherBase {
4885 public:
4886 // Returns true iff the matcher matches x; also explains the match
4887 // result to 'listener'.
4888 bool MatchAndExplain(T x, MatchResultListener* listener) const {
4889 return impl_->MatchAndExplain(x, listener);
4890 }
4891
4892 // Returns true iff this matcher matches x.
4893 bool Matches(T x) const {
4894 DummyMatchResultListener dummy;
4895 return MatchAndExplain(x, &dummy);
4896 }
4897
4898 // Describes this matcher to an ostream.
4899 void DescribeTo(::std::ostream* os) const { impl_->DescribeTo(os); }
4900
4901 // Describes the negation of this matcher to an ostream.
4902 void DescribeNegationTo(::std::ostream* os) const {
4903 impl_->DescribeNegationTo(os);
4904 }
4905
4906 // Explains why x matches, or doesn't match, the matcher.
4907 void ExplainMatchResultTo(T x, ::std::ostream* os) const {
4908 StreamMatchResultListener listener(os);
4909 MatchAndExplain(x, &listener);
4910 }
4911
4912 // Returns the describer for this matcher object; retains ownership
4913 // of the describer, which is only guaranteed to be alive when
4914 // this matcher object is alive.
4915 const MatcherDescriberInterface* GetDescriber() const {
4916 return impl_.get();
4917 }
4918
4919 protected:
4920 MatcherBase() {}
4921
4922 // Constructs a matcher from its implementation.
4923 explicit MatcherBase(const MatcherInterface<T>* impl)
4924 : impl_(impl) {}
4925
4926 virtual ~MatcherBase() {}
4927
4928 private:
4929 // shared_ptr (util/gtl/shared_ptr.h) and linked_ptr have similar
4930 // interfaces. The former dynamically allocates a chunk of memory
4931 // to hold the reference count, while the latter tracks all
4932 // references using a circular linked list without allocating
4933 // memory. It has been observed that linked_ptr performs better in
4934 // typical scenarios. However, shared_ptr can out-perform
4935 // linked_ptr when there are many more uses of the copy constructor
4936 // than the default constructor.
4937 //
4938 // If performance becomes a problem, we should see if using
4939 // shared_ptr helps.
4940 ::testing::internal::linked_ptr<const MatcherInterface<T> > impl_;
4941};
4942
4943} // namespace internal
4944
4945// A Matcher<T> is a copyable and IMMUTABLE (except by assignment)
4946// object that can check whether a value of type T matches. The
4947// implementation of Matcher<T> is just a linked_ptr to const
4948// MatcherInterface<T>, so copying is fairly cheap. Don't inherit
4949// from Matcher!
4950template <typename T>
4951class Matcher : public internal::MatcherBase<T> {
4952 public:
4953 // Constructs a null matcher. Needed for storing Matcher objects in STL
4954 // containers. A default-constructed matcher is not yet initialized. You
4955 // cannot use it until a valid value has been assigned to it.
4956 Matcher() {}
4957
4958 // Constructs a matcher from its implementation.
4959 explicit Matcher(const MatcherInterface<T>* impl)
4960 : internal::MatcherBase<T>(impl) {}
4961
4962 // Implicit constructor here allows people to write
4963 // EXPECT_CALL(foo, Bar(5)) instead of EXPECT_CALL(foo, Bar(Eq(5))) sometimes
4964 Matcher(T value); // NOLINT
4965};
4966
4967// The following two specializations allow the user to write str
4968// instead of Eq(str) and "foo" instead of Eq("foo") when a string
4969// matcher is expected.
4970template <>
4971class GTEST_API_ Matcher<const internal::string&>
4972 : public internal::MatcherBase<const internal::string&> {
4973 public:
4974 Matcher() {}
4975
4976 explicit Matcher(const MatcherInterface<const internal::string&>* impl)
4977 : internal::MatcherBase<const internal::string&>(impl) {}
4978
4979 // Allows the user to write str instead of Eq(str) sometimes, where
4980 // str is a string object.
4981 Matcher(const internal::string& s); // NOLINT
4982
4983 // Allows the user to write "foo" instead of Eq("foo") sometimes.
4984 Matcher(const char* s); // NOLINT
4985};
4986
4987template <>
4988class GTEST_API_ Matcher<internal::string>
4989 : public internal::MatcherBase<internal::string> {
4990 public:
4991 Matcher() {}
4992
4993 explicit Matcher(const MatcherInterface<internal::string>* impl)
4994 : internal::MatcherBase<internal::string>(impl) {}
4995
4996 // Allows the user to write str instead of Eq(str) sometimes, where
4997 // str is a string object.
4998 Matcher(const internal::string& s); // NOLINT
4999
5000 // Allows the user to write "foo" instead of Eq("foo") sometimes.
5001 Matcher(const char* s); // NOLINT
5002};
5003
5004#if GTEST_HAS_STRING_PIECE_
5005// The following two specializations allow the user to write str
5006// instead of Eq(str) and "foo" instead of Eq("foo") when a StringPiece
5007// matcher is expected.
5008template <>
5009class GTEST_API_ Matcher<const StringPiece&>
5010 : public internal::MatcherBase<const StringPiece&> {
5011 public:
5012 Matcher() {}
5013
5014 explicit Matcher(const MatcherInterface<const StringPiece&>* impl)
5015 : internal::MatcherBase<const StringPiece&>(impl) {}
5016
5017 // Allows the user to write str instead of Eq(str) sometimes, where
5018 // str is a string object.
5019 Matcher(const internal::string& s); // NOLINT
5020
5021 // Allows the user to write "foo" instead of Eq("foo") sometimes.
5022 Matcher(const char* s); // NOLINT
5023
5024 // Allows the user to pass StringPieces directly.
5025 Matcher(StringPiece s); // NOLINT
5026};
5027
5028template <>
5029class GTEST_API_ Matcher<StringPiece>
5030 : public internal::MatcherBase<StringPiece> {
5031 public:
5032 Matcher() {}
5033
5034 explicit Matcher(const MatcherInterface<StringPiece>* impl)
5035 : internal::MatcherBase<StringPiece>(impl) {}
5036
5037 // Allows the user to write str instead of Eq(str) sometimes, where
5038 // str is a string object.
5039 Matcher(const internal::string& s); // NOLINT
5040
5041 // Allows the user to write "foo" instead of Eq("foo") sometimes.
5042 Matcher(const char* s); // NOLINT
5043
5044 // Allows the user to pass StringPieces directly.
5045 Matcher(StringPiece s); // NOLINT
5046};
5047#endif // GTEST_HAS_STRING_PIECE_
5048
5049// The PolymorphicMatcher class template makes it easy to implement a
5050// polymorphic matcher (i.e. a matcher that can match values of more
5051// than one type, e.g. Eq(n) and NotNull()).
5052//
5053// To define a polymorphic matcher, a user should provide an Impl
5054// class that has a DescribeTo() method and a DescribeNegationTo()
5055// method, and define a member function (or member function template)
5056//
5057// bool MatchAndExplain(const Value& value,
5058// MatchResultListener* listener) const;
5059//
5060// See the definition of NotNull() for a complete example.
5061template <class Impl>
5062class PolymorphicMatcher {
5063 public:
5064 explicit PolymorphicMatcher(const Impl& an_impl) : impl_(an_impl) {}
5065
5066 // Returns a mutable reference to the underlying matcher
5067 // implementation object.
5068 Impl& mutable_impl() { return impl_; }
5069
5070 // Returns an immutable reference to the underlying matcher
5071 // implementation object.
5072 const Impl& impl() const { return impl_; }
5073
5074 template <typename T>
5075 operator Matcher<T>() const {
5076 return Matcher<T>(new MonomorphicImpl<T>(impl_));
5077 }
5078
5079 private:
5080 template <typename T>
5081 class MonomorphicImpl : public MatcherInterface<T> {
5082 public:
5083 explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {}
5084
5085 virtual void DescribeTo(::std::ostream* os) const {
5086 impl_.DescribeTo(os);
5087 }
5088
5089 virtual void DescribeNegationTo(::std::ostream* os) const {
5090 impl_.DescribeNegationTo(os);
5091 }
5092
5093 virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
5094 return impl_.MatchAndExplain(x, listener);
5095 }
5096
5097 private:
5098 const Impl impl_;
5099
5100 GTEST_DISALLOW_ASSIGN_(MonomorphicImpl);
5101 };
5102
5103 Impl impl_;
5104
5105 GTEST_DISALLOW_ASSIGN_(PolymorphicMatcher);
5106};
5107
5108// Creates a matcher from its implementation. This is easier to use
5109// than the Matcher<T> constructor as it doesn't require you to
5110// explicitly write the template argument, e.g.
5111//
5112// MakeMatcher(foo);
5113// vs
5114// Matcher<const string&>(foo);
5115template <typename T>
5116inline Matcher<T> MakeMatcher(const MatcherInterface<T>* impl) {
5117 return Matcher<T>(impl);
5118}
5119
5120// Creates a polymorphic matcher from its implementation. This is
5121// easier to use than the PolymorphicMatcher<Impl> constructor as it
5122// doesn't require you to explicitly write the template argument, e.g.
5123//
5124// MakePolymorphicMatcher(foo);
5125// vs
5126// PolymorphicMatcher<TypeOfFoo>(foo);
5127template <class Impl>
5128inline PolymorphicMatcher<Impl> MakePolymorphicMatcher(const Impl& impl) {
5129 return PolymorphicMatcher<Impl>(impl);
5130}
5131
5132// Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION
5133// and MUST NOT BE USED IN USER CODE!!!
5134namespace internal {
5135
5136// The MatcherCastImpl class template is a helper for implementing
5137// MatcherCast(). We need this helper in order to partially
5138// specialize the implementation of MatcherCast() (C++ allows
5139// class/struct templates to be partially specialized, but not
5140// function templates.).
5141
5142// This general version is used when MatcherCast()'s argument is a
5143// polymorphic matcher (i.e. something that can be converted to a
5144// Matcher but is not one yet; for example, Eq(value)) or a value (for
5145// example, "hello").
5146template <typename T, typename M>
5147class MatcherCastImpl {
5148 public:
5149 static Matcher<T> Cast(M polymorphic_matcher_or_value) {
5150 // M can be a polymorhic matcher, in which case we want to use
5151 // its conversion operator to create Matcher<T>. Or it can be a value
5152 // that should be passed to the Matcher<T>'s constructor.
5153 //
5154 // We can't call Matcher<T>(polymorphic_matcher_or_value) when M is a
5155 // polymorphic matcher because it'll be ambiguous if T has an implicit
5156 // constructor from M (this usually happens when T has an implicit
5157 // constructor from any type).
5158 //
5159 // It won't work to unconditionally implict_cast
5160 // polymorphic_matcher_or_value to Matcher<T> because it won't trigger
5161 // a user-defined conversion from M to T if one exists (assuming M is
5162 // a value).
5163 return CastImpl(
5164 polymorphic_matcher_or_value,
5165 BooleanConstant<
5166 internal::ImplicitlyConvertible<M, Matcher<T> >::value>());
5167 }
5168
5169 private:
5170 static Matcher<T> CastImpl(M value, BooleanConstant<false>) {
5171 // M can't be implicitly converted to Matcher<T>, so M isn't a polymorphic
5172 // matcher. It must be a value then. Use direct initialization to create
5173 // a matcher.
5174 return Matcher<T>(ImplicitCast_<T>(value));
5175 }
5176
5177 static Matcher<T> CastImpl(M polymorphic_matcher_or_value,
5178 BooleanConstant<true>) {
5179 // M is implicitly convertible to Matcher<T>, which means that either
5180 // M is a polymorhpic matcher or Matcher<T> has an implicit constructor
5181 // from M. In both cases using the implicit conversion will produce a
5182 // matcher.
5183 //
5184 // Even if T has an implicit constructor from M, it won't be called because
5185 // creating Matcher<T> would require a chain of two user-defined conversions
5186 // (first to create T from M and then to create Matcher<T> from T).
5187 return polymorphic_matcher_or_value;
5188 }
5189};
5190
5191// This more specialized version is used when MatcherCast()'s argument
5192// is already a Matcher. This only compiles when type T can be
5193// statically converted to type U.
5194template <typename T, typename U>
5195class MatcherCastImpl<T, Matcher<U> > {
5196 public:
5197 static Matcher<T> Cast(const Matcher<U>& source_matcher) {
5198 return Matcher<T>(new Impl(source_matcher));
5199 }
5200
5201 private:
5202 class Impl : public MatcherInterface<T> {
5203 public:
5204 explicit Impl(const Matcher<U>& source_matcher)
5205 : source_matcher_(source_matcher) {}
5206
5207 // We delegate the matching logic to the source matcher.
5208 virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
5209 return source_matcher_.MatchAndExplain(static_cast<U>(x), listener);
5210 }
5211
5212 virtual void DescribeTo(::std::ostream* os) const {
5213 source_matcher_.DescribeTo(os);
5214 }
5215
5216 virtual void DescribeNegationTo(::std::ostream* os) const {
5217 source_matcher_.DescribeNegationTo(os);
5218 }
5219
5220 private:
5221 const Matcher<U> source_matcher_;
5222
5223 GTEST_DISALLOW_ASSIGN_(Impl);
5224 };
5225};
5226
5227// This even more specialized version is used for efficiently casting
5228// a matcher to its own type.
5229template <typename T>
5230class MatcherCastImpl<T, Matcher<T> > {
5231 public:
5232 static Matcher<T> Cast(const Matcher<T>& matcher) { return matcher; }
5233};
5234
5235} // namespace internal
5236
5237// In order to be safe and clear, casting between different matcher
5238// types is done explicitly via MatcherCast<T>(m), which takes a
5239// matcher m and returns a Matcher<T>. It compiles only when T can be
5240// statically converted to the argument type of m.
5241template <typename T, typename M>
5242inline Matcher<T> MatcherCast(M matcher) {
5243 return internal::MatcherCastImpl<T, M>::Cast(matcher);
5244}
5245
5246// Implements SafeMatcherCast().
5247//
5248// We use an intermediate class to do the actual safe casting as Nokia's
5249// Symbian compiler cannot decide between
5250// template <T, M> ... (M) and
5251// template <T, U> ... (const Matcher<U>&)
5252// for function templates but can for member function templates.
5253template <typename T>
5254class SafeMatcherCastImpl {
5255 public:
5256 // This overload handles polymorphic matchers and values only since
5257 // monomorphic matchers are handled by the next one.
5258 template <typename M>
5259 static inline Matcher<T> Cast(M polymorphic_matcher_or_value) {
5260 return internal::MatcherCastImpl<T, M>::Cast(polymorphic_matcher_or_value);
5261 }
5262
5263 // This overload handles monomorphic matchers.
5264 //
5265 // In general, if type T can be implicitly converted to type U, we can
5266 // safely convert a Matcher<U> to a Matcher<T> (i.e. Matcher is
5267 // contravariant): just keep a copy of the original Matcher<U>, convert the
5268 // argument from type T to U, and then pass it to the underlying Matcher<U>.
5269 // The only exception is when U is a reference and T is not, as the
5270 // underlying Matcher<U> may be interested in the argument's address, which
5271 // is not preserved in the conversion from T to U.
5272 template <typename U>
5273 static inline Matcher<T> Cast(const Matcher<U>& matcher) {
5274 // Enforce that T can be implicitly converted to U.
5275 GTEST_COMPILE_ASSERT_((internal::ImplicitlyConvertible<T, U>::value),
5276 T_must_be_implicitly_convertible_to_U);
5277 // Enforce that we are not converting a non-reference type T to a reference
5278 // type U.
5279 GTEST_COMPILE_ASSERT_(
5280 internal::is_reference<T>::value || !internal::is_reference<U>::value,
5281 cannot_convert_non_referentce_arg_to_reference);
5282 // In case both T and U are arithmetic types, enforce that the
5283 // conversion is not lossy.
5284 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(T) RawT;
5285 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(U) RawU;
5286 const bool kTIsOther = GMOCK_KIND_OF_(RawT) == internal::kOther;
5287 const bool kUIsOther = GMOCK_KIND_OF_(RawU) == internal::kOther;
5288 GTEST_COMPILE_ASSERT_(
5289 kTIsOther || kUIsOther ||
5290 (internal::LosslessArithmeticConvertible<RawT, RawU>::value),
5291 conversion_of_arithmetic_types_must_be_lossless);
5292 return MatcherCast<T>(matcher);
5293 }
5294};
5295
5296template <typename T, typename M>
5297inline Matcher<T> SafeMatcherCast(const M& polymorphic_matcher) {
5298 return SafeMatcherCastImpl<T>::Cast(polymorphic_matcher);
5299}
5300
5301// A<T>() returns a matcher that matches any value of type T.
5302template <typename T>
5303Matcher<T> A();
5304
5305// Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION
5306// and MUST NOT BE USED IN USER CODE!!!
5307namespace internal {
5308
5309// If the explanation is not empty, prints it to the ostream.
5310inline void PrintIfNotEmpty(const internal::string& explanation,
5311 ::std::ostream* os) {
5312 if (explanation != "" && os != NULL) {
5313 *os << ", " << explanation;
5314 }
5315}
5316
5317// Returns true if the given type name is easy to read by a human.
5318// This is used to decide whether printing the type of a value might
5319// be helpful.
5320inline bool IsReadableTypeName(const string& type_name) {
5321 // We consider a type name readable if it's short or doesn't contain
5322 // a template or function type.
5323 return (type_name.length() <= 20 ||
5324 type_name.find_first_of("<(") == string::npos);
5325}
5326
5327// Matches the value against the given matcher, prints the value and explains
5328// the match result to the listener. Returns the match result.
5329// 'listener' must not be NULL.
5330// Value cannot be passed by const reference, because some matchers take a
5331// non-const argument.
5332template <typename Value, typename T>
5333bool MatchPrintAndExplain(Value& value, const Matcher<T>& matcher,
5334 MatchResultListener* listener) {
5335 if (!listener->IsInterested()) {
5336 // If the listener is not interested, we do not need to construct the
5337 // inner explanation.
5338 return matcher.Matches(value);
5339 }
5340
5341 StringMatchResultListener inner_listener;
5342 const bool match = matcher.MatchAndExplain(value, &inner_listener);
5343
5344 UniversalPrint(value, listener->stream());
5345#if GTEST_HAS_RTTI
5346 const string& type_name = GetTypeName<Value>();
5347 if (IsReadableTypeName(type_name))
5348 *listener->stream() << " (of type " << type_name << ")";
5349#endif
5350 PrintIfNotEmpty(inner_listener.str(), listener->stream());
5351
5352 return match;
5353}
5354
5355// An internal helper class for doing compile-time loop on a tuple's
5356// fields.
5357template <size_t N>
5358class TuplePrefix {
5359 public:
5360 // TuplePrefix<N>::Matches(matcher_tuple, value_tuple) returns true
5361 // iff the first N fields of matcher_tuple matches the first N
5362 // fields of value_tuple, respectively.
5363 template <typename MatcherTuple, typename ValueTuple>
5364 static bool Matches(const MatcherTuple& matcher_tuple,
5365 const ValueTuple& value_tuple) {
5366 using ::std::tr1::get;
5367 return TuplePrefix<N - 1>::Matches(matcher_tuple, value_tuple)
5368 && get<N - 1>(matcher_tuple).Matches(get<N - 1>(value_tuple));
5369 }
5370
5371 // TuplePrefix<N>::ExplainMatchFailuresTo(matchers, values, os)
5372 // describes failures in matching the first N fields of matchers
5373 // against the first N fields of values. If there is no failure,
5374 // nothing will be streamed to os.
5375 template <typename MatcherTuple, typename ValueTuple>
5376 static void ExplainMatchFailuresTo(const MatcherTuple& matchers,
5377 const ValueTuple& values,
5378 ::std::ostream* os) {
5379 using ::std::tr1::tuple_element;
5380 using ::std::tr1::get;
5381
5382 // First, describes failures in the first N - 1 fields.
5383 TuplePrefix<N - 1>::ExplainMatchFailuresTo(matchers, values, os);
5384
5385 // Then describes the failure (if any) in the (N - 1)-th (0-based)
5386 // field.
5387 typename tuple_element<N - 1, MatcherTuple>::type matcher =
5388 get<N - 1>(matchers);
5389 typedef typename tuple_element<N - 1, ValueTuple>::type Value;
5390 Value value = get<N - 1>(values);
5391 StringMatchResultListener listener;
5392 if (!matcher.MatchAndExplain(value, &listener)) {
5393 // TODO(wan): include in the message the name of the parameter
5394 // as used in MOCK_METHOD*() when possible.
5395 *os << " Expected arg #" << N - 1 << ": ";
5396 get<N - 1>(matchers).DescribeTo(os);
5397 *os << "\n Actual: ";
5398 // We remove the reference in type Value to prevent the
5399 // universal printer from printing the address of value, which
5400 // isn't interesting to the user most of the time. The
5401 // matcher's MatchAndExplain() method handles the case when
5402 // the address is interesting.
5403 internal::UniversalPrint(value, os);
5404 PrintIfNotEmpty(listener.str(), os);
5405 *os << "\n";
5406 }
5407 }
5408};
5409
5410// The base case.
5411template <>
5412class TuplePrefix<0> {
5413 public:
5414 template <typename MatcherTuple, typename ValueTuple>
5415 static bool Matches(const MatcherTuple& /* matcher_tuple */,
5416 const ValueTuple& /* value_tuple */) {
5417 return true;
5418 }
5419
5420 template <typename MatcherTuple, typename ValueTuple>
5421 static void ExplainMatchFailuresTo(const MatcherTuple& /* matchers */,
5422 const ValueTuple& /* values */,
5423 ::std::ostream* /* os */) {}
5424};
5425
5426// TupleMatches(matcher_tuple, value_tuple) returns true iff all
5427// matchers in matcher_tuple match the corresponding fields in
5428// value_tuple. It is a compiler error if matcher_tuple and
5429// value_tuple have different number of fields or incompatible field
5430// types.
5431template <typename MatcherTuple, typename ValueTuple>
5432bool TupleMatches(const MatcherTuple& matcher_tuple,
5433 const ValueTuple& value_tuple) {
5434 using ::std::tr1::tuple_size;
5435 // Makes sure that matcher_tuple and value_tuple have the same
5436 // number of fields.
5437 GTEST_COMPILE_ASSERT_(tuple_size<MatcherTuple>::value ==
5438 tuple_size<ValueTuple>::value,
5439 matcher_and_value_have_different_numbers_of_fields);
5440 return TuplePrefix<tuple_size<ValueTuple>::value>::
5441 Matches(matcher_tuple, value_tuple);
5442}
5443
5444// Describes failures in matching matchers against values. If there
5445// is no failure, nothing will be streamed to os.
5446template <typename MatcherTuple, typename ValueTuple>
5447void ExplainMatchFailureTupleTo(const MatcherTuple& matchers,
5448 const ValueTuple& values,
5449 ::std::ostream* os) {
5450 using ::std::tr1::tuple_size;
5451 TuplePrefix<tuple_size<MatcherTuple>::value>::ExplainMatchFailuresTo(
5452 matchers, values, os);
5453}
5454
5455// TransformTupleValues and its helper.
5456//
5457// TransformTupleValuesHelper hides the internal machinery that
5458// TransformTupleValues uses to implement a tuple traversal.
5459template <typename Tuple, typename Func, typename OutIter>
5460class TransformTupleValuesHelper {
5461 private:
5462 typedef typename ::std::tr1::tuple_size<Tuple> TupleSize;
5463
5464 public:
5465 // For each member of tuple 't', taken in order, evaluates '*out++ = f(t)'.
5466 // Returns the final value of 'out' in case the caller needs it.
5467 static OutIter Run(Func f, const Tuple& t, OutIter out) {
5468 return IterateOverTuple<Tuple, TupleSize::value>()(f, t, out);
5469 }
5470
5471 private:
5472 template <typename Tup, size_t kRemainingSize>
5473 struct IterateOverTuple {
5474 OutIter operator() (Func f, const Tup& t, OutIter out) const {
5475 *out++ = f(::std::tr1::get<TupleSize::value - kRemainingSize>(t));
5476 return IterateOverTuple<Tup, kRemainingSize - 1>()(f, t, out);
5477 }
5478 };
5479 template <typename Tup>
5480 struct IterateOverTuple<Tup, 0> {
5481 OutIter operator() (Func /* f */, const Tup& /* t */, OutIter out) const {
5482 return out;
5483 }
5484 };
5485};
5486
5487// Successively invokes 'f(element)' on each element of the tuple 't',
5488// appending each result to the 'out' iterator. Returns the final value
5489// of 'out'.
5490template <typename Tuple, typename Func, typename OutIter>
5491OutIter TransformTupleValues(Func f, const Tuple& t, OutIter out) {
5492 return TransformTupleValuesHelper<Tuple, Func, OutIter>::Run(f, t, out);
5493}
5494
5495// Implements A<T>().
5496template <typename T>
5497class AnyMatcherImpl : public MatcherInterface<T> {
5498 public:
5499 virtual bool MatchAndExplain(
5500 T /* x */, MatchResultListener* /* listener */) const { return true; }
5501 virtual void DescribeTo(::std::ostream* os) const { *os << "is anything"; }
5502 virtual void DescribeNegationTo(::std::ostream* os) const {
5503 // This is mostly for completeness' safe, as it's not very useful
5504 // to write Not(A<bool>()). However we cannot completely rule out
5505 // such a possibility, and it doesn't hurt to be prepared.
5506 *os << "never matches";
5507 }
5508};
5509
5510// Implements _, a matcher that matches any value of any
5511// type. This is a polymorphic matcher, so we need a template type
5512// conversion operator to make it appearing as a Matcher<T> for any
5513// type T.
5514class AnythingMatcher {
5515 public:
5516 template <typename T>
5517 operator Matcher<T>() const { return A<T>(); }
5518};
5519
5520// Implements a matcher that compares a given value with a
5521// pre-supplied value using one of the ==, <=, <, etc, operators. The
5522// two values being compared don't have to have the same type.
5523//
5524// The matcher defined here is polymorphic (for example, Eq(5) can be
5525// used to match an int, a short, a double, etc). Therefore we use
5526// a template type conversion operator in the implementation.
5527//
5528// We define this as a macro in order to eliminate duplicated source
5529// code.
5530//
5531// The following template definition assumes that the Rhs parameter is
5532// a "bare" type (i.e. neither 'const T' nor 'T&').
5533#define GMOCK_IMPLEMENT_COMPARISON_MATCHER_( \
5534 name, op, relation, negated_relation) \
5535 template <typename Rhs> class name##Matcher { \
5536 public: \
5537 explicit name##Matcher(const Rhs& rhs) : rhs_(rhs) {} \
5538 template <typename Lhs> \
5539 operator Matcher<Lhs>() const { \
5540 return MakeMatcher(new Impl<Lhs>(rhs_)); \
5541 } \
5542 private: \
5543 template <typename Lhs> \
5544 class Impl : public MatcherInterface<Lhs> { \
5545 public: \
5546 explicit Impl(const Rhs& rhs) : rhs_(rhs) {} \
5547 virtual bool MatchAndExplain(\
5548 Lhs lhs, MatchResultListener* /* listener */) const { \
5549 return lhs op rhs_; \
5550 } \
5551 virtual void DescribeTo(::std::ostream* os) const { \
5552 *os << relation " "; \
5553 UniversalPrint(rhs_, os); \
5554 } \
5555 virtual void DescribeNegationTo(::std::ostream* os) const { \
5556 *os << negated_relation " "; \
5557 UniversalPrint(rhs_, os); \
5558 } \
5559 private: \
5560 Rhs rhs_; \
5561 GTEST_DISALLOW_ASSIGN_(Impl); \
5562 }; \
5563 Rhs rhs_; \
5564 GTEST_DISALLOW_ASSIGN_(name##Matcher); \
5565 }
5566
5567// Implements Eq(v), Ge(v), Gt(v), Le(v), Lt(v), and Ne(v)
5568// respectively.
5569GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Eq, ==, "is equal to", "isn't equal to");
5570GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Ge, >=, "is >=", "isn't >=");
5571GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Gt, >, "is >", "isn't >");
5572GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Le, <=, "is <=", "isn't <=");
5573GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Lt, <, "is <", "isn't <");
5574GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Ne, !=, "isn't equal to", "is equal to");
5575
5576#undef GMOCK_IMPLEMENT_COMPARISON_MATCHER_
5577
5578// Implements the polymorphic IsNull() matcher, which matches any raw or smart
5579// pointer that is NULL.
5580class IsNullMatcher {
5581 public:
5582 template <typename Pointer>
5583 bool MatchAndExplain(const Pointer& p,
5584 MatchResultListener* /* listener */) const {
5585 return GetRawPointer(p) == NULL;
5586 }
5587
5588 void DescribeTo(::std::ostream* os) const { *os << "is NULL"; }
5589 void DescribeNegationTo(::std::ostream* os) const {
5590 *os << "isn't NULL";
5591 }
5592};
5593
5594// Implements the polymorphic NotNull() matcher, which matches any raw or smart
5595// pointer that is not NULL.
5596class NotNullMatcher {
5597 public:
5598 template <typename Pointer>
5599 bool MatchAndExplain(const Pointer& p,
5600 MatchResultListener* /* listener */) const {
5601 return GetRawPointer(p) != NULL;
5602 }
5603
5604 void DescribeTo(::std::ostream* os) const { *os << "isn't NULL"; }
5605 void DescribeNegationTo(::std::ostream* os) const {
5606 *os << "is NULL";
5607 }
5608};
5609
5610// Ref(variable) matches any argument that is a reference to
5611// 'variable'. This matcher is polymorphic as it can match any
5612// super type of the type of 'variable'.
5613//
5614// The RefMatcher template class implements Ref(variable). It can
5615// only be instantiated with a reference type. This prevents a user
5616// from mistakenly using Ref(x) to match a non-reference function
5617// argument. For example, the following will righteously cause a
5618// compiler error:
5619//
5620// int n;
5621// Matcher<int> m1 = Ref(n); // This won't compile.
5622// Matcher<int&> m2 = Ref(n); // This will compile.
5623template <typename T>
5624class RefMatcher;
5625
5626template <typename T>
5627class RefMatcher<T&> {
5628 // Google Mock is a generic framework and thus needs to support
5629 // mocking any function types, including those that take non-const
5630 // reference arguments. Therefore the template parameter T (and
5631 // Super below) can be instantiated to either a const type or a
5632 // non-const type.
5633 public:
5634 // RefMatcher() takes a T& instead of const T&, as we want the
5635 // compiler to catch using Ref(const_value) as a matcher for a
5636 // non-const reference.
5637 explicit RefMatcher(T& x) : object_(x) {} // NOLINT
5638
5639 template <typename Super>
5640 operator Matcher<Super&>() const {
5641 // By passing object_ (type T&) to Impl(), which expects a Super&,
5642 // we make sure that Super is a super type of T. In particular,
5643 // this catches using Ref(const_value) as a matcher for a
5644 // non-const reference, as you cannot implicitly convert a const
5645 // reference to a non-const reference.
5646 return MakeMatcher(new Impl<Super>(object_));
5647 }
5648
5649 private:
5650 template <typename Super>
5651 class Impl : public MatcherInterface<Super&> {
5652 public:
5653 explicit Impl(Super& x) : object_(x) {} // NOLINT
5654
5655 // MatchAndExplain() takes a Super& (as opposed to const Super&)
5656 // in order to match the interface MatcherInterface<Super&>.
5657 virtual bool MatchAndExplain(
5658 Super& x, MatchResultListener* listener) const {
5659 *listener << "which is located @" << static_cast<const void*>(&x);
5660 return &x == &object_;
5661 }
5662
5663 virtual void DescribeTo(::std::ostream* os) const {
5664 *os << "references the variable ";
5665 UniversalPrinter<Super&>::Print(object_, os);
5666 }
5667
5668 virtual void DescribeNegationTo(::std::ostream* os) const {
5669 *os << "does not reference the variable ";
5670 UniversalPrinter<Super&>::Print(object_, os);
5671 }
5672
5673 private:
5674 const Super& object_;
5675
5676 GTEST_DISALLOW_ASSIGN_(Impl);
5677 };
5678
5679 T& object_;
5680
5681 GTEST_DISALLOW_ASSIGN_(RefMatcher);
5682};
5683
5684// Polymorphic helper functions for narrow and wide string matchers.
5685inline bool CaseInsensitiveCStringEquals(const char* lhs, const char* rhs) {
5686 return String::CaseInsensitiveCStringEquals(lhs, rhs);
5687}
5688
5689inline bool CaseInsensitiveCStringEquals(const wchar_t* lhs,
5690 const wchar_t* rhs) {
5691 return String::CaseInsensitiveWideCStringEquals(lhs, rhs);
5692}
5693
5694// String comparison for narrow or wide strings that can have embedded NUL
5695// characters.
5696template <typename StringType>
5697bool CaseInsensitiveStringEquals(const StringType& s1,
5698 const StringType& s2) {
5699 // Are the heads equal?
5700 if (!CaseInsensitiveCStringEquals(s1.c_str(), s2.c_str())) {
5701 return false;
5702 }
5703
5704 // Skip the equal heads.
5705 const typename StringType::value_type nul = 0;
5706 const size_t i1 = s1.find(nul), i2 = s2.find(nul);
5707
5708 // Are we at the end of either s1 or s2?
5709 if (i1 == StringType::npos || i2 == StringType::npos) {
5710 return i1 == i2;
5711 }
5712
5713 // Are the tails equal?
5714 return CaseInsensitiveStringEquals(s1.substr(i1 + 1), s2.substr(i2 + 1));
5715}
5716
5717// String matchers.
5718
5719// Implements equality-based string matchers like StrEq, StrCaseNe, and etc.
5720template <typename StringType>
5721class StrEqualityMatcher {
5722 public:
5723 StrEqualityMatcher(const StringType& str, bool expect_eq,
5724 bool case_sensitive)
5725 : string_(str), expect_eq_(expect_eq), case_sensitive_(case_sensitive) {}
5726
5727 // Accepts pointer types, particularly:
5728 // const char*
5729 // char*
5730 // const wchar_t*
5731 // wchar_t*
5732 template <typename CharType>
5733 bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
5734 if (s == NULL) {
5735 return !expect_eq_;
5736 }
5737 return MatchAndExplain(StringType(s), listener);
5738 }
5739
5740 // Matches anything that can convert to StringType.
5741 //
5742 // This is a template, not just a plain function with const StringType&,
5743 // because StringPiece has some interfering non-explicit constructors.
5744 template <typename MatcheeStringType>
5745 bool MatchAndExplain(const MatcheeStringType& s,
5746 MatchResultListener* /* listener */) const {
5747 const StringType& s2(s);
5748 const bool eq = case_sensitive_ ? s2 == string_ :
5749 CaseInsensitiveStringEquals(s2, string_);
5750 return expect_eq_ == eq;
5751 }
5752
5753 void DescribeTo(::std::ostream* os) const {
5754 DescribeToHelper(expect_eq_, os);
5755 }
5756
5757 void DescribeNegationTo(::std::ostream* os) const {
5758 DescribeToHelper(!expect_eq_, os);
5759 }
5760
5761 private:
5762 void DescribeToHelper(bool expect_eq, ::std::ostream* os) const {
5763 *os << (expect_eq ? "is " : "isn't ");
5764 *os << "equal to ";
5765 if (!case_sensitive_) {
5766 *os << "(ignoring case) ";
5767 }
5768 UniversalPrint(string_, os);
5769 }
5770
5771 const StringType string_;
5772 const bool expect_eq_;
5773 const bool case_sensitive_;
5774
5775 GTEST_DISALLOW_ASSIGN_(StrEqualityMatcher);
5776};
5777
5778// Implements the polymorphic HasSubstr(substring) matcher, which
5779// can be used as a Matcher<T> as long as T can be converted to a
5780// string.
5781template <typename StringType>
5782class HasSubstrMatcher {
5783 public:
5784 explicit HasSubstrMatcher(const StringType& substring)
5785 : substring_(substring) {}
5786
5787 // Accepts pointer types, particularly:
5788 // const char*
5789 // char*
5790 // const wchar_t*
5791 // wchar_t*
5792 template <typename CharType>
5793 bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
5794 return s != NULL && MatchAndExplain(StringType(s), listener);
5795 }
5796
5797 // Matches anything that can convert to StringType.
5798 //
5799 // This is a template, not just a plain function with const StringType&,
5800 // because StringPiece has some interfering non-explicit constructors.
5801 template <typename MatcheeStringType>
5802 bool MatchAndExplain(const MatcheeStringType& s,
5803 MatchResultListener* /* listener */) const {
5804 const StringType& s2(s);
5805 return s2.find(substring_) != StringType::npos;
5806 }
5807
5808 // Describes what this matcher matches.
5809 void DescribeTo(::std::ostream* os) const {
5810 *os << "has substring ";
5811 UniversalPrint(substring_, os);
5812 }
5813
5814 void DescribeNegationTo(::std::ostream* os) const {
5815 *os << "has no substring ";
5816 UniversalPrint(substring_, os);
5817 }
5818
5819 private:
5820 const StringType substring_;
5821
5822 GTEST_DISALLOW_ASSIGN_(HasSubstrMatcher);
5823};
5824
5825// Implements the polymorphic StartsWith(substring) matcher, which
5826// can be used as a Matcher<T> as long as T can be converted to a
5827// string.
5828template <typename StringType>
5829class StartsWithMatcher {
5830 public:
5831 explicit StartsWithMatcher(const StringType& prefix) : prefix_(prefix) {
5832 }
5833
5834 // Accepts pointer types, particularly:
5835 // const char*
5836 // char*
5837 // const wchar_t*
5838 // wchar_t*
5839 template <typename CharType>
5840 bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
5841 return s != NULL && MatchAndExplain(StringType(s), listener);
5842 }
5843
5844 // Matches anything that can convert to StringType.
5845 //
5846 // This is a template, not just a plain function with const StringType&,
5847 // because StringPiece has some interfering non-explicit constructors.
5848 template <typename MatcheeStringType>
5849 bool MatchAndExplain(const MatcheeStringType& s,
5850 MatchResultListener* /* listener */) const {
5851 const StringType& s2(s);
5852 return s2.length() >= prefix_.length() &&
5853 s2.substr(0, prefix_.length()) == prefix_;
5854 }
5855
5856 void DescribeTo(::std::ostream* os) const {
5857 *os << "starts with ";
5858 UniversalPrint(prefix_, os);
5859 }
5860
5861 void DescribeNegationTo(::std::ostream* os) const {
5862 *os << "doesn't start with ";
5863 UniversalPrint(prefix_, os);
5864 }
5865
5866 private:
5867 const StringType prefix_;
5868
5869 GTEST_DISALLOW_ASSIGN_(StartsWithMatcher);
5870};
5871
5872// Implements the polymorphic EndsWith(substring) matcher, which
5873// can be used as a Matcher<T> as long as T can be converted to a
5874// string.
5875template <typename StringType>
5876class EndsWithMatcher {
5877 public:
5878 explicit EndsWithMatcher(const StringType& suffix) : suffix_(suffix) {}
5879
5880 // Accepts pointer types, particularly:
5881 // const char*
5882 // char*
5883 // const wchar_t*
5884 // wchar_t*
5885 template <typename CharType>
5886 bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
5887 return s != NULL && MatchAndExplain(StringType(s), listener);
5888 }
5889
5890 // Matches anything that can convert to StringType.
5891 //
5892 // This is a template, not just a plain function with const StringType&,
5893 // because StringPiece has some interfering non-explicit constructors.
5894 template <typename MatcheeStringType>
5895 bool MatchAndExplain(const MatcheeStringType& s,
5896 MatchResultListener* /* listener */) const {
5897 const StringType& s2(s);
5898 return s2.length() >= suffix_.length() &&
5899 s2.substr(s2.length() - suffix_.length()) == suffix_;
5900 }
5901
5902 void DescribeTo(::std::ostream* os) const {
5903 *os << "ends with ";
5904 UniversalPrint(suffix_, os);
5905 }
5906
5907 void DescribeNegationTo(::std::ostream* os) const {
5908 *os << "doesn't end with ";
5909 UniversalPrint(suffix_, os);
5910 }
5911
5912 private:
5913 const StringType suffix_;
5914
5915 GTEST_DISALLOW_ASSIGN_(EndsWithMatcher);
5916};
5917
5918// Implements polymorphic matchers MatchesRegex(regex) and
5919// ContainsRegex(regex), which can be used as a Matcher<T> as long as
5920// T can be converted to a string.
5921class MatchesRegexMatcher {
5922 public:
5923 MatchesRegexMatcher(const RE* regex, bool full_match)
5924 : regex_(regex), full_match_(full_match) {}
5925
5926 // Accepts pointer types, particularly:
5927 // const char*
5928 // char*
5929 // const wchar_t*
5930 // wchar_t*
5931 template <typename CharType>
5932 bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
5933 return s != NULL && MatchAndExplain(internal::string(s), listener);
5934 }
5935
5936 // Matches anything that can convert to internal::string.
5937 //
5938 // This is a template, not just a plain function with const internal::string&,
5939 // because StringPiece has some interfering non-explicit constructors.
5940 template <class MatcheeStringType>
5941 bool MatchAndExplain(const MatcheeStringType& s,
5942 MatchResultListener* /* listener */) const {
5943 const internal::string& s2(s);
5944 return full_match_ ? RE::FullMatch(s2, *regex_) :
5945 RE::PartialMatch(s2, *regex_);
5946 }
5947
5948 void DescribeTo(::std::ostream* os) const {
5949 *os << (full_match_ ? "matches" : "contains")
5950 << " regular expression ";
5951 UniversalPrinter<internal::string>::Print(regex_->pattern(), os);
5952 }
5953
5954 void DescribeNegationTo(::std::ostream* os) const {
5955 *os << "doesn't " << (full_match_ ? "match" : "contain")
5956 << " regular expression ";
5957 UniversalPrinter<internal::string>::Print(regex_->pattern(), os);
5958 }
5959
5960 private:
5961 const internal::linked_ptr<const RE> regex_;
5962 const bool full_match_;
5963
5964 GTEST_DISALLOW_ASSIGN_(MatchesRegexMatcher);
5965};
5966
5967// Implements a matcher that compares the two fields of a 2-tuple
5968// using one of the ==, <=, <, etc, operators. The two fields being
5969// compared don't have to have the same type.
5970//
5971// The matcher defined here is polymorphic (for example, Eq() can be
5972// used to match a tuple<int, short>, a tuple<const long&, double>,
5973// etc). Therefore we use a template type conversion operator in the
5974// implementation.
5975//
5976// We define this as a macro in order to eliminate duplicated source
5977// code.
5978#define GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(name, op, relation) \
5979 class name##2Matcher { \
5980 public: \
5981 template <typename T1, typename T2> \
5982 operator Matcher< ::std::tr1::tuple<T1, T2> >() const { \
5983 return MakeMatcher(new Impl< ::std::tr1::tuple<T1, T2> >); \
5984 } \
5985 template <typename T1, typename T2> \
5986 operator Matcher<const ::std::tr1::tuple<T1, T2>&>() const { \
5987 return MakeMatcher(new Impl<const ::std::tr1::tuple<T1, T2>&>); \
5988 } \
5989 private: \
5990 template <typename Tuple> \
5991 class Impl : public MatcherInterface<Tuple> { \
5992 public: \
5993 virtual bool MatchAndExplain( \
5994 Tuple args, \
5995 MatchResultListener* /* listener */) const { \
5996 return ::std::tr1::get<0>(args) op ::std::tr1::get<1>(args); \
5997 } \
5998 virtual void DescribeTo(::std::ostream* os) const { \
5999 *os << "are " relation; \
6000 } \
6001 virtual void DescribeNegationTo(::std::ostream* os) const { \
6002 *os << "aren't " relation; \
6003 } \
6004 }; \
6005 }
6006
6007// Implements Eq(), Ge(), Gt(), Le(), Lt(), and Ne() respectively.
6008GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(Eq, ==, "an equal pair");
6009GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(
6010 Ge, >=, "a pair where the first >= the second");
6011GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(
6012 Gt, >, "a pair where the first > the second");
6013GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(
6014 Le, <=, "a pair where the first <= the second");
6015GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(
6016 Lt, <, "a pair where the first < the second");
6017GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(Ne, !=, "an unequal pair");
6018
6019#undef GMOCK_IMPLEMENT_COMPARISON2_MATCHER_
6020
6021// Implements the Not(...) matcher for a particular argument type T.
6022// We do not nest it inside the NotMatcher class template, as that
6023// will prevent different instantiations of NotMatcher from sharing
6024// the same NotMatcherImpl<T> class.
6025template <typename T>
6026class NotMatcherImpl : public MatcherInterface<T> {
6027 public:
6028 explicit NotMatcherImpl(const Matcher<T>& matcher)
6029 : matcher_(matcher) {}
6030
6031 virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
6032 return !matcher_.MatchAndExplain(x, listener);
6033 }
6034
6035 virtual void DescribeTo(::std::ostream* os) const {
6036 matcher_.DescribeNegationTo(os);
6037 }
6038
6039 virtual void DescribeNegationTo(::std::ostream* os) const {
6040 matcher_.DescribeTo(os);
6041 }
6042
6043 private:
6044 const Matcher<T> matcher_;
6045
6046 GTEST_DISALLOW_ASSIGN_(NotMatcherImpl);
6047};
6048
6049// Implements the Not(m) matcher, which matches a value that doesn't
6050// match matcher m.
6051template <typename InnerMatcher>
6052class NotMatcher {
6053 public:
6054 explicit NotMatcher(InnerMatcher matcher) : matcher_(matcher) {}
6055
6056 // This template type conversion operator allows Not(m) to be used
6057 // to match any type m can match.
6058 template <typename T>
6059 operator Matcher<T>() const {
6060 return Matcher<T>(new NotMatcherImpl<T>(SafeMatcherCast<T>(matcher_)));
6061 }
6062
6063 private:
6064 InnerMatcher matcher_;
6065
6066 GTEST_DISALLOW_ASSIGN_(NotMatcher);
6067};
6068
6069// Implements the AllOf(m1, m2) matcher for a particular argument type
6070// T. We do not nest it inside the BothOfMatcher class template, as
6071// that will prevent different instantiations of BothOfMatcher from
6072// sharing the same BothOfMatcherImpl<T> class.
6073template <typename T>
6074class BothOfMatcherImpl : public MatcherInterface<T> {
6075 public:
6076 BothOfMatcherImpl(const Matcher<T>& matcher1, const Matcher<T>& matcher2)
6077 : matcher1_(matcher1), matcher2_(matcher2) {}
6078
6079 virtual void DescribeTo(::std::ostream* os) const {
6080 *os << "(";
6081 matcher1_.DescribeTo(os);
6082 *os << ") and (";
6083 matcher2_.DescribeTo(os);
6084 *os << ")";
6085 }
6086
6087 virtual void DescribeNegationTo(::std::ostream* os) const {
6088 *os << "(";
6089 matcher1_.DescribeNegationTo(os);
6090 *os << ") or (";
6091 matcher2_.DescribeNegationTo(os);
6092 *os << ")";
6093 }
6094
6095 virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
6096 // If either matcher1_ or matcher2_ doesn't match x, we only need
6097 // to explain why one of them fails.
6098 StringMatchResultListener listener1;
6099 if (!matcher1_.MatchAndExplain(x, &listener1)) {
6100 *listener << listener1.str();
6101 return false;
6102 }
6103
6104 StringMatchResultListener listener2;
6105 if (!matcher2_.MatchAndExplain(x, &listener2)) {
6106 *listener << listener2.str();
6107 return false;
6108 }
6109
6110 // Otherwise we need to explain why *both* of them match.
6111 const internal::string s1 = listener1.str();
6112 const internal::string s2 = listener2.str();
6113
6114 if (s1 == "") {
6115 *listener << s2;
6116 } else {
6117 *listener << s1;
6118 if (s2 != "") {
6119 *listener << ", and " << s2;
6120 }
6121 }
6122 return true;
6123 }
6124
6125 private:
6126 const Matcher<T> matcher1_;
6127 const Matcher<T> matcher2_;
6128
6129 GTEST_DISALLOW_ASSIGN_(BothOfMatcherImpl);
6130};
6131
6132#if GTEST_LANG_CXX11
6133// MatcherList provides mechanisms for storing a variable number of matchers in
6134// a list structure (ListType) and creating a combining matcher from such a
6135// list.
6136// The template is defined recursively using the following template paramters:
6137// * kSize is the length of the MatcherList.
6138// * Head is the type of the first matcher of the list.
6139// * Tail denotes the types of the remaining matchers of the list.
6140template <int kSize, typename Head, typename... Tail>
6141struct MatcherList {
6142 typedef MatcherList<kSize - 1, Tail...> MatcherListTail;
6143 typedef ::std::pair<Head, typename MatcherListTail::ListType> ListType;
6144
6145 // BuildList stores variadic type values in a nested pair structure.
6146 // Example:
6147 // MatcherList<3, int, string, float>::BuildList(5, "foo", 2.0) will return
6148 // the corresponding result of type pair<int, pair<string, float>>.
6149 static ListType BuildList(const Head& matcher, const Tail&... tail) {
6150 return ListType(matcher, MatcherListTail::BuildList(tail...));
6151 }
6152
6153 // CreateMatcher<T> creates a Matcher<T> from a given list of matchers (built
6154 // by BuildList()). CombiningMatcher<T> is used to combine the matchers of the
6155 // list. CombiningMatcher<T> must implement MatcherInterface<T> and have a
6156 // constructor taking two Matcher<T>s as input.
6157 template <typename T, template <typename /* T */> class CombiningMatcher>
6158 static Matcher<T> CreateMatcher(const ListType& matchers) {
6159 return Matcher<T>(new CombiningMatcher<T>(
6160 SafeMatcherCast<T>(matchers.first),
6161 MatcherListTail::template CreateMatcher<T, CombiningMatcher>(
6162 matchers.second)));
6163 }
6164};
6165
6166// The following defines the base case for the recursive definition of
6167// MatcherList.
6168template <typename Matcher1, typename Matcher2>
6169struct MatcherList<2, Matcher1, Matcher2> {
6170 typedef ::std::pair<Matcher1, Matcher2> ListType;
6171
6172 static ListType BuildList(const Matcher1& matcher1,
6173 const Matcher2& matcher2) {
6174 return ::std::pair<Matcher1, Matcher2>(matcher1, matcher2);
6175 }
6176
6177 template <typename T, template <typename /* T */> class CombiningMatcher>
6178 static Matcher<T> CreateMatcher(const ListType& matchers) {
6179 return Matcher<T>(new CombiningMatcher<T>(
6180 SafeMatcherCast<T>(matchers.first),
6181 SafeMatcherCast<T>(matchers.second)));
6182 }
6183};
6184
6185// VariadicMatcher is used for the variadic implementation of
6186// AllOf(m_1, m_2, ...) and AnyOf(m_1, m_2, ...).
6187// CombiningMatcher<T> is used to recursively combine the provided matchers
6188// (of type Args...).
6189template <template <typename T> class CombiningMatcher, typename... Args>
6190class VariadicMatcher {
6191 public:
6192 VariadicMatcher(const Args&... matchers) // NOLINT
6193 : matchers_(MatcherListType::BuildList(matchers...)) {}
6194
6195 // This template type conversion operator allows an
6196 // VariadicMatcher<Matcher1, Matcher2...> object to match any type that
6197 // all of the provided matchers (Matcher1, Matcher2, ...) can match.
6198 template <typename T>
6199 operator Matcher<T>() const {
6200 return MatcherListType::template CreateMatcher<T, CombiningMatcher>(
6201 matchers_);
6202 }
6203
6204 private:
6205 typedef MatcherList<sizeof...(Args), Args...> MatcherListType;
6206
6207 const typename MatcherListType::ListType matchers_;
6208
6209 GTEST_DISALLOW_ASSIGN_(VariadicMatcher);
6210};
6211
6212template <typename... Args>
6213using AllOfMatcher = VariadicMatcher<BothOfMatcherImpl, Args...>;
6214
6215#endif // GTEST_LANG_CXX11
6216
6217// Used for implementing the AllOf(m_1, ..., m_n) matcher, which
6218// matches a value that matches all of the matchers m_1, ..., and m_n.
6219template <typename Matcher1, typename Matcher2>
6220class BothOfMatcher {
6221 public:
6222 BothOfMatcher(Matcher1 matcher1, Matcher2 matcher2)
6223 : matcher1_(matcher1), matcher2_(matcher2) {}
6224
6225 // This template type conversion operator allows a
6226 // BothOfMatcher<Matcher1, Matcher2> object to match any type that
6227 // both Matcher1 and Matcher2 can match.
6228 template <typename T>
6229 operator Matcher<T>() const {
6230 return Matcher<T>(new BothOfMatcherImpl<T>(SafeMatcherCast<T>(matcher1_),
6231 SafeMatcherCast<T>(matcher2_)));
6232 }
6233
6234 private:
6235 Matcher1 matcher1_;
6236 Matcher2 matcher2_;
6237
6238 GTEST_DISALLOW_ASSIGN_(BothOfMatcher);
6239};
6240
6241// Implements the AnyOf(m1, m2) matcher for a particular argument type
6242// T. We do not nest it inside the AnyOfMatcher class template, as
6243// that will prevent different instantiations of AnyOfMatcher from
6244// sharing the same EitherOfMatcherImpl<T> class.
6245template <typename T>
6246class EitherOfMatcherImpl : public MatcherInterface<T> {
6247 public:
6248 EitherOfMatcherImpl(const Matcher<T>& matcher1, const Matcher<T>& matcher2)
6249 : matcher1_(matcher1), matcher2_(matcher2) {}
6250
6251 virtual void DescribeTo(::std::ostream* os) const {
6252 *os << "(";
6253 matcher1_.DescribeTo(os);
6254 *os << ") or (";
6255 matcher2_.DescribeTo(os);
6256 *os << ")";
6257 }
6258
6259 virtual void DescribeNegationTo(::std::ostream* os) const {
6260 *os << "(";
6261 matcher1_.DescribeNegationTo(os);
6262 *os << ") and (";
6263 matcher2_.DescribeNegationTo(os);
6264 *os << ")";
6265 }
6266
6267 virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
6268 // If either matcher1_ or matcher2_ matches x, we just need to
6269 // explain why *one* of them matches.
6270 StringMatchResultListener listener1;
6271 if (matcher1_.MatchAndExplain(x, &listener1)) {
6272 *listener << listener1.str();
6273 return true;
6274 }
6275
6276 StringMatchResultListener listener2;
6277 if (matcher2_.MatchAndExplain(x, &listener2)) {
6278 *listener << listener2.str();
6279 return true;
6280 }
6281
6282 // Otherwise we need to explain why *both* of them fail.
6283 const internal::string s1 = listener1.str();
6284 const internal::string s2 = listener2.str();
6285
6286 if (s1 == "") {
6287 *listener << s2;
6288 } else {
6289 *listener << s1;
6290 if (s2 != "") {
6291 *listener << ", and " << s2;
6292 }
6293 }
6294 return false;
6295 }
6296
6297 private:
6298 const Matcher<T> matcher1_;
6299 const Matcher<T> matcher2_;
6300
6301 GTEST_DISALLOW_ASSIGN_(EitherOfMatcherImpl);
6302};
6303
6304#if GTEST_LANG_CXX11
6305// AnyOfMatcher is used for the variadic implementation of AnyOf(m_1, m_2, ...).
6306template <typename... Args>
6307using AnyOfMatcher = VariadicMatcher<EitherOfMatcherImpl, Args...>;
6308
6309#endif // GTEST_LANG_CXX11
6310
6311// Used for implementing the AnyOf(m_1, ..., m_n) matcher, which
6312// matches a value that matches at least one of the matchers m_1, ...,
6313// and m_n.
6314template <typename Matcher1, typename Matcher2>
6315class EitherOfMatcher {
6316 public:
6317 EitherOfMatcher(Matcher1 matcher1, Matcher2 matcher2)
6318 : matcher1_(matcher1), matcher2_(matcher2) {}
6319
6320 // This template type conversion operator allows a
6321 // EitherOfMatcher<Matcher1, Matcher2> object to match any type that
6322 // both Matcher1 and Matcher2 can match.
6323 template <typename T>
6324 operator Matcher<T>() const {
6325 return Matcher<T>(new EitherOfMatcherImpl<T>(
6326 SafeMatcherCast<T>(matcher1_), SafeMatcherCast<T>(matcher2_)));
6327 }
6328
6329 private:
6330 Matcher1 matcher1_;
6331 Matcher2 matcher2_;
6332
6333 GTEST_DISALLOW_ASSIGN_(EitherOfMatcher);
6334};
6335
6336// Used for implementing Truly(pred), which turns a predicate into a
6337// matcher.
6338template <typename Predicate>
6339class TrulyMatcher {
6340 public:
6341 explicit TrulyMatcher(Predicate pred) : predicate_(pred) {}
6342
6343 // This method template allows Truly(pred) to be used as a matcher
6344 // for type T where T is the argument type of predicate 'pred'. The
6345 // argument is passed by reference as the predicate may be
6346 // interested in the address of the argument.
6347 template <typename T>
6348 bool MatchAndExplain(T& x, // NOLINT
6349 MatchResultListener* /* listener */) const {
6350 // Without the if-statement, MSVC sometimes warns about converting
6351 // a value to bool (warning 4800).
6352 //
6353 // We cannot write 'return !!predicate_(x);' as that doesn't work
6354 // when predicate_(x) returns a class convertible to bool but
6355 // having no operator!().
6356 if (predicate_(x))
6357 return true;
6358 return false;
6359 }
6360
6361 void DescribeTo(::std::ostream* os) const {
6362 *os << "satisfies the given predicate";
6363 }
6364
6365 void DescribeNegationTo(::std::ostream* os) const {
6366 *os << "doesn't satisfy the given predicate";
6367 }
6368
6369 private:
6370 Predicate predicate_;
6371
6372 GTEST_DISALLOW_ASSIGN_(TrulyMatcher);
6373};
6374
6375// Used for implementing Matches(matcher), which turns a matcher into
6376// a predicate.
6377template <typename M>
6378class MatcherAsPredicate {
6379 public:
6380 explicit MatcherAsPredicate(M matcher) : matcher_(matcher) {}
6381
6382 // This template operator() allows Matches(m) to be used as a
6383 // predicate on type T where m is a matcher on type T.
6384 //
6385 // The argument x is passed by reference instead of by value, as
6386 // some matcher may be interested in its address (e.g. as in
6387 // Matches(Ref(n))(x)).
6388 template <typename T>
6389 bool operator()(const T& x) const {
6390 // We let matcher_ commit to a particular type here instead of
6391 // when the MatcherAsPredicate object was constructed. This
6392 // allows us to write Matches(m) where m is a polymorphic matcher
6393 // (e.g. Eq(5)).
6394 //
6395 // If we write Matcher<T>(matcher_).Matches(x) here, it won't
6396 // compile when matcher_ has type Matcher<const T&>; if we write
6397 // Matcher<const T&>(matcher_).Matches(x) here, it won't compile
6398 // when matcher_ has type Matcher<T>; if we just write
6399 // matcher_.Matches(x), it won't compile when matcher_ is
6400 // polymorphic, e.g. Eq(5).
6401 //
6402 // MatcherCast<const T&>() is necessary for making the code work
6403 // in all of the above situations.
6404 return MatcherCast<const T&>(matcher_).Matches(x);
6405 }
6406
6407 private:
6408 M matcher_;
6409
6410 GTEST_DISALLOW_ASSIGN_(MatcherAsPredicate);
6411};
6412
6413// For implementing ASSERT_THAT() and EXPECT_THAT(). The template
6414// argument M must be a type that can be converted to a matcher.
6415template <typename M>
6416class PredicateFormatterFromMatcher {
6417 public:
6418 explicit PredicateFormatterFromMatcher(const M& m) : matcher_(m) {}
6419
6420 // This template () operator allows a PredicateFormatterFromMatcher
6421 // object to act as a predicate-formatter suitable for using with
6422 // Google Test's EXPECT_PRED_FORMAT1() macro.
6423 template <typename T>
6424 AssertionResult operator()(const char* value_text, const T& x) const {
6425 // We convert matcher_ to a Matcher<const T&> *now* instead of
6426 // when the PredicateFormatterFromMatcher object was constructed,
6427 // as matcher_ may be polymorphic (e.g. NotNull()) and we won't
6428 // know which type to instantiate it to until we actually see the
6429 // type of x here.
6430 //
6431 // We write SafeMatcherCast<const T&>(matcher_) instead of
6432 // Matcher<const T&>(matcher_), as the latter won't compile when
6433 // matcher_ has type Matcher<T> (e.g. An<int>()).
6434 // We don't write MatcherCast<const T&> either, as that allows
6435 // potentially unsafe downcasting of the matcher argument.
6436 const Matcher<const T&> matcher = SafeMatcherCast<const T&>(matcher_);
6437 StringMatchResultListener listener;
6438 if (MatchPrintAndExplain(x, matcher, &listener))
6439 return AssertionSuccess();
6440
6441 ::std::stringstream ss;
6442 ss << "Value of: " << value_text << "\n"
6443 << "Expected: ";
6444 matcher.DescribeTo(&ss);
6445 ss << "\n Actual: " << listener.str();
6446 return AssertionFailure() << ss.str();
6447 }
6448
6449 private:
6450 const M matcher_;
6451
6452 GTEST_DISALLOW_ASSIGN_(PredicateFormatterFromMatcher);
6453};
6454
6455// A helper function for converting a matcher to a predicate-formatter
6456// without the user needing to explicitly write the type. This is
6457// used for implementing ASSERT_THAT() and EXPECT_THAT().
6458template <typename M>
6459inline PredicateFormatterFromMatcher<M>
6460MakePredicateFormatterFromMatcher(const M& matcher) {
6461 return PredicateFormatterFromMatcher<M>(matcher);
6462}
6463
6464// Implements the polymorphic floating point equality matcher, which matches
6465// two float values using ULP-based approximation or, optionally, a
6466// user-specified epsilon. The template is meant to be instantiated with
6467// FloatType being either float or double.
6468template <typename FloatType>
6469class FloatingEqMatcher {
6470 public:
6471 // Constructor for FloatingEqMatcher.
6472 // The matcher's input will be compared with rhs. The matcher treats two
6473 // NANs as equal if nan_eq_nan is true. Otherwise, under IEEE standards,
6474 // equality comparisons between NANs will always return false. We specify a
6475 // negative max_abs_error_ term to indicate that ULP-based approximation will
6476 // be used for comparison.
6477 FloatingEqMatcher(FloatType rhs, bool nan_eq_nan) :
6478 rhs_(rhs), nan_eq_nan_(nan_eq_nan), max_abs_error_(-1) {
6479 }
6480
6481 // Constructor that supports a user-specified max_abs_error that will be used
6482 // for comparison instead of ULP-based approximation. The max absolute
6483 // should be non-negative.
6484 FloatingEqMatcher(FloatType rhs, bool nan_eq_nan, FloatType max_abs_error) :
6485 rhs_(rhs), nan_eq_nan_(nan_eq_nan), max_abs_error_(max_abs_error) {
6486 GTEST_CHECK_(max_abs_error >= 0)
6487 << ", where max_abs_error is" << max_abs_error;
6488 }
6489
6490 // Implements floating point equality matcher as a Matcher<T>.
6491 template <typename T>
6492 class Impl : public MatcherInterface<T> {
6493 public:
6494 Impl(FloatType rhs, bool nan_eq_nan, FloatType max_abs_error) :
6495 rhs_(rhs), nan_eq_nan_(nan_eq_nan), max_abs_error_(max_abs_error) {}
6496
6497 virtual bool MatchAndExplain(T value,
6498 MatchResultListener* /* listener */) const {
6499 const FloatingPoint<FloatType> lhs(value), rhs(rhs_);
6500
6501 // Compares NaNs first, if nan_eq_nan_ is true.
6502 if (lhs.is_nan() || rhs.is_nan()) {
6503 if (lhs.is_nan() && rhs.is_nan()) {
6504 return nan_eq_nan_;
6505 }
6506 // One is nan; the other is not nan.
6507 return false;
6508 }
6509 if (HasMaxAbsError()) {
6510 // We perform an equality check so that inf will match inf, regardless
6511 // of error bounds. If the result of value - rhs_ would result in
6512 // overflow or if either value is inf, the default result is infinity,
6513 // which should only match if max_abs_error_ is also infinity.
6514 return value == rhs_ || fabs(value - rhs_) <= max_abs_error_;
6515 } else {
6516 return lhs.AlmostEquals(rhs);
6517 }
6518 }
6519
6520 virtual void DescribeTo(::std::ostream* os) const {
6521 // os->precision() returns the previously set precision, which we
6522 // store to restore the ostream to its original configuration
6523 // after outputting.
6524 const ::std::streamsize old_precision = os->precision(
6525 ::std::numeric_limits<FloatType>::digits10 + 2);
6526 if (FloatingPoint<FloatType>(rhs_).is_nan()) {
6527 if (nan_eq_nan_) {
6528 *os << "is NaN";
6529 } else {
6530 *os << "never matches";
6531 }
6532 } else {
6533 *os << "is approximately " << rhs_;
6534 if (HasMaxAbsError()) {
6535 *os << " (absolute error <= " << max_abs_error_ << ")";
6536 }
6537 }
6538 os->precision(old_precision);
6539 }
6540
6541 virtual void DescribeNegationTo(::std::ostream* os) const {
6542 // As before, get original precision.
6543 const ::std::streamsize old_precision = os->precision(
6544 ::std::numeric_limits<FloatType>::digits10 + 2);
6545 if (FloatingPoint<FloatType>(rhs_).is_nan()) {
6546 if (nan_eq_nan_) {
6547 *os << "isn't NaN";
6548 } else {
6549 *os << "is anything";
6550 }
6551 } else {
6552 *os << "isn't approximately " << rhs_;
6553 if (HasMaxAbsError()) {
6554 *os << " (absolute error > " << max_abs_error_ << ")";
6555 }
6556 }
6557 // Restore original precision.
6558 os->precision(old_precision);
6559 }
6560
6561 private:
6562 bool HasMaxAbsError() const {
6563 return max_abs_error_ >= 0;
6564 }
6565
6566 const FloatType rhs_;
6567 const bool nan_eq_nan_;
6568 // max_abs_error will be used for value comparison when >= 0.
6569 const FloatType max_abs_error_;
6570
6571 GTEST_DISALLOW_ASSIGN_(Impl);
6572 };
6573
6574 // The following 3 type conversion operators allow FloatEq(rhs) and
6575 // NanSensitiveFloatEq(rhs) to be used as a Matcher<float>, a
6576 // Matcher<const float&>, or a Matcher<float&>, but nothing else.
6577 // (While Google's C++ coding style doesn't allow arguments passed
6578 // by non-const reference, we may see them in code not conforming to
6579 // the style. Therefore Google Mock needs to support them.)
6580 operator Matcher<FloatType>() const {
6581 return MakeMatcher(new Impl<FloatType>(rhs_, nan_eq_nan_, max_abs_error_));
6582 }
6583
6584 operator Matcher<const FloatType&>() const {
6585 return MakeMatcher(
6586 new Impl<const FloatType&>(rhs_, nan_eq_nan_, max_abs_error_));
6587 }
6588
6589 operator Matcher<FloatType&>() const {
6590 return MakeMatcher(new Impl<FloatType&>(rhs_, nan_eq_nan_, max_abs_error_));
6591 }
6592
6593 private:
6594 const FloatType rhs_;
6595 const bool nan_eq_nan_;
6596 // max_abs_error will be used for value comparison when >= 0.
6597 const FloatType max_abs_error_;
6598
6599 GTEST_DISALLOW_ASSIGN_(FloatingEqMatcher);
6600};
6601
6602// Implements the Pointee(m) matcher for matching a pointer whose
6603// pointee matches matcher m. The pointer can be either raw or smart.
6604template <typename InnerMatcher>
6605class PointeeMatcher {
6606 public:
6607 explicit PointeeMatcher(const InnerMatcher& matcher) : matcher_(matcher) {}
6608
6609 // This type conversion operator template allows Pointee(m) to be
6610 // used as a matcher for any pointer type whose pointee type is
6611 // compatible with the inner matcher, where type Pointer can be
6612 // either a raw pointer or a smart pointer.
6613 //
6614 // The reason we do this instead of relying on
6615 // MakePolymorphicMatcher() is that the latter is not flexible
6616 // enough for implementing the DescribeTo() method of Pointee().
6617 template <typename Pointer>
6618 operator Matcher<Pointer>() const {
6619 return MakeMatcher(new Impl<Pointer>(matcher_));
6620 }
6621
6622 private:
6623 // The monomorphic implementation that works for a particular pointer type.
6624 template <typename Pointer>
6625 class Impl : public MatcherInterface<Pointer> {
6626 public:
6627 typedef typename PointeeOf<GTEST_REMOVE_CONST_( // NOLINT
6628 GTEST_REMOVE_REFERENCE_(Pointer))>::type Pointee;
6629
6630 explicit Impl(const InnerMatcher& matcher)
6631 : matcher_(MatcherCast<const Pointee&>(matcher)) {}
6632
6633 virtual void DescribeTo(::std::ostream* os) const {
6634 *os << "points to a value that ";
6635 matcher_.DescribeTo(os);
6636 }
6637
6638 virtual void DescribeNegationTo(::std::ostream* os) const {
6639 *os << "does not point to a value that ";
6640 matcher_.DescribeTo(os);
6641 }
6642
6643 virtual bool MatchAndExplain(Pointer pointer,
6644 MatchResultListener* listener) const {
6645 if (GetRawPointer(pointer) == NULL)
6646 return false;
6647
6648 *listener << "which points to ";
6649 return MatchPrintAndExplain(*pointer, matcher_, listener);
6650 }
6651
6652 private:
6653 const Matcher<const Pointee&> matcher_;
6654
6655 GTEST_DISALLOW_ASSIGN_(Impl);
6656 };
6657
6658 const InnerMatcher matcher_;
6659
6660 GTEST_DISALLOW_ASSIGN_(PointeeMatcher);
6661};
6662
6663// Implements the Field() matcher for matching a field (i.e. member
6664// variable) of an object.
6665template <typename Class, typename FieldType>
6666class FieldMatcher {
6667 public:
6668 FieldMatcher(FieldType Class::*field,
6669 const Matcher<const FieldType&>& matcher)
6670 : field_(field), matcher_(matcher) {}
6671
6672 void DescribeTo(::std::ostream* os) const {
6673 *os << "is an object whose given field ";
6674 matcher_.DescribeTo(os);
6675 }
6676
6677 void DescribeNegationTo(::std::ostream* os) const {
6678 *os << "is an object whose given field ";
6679 matcher_.DescribeNegationTo(os);
6680 }
6681
6682 template <typename T>
6683 bool MatchAndExplain(const T& value, MatchResultListener* listener) const {
6684 return MatchAndExplainImpl(
6685 typename ::testing::internal::
6686 is_pointer<GTEST_REMOVE_CONST_(T)>::type(),
6687 value, listener);
6688 }
6689
6690 private:
6691 // The first argument of MatchAndExplainImpl() is needed to help
6692 // Symbian's C++ compiler choose which overload to use. Its type is
6693 // true_type iff the Field() matcher is used to match a pointer.
6694 bool MatchAndExplainImpl(false_type /* is_not_pointer */, const Class& obj,
6695 MatchResultListener* listener) const {
6696 *listener << "whose given field is ";
6697 return MatchPrintAndExplain(obj.*field_, matcher_, listener);
6698 }
6699
6700 bool MatchAndExplainImpl(true_type /* is_pointer */, const Class* p,
6701 MatchResultListener* listener) const {
6702 if (p == NULL)
6703 return false;
6704
6705 *listener << "which points to an object ";
6706 // Since *p has a field, it must be a class/struct/union type and
6707 // thus cannot be a pointer. Therefore we pass false_type() as
6708 // the first argument.
6709 return MatchAndExplainImpl(false_type(), *p, listener);
6710 }
6711
6712 const FieldType Class::*field_;
6713 const Matcher<const FieldType&> matcher_;
6714
6715 GTEST_DISALLOW_ASSIGN_(FieldMatcher);
6716};
6717
6718// Implements the Property() matcher for matching a property
6719// (i.e. return value of a getter method) of an object.
6720template <typename Class, typename PropertyType>
6721class PropertyMatcher {
6722 public:
6723 // The property may have a reference type, so 'const PropertyType&'
6724 // may cause double references and fail to compile. That's why we
6725 // need GTEST_REFERENCE_TO_CONST, which works regardless of
6726 // PropertyType being a reference or not.
6727 typedef GTEST_REFERENCE_TO_CONST_(PropertyType) RefToConstProperty;
6728
6729 PropertyMatcher(PropertyType (Class::*property)() const,
6730 const Matcher<RefToConstProperty>& matcher)
6731 : property_(property), matcher_(matcher) {}
6732
6733 void DescribeTo(::std::ostream* os) const {
6734 *os << "is an object whose given property ";
6735 matcher_.DescribeTo(os);
6736 }
6737
6738 void DescribeNegationTo(::std::ostream* os) const {
6739 *os << "is an object whose given property ";
6740 matcher_.DescribeNegationTo(os);
6741 }
6742
6743 template <typename T>
6744 bool MatchAndExplain(const T&value, MatchResultListener* listener) const {
6745 return MatchAndExplainImpl(
6746 typename ::testing::internal::
6747 is_pointer<GTEST_REMOVE_CONST_(T)>::type(),
6748 value, listener);
6749 }
6750
6751 private:
6752 // The first argument of MatchAndExplainImpl() is needed to help
6753 // Symbian's C++ compiler choose which overload to use. Its type is
6754 // true_type iff the Property() matcher is used to match a pointer.
6755 bool MatchAndExplainImpl(false_type /* is_not_pointer */, const Class& obj,
6756 MatchResultListener* listener) const {
6757 *listener << "whose given property is ";
6758 // Cannot pass the return value (for example, int) to MatchPrintAndExplain,
6759 // which takes a non-const reference as argument.
6760 RefToConstProperty result = (obj.*property_)();
6761 return MatchPrintAndExplain(result, matcher_, listener);
6762 }
6763
6764 bool MatchAndExplainImpl(true_type /* is_pointer */, const Class* p,
6765 MatchResultListener* listener) const {
6766 if (p == NULL)
6767 return false;
6768
6769 *listener << "which points to an object ";
6770 // Since *p has a property method, it must be a class/struct/union
6771 // type and thus cannot be a pointer. Therefore we pass
6772 // false_type() as the first argument.
6773 return MatchAndExplainImpl(false_type(), *p, listener);
6774 }
6775
6776 PropertyType (Class::*property_)() const;
6777 const Matcher<RefToConstProperty> matcher_;
6778
6779 GTEST_DISALLOW_ASSIGN_(PropertyMatcher);
6780};
6781
6782// Type traits specifying various features of different functors for ResultOf.
6783// The default template specifies features for functor objects.
6784// Functor classes have to typedef argument_type and result_type
6785// to be compatible with ResultOf.
6786template <typename Functor>
6787struct CallableTraits {
6788 typedef typename Functor::result_type ResultType;
6789 typedef Functor StorageType;
6790
6791 static void CheckIsValid(Functor /* functor */) {}
6792 template <typename T>
6793 static ResultType Invoke(Functor f, T arg) { return f(arg); }
6794};
6795
6796// Specialization for function pointers.
6797template <typename ArgType, typename ResType>
6798struct CallableTraits<ResType(*)(ArgType)> {
6799 typedef ResType ResultType;
6800 typedef ResType(*StorageType)(ArgType);
6801
6802 static void CheckIsValid(ResType(*f)(ArgType)) {
6803 GTEST_CHECK_(f != NULL)
6804 << "NULL function pointer is passed into ResultOf().";
6805 }
6806 template <typename T>
6807 static ResType Invoke(ResType(*f)(ArgType), T arg) {
6808 return (*f)(arg);
6809 }
6810};
6811
6812// Implements the ResultOf() matcher for matching a return value of a
6813// unary function of an object.
6814template <typename Callable>
6815class ResultOfMatcher {
6816 public:
6817 typedef typename CallableTraits<Callable>::ResultType ResultType;
6818
6819 ResultOfMatcher(Callable callable, const Matcher<ResultType>& matcher)
6820 : callable_(callable), matcher_(matcher) {
6821 CallableTraits<Callable>::CheckIsValid(callable_);
6822 }
6823
6824 template <typename T>
6825 operator Matcher<T>() const {
6826 return Matcher<T>(new Impl<T>(callable_, matcher_));
6827 }
6828
6829 private:
6830 typedef typename CallableTraits<Callable>::StorageType CallableStorageType;
6831
6832 template <typename T>
6833 class Impl : public MatcherInterface<T> {
6834 public:
6835 Impl(CallableStorageType callable, const Matcher<ResultType>& matcher)
6836 : callable_(callable), matcher_(matcher) {}
6837
6838 virtual void DescribeTo(::std::ostream* os) const {
6839 *os << "is mapped by the given callable to a value that ";
6840 matcher_.DescribeTo(os);
6841 }
6842
6843 virtual void DescribeNegationTo(::std::ostream* os) const {
6844 *os << "is mapped by the given callable to a value that ";
6845 matcher_.DescribeNegationTo(os);
6846 }
6847
6848 virtual bool MatchAndExplain(T obj, MatchResultListener* listener) const {
6849 *listener << "which is mapped by the given callable to ";
6850 // Cannot pass the return value (for example, int) to
6851 // MatchPrintAndExplain, which takes a non-const reference as argument.
6852 ResultType result =
6853 CallableTraits<Callable>::template Invoke<T>(callable_, obj);
6854 return MatchPrintAndExplain(result, matcher_, listener);
6855 }
6856
6857 private:
6858 // Functors often define operator() as non-const method even though
6859 // they are actualy stateless. But we need to use them even when
6860 // 'this' is a const pointer. It's the user's responsibility not to
6861 // use stateful callables with ResultOf(), which does't guarantee
6862 // how many times the callable will be invoked.
6863 mutable CallableStorageType callable_;
6864 const Matcher<ResultType> matcher_;
6865
6866 GTEST_DISALLOW_ASSIGN_(Impl);
6867 }; // class Impl
6868
6869 const CallableStorageType callable_;
6870 const Matcher<ResultType> matcher_;
6871
6872 GTEST_DISALLOW_ASSIGN_(ResultOfMatcher);
6873};
6874
6875// Implements a matcher that checks the size of an STL-style container.
6876template <typename SizeMatcher>
6877class SizeIsMatcher {
6878 public:
6879 explicit SizeIsMatcher(const SizeMatcher& size_matcher)
6880 : size_matcher_(size_matcher) {
6881 }
6882
6883 template <typename Container>
6884 operator Matcher<Container>() const {
6885 return MakeMatcher(new Impl<Container>(size_matcher_));
6886 }
6887
6888 template <typename Container>
6889 class Impl : public MatcherInterface<Container> {
6890 public:
6891 typedef internal::StlContainerView<
6892 GTEST_REMOVE_REFERENCE_AND_CONST_(Container)> ContainerView;
6893 typedef typename ContainerView::type::size_type SizeType;
6894 explicit Impl(const SizeMatcher& size_matcher)
6895 : size_matcher_(MatcherCast<SizeType>(size_matcher)) {}
6896
6897 virtual void DescribeTo(::std::ostream* os) const {
6898 *os << "size ";
6899 size_matcher_.DescribeTo(os);
6900 }
6901 virtual void DescribeNegationTo(::std::ostream* os) const {
6902 *os << "size ";
6903 size_matcher_.DescribeNegationTo(os);
6904 }
6905
6906 virtual bool MatchAndExplain(Container container,
6907 MatchResultListener* listener) const {
6908 SizeType size = container.size();
6909 StringMatchResultListener size_listener;
6910 const bool result = size_matcher_.MatchAndExplain(size, &size_listener);
6911 *listener
6912 << "whose size " << size << (result ? " matches" : " doesn't match");
6913 PrintIfNotEmpty(size_listener.str(), listener->stream());
6914 return result;
6915 }
6916
6917 private:
6918 const Matcher<SizeType> size_matcher_;
6919 GTEST_DISALLOW_ASSIGN_(Impl);
6920 };
6921
6922 private:
6923 const SizeMatcher size_matcher_;
6924 GTEST_DISALLOW_ASSIGN_(SizeIsMatcher);
6925};
6926
6927// Implements an equality matcher for any STL-style container whose elements
6928// support ==. This matcher is like Eq(), but its failure explanations provide
6929// more detailed information that is useful when the container is used as a set.
6930// The failure message reports elements that are in one of the operands but not
6931// the other. The failure messages do not report duplicate or out-of-order
6932// elements in the containers (which don't properly matter to sets, but can
6933// occur if the containers are vectors or lists, for example).
6934//
6935// Uses the container's const_iterator, value_type, operator ==,
6936// begin(), and end().
6937template <typename Container>
6938class ContainerEqMatcher {
6939 public:
6940 typedef internal::StlContainerView<Container> View;
6941 typedef typename View::type StlContainer;
6942 typedef typename View::const_reference StlContainerReference;
6943
6944 // We make a copy of rhs in case the elements in it are modified
6945 // after this matcher is created.
6946 explicit ContainerEqMatcher(const Container& rhs) : rhs_(View::Copy(rhs)) {
6947 // Makes sure the user doesn't instantiate this class template
6948 // with a const or reference type.
6949 (void)testing::StaticAssertTypeEq<Container,
6950 GTEST_REMOVE_REFERENCE_AND_CONST_(Container)>();
6951 }
6952
6953 void DescribeTo(::std::ostream* os) const {
6954 *os << "equals ";
6955 UniversalPrint(rhs_, os);
6956 }
6957 void DescribeNegationTo(::std::ostream* os) const {
6958 *os << "does not equal ";
6959 UniversalPrint(rhs_, os);
6960 }
6961
6962 template <typename LhsContainer>
6963 bool MatchAndExplain(const LhsContainer& lhs,
6964 MatchResultListener* listener) const {
6965 // GTEST_REMOVE_CONST_() is needed to work around an MSVC 8.0 bug
6966 // that causes LhsContainer to be a const type sometimes.
6967 typedef internal::StlContainerView<GTEST_REMOVE_CONST_(LhsContainer)>
6968 LhsView;
6969 typedef typename LhsView::type LhsStlContainer;
6970 StlContainerReference lhs_stl_container = LhsView::ConstReference(lhs);
6971 if (lhs_stl_container == rhs_)
6972 return true;
6973
6974 ::std::ostream* const os = listener->stream();
6975 if (os != NULL) {
6976 // Something is different. Check for extra values first.
6977 bool printed_header = false;
6978 for (typename LhsStlContainer::const_iterator it =
6979 lhs_stl_container.begin();
6980 it != lhs_stl_container.end(); ++it) {
6981 if (internal::ArrayAwareFind(rhs_.begin(), rhs_.end(), *it) ==
6982 rhs_.end()) {
6983 if (printed_header) {
6984 *os << ", ";
6985 } else {
6986 *os << "which has these unexpected elements: ";
6987 printed_header = true;
6988 }
6989 UniversalPrint(*it, os);
6990 }
6991 }
6992
6993 // Now check for missing values.
6994 bool printed_header2 = false;
6995 for (typename StlContainer::const_iterator it = rhs_.begin();
6996 it != rhs_.end(); ++it) {
6997 if (internal::ArrayAwareFind(
6998 lhs_stl_container.begin(), lhs_stl_container.end(), *it) ==
6999 lhs_stl_container.end()) {
7000 if (printed_header2) {
7001 *os << ", ";
7002 } else {
7003 *os << (printed_header ? ",\nand" : "which")
7004 << " doesn't have these expected elements: ";
7005 printed_header2 = true;
7006 }
7007 UniversalPrint(*it, os);
7008 }
7009 }
7010 }
7011
7012 return false;
7013 }
7014
7015 private:
7016 const StlContainer rhs_;
7017
7018 GTEST_DISALLOW_ASSIGN_(ContainerEqMatcher);
7019};
7020
7021// A comparator functor that uses the < operator to compare two values.
7022struct LessComparator {
7023 template <typename T, typename U>
7024 bool operator()(const T& lhs, const U& rhs) const { return lhs < rhs; }
7025};
7026
7027// Implements WhenSortedBy(comparator, container_matcher).
7028template <typename Comparator, typename ContainerMatcher>
7029class WhenSortedByMatcher {
7030 public:
7031 WhenSortedByMatcher(const Comparator& comparator,
7032 const ContainerMatcher& matcher)
7033 : comparator_(comparator), matcher_(matcher) {}
7034
7035 template <typename LhsContainer>
7036 operator Matcher<LhsContainer>() const {
7037 return MakeMatcher(new Impl<LhsContainer>(comparator_, matcher_));
7038 }
7039
7040 template <typename LhsContainer>
7041 class Impl : public MatcherInterface<LhsContainer> {
7042 public:
7043 typedef internal::StlContainerView<
7044 GTEST_REMOVE_REFERENCE_AND_CONST_(LhsContainer)> LhsView;
7045 typedef typename LhsView::type LhsStlContainer;
7046 typedef typename LhsView::const_reference LhsStlContainerReference;
7047 // Transforms std::pair<const Key, Value> into std::pair<Key, Value>
7048 // so that we can match associative containers.
7049 typedef typename RemoveConstFromKey<
7050 typename LhsStlContainer::value_type>::type LhsValue;
7051
7052 Impl(const Comparator& comparator, const ContainerMatcher& matcher)
7053 : comparator_(comparator), matcher_(matcher) {}
7054
7055 virtual void DescribeTo(::std::ostream* os) const {
7056 *os << "(when sorted) ";
7057 matcher_.DescribeTo(os);
7058 }
7059
7060 virtual void DescribeNegationTo(::std::ostream* os) const {
7061 *os << "(when sorted) ";
7062 matcher_.DescribeNegationTo(os);
7063 }
7064
7065 virtual bool MatchAndExplain(LhsContainer lhs,
7066 MatchResultListener* listener) const {
7067 LhsStlContainerReference lhs_stl_container = LhsView::ConstReference(lhs);
7068 ::std::vector<LhsValue> sorted_container(lhs_stl_container.begin(),
7069 lhs_stl_container.end());
7070 ::std::sort(
7071 sorted_container.begin(), sorted_container.end(), comparator_);
7072
7073 if (!listener->IsInterested()) {
7074 // If the listener is not interested, we do not need to
7075 // construct the inner explanation.
7076 return matcher_.Matches(sorted_container);
7077 }
7078
7079 *listener << "which is ";
7080 UniversalPrint(sorted_container, listener->stream());
7081 *listener << " when sorted";
7082
7083 StringMatchResultListener inner_listener;
7084 const bool match = matcher_.MatchAndExplain(sorted_container,
7085 &inner_listener);
7086 PrintIfNotEmpty(inner_listener.str(), listener->stream());
7087 return match;
7088 }
7089
7090 private:
7091 const Comparator comparator_;
7092 const Matcher<const ::std::vector<LhsValue>&> matcher_;
7093
7094 GTEST_DISALLOW_COPY_AND_ASSIGN_(Impl);
7095 };
7096
7097 private:
7098 const Comparator comparator_;
7099 const ContainerMatcher matcher_;
7100
7101 GTEST_DISALLOW_ASSIGN_(WhenSortedByMatcher);
7102};
7103
7104// Implements Pointwise(tuple_matcher, rhs_container). tuple_matcher
7105// must be able to be safely cast to Matcher<tuple<const T1&, const
7106// T2&> >, where T1 and T2 are the types of elements in the LHS
7107// container and the RHS container respectively.
7108template <typename TupleMatcher, typename RhsContainer>
7109class PointwiseMatcher {
7110 public:
7111 typedef internal::StlContainerView<RhsContainer> RhsView;
7112 typedef typename RhsView::type RhsStlContainer;
7113 typedef typename RhsStlContainer::value_type RhsValue;
7114
7115 // Like ContainerEq, we make a copy of rhs in case the elements in
7116 // it are modified after this matcher is created.
7117 PointwiseMatcher(const TupleMatcher& tuple_matcher, const RhsContainer& rhs)
7118 : tuple_matcher_(tuple_matcher), rhs_(RhsView::Copy(rhs)) {
7119 // Makes sure the user doesn't instantiate this class template
7120 // with a const or reference type.
7121 (void)testing::StaticAssertTypeEq<RhsContainer,
7122 GTEST_REMOVE_REFERENCE_AND_CONST_(RhsContainer)>();
7123 }
7124
7125 template <typename LhsContainer>
7126 operator Matcher<LhsContainer>() const {
7127 return MakeMatcher(new Impl<LhsContainer>(tuple_matcher_, rhs_));
7128 }
7129
7130 template <typename LhsContainer>
7131 class Impl : public MatcherInterface<LhsContainer> {
7132 public:
7133 typedef internal::StlContainerView<
7134 GTEST_REMOVE_REFERENCE_AND_CONST_(LhsContainer)> LhsView;
7135 typedef typename LhsView::type LhsStlContainer;
7136 typedef typename LhsView::const_reference LhsStlContainerReference;
7137 typedef typename LhsStlContainer::value_type LhsValue;
7138 // We pass the LHS value and the RHS value to the inner matcher by
7139 // reference, as they may be expensive to copy. We must use tuple
7140 // instead of pair here, as a pair cannot hold references (C++ 98,
7141 // 20.2.2 [lib.pairs]).
7142 typedef ::std::tr1::tuple<const LhsValue&, const RhsValue&> InnerMatcherArg;
7143
7144 Impl(const TupleMatcher& tuple_matcher, const RhsStlContainer& rhs)
7145 // mono_tuple_matcher_ holds a monomorphic version of the tuple matcher.
7146 : mono_tuple_matcher_(SafeMatcherCast<InnerMatcherArg>(tuple_matcher)),
7147 rhs_(rhs) {}
7148
7149 virtual void DescribeTo(::std::ostream* os) const {
7150 *os << "contains " << rhs_.size()
7151 << " values, where each value and its corresponding value in ";
7152 UniversalPrinter<RhsStlContainer>::Print(rhs_, os);
7153 *os << " ";
7154 mono_tuple_matcher_.DescribeTo(os);
7155 }
7156 virtual void DescribeNegationTo(::std::ostream* os) const {
7157 *os << "doesn't contain exactly " << rhs_.size()
7158 << " values, or contains a value x at some index i"
7159 << " where x and the i-th value of ";
7160 UniversalPrint(rhs_, os);
7161 *os << " ";
7162 mono_tuple_matcher_.DescribeNegationTo(os);
7163 }
7164
7165 virtual bool MatchAndExplain(LhsContainer lhs,
7166 MatchResultListener* listener) const {
7167 LhsStlContainerReference lhs_stl_container = LhsView::ConstReference(lhs);
7168 const size_t actual_size = lhs_stl_container.size();
7169 if (actual_size != rhs_.size()) {
7170 *listener << "which contains " << actual_size << " values";
7171 return false;
7172 }
7173
7174 typename LhsStlContainer::const_iterator left = lhs_stl_container.begin();
7175 typename RhsStlContainer::const_iterator right = rhs_.begin();
7176 for (size_t i = 0; i != actual_size; ++i, ++left, ++right) {
7177 const InnerMatcherArg value_pair(*left, *right);
7178
7179 if (listener->IsInterested()) {
7180 StringMatchResultListener inner_listener;
7181 if (!mono_tuple_matcher_.MatchAndExplain(
7182 value_pair, &inner_listener)) {
7183 *listener << "where the value pair (";
7184 UniversalPrint(*left, listener->stream());
7185 *listener << ", ";
7186 UniversalPrint(*right, listener->stream());
7187 *listener << ") at index #" << i << " don't match";
7188 PrintIfNotEmpty(inner_listener.str(), listener->stream());
7189 return false;
7190 }
7191 } else {
7192 if (!mono_tuple_matcher_.Matches(value_pair))
7193 return false;
7194 }
7195 }
7196
7197 return true;
7198 }
7199
7200 private:
7201 const Matcher<InnerMatcherArg> mono_tuple_matcher_;
7202 const RhsStlContainer rhs_;
7203
7204 GTEST_DISALLOW_ASSIGN_(Impl);
7205 };
7206
7207 private:
7208 const TupleMatcher tuple_matcher_;
7209 const RhsStlContainer rhs_;
7210
7211 GTEST_DISALLOW_ASSIGN_(PointwiseMatcher);
7212};
7213
7214// Holds the logic common to ContainsMatcherImpl and EachMatcherImpl.
7215template <typename Container>
7216class QuantifierMatcherImpl : public MatcherInterface<Container> {
7217 public:
7218 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
7219 typedef StlContainerView<RawContainer> View;
7220 typedef typename View::type StlContainer;
7221 typedef typename View::const_reference StlContainerReference;
7222 typedef typename StlContainer::value_type Element;
7223
7224 template <typename InnerMatcher>
7225 explicit QuantifierMatcherImpl(InnerMatcher inner_matcher)
7226 : inner_matcher_(
7227 testing::SafeMatcherCast<const Element&>(inner_matcher)) {}
7228
7229 // Checks whether:
7230 // * All elements in the container match, if all_elements_should_match.
7231 // * Any element in the container matches, if !all_elements_should_match.
7232 bool MatchAndExplainImpl(bool all_elements_should_match,
7233 Container container,
7234 MatchResultListener* listener) const {
7235 StlContainerReference stl_container = View::ConstReference(container);
7236 size_t i = 0;
7237 for (typename StlContainer::const_iterator it = stl_container.begin();
7238 it != stl_container.end(); ++it, ++i) {
7239 StringMatchResultListener inner_listener;
7240 const bool matches = inner_matcher_.MatchAndExplain(*it, &inner_listener);
7241
7242 if (matches != all_elements_should_match) {
7243 *listener << "whose element #" << i
7244 << (matches ? " matches" : " doesn't match");
7245 PrintIfNotEmpty(inner_listener.str(), listener->stream());
7246 return !all_elements_should_match;
7247 }
7248 }
7249 return all_elements_should_match;
7250 }
7251
7252 protected:
7253 const Matcher<const Element&> inner_matcher_;
7254
7255 GTEST_DISALLOW_ASSIGN_(QuantifierMatcherImpl);
7256};
7257
7258// Implements Contains(element_matcher) for the given argument type Container.
7259// Symmetric to EachMatcherImpl.
7260template <typename Container>
7261class ContainsMatcherImpl : public QuantifierMatcherImpl<Container> {
7262 public:
7263 template <typename InnerMatcher>
7264 explicit ContainsMatcherImpl(InnerMatcher inner_matcher)
7265 : QuantifierMatcherImpl<Container>(inner_matcher) {}
7266
7267 // Describes what this matcher does.
7268 virtual void DescribeTo(::std::ostream* os) const {
7269 *os << "contains at least one element that ";
7270 this->inner_matcher_.DescribeTo(os);
7271 }
7272
7273 virtual void DescribeNegationTo(::std::ostream* os) const {
7274 *os << "doesn't contain any element that ";
7275 this->inner_matcher_.DescribeTo(os);
7276 }
7277
7278 virtual bool MatchAndExplain(Container container,
7279 MatchResultListener* listener) const {
7280 return this->MatchAndExplainImpl(false, container, listener);
7281 }
7282
7283 private:
7284 GTEST_DISALLOW_ASSIGN_(ContainsMatcherImpl);
7285};
7286
7287// Implements Each(element_matcher) for the given argument type Container.
7288// Symmetric to ContainsMatcherImpl.
7289template <typename Container>
7290class EachMatcherImpl : public QuantifierMatcherImpl<Container> {
7291 public:
7292 template <typename InnerMatcher>
7293 explicit EachMatcherImpl(InnerMatcher inner_matcher)
7294 : QuantifierMatcherImpl<Container>(inner_matcher) {}
7295
7296 // Describes what this matcher does.
7297 virtual void DescribeTo(::std::ostream* os) const {
7298 *os << "only contains elements that ";
7299 this->inner_matcher_.DescribeTo(os);
7300 }
7301
7302 virtual void DescribeNegationTo(::std::ostream* os) const {
7303 *os << "contains some element that ";
7304 this->inner_matcher_.DescribeNegationTo(os);
7305 }
7306
7307 virtual bool MatchAndExplain(Container container,
7308 MatchResultListener* listener) const {
7309 return this->MatchAndExplainImpl(true, container, listener);
7310 }
7311
7312 private:
7313 GTEST_DISALLOW_ASSIGN_(EachMatcherImpl);
7314};
7315
7316// Implements polymorphic Contains(element_matcher).
7317template <typename M>
7318class ContainsMatcher {
7319 public:
7320 explicit ContainsMatcher(M m) : inner_matcher_(m) {}
7321
7322 template <typename Container>
7323 operator Matcher<Container>() const {
7324 return MakeMatcher(new ContainsMatcherImpl<Container>(inner_matcher_));
7325 }
7326
7327 private:
7328 const M inner_matcher_;
7329
7330 GTEST_DISALLOW_ASSIGN_(ContainsMatcher);
7331};
7332
7333// Implements polymorphic Each(element_matcher).
7334template <typename M>
7335class EachMatcher {
7336 public:
7337 explicit EachMatcher(M m) : inner_matcher_(m) {}
7338
7339 template <typename Container>
7340 operator Matcher<Container>() const {
7341 return MakeMatcher(new EachMatcherImpl<Container>(inner_matcher_));
7342 }
7343
7344 private:
7345 const M inner_matcher_;
7346
7347 GTEST_DISALLOW_ASSIGN_(EachMatcher);
7348};
7349
7350// Implements Key(inner_matcher) for the given argument pair type.
7351// Key(inner_matcher) matches an std::pair whose 'first' field matches
7352// inner_matcher. For example, Contains(Key(Ge(5))) can be used to match an
7353// std::map that contains at least one element whose key is >= 5.
7354template <typename PairType>
7355class KeyMatcherImpl : public MatcherInterface<PairType> {
7356 public:
7357 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(PairType) RawPairType;
7358 typedef typename RawPairType::first_type KeyType;
7359
7360 template <typename InnerMatcher>
7361 explicit KeyMatcherImpl(InnerMatcher inner_matcher)
7362 : inner_matcher_(
7363 testing::SafeMatcherCast<const KeyType&>(inner_matcher)) {
7364 }
7365
7366 // Returns true iff 'key_value.first' (the key) matches the inner matcher.
7367 virtual bool MatchAndExplain(PairType key_value,
7368 MatchResultListener* listener) const {
7369 StringMatchResultListener inner_listener;
7370 const bool match = inner_matcher_.MatchAndExplain(key_value.first,
7371 &inner_listener);
7372 const internal::string explanation = inner_listener.str();
7373 if (explanation != "") {
7374 *listener << "whose first field is a value " << explanation;
7375 }
7376 return match;
7377 }
7378
7379 // Describes what this matcher does.
7380 virtual void DescribeTo(::std::ostream* os) const {
7381 *os << "has a key that ";
7382 inner_matcher_.DescribeTo(os);
7383 }
7384
7385 // Describes what the negation of this matcher does.
7386 virtual void DescribeNegationTo(::std::ostream* os) const {
7387 *os << "doesn't have a key that ";
7388 inner_matcher_.DescribeTo(os);
7389 }
7390
7391 private:
7392 const Matcher<const KeyType&> inner_matcher_;
7393
7394 GTEST_DISALLOW_ASSIGN_(KeyMatcherImpl);
7395};
7396
7397// Implements polymorphic Key(matcher_for_key).
7398template <typename M>
7399class KeyMatcher {
7400 public:
7401 explicit KeyMatcher(M m) : matcher_for_key_(m) {}
7402
7403 template <typename PairType>
7404 operator Matcher<PairType>() const {
7405 return MakeMatcher(new KeyMatcherImpl<PairType>(matcher_for_key_));
7406 }
7407
7408 private:
7409 const M matcher_for_key_;
7410
7411 GTEST_DISALLOW_ASSIGN_(KeyMatcher);
7412};
7413
7414// Implements Pair(first_matcher, second_matcher) for the given argument pair
7415// type with its two matchers. See Pair() function below.
7416template <typename PairType>
7417class PairMatcherImpl : public MatcherInterface<PairType> {
7418 public:
7419 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(PairType) RawPairType;
7420 typedef typename RawPairType::first_type FirstType;
7421 typedef typename RawPairType::second_type SecondType;
7422
7423 template <typename FirstMatcher, typename SecondMatcher>
7424 PairMatcherImpl(FirstMatcher first_matcher, SecondMatcher second_matcher)
7425 : first_matcher_(
7426 testing::SafeMatcherCast<const FirstType&>(first_matcher)),
7427 second_matcher_(
7428 testing::SafeMatcherCast<const SecondType&>(second_matcher)) {
7429 }
7430
7431 // Describes what this matcher does.
7432 virtual void DescribeTo(::std::ostream* os) const {
7433 *os << "has a first field that ";
7434 first_matcher_.DescribeTo(os);
7435 *os << ", and has a second field that ";
7436 second_matcher_.DescribeTo(os);
7437 }
7438
7439 // Describes what the negation of this matcher does.
7440 virtual void DescribeNegationTo(::std::ostream* os) const {
7441 *os << "has a first field that ";
7442 first_matcher_.DescribeNegationTo(os);
7443 *os << ", or has a second field that ";
7444 second_matcher_.DescribeNegationTo(os);
7445 }
7446
7447 // Returns true iff 'a_pair.first' matches first_matcher and 'a_pair.second'
7448 // matches second_matcher.
7449 virtual bool MatchAndExplain(PairType a_pair,
7450 MatchResultListener* listener) const {
7451 if (!listener->IsInterested()) {
7452 // If the listener is not interested, we don't need to construct the
7453 // explanation.
7454 return first_matcher_.Matches(a_pair.first) &&
7455 second_matcher_.Matches(a_pair.second);
7456 }
7457 StringMatchResultListener first_inner_listener;
7458 if (!first_matcher_.MatchAndExplain(a_pair.first,
7459 &first_inner_listener)) {
7460 *listener << "whose first field does not match";
7461 PrintIfNotEmpty(first_inner_listener.str(), listener->stream());
7462 return false;
7463 }
7464 StringMatchResultListener second_inner_listener;
7465 if (!second_matcher_.MatchAndExplain(a_pair.second,
7466 &second_inner_listener)) {
7467 *listener << "whose second field does not match";
7468 PrintIfNotEmpty(second_inner_listener.str(), listener->stream());
7469 return false;
7470 }
7471 ExplainSuccess(first_inner_listener.str(), second_inner_listener.str(),
7472 listener);
7473 return true;
7474 }
7475
7476 private:
7477 void ExplainSuccess(const internal::string& first_explanation,
7478 const internal::string& second_explanation,
7479 MatchResultListener* listener) const {
7480 *listener << "whose both fields match";
7481 if (first_explanation != "") {
7482 *listener << ", where the first field is a value " << first_explanation;
7483 }
7484 if (second_explanation != "") {
7485 *listener << ", ";
7486 if (first_explanation != "") {
7487 *listener << "and ";
7488 } else {
7489 *listener << "where ";
7490 }
7491 *listener << "the second field is a value " << second_explanation;
7492 }
7493 }
7494
7495 const Matcher<const FirstType&> first_matcher_;
7496 const Matcher<const SecondType&> second_matcher_;
7497
7498 GTEST_DISALLOW_ASSIGN_(PairMatcherImpl);
7499};
7500
7501// Implements polymorphic Pair(first_matcher, second_matcher).
7502template <typename FirstMatcher, typename SecondMatcher>
7503class PairMatcher {
7504 public:
7505 PairMatcher(FirstMatcher first_matcher, SecondMatcher second_matcher)
7506 : first_matcher_(first_matcher), second_matcher_(second_matcher) {}
7507
7508 template <typename PairType>
7509 operator Matcher<PairType> () const {
7510 return MakeMatcher(
7511 new PairMatcherImpl<PairType>(
7512 first_matcher_, second_matcher_));
7513 }
7514
7515 private:
7516 const FirstMatcher first_matcher_;
7517 const SecondMatcher second_matcher_;
7518
7519 GTEST_DISALLOW_ASSIGN_(PairMatcher);
7520};
7521
7522// Implements ElementsAre() and ElementsAreArray().
7523template <typename Container>
7524class ElementsAreMatcherImpl : public MatcherInterface<Container> {
7525 public:
7526 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
7527 typedef internal::StlContainerView<RawContainer> View;
7528 typedef typename View::type StlContainer;
7529 typedef typename View::const_reference StlContainerReference;
7530 typedef typename StlContainer::value_type Element;
7531
7532 // Constructs the matcher from a sequence of element values or
7533 // element matchers.
7534 template <typename InputIter>
7535 ElementsAreMatcherImpl(InputIter first, InputIter last) {
7536 while (first != last) {
7537 matchers_.push_back(MatcherCast<const Element&>(*first++));
7538 }
7539 }
7540
7541 // Describes what this matcher does.
7542 virtual void DescribeTo(::std::ostream* os) const {
7543 if (count() == 0) {
7544 *os << "is empty";
7545 } else if (count() == 1) {
7546 *os << "has 1 element that ";
7547 matchers_[0].DescribeTo(os);
7548 } else {
7549 *os << "has " << Elements(count()) << " where\n";
7550 for (size_t i = 0; i != count(); ++i) {
7551 *os << "element #" << i << " ";
7552 matchers_[i].DescribeTo(os);
7553 if (i + 1 < count()) {
7554 *os << ",\n";
7555 }
7556 }
7557 }
7558 }
7559
7560 // Describes what the negation of this matcher does.
7561 virtual void DescribeNegationTo(::std::ostream* os) const {
7562 if (count() == 0) {
7563 *os << "isn't empty";
7564 return;
7565 }
7566
7567 *os << "doesn't have " << Elements(count()) << ", or\n";
7568 for (size_t i = 0; i != count(); ++i) {
7569 *os << "element #" << i << " ";
7570 matchers_[i].DescribeNegationTo(os);
7571 if (i + 1 < count()) {
7572 *os << ", or\n";
7573 }
7574 }
7575 }
7576
7577 virtual bool MatchAndExplain(Container container,
7578 MatchResultListener* listener) const {
7579 // To work with stream-like "containers", we must only walk
7580 // through the elements in one pass.
7581
7582 const bool listener_interested = listener->IsInterested();
7583
7584 // explanations[i] is the explanation of the element at index i.
7585 ::std::vector<internal::string> explanations(count());
7586 StlContainerReference stl_container = View::ConstReference(container);
7587 typename StlContainer::const_iterator it = stl_container.begin();
7588 size_t exam_pos = 0;
7589 bool mismatch_found = false; // Have we found a mismatched element yet?
7590
7591 // Go through the elements and matchers in pairs, until we reach
7592 // the end of either the elements or the matchers, or until we find a
7593 // mismatch.
7594 for (; it != stl_container.end() && exam_pos != count(); ++it, ++exam_pos) {
7595 bool match; // Does the current element match the current matcher?
7596 if (listener_interested) {
7597 StringMatchResultListener s;
7598 match = matchers_[exam_pos].MatchAndExplain(*it, &s);
7599 explanations[exam_pos] = s.str();
7600 } else {
7601 match = matchers_[exam_pos].Matches(*it);
7602 }
7603
7604 if (!match) {
7605 mismatch_found = true;
7606 break;
7607 }
7608 }
7609 // If mismatch_found is true, 'exam_pos' is the index of the mismatch.
7610
7611 // Find how many elements the actual container has. We avoid
7612 // calling size() s.t. this code works for stream-like "containers"
7613 // that don't define size().
7614 size_t actual_count = exam_pos;
7615 for (; it != stl_container.end(); ++it) {
7616 ++actual_count;
7617 }
7618
7619 if (actual_count != count()) {
7620 // The element count doesn't match. If the container is empty,
7621 // there's no need to explain anything as Google Mock already
7622 // prints the empty container. Otherwise we just need to show
7623 // how many elements there actually are.
7624 if (listener_interested && (actual_count != 0)) {
7625 *listener << "which has " << Elements(actual_count);
7626 }
7627 return false;
7628 }
7629
7630 if (mismatch_found) {
7631 // The element count matches, but the exam_pos-th element doesn't match.
7632 if (listener_interested) {
7633 *listener << "whose element #" << exam_pos << " doesn't match";
7634 PrintIfNotEmpty(explanations[exam_pos], listener->stream());
7635 }
7636 return false;
7637 }
7638
7639 // Every element matches its expectation. We need to explain why
7640 // (the obvious ones can be skipped).
7641 if (listener_interested) {
7642 bool reason_printed = false;
7643 for (size_t i = 0; i != count(); ++i) {
7644 const internal::string& s = explanations[i];
7645 if (!s.empty()) {
7646 if (reason_printed) {
7647 *listener << ",\nand ";
7648 }
7649 *listener << "whose element #" << i << " matches, " << s;
7650 reason_printed = true;
7651 }
7652 }
7653 }
7654 return true;
7655 }
7656
7657 private:
7658 static Message Elements(size_t count) {
7659 return Message() << count << (count == 1 ? " element" : " elements");
7660 }
7661
7662 size_t count() const { return matchers_.size(); }
7663
7664 ::std::vector<Matcher<const Element&> > matchers_;
7665
7666 GTEST_DISALLOW_ASSIGN_(ElementsAreMatcherImpl);
7667};
7668
7669// Connectivity matrix of (elements X matchers), in element-major order.
7670// Initially, there are no edges.
7671// Use NextGraph() to iterate over all possible edge configurations.
7672// Use Randomize() to generate a random edge configuration.
7673class GTEST_API_ MatchMatrix {
7674 public:
7675 MatchMatrix(size_t num_elements, size_t num_matchers)
7676 : num_elements_(num_elements),
7677 num_matchers_(num_matchers),
7678 matched_(num_elements_* num_matchers_, 0) {
7679 }
7680
7681 size_t LhsSize() const { return num_elements_; }
7682 size_t RhsSize() const { return num_matchers_; }
7683 bool HasEdge(size_t ilhs, size_t irhs) const {
7684 return matched_[SpaceIndex(ilhs, irhs)] == 1;
7685 }
7686 void SetEdge(size_t ilhs, size_t irhs, bool b) {
7687 matched_[SpaceIndex(ilhs, irhs)] = b ? 1 : 0;
7688 }
7689
7690 // Treating the connectivity matrix as a (LhsSize()*RhsSize())-bit number,
7691 // adds 1 to that number; returns false if incrementing the graph left it
7692 // empty.
7693 bool NextGraph();
7694
7695 void Randomize();
7696
7697 string DebugString() const;
7698
7699 private:
7700 size_t SpaceIndex(size_t ilhs, size_t irhs) const {
7701 return ilhs * num_matchers_ + irhs;
7702 }
7703
7704 size_t num_elements_;
7705 size_t num_matchers_;
7706
7707 // Each element is a char interpreted as bool. They are stored as a
7708 // flattened array in lhs-major order, use 'SpaceIndex()' to translate
7709 // a (ilhs, irhs) matrix coordinate into an offset.
7710 ::std::vector<char> matched_;
7711};
7712
7713typedef ::std::pair<size_t, size_t> ElementMatcherPair;
7714typedef ::std::vector<ElementMatcherPair> ElementMatcherPairs;
7715
7716// Returns a maximum bipartite matching for the specified graph 'g'.
7717// The matching is represented as a vector of {element, matcher} pairs.
7718GTEST_API_ ElementMatcherPairs
7719FindMaxBipartiteMatching(const MatchMatrix& g);
7720
7721GTEST_API_ bool FindPairing(const MatchMatrix& matrix,
7722 MatchResultListener* listener);
7723
7724// Untyped base class for implementing UnorderedElementsAre. By
7725// putting logic that's not specific to the element type here, we
7726// reduce binary bloat and increase compilation speed.
7727class GTEST_API_ UnorderedElementsAreMatcherImplBase {
7728 protected:
7729 // A vector of matcher describers, one for each element matcher.
7730 // Does not own the describers (and thus can be used only when the
7731 // element matchers are alive).
7732 typedef ::std::vector<const MatcherDescriberInterface*> MatcherDescriberVec;
7733
7734 // Describes this UnorderedElementsAre matcher.
7735 void DescribeToImpl(::std::ostream* os) const;
7736
7737 // Describes the negation of this UnorderedElementsAre matcher.
7738 void DescribeNegationToImpl(::std::ostream* os) const;
7739
7740 bool VerifyAllElementsAndMatchersAreMatched(
7741 const ::std::vector<string>& element_printouts,
7742 const MatchMatrix& matrix,
7743 MatchResultListener* listener) const;
7744
7745 MatcherDescriberVec& matcher_describers() {
7746 return matcher_describers_;
7747 }
7748
7749 static Message Elements(size_t n) {
7750 return Message() << n << " element" << (n == 1 ? "" : "s");
7751 }
7752
7753 private:
7754 MatcherDescriberVec matcher_describers_;
7755
7756 GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreMatcherImplBase);
7757};
7758
7759// Implements unordered ElementsAre and unordered ElementsAreArray.
7760template <typename Container>
7761class UnorderedElementsAreMatcherImpl
7762 : public MatcherInterface<Container>,
7763 public UnorderedElementsAreMatcherImplBase {
7764 public:
7765 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
7766 typedef internal::StlContainerView<RawContainer> View;
7767 typedef typename View::type StlContainer;
7768 typedef typename View::const_reference StlContainerReference;
7769 typedef typename StlContainer::const_iterator StlContainerConstIterator;
7770 typedef typename StlContainer::value_type Element;
7771
7772 // Constructs the matcher from a sequence of element values or
7773 // element matchers.
7774 template <typename InputIter>
7775 UnorderedElementsAreMatcherImpl(InputIter first, InputIter last) {
7776 for (; first != last; ++first) {
7777 matchers_.push_back(MatcherCast<const Element&>(*first));
7778 matcher_describers().push_back(matchers_.back().GetDescriber());
7779 }
7780 }
7781
7782 // Describes what this matcher does.
7783 virtual void DescribeTo(::std::ostream* os) const {
7784 return UnorderedElementsAreMatcherImplBase::DescribeToImpl(os);
7785 }
7786
7787 // Describes what the negation of this matcher does.
7788 virtual void DescribeNegationTo(::std::ostream* os) const {
7789 return UnorderedElementsAreMatcherImplBase::DescribeNegationToImpl(os);
7790 }
7791
7792 virtual bool MatchAndExplain(Container container,
7793 MatchResultListener* listener) const {
7794 StlContainerReference stl_container = View::ConstReference(container);
7795 ::std::vector<string> element_printouts;
7796 MatchMatrix matrix = AnalyzeElements(stl_container.begin(),
7797 stl_container.end(),
7798 &element_printouts,
7799 listener);
7800
7801 const size_t actual_count = matrix.LhsSize();
7802 if (actual_count == 0 && matchers_.empty()) {
7803 return true;
7804 }
7805 if (actual_count != matchers_.size()) {
7806 // The element count doesn't match. If the container is empty,
7807 // there's no need to explain anything as Google Mock already
7808 // prints the empty container. Otherwise we just need to show
7809 // how many elements there actually are.
7810 if (actual_count != 0 && listener->IsInterested()) {
7811 *listener << "which has " << Elements(actual_count);
7812 }
7813 return false;
7814 }
7815
7816 return VerifyAllElementsAndMatchersAreMatched(element_printouts,
7817 matrix, listener) &&
7818 FindPairing(matrix, listener);
7819 }
7820
7821 private:
7822 typedef ::std::vector<Matcher<const Element&> > MatcherVec;
7823
7824 template <typename ElementIter>
7825 MatchMatrix AnalyzeElements(ElementIter elem_first, ElementIter elem_last,
7826 ::std::vector<string>* element_printouts,
7827 MatchResultListener* listener) const {
7828 element_printouts->clear();
7829 ::std::vector<char> did_match;
7830 size_t num_elements = 0;
7831 for (; elem_first != elem_last; ++num_elements, ++elem_first) {
7832 if (listener->IsInterested()) {
7833 element_printouts->push_back(PrintToString(*elem_first));
7834 }
7835 for (size_t irhs = 0; irhs != matchers_.size(); ++irhs) {
7836 did_match.push_back(Matches(matchers_[irhs])(*elem_first));
7837 }
7838 }
7839
7840 MatchMatrix matrix(num_elements, matchers_.size());
7841 ::std::vector<char>::const_iterator did_match_iter = did_match.begin();
7842 for (size_t ilhs = 0; ilhs != num_elements; ++ilhs) {
7843 for (size_t irhs = 0; irhs != matchers_.size(); ++irhs) {
7844 matrix.SetEdge(ilhs, irhs, *did_match_iter++ != 0);
7845 }
7846 }
7847 return matrix;
7848 }
7849
7850 MatcherVec matchers_;
7851
7852 GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreMatcherImpl);
7853};
7854
7855// Functor for use in TransformTuple.
7856// Performs MatcherCast<Target> on an input argument of any type.
7857template <typename Target>
7858struct CastAndAppendTransform {
7859 template <typename Arg>
7860 Matcher<Target> operator()(const Arg& a) const {
7861 return MatcherCast<Target>(a);
7862 }
7863};
7864
7865// Implements UnorderedElementsAre.
7866template <typename MatcherTuple>
7867class UnorderedElementsAreMatcher {
7868 public:
7869 explicit UnorderedElementsAreMatcher(const MatcherTuple& args)
7870 : matchers_(args) {}
7871
7872 template <typename Container>
7873 operator Matcher<Container>() const {
7874 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
7875 typedef typename internal::StlContainerView<RawContainer>::type View;
7876 typedef typename View::value_type Element;
7877 typedef ::std::vector<Matcher<const Element&> > MatcherVec;
7878 MatcherVec matchers;
7879 matchers.reserve(::std::tr1::tuple_size<MatcherTuple>::value);
7880 TransformTupleValues(CastAndAppendTransform<const Element&>(), matchers_,
7881 ::std::back_inserter(matchers));
7882 return MakeMatcher(new UnorderedElementsAreMatcherImpl<Container>(
7883 matchers.begin(), matchers.end()));
7884 }
7885
7886 private:
7887 const MatcherTuple matchers_;
7888 GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreMatcher);
7889};
7890
7891// Implements ElementsAre.
7892template <typename MatcherTuple>
7893class ElementsAreMatcher {
7894 public:
7895 explicit ElementsAreMatcher(const MatcherTuple& args) : matchers_(args) {}
7896
7897 template <typename Container>
7898 operator Matcher<Container>() const {
7899 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
7900 typedef typename internal::StlContainerView<RawContainer>::type View;
7901 typedef typename View::value_type Element;
7902 typedef ::std::vector<Matcher<const Element&> > MatcherVec;
7903 MatcherVec matchers;
7904 matchers.reserve(::std::tr1::tuple_size<MatcherTuple>::value);
7905 TransformTupleValues(CastAndAppendTransform<const Element&>(), matchers_,
7906 ::std::back_inserter(matchers));
7907 return MakeMatcher(new ElementsAreMatcherImpl<Container>(
7908 matchers.begin(), matchers.end()));
7909 }
7910
7911 private:
7912 const MatcherTuple matchers_;
7913 GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher);
7914};
7915
7916// Implements UnorderedElementsAreArray().
7917template <typename T>
7918class UnorderedElementsAreArrayMatcher {
7919 public:
7920 UnorderedElementsAreArrayMatcher() {}
7921
7922 template <typename Iter>
7923 UnorderedElementsAreArrayMatcher(Iter first, Iter last)
7924 : matchers_(first, last) {}
7925
7926 template <typename Container>
7927 operator Matcher<Container>() const {
7928 return MakeMatcher(
7929 new UnorderedElementsAreMatcherImpl<Container>(matchers_.begin(),
7930 matchers_.end()));
7931 }
7932
7933 private:
7934 ::std::vector<T> matchers_;
7935
7936 GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreArrayMatcher);
7937};
7938
7939// Implements ElementsAreArray().
7940template <typename T>
7941class ElementsAreArrayMatcher {
7942 public:
7943 template <typename Iter>
7944 ElementsAreArrayMatcher(Iter first, Iter last) : matchers_(first, last) {}
7945
7946 template <typename Container>
7947 operator Matcher<Container>() const {
7948 return MakeMatcher(new ElementsAreMatcherImpl<Container>(
7949 matchers_.begin(), matchers_.end()));
7950 }
7951
7952 private:
7953 const ::std::vector<T> matchers_;
7954
7955 GTEST_DISALLOW_ASSIGN_(ElementsAreArrayMatcher);
7956};
7957
7958// Returns the description for a matcher defined using the MATCHER*()
7959// macro where the user-supplied description string is "", if
7960// 'negation' is false; otherwise returns the description of the
7961// negation of the matcher. 'param_values' contains a list of strings
7962// that are the print-out of the matcher's parameters.
7963GTEST_API_ string FormatMatcherDescription(bool negation,
7964 const char* matcher_name,
7965 const Strings& param_values);
7966
7967} // namespace internal
7968
7969// ElementsAreArray(first, last)
7970// ElementsAreArray(pointer, count)
7971// ElementsAreArray(array)
7972// ElementsAreArray(vector)
7973// ElementsAreArray({ e1, e2, ..., en })
7974//
7975// The ElementsAreArray() functions are like ElementsAre(...), except
7976// that they are given a homogeneous sequence rather than taking each
7977// element as a function argument. The sequence can be specified as an
7978// array, a pointer and count, a vector, an initializer list, or an
7979// STL iterator range. In each of these cases, the underlying sequence
7980// can be either a sequence of values or a sequence of matchers.
7981//
7982// All forms of ElementsAreArray() make a copy of the input matcher sequence.
7983
7984template <typename Iter>
7985inline internal::ElementsAreArrayMatcher<
7986 typename ::std::iterator_traits<Iter>::value_type>
7987ElementsAreArray(Iter first, Iter last) {
7988 typedef typename ::std::iterator_traits<Iter>::value_type T;
7989 return internal::ElementsAreArrayMatcher<T>(first, last);
7990}
7991
7992template <typename T>
7993inline internal::ElementsAreArrayMatcher<T> ElementsAreArray(
7994 const T* pointer, size_t count) {
7995 return ElementsAreArray(pointer, pointer + count);
7996}
7997
7998template <typename T, size_t N>
7999inline internal::ElementsAreArrayMatcher<T> ElementsAreArray(
8000 const T (&array)[N]) {
8001 return ElementsAreArray(array, N);
8002}
8003
8004template <typename T, typename A>
8005inline internal::ElementsAreArrayMatcher<T> ElementsAreArray(
8006 const ::std::vector<T, A>& vec) {
8007 return ElementsAreArray(vec.begin(), vec.end());
8008}
8009
8010#if GTEST_LANG_CXX11
8011template <typename T>
8012inline internal::ElementsAreArrayMatcher<T>
8013ElementsAreArray(::std::initializer_list<T> xs) {
8014 return ElementsAreArray(xs.begin(), xs.end());
8015}
8016#endif
8017
8018// UnorderedElementsAreArray(first, last)
8019// UnorderedElementsAreArray(pointer, count)
8020// UnorderedElementsAreArray(array)
8021// UnorderedElementsAreArray(vector)
8022// UnorderedElementsAreArray({ e1, e2, ..., en })
8023//
8024// The UnorderedElementsAreArray() functions are like
8025// ElementsAreArray(...), but allow matching the elements in any order.
8026template <typename Iter>
8027inline internal::UnorderedElementsAreArrayMatcher<
8028 typename ::std::iterator_traits<Iter>::value_type>
8029UnorderedElementsAreArray(Iter first, Iter last) {
8030 typedef typename ::std::iterator_traits<Iter>::value_type T;
8031 return internal::UnorderedElementsAreArrayMatcher<T>(first, last);
8032}
8033
8034template <typename T>
8035inline internal::UnorderedElementsAreArrayMatcher<T>
8036UnorderedElementsAreArray(const T* pointer, size_t count) {
8037 return UnorderedElementsAreArray(pointer, pointer + count);
8038}
8039
8040template <typename T, size_t N>
8041inline internal::UnorderedElementsAreArrayMatcher<T>
8042UnorderedElementsAreArray(const T (&array)[N]) {
8043 return UnorderedElementsAreArray(array, N);
8044}
8045
8046template <typename T, typename A>
8047inline internal::UnorderedElementsAreArrayMatcher<T>
8048UnorderedElementsAreArray(const ::std::vector<T, A>& vec) {
8049 return UnorderedElementsAreArray(vec.begin(), vec.end());
8050}
8051
8052#if GTEST_LANG_CXX11
8053template <typename T>
8054inline internal::UnorderedElementsAreArrayMatcher<T>
8055UnorderedElementsAreArray(::std::initializer_list<T> xs) {
8056 return UnorderedElementsAreArray(xs.begin(), xs.end());
8057}
8058#endif
8059
8060// _ is a matcher that matches anything of any type.
8061//
8062// This definition is fine as:
8063//
8064// 1. The C++ standard permits using the name _ in a namespace that
8065// is not the global namespace or ::std.
8066// 2. The AnythingMatcher class has no data member or constructor,
8067// so it's OK to create global variables of this type.
8068// 3. c-style has approved of using _ in this case.
8069const internal::AnythingMatcher _ = {};
8070// Creates a matcher that matches any value of the given type T.
8071template <typename T>
8072inline Matcher<T> A() { return MakeMatcher(new internal::AnyMatcherImpl<T>()); }
8073
8074// Creates a matcher that matches any value of the given type T.
8075template <typename T>
8076inline Matcher<T> An() { return A<T>(); }
8077
8078// Creates a polymorphic matcher that matches anything equal to x.
8079// Note: if the parameter of Eq() were declared as const T&, Eq("foo")
8080// wouldn't compile.
8081template <typename T>
8082inline internal::EqMatcher<T> Eq(T x) { return internal::EqMatcher<T>(x); }
8083
8084// Constructs a Matcher<T> from a 'value' of type T. The constructed
8085// matcher matches any value that's equal to 'value'.
8086template <typename T>
8087Matcher<T>::Matcher(T value) { *this = Eq(value); }
8088
8089// Creates a monomorphic matcher that matches anything with type Lhs
8090// and equal to rhs. A user may need to use this instead of Eq(...)
8091// in order to resolve an overloading ambiguity.
8092//
8093// TypedEq<T>(x) is just a convenient short-hand for Matcher<T>(Eq(x))
8094// or Matcher<T>(x), but more readable than the latter.
8095//
8096// We could define similar monomorphic matchers for other comparison
8097// operations (e.g. TypedLt, TypedGe, and etc), but decided not to do
8098// it yet as those are used much less than Eq() in practice. A user
8099// can always write Matcher<T>(Lt(5)) to be explicit about the type,
8100// for example.
8101template <typename Lhs, typename Rhs>
8102inline Matcher<Lhs> TypedEq(const Rhs& rhs) { return Eq(rhs); }
8103
8104// Creates a polymorphic matcher that matches anything >= x.
8105template <typename Rhs>
8106inline internal::GeMatcher<Rhs> Ge(Rhs x) {
8107 return internal::GeMatcher<Rhs>(x);
8108}
8109
8110// Creates a polymorphic matcher that matches anything > x.
8111template <typename Rhs>
8112inline internal::GtMatcher<Rhs> Gt(Rhs x) {
8113 return internal::GtMatcher<Rhs>(x);
8114}
8115
8116// Creates a polymorphic matcher that matches anything <= x.
8117template <typename Rhs>
8118inline internal::LeMatcher<Rhs> Le(Rhs x) {
8119 return internal::LeMatcher<Rhs>(x);
8120}
8121
8122// Creates a polymorphic matcher that matches anything < x.
8123template <typename Rhs>
8124inline internal::LtMatcher<Rhs> Lt(Rhs x) {
8125 return internal::LtMatcher<Rhs>(x);
8126}
8127
8128// Creates a polymorphic matcher that matches anything != x.
8129template <typename Rhs>
8130inline internal::NeMatcher<Rhs> Ne(Rhs x) {
8131 return internal::NeMatcher<Rhs>(x);
8132}
8133
8134// Creates a polymorphic matcher that matches any NULL pointer.
8135inline PolymorphicMatcher<internal::IsNullMatcher > IsNull() {
8136 return MakePolymorphicMatcher(internal::IsNullMatcher());
8137}
8138
8139// Creates a polymorphic matcher that matches any non-NULL pointer.
8140// This is convenient as Not(NULL) doesn't compile (the compiler
8141// thinks that that expression is comparing a pointer with an integer).
8142inline PolymorphicMatcher<internal::NotNullMatcher > NotNull() {
8143 return MakePolymorphicMatcher(internal::NotNullMatcher());
8144}
8145
8146// Creates a polymorphic matcher that matches any argument that
8147// references variable x.
8148template <typename T>
8149inline internal::RefMatcher<T&> Ref(T& x) { // NOLINT
8150 return internal::RefMatcher<T&>(x);
8151}
8152
8153// Creates a matcher that matches any double argument approximately
8154// equal to rhs, where two NANs are considered unequal.
8155inline internal::FloatingEqMatcher<double> DoubleEq(double rhs) {
8156 return internal::FloatingEqMatcher<double>(rhs, false);
8157}
8158
8159// Creates a matcher that matches any double argument approximately
8160// equal to rhs, including NaN values when rhs is NaN.
8161inline internal::FloatingEqMatcher<double> NanSensitiveDoubleEq(double rhs) {
8162 return internal::FloatingEqMatcher<double>(rhs, true);
8163}
8164
8165// Creates a matcher that matches any double argument approximately equal to
8166// rhs, up to the specified max absolute error bound, where two NANs are
8167// considered unequal. The max absolute error bound must be non-negative.
8168inline internal::FloatingEqMatcher<double> DoubleNear(
8169 double rhs, double max_abs_error) {
8170 return internal::FloatingEqMatcher<double>(rhs, false, max_abs_error);
8171}
8172
8173// Creates a matcher that matches any double argument approximately equal to
8174// rhs, up to the specified max absolute error bound, including NaN values when
8175// rhs is NaN. The max absolute error bound must be non-negative.
8176inline internal::FloatingEqMatcher<double> NanSensitiveDoubleNear(
8177 double rhs, double max_abs_error) {
8178 return internal::FloatingEqMatcher<double>(rhs, true, max_abs_error);
8179}
8180
8181// Creates a matcher that matches any float argument approximately
8182// equal to rhs, where two NANs are considered unequal.
8183inline internal::FloatingEqMatcher<float> FloatEq(float rhs) {
8184 return internal::FloatingEqMatcher<float>(rhs, false);
8185}
8186
8187// Creates a matcher that matches any float argument approximately
8188// equal to rhs, including NaN values when rhs is NaN.
8189inline internal::FloatingEqMatcher<float> NanSensitiveFloatEq(float rhs) {
8190 return internal::FloatingEqMatcher<float>(rhs, true);
8191}
8192
8193// Creates a matcher that matches any float argument approximately equal to
8194// rhs, up to the specified max absolute error bound, where two NANs are
8195// considered unequal. The max absolute error bound must be non-negative.
8196inline internal::FloatingEqMatcher<float> FloatNear(
8197 float rhs, float max_abs_error) {
8198 return internal::FloatingEqMatcher<float>(rhs, false, max_abs_error);
8199}
8200
8201// Creates a matcher that matches any float argument approximately equal to
8202// rhs, up to the specified max absolute error bound, including NaN values when
8203// rhs is NaN. The max absolute error bound must be non-negative.
8204inline internal::FloatingEqMatcher<float> NanSensitiveFloatNear(
8205 float rhs, float max_abs_error) {
8206 return internal::FloatingEqMatcher<float>(rhs, true, max_abs_error);
8207}
8208
8209// Creates a matcher that matches a pointer (raw or smart) that points
8210// to a value that matches inner_matcher.
8211template <typename InnerMatcher>
8212inline internal::PointeeMatcher<InnerMatcher> Pointee(
8213 const InnerMatcher& inner_matcher) {
8214 return internal::PointeeMatcher<InnerMatcher>(inner_matcher);
8215}
8216
8217// Creates a matcher that matches an object whose given field matches
8218// 'matcher'. For example,
8219// Field(&Foo::number, Ge(5))
8220// matches a Foo object x iff x.number >= 5.
8221template <typename Class, typename FieldType, typename FieldMatcher>
8222inline PolymorphicMatcher<
8223 internal::FieldMatcher<Class, FieldType> > Field(
8224 FieldType Class::*field, const FieldMatcher& matcher) {
8225 return MakePolymorphicMatcher(
8226 internal::FieldMatcher<Class, FieldType>(
8227 field, MatcherCast<const FieldType&>(matcher)));
8228 // The call to MatcherCast() is required for supporting inner
8229 // matchers of compatible types. For example, it allows
8230 // Field(&Foo::bar, m)
8231 // to compile where bar is an int32 and m is a matcher for int64.
8232}
8233
8234// Creates a matcher that matches an object whose given property
8235// matches 'matcher'. For example,
8236// Property(&Foo::str, StartsWith("hi"))
8237// matches a Foo object x iff x.str() starts with "hi".
8238template <typename Class, typename PropertyType, typename PropertyMatcher>
8239inline PolymorphicMatcher<
8240 internal::PropertyMatcher<Class, PropertyType> > Property(
8241 PropertyType (Class::*property)() const, const PropertyMatcher& matcher) {
8242 return MakePolymorphicMatcher(
8243 internal::PropertyMatcher<Class, PropertyType>(
8244 property,
8245 MatcherCast<GTEST_REFERENCE_TO_CONST_(PropertyType)>(matcher)));
8246 // The call to MatcherCast() is required for supporting inner
8247 // matchers of compatible types. For example, it allows
8248 // Property(&Foo::bar, m)
8249 // to compile where bar() returns an int32 and m is a matcher for int64.
8250}
8251
8252// Creates a matcher that matches an object iff the result of applying
8253// a callable to x matches 'matcher'.
8254// For example,
8255// ResultOf(f, StartsWith("hi"))
8256// matches a Foo object x iff f(x) starts with "hi".
8257// callable parameter can be a function, function pointer, or a functor.
8258// Callable has to satisfy the following conditions:
8259// * It is required to keep no state affecting the results of
8260// the calls on it and make no assumptions about how many calls
8261// will be made. Any state it keeps must be protected from the
8262// concurrent access.
8263// * If it is a function object, it has to define type result_type.
8264// We recommend deriving your functor classes from std::unary_function.
8265template <typename Callable, typename ResultOfMatcher>
8266internal::ResultOfMatcher<Callable> ResultOf(
8267 Callable callable, const ResultOfMatcher& matcher) {
8268 return internal::ResultOfMatcher<Callable>(
8269 callable,
8270 MatcherCast<typename internal::CallableTraits<Callable>::ResultType>(
8271 matcher));
8272 // The call to MatcherCast() is required for supporting inner
8273 // matchers of compatible types. For example, it allows
8274 // ResultOf(Function, m)
8275 // to compile where Function() returns an int32 and m is a matcher for int64.
8276}
8277
8278// String matchers.
8279
8280// Matches a string equal to str.
8281inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> >
8282 StrEq(const internal::string& str) {
8283 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>(
8284 str, true, true));
8285}
8286
8287// Matches a string not equal to str.
8288inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> >
8289 StrNe(const internal::string& str) {
8290 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>(
8291 str, false, true));
8292}
8293
8294// Matches a string equal to str, ignoring case.
8295inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> >
8296 StrCaseEq(const internal::string& str) {
8297 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>(
8298 str, true, false));
8299}
8300
8301// Matches a string not equal to str, ignoring case.
8302inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> >
8303 StrCaseNe(const internal::string& str) {
8304 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>(
8305 str, false, false));
8306}
8307
8308// Creates a matcher that matches any string, std::string, or C string
8309// that contains the given substring.
8310inline PolymorphicMatcher<internal::HasSubstrMatcher<internal::string> >
8311 HasSubstr(const internal::string& substring) {
8312 return MakePolymorphicMatcher(internal::HasSubstrMatcher<internal::string>(
8313 substring));
8314}
8315
8316// Matches a string that starts with 'prefix' (case-sensitive).
8317inline PolymorphicMatcher<internal::StartsWithMatcher<internal::string> >
8318 StartsWith(const internal::string& prefix) {
8319 return MakePolymorphicMatcher(internal::StartsWithMatcher<internal::string>(
8320 prefix));
8321}
8322
8323// Matches a string that ends with 'suffix' (case-sensitive).
8324inline PolymorphicMatcher<internal::EndsWithMatcher<internal::string> >
8325 EndsWith(const internal::string& suffix) {
8326 return MakePolymorphicMatcher(internal::EndsWithMatcher<internal::string>(
8327 suffix));
8328}
8329
8330// Matches a string that fully matches regular expression 'regex'.
8331// The matcher takes ownership of 'regex'.
8332inline PolymorphicMatcher<internal::MatchesRegexMatcher> MatchesRegex(
8333 const internal::RE* regex) {
8334 return MakePolymorphicMatcher(internal::MatchesRegexMatcher(regex, true));
8335}
8336inline PolymorphicMatcher<internal::MatchesRegexMatcher> MatchesRegex(
8337 const internal::string& regex) {
8338 return MatchesRegex(new internal::RE(regex));
8339}
8340
8341// Matches a string that contains regular expression 'regex'.
8342// The matcher takes ownership of 'regex'.
8343inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex(
8344 const internal::RE* regex) {
8345 return MakePolymorphicMatcher(internal::MatchesRegexMatcher(regex, false));
8346}
8347inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex(
8348 const internal::string& regex) {
8349 return ContainsRegex(new internal::RE(regex));
8350}
8351
8352#if GTEST_HAS_GLOBAL_WSTRING || GTEST_HAS_STD_WSTRING
8353// Wide string matchers.
8354
8355// Matches a string equal to str.
8356inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> >
8357 StrEq(const internal::wstring& str) {
8358 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstring>(
8359 str, true, true));
8360}
8361
8362// Matches a string not equal to str.
8363inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> >
8364 StrNe(const internal::wstring& str) {
8365 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstring>(
8366 str, false, true));
8367}
8368
8369// Matches a string equal to str, ignoring case.
8370inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> >
8371 StrCaseEq(const internal::wstring& str) {
8372 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstring>(
8373 str, true, false));
8374}
8375
8376// Matches a string not equal to str, ignoring case.
8377inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> >
8378 StrCaseNe(const internal::wstring& str) {
8379 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstring>(
8380 str, false, false));
8381}
8382
8383// Creates a matcher that matches any wstring, std::wstring, or C wide string
8384// that contains the given substring.
8385inline PolymorphicMatcher<internal::HasSubstrMatcher<internal::wstring> >
8386 HasSubstr(const internal::wstring& substring) {
8387 return MakePolymorphicMatcher(internal::HasSubstrMatcher<internal::wstring>(
8388 substring));
8389}
8390
8391// Matches a string that starts with 'prefix' (case-sensitive).
8392inline PolymorphicMatcher<internal::StartsWithMatcher<internal::wstring> >
8393 StartsWith(const internal::wstring& prefix) {
8394 return MakePolymorphicMatcher(internal::StartsWithMatcher<internal::wstring>(
8395 prefix));
8396}
8397
8398// Matches a string that ends with 'suffix' (case-sensitive).
8399inline PolymorphicMatcher<internal::EndsWithMatcher<internal::wstring> >
8400 EndsWith(const internal::wstring& suffix) {
8401 return MakePolymorphicMatcher(internal::EndsWithMatcher<internal::wstring>(
8402 suffix));
8403}
8404
8405#endif // GTEST_HAS_GLOBAL_WSTRING || GTEST_HAS_STD_WSTRING
8406
8407// Creates a polymorphic matcher that matches a 2-tuple where the
8408// first field == the second field.
8409inline internal::Eq2Matcher Eq() { return internal::Eq2Matcher(); }
8410
8411// Creates a polymorphic matcher that matches a 2-tuple where the
8412// first field >= the second field.
8413inline internal::Ge2Matcher Ge() { return internal::Ge2Matcher(); }
8414
8415// Creates a polymorphic matcher that matches a 2-tuple where the
8416// first field > the second field.
8417inline internal::Gt2Matcher Gt() { return internal::Gt2Matcher(); }
8418
8419// Creates a polymorphic matcher that matches a 2-tuple where the
8420// first field <= the second field.
8421inline internal::Le2Matcher Le() { return internal::Le2Matcher(); }
8422
8423// Creates a polymorphic matcher that matches a 2-tuple where the
8424// first field < the second field.
8425inline internal::Lt2Matcher Lt() { return internal::Lt2Matcher(); }
8426
8427// Creates a polymorphic matcher that matches a 2-tuple where the
8428// first field != the second field.
8429inline internal::Ne2Matcher Ne() { return internal::Ne2Matcher(); }
8430
8431// Creates a matcher that matches any value of type T that m doesn't
8432// match.
8433template <typename InnerMatcher>
8434inline internal::NotMatcher<InnerMatcher> Not(InnerMatcher m) {
8435 return internal::NotMatcher<InnerMatcher>(m);
8436}
8437
8438// Returns a matcher that matches anything that satisfies the given
8439// predicate. The predicate can be any unary function or functor
8440// whose return type can be implicitly converted to bool.
8441template <typename Predicate>
8442inline PolymorphicMatcher<internal::TrulyMatcher<Predicate> >
8443Truly(Predicate pred) {
8444 return MakePolymorphicMatcher(internal::TrulyMatcher<Predicate>(pred));
8445}
8446
8447// Returns a matcher that matches the container size. The container must
8448// support both size() and size_type which all STL-like containers provide.
8449// Note that the parameter 'size' can be a value of type size_type as well as
8450// matcher. For instance:
8451// EXPECT_THAT(container, SizeIs(2)); // Checks container has 2 elements.
8452// EXPECT_THAT(container, SizeIs(Le(2)); // Checks container has at most 2.
8453template <typename SizeMatcher>
8454inline internal::SizeIsMatcher<SizeMatcher>
8455SizeIs(const SizeMatcher& size_matcher) {
8456 return internal::SizeIsMatcher<SizeMatcher>(size_matcher);
8457}
8458
8459// Returns a matcher that matches an equal container.
8460// This matcher behaves like Eq(), but in the event of mismatch lists the
8461// values that are included in one container but not the other. (Duplicate
8462// values and order differences are not explained.)
8463template <typename Container>
8464inline PolymorphicMatcher<internal::ContainerEqMatcher< // NOLINT
8465 GTEST_REMOVE_CONST_(Container)> >
8466 ContainerEq(const Container& rhs) {
8467 // This following line is for working around a bug in MSVC 8.0,
8468 // which causes Container to be a const type sometimes.
8469 typedef GTEST_REMOVE_CONST_(Container) RawContainer;
8470 return MakePolymorphicMatcher(
8471 internal::ContainerEqMatcher<RawContainer>(rhs));
8472}
8473
8474// Returns a matcher that matches a container that, when sorted using
8475// the given comparator, matches container_matcher.
8476template <typename Comparator, typename ContainerMatcher>
8477inline internal::WhenSortedByMatcher<Comparator, ContainerMatcher>
8478WhenSortedBy(const Comparator& comparator,
8479 const ContainerMatcher& container_matcher) {
8480 return internal::WhenSortedByMatcher<Comparator, ContainerMatcher>(
8481 comparator, container_matcher);
8482}
8483
8484// Returns a matcher that matches a container that, when sorted using
8485// the < operator, matches container_matcher.
8486template <typename ContainerMatcher>
8487inline internal::WhenSortedByMatcher<internal::LessComparator, ContainerMatcher>
8488WhenSorted(const ContainerMatcher& container_matcher) {
8489 return
8490 internal::WhenSortedByMatcher<internal::LessComparator, ContainerMatcher>(
8491 internal::LessComparator(), container_matcher);
8492}
8493
8494// Matches an STL-style container or a native array that contains the
8495// same number of elements as in rhs, where its i-th element and rhs's
8496// i-th element (as a pair) satisfy the given pair matcher, for all i.
8497// TupleMatcher must be able to be safely cast to Matcher<tuple<const
8498// T1&, const T2&> >, where T1 and T2 are the types of elements in the
8499// LHS container and the RHS container respectively.
8500template <typename TupleMatcher, typename Container>
8501inline internal::PointwiseMatcher<TupleMatcher,
8502 GTEST_REMOVE_CONST_(Container)>
8503Pointwise(const TupleMatcher& tuple_matcher, const Container& rhs) {
8504 // This following line is for working around a bug in MSVC 8.0,
8505 // which causes Container to be a const type sometimes.
8506 typedef GTEST_REMOVE_CONST_(Container) RawContainer;
8507 return internal::PointwiseMatcher<TupleMatcher, RawContainer>(
8508 tuple_matcher, rhs);
8509}
8510
8511// Matches an STL-style container or a native array that contains at
8512// least one element matching the given value or matcher.
8513//
8514// Examples:
8515// ::std::set<int> page_ids;
8516// page_ids.insert(3);
8517// page_ids.insert(1);
8518// EXPECT_THAT(page_ids, Contains(1));
8519// EXPECT_THAT(page_ids, Contains(Gt(2)));
8520// EXPECT_THAT(page_ids, Not(Contains(4)));
8521//
8522// ::std::map<int, size_t> page_lengths;
8523// page_lengths[1] = 100;
8524// EXPECT_THAT(page_lengths,
8525// Contains(::std::pair<const int, size_t>(1, 100)));
8526//
8527// const char* user_ids[] = { "joe", "mike", "tom" };
8528// EXPECT_THAT(user_ids, Contains(Eq(::std::string("tom"))));
8529template <typename M>
8530inline internal::ContainsMatcher<M> Contains(M matcher) {
8531 return internal::ContainsMatcher<M>(matcher);
8532}
8533
8534// Matches an STL-style container or a native array that contains only
8535// elements matching the given value or matcher.
8536//
8537// Each(m) is semantically equivalent to Not(Contains(Not(m))). Only
8538// the messages are different.
8539//
8540// Examples:
8541// ::std::set<int> page_ids;
8542// // Each(m) matches an empty container, regardless of what m is.
8543// EXPECT_THAT(page_ids, Each(Eq(1)));
8544// EXPECT_THAT(page_ids, Each(Eq(77)));
8545//
8546// page_ids.insert(3);
8547// EXPECT_THAT(page_ids, Each(Gt(0)));
8548// EXPECT_THAT(page_ids, Not(Each(Gt(4))));
8549// page_ids.insert(1);
8550// EXPECT_THAT(page_ids, Not(Each(Lt(2))));
8551//
8552// ::std::map<int, size_t> page_lengths;
8553// page_lengths[1] = 100;
8554// page_lengths[2] = 200;
8555// page_lengths[3] = 300;
8556// EXPECT_THAT(page_lengths, Not(Each(Pair(1, 100))));
8557// EXPECT_THAT(page_lengths, Each(Key(Le(3))));
8558//
8559// const char* user_ids[] = { "joe", "mike", "tom" };
8560// EXPECT_THAT(user_ids, Not(Each(Eq(::std::string("tom")))));
8561template <typename M>
8562inline internal::EachMatcher<M> Each(M matcher) {
8563 return internal::EachMatcher<M>(matcher);
8564}
8565
8566// Key(inner_matcher) matches an std::pair whose 'first' field matches
8567// inner_matcher. For example, Contains(Key(Ge(5))) can be used to match an
8568// std::map that contains at least one element whose key is >= 5.
8569template <typename M>
8570inline internal::KeyMatcher<M> Key(M inner_matcher) {
8571 return internal::KeyMatcher<M>(inner_matcher);
8572}
8573
8574// Pair(first_matcher, second_matcher) matches a std::pair whose 'first' field
8575// matches first_matcher and whose 'second' field matches second_matcher. For
8576// example, EXPECT_THAT(map_type, ElementsAre(Pair(Ge(5), "foo"))) can be used
8577// to match a std::map<int, string> that contains exactly one element whose key
8578// is >= 5 and whose value equals "foo".
8579template <typename FirstMatcher, typename SecondMatcher>
8580inline internal::PairMatcher<FirstMatcher, SecondMatcher>
8581Pair(FirstMatcher first_matcher, SecondMatcher second_matcher) {
8582 return internal::PairMatcher<FirstMatcher, SecondMatcher>(
8583 first_matcher, second_matcher);
8584}
8585
8586// Returns a predicate that is satisfied by anything that matches the
8587// given matcher.
8588template <typename M>
8589inline internal::MatcherAsPredicate<M> Matches(M matcher) {
8590 return internal::MatcherAsPredicate<M>(matcher);
8591}
8592
8593// Returns true iff the value matches the matcher.
8594template <typename T, typename M>
8595inline bool Value(const T& value, M matcher) {
8596 return testing::Matches(matcher)(value);
8597}
8598
8599// Matches the value against the given matcher and explains the match
8600// result to listener.
8601template <typename T, typename M>
8602inline bool ExplainMatchResult(
8603 M matcher, const T& value, MatchResultListener* listener) {
8604 return SafeMatcherCast<const T&>(matcher).MatchAndExplain(value, listener);
8605}
8606
8607#if GTEST_LANG_CXX11
8608// Define variadic matcher versions. They are overloaded in
8609// gmock-generated-matchers.h for the cases supported by pre C++11 compilers.
8610template <typename... Args>
8611inline internal::AllOfMatcher<Args...> AllOf(const Args&... matchers) {
8612 return internal::AllOfMatcher<Args...>(matchers...);
8613}
8614
8615template <typename... Args>
8616inline internal::AnyOfMatcher<Args...> AnyOf(const Args&... matchers) {
8617 return internal::AnyOfMatcher<Args...>(matchers...);
8618}
8619
8620#endif // GTEST_LANG_CXX11
8621
8622// AllArgs(m) is a synonym of m. This is useful in
8623//
8624// EXPECT_CALL(foo, Bar(_, _)).With(AllArgs(Eq()));
8625//
8626// which is easier to read than
8627//
8628// EXPECT_CALL(foo, Bar(_, _)).With(Eq());
8629template <typename InnerMatcher>
8630inline InnerMatcher AllArgs(const InnerMatcher& matcher) { return matcher; }
8631
8632// These macros allow using matchers to check values in Google Test
8633// tests. ASSERT_THAT(value, matcher) and EXPECT_THAT(value, matcher)
8634// succeed iff the value matches the matcher. If the assertion fails,
8635// the value and the description of the matcher will be printed.
8636#define ASSERT_THAT(value, matcher) ASSERT_PRED_FORMAT1(\
8637 ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value)
8638#define EXPECT_THAT(value, matcher) EXPECT_PRED_FORMAT1(\
8639 ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value)
8640
8641} // namespace testing
8642
8643#endif // GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
8644
8645namespace testing {
8646
8647// An abstract handle of an expectation.
8648class Expectation;
8649
8650// A set of expectation handles.
8651class ExpectationSet;
8652
8653// Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION
8654// and MUST NOT BE USED IN USER CODE!!!
8655namespace internal {
8656
8657// Implements a mock function.
8658template <typename F> class FunctionMocker;
8659
8660// Base class for expectations.
8661class ExpectationBase;
8662
8663// Implements an expectation.
8664template <typename F> class TypedExpectation;
8665
8666// Helper class for testing the Expectation class template.
8667class ExpectationTester;
8668
8669// Base class for function mockers.
8670template <typename F> class FunctionMockerBase;
8671
8672// Protects the mock object registry (in class Mock), all function
8673// mockers, and all expectations.
8674//
8675// The reason we don't use more fine-grained protection is: when a
8676// mock function Foo() is called, it needs to consult its expectations
8677// to see which one should be picked. If another thread is allowed to
8678// call a mock function (either Foo() or a different one) at the same
8679// time, it could affect the "retired" attributes of Foo()'s
8680// expectations when InSequence() is used, and thus affect which
8681// expectation gets picked. Therefore, we sequence all mock function
8682// calls to ensure the integrity of the mock objects' states.
8683GTEST_API_ GTEST_DECLARE_STATIC_MUTEX_(g_gmock_mutex);
8684
8685// Untyped base class for ActionResultHolder<R>.
8686class UntypedActionResultHolderBase;
8687
8688// Abstract base class of FunctionMockerBase. This is the
8689// type-agnostic part of the function mocker interface. Its pure
8690// virtual methods are implemented by FunctionMockerBase.
8691class GTEST_API_ UntypedFunctionMockerBase {
8692 public:
8693 UntypedFunctionMockerBase();
8694 virtual ~UntypedFunctionMockerBase();
8695
8696 // Verifies that all expectations on this mock function have been
8697 // satisfied. Reports one or more Google Test non-fatal failures
8698 // and returns false if not.
8699 bool VerifyAndClearExpectationsLocked()
8700 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
8701
8702 // Clears the ON_CALL()s set on this mock function.
8703 virtual void ClearDefaultActionsLocked()
8704 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) = 0;
8705
8706 // In all of the following Untyped* functions, it's the caller's
8707 // responsibility to guarantee the correctness of the arguments'
8708 // types.
8709
8710 // Performs the default action with the given arguments and returns
8711 // the action's result. The call description string will be used in
8712 // the error message to describe the call in the case the default
8713 // action fails.
8714 // L = *
8715 virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction(
8716 const void* untyped_args,
8717 const string& call_description) const = 0;
8718
8719 // Performs the given action with the given arguments and returns
8720 // the action's result.
8721 // L = *
8722 virtual UntypedActionResultHolderBase* UntypedPerformAction(
8723 const void* untyped_action,
8724 const void* untyped_args) const = 0;
8725
8726 // Writes a message that the call is uninteresting (i.e. neither
8727 // explicitly expected nor explicitly unexpected) to the given
8728 // ostream.
8729 virtual void UntypedDescribeUninterestingCall(
8730 const void* untyped_args,
8731 ::std::ostream* os) const
8732 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) = 0;
8733
8734 // Returns the expectation that matches the given function arguments
8735 // (or NULL is there's no match); when a match is found,
8736 // untyped_action is set to point to the action that should be
8737 // performed (or NULL if the action is "do default"), and
8738 // is_excessive is modified to indicate whether the call exceeds the
8739 // expected number.
8740 virtual const ExpectationBase* UntypedFindMatchingExpectation(
8741 const void* untyped_args,
8742 const void** untyped_action, bool* is_excessive,
8743 ::std::ostream* what, ::std::ostream* why)
8744 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) = 0;
8745
8746 // Prints the given function arguments to the ostream.
8747 virtual void UntypedPrintArgs(const void* untyped_args,
8748 ::std::ostream* os) const = 0;
8749
8750 // Sets the mock object this mock method belongs to, and registers
8751 // this information in the global mock registry. Will be called
8752 // whenever an EXPECT_CALL() or ON_CALL() is executed on this mock
8753 // method.
8754 // TODO(wan@google.com): rename to SetAndRegisterOwner().
8755 void RegisterOwner(const void* mock_obj)
8756 GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
8757
8758 // Sets the mock object this mock method belongs to, and sets the
8759 // name of the mock function. Will be called upon each invocation
8760 // of this mock function.
8761 void SetOwnerAndName(const void* mock_obj, const char* name)
8762 GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
8763
8764 // Returns the mock object this mock method belongs to. Must be
8765 // called after RegisterOwner() or SetOwnerAndName() has been
8766 // called.
8767 const void* MockObject() const
8768 GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
8769
8770 // Returns the name of this mock method. Must be called after
8771 // SetOwnerAndName() has been called.
8772 const char* Name() const
8773 GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
8774
8775 // Returns the result of invoking this mock function with the given
8776 // arguments. This function can be safely called from multiple
8777 // threads concurrently. The caller is responsible for deleting the
8778 // result.
8779 const UntypedActionResultHolderBase* UntypedInvokeWith(
8780 const void* untyped_args)
8781 GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
8782
8783 protected:
8784 typedef std::vector<const void*> UntypedOnCallSpecs;
8785
8786 typedef std::vector<internal::linked_ptr<ExpectationBase> >
8787 UntypedExpectations;
8788
8789 // Returns an Expectation object that references and co-owns exp,
8790 // which must be an expectation on this mock function.
8791 Expectation GetHandleOf(ExpectationBase* exp);
8792
8793 // Address of the mock object this mock method belongs to. Only
8794 // valid after this mock method has been called or
8795 // ON_CALL/EXPECT_CALL has been invoked on it.
8796 const void* mock_obj_; // Protected by g_gmock_mutex.
8797
8798 // Name of the function being mocked. Only valid after this mock
8799 // method has been called.
8800 const char* name_; // Protected by g_gmock_mutex.
8801
8802 // All default action specs for this function mocker.
8803 UntypedOnCallSpecs untyped_on_call_specs_;
8804
8805 // All expectations for this function mocker.
8806 UntypedExpectations untyped_expectations_;
8807}; // class UntypedFunctionMockerBase
8808
8809// Untyped base class for OnCallSpec<F>.
8810class UntypedOnCallSpecBase {
8811 public:
8812 // The arguments are the location of the ON_CALL() statement.
8813 UntypedOnCallSpecBase(const char* a_file, int a_line)
8814 : file_(a_file), line_(a_line), last_clause_(kNone) {}
8815
8816 // Where in the source file was the default action spec defined?
8817 const char* file() const { return file_; }
8818 int line() const { return line_; }
8819
8820 protected:
8821 // Gives each clause in the ON_CALL() statement a name.
8822 enum Clause {
8823 // Do not change the order of the enum members! The run-time
8824 // syntax checking relies on it.
8825 kNone,
8826 kWith,
8827 kWillByDefault
8828 };
8829
8830 // Asserts that the ON_CALL() statement has a certain property.
8831 void AssertSpecProperty(bool property, const string& failure_message) const {
8832 Assert(property, file_, line_, failure_message);
8833 }
8834
8835 // Expects that the ON_CALL() statement has a certain property.
8836 void ExpectSpecProperty(bool property, const string& failure_message) const {
8837 Expect(property, file_, line_, failure_message);
8838 }
8839
8840 const char* file_;
8841 int line_;
8842
8843 // The last clause in the ON_CALL() statement as seen so far.
8844 // Initially kNone and changes as the statement is parsed.
8845 Clause last_clause_;
8846}; // class UntypedOnCallSpecBase
8847
8848// This template class implements an ON_CALL spec.
8849template <typename F>
8850class OnCallSpec : public UntypedOnCallSpecBase {
8851 public:
8852 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
8853 typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple;
8854
8855 // Constructs an OnCallSpec object from the information inside
8856 // the parenthesis of an ON_CALL() statement.
8857 OnCallSpec(const char* a_file, int a_line,
8858 const ArgumentMatcherTuple& matchers)
8859 : UntypedOnCallSpecBase(a_file, a_line),
8860 matchers_(matchers),
8861 // By default, extra_matcher_ should match anything. However,
8862 // we cannot initialize it with _ as that triggers a compiler
8863 // bug in Symbian's C++ compiler (cannot decide between two
8864 // overloaded constructors of Matcher<const ArgumentTuple&>).
8865 extra_matcher_(A<const ArgumentTuple&>()) {
8866 }
8867
8868 // Implements the .With() clause.
8869 OnCallSpec& With(const Matcher<const ArgumentTuple&>& m) {
8870 // Makes sure this is called at most once.
8871 ExpectSpecProperty(last_clause_ < kWith,
8872 ".With() cannot appear "
8873 "more than once in an ON_CALL().");
8874 last_clause_ = kWith;
8875
8876 extra_matcher_ = m;
8877 return *this;
8878 }
8879
8880 // Implements the .WillByDefault() clause.
8881 OnCallSpec& WillByDefault(const Action<F>& action) {
8882 ExpectSpecProperty(last_clause_ < kWillByDefault,
8883 ".WillByDefault() must appear "
8884 "exactly once in an ON_CALL().");
8885 last_clause_ = kWillByDefault;
8886
8887 ExpectSpecProperty(!action.IsDoDefault(),
8888 "DoDefault() cannot be used in ON_CALL().");
8889 action_ = action;
8890 return *this;
8891 }
8892
8893 // Returns true iff the given arguments match the matchers.
8894 bool Matches(const ArgumentTuple& args) const {
8895 return TupleMatches(matchers_, args) && extra_matcher_.Matches(args);
8896 }
8897
8898 // Returns the action specified by the user.
8899 const Action<F>& GetAction() const {
8900 AssertSpecProperty(last_clause_ == kWillByDefault,
8901 ".WillByDefault() must appear exactly "
8902 "once in an ON_CALL().");
8903 return action_;
8904 }
8905
8906 private:
8907 // The information in statement
8908 //
8909 // ON_CALL(mock_object, Method(matchers))
8910 // .With(multi-argument-matcher)
8911 // .WillByDefault(action);
8912 //
8913 // is recorded in the data members like this:
8914 //
8915 // source file that contains the statement => file_
8916 // line number of the statement => line_
8917 // matchers => matchers_
8918 // multi-argument-matcher => extra_matcher_
8919 // action => action_
8920 ArgumentMatcherTuple matchers_;
8921 Matcher<const ArgumentTuple&> extra_matcher_;
8922 Action<F> action_;
8923}; // class OnCallSpec
8924
8925// Possible reactions on uninteresting calls.
8926enum CallReaction {
8927 kAllow,
8928 kWarn,
8929 kFail,
8930 kDefault = kWarn // By default, warn about uninteresting calls.
8931};
8932
8933} // namespace internal
8934
8935// Utilities for manipulating mock objects.
8936class GTEST_API_ Mock {
8937 public:
8938 // The following public methods can be called concurrently.
8939
8940 // Tells Google Mock to ignore mock_obj when checking for leaked
8941 // mock objects.
8942 static void AllowLeak(const void* mock_obj)
8943 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
8944
8945 // Verifies and clears all expectations on the given mock object.
8946 // If the expectations aren't satisfied, generates one or more
8947 // Google Test non-fatal failures and returns false.
8948 static bool VerifyAndClearExpectations(void* mock_obj)
8949 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
8950
8951 // Verifies all expectations on the given mock object and clears its
8952 // default actions and expectations. Returns true iff the
8953 // verification was successful.
8954 static bool VerifyAndClear(void* mock_obj)
8955 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
8956
8957 private:
8958 friend class internal::UntypedFunctionMockerBase;
8959
8960 // Needed for a function mocker to register itself (so that we know
8961 // how to clear a mock object).
8962 template <typename F>
8963 friend class internal::FunctionMockerBase;
8964
8965 template <typename M>
8966 friend class NiceMock;
8967
8968 template <typename M>
8969 friend class NaggyMock;
8970
8971 template <typename M>
8972 friend class StrictMock;
8973
8974 // Tells Google Mock to allow uninteresting calls on the given mock
8975 // object.
8976 static void AllowUninterestingCalls(const void* mock_obj)
8977 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
8978
8979 // Tells Google Mock to warn the user about uninteresting calls on
8980 // the given mock object.
8981 static void WarnUninterestingCalls(const void* mock_obj)
8982 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
8983
8984 // Tells Google Mock to fail uninteresting calls on the given mock
8985 // object.
8986 static void FailUninterestingCalls(const void* mock_obj)
8987 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
8988
8989 // Tells Google Mock the given mock object is being destroyed and
8990 // its entry in the call-reaction table should be removed.
8991 static void UnregisterCallReaction(const void* mock_obj)
8992 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
8993
8994 // Returns the reaction Google Mock will have on uninteresting calls
8995 // made on the given mock object.
8996 static internal::CallReaction GetReactionOnUninterestingCalls(
8997 const void* mock_obj)
8998 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
8999
9000 // Verifies that all expectations on the given mock object have been
9001 // satisfied. Reports one or more Google Test non-fatal failures
9002 // and returns false if not.
9003 static bool VerifyAndClearExpectationsLocked(void* mock_obj)
9004 GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex);
9005
9006 // Clears all ON_CALL()s set on the given mock object.
9007 static void ClearDefaultActionsLocked(void* mock_obj)
9008 GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex);
9009
9010 // Registers a mock object and a mock method it owns.
9011 static void Register(
9012 const void* mock_obj,
9013 internal::UntypedFunctionMockerBase* mocker)
9014 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
9015
9016 // Tells Google Mock where in the source code mock_obj is used in an
9017 // ON_CALL or EXPECT_CALL. In case mock_obj is leaked, this
9018 // information helps the user identify which object it is.
9019 static void RegisterUseByOnCallOrExpectCall(
9020 const void* mock_obj, const char* file, int line)
9021 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
9022
9023 // Unregisters a mock method; removes the owning mock object from
9024 // the registry when the last mock method associated with it has
9025 // been unregistered. This is called only in the destructor of
9026 // FunctionMockerBase.
9027 static void UnregisterLocked(internal::UntypedFunctionMockerBase* mocker)
9028 GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex);
9029}; // class Mock
9030
9031// An abstract handle of an expectation. Useful in the .After()
9032// clause of EXPECT_CALL() for setting the (partial) order of
9033// expectations. The syntax:
9034//
9035// Expectation e1 = EXPECT_CALL(...)...;
9036// EXPECT_CALL(...).After(e1)...;
9037//
9038// sets two expectations where the latter can only be matched after
9039// the former has been satisfied.
9040//
9041// Notes:
9042// - This class is copyable and has value semantics.
9043// - Constness is shallow: a const Expectation object itself cannot
9044// be modified, but the mutable methods of the ExpectationBase
9045// object it references can be called via expectation_base().
9046// - The constructors and destructor are defined out-of-line because
9047// the Symbian WINSCW compiler wants to otherwise instantiate them
9048// when it sees this class definition, at which point it doesn't have
9049// ExpectationBase available yet, leading to incorrect destruction
9050// in the linked_ptr (or compilation errors if using a checking
9051// linked_ptr).
9052class GTEST_API_ Expectation {
9053 public:
9054 // Constructs a null object that doesn't reference any expectation.
9055 Expectation();
9056
9057 ~Expectation();
9058
9059 // This single-argument ctor must not be explicit, in order to support the
9060 // Expectation e = EXPECT_CALL(...);
9061 // syntax.
9062 //
9063 // A TypedExpectation object stores its pre-requisites as
9064 // Expectation objects, and needs to call the non-const Retire()
9065 // method on the ExpectationBase objects they reference. Therefore
9066 // Expectation must receive a *non-const* reference to the
9067 // ExpectationBase object.
9068 Expectation(internal::ExpectationBase& exp); // NOLINT
9069
9070 // The compiler-generated copy ctor and operator= work exactly as
9071 // intended, so we don't need to define our own.
9072
9073 // Returns true iff rhs references the same expectation as this object does.
9074 bool operator==(const Expectation& rhs) const {
9075 return expectation_base_ == rhs.expectation_base_;
9076 }
9077
9078 bool operator!=(const Expectation& rhs) const { return !(*this == rhs); }
9079
9080 private:
9081 friend class ExpectationSet;
9082 friend class Sequence;
9083 friend class ::testing::internal::ExpectationBase;
9084 friend class ::testing::internal::UntypedFunctionMockerBase;
9085
9086 template <typename F>
9087 friend class ::testing::internal::FunctionMockerBase;
9088
9089 template <typename F>
9090 friend class ::testing::internal::TypedExpectation;
9091
9092 // This comparator is needed for putting Expectation objects into a set.
9093 class Less {
9094 public:
9095 bool operator()(const Expectation& lhs, const Expectation& rhs) const {
9096 return lhs.expectation_base_.get() < rhs.expectation_base_.get();
9097 }
9098 };
9099
9100 typedef ::std::set<Expectation, Less> Set;
9101
9102 Expectation(
9103 const internal::linked_ptr<internal::ExpectationBase>& expectation_base);
9104
9105 // Returns the expectation this object references.
9106 const internal::linked_ptr<internal::ExpectationBase>&
9107 expectation_base() const {
9108 return expectation_base_;
9109 }
9110
9111 // A linked_ptr that co-owns the expectation this handle references.
9112 internal::linked_ptr<internal::ExpectationBase> expectation_base_;
9113};
9114
9115// A set of expectation handles. Useful in the .After() clause of
9116// EXPECT_CALL() for setting the (partial) order of expectations. The
9117// syntax:
9118//
9119// ExpectationSet es;
9120// es += EXPECT_CALL(...)...;
9121// es += EXPECT_CALL(...)...;
9122// EXPECT_CALL(...).After(es)...;
9123//
9124// sets three expectations where the last one can only be matched
9125// after the first two have both been satisfied.
9126//
9127// This class is copyable and has value semantics.
9128class ExpectationSet {
9129 public:
9130 // A bidirectional iterator that can read a const element in the set.
9131 typedef Expectation::Set::const_iterator const_iterator;
9132
9133 // An object stored in the set. This is an alias of Expectation.
9134 typedef Expectation::Set::value_type value_type;
9135
9136 // Constructs an empty set.
9137 ExpectationSet() {}
9138
9139 // This single-argument ctor must not be explicit, in order to support the
9140 // ExpectationSet es = EXPECT_CALL(...);
9141 // syntax.
9142 ExpectationSet(internal::ExpectationBase& exp) { // NOLINT
9143 *this += Expectation(exp);
9144 }
9145
9146 // This single-argument ctor implements implicit conversion from
9147 // Expectation and thus must not be explicit. This allows either an
9148 // Expectation or an ExpectationSet to be used in .After().
9149 ExpectationSet(const Expectation& e) { // NOLINT
9150 *this += e;
9151 }
9152
9153 // The compiler-generator ctor and operator= works exactly as
9154 // intended, so we don't need to define our own.
9155
9156 // Returns true iff rhs contains the same set of Expectation objects
9157 // as this does.
9158 bool operator==(const ExpectationSet& rhs) const {
9159 return expectations_ == rhs.expectations_;
9160 }
9161
9162 bool operator!=(const ExpectationSet& rhs) const { return !(*this == rhs); }
9163
9164 // Implements the syntax
9165 // expectation_set += EXPECT_CALL(...);
9166 ExpectationSet& operator+=(const Expectation& e) {
9167 expectations_.insert(e);
9168 return *this;
9169 }
9170
9171 int size() const { return static_cast<int>(expectations_.size()); }
9172
9173 const_iterator begin() const { return expectations_.begin(); }
9174 const_iterator end() const { return expectations_.end(); }
9175
9176 private:
9177 Expectation::Set expectations_;
9178};
9179
9180
9181// Sequence objects are used by a user to specify the relative order
9182// in which the expectations should match. They are copyable (we rely
9183// on the compiler-defined copy constructor and assignment operator).
9184class GTEST_API_ Sequence {
9185 public:
9186 // Constructs an empty sequence.
9187 Sequence() : last_expectation_(new Expectation) {}
9188
9189 // Adds an expectation to this sequence. The caller must ensure
9190 // that no other thread is accessing this Sequence object.
9191 void AddExpectation(const Expectation& expectation) const;
9192
9193 private:
9194 // The last expectation in this sequence. We use a linked_ptr here
9195 // because Sequence objects are copyable and we want the copies to
9196 // be aliases. The linked_ptr allows the copies to co-own and share
9197 // the same Expectation object.
9198 internal::linked_ptr<Expectation> last_expectation_;
9199}; // class Sequence
9200
9201// An object of this type causes all EXPECT_CALL() statements
9202// encountered in its scope to be put in an anonymous sequence. The
9203// work is done in the constructor and destructor. You should only
9204// create an InSequence object on the stack.
9205//
9206// The sole purpose for this class is to support easy definition of
9207// sequential expectations, e.g.
9208//
9209// {
9210// InSequence dummy; // The name of the object doesn't matter.
9211//
9212// // The following expectations must match in the order they appear.
9213// EXPECT_CALL(a, Bar())...;
9214// EXPECT_CALL(a, Baz())...;
9215// ...
9216// EXPECT_CALL(b, Xyz())...;
9217// }
9218//
9219// You can create InSequence objects in multiple threads, as long as
9220// they are used to affect different mock objects. The idea is that
9221// each thread can create and set up its own mocks as if it's the only
9222// thread. However, for clarity of your tests we recommend you to set
9223// up mocks in the main thread unless you have a good reason not to do
9224// so.
9225class GTEST_API_ InSequence {
9226 public:
9227 InSequence();
9228 ~InSequence();
9229 private:
9230 bool sequence_created_;
9231
9232 GTEST_DISALLOW_COPY_AND_ASSIGN_(InSequence); // NOLINT
9233} GTEST_ATTRIBUTE_UNUSED_;
9234
9235namespace internal {
9236
9237// Points to the implicit sequence introduced by a living InSequence
9238// object (if any) in the current thread or NULL.
9239GTEST_API_ extern ThreadLocal<Sequence*> g_gmock_implicit_sequence;
9240
9241// Base class for implementing expectations.
9242//
9243// There are two reasons for having a type-agnostic base class for
9244// Expectation:
9245//
9246// 1. We need to store collections of expectations of different
9247// types (e.g. all pre-requisites of a particular expectation, all
9248// expectations in a sequence). Therefore these expectation objects
9249// must share a common base class.
9250//
9251// 2. We can avoid binary code bloat by moving methods not depending
9252// on the template argument of Expectation to the base class.
9253//
9254// This class is internal and mustn't be used by user code directly.
9255class GTEST_API_ ExpectationBase {
9256 public:
9257 // source_text is the EXPECT_CALL(...) source that created this Expectation.
9258 ExpectationBase(const char* file, int line, const string& source_text);
9259
9260 virtual ~ExpectationBase();
9261
9262 // Where in the source file was the expectation spec defined?
9263 const char* file() const { return file_; }
9264 int line() const { return line_; }
9265 const char* source_text() const { return source_text_.c_str(); }
9266 // Returns the cardinality specified in the expectation spec.
9267 const Cardinality& cardinality() const { return cardinality_; }
9268
9269 // Describes the source file location of this expectation.
9270 void DescribeLocationTo(::std::ostream* os) const {
9271 *os << FormatFileLocation(file(), line()) << " ";
9272 }
9273
9274 // Describes how many times a function call matching this
9275 // expectation has occurred.
9276 void DescribeCallCountTo(::std::ostream* os) const
9277 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
9278
9279 // If this mock method has an extra matcher (i.e. .With(matcher)),
9280 // describes it to the ostream.
9281 virtual void MaybeDescribeExtraMatcherTo(::std::ostream* os) = 0;
9282
9283 protected:
9284 friend class ::testing::Expectation;
9285 friend class UntypedFunctionMockerBase;
9286
9287 enum Clause {
9288 // Don't change the order of the enum members!
9289 kNone,
9290 kWith,
9291 kTimes,
9292 kInSequence,
9293 kAfter,
9294 kWillOnce,
9295 kWillRepeatedly,
9296 kRetiresOnSaturation
9297 };
9298
9299 typedef std::vector<const void*> UntypedActions;
9300
9301 // Returns an Expectation object that references and co-owns this
9302 // expectation.
9303 virtual Expectation GetHandle() = 0;
9304
9305 // Asserts that the EXPECT_CALL() statement has the given property.
9306 void AssertSpecProperty(bool property, const string& failure_message) const {
9307 Assert(property, file_, line_, failure_message);
9308 }
9309
9310 // Expects that the EXPECT_CALL() statement has the given property.
9311 void ExpectSpecProperty(bool property, const string& failure_message) const {
9312 Expect(property, file_, line_, failure_message);
9313 }
9314
9315 // Explicitly specifies the cardinality of this expectation. Used
9316 // by the subclasses to implement the .Times() clause.
9317 void SpecifyCardinality(const Cardinality& cardinality);
9318
9319 // Returns true iff the user specified the cardinality explicitly
9320 // using a .Times().
9321 bool cardinality_specified() const { return cardinality_specified_; }
9322
9323 // Sets the cardinality of this expectation spec.
9324 void set_cardinality(const Cardinality& a_cardinality) {
9325 cardinality_ = a_cardinality;
9326 }
9327
9328 // The following group of methods should only be called after the
9329 // EXPECT_CALL() statement, and only when g_gmock_mutex is held by
9330 // the current thread.
9331
9332 // Retires all pre-requisites of this expectation.
9333 void RetireAllPreRequisites()
9334 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
9335
9336 // Returns true iff this expectation is retired.
9337 bool is_retired() const
9338 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9339 g_gmock_mutex.AssertHeld();
9340 return retired_;
9341 }
9342
9343 // Retires this expectation.
9344 void Retire()
9345 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9346 g_gmock_mutex.AssertHeld();
9347 retired_ = true;
9348 }
9349
9350 // Returns true iff this expectation is satisfied.
9351 bool IsSatisfied() const
9352 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9353 g_gmock_mutex.AssertHeld();
9354 return cardinality().IsSatisfiedByCallCount(call_count_);
9355 }
9356
9357 // Returns true iff this expectation is saturated.
9358 bool IsSaturated() const
9359 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9360 g_gmock_mutex.AssertHeld();
9361 return cardinality().IsSaturatedByCallCount(call_count_);
9362 }
9363
9364 // Returns true iff this expectation is over-saturated.
9365 bool IsOverSaturated() const
9366 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9367 g_gmock_mutex.AssertHeld();
9368 return cardinality().IsOverSaturatedByCallCount(call_count_);
9369 }
9370
9371 // Returns true iff all pre-requisites of this expectation are satisfied.
9372 bool AllPrerequisitesAreSatisfied() const
9373 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
9374
9375 // Adds unsatisfied pre-requisites of this expectation to 'result'.
9376 void FindUnsatisfiedPrerequisites(ExpectationSet* result) const
9377 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
9378
9379 // Returns the number this expectation has been invoked.
9380 int call_count() const
9381 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9382 g_gmock_mutex.AssertHeld();
9383 return call_count_;
9384 }
9385
9386 // Increments the number this expectation has been invoked.
9387 void IncrementCallCount()
9388 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9389 g_gmock_mutex.AssertHeld();
9390 call_count_++;
9391 }
9392
9393 // Checks the action count (i.e. the number of WillOnce() and
9394 // WillRepeatedly() clauses) against the cardinality if this hasn't
9395 // been done before. Prints a warning if there are too many or too
9396 // few actions.
9397 void CheckActionCountIfNotDone() const
9398 GTEST_LOCK_EXCLUDED_(mutex_);
9399
9400 friend class ::testing::Sequence;
9401 friend class ::testing::internal::ExpectationTester;
9402
9403 template <typename Function>
9404 friend class TypedExpectation;
9405
9406 // Implements the .Times() clause.
9407 void UntypedTimes(const Cardinality& a_cardinality);
9408
9409 // This group of fields are part of the spec and won't change after
9410 // an EXPECT_CALL() statement finishes.
9411 const char* file_; // The file that contains the expectation.
9412 int line_; // The line number of the expectation.
9413 const string source_text_; // The EXPECT_CALL(...) source text.
9414 // True iff the cardinality is specified explicitly.
9415 bool cardinality_specified_;
9416 Cardinality cardinality_; // The cardinality of the expectation.
9417 // The immediate pre-requisites (i.e. expectations that must be
9418 // satisfied before this expectation can be matched) of this
9419 // expectation. We use linked_ptr in the set because we want an
9420 // Expectation object to be co-owned by its FunctionMocker and its
9421 // successors. This allows multiple mock objects to be deleted at
9422 // different times.
9423 ExpectationSet immediate_prerequisites_;
9424
9425 // This group of fields are the current state of the expectation,
9426 // and can change as the mock function is called.
9427 int call_count_; // How many times this expectation has been invoked.
9428 bool retired_; // True iff this expectation has retired.
9429 UntypedActions untyped_actions_;
9430 bool extra_matcher_specified_;
9431 bool repeated_action_specified_; // True if a WillRepeatedly() was specified.
9432 bool retires_on_saturation_;
9433 Clause last_clause_;
9434 mutable bool action_count_checked_; // Under mutex_.
9435 mutable Mutex mutex_; // Protects action_count_checked_.
9436
9437 GTEST_DISALLOW_ASSIGN_(ExpectationBase);
9438}; // class ExpectationBase
9439
9440// Impements an expectation for the given function type.
9441template <typename F>
9442class TypedExpectation : public ExpectationBase {
9443 public:
9444 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
9445 typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple;
9446 typedef typename Function<F>::Result Result;
9447
9448 TypedExpectation(FunctionMockerBase<F>* owner,
9449 const char* a_file, int a_line, const string& a_source_text,
9450 const ArgumentMatcherTuple& m)
9451 : ExpectationBase(a_file, a_line, a_source_text),
9452 owner_(owner),
9453 matchers_(m),
9454 // By default, extra_matcher_ should match anything. However,
9455 // we cannot initialize it with _ as that triggers a compiler
9456 // bug in Symbian's C++ compiler (cannot decide between two
9457 // overloaded constructors of Matcher<const ArgumentTuple&>).
9458 extra_matcher_(A<const ArgumentTuple&>()),
9459 repeated_action_(DoDefault()) {}
9460
9461 virtual ~TypedExpectation() {
9462 // Check the validity of the action count if it hasn't been done
9463 // yet (for example, if the expectation was never used).
9464 CheckActionCountIfNotDone();
9465 for (UntypedActions::const_iterator it = untyped_actions_.begin();
9466 it != untyped_actions_.end(); ++it) {
9467 delete static_cast<const Action<F>*>(*it);
9468 }
9469 }
9470
9471 // Implements the .With() clause.
9472 TypedExpectation& With(const Matcher<const ArgumentTuple&>& m) {
9473 if (last_clause_ == kWith) {
9474 ExpectSpecProperty(false,
9475 ".With() cannot appear "
9476 "more than once in an EXPECT_CALL().");
9477 } else {
9478 ExpectSpecProperty(last_clause_ < kWith,
9479 ".With() must be the first "
9480 "clause in an EXPECT_CALL().");
9481 }
9482 last_clause_ = kWith;
9483
9484 extra_matcher_ = m;
9485 extra_matcher_specified_ = true;
9486 return *this;
9487 }
9488
9489 // Implements the .Times() clause.
9490 TypedExpectation& Times(const Cardinality& a_cardinality) {
9491 ExpectationBase::UntypedTimes(a_cardinality);
9492 return *this;
9493 }
9494
9495 // Implements the .Times() clause.
9496 TypedExpectation& Times(int n) {
9497 return Times(Exactly(n));
9498 }
9499
9500 // Implements the .InSequence() clause.
9501 TypedExpectation& InSequence(const Sequence& s) {
9502 ExpectSpecProperty(last_clause_ <= kInSequence,
9503 ".InSequence() cannot appear after .After(),"
9504 " .WillOnce(), .WillRepeatedly(), or "
9505 ".RetiresOnSaturation().");
9506 last_clause_ = kInSequence;
9507
9508 s.AddExpectation(GetHandle());
9509 return *this;
9510 }
9511 TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2) {
9512 return InSequence(s1).InSequence(s2);
9513 }
9514 TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2,
9515 const Sequence& s3) {
9516 return InSequence(s1, s2).InSequence(s3);
9517 }
9518 TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2,
9519 const Sequence& s3, const Sequence& s4) {
9520 return InSequence(s1, s2, s3).InSequence(s4);
9521 }
9522 TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2,
9523 const Sequence& s3, const Sequence& s4,
9524 const Sequence& s5) {
9525 return InSequence(s1, s2, s3, s4).InSequence(s5);
9526 }
9527
9528 // Implements that .After() clause.
9529 TypedExpectation& After(const ExpectationSet& s) {
9530 ExpectSpecProperty(last_clause_ <= kAfter,
9531 ".After() cannot appear after .WillOnce(),"
9532 " .WillRepeatedly(), or "
9533 ".RetiresOnSaturation().");
9534 last_clause_ = kAfter;
9535
9536 for (ExpectationSet::const_iterator it = s.begin(); it != s.end(); ++it) {
9537 immediate_prerequisites_ += *it;
9538 }
9539 return *this;
9540 }
9541 TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2) {
9542 return After(s1).After(s2);
9543 }
9544 TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2,
9545 const ExpectationSet& s3) {
9546 return After(s1, s2).After(s3);
9547 }
9548 TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2,
9549 const ExpectationSet& s3, const ExpectationSet& s4) {
9550 return After(s1, s2, s3).After(s4);
9551 }
9552 TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2,
9553 const ExpectationSet& s3, const ExpectationSet& s4,
9554 const ExpectationSet& s5) {
9555 return After(s1, s2, s3, s4).After(s5);
9556 }
9557
9558 // Implements the .WillOnce() clause.
9559 TypedExpectation& WillOnce(const Action<F>& action) {
9560 ExpectSpecProperty(last_clause_ <= kWillOnce,
9561 ".WillOnce() cannot appear after "
9562 ".WillRepeatedly() or .RetiresOnSaturation().");
9563 last_clause_ = kWillOnce;
9564
9565 untyped_actions_.push_back(new Action<F>(action));
9566 if (!cardinality_specified()) {
9567 set_cardinality(Exactly(static_cast<int>(untyped_actions_.size())));
9568 }
9569 return *this;
9570 }
9571
9572 // Implements the .WillRepeatedly() clause.
9573 TypedExpectation& WillRepeatedly(const Action<F>& action) {
9574 if (last_clause_ == kWillRepeatedly) {
9575 ExpectSpecProperty(false,
9576 ".WillRepeatedly() cannot appear "
9577 "more than once in an EXPECT_CALL().");
9578 } else {
9579 ExpectSpecProperty(last_clause_ < kWillRepeatedly,
9580 ".WillRepeatedly() cannot appear "
9581 "after .RetiresOnSaturation().");
9582 }
9583 last_clause_ = kWillRepeatedly;
9584 repeated_action_specified_ = true;
9585
9586 repeated_action_ = action;
9587 if (!cardinality_specified()) {
9588 set_cardinality(AtLeast(static_cast<int>(untyped_actions_.size())));
9589 }
9590
9591 // Now that no more action clauses can be specified, we check
9592 // whether their count makes sense.
9593 CheckActionCountIfNotDone();
9594 return *this;
9595 }
9596
9597 // Implements the .RetiresOnSaturation() clause.
9598 TypedExpectation& RetiresOnSaturation() {
9599 ExpectSpecProperty(last_clause_ < kRetiresOnSaturation,
9600 ".RetiresOnSaturation() cannot appear "
9601 "more than once.");
9602 last_clause_ = kRetiresOnSaturation;
9603 retires_on_saturation_ = true;
9604
9605 // Now that no more action clauses can be specified, we check
9606 // whether their count makes sense.
9607 CheckActionCountIfNotDone();
9608 return *this;
9609 }
9610
9611 // Returns the matchers for the arguments as specified inside the
9612 // EXPECT_CALL() macro.
9613 const ArgumentMatcherTuple& matchers() const {
9614 return matchers_;
9615 }
9616
9617 // Returns the matcher specified by the .With() clause.
9618 const Matcher<const ArgumentTuple&>& extra_matcher() const {
9619 return extra_matcher_;
9620 }
9621
9622 // Returns the action specified by the .WillRepeatedly() clause.
9623 const Action<F>& repeated_action() const { return repeated_action_; }
9624
9625 // If this mock method has an extra matcher (i.e. .With(matcher)),
9626 // describes it to the ostream.
9627 virtual void MaybeDescribeExtraMatcherTo(::std::ostream* os) {
9628 if (extra_matcher_specified_) {
9629 *os << " Expected args: ";
9630 extra_matcher_.DescribeTo(os);
9631 *os << "\n";
9632 }
9633 }
9634
9635 private:
9636 template <typename Function>
9637 friend class FunctionMockerBase;
9638
9639 // Returns an Expectation object that references and co-owns this
9640 // expectation.
9641 virtual Expectation GetHandle() {
9642 return owner_->GetHandleOf(this);
9643 }
9644
9645 // The following methods will be called only after the EXPECT_CALL()
9646 // statement finishes and when the current thread holds
9647 // g_gmock_mutex.
9648
9649 // Returns true iff this expectation matches the given arguments.
9650 bool Matches(const ArgumentTuple& args) const
9651 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9652 g_gmock_mutex.AssertHeld();
9653 return TupleMatches(matchers_, args) && extra_matcher_.Matches(args);
9654 }
9655
9656 // Returns true iff this expectation should handle the given arguments.
9657 bool ShouldHandleArguments(const ArgumentTuple& args) const
9658 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9659 g_gmock_mutex.AssertHeld();
9660
9661 // In case the action count wasn't checked when the expectation
9662 // was defined (e.g. if this expectation has no WillRepeatedly()
9663 // or RetiresOnSaturation() clause), we check it when the
9664 // expectation is used for the first time.
9665 CheckActionCountIfNotDone();
9666 return !is_retired() && AllPrerequisitesAreSatisfied() && Matches(args);
9667 }
9668
9669 // Describes the result of matching the arguments against this
9670 // expectation to the given ostream.
9671 void ExplainMatchResultTo(
9672 const ArgumentTuple& args,
9673 ::std::ostream* os) const
9674 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9675 g_gmock_mutex.AssertHeld();
9676
9677 if (is_retired()) {
9678 *os << " Expected: the expectation is active\n"
9679 << " Actual: it is retired\n";
9680 } else if (!Matches(args)) {
9681 if (!TupleMatches(matchers_, args)) {
9682 ExplainMatchFailureTupleTo(matchers_, args, os);
9683 }
9684 StringMatchResultListener listener;
9685 if (!extra_matcher_.MatchAndExplain(args, &listener)) {
9686 *os << " Expected args: ";
9687 extra_matcher_.DescribeTo(os);
9688 *os << "\n Actual: don't match";
9689
9690 internal::PrintIfNotEmpty(listener.str(), os);
9691 *os << "\n";
9692 }
9693 } else if (!AllPrerequisitesAreSatisfied()) {
9694 *os << " Expected: all pre-requisites are satisfied\n"
9695 << " Actual: the following immediate pre-requisites "
9696 << "are not satisfied:\n";
9697 ExpectationSet unsatisfied_prereqs;
9698 FindUnsatisfiedPrerequisites(&unsatisfied_prereqs);
9699 int i = 0;
9700 for (ExpectationSet::const_iterator it = unsatisfied_prereqs.begin();
9701 it != unsatisfied_prereqs.end(); ++it) {
9702 it->expectation_base()->DescribeLocationTo(os);
9703 *os << "pre-requisite #" << i++ << "\n";
9704 }
9705 *os << " (end of pre-requisites)\n";
9706 } else {
9707 // This line is here just for completeness' sake. It will never
9708 // be executed as currently the ExplainMatchResultTo() function
9709 // is called only when the mock function call does NOT match the
9710 // expectation.
9711 *os << "The call matches the expectation.\n";
9712 }
9713 }
9714
9715 // Returns the action that should be taken for the current invocation.
9716 const Action<F>& GetCurrentAction(
9717 const FunctionMockerBase<F>* mocker,
9718 const ArgumentTuple& args) const
9719 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9720 g_gmock_mutex.AssertHeld();
9721 const int count = call_count();
9722 Assert(count >= 1, __FILE__, __LINE__,
9723 "call_count() is <= 0 when GetCurrentAction() is "
9724 "called - this should never happen.");
9725
9726 const int action_count = static_cast<int>(untyped_actions_.size());
9727 if (action_count > 0 && !repeated_action_specified_ &&
9728 count > action_count) {
9729 // If there is at least one WillOnce() and no WillRepeatedly(),
9730 // we warn the user when the WillOnce() clauses ran out.
9731 ::std::stringstream ss;
9732 DescribeLocationTo(&ss);
9733 ss << "Actions ran out in " << source_text() << "...\n"
9734 << "Called " << count << " times, but only "
9735 << action_count << " WillOnce()"
9736 << (action_count == 1 ? " is" : "s are") << " specified - ";
9737 mocker->DescribeDefaultActionTo(args, &ss);
9738 Log(kWarning, ss.str(), 1);
9739 }
9740
9741 return count <= action_count ?
9742 *static_cast<const Action<F>*>(untyped_actions_[count - 1]) :
9743 repeated_action();
9744 }
9745
9746 // Given the arguments of a mock function call, if the call will
9747 // over-saturate this expectation, returns the default action;
9748 // otherwise, returns the next action in this expectation. Also
9749 // describes *what* happened to 'what', and explains *why* Google
9750 // Mock does it to 'why'. This method is not const as it calls
9751 // IncrementCallCount(). A return value of NULL means the default
9752 // action.
9753 const Action<F>* GetActionForArguments(
9754 const FunctionMockerBase<F>* mocker,
9755 const ArgumentTuple& args,
9756 ::std::ostream* what,
9757 ::std::ostream* why)
9758 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9759 g_gmock_mutex.AssertHeld();
9760 if (IsSaturated()) {
9761 // We have an excessive call.
9762 IncrementCallCount();
9763 *what << "Mock function called more times than expected - ";
9764 mocker->DescribeDefaultActionTo(args, what);
9765 DescribeCallCountTo(why);
9766
9767 // TODO(wan@google.com): allow the user to control whether
9768 // unexpected calls should fail immediately or continue using a
9769 // flag --gmock_unexpected_calls_are_fatal.
9770 return NULL;
9771 }
9772
9773 IncrementCallCount();
9774 RetireAllPreRequisites();
9775
9776 if (retires_on_saturation_ && IsSaturated()) {
9777 Retire();
9778 }
9779
9780 // Must be done after IncrementCount()!
9781 *what << "Mock function call matches " << source_text() <<"...\n";
9782 return &(GetCurrentAction(mocker, args));
9783 }
9784
9785 // All the fields below won't change once the EXPECT_CALL()
9786 // statement finishes.
9787 FunctionMockerBase<F>* const owner_;
9788 ArgumentMatcherTuple matchers_;
9789 Matcher<const ArgumentTuple&> extra_matcher_;
9790 Action<F> repeated_action_;
9791
9792 GTEST_DISALLOW_COPY_AND_ASSIGN_(TypedExpectation);
9793}; // class TypedExpectation
9794
9795// A MockSpec object is used by ON_CALL() or EXPECT_CALL() for
9796// specifying the default behavior of, or expectation on, a mock
9797// function.
9798
9799// Note: class MockSpec really belongs to the ::testing namespace.
9800// However if we define it in ::testing, MSVC will complain when
9801// classes in ::testing::internal declare it as a friend class
9802// template. To workaround this compiler bug, we define MockSpec in
9803// ::testing::internal and import it into ::testing.
9804
9805// Logs a message including file and line number information.
9806GTEST_API_ void LogWithLocation(testing::internal::LogSeverity severity,
9807 const char* file, int line,
9808 const string& message);
9809
9810template <typename F>
9811class MockSpec {
9812 public:
9813 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
9814 typedef typename internal::Function<F>::ArgumentMatcherTuple
9815 ArgumentMatcherTuple;
9816
9817 // Constructs a MockSpec object, given the function mocker object
9818 // that the spec is associated with.
9819 explicit MockSpec(internal::FunctionMockerBase<F>* function_mocker)
9820 : function_mocker_(function_mocker) {}
9821
9822 // Adds a new default action spec to the function mocker and returns
9823 // the newly created spec.
9824 internal::OnCallSpec<F>& InternalDefaultActionSetAt(
9825 const char* file, int line, const char* obj, const char* call) {
9826 LogWithLocation(internal::kInfo, file, line,
9827 string("ON_CALL(") + obj + ", " + call + ") invoked");
9828 return function_mocker_->AddNewOnCallSpec(file, line, matchers_);
9829 }
9830
9831 // Adds a new expectation spec to the function mocker and returns
9832 // the newly created spec.
9833 internal::TypedExpectation<F>& InternalExpectedAt(
9834 const char* file, int line, const char* obj, const char* call) {
9835 const string source_text(string("EXPECT_CALL(") + obj + ", " + call + ")");
9836 LogWithLocation(internal::kInfo, file, line, source_text + " invoked");
9837 return function_mocker_->AddNewExpectation(
9838 file, line, source_text, matchers_);
9839 }
9840
9841 private:
9842 template <typename Function>
9843 friend class internal::FunctionMocker;
9844
9845 void SetMatchers(const ArgumentMatcherTuple& matchers) {
9846 matchers_ = matchers;
9847 }
9848
9849 // The function mocker that owns this spec.
9850 internal::FunctionMockerBase<F>* const function_mocker_;
9851 // The argument matchers specified in the spec.
9852 ArgumentMatcherTuple matchers_;
9853
9854 GTEST_DISALLOW_ASSIGN_(MockSpec);
9855}; // class MockSpec
9856
9857// MSVC warns about using 'this' in base member initializer list, so
9858// we need to temporarily disable the warning. We have to do it for
9859// the entire class to suppress the warning, even though it's about
9860// the constructor only.
9861
9862#ifdef _MSC_VER
9863# pragma warning(push) // Saves the current warning state.
9864# pragma warning(disable:4355) // Temporarily disables warning 4355.
9865#endif // _MSV_VER
9866
9867// C++ treats the void type specially. For example, you cannot define
9868// a void-typed variable or pass a void value to a function.
9869// ActionResultHolder<T> holds a value of type T, where T must be a
9870// copyable type or void (T doesn't need to be default-constructable).
9871// It hides the syntactic difference between void and other types, and
9872// is used to unify the code for invoking both void-returning and
9873// non-void-returning mock functions.
9874
9875// Untyped base class for ActionResultHolder<T>.
9876class UntypedActionResultHolderBase {
9877 public:
9878 virtual ~UntypedActionResultHolderBase() {}
9879
9880 // Prints the held value as an action's result to os.
9881 virtual void PrintAsActionResult(::std::ostream* os) const = 0;
9882};
9883
9884// This generic definition is used when T is not void.
9885template <typename T>
9886class ActionResultHolder : public UntypedActionResultHolderBase {
9887 public:
9888 explicit ActionResultHolder(T a_value) : value_(a_value) {}
9889
9890 // The compiler-generated copy constructor and assignment operator
9891 // are exactly what we need, so we don't need to define them.
9892
9893 // Returns the held value and deletes this object.
9894 T GetValueAndDelete() const {
9895 T retval(value_);
9896 delete this;
9897 return retval;
9898 }
9899
9900 // Prints the held value as an action's result to os.
9901 virtual void PrintAsActionResult(::std::ostream* os) const {
9902 *os << "\n Returns: ";
9903 // T may be a reference type, so we don't use UniversalPrint().
9904 UniversalPrinter<T>::Print(value_, os);
9905 }
9906
9907 // Performs the given mock function's default action and returns the
9908 // result in a new-ed ActionResultHolder.
9909 template <typename F>
9910 static ActionResultHolder* PerformDefaultAction(
9911 const FunctionMockerBase<F>* func_mocker,
9912 const typename Function<F>::ArgumentTuple& args,
9913 const string& call_description) {
9914 return new ActionResultHolder(
9915 func_mocker->PerformDefaultAction(args, call_description));
9916 }
9917
9918 // Performs the given action and returns the result in a new-ed
9919 // ActionResultHolder.
9920 template <typename F>
9921 static ActionResultHolder*
9922 PerformAction(const Action<F>& action,
9923 const typename Function<F>::ArgumentTuple& args) {
9924 return new ActionResultHolder(action.Perform(args));
9925 }
9926
9927 private:
9928 T value_;
9929
9930 // T could be a reference type, so = isn't supported.
9931 GTEST_DISALLOW_ASSIGN_(ActionResultHolder);
9932};
9933
9934// Specialization for T = void.
9935template <>
9936class ActionResultHolder<void> : public UntypedActionResultHolderBase {
9937 public:
9938 void GetValueAndDelete() const { delete this; }
9939
9940 virtual void PrintAsActionResult(::std::ostream* /* os */) const {}
9941
9942 // Performs the given mock function's default action and returns NULL;
9943 template <typename F>
9944 static ActionResultHolder* PerformDefaultAction(
9945 const FunctionMockerBase<F>* func_mocker,
9946 const typename Function<F>::ArgumentTuple& args,
9947 const string& call_description) {
9948 func_mocker->PerformDefaultAction(args, call_description);
9949 return NULL;
9950 }
9951
9952 // Performs the given action and returns NULL.
9953 template <typename F>
9954 static ActionResultHolder* PerformAction(
9955 const Action<F>& action,
9956 const typename Function<F>::ArgumentTuple& args) {
9957 action.Perform(args);
9958 return NULL;
9959 }
9960};
9961
9962// The base of the function mocker class for the given function type.
9963// We put the methods in this class instead of its child to avoid code
9964// bloat.
9965template <typename F>
9966class FunctionMockerBase : public UntypedFunctionMockerBase {
9967 public:
9968 typedef typename Function<F>::Result Result;
9969 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
9970 typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple;
9971
9972 FunctionMockerBase() : current_spec_(this) {}
9973
9974 // The destructor verifies that all expectations on this mock
9975 // function have been satisfied. If not, it will report Google Test
9976 // non-fatal failures for the violations.
9977 virtual ~FunctionMockerBase()
9978 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
9979 MutexLock l(&g_gmock_mutex);
9980 VerifyAndClearExpectationsLocked();
9981 Mock::UnregisterLocked(this);
9982 ClearDefaultActionsLocked();
9983 }
9984
9985 // Returns the ON_CALL spec that matches this mock function with the
9986 // given arguments; returns NULL if no matching ON_CALL is found.
9987 // L = *
9988 const OnCallSpec<F>* FindOnCallSpec(
9989 const ArgumentTuple& args) const {
9990 for (UntypedOnCallSpecs::const_reverse_iterator it
9991 = untyped_on_call_specs_.rbegin();
9992 it != untyped_on_call_specs_.rend(); ++it) {
9993 const OnCallSpec<F>* spec = static_cast<const OnCallSpec<F>*>(*it);
9994 if (spec->Matches(args))
9995 return spec;
9996 }
9997
9998 return NULL;
9999 }
10000
10001 // Performs the default action of this mock function on the given
10002 // arguments and returns the result. Asserts (or throws if
10003 // exceptions are enabled) with a helpful call descrption if there
10004 // is no valid return value. This method doesn't depend on the
10005 // mutable state of this object, and thus can be called concurrently
10006 // without locking.
10007 // L = *
10008 Result PerformDefaultAction(const ArgumentTuple& args,
10009 const string& call_description) const {
10010 const OnCallSpec<F>* const spec =
10011 this->FindOnCallSpec(args);
10012 if (spec != NULL) {
10013 return spec->GetAction().Perform(args);
10014 }
10015 const string message = call_description +
10016 "\n The mock function has no default action "
10017 "set, and its return type has no default value set.";
10018#if GTEST_HAS_EXCEPTIONS
10019 if (!DefaultValue<Result>::Exists()) {
10020 throw std::runtime_error(message);
10021 }
10022#else
10023 Assert(DefaultValue<Result>::Exists(), "", -1, message);
10024#endif
10025 return DefaultValue<Result>::Get();
10026 }
10027
10028 // Performs the default action with the given arguments and returns
10029 // the action's result. The call description string will be used in
10030 // the error message to describe the call in the case the default
10031 // action fails. The caller is responsible for deleting the result.
10032 // L = *
10033 virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction(
10034 const void* untyped_args, // must point to an ArgumentTuple
10035 const string& call_description) const {
10036 const ArgumentTuple& args =
10037 *static_cast<const ArgumentTuple*>(untyped_args);
10038 return ResultHolder::PerformDefaultAction(this, args, call_description);
10039 }
10040
10041 // Performs the given action with the given arguments and returns
10042 // the action's result. The caller is responsible for deleting the
10043 // result.
10044 // L = *
10045 virtual UntypedActionResultHolderBase* UntypedPerformAction(
10046 const void* untyped_action, const void* untyped_args) const {
10047 // Make a copy of the action before performing it, in case the
10048 // action deletes the mock object (and thus deletes itself).
10049 const Action<F> action = *static_cast<const Action<F>*>(untyped_action);
10050 const ArgumentTuple& args =
10051 *static_cast<const ArgumentTuple*>(untyped_args);
10052 return ResultHolder::PerformAction(action, args);
10053 }
10054
10055 // Implements UntypedFunctionMockerBase::ClearDefaultActionsLocked():
10056 // clears the ON_CALL()s set on this mock function.
10057 virtual void ClearDefaultActionsLocked()
10058 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
10059 g_gmock_mutex.AssertHeld();
10060
10061 // Deleting our default actions may trigger other mock objects to be
10062 // deleted, for example if an action contains a reference counted smart
10063 // pointer to that mock object, and that is the last reference. So if we
10064 // delete our actions within the context of the global mutex we may deadlock
10065 // when this method is called again. Instead, make a copy of the set of
10066 // actions to delete, clear our set within the mutex, and then delete the
10067 // actions outside of the mutex.
10068 UntypedOnCallSpecs specs_to_delete;
10069 untyped_on_call_specs_.swap(specs_to_delete);
10070
10071 g_gmock_mutex.Unlock();
10072 for (UntypedOnCallSpecs::const_iterator it =
10073 specs_to_delete.begin();
10074 it != specs_to_delete.end(); ++it) {
10075 delete static_cast<const OnCallSpec<F>*>(*it);
10076 }
10077
10078 // Lock the mutex again, since the caller expects it to be locked when we
10079 // return.
10080 g_gmock_mutex.Lock();
10081 }
10082
10083 protected:
10084 template <typename Function>
10085 friend class MockSpec;
10086
10087 typedef ActionResultHolder<Result> ResultHolder;
10088
10089 // Returns the result of invoking this mock function with the given
10090 // arguments. This function can be safely called from multiple
10091 // threads concurrently.
10092 Result InvokeWith(const ArgumentTuple& args)
10093 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
10094 const ResultHolder *rh = static_cast<const ResultHolder*>(
10095 this->UntypedInvokeWith(&args));
10096 return rh ? rh->GetValueAndDelete() : Result();
10097 }
10098
10099 // Adds and returns a default action spec for this mock function.
10100 OnCallSpec<F>& AddNewOnCallSpec(
10101 const char* file, int line,
10102 const ArgumentMatcherTuple& m)
10103 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
10104 Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line);
10105 OnCallSpec<F>* const on_call_spec = new OnCallSpec<F>(file, line, m);
10106 untyped_on_call_specs_.push_back(on_call_spec);
10107 return *on_call_spec;
10108 }
10109
10110 // Adds and returns an expectation spec for this mock function.
10111 TypedExpectation<F>& AddNewExpectation(
10112 const char* file,
10113 int line,
10114 const string& source_text,
10115 const ArgumentMatcherTuple& m)
10116 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
10117 Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line);
10118 TypedExpectation<F>* const expectation =
10119 new TypedExpectation<F>(this, file, line, source_text, m);
10120 const linked_ptr<ExpectationBase> untyped_expectation(expectation);
10121 untyped_expectations_.push_back(untyped_expectation);
10122
10123 // Adds this expectation into the implicit sequence if there is one.
10124 Sequence* const implicit_sequence = g_gmock_implicit_sequence.get();
10125 if (implicit_sequence != NULL) {
10126 implicit_sequence->AddExpectation(Expectation(untyped_expectation));
10127 }
10128
10129 return *expectation;
10130 }
10131
10132 // The current spec (either default action spec or expectation spec)
10133 // being described on this function mocker.
10134 MockSpec<F>& current_spec() { return current_spec_; }
10135
10136 private:
10137 template <typename Func> friend class TypedExpectation;
10138
10139 // Some utilities needed for implementing UntypedInvokeWith().
10140
10141 // Describes what default action will be performed for the given
10142 // arguments.
10143 // L = *
10144 void DescribeDefaultActionTo(const ArgumentTuple& args,
10145 ::std::ostream* os) const {
10146 const OnCallSpec<F>* const spec = FindOnCallSpec(args);
10147
10148 if (spec == NULL) {
10149 *os << (internal::type_equals<Result, void>::value ?
10150 "returning directly.\n" :
10151 "returning default value.\n");
10152 } else {
10153 *os << "taking default action specified at:\n"
10154 << FormatFileLocation(spec->file(), spec->line()) << "\n";
10155 }
10156 }
10157
10158 // Writes a message that the call is uninteresting (i.e. neither
10159 // explicitly expected nor explicitly unexpected) to the given
10160 // ostream.
10161 virtual void UntypedDescribeUninterestingCall(
10162 const void* untyped_args,
10163 ::std::ostream* os) const
10164 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
10165 const ArgumentTuple& args =
10166 *static_cast<const ArgumentTuple*>(untyped_args);
10167 *os << "Uninteresting mock function call - ";
10168 DescribeDefaultActionTo(args, os);
10169 *os << " Function call: " << Name();
10170 UniversalPrint(args, os);
10171 }
10172
10173 // Returns the expectation that matches the given function arguments
10174 // (or NULL is there's no match); when a match is found,
10175 // untyped_action is set to point to the action that should be
10176 // performed (or NULL if the action is "do default"), and
10177 // is_excessive is modified to indicate whether the call exceeds the
10178 // expected number.
10179 //
10180 // Critical section: We must find the matching expectation and the
10181 // corresponding action that needs to be taken in an ATOMIC
10182 // transaction. Otherwise another thread may call this mock
10183 // method in the middle and mess up the state.
10184 //
10185 // However, performing the action has to be left out of the critical
10186 // section. The reason is that we have no control on what the
10187 // action does (it can invoke an arbitrary user function or even a
10188 // mock function) and excessive locking could cause a dead lock.
10189 virtual const ExpectationBase* UntypedFindMatchingExpectation(
10190 const void* untyped_args,
10191 const void** untyped_action, bool* is_excessive,
10192 ::std::ostream* what, ::std::ostream* why)
10193 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
10194 const ArgumentTuple& args =
10195 *static_cast<const ArgumentTuple*>(untyped_args);
10196 MutexLock l(&g_gmock_mutex);
10197 TypedExpectation<F>* exp = this->FindMatchingExpectationLocked(args);
10198 if (exp == NULL) { // A match wasn't found.
10199 this->FormatUnexpectedCallMessageLocked(args, what, why);
10200 return NULL;
10201 }
10202
10203 // This line must be done before calling GetActionForArguments(),
10204 // which will increment the call count for *exp and thus affect
10205 // its saturation status.
10206 *is_excessive = exp->IsSaturated();
10207 const Action<F>* action = exp->GetActionForArguments(this, args, what, why);
10208 if (action != NULL && action->IsDoDefault())
10209 action = NULL; // Normalize "do default" to NULL.
10210 *untyped_action = action;
10211 return exp;
10212 }
10213
10214 // Prints the given function arguments to the ostream.
10215 virtual void UntypedPrintArgs(const void* untyped_args,
10216 ::std::ostream* os) const {
10217 const ArgumentTuple& args =
10218 *static_cast<const ArgumentTuple*>(untyped_args);
10219 UniversalPrint(args, os);
10220 }
10221
10222 // Returns the expectation that matches the arguments, or NULL if no
10223 // expectation matches them.
10224 TypedExpectation<F>* FindMatchingExpectationLocked(
10225 const ArgumentTuple& args) const
10226 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
10227 g_gmock_mutex.AssertHeld();
10228 for (typename UntypedExpectations::const_reverse_iterator it =
10229 untyped_expectations_.rbegin();
10230 it != untyped_expectations_.rend(); ++it) {
10231 TypedExpectation<F>* const exp =
10232 static_cast<TypedExpectation<F>*>(it->get());
10233 if (exp->ShouldHandleArguments(args)) {
10234 return exp;
10235 }
10236 }
10237 return NULL;
10238 }
10239
10240 // Returns a message that the arguments don't match any expectation.
10241 void FormatUnexpectedCallMessageLocked(
10242 const ArgumentTuple& args,
10243 ::std::ostream* os,
10244 ::std::ostream* why) const
10245 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
10246 g_gmock_mutex.AssertHeld();
10247 *os << "\nUnexpected mock function call - ";
10248 DescribeDefaultActionTo(args, os);
10249 PrintTriedExpectationsLocked(args, why);
10250 }
10251
10252 // Prints a list of expectations that have been tried against the
10253 // current mock function call.
10254 void PrintTriedExpectationsLocked(
10255 const ArgumentTuple& args,
10256 ::std::ostream* why) const
10257 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
10258 g_gmock_mutex.AssertHeld();
10259 const int count = static_cast<int>(untyped_expectations_.size());
10260 *why << "Google Mock tried the following " << count << " "
10261 << (count == 1 ? "expectation, but it didn't match" :
10262 "expectations, but none matched")
10263 << ":\n";
10264 for (int i = 0; i < count; i++) {
10265 TypedExpectation<F>* const expectation =
10266 static_cast<TypedExpectation<F>*>(untyped_expectations_[i].get());
10267 *why << "\n";
10268 expectation->DescribeLocationTo(why);
10269 if (count > 1) {
10270 *why << "tried expectation #" << i << ": ";
10271 }
10272 *why << expectation->source_text() << "...\n";
10273 expectation->ExplainMatchResultTo(args, why);
10274 expectation->DescribeCallCountTo(why);
10275 }
10276 }
10277
10278 // The current spec (either default action spec or expectation spec)
10279 // being described on this function mocker.
10280 MockSpec<F> current_spec_;
10281
10282 // There is no generally useful and implementable semantics of
10283 // copying a mock object, so copying a mock is usually a user error.
10284 // Thus we disallow copying function mockers. If the user really
10285 // wants to copy a mock object, he should implement his own copy
10286 // operation, for example:
10287 //
10288 // class MockFoo : public Foo {
10289 // public:
10290 // // Defines a copy constructor explicitly.
10291 // MockFoo(const MockFoo& src) {}
10292 // ...
10293 // };
10294 GTEST_DISALLOW_COPY_AND_ASSIGN_(FunctionMockerBase);
10295}; // class FunctionMockerBase
10296
10297#ifdef _MSC_VER
10298# pragma warning(pop) // Restores the warning state.
10299#endif // _MSV_VER
10300
10301// Implements methods of FunctionMockerBase.
10302
10303// Verifies that all expectations on this mock function have been
10304// satisfied. Reports one or more Google Test non-fatal failures and
10305// returns false if not.
10306
10307// Reports an uninteresting call (whose description is in msg) in the
10308// manner specified by 'reaction'.
10309void ReportUninterestingCall(CallReaction reaction, const string& msg);
10310
10311} // namespace internal
10312
10313// The style guide prohibits "using" statements in a namespace scope
10314// inside a header file. However, the MockSpec class template is
10315// meant to be defined in the ::testing namespace. The following line
10316// is just a trick for working around a bug in MSVC 8.0, which cannot
10317// handle it if we define MockSpec in ::testing.
10318using internal::MockSpec;
10319
10320// Const(x) is a convenient function for obtaining a const reference
10321// to x. This is useful for setting expectations on an overloaded
10322// const mock method, e.g.
10323//
10324// class MockFoo : public FooInterface {
10325// public:
10326// MOCK_METHOD0(Bar, int());
10327// MOCK_CONST_METHOD0(Bar, int&());
10328// };
10329//
10330// MockFoo foo;
10331// // Expects a call to non-const MockFoo::Bar().
10332// EXPECT_CALL(foo, Bar());
10333// // Expects a call to const MockFoo::Bar().
10334// EXPECT_CALL(Const(foo), Bar());
10335template <typename T>
10336inline const T& Const(const T& x) { return x; }
10337
10338// Constructs an Expectation object that references and co-owns exp.
10339inline Expectation::Expectation(internal::ExpectationBase& exp) // NOLINT
10340 : expectation_base_(exp.GetHandle().expectation_base()) {}
10341
10342} // namespace testing
10343
10344// A separate macro is required to avoid compile errors when the name
10345// of the method used in call is a result of macro expansion.
10346// See CompilesWithMethodNameExpandedFromMacro tests in
10347// internal/gmock-spec-builders_test.cc for more details.
10348#define GMOCK_ON_CALL_IMPL_(obj, call) \
10349 ((obj).gmock_##call).InternalDefaultActionSetAt(__FILE__, __LINE__, \
10350 #obj, #call)
10351#define ON_CALL(obj, call) GMOCK_ON_CALL_IMPL_(obj, call)
10352
10353#define GMOCK_EXPECT_CALL_IMPL_(obj, call) \
10354 ((obj).gmock_##call).InternalExpectedAt(__FILE__, __LINE__, #obj, #call)
10355#define EXPECT_CALL(obj, call) GMOCK_EXPECT_CALL_IMPL_(obj, call)
10356
10357#endif // GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_
10358
10359namespace testing {
10360namespace internal {
10361
10362template <typename F>
10363class FunctionMockerBase;
10364
10365// Note: class FunctionMocker really belongs to the ::testing
10366// namespace. However if we define it in ::testing, MSVC will
10367// complain when classes in ::testing::internal declare it as a
10368// friend class template. To workaround this compiler bug, we define
10369// FunctionMocker in ::testing::internal and import it into ::testing.
10370template <typename F>
10371class FunctionMocker;
10372
10373template <typename R>
10374class FunctionMocker<R()> : public
10375 internal::FunctionMockerBase<R()> {
10376 public:
10377 typedef R F();
10378 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
10379
10380 MockSpec<F>& With() {
10381 return this->current_spec();
10382 }
10383
10384 R Invoke() {
10385 // Even though gcc and MSVC don't enforce it, 'this->' is required
10386 // by the C++ standard [14.6.4] here, as the base class type is
10387 // dependent on the template argument (and thus shouldn't be
10388 // looked into when resolving InvokeWith).
10389 return this->InvokeWith(ArgumentTuple());
10390 }
10391};
10392
10393template <typename R, typename A1>
10394class FunctionMocker<R(A1)> : public
10395 internal::FunctionMockerBase<R(A1)> {
10396 public:
10397 typedef R F(A1);
10398 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
10399
10400 MockSpec<F>& With(const Matcher<A1>& m1) {
10401 this->current_spec().SetMatchers(::std::tr1::make_tuple(m1));
10402 return this->current_spec();
10403 }
10404
10405 R Invoke(A1 a1) {
10406 // Even though gcc and MSVC don't enforce it, 'this->' is required
10407 // by the C++ standard [14.6.4] here, as the base class type is
10408 // dependent on the template argument (and thus shouldn't be
10409 // looked into when resolving InvokeWith).
10410 return this->InvokeWith(ArgumentTuple(a1));
10411 }
10412};
10413
10414template <typename R, typename A1, typename A2>
10415class FunctionMocker<R(A1, A2)> : public
10416 internal::FunctionMockerBase<R(A1, A2)> {
10417 public:
10418 typedef R F(A1, A2);
10419 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
10420
10421 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2) {
10422 this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2));
10423 return this->current_spec();
10424 }
10425
10426 R Invoke(A1 a1, A2 a2) {
10427 // Even though gcc and MSVC don't enforce it, 'this->' is required
10428 // by the C++ standard [14.6.4] here, as the base class type is
10429 // dependent on the template argument (and thus shouldn't be
10430 // looked into when resolving InvokeWith).
10431 return this->InvokeWith(ArgumentTuple(a1, a2));
10432 }
10433};
10434
10435template <typename R, typename A1, typename A2, typename A3>
10436class FunctionMocker<R(A1, A2, A3)> : public
10437 internal::FunctionMockerBase<R(A1, A2, A3)> {
10438 public:
10439 typedef R F(A1, A2, A3);
10440 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
10441
10442 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
10443 const Matcher<A3>& m3) {
10444 this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3));
10445 return this->current_spec();
10446 }
10447
10448 R Invoke(A1 a1, A2 a2, A3 a3) {
10449 // Even though gcc and MSVC don't enforce it, 'this->' is required
10450 // by the C++ standard [14.6.4] here, as the base class type is
10451 // dependent on the template argument (and thus shouldn't be
10452 // looked into when resolving InvokeWith).
10453 return this->InvokeWith(ArgumentTuple(a1, a2, a3));
10454 }
10455};
10456
10457template <typename R, typename A1, typename A2, typename A3, typename A4>
10458class FunctionMocker<R(A1, A2, A3, A4)> : public
10459 internal::FunctionMockerBase<R(A1, A2, A3, A4)> {
10460 public:
10461 typedef R F(A1, A2, A3, A4);
10462 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
10463
10464 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
10465 const Matcher<A3>& m3, const Matcher<A4>& m4) {
10466 this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4));
10467 return this->current_spec();
10468 }
10469
10470 R Invoke(A1 a1, A2 a2, A3 a3, A4 a4) {
10471 // Even though gcc and MSVC don't enforce it, 'this->' is required
10472 // by the C++ standard [14.6.4] here, as the base class type is
10473 // dependent on the template argument (and thus shouldn't be
10474 // looked into when resolving InvokeWith).
10475 return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4));
10476 }
10477};
10478
10479template <typename R, typename A1, typename A2, typename A3, typename A4,
10480 typename A5>
10481class FunctionMocker<R(A1, A2, A3, A4, A5)> : public
10482 internal::FunctionMockerBase<R(A1, A2, A3, A4, A5)> {
10483 public:
10484 typedef R F(A1, A2, A3, A4, A5);
10485 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
10486
10487 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
10488 const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5) {
10489 this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4,
10490 m5));
10491 return this->current_spec();
10492 }
10493
10494 R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) {
10495 // Even though gcc and MSVC don't enforce it, 'this->' is required
10496 // by the C++ standard [14.6.4] here, as the base class type is
10497 // dependent on the template argument (and thus shouldn't be
10498 // looked into when resolving InvokeWith).
10499 return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5));
10500 }
10501};
10502
10503template <typename R, typename A1, typename A2, typename A3, typename A4,
10504 typename A5, typename A6>
10505class FunctionMocker<R(A1, A2, A3, A4, A5, A6)> : public
10506 internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6)> {
10507 public:
10508 typedef R F(A1, A2, A3, A4, A5, A6);
10509 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
10510
10511 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
10512 const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5,
10513 const Matcher<A6>& m6) {
10514 this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5,
10515 m6));
10516 return this->current_spec();
10517 }
10518
10519 R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) {
10520 // Even though gcc and MSVC don't enforce it, 'this->' is required
10521 // by the C++ standard [14.6.4] here, as the base class type is
10522 // dependent on the template argument (and thus shouldn't be
10523 // looked into when resolving InvokeWith).
10524 return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6));
10525 }
10526};
10527
10528template <typename R, typename A1, typename A2, typename A3, typename A4,
10529 typename A5, typename A6, typename A7>
10530class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7)> : public
10531 internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6, A7)> {
10532 public:
10533 typedef R F(A1, A2, A3, A4, A5, A6, A7);
10534 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
10535
10536 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
10537 const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5,
10538 const Matcher<A6>& m6, const Matcher<A7>& m7) {
10539 this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5,
10540 m6, m7));
10541 return this->current_spec();
10542 }
10543
10544 R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) {
10545 // Even though gcc and MSVC don't enforce it, 'this->' is required
10546 // by the C++ standard [14.6.4] here, as the base class type is
10547 // dependent on the template argument (and thus shouldn't be
10548 // looked into when resolving InvokeWith).
10549 return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7));
10550 }
10551};
10552
10553template <typename R, typename A1, typename A2, typename A3, typename A4,
10554 typename A5, typename A6, typename A7, typename A8>
10555class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8)> : public
10556 internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6, A7, A8)> {
10557 public:
10558 typedef R F(A1, A2, A3, A4, A5, A6, A7, A8);
10559 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
10560
10561 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
10562 const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5,
10563 const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8) {
10564 this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5,
10565 m6, m7, m8));
10566 return this->current_spec();
10567 }
10568
10569 R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) {
10570 // Even though gcc and MSVC don't enforce it, 'this->' is required
10571 // by the C++ standard [14.6.4] here, as the base class type is
10572 // dependent on the template argument (and thus shouldn't be
10573 // looked into when resolving InvokeWith).
10574 return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8));
10575 }
10576};
10577
10578template <typename R, typename A1, typename A2, typename A3, typename A4,
10579 typename A5, typename A6, typename A7, typename A8, typename A9>
10580class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> : public
10581 internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> {
10582 public:
10583 typedef R F(A1, A2, A3, A4, A5, A6, A7, A8, A9);
10584 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
10585
10586 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
10587 const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5,
10588 const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8,
10589 const Matcher<A9>& m9) {
10590 this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5,
10591 m6, m7, m8, m9));
10592 return this->current_spec();
10593 }
10594
10595 R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) {
10596 // Even though gcc and MSVC don't enforce it, 'this->' is required
10597 // by the C++ standard [14.6.4] here, as the base class type is
10598 // dependent on the template argument (and thus shouldn't be
10599 // looked into when resolving InvokeWith).
10600 return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8, a9));
10601 }
10602};
10603
10604template <typename R, typename A1, typename A2, typename A3, typename A4,
10605 typename A5, typename A6, typename A7, typename A8, typename A9,
10606 typename A10>
10607class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> : public
10608 internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> {
10609 public:
10610 typedef R F(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10);
10611 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
10612
10613 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
10614 const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5,
10615 const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8,
10616 const Matcher<A9>& m9, const Matcher<A10>& m10) {
10617 this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5,
10618 m6, m7, m8, m9, m10));
10619 return this->current_spec();
10620 }
10621
10622 R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9,
10623 A10 a10) {
10624 // Even though gcc and MSVC don't enforce it, 'this->' is required
10625 // by the C++ standard [14.6.4] here, as the base class type is
10626 // dependent on the template argument (and thus shouldn't be
10627 // looked into when resolving InvokeWith).
10628 return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8, a9,
10629 a10));
10630 }
10631};
10632
10633} // namespace internal
10634
10635// The style guide prohibits "using" statements in a namespace scope
10636// inside a header file. However, the FunctionMocker class template
10637// is meant to be defined in the ::testing namespace. The following
10638// line is just a trick for working around a bug in MSVC 8.0, which
10639// cannot handle it if we define FunctionMocker in ::testing.
10640using internal::FunctionMocker;
10641
10642// GMOCK_RESULT_(tn, F) expands to the result type of function type F.
10643// We define this as a variadic macro in case F contains unprotected
10644// commas (the same reason that we use variadic macros in other places
10645// in this file).
10646// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10647#define GMOCK_RESULT_(tn, ...) \
10648 tn ::testing::internal::Function<__VA_ARGS__>::Result
10649
10650// The type of argument N of the given function type.
10651// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10652#define GMOCK_ARG_(tn, N, ...) \
10653 tn ::testing::internal::Function<__VA_ARGS__>::Argument##N
10654
10655// The matcher type for argument N of the given function type.
10656// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10657#define GMOCK_MATCHER_(tn, N, ...) \
10658 const ::testing::Matcher<GMOCK_ARG_(tn, N, __VA_ARGS__)>&
10659
10660// The variable for mocking the given method.
10661// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10662#define GMOCK_MOCKER_(arity, constness, Method) \
10663 GTEST_CONCAT_TOKEN_(gmock##constness##arity##_##Method##_, __LINE__)
10664
10665// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10666#define GMOCK_METHOD0_(tn, constness, ct, Method, ...) \
10667 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
10668 ) constness { \
10669 GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \
10670 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
10671 == 0), \
10672 this_method_does_not_take_0_arguments); \
10673 GMOCK_MOCKER_(0, constness, Method).SetOwnerAndName(this, #Method); \
10674 return GMOCK_MOCKER_(0, constness, Method).Invoke(); \
10675 } \
10676 ::testing::MockSpec<__VA_ARGS__>& \
10677 gmock_##Method() constness { \
10678 GMOCK_MOCKER_(0, constness, Method).RegisterOwner(this); \
10679 return GMOCK_MOCKER_(0, constness, Method).With(); \
10680 } \
10681 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(0, constness, \
10682 Method)
10683
10684// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10685#define GMOCK_METHOD1_(tn, constness, ct, Method, ...) \
10686 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
10687 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1) constness { \
10688 GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \
10689 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
10690 == 1), \
10691 this_method_does_not_take_1_argument); \
10692 GMOCK_MOCKER_(1, constness, Method).SetOwnerAndName(this, #Method); \
10693 return GMOCK_MOCKER_(1, constness, Method).Invoke(gmock_a1); \
10694 } \
10695 ::testing::MockSpec<__VA_ARGS__>& \
10696 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1) constness { \
10697 GMOCK_MOCKER_(1, constness, Method).RegisterOwner(this); \
10698 return GMOCK_MOCKER_(1, constness, Method).With(gmock_a1); \
10699 } \
10700 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(1, constness, \
10701 Method)
10702
10703// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10704#define GMOCK_METHOD2_(tn, constness, ct, Method, ...) \
10705 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
10706 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
10707 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2) constness { \
10708 GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \
10709 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
10710 == 2), \
10711 this_method_does_not_take_2_arguments); \
10712 GMOCK_MOCKER_(2, constness, Method).SetOwnerAndName(this, #Method); \
10713 return GMOCK_MOCKER_(2, constness, Method).Invoke(gmock_a1, gmock_a2); \
10714 } \
10715 ::testing::MockSpec<__VA_ARGS__>& \
10716 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
10717 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2) constness { \
10718 GMOCK_MOCKER_(2, constness, Method).RegisterOwner(this); \
10719 return GMOCK_MOCKER_(2, constness, Method).With(gmock_a1, gmock_a2); \
10720 } \
10721 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(2, constness, \
10722 Method)
10723
10724// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10725#define GMOCK_METHOD3_(tn, constness, ct, Method, ...) \
10726 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
10727 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
10728 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
10729 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3) constness { \
10730 GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \
10731 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
10732 == 3), \
10733 this_method_does_not_take_3_arguments); \
10734 GMOCK_MOCKER_(3, constness, Method).SetOwnerAndName(this, #Method); \
10735 return GMOCK_MOCKER_(3, constness, Method).Invoke(gmock_a1, gmock_a2, \
10736 gmock_a3); \
10737 } \
10738 ::testing::MockSpec<__VA_ARGS__>& \
10739 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
10740 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
10741 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3) constness { \
10742 GMOCK_MOCKER_(3, constness, Method).RegisterOwner(this); \
10743 return GMOCK_MOCKER_(3, constness, Method).With(gmock_a1, gmock_a2, \
10744 gmock_a3); \
10745 } \
10746 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(3, constness, \
10747 Method)
10748
10749// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10750#define GMOCK_METHOD4_(tn, constness, ct, Method, ...) \
10751 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
10752 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
10753 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
10754 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
10755 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4) constness { \
10756 GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \
10757 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
10758 == 4), \
10759 this_method_does_not_take_4_arguments); \
10760 GMOCK_MOCKER_(4, constness, Method).SetOwnerAndName(this, #Method); \
10761 return GMOCK_MOCKER_(4, constness, Method).Invoke(gmock_a1, gmock_a2, \
10762 gmock_a3, gmock_a4); \
10763 } \
10764 ::testing::MockSpec<__VA_ARGS__>& \
10765 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
10766 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
10767 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
10768 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4) constness { \
10769 GMOCK_MOCKER_(4, constness, Method).RegisterOwner(this); \
10770 return GMOCK_MOCKER_(4, constness, Method).With(gmock_a1, gmock_a2, \
10771 gmock_a3, gmock_a4); \
10772 } \
10773 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(4, constness, \
10774 Method)
10775
10776// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10777#define GMOCK_METHOD5_(tn, constness, ct, Method, ...) \
10778 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
10779 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
10780 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
10781 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
10782 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \
10783 GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5) constness { \
10784 GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \
10785 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
10786 == 5), \
10787 this_method_does_not_take_5_arguments); \
10788 GMOCK_MOCKER_(5, constness, Method).SetOwnerAndName(this, #Method); \
10789 return GMOCK_MOCKER_(5, constness, Method).Invoke(gmock_a1, gmock_a2, \
10790 gmock_a3, gmock_a4, gmock_a5); \
10791 } \
10792 ::testing::MockSpec<__VA_ARGS__>& \
10793 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
10794 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
10795 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
10796 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
10797 GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5) constness { \
10798 GMOCK_MOCKER_(5, constness, Method).RegisterOwner(this); \
10799 return GMOCK_MOCKER_(5, constness, Method).With(gmock_a1, gmock_a2, \
10800 gmock_a3, gmock_a4, gmock_a5); \
10801 } \
10802 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(5, constness, \
10803 Method)
10804
10805// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10806#define GMOCK_METHOD6_(tn, constness, ct, Method, ...) \
10807 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
10808 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
10809 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
10810 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
10811 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \
10812 GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \
10813 GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6) constness { \
10814 GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \
10815 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
10816 == 6), \
10817 this_method_does_not_take_6_arguments); \
10818 GMOCK_MOCKER_(6, constness, Method).SetOwnerAndName(this, #Method); \
10819 return GMOCK_MOCKER_(6, constness, Method).Invoke(gmock_a1, gmock_a2, \
10820 gmock_a3, gmock_a4, gmock_a5, gmock_a6); \
10821 } \
10822 ::testing::MockSpec<__VA_ARGS__>& \
10823 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
10824 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
10825 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
10826 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
10827 GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \
10828 GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6) constness { \
10829 GMOCK_MOCKER_(6, constness, Method).RegisterOwner(this); \
10830 return GMOCK_MOCKER_(6, constness, Method).With(gmock_a1, gmock_a2, \
10831 gmock_a3, gmock_a4, gmock_a5, gmock_a6); \
10832 } \
10833 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(6, constness, \
10834 Method)
10835
10836// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10837#define GMOCK_METHOD7_(tn, constness, ct, Method, ...) \
10838 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
10839 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
10840 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
10841 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
10842 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \
10843 GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \
10844 GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
10845 GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7) constness { \
10846 GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \
10847 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
10848 == 7), \
10849 this_method_does_not_take_7_arguments); \
10850 GMOCK_MOCKER_(7, constness, Method).SetOwnerAndName(this, #Method); \
10851 return GMOCK_MOCKER_(7, constness, Method).Invoke(gmock_a1, gmock_a2, \
10852 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7); \
10853 } \
10854 ::testing::MockSpec<__VA_ARGS__>& \
10855 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
10856 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
10857 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
10858 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
10859 GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \
10860 GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \
10861 GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7) constness { \
10862 GMOCK_MOCKER_(7, constness, Method).RegisterOwner(this); \
10863 return GMOCK_MOCKER_(7, constness, Method).With(gmock_a1, gmock_a2, \
10864 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7); \
10865 } \
10866 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(7, constness, \
10867 Method)
10868
10869// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10870#define GMOCK_METHOD8_(tn, constness, ct, Method, ...) \
10871 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
10872 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
10873 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
10874 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
10875 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \
10876 GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \
10877 GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
10878 GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \
10879 GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8) constness { \
10880 GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \
10881 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
10882 == 8), \
10883 this_method_does_not_take_8_arguments); \
10884 GMOCK_MOCKER_(8, constness, Method).SetOwnerAndName(this, #Method); \
10885 return GMOCK_MOCKER_(8, constness, Method).Invoke(gmock_a1, gmock_a2, \
10886 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8); \
10887 } \
10888 ::testing::MockSpec<__VA_ARGS__>& \
10889 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
10890 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
10891 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
10892 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
10893 GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \
10894 GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \
10895 GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \
10896 GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8) constness { \
10897 GMOCK_MOCKER_(8, constness, Method).RegisterOwner(this); \
10898 return GMOCK_MOCKER_(8, constness, Method).With(gmock_a1, gmock_a2, \
10899 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8); \
10900 } \
10901 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(8, constness, \
10902 Method)
10903
10904// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10905#define GMOCK_METHOD9_(tn, constness, ct, Method, ...) \
10906 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
10907 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
10908 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
10909 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
10910 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \
10911 GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \
10912 GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
10913 GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \
10914 GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8, \
10915 GMOCK_ARG_(tn, 9, __VA_ARGS__) gmock_a9) constness { \
10916 GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \
10917 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
10918 == 9), \
10919 this_method_does_not_take_9_arguments); \
10920 GMOCK_MOCKER_(9, constness, Method).SetOwnerAndName(this, #Method); \
10921 return GMOCK_MOCKER_(9, constness, Method).Invoke(gmock_a1, gmock_a2, \
10922 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, \
10923 gmock_a9); \
10924 } \
10925 ::testing::MockSpec<__VA_ARGS__>& \
10926 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
10927 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
10928 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
10929 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
10930 GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \
10931 GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \
10932 GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \
10933 GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8, \
10934 GMOCK_MATCHER_(tn, 9, __VA_ARGS__) gmock_a9) constness { \
10935 GMOCK_MOCKER_(9, constness, Method).RegisterOwner(this); \
10936 return GMOCK_MOCKER_(9, constness, Method).With(gmock_a1, gmock_a2, \
10937 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, \
10938 gmock_a9); \
10939 } \
10940 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(9, constness, \
10941 Method)
10942
10943// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10944#define GMOCK_METHOD10_(tn, constness, ct, Method, ...) \
10945 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
10946 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
10947 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
10948 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
10949 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \
10950 GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \
10951 GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
10952 GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \
10953 GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8, \
10954 GMOCK_ARG_(tn, 9, __VA_ARGS__) gmock_a9, \
10955 GMOCK_ARG_(tn, 10, __VA_ARGS__) gmock_a10) constness { \
10956 GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \
10957 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
10958 == 10), \
10959 this_method_does_not_take_10_arguments); \
10960 GMOCK_MOCKER_(10, constness, Method).SetOwnerAndName(this, #Method); \
10961 return GMOCK_MOCKER_(10, constness, Method).Invoke(gmock_a1, gmock_a2, \
10962 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, gmock_a9, \
10963 gmock_a10); \
10964 } \
10965 ::testing::MockSpec<__VA_ARGS__>& \
10966 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
10967 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
10968 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
10969 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
10970 GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \
10971 GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \
10972 GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \
10973 GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8, \
10974 GMOCK_MATCHER_(tn, 9, __VA_ARGS__) gmock_a9, \
10975 GMOCK_MATCHER_(tn, 10, \
10976 __VA_ARGS__) gmock_a10) constness { \
10977 GMOCK_MOCKER_(10, constness, Method).RegisterOwner(this); \
10978 return GMOCK_MOCKER_(10, constness, Method).With(gmock_a1, gmock_a2, \
10979 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, gmock_a9, \
10980 gmock_a10); \
10981 } \
10982 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(10, constness, \
10983 Method)
10984
10985#define MOCK_METHOD0(m, ...) GMOCK_METHOD0_(, , , m, __VA_ARGS__)
10986#define MOCK_METHOD1(m, ...) GMOCK_METHOD1_(, , , m, __VA_ARGS__)
10987#define MOCK_METHOD2(m, ...) GMOCK_METHOD2_(, , , m, __VA_ARGS__)
10988#define MOCK_METHOD3(m, ...) GMOCK_METHOD3_(, , , m, __VA_ARGS__)
10989#define MOCK_METHOD4(m, ...) GMOCK_METHOD4_(, , , m, __VA_ARGS__)
10990#define MOCK_METHOD5(m, ...) GMOCK_METHOD5_(, , , m, __VA_ARGS__)
10991#define MOCK_METHOD6(m, ...) GMOCK_METHOD6_(, , , m, __VA_ARGS__)
10992#define MOCK_METHOD7(m, ...) GMOCK_METHOD7_(, , , m, __VA_ARGS__)
10993#define MOCK_METHOD8(m, ...) GMOCK_METHOD8_(, , , m, __VA_ARGS__)
10994#define MOCK_METHOD9(m, ...) GMOCK_METHOD9_(, , , m, __VA_ARGS__)
10995#define MOCK_METHOD10(m, ...) GMOCK_METHOD10_(, , , m, __VA_ARGS__)
10996
10997#define MOCK_CONST_METHOD0(m, ...) GMOCK_METHOD0_(, const, , m, __VA_ARGS__)
10998#define MOCK_CONST_METHOD1(m, ...) GMOCK_METHOD1_(, const, , m, __VA_ARGS__)
10999#define MOCK_CONST_METHOD2(m, ...) GMOCK_METHOD2_(, const, , m, __VA_ARGS__)
11000#define MOCK_CONST_METHOD3(m, ...) GMOCK_METHOD3_(, const, , m, __VA_ARGS__)
11001#define MOCK_CONST_METHOD4(m, ...) GMOCK_METHOD4_(, const, , m, __VA_ARGS__)
11002#define MOCK_CONST_METHOD5(m, ...) GMOCK_METHOD5_(, const, , m, __VA_ARGS__)
11003#define MOCK_CONST_METHOD6(m, ...) GMOCK_METHOD6_(, const, , m, __VA_ARGS__)
11004#define MOCK_CONST_METHOD7(m, ...) GMOCK_METHOD7_(, const, , m, __VA_ARGS__)
11005#define MOCK_CONST_METHOD8(m, ...) GMOCK_METHOD8_(, const, , m, __VA_ARGS__)
11006#define MOCK_CONST_METHOD9(m, ...) GMOCK_METHOD9_(, const, , m, __VA_ARGS__)
11007#define MOCK_CONST_METHOD10(m, ...) GMOCK_METHOD10_(, const, , m, __VA_ARGS__)
11008
11009#define MOCK_METHOD0_T(m, ...) GMOCK_METHOD0_(typename, , , m, __VA_ARGS__)
11010#define MOCK_METHOD1_T(m, ...) GMOCK_METHOD1_(typename, , , m, __VA_ARGS__)
11011#define MOCK_METHOD2_T(m, ...) GMOCK_METHOD2_(typename, , , m, __VA_ARGS__)
11012#define MOCK_METHOD3_T(m, ...) GMOCK_METHOD3_(typename, , , m, __VA_ARGS__)
11013#define MOCK_METHOD4_T(m, ...) GMOCK_METHOD4_(typename, , , m, __VA_ARGS__)
11014#define MOCK_METHOD5_T(m, ...) GMOCK_METHOD5_(typename, , , m, __VA_ARGS__)
11015#define MOCK_METHOD6_T(m, ...) GMOCK_METHOD6_(typename, , , m, __VA_ARGS__)
11016#define MOCK_METHOD7_T(m, ...) GMOCK_METHOD7_(typename, , , m, __VA_ARGS__)
11017#define MOCK_METHOD8_T(m, ...) GMOCK_METHOD8_(typename, , , m, __VA_ARGS__)
11018#define MOCK_METHOD9_T(m, ...) GMOCK_METHOD9_(typename, , , m, __VA_ARGS__)
11019#define MOCK_METHOD10_T(m, ...) GMOCK_METHOD10_(typename, , , m, __VA_ARGS__)
11020
11021#define MOCK_CONST_METHOD0_T(m, ...) \
11022 GMOCK_METHOD0_(typename, const, , m, __VA_ARGS__)
11023#define MOCK_CONST_METHOD1_T(m, ...) \
11024 GMOCK_METHOD1_(typename, const, , m, __VA_ARGS__)
11025#define MOCK_CONST_METHOD2_T(m, ...) \
11026 GMOCK_METHOD2_(typename, const, , m, __VA_ARGS__)
11027#define MOCK_CONST_METHOD3_T(m, ...) \
11028 GMOCK_METHOD3_(typename, const, , m, __VA_ARGS__)
11029#define MOCK_CONST_METHOD4_T(m, ...) \
11030 GMOCK_METHOD4_(typename, const, , m, __VA_ARGS__)
11031#define MOCK_CONST_METHOD5_T(m, ...) \
11032 GMOCK_METHOD5_(typename, const, , m, __VA_ARGS__)
11033#define MOCK_CONST_METHOD6_T(m, ...) \
11034 GMOCK_METHOD6_(typename, const, , m, __VA_ARGS__)
11035#define MOCK_CONST_METHOD7_T(m, ...) \
11036 GMOCK_METHOD7_(typename, const, , m, __VA_ARGS__)
11037#define MOCK_CONST_METHOD8_T(m, ...) \
11038 GMOCK_METHOD8_(typename, const, , m, __VA_ARGS__)
11039#define MOCK_CONST_METHOD9_T(m, ...) \
11040 GMOCK_METHOD9_(typename, const, , m, __VA_ARGS__)
11041#define MOCK_CONST_METHOD10_T(m, ...) \
11042 GMOCK_METHOD10_(typename, const, , m, __VA_ARGS__)
11043
11044#define MOCK_METHOD0_WITH_CALLTYPE(ct, m, ...) \
11045 GMOCK_METHOD0_(, , ct, m, __VA_ARGS__)
11046#define MOCK_METHOD1_WITH_CALLTYPE(ct, m, ...) \
11047 GMOCK_METHOD1_(, , ct, m, __VA_ARGS__)
11048#define MOCK_METHOD2_WITH_CALLTYPE(ct, m, ...) \
11049 GMOCK_METHOD2_(, , ct, m, __VA_ARGS__)
11050#define MOCK_METHOD3_WITH_CALLTYPE(ct, m, ...) \
11051 GMOCK_METHOD3_(, , ct, m, __VA_ARGS__)
11052#define MOCK_METHOD4_WITH_CALLTYPE(ct, m, ...) \
11053 GMOCK_METHOD4_(, , ct, m, __VA_ARGS__)
11054#define MOCK_METHOD5_WITH_CALLTYPE(ct, m, ...) \
11055 GMOCK_METHOD5_(, , ct, m, __VA_ARGS__)
11056#define MOCK_METHOD6_WITH_CALLTYPE(ct, m, ...) \
11057 GMOCK_METHOD6_(, , ct, m, __VA_ARGS__)
11058#define MOCK_METHOD7_WITH_CALLTYPE(ct, m, ...) \
11059 GMOCK_METHOD7_(, , ct, m, __VA_ARGS__)
11060#define MOCK_METHOD8_WITH_CALLTYPE(ct, m, ...) \
11061 GMOCK_METHOD8_(, , ct, m, __VA_ARGS__)
11062#define MOCK_METHOD9_WITH_CALLTYPE(ct, m, ...) \
11063 GMOCK_METHOD9_(, , ct, m, __VA_ARGS__)
11064#define MOCK_METHOD10_WITH_CALLTYPE(ct, m, ...) \
11065 GMOCK_METHOD10_(, , ct, m, __VA_ARGS__)
11066
11067#define MOCK_CONST_METHOD0_WITH_CALLTYPE(ct, m, ...) \
11068 GMOCK_METHOD0_(, const, ct, m, __VA_ARGS__)
11069#define MOCK_CONST_METHOD1_WITH_CALLTYPE(ct, m, ...) \
11070 GMOCK_METHOD1_(, const, ct, m, __VA_ARGS__)
11071#define MOCK_CONST_METHOD2_WITH_CALLTYPE(ct, m, ...) \
11072 GMOCK_METHOD2_(, const, ct, m, __VA_ARGS__)
11073#define MOCK_CONST_METHOD3_WITH_CALLTYPE(ct, m, ...) \
11074 GMOCK_METHOD3_(, const, ct, m, __VA_ARGS__)
11075#define MOCK_CONST_METHOD4_WITH_CALLTYPE(ct, m, ...) \
11076 GMOCK_METHOD4_(, const, ct, m, __VA_ARGS__)
11077#define MOCK_CONST_METHOD5_WITH_CALLTYPE(ct, m, ...) \
11078 GMOCK_METHOD5_(, const, ct, m, __VA_ARGS__)
11079#define MOCK_CONST_METHOD6_WITH_CALLTYPE(ct, m, ...) \
11080 GMOCK_METHOD6_(, const, ct, m, __VA_ARGS__)
11081#define MOCK_CONST_METHOD7_WITH_CALLTYPE(ct, m, ...) \
11082 GMOCK_METHOD7_(, const, ct, m, __VA_ARGS__)
11083#define MOCK_CONST_METHOD8_WITH_CALLTYPE(ct, m, ...) \
11084 GMOCK_METHOD8_(, const, ct, m, __VA_ARGS__)
11085#define MOCK_CONST_METHOD9_WITH_CALLTYPE(ct, m, ...) \
11086 GMOCK_METHOD9_(, const, ct, m, __VA_ARGS__)
11087#define MOCK_CONST_METHOD10_WITH_CALLTYPE(ct, m, ...) \
11088 GMOCK_METHOD10_(, const, ct, m, __VA_ARGS__)
11089
11090#define MOCK_METHOD0_T_WITH_CALLTYPE(ct, m, ...) \
11091 GMOCK_METHOD0_(typename, , ct, m, __VA_ARGS__)
11092#define MOCK_METHOD1_T_WITH_CALLTYPE(ct, m, ...) \
11093 GMOCK_METHOD1_(typename, , ct, m, __VA_ARGS__)
11094#define MOCK_METHOD2_T_WITH_CALLTYPE(ct, m, ...) \
11095 GMOCK_METHOD2_(typename, , ct, m, __VA_ARGS__)
11096#define MOCK_METHOD3_T_WITH_CALLTYPE(ct, m, ...) \
11097 GMOCK_METHOD3_(typename, , ct, m, __VA_ARGS__)
11098#define MOCK_METHOD4_T_WITH_CALLTYPE(ct, m, ...) \
11099 GMOCK_METHOD4_(typename, , ct, m, __VA_ARGS__)
11100#define MOCK_METHOD5_T_WITH_CALLTYPE(ct, m, ...) \
11101 GMOCK_METHOD5_(typename, , ct, m, __VA_ARGS__)
11102#define MOCK_METHOD6_T_WITH_CALLTYPE(ct, m, ...) \
11103 GMOCK_METHOD6_(typename, , ct, m, __VA_ARGS__)
11104#define MOCK_METHOD7_T_WITH_CALLTYPE(ct, m, ...) \
11105 GMOCK_METHOD7_(typename, , ct, m, __VA_ARGS__)
11106#define MOCK_METHOD8_T_WITH_CALLTYPE(ct, m, ...) \
11107 GMOCK_METHOD8_(typename, , ct, m, __VA_ARGS__)
11108#define MOCK_METHOD9_T_WITH_CALLTYPE(ct, m, ...) \
11109 GMOCK_METHOD9_(typename, , ct, m, __VA_ARGS__)
11110#define MOCK_METHOD10_T_WITH_CALLTYPE(ct, m, ...) \
11111 GMOCK_METHOD10_(typename, , ct, m, __VA_ARGS__)
11112
11113#define MOCK_CONST_METHOD0_T_WITH_CALLTYPE(ct, m, ...) \
11114 GMOCK_METHOD0_(typename, const, ct, m, __VA_ARGS__)
11115#define MOCK_CONST_METHOD1_T_WITH_CALLTYPE(ct, m, ...) \
11116 GMOCK_METHOD1_(typename, const, ct, m, __VA_ARGS__)
11117#define MOCK_CONST_METHOD2_T_WITH_CALLTYPE(ct, m, ...) \
11118 GMOCK_METHOD2_(typename, const, ct, m, __VA_ARGS__)
11119#define MOCK_CONST_METHOD3_T_WITH_CALLTYPE(ct, m, ...) \
11120 GMOCK_METHOD3_(typename, const, ct, m, __VA_ARGS__)
11121#define MOCK_CONST_METHOD4_T_WITH_CALLTYPE(ct, m, ...) \
11122 GMOCK_METHOD4_(typename, const, ct, m, __VA_ARGS__)
11123#define MOCK_CONST_METHOD5_T_WITH_CALLTYPE(ct, m, ...) \
11124 GMOCK_METHOD5_(typename, const, ct, m, __VA_ARGS__)
11125#define MOCK_CONST_METHOD6_T_WITH_CALLTYPE(ct, m, ...) \
11126 GMOCK_METHOD6_(typename, const, ct, m, __VA_ARGS__)
11127#define MOCK_CONST_METHOD7_T_WITH_CALLTYPE(ct, m, ...) \
11128 GMOCK_METHOD7_(typename, const, ct, m, __VA_ARGS__)
11129#define MOCK_CONST_METHOD8_T_WITH_CALLTYPE(ct, m, ...) \
11130 GMOCK_METHOD8_(typename, const, ct, m, __VA_ARGS__)
11131#define MOCK_CONST_METHOD9_T_WITH_CALLTYPE(ct, m, ...) \
11132 GMOCK_METHOD9_(typename, const, ct, m, __VA_ARGS__)
11133#define MOCK_CONST_METHOD10_T_WITH_CALLTYPE(ct, m, ...) \
11134 GMOCK_METHOD10_(typename, const, ct, m, __VA_ARGS__)
11135
11136// A MockFunction<F> class has one mock method whose type is F. It is
11137// useful when you just want your test code to emit some messages and
11138// have Google Mock verify the right messages are sent (and perhaps at
11139// the right times). For example, if you are exercising code:
11140//
11141// Foo(1);
11142// Foo(2);
11143// Foo(3);
11144//
11145// and want to verify that Foo(1) and Foo(3) both invoke
11146// mock.Bar("a"), but Foo(2) doesn't invoke anything, you can write:
11147//
11148// TEST(FooTest, InvokesBarCorrectly) {
11149// MyMock mock;
11150// MockFunction<void(string check_point_name)> check;
11151// {
11152// InSequence s;
11153//
11154// EXPECT_CALL(mock, Bar("a"));
11155// EXPECT_CALL(check, Call("1"));
11156// EXPECT_CALL(check, Call("2"));
11157// EXPECT_CALL(mock, Bar("a"));
11158// }
11159// Foo(1);
11160// check.Call("1");
11161// Foo(2);
11162// check.Call("2");
11163// Foo(3);
11164// }
11165//
11166// The expectation spec says that the first Bar("a") must happen
11167// before check point "1", the second Bar("a") must happen after check
11168// point "2", and nothing should happen between the two check
11169// points. The explicit check points make it easy to tell which
11170// Bar("a") is called by which call to Foo().
11171template <typename F>
11172class MockFunction;
11173
11174template <typename R>
11175class MockFunction<R()> {
11176 public:
11177 MockFunction() {}
11178
11179 MOCK_METHOD0_T(Call, R());
11180
11181 private:
11182 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11183};
11184
11185template <typename R, typename A0>
11186class MockFunction<R(A0)> {
11187 public:
11188 MockFunction() {}
11189
11190 MOCK_METHOD1_T(Call, R(A0));
11191
11192 private:
11193 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11194};
11195
11196template <typename R, typename A0, typename A1>
11197class MockFunction<R(A0, A1)> {
11198 public:
11199 MockFunction() {}
11200
11201 MOCK_METHOD2_T(Call, R(A0, A1));
11202
11203 private:
11204 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11205};
11206
11207template <typename R, typename A0, typename A1, typename A2>
11208class MockFunction<R(A0, A1, A2)> {
11209 public:
11210 MockFunction() {}
11211
11212 MOCK_METHOD3_T(Call, R(A0, A1, A2));
11213
11214 private:
11215 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11216};
11217
11218template <typename R, typename A0, typename A1, typename A2, typename A3>
11219class MockFunction<R(A0, A1, A2, A3)> {
11220 public:
11221 MockFunction() {}
11222
11223 MOCK_METHOD4_T(Call, R(A0, A1, A2, A3));
11224
11225 private:
11226 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11227};
11228
11229template <typename R, typename A0, typename A1, typename A2, typename A3,
11230 typename A4>
11231class MockFunction<R(A0, A1, A2, A3, A4)> {
11232 public:
11233 MockFunction() {}
11234
11235 MOCK_METHOD5_T(Call, R(A0, A1, A2, A3, A4));
11236
11237 private:
11238 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11239};
11240
11241template <typename R, typename A0, typename A1, typename A2, typename A3,
11242 typename A4, typename A5>
11243class MockFunction<R(A0, A1, A2, A3, A4, A5)> {
11244 public:
11245 MockFunction() {}
11246
11247 MOCK_METHOD6_T(Call, R(A0, A1, A2, A3, A4, A5));
11248
11249 private:
11250 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11251};
11252
11253template <typename R, typename A0, typename A1, typename A2, typename A3,
11254 typename A4, typename A5, typename A6>
11255class MockFunction<R(A0, A1, A2, A3, A4, A5, A6)> {
11256 public:
11257 MockFunction() {}
11258
11259 MOCK_METHOD7_T(Call, R(A0, A1, A2, A3, A4, A5, A6));
11260
11261 private:
11262 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11263};
11264
11265template <typename R, typename A0, typename A1, typename A2, typename A3,
11266 typename A4, typename A5, typename A6, typename A7>
11267class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7)> {
11268 public:
11269 MockFunction() {}
11270
11271 MOCK_METHOD8_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7));
11272
11273 private:
11274 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11275};
11276
11277template <typename R, typename A0, typename A1, typename A2, typename A3,
11278 typename A4, typename A5, typename A6, typename A7, typename A8>
11279class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7, A8)> {
11280 public:
11281 MockFunction() {}
11282
11283 MOCK_METHOD9_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7, A8));
11284
11285 private:
11286 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11287};
11288
11289template <typename R, typename A0, typename A1, typename A2, typename A3,
11290 typename A4, typename A5, typename A6, typename A7, typename A8,
11291 typename A9>
11292class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9)> {
11293 public:
11294 MockFunction() {}
11295
11296 MOCK_METHOD10_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9));
11297
11298 private:
11299 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11300};
11301
11302} // namespace testing
11303
11304#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
11305// This file was GENERATED by command:
11306// pump.py gmock-generated-nice-strict.h.pump
11307// DO NOT EDIT BY HAND!!!
11308
11309// Copyright 2008, Google Inc.
11310// All rights reserved.
11311//
11312// Redistribution and use in source and binary forms, with or without
11313// modification, are permitted provided that the following conditions are
11314// met:
11315//
11316// * Redistributions of source code must retain the above copyright
11317// notice, this list of conditions and the following disclaimer.
11318// * Redistributions in binary form must reproduce the above
11319// copyright notice, this list of conditions and the following disclaimer
11320// in the documentation and/or other materials provided with the
11321// distribution.
11322// * Neither the name of Google Inc. nor the names of its
11323// contributors may be used to endorse or promote products derived from
11324// this software without specific prior written permission.
11325//
11326// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
11327// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
11328// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
11329// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
11330// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
11331// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11332// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11333// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11334// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
11335// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
11336// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11337//
11338// Author: wan@google.com (Zhanyong Wan)
11339
11340// Implements class templates NiceMock, NaggyMock, and StrictMock.
11341//
11342// Given a mock class MockFoo that is created using Google Mock,
11343// NiceMock<MockFoo> is a subclass of MockFoo that allows
11344// uninteresting calls (i.e. calls to mock methods that have no
11345// EXPECT_CALL specs), NaggyMock<MockFoo> is a subclass of MockFoo
11346// that prints a warning when an uninteresting call occurs, and
11347// StrictMock<MockFoo> is a subclass of MockFoo that treats all
11348// uninteresting calls as errors.
11349//
11350// Currently a mock is naggy by default, so MockFoo and
11351// NaggyMock<MockFoo> behave like the same. However, we will soon
11352// switch the default behavior of mocks to be nice, as that in general
11353// leads to more maintainable tests. When that happens, MockFoo will
11354// stop behaving like NaggyMock<MockFoo> and start behaving like
11355// NiceMock<MockFoo>.
11356//
11357// NiceMock, NaggyMock, and StrictMock "inherit" the constructors of
11358// their respective base class, with up-to 10 arguments. Therefore
11359// you can write NiceMock<MockFoo>(5, "a") to construct a nice mock
11360// where MockFoo has a constructor that accepts (int, const char*),
11361// for example.
11362//
11363// A known limitation is that NiceMock<MockFoo>, NaggyMock<MockFoo>,
11364// and StrictMock<MockFoo> only works for mock methods defined using
11365// the MOCK_METHOD* family of macros DIRECTLY in the MockFoo class.
11366// If a mock method is defined in a base class of MockFoo, the "nice"
11367// or "strict" modifier may not affect it, depending on the compiler.
11368// In particular, nesting NiceMock, NaggyMock, and StrictMock is NOT
11369// supported.
11370//
11371// Another known limitation is that the constructors of the base mock
11372// cannot have arguments passed by non-const reference, which are
11373// banned by the Google C++ style guide anyway.
11374
11375#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
11376#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
11377
11378
11379namespace testing {
11380
11381template <class MockClass>
11382class NiceMock : public MockClass {
11383 public:
11384 // We don't factor out the constructor body to a common method, as
11385 // we have to avoid a possible clash with members of MockClass.
11386 NiceMock() {
11387 ::testing::Mock::AllowUninterestingCalls(
11388 internal::ImplicitCast_<MockClass*>(this));
11389 }
11390
11391 // C++ doesn't (yet) allow inheritance of constructors, so we have
11392 // to define it for each arity.
11393 template <typename A1>
11394 explicit NiceMock(const A1& a1) : MockClass(a1) {
11395 ::testing::Mock::AllowUninterestingCalls(
11396 internal::ImplicitCast_<MockClass*>(this));
11397 }
11398 template <typename A1, typename A2>
11399 NiceMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {
11400 ::testing::Mock::AllowUninterestingCalls(
11401 internal::ImplicitCast_<MockClass*>(this));
11402 }
11403
11404 template <typename A1, typename A2, typename A3>
11405 NiceMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {
11406 ::testing::Mock::AllowUninterestingCalls(
11407 internal::ImplicitCast_<MockClass*>(this));
11408 }
11409
11410 template <typename A1, typename A2, typename A3, typename A4>
11411 NiceMock(const A1& a1, const A2& a2, const A3& a3,
11412 const A4& a4) : MockClass(a1, a2, a3, a4) {
11413 ::testing::Mock::AllowUninterestingCalls(
11414 internal::ImplicitCast_<MockClass*>(this));
11415 }
11416
11417 template <typename A1, typename A2, typename A3, typename A4, typename A5>
11418 NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11419 const A5& a5) : MockClass(a1, a2, a3, a4, a5) {
11420 ::testing::Mock::AllowUninterestingCalls(
11421 internal::ImplicitCast_<MockClass*>(this));
11422 }
11423
11424 template <typename A1, typename A2, typename A3, typename A4, typename A5,
11425 typename A6>
11426 NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11427 const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {
11428 ::testing::Mock::AllowUninterestingCalls(
11429 internal::ImplicitCast_<MockClass*>(this));
11430 }
11431
11432 template <typename A1, typename A2, typename A3, typename A4, typename A5,
11433 typename A6, typename A7>
11434 NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11435 const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5,
11436 a6, a7) {
11437 ::testing::Mock::AllowUninterestingCalls(
11438 internal::ImplicitCast_<MockClass*>(this));
11439 }
11440
11441 template <typename A1, typename A2, typename A3, typename A4, typename A5,
11442 typename A6, typename A7, typename A8>
11443 NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11444 const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1,
11445 a2, a3, a4, a5, a6, a7, a8) {
11446 ::testing::Mock::AllowUninterestingCalls(
11447 internal::ImplicitCast_<MockClass*>(this));
11448 }
11449
11450 template <typename A1, typename A2, typename A3, typename A4, typename A5,
11451 typename A6, typename A7, typename A8, typename A9>
11452 NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11453 const A5& a5, const A6& a6, const A7& a7, const A8& a8,
11454 const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
11455 ::testing::Mock::AllowUninterestingCalls(
11456 internal::ImplicitCast_<MockClass*>(this));
11457 }
11458
11459 template <typename A1, typename A2, typename A3, typename A4, typename A5,
11460 typename A6, typename A7, typename A8, typename A9, typename A10>
11461 NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11462 const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9,
11463 const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {
11464 ::testing::Mock::AllowUninterestingCalls(
11465 internal::ImplicitCast_<MockClass*>(this));
11466 }
11467
11468 virtual ~NiceMock() {
11469 ::testing::Mock::UnregisterCallReaction(
11470 internal::ImplicitCast_<MockClass*>(this));
11471 }
11472
11473 private:
11474 GTEST_DISALLOW_COPY_AND_ASSIGN_(NiceMock);
11475};
11476
11477template <class MockClass>
11478class NaggyMock : public MockClass {
11479 public:
11480 // We don't factor out the constructor body to a common method, as
11481 // we have to avoid a possible clash with members of MockClass.
11482 NaggyMock() {
11483 ::testing::Mock::WarnUninterestingCalls(
11484 internal::ImplicitCast_<MockClass*>(this));
11485 }
11486
11487 // C++ doesn't (yet) allow inheritance of constructors, so we have
11488 // to define it for each arity.
11489 template <typename A1>
11490 explicit NaggyMock(const A1& a1) : MockClass(a1) {
11491 ::testing::Mock::WarnUninterestingCalls(
11492 internal::ImplicitCast_<MockClass*>(this));
11493 }
11494 template <typename A1, typename A2>
11495 NaggyMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {
11496 ::testing::Mock::WarnUninterestingCalls(
11497 internal::ImplicitCast_<MockClass*>(this));
11498 }
11499
11500 template <typename A1, typename A2, typename A3>
11501 NaggyMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {
11502 ::testing::Mock::WarnUninterestingCalls(
11503 internal::ImplicitCast_<MockClass*>(this));
11504 }
11505
11506 template <typename A1, typename A2, typename A3, typename A4>
11507 NaggyMock(const A1& a1, const A2& a2, const A3& a3,
11508 const A4& a4) : MockClass(a1, a2, a3, a4) {
11509 ::testing::Mock::WarnUninterestingCalls(
11510 internal::ImplicitCast_<MockClass*>(this));
11511 }
11512
11513 template <typename A1, typename A2, typename A3, typename A4, typename A5>
11514 NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11515 const A5& a5) : MockClass(a1, a2, a3, a4, a5) {
11516 ::testing::Mock::WarnUninterestingCalls(
11517 internal::ImplicitCast_<MockClass*>(this));
11518 }
11519
11520 template <typename A1, typename A2, typename A3, typename A4, typename A5,
11521 typename A6>
11522 NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11523 const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {
11524 ::testing::Mock::WarnUninterestingCalls(
11525 internal::ImplicitCast_<MockClass*>(this));
11526 }
11527
11528 template <typename A1, typename A2, typename A3, typename A4, typename A5,
11529 typename A6, typename A7>
11530 NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11531 const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5,
11532 a6, a7) {
11533 ::testing::Mock::WarnUninterestingCalls(
11534 internal::ImplicitCast_<MockClass*>(this));
11535 }
11536
11537 template <typename A1, typename A2, typename A3, typename A4, typename A5,
11538 typename A6, typename A7, typename A8>
11539 NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11540 const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1,
11541 a2, a3, a4, a5, a6, a7, a8) {
11542 ::testing::Mock::WarnUninterestingCalls(
11543 internal::ImplicitCast_<MockClass*>(this));
11544 }
11545
11546 template <typename A1, typename A2, typename A3, typename A4, typename A5,
11547 typename A6, typename A7, typename A8, typename A9>
11548 NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11549 const A5& a5, const A6& a6, const A7& a7, const A8& a8,
11550 const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
11551 ::testing::Mock::WarnUninterestingCalls(
11552 internal::ImplicitCast_<MockClass*>(this));
11553 }
11554
11555 template <typename A1, typename A2, typename A3, typename A4, typename A5,
11556 typename A6, typename A7, typename A8, typename A9, typename A10>
11557 NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11558 const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9,
11559 const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {
11560 ::testing::Mock::WarnUninterestingCalls(
11561 internal::ImplicitCast_<MockClass*>(this));
11562 }
11563
11564 virtual ~NaggyMock() {
11565 ::testing::Mock::UnregisterCallReaction(
11566 internal::ImplicitCast_<MockClass*>(this));
11567 }
11568
11569 private:
11570 GTEST_DISALLOW_COPY_AND_ASSIGN_(NaggyMock);
11571};
11572
11573template <class MockClass>
11574class StrictMock : public MockClass {
11575 public:
11576 // We don't factor out the constructor body to a common method, as
11577 // we have to avoid a possible clash with members of MockClass.
11578 StrictMock() {
11579 ::testing::Mock::FailUninterestingCalls(
11580 internal::ImplicitCast_<MockClass*>(this));
11581 }
11582
11583 // C++ doesn't (yet) allow inheritance of constructors, so we have
11584 // to define it for each arity.
11585 template <typename A1>
11586 explicit StrictMock(const A1& a1) : MockClass(a1) {
11587 ::testing::Mock::FailUninterestingCalls(
11588 internal::ImplicitCast_<MockClass*>(this));
11589 }
11590 template <typename A1, typename A2>
11591 StrictMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {
11592 ::testing::Mock::FailUninterestingCalls(
11593 internal::ImplicitCast_<MockClass*>(this));
11594 }
11595
11596 template <typename A1, typename A2, typename A3>
11597 StrictMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {
11598 ::testing::Mock::FailUninterestingCalls(
11599 internal::ImplicitCast_<MockClass*>(this));
11600 }
11601
11602 template <typename A1, typename A2, typename A3, typename A4>
11603 StrictMock(const A1& a1, const A2& a2, const A3& a3,
11604 const A4& a4) : MockClass(a1, a2, a3, a4) {
11605 ::testing::Mock::FailUninterestingCalls(
11606 internal::ImplicitCast_<MockClass*>(this));
11607 }
11608
11609 template <typename A1, typename A2, typename A3, typename A4, typename A5>
11610 StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11611 const A5& a5) : MockClass(a1, a2, a3, a4, a5) {
11612 ::testing::Mock::FailUninterestingCalls(
11613 internal::ImplicitCast_<MockClass*>(this));
11614 }
11615
11616 template <typename A1, typename A2, typename A3, typename A4, typename A5,
11617 typename A6>
11618 StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11619 const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {
11620 ::testing::Mock::FailUninterestingCalls(
11621 internal::ImplicitCast_<MockClass*>(this));
11622 }
11623
11624 template <typename A1, typename A2, typename A3, typename A4, typename A5,
11625 typename A6, typename A7>
11626 StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11627 const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5,
11628 a6, a7) {
11629 ::testing::Mock::FailUninterestingCalls(
11630 internal::ImplicitCast_<MockClass*>(this));
11631 }
11632
11633 template <typename A1, typename A2, typename A3, typename A4, typename A5,
11634 typename A6, typename A7, typename A8>
11635 StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11636 const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1,
11637 a2, a3, a4, a5, a6, a7, a8) {
11638 ::testing::Mock::FailUninterestingCalls(
11639 internal::ImplicitCast_<MockClass*>(this));
11640 }
11641
11642 template <typename A1, typename A2, typename A3, typename A4, typename A5,
11643 typename A6, typename A7, typename A8, typename A9>
11644 StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11645 const A5& a5, const A6& a6, const A7& a7, const A8& a8,
11646 const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
11647 ::testing::Mock::FailUninterestingCalls(
11648 internal::ImplicitCast_<MockClass*>(this));
11649 }
11650
11651 template <typename A1, typename A2, typename A3, typename A4, typename A5,
11652 typename A6, typename A7, typename A8, typename A9, typename A10>
11653 StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11654 const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9,
11655 const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {
11656 ::testing::Mock::FailUninterestingCalls(
11657 internal::ImplicitCast_<MockClass*>(this));
11658 }
11659
11660 virtual ~StrictMock() {
11661 ::testing::Mock::UnregisterCallReaction(
11662 internal::ImplicitCast_<MockClass*>(this));
11663 }
11664
11665 private:
11666 GTEST_DISALLOW_COPY_AND_ASSIGN_(StrictMock);
11667};
11668
11669// The following specializations catch some (relatively more common)
11670// user errors of nesting nice and strict mocks. They do NOT catch
11671// all possible errors.
11672
11673// These specializations are declared but not defined, as NiceMock,
11674// NaggyMock, and StrictMock cannot be nested.
11675
11676template <typename MockClass>
11677class NiceMock<NiceMock<MockClass> >;
11678template <typename MockClass>
11679class NiceMock<NaggyMock<MockClass> >;
11680template <typename MockClass>
11681class NiceMock<StrictMock<MockClass> >;
11682
11683template <typename MockClass>
11684class NaggyMock<NiceMock<MockClass> >;
11685template <typename MockClass>
11686class NaggyMock<NaggyMock<MockClass> >;
11687template <typename MockClass>
11688class NaggyMock<StrictMock<MockClass> >;
11689
11690template <typename MockClass>
11691class StrictMock<NiceMock<MockClass> >;
11692template <typename MockClass>
11693class StrictMock<NaggyMock<MockClass> >;
11694template <typename MockClass>
11695class StrictMock<StrictMock<MockClass> >;
11696
11697} // namespace testing
11698
11699#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
11700// This file was GENERATED by command:
11701// pump.py gmock-generated-matchers.h.pump
11702// DO NOT EDIT BY HAND!!!
11703
11704// Copyright 2008, Google Inc.
11705// All rights reserved.
11706//
11707// Redistribution and use in source and binary forms, with or without
11708// modification, are permitted provided that the following conditions are
11709// met:
11710//
11711// * Redistributions of source code must retain the above copyright
11712// notice, this list of conditions and the following disclaimer.
11713// * Redistributions in binary form must reproduce the above
11714// copyright notice, this list of conditions and the following disclaimer
11715// in the documentation and/or other materials provided with the
11716// distribution.
11717// * Neither the name of Google Inc. nor the names of its
11718// contributors may be used to endorse or promote products derived from
11719// this software without specific prior written permission.
11720//
11721// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
11722// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
11723// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
11724// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
11725// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
11726// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11727// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11728// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11729// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
11730// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
11731// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11732
11733// Google Mock - a framework for writing C++ mock classes.
11734//
11735// This file implements some commonly used variadic matchers.
11736
11737#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
11738#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
11739
11740#include <iterator>
11741#include <sstream>
11742#include <string>
11743#include <vector>
11744
11745namespace testing {
11746namespace internal {
11747
11748// The type of the i-th (0-based) field of Tuple.
11749#define GMOCK_FIELD_TYPE_(Tuple, i) \
11750 typename ::std::tr1::tuple_element<i, Tuple>::type
11751
11752// TupleFields<Tuple, k0, ..., kn> is for selecting fields from a
11753// tuple of type Tuple. It has two members:
11754//
11755// type: a tuple type whose i-th field is the ki-th field of Tuple.
11756// GetSelectedFields(t): returns fields k0, ..., and kn of t as a tuple.
11757//
11758// For example, in class TupleFields<tuple<bool, char, int>, 2, 0>, we have:
11759//
11760// type is tuple<int, bool>, and
11761// GetSelectedFields(make_tuple(true, 'a', 42)) is (42, true).
11762
11763template <class Tuple, int k0 = -1, int k1 = -1, int k2 = -1, int k3 = -1,
11764 int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1, int k8 = -1,
11765 int k9 = -1>
11766class TupleFields;
11767
11768// This generic version is used when there are 10 selectors.
11769template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6,
11770 int k7, int k8, int k9>
11771class TupleFields {
11772 public:
11773 typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
11774 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
11775 GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4),
11776 GMOCK_FIELD_TYPE_(Tuple, k5), GMOCK_FIELD_TYPE_(Tuple, k6),
11777 GMOCK_FIELD_TYPE_(Tuple, k7), GMOCK_FIELD_TYPE_(Tuple, k8),
11778 GMOCK_FIELD_TYPE_(Tuple, k9)> type;
11779 static type GetSelectedFields(const Tuple& t) {
11780 using ::std::tr1::get;
11781 return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t),
11782 get<k5>(t), get<k6>(t), get<k7>(t), get<k8>(t), get<k9>(t));
11783 }
11784};
11785
11786// The following specialization is used for 0 ~ 9 selectors.
11787
11788template <class Tuple>
11789class TupleFields<Tuple, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1> {
11790 public:
11791 typedef ::std::tr1::tuple<> type;
11792 static type GetSelectedFields(const Tuple& /* t */) {
11793 using ::std::tr1::get;
11794 return type();
11795 }
11796};
11797
11798template <class Tuple, int k0>
11799class TupleFields<Tuple, k0, -1, -1, -1, -1, -1, -1, -1, -1, -1> {
11800 public:
11801 typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0)> type;
11802 static type GetSelectedFields(const Tuple& t) {
11803 using ::std::tr1::get;
11804 return type(get<k0>(t));
11805 }
11806};
11807
11808template <class Tuple, int k0, int k1>
11809class TupleFields<Tuple, k0, k1, -1, -1, -1, -1, -1, -1, -1, -1> {
11810 public:
11811 typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
11812 GMOCK_FIELD_TYPE_(Tuple, k1)> type;
11813 static type GetSelectedFields(const Tuple& t) {
11814 using ::std::tr1::get;
11815 return type(get<k0>(t), get<k1>(t));
11816 }
11817};
11818
11819template <class Tuple, int k0, int k1, int k2>
11820class TupleFields<Tuple, k0, k1, k2, -1, -1, -1, -1, -1, -1, -1> {
11821 public:
11822 typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
11823 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2)> type;
11824 static type GetSelectedFields(const Tuple& t) {
11825 using ::std::tr1::get;
11826 return type(get<k0>(t), get<k1>(t), get<k2>(t));
11827 }
11828};
11829
11830template <class Tuple, int k0, int k1, int k2, int k3>
11831class TupleFields<Tuple, k0, k1, k2, k3, -1, -1, -1, -1, -1, -1> {
11832 public:
11833 typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
11834 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
11835 GMOCK_FIELD_TYPE_(Tuple, k3)> type;
11836 static type GetSelectedFields(const Tuple& t) {
11837 using ::std::tr1::get;
11838 return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t));
11839 }
11840};
11841
11842template <class Tuple, int k0, int k1, int k2, int k3, int k4>
11843class TupleFields<Tuple, k0, k1, k2, k3, k4, -1, -1, -1, -1, -1> {
11844 public:
11845 typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
11846 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
11847 GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4)> type;
11848 static type GetSelectedFields(const Tuple& t) {
11849 using ::std::tr1::get;
11850 return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t));
11851 }
11852};
11853
11854template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5>
11855class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, -1, -1, -1, -1> {
11856 public:
11857 typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
11858 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
11859 GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4),
11860 GMOCK_FIELD_TYPE_(Tuple, k5)> type;
11861 static type GetSelectedFields(const Tuple& t) {
11862 using ::std::tr1::get;
11863 return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t),
11864 get<k5>(t));
11865 }
11866};
11867
11868template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6>
11869class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, k6, -1, -1, -1> {
11870 public:
11871 typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
11872 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
11873 GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4),
11874 GMOCK_FIELD_TYPE_(Tuple, k5), GMOCK_FIELD_TYPE_(Tuple, k6)> type;
11875 static type GetSelectedFields(const Tuple& t) {
11876 using ::std::tr1::get;
11877 return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t),
11878 get<k5>(t), get<k6>(t));
11879 }
11880};
11881
11882template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6,
11883 int k7>
11884class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, k6, k7, -1, -1> {
11885 public:
11886 typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
11887 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
11888 GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4),
11889 GMOCK_FIELD_TYPE_(Tuple, k5), GMOCK_FIELD_TYPE_(Tuple, k6),
11890 GMOCK_FIELD_TYPE_(Tuple, k7)> type;
11891 static type GetSelectedFields(const Tuple& t) {
11892 using ::std::tr1::get;
11893 return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t),
11894 get<k5>(t), get<k6>(t), get<k7>(t));
11895 }
11896};
11897
11898template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6,
11899 int k7, int k8>
11900class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, k6, k7, k8, -1> {
11901 public:
11902 typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
11903 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
11904 GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4),
11905 GMOCK_FIELD_TYPE_(Tuple, k5), GMOCK_FIELD_TYPE_(Tuple, k6),
11906 GMOCK_FIELD_TYPE_(Tuple, k7), GMOCK_FIELD_TYPE_(Tuple, k8)> type;
11907 static type GetSelectedFields(const Tuple& t) {
11908 using ::std::tr1::get;
11909 return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t),
11910 get<k5>(t), get<k6>(t), get<k7>(t), get<k8>(t));
11911 }
11912};
11913
11914#undef GMOCK_FIELD_TYPE_
11915
11916// Implements the Args() matcher.
11917template <class ArgsTuple, int k0 = -1, int k1 = -1, int k2 = -1, int k3 = -1,
11918 int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1, int k8 = -1,
11919 int k9 = -1>
11920class ArgsMatcherImpl : public MatcherInterface<ArgsTuple> {
11921 public:
11922 // ArgsTuple may have top-level const or reference modifiers.
11923 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(ArgsTuple) RawArgsTuple;
11924 typedef typename internal::TupleFields<RawArgsTuple, k0, k1, k2, k3, k4, k5,
11925 k6, k7, k8, k9>::type SelectedArgs;
11926 typedef Matcher<const SelectedArgs&> MonomorphicInnerMatcher;
11927
11928 template <typename InnerMatcher>
11929 explicit ArgsMatcherImpl(const InnerMatcher& inner_matcher)
11930 : inner_matcher_(SafeMatcherCast<const SelectedArgs&>(inner_matcher)) {}
11931
11932 virtual bool MatchAndExplain(ArgsTuple args,
11933 MatchResultListener* listener) const {
11934 const SelectedArgs& selected_args = GetSelectedArgs(args);
11935 if (!listener->IsInterested())
11936 return inner_matcher_.Matches(selected_args);
11937
11938 PrintIndices(listener->stream());
11939 *listener << "are " << PrintToString(selected_args);
11940
11941 StringMatchResultListener inner_listener;
11942 const bool match = inner_matcher_.MatchAndExplain(selected_args,
11943 &inner_listener);
11944 PrintIfNotEmpty(inner_listener.str(), listener->stream());
11945 return match;
11946 }
11947
11948 virtual void DescribeTo(::std::ostream* os) const {
11949 *os << "are a tuple ";
11950 PrintIndices(os);
11951 inner_matcher_.DescribeTo(os);
11952 }
11953
11954 virtual void DescribeNegationTo(::std::ostream* os) const {
11955 *os << "are a tuple ";
11956 PrintIndices(os);
11957 inner_matcher_.DescribeNegationTo(os);
11958 }
11959
11960 private:
11961 static SelectedArgs GetSelectedArgs(ArgsTuple args) {
11962 return TupleFields<RawArgsTuple, k0, k1, k2, k3, k4, k5, k6, k7, k8,
11963 k9>::GetSelectedFields(args);
11964 }
11965
11966 // Prints the indices of the selected fields.
11967 static void PrintIndices(::std::ostream* os) {
11968 *os << "whose fields (";
11969 const int indices[10] = { k0, k1, k2, k3, k4, k5, k6, k7, k8, k9 };
11970 for (int i = 0; i < 10; i++) {
11971 if (indices[i] < 0)
11972 break;
11973
11974 if (i >= 1)
11975 *os << ", ";
11976
11977 *os << "#" << indices[i];
11978 }
11979 *os << ") ";
11980 }
11981
11982 const MonomorphicInnerMatcher inner_matcher_;
11983
11984 GTEST_DISALLOW_ASSIGN_(ArgsMatcherImpl);
11985};
11986
11987template <class InnerMatcher, int k0 = -1, int k1 = -1, int k2 = -1,
11988 int k3 = -1, int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1,
11989 int k8 = -1, int k9 = -1>
11990class ArgsMatcher {
11991 public:
11992 explicit ArgsMatcher(const InnerMatcher& inner_matcher)
11993 : inner_matcher_(inner_matcher) {}
11994
11995 template <typename ArgsTuple>
11996 operator Matcher<ArgsTuple>() const {
11997 return MakeMatcher(new ArgsMatcherImpl<ArgsTuple, k0, k1, k2, k3, k4, k5,
11998 k6, k7, k8, k9>(inner_matcher_));
11999 }
12000
12001 private:
12002 const InnerMatcher inner_matcher_;
12003
12004 GTEST_DISALLOW_ASSIGN_(ArgsMatcher);
12005};
12006
12007// A set of metafunctions for computing the result type of AllOf.
12008// AllOf(m1, ..., mN) returns
12009// AllOfResultN<decltype(m1), ..., decltype(mN)>::type.
12010
12011// Although AllOf isn't defined for one argument, AllOfResult1 is defined
12012// to simplify the implementation.
12013template <typename M1>
12014struct AllOfResult1 {
12015 typedef M1 type;
12016};
12017
12018template <typename M1, typename M2>
12019struct AllOfResult2 {
12020 typedef BothOfMatcher<
12021 typename AllOfResult1<M1>::type,
12022 typename AllOfResult1<M2>::type
12023 > type;
12024};
12025
12026template <typename M1, typename M2, typename M3>
12027struct AllOfResult3 {
12028 typedef BothOfMatcher<
12029 typename AllOfResult1<M1>::type,
12030 typename AllOfResult2<M2, M3>::type
12031 > type;
12032};
12033
12034template <typename M1, typename M2, typename M3, typename M4>
12035struct AllOfResult4 {
12036 typedef BothOfMatcher<
12037 typename AllOfResult2<M1, M2>::type,
12038 typename AllOfResult2<M3, M4>::type
12039 > type;
12040};
12041
12042template <typename M1, typename M2, typename M3, typename M4, typename M5>
12043struct AllOfResult5 {
12044 typedef BothOfMatcher<
12045 typename AllOfResult2<M1, M2>::type,
12046 typename AllOfResult3<M3, M4, M5>::type
12047 > type;
12048};
12049
12050template <typename M1, typename M2, typename M3, typename M4, typename M5,
12051 typename M6>
12052struct AllOfResult6 {
12053 typedef BothOfMatcher<
12054 typename AllOfResult3<M1, M2, M3>::type,
12055 typename AllOfResult3<M4, M5, M6>::type
12056 > type;
12057};
12058
12059template <typename M1, typename M2, typename M3, typename M4, typename M5,
12060 typename M6, typename M7>
12061struct AllOfResult7 {
12062 typedef BothOfMatcher<
12063 typename AllOfResult3<M1, M2, M3>::type,
12064 typename AllOfResult4<M4, M5, M6, M7>::type
12065 > type;
12066};
12067
12068template <typename M1, typename M2, typename M3, typename M4, typename M5,
12069 typename M6, typename M7, typename M8>
12070struct AllOfResult8 {
12071 typedef BothOfMatcher<
12072 typename AllOfResult4<M1, M2, M3, M4>::type,
12073 typename AllOfResult4<M5, M6, M7, M8>::type
12074 > type;
12075};
12076
12077template <typename M1, typename M2, typename M3, typename M4, typename M5,
12078 typename M6, typename M7, typename M8, typename M9>
12079struct AllOfResult9 {
12080 typedef BothOfMatcher<
12081 typename AllOfResult4<M1, M2, M3, M4>::type,
12082 typename AllOfResult5<M5, M6, M7, M8, M9>::type
12083 > type;
12084};
12085
12086template <typename M1, typename M2, typename M3, typename M4, typename M5,
12087 typename M6, typename M7, typename M8, typename M9, typename M10>
12088struct AllOfResult10 {
12089 typedef BothOfMatcher<
12090 typename AllOfResult5<M1, M2, M3, M4, M5>::type,
12091 typename AllOfResult5<M6, M7, M8, M9, M10>::type
12092 > type;
12093};
12094
12095// A set of metafunctions for computing the result type of AnyOf.
12096// AnyOf(m1, ..., mN) returns
12097// AnyOfResultN<decltype(m1), ..., decltype(mN)>::type.
12098
12099// Although AnyOf isn't defined for one argument, AnyOfResult1 is defined
12100// to simplify the implementation.
12101template <typename M1>
12102struct AnyOfResult1 {
12103 typedef M1 type;
12104};
12105
12106template <typename M1, typename M2>
12107struct AnyOfResult2 {
12108 typedef EitherOfMatcher<
12109 typename AnyOfResult1<M1>::type,
12110 typename AnyOfResult1<M2>::type
12111 > type;
12112};
12113
12114template <typename M1, typename M2, typename M3>
12115struct AnyOfResult3 {
12116 typedef EitherOfMatcher<
12117 typename AnyOfResult1<M1>::type,
12118 typename AnyOfResult2<M2, M3>::type
12119 > type;
12120};
12121
12122template <typename M1, typename M2, typename M3, typename M4>
12123struct AnyOfResult4 {
12124 typedef EitherOfMatcher<
12125 typename AnyOfResult2<M1, M2>::type,
12126 typename AnyOfResult2<M3, M4>::type
12127 > type;
12128};
12129
12130template <typename M1, typename M2, typename M3, typename M4, typename M5>
12131struct AnyOfResult5 {
12132 typedef EitherOfMatcher<
12133 typename AnyOfResult2<M1, M2>::type,
12134 typename AnyOfResult3<M3, M4, M5>::type
12135 > type;
12136};
12137
12138template <typename M1, typename M2, typename M3, typename M4, typename M5,
12139 typename M6>
12140struct AnyOfResult6 {
12141 typedef EitherOfMatcher<
12142 typename AnyOfResult3<M1, M2, M3>::type,
12143 typename AnyOfResult3<M4, M5, M6>::type
12144 > type;
12145};
12146
12147template <typename M1, typename M2, typename M3, typename M4, typename M5,
12148 typename M6, typename M7>
12149struct AnyOfResult7 {
12150 typedef EitherOfMatcher<
12151 typename AnyOfResult3<M1, M2, M3>::type,
12152 typename AnyOfResult4<M4, M5, M6, M7>::type
12153 > type;
12154};
12155
12156template <typename M1, typename M2, typename M3, typename M4, typename M5,
12157 typename M6, typename M7, typename M8>
12158struct AnyOfResult8 {
12159 typedef EitherOfMatcher<
12160 typename AnyOfResult4<M1, M2, M3, M4>::type,
12161 typename AnyOfResult4<M5, M6, M7, M8>::type
12162 > type;
12163};
12164
12165template <typename M1, typename M2, typename M3, typename M4, typename M5,
12166 typename M6, typename M7, typename M8, typename M9>
12167struct AnyOfResult9 {
12168 typedef EitherOfMatcher<
12169 typename AnyOfResult4<M1, M2, M3, M4>::type,
12170 typename AnyOfResult5<M5, M6, M7, M8, M9>::type
12171 > type;
12172};
12173
12174template <typename M1, typename M2, typename M3, typename M4, typename M5,
12175 typename M6, typename M7, typename M8, typename M9, typename M10>
12176struct AnyOfResult10 {
12177 typedef EitherOfMatcher<
12178 typename AnyOfResult5<M1, M2, M3, M4, M5>::type,
12179 typename AnyOfResult5<M6, M7, M8, M9, M10>::type
12180 > type;
12181};
12182
12183} // namespace internal
12184
12185// Args<N1, N2, ..., Nk>(a_matcher) matches a tuple if the selected
12186// fields of it matches a_matcher. C++ doesn't support default
12187// arguments for function templates, so we have to overload it.
12188template <typename InnerMatcher>
12189inline internal::ArgsMatcher<InnerMatcher>
12190Args(const InnerMatcher& matcher) {
12191 return internal::ArgsMatcher<InnerMatcher>(matcher);
12192}
12193
12194template <int k1, typename InnerMatcher>
12195inline internal::ArgsMatcher<InnerMatcher, k1>
12196Args(const InnerMatcher& matcher) {
12197 return internal::ArgsMatcher<InnerMatcher, k1>(matcher);
12198}
12199
12200template <int k1, int k2, typename InnerMatcher>
12201inline internal::ArgsMatcher<InnerMatcher, k1, k2>
12202Args(const InnerMatcher& matcher) {
12203 return internal::ArgsMatcher<InnerMatcher, k1, k2>(matcher);
12204}
12205
12206template <int k1, int k2, int k3, typename InnerMatcher>
12207inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3>
12208Args(const InnerMatcher& matcher) {
12209 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3>(matcher);
12210}
12211
12212template <int k1, int k2, int k3, int k4, typename InnerMatcher>
12213inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4>
12214Args(const InnerMatcher& matcher) {
12215 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4>(matcher);
12216}
12217
12218template <int k1, int k2, int k3, int k4, int k5, typename InnerMatcher>
12219inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5>
12220Args(const InnerMatcher& matcher) {
12221 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5>(matcher);
12222}
12223
12224template <int k1, int k2, int k3, int k4, int k5, int k6, typename InnerMatcher>
12225inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6>
12226Args(const InnerMatcher& matcher) {
12227 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6>(matcher);
12228}
12229
12230template <int k1, int k2, int k3, int k4, int k5, int k6, int k7,
12231 typename InnerMatcher>
12232inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7>
12233Args(const InnerMatcher& matcher) {
12234 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6,
12235 k7>(matcher);
12236}
12237
12238template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
12239 typename InnerMatcher>
12240inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8>
12241Args(const InnerMatcher& matcher) {
12242 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7,
12243 k8>(matcher);
12244}
12245
12246template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
12247 int k9, typename InnerMatcher>
12248inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8, k9>
12249Args(const InnerMatcher& matcher) {
12250 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8,
12251 k9>(matcher);
12252}
12253
12254template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
12255 int k9, int k10, typename InnerMatcher>
12256inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8, k9,
12257 k10>
12258Args(const InnerMatcher& matcher) {
12259 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8,
12260 k9, k10>(matcher);
12261}
12262
12263// ElementsAre(e_1, e_2, ... e_n) matches an STL-style container with
12264// n elements, where the i-th element in the container must
12265// match the i-th argument in the list. Each argument of
12266// ElementsAre() can be either a value or a matcher. We support up to
12267// 10 arguments.
12268//
12269// The use of DecayArray in the implementation allows ElementsAre()
12270// to accept string literals, whose type is const char[N], but we
12271// want to treat them as const char*.
12272//
12273// NOTE: Since ElementsAre() cares about the order of the elements, it
12274// must not be used with containers whose elements's order is
12275// undefined (e.g. hash_map).
12276
12277inline internal::ElementsAreMatcher<
12278 std::tr1::tuple<> >
12279ElementsAre() {
12280 typedef std::tr1::tuple<> Args;
12281 return internal::ElementsAreMatcher<Args>(Args());
12282}
12283
12284template <typename T1>
12285inline internal::ElementsAreMatcher<
12286 std::tr1::tuple<
12287 typename internal::DecayArray<T1>::type> >
12288ElementsAre(const T1& e1) {
12289 typedef std::tr1::tuple<
12290 typename internal::DecayArray<T1>::type> Args;
12291 return internal::ElementsAreMatcher<Args>(Args(e1));
12292}
12293
12294template <typename T1, typename T2>
12295inline internal::ElementsAreMatcher<
12296 std::tr1::tuple<
12297 typename internal::DecayArray<T1>::type,
12298 typename internal::DecayArray<T2>::type> >
12299ElementsAre(const T1& e1, const T2& e2) {
12300 typedef std::tr1::tuple<
12301 typename internal::DecayArray<T1>::type,
12302 typename internal::DecayArray<T2>::type> Args;
12303 return internal::ElementsAreMatcher<Args>(Args(e1, e2));
12304}
12305
12306template <typename T1, typename T2, typename T3>
12307inline internal::ElementsAreMatcher<
12308 std::tr1::tuple<
12309 typename internal::DecayArray<T1>::type,
12310 typename internal::DecayArray<T2>::type,
12311 typename internal::DecayArray<T3>::type> >
12312ElementsAre(const T1& e1, const T2& e2, const T3& e3) {
12313 typedef std::tr1::tuple<
12314 typename internal::DecayArray<T1>::type,
12315 typename internal::DecayArray<T2>::type,
12316 typename internal::DecayArray<T3>::type> Args;
12317 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3));
12318}
12319
12320template <typename T1, typename T2, typename T3, typename T4>
12321inline internal::ElementsAreMatcher<
12322 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> >
12327ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4) {
12328 typedef std::tr1::tuple<
12329 typename internal::DecayArray<T1>::type,
12330 typename internal::DecayArray<T2>::type,
12331 typename internal::DecayArray<T3>::type,
12332 typename internal::DecayArray<T4>::type> Args;
12333 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4));
12334}
12335
12336template <typename T1, typename T2, typename T3, typename T4, typename T5>
12337inline internal::ElementsAreMatcher<
12338 std::tr1::tuple<
12339 typename internal::DecayArray<T1>::type,
12340 typename internal::DecayArray<T2>::type,
12341 typename internal::DecayArray<T3>::type,
12342 typename internal::DecayArray<T4>::type,
12343 typename internal::DecayArray<T5>::type> >
12344ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
12345 const T5& e5) {
12346 typedef std::tr1::tuple<
12347 typename internal::DecayArray<T1>::type,
12348 typename internal::DecayArray<T2>::type,
12349 typename internal::DecayArray<T3>::type,
12350 typename internal::DecayArray<T4>::type,
12351 typename internal::DecayArray<T5>::type> Args;
12352 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5));
12353}
12354
12355template <typename T1, typename T2, typename T3, typename T4, typename T5,
12356 typename T6>
12357inline internal::ElementsAreMatcher<
12358 std::tr1::tuple<
12359 typename internal::DecayArray<T1>::type,
12360 typename internal::DecayArray<T2>::type,
12361 typename internal::DecayArray<T3>::type,
12362 typename internal::DecayArray<T4>::type,
12363 typename internal::DecayArray<T5>::type,
12364 typename internal::DecayArray<T6>::type> >
12365ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
12366 const T5& e5, const T6& e6) {
12367 typedef std::tr1::tuple<
12368 typename internal::DecayArray<T1>::type,
12369 typename internal::DecayArray<T2>::type,
12370 typename internal::DecayArray<T3>::type,
12371 typename internal::DecayArray<T4>::type,
12372 typename internal::DecayArray<T5>::type,
12373 typename internal::DecayArray<T6>::type> Args;
12374 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, e6));
12375}
12376
12377template <typename T1, typename T2, typename T3, typename T4, typename T5,
12378 typename T6, typename T7>
12379inline internal::ElementsAreMatcher<
12380 std::tr1::tuple<
12381 typename internal::DecayArray<T1>::type,
12382 typename internal::DecayArray<T2>::type,
12383 typename internal::DecayArray<T3>::type,
12384 typename internal::DecayArray<T4>::type,
12385 typename internal::DecayArray<T5>::type,
12386 typename internal::DecayArray<T6>::type,
12387 typename internal::DecayArray<T7>::type> >
12388ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
12389 const T5& e5, const T6& e6, const T7& e7) {
12390 typedef std::tr1::tuple<
12391 typename internal::DecayArray<T1>::type,
12392 typename internal::DecayArray<T2>::type,
12393 typename internal::DecayArray<T3>::type,
12394 typename internal::DecayArray<T4>::type,
12395 typename internal::DecayArray<T5>::type,
12396 typename internal::DecayArray<T6>::type,
12397 typename internal::DecayArray<T7>::type> Args;
12398 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, e6, e7));
12399}
12400
12401template <typename T1, typename T2, typename T3, typename T4, typename T5,
12402 typename T6, typename T7, typename T8>
12403inline internal::ElementsAreMatcher<
12404 std::tr1::tuple<
12405 typename internal::DecayArray<T1>::type,
12406 typename internal::DecayArray<T2>::type,
12407 typename internal::DecayArray<T3>::type,
12408 typename internal::DecayArray<T4>::type,
12409 typename internal::DecayArray<T5>::type,
12410 typename internal::DecayArray<T6>::type,
12411 typename internal::DecayArray<T7>::type,
12412 typename internal::DecayArray<T8>::type> >
12413ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
12414 const T5& e5, const T6& e6, const T7& e7, const T8& e8) {
12415 typedef std::tr1::tuple<
12416 typename internal::DecayArray<T1>::type,
12417 typename internal::DecayArray<T2>::type,
12418 typename internal::DecayArray<T3>::type,
12419 typename internal::DecayArray<T4>::type,
12420 typename internal::DecayArray<T5>::type,
12421 typename internal::DecayArray<T6>::type,
12422 typename internal::DecayArray<T7>::type,
12423 typename internal::DecayArray<T8>::type> Args;
12424 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, e6, e7,
12425 e8));
12426}
12427
12428template <typename T1, typename T2, typename T3, typename T4, typename T5,
12429 typename T6, typename T7, typename T8, typename T9>
12430inline internal::ElementsAreMatcher<
12431 std::tr1::tuple<
12432 typename internal::DecayArray<T1>::type,
12433 typename internal::DecayArray<T2>::type,
12434 typename internal::DecayArray<T3>::type,
12435 typename internal::DecayArray<T4>::type,
12436 typename internal::DecayArray<T5>::type,
12437 typename internal::DecayArray<T6>::type,
12438 typename internal::DecayArray<T7>::type,
12439 typename internal::DecayArray<T8>::type,
12440 typename internal::DecayArray<T9>::type> >
12441ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
12442 const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9) {
12443 typedef std::tr1::tuple<
12444 typename internal::DecayArray<T1>::type,
12445 typename internal::DecayArray<T2>::type,
12446 typename internal::DecayArray<T3>::type,
12447 typename internal::DecayArray<T4>::type,
12448 typename internal::DecayArray<T5>::type,
12449 typename internal::DecayArray<T6>::type,
12450 typename internal::DecayArray<T7>::type,
12451 typename internal::DecayArray<T8>::type,
12452 typename internal::DecayArray<T9>::type> Args;
12453 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, e6, e7,
12454 e8, e9));
12455}
12456
12457template <typename T1, typename T2, typename T3, typename T4, typename T5,
12458 typename T6, typename T7, typename T8, typename T9, typename T10>
12459inline internal::ElementsAreMatcher<
12460 std::tr1::tuple<
12461 typename internal::DecayArray<T1>::type,
12462 typename internal::DecayArray<T2>::type,
12463 typename internal::DecayArray<T3>::type,
12464 typename internal::DecayArray<T4>::type,
12465 typename internal::DecayArray<T5>::type,
12466 typename internal::DecayArray<T6>::type,
12467 typename internal::DecayArray<T7>::type,
12468 typename internal::DecayArray<T8>::type,
12469 typename internal::DecayArray<T9>::type,
12470 typename internal::DecayArray<T10>::type> >
12471ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
12472 const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9,
12473 const T10& e10) {
12474 typedef std::tr1::tuple<
12475 typename internal::DecayArray<T1>::type,
12476 typename internal::DecayArray<T2>::type,
12477 typename internal::DecayArray<T3>::type,
12478 typename internal::DecayArray<T4>::type,
12479 typename internal::DecayArray<T5>::type,
12480 typename internal::DecayArray<T6>::type,
12481 typename internal::DecayArray<T7>::type,
12482 typename internal::DecayArray<T8>::type,
12483 typename internal::DecayArray<T9>::type,
12484 typename internal::DecayArray<T10>::type> Args;
12485 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, e6, e7,
12486 e8, e9, e10));
12487}
12488
12489// UnorderedElementsAre(e_1, e_2, ..., e_n) is an ElementsAre extension
12490// that matches n elements in any order. We support up to n=10 arguments.
12491
12492inline internal::UnorderedElementsAreMatcher<
12493 std::tr1::tuple<> >
12494UnorderedElementsAre() {
12495 typedef std::tr1::tuple<> Args;
12496 return internal::UnorderedElementsAreMatcher<Args>(Args());
12497}
12498
12499template <typename T1>
12500inline internal::UnorderedElementsAreMatcher<
12501 std::tr1::tuple<
12502 typename internal::DecayArray<T1>::type> >
12503UnorderedElementsAre(const T1& e1) {
12504 typedef std::tr1::tuple<
12505 typename internal::DecayArray<T1>::type> Args;
12506 return internal::UnorderedElementsAreMatcher<Args>(Args(e1));
12507}
12508
12509template <typename T1, typename T2>
12510inline internal::UnorderedElementsAreMatcher<
12511 std::tr1::tuple<
12512 typename internal::DecayArray<T1>::type,
12513 typename internal::DecayArray<T2>::type> >
12514UnorderedElementsAre(const T1& e1, const T2& e2) {
12515 typedef std::tr1::tuple<
12516 typename internal::DecayArray<T1>::type,
12517 typename internal::DecayArray<T2>::type> Args;
12518 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2));
12519}
12520
12521template <typename T1, typename T2, typename T3>
12522inline internal::UnorderedElementsAreMatcher<
12523 std::tr1::tuple<
12524 typename internal::DecayArray<T1>::type,
12525 typename internal::DecayArray<T2>::type,
12526 typename internal::DecayArray<T3>::type> >
12527UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3) {
12528 typedef std::tr1::tuple<
12529 typename internal::DecayArray<T1>::type,
12530 typename internal::DecayArray<T2>::type,
12531 typename internal::DecayArray<T3>::type> Args;
12532 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3));
12533}
12534
12535template <typename T1, typename T2, typename T3, typename T4>
12536inline internal::UnorderedElementsAreMatcher<
12537 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> >
12542UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4) {
12543 typedef std::tr1::tuple<
12544 typename internal::DecayArray<T1>::type,
12545 typename internal::DecayArray<T2>::type,
12546 typename internal::DecayArray<T3>::type,
12547 typename internal::DecayArray<T4>::type> Args;
12548 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4));
12549}
12550
12551template <typename T1, typename T2, typename T3, typename T4, typename T5>
12552inline internal::UnorderedElementsAreMatcher<
12553 std::tr1::tuple<
12554 typename internal::DecayArray<T1>::type,
12555 typename internal::DecayArray<T2>::type,
12556 typename internal::DecayArray<T3>::type,
12557 typename internal::DecayArray<T4>::type,
12558 typename internal::DecayArray<T5>::type> >
12559UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
12560 const T5& e5) {
12561 typedef std::tr1::tuple<
12562 typename internal::DecayArray<T1>::type,
12563 typename internal::DecayArray<T2>::type,
12564 typename internal::DecayArray<T3>::type,
12565 typename internal::DecayArray<T4>::type,
12566 typename internal::DecayArray<T5>::type> Args;
12567 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5));
12568}
12569
12570template <typename T1, typename T2, typename T3, typename T4, typename T5,
12571 typename T6>
12572inline internal::UnorderedElementsAreMatcher<
12573 std::tr1::tuple<
12574 typename internal::DecayArray<T1>::type,
12575 typename internal::DecayArray<T2>::type,
12576 typename internal::DecayArray<T3>::type,
12577 typename internal::DecayArray<T4>::type,
12578 typename internal::DecayArray<T5>::type,
12579 typename internal::DecayArray<T6>::type> >
12580UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
12581 const T5& e5, const T6& e6) {
12582 typedef std::tr1::tuple<
12583 typename internal::DecayArray<T1>::type,
12584 typename internal::DecayArray<T2>::type,
12585 typename internal::DecayArray<T3>::type,
12586 typename internal::DecayArray<T4>::type,
12587 typename internal::DecayArray<T5>::type,
12588 typename internal::DecayArray<T6>::type> Args;
12589 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5,
12590 e6));
12591}
12592
12593template <typename T1, typename T2, typename T3, typename T4, typename T5,
12594 typename T6, typename T7>
12595inline internal::UnorderedElementsAreMatcher<
12596 std::tr1::tuple<
12597 typename internal::DecayArray<T1>::type,
12598 typename internal::DecayArray<T2>::type,
12599 typename internal::DecayArray<T3>::type,
12600 typename internal::DecayArray<T4>::type,
12601 typename internal::DecayArray<T5>::type,
12602 typename internal::DecayArray<T6>::type,
12603 typename internal::DecayArray<T7>::type> >
12604UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
12605 const T5& e5, const T6& e6, const T7& e7) {
12606 typedef std::tr1::tuple<
12607 typename internal::DecayArray<T1>::type,
12608 typename internal::DecayArray<T2>::type,
12609 typename internal::DecayArray<T3>::type,
12610 typename internal::DecayArray<T4>::type,
12611 typename internal::DecayArray<T5>::type,
12612 typename internal::DecayArray<T6>::type,
12613 typename internal::DecayArray<T7>::type> Args;
12614 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5,
12615 e6, e7));
12616}
12617
12618template <typename T1, typename T2, typename T3, typename T4, typename T5,
12619 typename T6, typename T7, typename T8>
12620inline internal::UnorderedElementsAreMatcher<
12621 std::tr1::tuple<
12622 typename internal::DecayArray<T1>::type,
12623 typename internal::DecayArray<T2>::type,
12624 typename internal::DecayArray<T3>::type,
12625 typename internal::DecayArray<T4>::type,
12626 typename internal::DecayArray<T5>::type,
12627 typename internal::DecayArray<T6>::type,
12628 typename internal::DecayArray<T7>::type,
12629 typename internal::DecayArray<T8>::type> >
12630UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
12631 const T5& e5, const T6& e6, const T7& e7, const T8& e8) {
12632 typedef std::tr1::tuple<
12633 typename internal::DecayArray<T1>::type,
12634 typename internal::DecayArray<T2>::type,
12635 typename internal::DecayArray<T3>::type,
12636 typename internal::DecayArray<T4>::type,
12637 typename internal::DecayArray<T5>::type,
12638 typename internal::DecayArray<T6>::type,
12639 typename internal::DecayArray<T7>::type,
12640 typename internal::DecayArray<T8>::type> Args;
12641 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5,
12642 e6, e7, e8));
12643}
12644
12645template <typename T1, typename T2, typename T3, typename T4, typename T5,
12646 typename T6, typename T7, typename T8, typename T9>
12647inline internal::UnorderedElementsAreMatcher<
12648 std::tr1::tuple<
12649 typename internal::DecayArray<T1>::type,
12650 typename internal::DecayArray<T2>::type,
12651 typename internal::DecayArray<T3>::type,
12652 typename internal::DecayArray<T4>::type,
12653 typename internal::DecayArray<T5>::type,
12654 typename internal::DecayArray<T6>::type,
12655 typename internal::DecayArray<T7>::type,
12656 typename internal::DecayArray<T8>::type,
12657 typename internal::DecayArray<T9>::type> >
12658UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
12659 const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9) {
12660 typedef std::tr1::tuple<
12661 typename internal::DecayArray<T1>::type,
12662 typename internal::DecayArray<T2>::type,
12663 typename internal::DecayArray<T3>::type,
12664 typename internal::DecayArray<T4>::type,
12665 typename internal::DecayArray<T5>::type,
12666 typename internal::DecayArray<T6>::type,
12667 typename internal::DecayArray<T7>::type,
12668 typename internal::DecayArray<T8>::type,
12669 typename internal::DecayArray<T9>::type> Args;
12670 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5,
12671 e6, e7, e8, e9));
12672}
12673
12674template <typename T1, typename T2, typename T3, typename T4, typename T5,
12675 typename T6, typename T7, typename T8, typename T9, typename T10>
12676inline internal::UnorderedElementsAreMatcher<
12677 std::tr1::tuple<
12678 typename internal::DecayArray<T1>::type,
12679 typename internal::DecayArray<T2>::type,
12680 typename internal::DecayArray<T3>::type,
12681 typename internal::DecayArray<T4>::type,
12682 typename internal::DecayArray<T5>::type,
12683 typename internal::DecayArray<T6>::type,
12684 typename internal::DecayArray<T7>::type,
12685 typename internal::DecayArray<T8>::type,
12686 typename internal::DecayArray<T9>::type,
12687 typename internal::DecayArray<T10>::type> >
12688UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
12689 const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9,
12690 const T10& e10) {
12691 typedef std::tr1::tuple<
12692 typename internal::DecayArray<T1>::type,
12693 typename internal::DecayArray<T2>::type,
12694 typename internal::DecayArray<T3>::type,
12695 typename internal::DecayArray<T4>::type,
12696 typename internal::DecayArray<T5>::type,
12697 typename internal::DecayArray<T6>::type,
12698 typename internal::DecayArray<T7>::type,
12699 typename internal::DecayArray<T8>::type,
12700 typename internal::DecayArray<T9>::type,
12701 typename internal::DecayArray<T10>::type> Args;
12702 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5,
12703 e6, e7, e8, e9, e10));
12704}
12705
12706// AllOf(m1, m2, ..., mk) matches any value that matches all of the given
12707// sub-matchers. AllOf is called fully qualified to prevent ADL from firing.
12708
12709template <typename M1, typename M2>
12710inline typename internal::AllOfResult2<M1, M2>::type
12711AllOf(M1 m1, M2 m2) {
12712 return typename internal::AllOfResult2<M1, M2>::type(
12713 m1,
12714 m2);
12715}
12716
12717template <typename M1, typename M2, typename M3>
12718inline typename internal::AllOfResult3<M1, M2, M3>::type
12719AllOf(M1 m1, M2 m2, M3 m3) {
12720 return typename internal::AllOfResult3<M1, M2, M3>::type(
12721 m1,
12722 ::testing::AllOf(m2, m3));
12723}
12724
12725template <typename M1, typename M2, typename M3, typename M4>
12726inline typename internal::AllOfResult4<M1, M2, M3, M4>::type
12727AllOf(M1 m1, M2 m2, M3 m3, M4 m4) {
12728 return typename internal::AllOfResult4<M1, M2, M3, M4>::type(
12729 ::testing::AllOf(m1, m2),
12730 ::testing::AllOf(m3, m4));
12731}
12732
12733template <typename M1, typename M2, typename M3, typename M4, typename M5>
12734inline typename internal::AllOfResult5<M1, M2, M3, M4, M5>::type
12735AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5) {
12736 return typename internal::AllOfResult5<M1, M2, M3, M4, M5>::type(
12737 ::testing::AllOf(m1, m2),
12738 ::testing::AllOf(m3, m4, m5));
12739}
12740
12741template <typename M1, typename M2, typename M3, typename M4, typename M5,
12742 typename M6>
12743inline typename internal::AllOfResult6<M1, M2, M3, M4, M5, M6>::type
12744AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6) {
12745 return typename internal::AllOfResult6<M1, M2, M3, M4, M5, M6>::type(
12746 ::testing::AllOf(m1, m2, m3),
12747 ::testing::AllOf(m4, m5, m6));
12748}
12749
12750template <typename M1, typename M2, typename M3, typename M4, typename M5,
12751 typename M6, typename M7>
12752inline typename internal::AllOfResult7<M1, M2, M3, M4, M5, M6, M7>::type
12753AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7) {
12754 return typename internal::AllOfResult7<M1, M2, M3, M4, M5, M6, M7>::type(
12755 ::testing::AllOf(m1, m2, m3),
12756 ::testing::AllOf(m4, m5, m6, m7));
12757}
12758
12759template <typename M1, typename M2, typename M3, typename M4, typename M5,
12760 typename M6, typename M7, typename M8>
12761inline typename internal::AllOfResult8<M1, M2, M3, M4, M5, M6, M7, M8>::type
12762AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8) {
12763 return typename internal::AllOfResult8<M1, M2, M3, M4, M5, M6, M7, M8>::type(
12764 ::testing::AllOf(m1, m2, m3, m4),
12765 ::testing::AllOf(m5, m6, m7, m8));
12766}
12767
12768template <typename M1, typename M2, typename M3, typename M4, typename M5,
12769 typename M6, typename M7, typename M8, typename M9>
12770inline typename internal::AllOfResult9<M1, M2, M3, M4, M5, M6, M7, M8, M9>::type
12771AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9) {
12772 return typename internal::AllOfResult9<M1, M2, M3, M4, M5, M6, M7, M8,
12773 M9>::type(
12774 ::testing::AllOf(m1, m2, m3, m4),
12775 ::testing::AllOf(m5, m6, m7, m8, m9));
12776}
12777
12778template <typename M1, typename M2, typename M3, typename M4, typename M5,
12779 typename M6, typename M7, typename M8, typename M9, typename M10>
12780inline typename internal::AllOfResult10<M1, M2, M3, M4, M5, M6, M7, M8, M9,
12781 M10>::type
12782AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
12783 return typename internal::AllOfResult10<M1, M2, M3, M4, M5, M6, M7, M8, M9,
12784 M10>::type(
12785 ::testing::AllOf(m1, m2, m3, m4, m5),
12786 ::testing::AllOf(m6, m7, m8, m9, m10));
12787}
12788
12789// AnyOf(m1, m2, ..., mk) matches any value that matches any of the given
12790// sub-matchers. AnyOf is called fully qualified to prevent ADL from firing.
12791
12792template <typename M1, typename M2>
12793inline typename internal::AnyOfResult2<M1, M2>::type
12794AnyOf(M1 m1, M2 m2) {
12795 return typename internal::AnyOfResult2<M1, M2>::type(
12796 m1,
12797 m2);
12798}
12799
12800template <typename M1, typename M2, typename M3>
12801inline typename internal::AnyOfResult3<M1, M2, M3>::type
12802AnyOf(M1 m1, M2 m2, M3 m3) {
12803 return typename internal::AnyOfResult3<M1, M2, M3>::type(
12804 m1,
12805 ::testing::AnyOf(m2, m3));
12806}
12807
12808template <typename M1, typename M2, typename M3, typename M4>
12809inline typename internal::AnyOfResult4<M1, M2, M3, M4>::type
12810AnyOf(M1 m1, M2 m2, M3 m3, M4 m4) {
12811 return typename internal::AnyOfResult4<M1, M2, M3, M4>::type(
12812 ::testing::AnyOf(m1, m2),
12813 ::testing::AnyOf(m3, m4));
12814}
12815
12816template <typename M1, typename M2, typename M3, typename M4, typename M5>
12817inline typename internal::AnyOfResult5<M1, M2, M3, M4, M5>::type
12818AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5) {
12819 return typename internal::AnyOfResult5<M1, M2, M3, M4, M5>::type(
12820 ::testing::AnyOf(m1, m2),
12821 ::testing::AnyOf(m3, m4, m5));
12822}
12823
12824template <typename M1, typename M2, typename M3, typename M4, typename M5,
12825 typename M6>
12826inline typename internal::AnyOfResult6<M1, M2, M3, M4, M5, M6>::type
12827AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6) {
12828 return typename internal::AnyOfResult6<M1, M2, M3, M4, M5, M6>::type(
12829 ::testing::AnyOf(m1, m2, m3),
12830 ::testing::AnyOf(m4, m5, m6));
12831}
12832
12833template <typename M1, typename M2, typename M3, typename M4, typename M5,
12834 typename M6, typename M7>
12835inline typename internal::AnyOfResult7<M1, M2, M3, M4, M5, M6, M7>::type
12836AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7) {
12837 return typename internal::AnyOfResult7<M1, M2, M3, M4, M5, M6, M7>::type(
12838 ::testing::AnyOf(m1, m2, m3),
12839 ::testing::AnyOf(m4, m5, m6, m7));
12840}
12841
12842template <typename M1, typename M2, typename M3, typename M4, typename M5,
12843 typename M6, typename M7, typename M8>
12844inline typename internal::AnyOfResult8<M1, M2, M3, M4, M5, M6, M7, M8>::type
12845AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8) {
12846 return typename internal::AnyOfResult8<M1, M2, M3, M4, M5, M6, M7, M8>::type(
12847 ::testing::AnyOf(m1, m2, m3, m4),
12848 ::testing::AnyOf(m5, m6, m7, m8));
12849}
12850
12851template <typename M1, typename M2, typename M3, typename M4, typename M5,
12852 typename M6, typename M7, typename M8, typename M9>
12853inline typename internal::AnyOfResult9<M1, M2, M3, M4, M5, M6, M7, M8, M9>::type
12854AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9) {
12855 return typename internal::AnyOfResult9<M1, M2, M3, M4, M5, M6, M7, M8,
12856 M9>::type(
12857 ::testing::AnyOf(m1, m2, m3, m4),
12858 ::testing::AnyOf(m5, m6, m7, m8, m9));
12859}
12860
12861template <typename M1, typename M2, typename M3, typename M4, typename M5,
12862 typename M6, typename M7, typename M8, typename M9, typename M10>
12863inline typename internal::AnyOfResult10<M1, M2, M3, M4, M5, M6, M7, M8, M9,
12864 M10>::type
12865AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
12866 return typename internal::AnyOfResult10<M1, M2, M3, M4, M5, M6, M7, M8, M9,
12867 M10>::type(
12868 ::testing::AnyOf(m1, m2, m3, m4, m5),
12869 ::testing::AnyOf(m6, m7, m8, m9, m10));
12870}
12871
12872} // namespace testing
12873
12874
12875// The MATCHER* family of macros can be used in a namespace scope to
12876// define custom matchers easily.
12877//
12878// Basic Usage
12879// ===========
12880//
12881// The syntax
12882//
12883// MATCHER(name, description_string) { statements; }
12884//
12885// defines a matcher with the given name that executes the statements,
12886// which must return a bool to indicate if the match succeeds. Inside
12887// the statements, you can refer to the value being matched by 'arg',
12888// and refer to its type by 'arg_type'.
12889//
12890// The description string documents what the matcher does, and is used
12891// to generate the failure message when the match fails. Since a
12892// MATCHER() is usually defined in a header file shared by multiple
12893// C++ source files, we require the description to be a C-string
12894// literal to avoid possible side effects. It can be empty, in which
12895// case we'll use the sequence of words in the matcher name as the
12896// description.
12897//
12898// For example:
12899//
12900// MATCHER(IsEven, "") { return (arg % 2) == 0; }
12901//
12902// allows you to write
12903//
12904// // Expects mock_foo.Bar(n) to be called where n is even.
12905// EXPECT_CALL(mock_foo, Bar(IsEven()));
12906//
12907// or,
12908//
12909// // Verifies that the value of some_expression is even.
12910// EXPECT_THAT(some_expression, IsEven());
12911//
12912// If the above assertion fails, it will print something like:
12913//
12914// Value of: some_expression
12915// Expected: is even
12916// Actual: 7
12917//
12918// where the description "is even" is automatically calculated from the
12919// matcher name IsEven.
12920//
12921// Argument Type
12922// =============
12923//
12924// Note that the type of the value being matched (arg_type) is
12925// determined by the context in which you use the matcher and is
12926// supplied to you by the compiler, so you don't need to worry about
12927// declaring it (nor can you). This allows the matcher to be
12928// polymorphic. For example, IsEven() can be used to match any type
12929// where the value of "(arg % 2) == 0" can be implicitly converted to
12930// a bool. In the "Bar(IsEven())" example above, if method Bar()
12931// takes an int, 'arg_type' will be int; if it takes an unsigned long,
12932// 'arg_type' will be unsigned long; and so on.
12933//
12934// Parameterizing Matchers
12935// =======================
12936//
12937// Sometimes you'll want to parameterize the matcher. For that you
12938// can use another macro:
12939//
12940// MATCHER_P(name, param_name, description_string) { statements; }
12941//
12942// For example:
12943//
12944// MATCHER_P(HasAbsoluteValue, value, "") { return abs(arg) == value; }
12945//
12946// will allow you to write:
12947//
12948// EXPECT_THAT(Blah("a"), HasAbsoluteValue(n));
12949//
12950// which may lead to this message (assuming n is 10):
12951//
12952// Value of: Blah("a")
12953// Expected: has absolute value 10
12954// Actual: -9
12955//
12956// Note that both the matcher description and its parameter are
12957// printed, making the message human-friendly.
12958//
12959// In the matcher definition body, you can write 'foo_type' to
12960// reference the type of a parameter named 'foo'. For example, in the
12961// body of MATCHER_P(HasAbsoluteValue, value) above, you can write
12962// 'value_type' to refer to the type of 'value'.
12963//
12964// We also provide MATCHER_P2, MATCHER_P3, ..., up to MATCHER_P10 to
12965// support multi-parameter matchers.
12966//
12967// Describing Parameterized Matchers
12968// =================================
12969//
12970// The last argument to MATCHER*() is a string-typed expression. The
12971// expression can reference all of the matcher's parameters and a
12972// special bool-typed variable named 'negation'. When 'negation' is
12973// false, the expression should evaluate to the matcher's description;
12974// otherwise it should evaluate to the description of the negation of
12975// the matcher. For example,
12976//
12977// using testing::PrintToString;
12978//
12979// MATCHER_P2(InClosedRange, low, hi,
12980// string(negation ? "is not" : "is") + " in range [" +
12981// PrintToString(low) + ", " + PrintToString(hi) + "]") {
12982// return low <= arg && arg <= hi;
12983// }
12984// ...
12985// EXPECT_THAT(3, InClosedRange(4, 6));
12986// EXPECT_THAT(3, Not(InClosedRange(2, 4)));
12987//
12988// would generate two failures that contain the text:
12989//
12990// Expected: is in range [4, 6]
12991// ...
12992// Expected: is not in range [2, 4]
12993//
12994// If you specify "" as the description, the failure message will
12995// contain the sequence of words in the matcher name followed by the
12996// parameter values printed as a tuple. For example,
12997//
12998// MATCHER_P2(InClosedRange, low, hi, "") { ... }
12999// ...
13000// EXPECT_THAT(3, InClosedRange(4, 6));
13001// EXPECT_THAT(3, Not(InClosedRange(2, 4)));
13002//
13003// would generate two failures that contain the text:
13004//
13005// Expected: in closed range (4, 6)
13006// ...
13007// Expected: not (in closed range (2, 4))
13008//
13009// Types of Matcher Parameters
13010// ===========================
13011//
13012// For the purpose of typing, you can view
13013//
13014// MATCHER_Pk(Foo, p1, ..., pk, description_string) { ... }
13015//
13016// as shorthand for
13017//
13018// template <typename p1_type, ..., typename pk_type>
13019// FooMatcherPk<p1_type, ..., pk_type>
13020// Foo(p1_type p1, ..., pk_type pk) { ... }
13021//
13022// When you write Foo(v1, ..., vk), the compiler infers the types of
13023// the parameters v1, ..., and vk for you. If you are not happy with
13024// the result of the type inference, you can specify the types by
13025// explicitly instantiating the template, as in Foo<long, bool>(5,
13026// false). As said earlier, you don't get to (or need to) specify
13027// 'arg_type' as that's determined by the context in which the matcher
13028// is used. You can assign the result of expression Foo(p1, ..., pk)
13029// to a variable of type FooMatcherPk<p1_type, ..., pk_type>. This
13030// can be useful when composing matchers.
13031//
13032// While you can instantiate a matcher template with reference types,
13033// passing the parameters by pointer usually makes your code more
13034// readable. If, however, you still want to pass a parameter by
13035// reference, be aware that in the failure message generated by the
13036// matcher you will see the value of the referenced object but not its
13037// address.
13038//
13039// Explaining Match Results
13040// ========================
13041//
13042// Sometimes the matcher description alone isn't enough to explain why
13043// the match has failed or succeeded. For example, when expecting a
13044// long string, it can be very helpful to also print the diff between
13045// the expected string and the actual one. To achieve that, you can
13046// optionally stream additional information to a special variable
13047// named result_listener, whose type is a pointer to class
13048// MatchResultListener:
13049//
13050// MATCHER_P(EqualsLongString, str, "") {
13051// if (arg == str) return true;
13052//
13053// *result_listener << "the difference: "
13054/// << DiffStrings(str, arg);
13055// return false;
13056// }
13057//
13058// Overloading Matchers
13059// ====================
13060//
13061// You can overload matchers with different numbers of parameters:
13062//
13063// MATCHER_P(Blah, a, description_string1) { ... }
13064// MATCHER_P2(Blah, a, b, description_string2) { ... }
13065//
13066// Caveats
13067// =======
13068//
13069// When defining a new matcher, you should also consider implementing
13070// MatcherInterface or using MakePolymorphicMatcher(). These
13071// approaches require more work than the MATCHER* macros, but also
13072// give you more control on the types of the value being matched and
13073// the matcher parameters, which may leads to better compiler error
13074// messages when the matcher is used wrong. They also allow
13075// overloading matchers based on parameter types (as opposed to just
13076// based on the number of parameters).
13077//
13078// MATCHER*() can only be used in a namespace scope. The reason is
13079// that C++ doesn't yet allow function-local types to be used to
13080// instantiate templates. The up-coming C++0x standard will fix this.
13081// Once that's done, we'll consider supporting using MATCHER*() inside
13082// a function.
13083//
13084// More Information
13085// ================
13086//
13087// To learn more about using these macros, please search for 'MATCHER'
13088// on http://code.google.com/p/googlemock/wiki/CookBook.
13089
13090#define MATCHER(name, description)\
13091 class name##Matcher {\
13092 public:\
13093 template <typename arg_type>\
13094 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13095 public:\
13096 gmock_Impl()\
13097 {}\
13098 virtual bool MatchAndExplain(\
13099 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13100 virtual void DescribeTo(::std::ostream* gmock_os) const {\
13101 *gmock_os << FormatDescription(false);\
13102 }\
13103 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13104 *gmock_os << FormatDescription(true);\
13105 }\
13106 private:\
13107 ::testing::internal::string FormatDescription(bool negation) const {\
13108 const ::testing::internal::string gmock_description = (description);\
13109 if (!gmock_description.empty())\
13110 return gmock_description;\
13111 return ::testing::internal::FormatMatcherDescription(\
13112 negation, #name, \
13113 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13114 ::std::tr1::tuple<>()));\
13115 }\
13116 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13117 };\
13118 template <typename arg_type>\
13119 operator ::testing::Matcher<arg_type>() const {\
13120 return ::testing::Matcher<arg_type>(\
13121 new gmock_Impl<arg_type>());\
13122 }\
13123 name##Matcher() {\
13124 }\
13125 private:\
13126 GTEST_DISALLOW_ASSIGN_(name##Matcher);\
13127 };\
13128 inline name##Matcher name() {\
13129 return name##Matcher();\
13130 }\
13131 template <typename arg_type>\
13132 bool name##Matcher::gmock_Impl<arg_type>::MatchAndExplain(\
13133 arg_type arg, \
13134 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13135 const
13136
13137#define MATCHER_P(name, p0, description)\
13138 template <typename p0##_type>\
13139 class name##MatcherP {\
13140 public:\
13141 template <typename arg_type>\
13142 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13143 public:\
13144 explicit gmock_Impl(p0##_type gmock_p0)\
13145 : p0(gmock_p0) {}\
13146 virtual bool MatchAndExplain(\
13147 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13148 virtual void DescribeTo(::std::ostream* gmock_os) const {\
13149 *gmock_os << FormatDescription(false);\
13150 }\
13151 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13152 *gmock_os << FormatDescription(true);\
13153 }\
13154 p0##_type p0;\
13155 private:\
13156 ::testing::internal::string FormatDescription(bool negation) const {\
13157 const ::testing::internal::string gmock_description = (description);\
13158 if (!gmock_description.empty())\
13159 return gmock_description;\
13160 return ::testing::internal::FormatMatcherDescription(\
13161 negation, #name, \
13162 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13163 ::std::tr1::tuple<p0##_type>(p0)));\
13164 }\
13165 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13166 };\
13167 template <typename arg_type>\
13168 operator ::testing::Matcher<arg_type>() const {\
13169 return ::testing::Matcher<arg_type>(\
13170 new gmock_Impl<arg_type>(p0));\
13171 }\
13172 name##MatcherP(p0##_type gmock_p0) : p0(gmock_p0) {\
13173 }\
13174 p0##_type p0;\
13175 private:\
13176 GTEST_DISALLOW_ASSIGN_(name##MatcherP);\
13177 };\
13178 template <typename p0##_type>\
13179 inline name##MatcherP<p0##_type> name(p0##_type p0) {\
13180 return name##MatcherP<p0##_type>(p0);\
13181 }\
13182 template <typename p0##_type>\
13183 template <typename arg_type>\
13184 bool name##MatcherP<p0##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
13185 arg_type arg, \
13186 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13187 const
13188
13189#define MATCHER_P2(name, p0, p1, description)\
13190 template <typename p0##_type, typename p1##_type>\
13191 class name##MatcherP2 {\
13192 public:\
13193 template <typename arg_type>\
13194 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13195 public:\
13196 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1)\
13197 : p0(gmock_p0), p1(gmock_p1) {}\
13198 virtual bool MatchAndExplain(\
13199 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13200 virtual void DescribeTo(::std::ostream* gmock_os) const {\
13201 *gmock_os << FormatDescription(false);\
13202 }\
13203 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13204 *gmock_os << FormatDescription(true);\
13205 }\
13206 p0##_type p0;\
13207 p1##_type p1;\
13208 private:\
13209 ::testing::internal::string FormatDescription(bool negation) const {\
13210 const ::testing::internal::string gmock_description = (description);\
13211 if (!gmock_description.empty())\
13212 return gmock_description;\
13213 return ::testing::internal::FormatMatcherDescription(\
13214 negation, #name, \
13215 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13216 ::std::tr1::tuple<p0##_type, p1##_type>(p0, p1)));\
13217 }\
13218 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13219 };\
13220 template <typename arg_type>\
13221 operator ::testing::Matcher<arg_type>() const {\
13222 return ::testing::Matcher<arg_type>(\
13223 new gmock_Impl<arg_type>(p0, p1));\
13224 }\
13225 name##MatcherP2(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \
13226 p1(gmock_p1) {\
13227 }\
13228 p0##_type p0;\
13229 p1##_type p1;\
13230 private:\
13231 GTEST_DISALLOW_ASSIGN_(name##MatcherP2);\
13232 };\
13233 template <typename p0##_type, typename p1##_type>\
13234 inline name##MatcherP2<p0##_type, p1##_type> name(p0##_type p0, \
13235 p1##_type p1) {\
13236 return name##MatcherP2<p0##_type, p1##_type>(p0, p1);\
13237 }\
13238 template <typename p0##_type, typename p1##_type>\
13239 template <typename arg_type>\
13240 bool name##MatcherP2<p0##_type, \
13241 p1##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
13242 arg_type arg, \
13243 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13244 const
13245
13246#define MATCHER_P3(name, p0, p1, p2, description)\
13247 template <typename p0##_type, typename p1##_type, typename p2##_type>\
13248 class name##MatcherP3 {\
13249 public:\
13250 template <typename arg_type>\
13251 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13252 public:\
13253 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2)\
13254 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\
13255 virtual bool MatchAndExplain(\
13256 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13257 virtual void DescribeTo(::std::ostream* gmock_os) const {\
13258 *gmock_os << FormatDescription(false);\
13259 }\
13260 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13261 *gmock_os << FormatDescription(true);\
13262 }\
13263 p0##_type p0;\
13264 p1##_type p1;\
13265 p2##_type p2;\
13266 private:\
13267 ::testing::internal::string FormatDescription(bool negation) const {\
13268 const ::testing::internal::string gmock_description = (description);\
13269 if (!gmock_description.empty())\
13270 return gmock_description;\
13271 return ::testing::internal::FormatMatcherDescription(\
13272 negation, #name, \
13273 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13274 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type>(p0, p1, \
13275 p2)));\
13276 }\
13277 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13278 };\
13279 template <typename arg_type>\
13280 operator ::testing::Matcher<arg_type>() const {\
13281 return ::testing::Matcher<arg_type>(\
13282 new gmock_Impl<arg_type>(p0, p1, p2));\
13283 }\
13284 name##MatcherP3(p0##_type gmock_p0, p1##_type gmock_p1, \
13285 p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {\
13286 }\
13287 p0##_type p0;\
13288 p1##_type p1;\
13289 p2##_type p2;\
13290 private:\
13291 GTEST_DISALLOW_ASSIGN_(name##MatcherP3);\
13292 };\
13293 template <typename p0##_type, typename p1##_type, typename p2##_type>\
13294 inline name##MatcherP3<p0##_type, p1##_type, p2##_type> name(p0##_type p0, \
13295 p1##_type p1, p2##_type p2) {\
13296 return name##MatcherP3<p0##_type, p1##_type, p2##_type>(p0, p1, p2);\
13297 }\
13298 template <typename p0##_type, typename p1##_type, typename p2##_type>\
13299 template <typename arg_type>\
13300 bool name##MatcherP3<p0##_type, p1##_type, \
13301 p2##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
13302 arg_type arg, \
13303 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13304 const
13305
13306#define MATCHER_P4(name, p0, p1, p2, p3, description)\
13307 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13308 typename p3##_type>\
13309 class name##MatcherP4 {\
13310 public:\
13311 template <typename arg_type>\
13312 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13313 public:\
13314 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
13315 p3##_type gmock_p3)\
13316 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3) {}\
13317 virtual bool MatchAndExplain(\
13318 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13319 virtual void DescribeTo(::std::ostream* gmock_os) const {\
13320 *gmock_os << FormatDescription(false);\
13321 }\
13322 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13323 *gmock_os << FormatDescription(true);\
13324 }\
13325 p0##_type p0;\
13326 p1##_type p1;\
13327 p2##_type p2;\
13328 p3##_type p3;\
13329 private:\
13330 ::testing::internal::string FormatDescription(bool negation) const {\
13331 const ::testing::internal::string gmock_description = (description);\
13332 if (!gmock_description.empty())\
13333 return gmock_description;\
13334 return ::testing::internal::FormatMatcherDescription(\
13335 negation, #name, \
13336 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13337 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, \
13338 p3##_type>(p0, p1, p2, p3)));\
13339 }\
13340 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13341 };\
13342 template <typename arg_type>\
13343 operator ::testing::Matcher<arg_type>() const {\
13344 return ::testing::Matcher<arg_type>(\
13345 new gmock_Impl<arg_type>(p0, p1, p2, p3));\
13346 }\
13347 name##MatcherP4(p0##_type gmock_p0, p1##_type gmock_p1, \
13348 p2##_type gmock_p2, p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), \
13349 p2(gmock_p2), p3(gmock_p3) {\
13350 }\
13351 p0##_type p0;\
13352 p1##_type p1;\
13353 p2##_type p2;\
13354 p3##_type p3;\
13355 private:\
13356 GTEST_DISALLOW_ASSIGN_(name##MatcherP4);\
13357 };\
13358 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13359 typename p3##_type>\
13360 inline name##MatcherP4<p0##_type, p1##_type, p2##_type, \
13361 p3##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
13362 p3##_type p3) {\
13363 return name##MatcherP4<p0##_type, p1##_type, p2##_type, p3##_type>(p0, \
13364 p1, p2, p3);\
13365 }\
13366 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13367 typename p3##_type>\
13368 template <typename arg_type>\
13369 bool name##MatcherP4<p0##_type, p1##_type, p2##_type, \
13370 p3##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
13371 arg_type arg, \
13372 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13373 const
13374
13375#define MATCHER_P5(name, p0, p1, p2, p3, p4, description)\
13376 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13377 typename p3##_type, typename p4##_type>\
13378 class name##MatcherP5 {\
13379 public:\
13380 template <typename arg_type>\
13381 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13382 public:\
13383 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
13384 p3##_type gmock_p3, p4##_type gmock_p4)\
13385 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
13386 p4(gmock_p4) {}\
13387 virtual bool MatchAndExplain(\
13388 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13389 virtual void DescribeTo(::std::ostream* gmock_os) const {\
13390 *gmock_os << FormatDescription(false);\
13391 }\
13392 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13393 *gmock_os << FormatDescription(true);\
13394 }\
13395 p0##_type p0;\
13396 p1##_type p1;\
13397 p2##_type p2;\
13398 p3##_type p3;\
13399 p4##_type p4;\
13400 private:\
13401 ::testing::internal::string FormatDescription(bool negation) const {\
13402 const ::testing::internal::string gmock_description = (description);\
13403 if (!gmock_description.empty())\
13404 return gmock_description;\
13405 return ::testing::internal::FormatMatcherDescription(\
13406 negation, #name, \
13407 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13408 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
13409 p4##_type>(p0, p1, p2, p3, p4)));\
13410 }\
13411 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13412 };\
13413 template <typename arg_type>\
13414 operator ::testing::Matcher<arg_type>() const {\
13415 return ::testing::Matcher<arg_type>(\
13416 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4));\
13417 }\
13418 name##MatcherP5(p0##_type gmock_p0, p1##_type gmock_p1, \
13419 p2##_type gmock_p2, p3##_type gmock_p3, \
13420 p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
13421 p3(gmock_p3), p4(gmock_p4) {\
13422 }\
13423 p0##_type p0;\
13424 p1##_type p1;\
13425 p2##_type p2;\
13426 p3##_type p3;\
13427 p4##_type p4;\
13428 private:\
13429 GTEST_DISALLOW_ASSIGN_(name##MatcherP5);\
13430 };\
13431 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13432 typename p3##_type, typename p4##_type>\
13433 inline name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \
13434 p4##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
13435 p4##_type p4) {\
13436 return name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \
13437 p4##_type>(p0, p1, p2, p3, p4);\
13438 }\
13439 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13440 typename p3##_type, typename p4##_type>\
13441 template <typename arg_type>\
13442 bool name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \
13443 p4##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
13444 arg_type arg, \
13445 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13446 const
13447
13448#define MATCHER_P6(name, p0, p1, p2, p3, p4, p5, description)\
13449 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13450 typename p3##_type, typename p4##_type, typename p5##_type>\
13451 class name##MatcherP6 {\
13452 public:\
13453 template <typename arg_type>\
13454 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13455 public:\
13456 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
13457 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5)\
13458 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
13459 p4(gmock_p4), p5(gmock_p5) {}\
13460 virtual bool MatchAndExplain(\
13461 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13462 virtual void DescribeTo(::std::ostream* gmock_os) const {\
13463 *gmock_os << FormatDescription(false);\
13464 }\
13465 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13466 *gmock_os << FormatDescription(true);\
13467 }\
13468 p0##_type p0;\
13469 p1##_type p1;\
13470 p2##_type p2;\
13471 p3##_type p3;\
13472 p4##_type p4;\
13473 p5##_type p5;\
13474 private:\
13475 ::testing::internal::string FormatDescription(bool negation) const {\
13476 const ::testing::internal::string gmock_description = (description);\
13477 if (!gmock_description.empty())\
13478 return gmock_description;\
13479 return ::testing::internal::FormatMatcherDescription(\
13480 negation, #name, \
13481 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13482 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
13483 p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5)));\
13484 }\
13485 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13486 };\
13487 template <typename arg_type>\
13488 operator ::testing::Matcher<arg_type>() const {\
13489 return ::testing::Matcher<arg_type>(\
13490 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5));\
13491 }\
13492 name##MatcherP6(p0##_type gmock_p0, p1##_type gmock_p1, \
13493 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
13494 p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
13495 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {\
13496 }\
13497 p0##_type p0;\
13498 p1##_type p1;\
13499 p2##_type p2;\
13500 p3##_type p3;\
13501 p4##_type p4;\
13502 p5##_type p5;\
13503 private:\
13504 GTEST_DISALLOW_ASSIGN_(name##MatcherP6);\
13505 };\
13506 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13507 typename p3##_type, typename p4##_type, typename p5##_type>\
13508 inline name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, \
13509 p4##_type, p5##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
13510 p3##_type p3, p4##_type p4, p5##_type p5) {\
13511 return name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, \
13512 p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5);\
13513 }\
13514 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13515 typename p3##_type, typename p4##_type, typename p5##_type>\
13516 template <typename arg_type>\
13517 bool name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
13518 p5##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
13519 arg_type arg, \
13520 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13521 const
13522
13523#define MATCHER_P7(name, p0, p1, p2, p3, p4, p5, p6, description)\
13524 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13525 typename p3##_type, typename p4##_type, typename p5##_type, \
13526 typename p6##_type>\
13527 class name##MatcherP7 {\
13528 public:\
13529 template <typename arg_type>\
13530 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13531 public:\
13532 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
13533 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
13534 p6##_type gmock_p6)\
13535 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
13536 p4(gmock_p4), p5(gmock_p5), p6(gmock_p6) {}\
13537 virtual bool MatchAndExplain(\
13538 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13539 virtual void DescribeTo(::std::ostream* gmock_os) const {\
13540 *gmock_os << FormatDescription(false);\
13541 }\
13542 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13543 *gmock_os << FormatDescription(true);\
13544 }\
13545 p0##_type p0;\
13546 p1##_type p1;\
13547 p2##_type p2;\
13548 p3##_type p3;\
13549 p4##_type p4;\
13550 p5##_type p5;\
13551 p6##_type p6;\
13552 private:\
13553 ::testing::internal::string FormatDescription(bool negation) const {\
13554 const ::testing::internal::string gmock_description = (description);\
13555 if (!gmock_description.empty())\
13556 return gmock_description;\
13557 return ::testing::internal::FormatMatcherDescription(\
13558 negation, #name, \
13559 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13560 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
13561 p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, \
13562 p6)));\
13563 }\
13564 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13565 };\
13566 template <typename arg_type>\
13567 operator ::testing::Matcher<arg_type>() const {\
13568 return ::testing::Matcher<arg_type>(\
13569 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6));\
13570 }\
13571 name##MatcherP7(p0##_type gmock_p0, p1##_type gmock_p1, \
13572 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
13573 p5##_type gmock_p5, p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), \
13574 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), \
13575 p6(gmock_p6) {\
13576 }\
13577 p0##_type p0;\
13578 p1##_type p1;\
13579 p2##_type p2;\
13580 p3##_type p3;\
13581 p4##_type p4;\
13582 p5##_type p5;\
13583 p6##_type p6;\
13584 private:\
13585 GTEST_DISALLOW_ASSIGN_(name##MatcherP7);\
13586 };\
13587 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13588 typename p3##_type, typename p4##_type, typename p5##_type, \
13589 typename p6##_type>\
13590 inline name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, \
13591 p4##_type, p5##_type, p6##_type> name(p0##_type p0, p1##_type p1, \
13592 p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
13593 p6##_type p6) {\
13594 return name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, \
13595 p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, p6);\
13596 }\
13597 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13598 typename p3##_type, typename p4##_type, typename p5##_type, \
13599 typename p6##_type>\
13600 template <typename arg_type>\
13601 bool name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
13602 p5##_type, p6##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
13603 arg_type arg, \
13604 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13605 const
13606
13607#define MATCHER_P8(name, p0, p1, p2, p3, p4, p5, p6, p7, description)\
13608 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13609 typename p3##_type, typename p4##_type, typename p5##_type, \
13610 typename p6##_type, typename p7##_type>\
13611 class name##MatcherP8 {\
13612 public:\
13613 template <typename arg_type>\
13614 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13615 public:\
13616 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
13617 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
13618 p6##_type gmock_p6, p7##_type gmock_p7)\
13619 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
13620 p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7) {}\
13621 virtual bool MatchAndExplain(\
13622 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13623 virtual void DescribeTo(::std::ostream* gmock_os) const {\
13624 *gmock_os << FormatDescription(false);\
13625 }\
13626 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13627 *gmock_os << FormatDescription(true);\
13628 }\
13629 p0##_type p0;\
13630 p1##_type p1;\
13631 p2##_type p2;\
13632 p3##_type p3;\
13633 p4##_type p4;\
13634 p5##_type p5;\
13635 p6##_type p6;\
13636 p7##_type p7;\
13637 private:\
13638 ::testing::internal::string FormatDescription(bool negation) const {\
13639 const ::testing::internal::string gmock_description = (description);\
13640 if (!gmock_description.empty())\
13641 return gmock_description;\
13642 return ::testing::internal::FormatMatcherDescription(\
13643 negation, #name, \
13644 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13645 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
13646 p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, \
13647 p3, p4, p5, p6, p7)));\
13648 }\
13649 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13650 };\
13651 template <typename arg_type>\
13652 operator ::testing::Matcher<arg_type>() const {\
13653 return ::testing::Matcher<arg_type>(\
13654 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7));\
13655 }\
13656 name##MatcherP8(p0##_type gmock_p0, p1##_type gmock_p1, \
13657 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
13658 p5##_type gmock_p5, p6##_type gmock_p6, \
13659 p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
13660 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
13661 p7(gmock_p7) {\
13662 }\
13663 p0##_type p0;\
13664 p1##_type p1;\
13665 p2##_type p2;\
13666 p3##_type p3;\
13667 p4##_type p4;\
13668 p5##_type p5;\
13669 p6##_type p6;\
13670 p7##_type p7;\
13671 private:\
13672 GTEST_DISALLOW_ASSIGN_(name##MatcherP8);\
13673 };\
13674 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13675 typename p3##_type, typename p4##_type, typename p5##_type, \
13676 typename p6##_type, typename p7##_type>\
13677 inline name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, \
13678 p4##_type, p5##_type, p6##_type, p7##_type> name(p0##_type p0, \
13679 p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
13680 p6##_type p6, p7##_type p7) {\
13681 return name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, \
13682 p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, p3, p4, p5, \
13683 p6, p7);\
13684 }\
13685 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13686 typename p3##_type, typename p4##_type, typename p5##_type, \
13687 typename p6##_type, typename p7##_type>\
13688 template <typename arg_type>\
13689 bool name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
13690 p5##_type, p6##_type, \
13691 p7##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
13692 arg_type arg, \
13693 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13694 const
13695
13696#define MATCHER_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, description)\
13697 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13698 typename p3##_type, typename p4##_type, typename p5##_type, \
13699 typename p6##_type, typename p7##_type, typename p8##_type>\
13700 class name##MatcherP9 {\
13701 public:\
13702 template <typename arg_type>\
13703 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13704 public:\
13705 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
13706 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
13707 p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8)\
13708 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
13709 p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
13710 p8(gmock_p8) {}\
13711 virtual bool MatchAndExplain(\
13712 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13713 virtual void DescribeTo(::std::ostream* gmock_os) const {\
13714 *gmock_os << FormatDescription(false);\
13715 }\
13716 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13717 *gmock_os << FormatDescription(true);\
13718 }\
13719 p0##_type p0;\
13720 p1##_type p1;\
13721 p2##_type p2;\
13722 p3##_type p3;\
13723 p4##_type p4;\
13724 p5##_type p5;\
13725 p6##_type p6;\
13726 p7##_type p7;\
13727 p8##_type p8;\
13728 private:\
13729 ::testing::internal::string FormatDescription(bool negation) const {\
13730 const ::testing::internal::string gmock_description = (description);\
13731 if (!gmock_description.empty())\
13732 return gmock_description;\
13733 return ::testing::internal::FormatMatcherDescription(\
13734 negation, #name, \
13735 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13736 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
13737 p4##_type, p5##_type, p6##_type, p7##_type, \
13738 p8##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8)));\
13739 }\
13740 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13741 };\
13742 template <typename arg_type>\
13743 operator ::testing::Matcher<arg_type>() const {\
13744 return ::testing::Matcher<arg_type>(\
13745 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8));\
13746 }\
13747 name##MatcherP9(p0##_type gmock_p0, p1##_type gmock_p1, \
13748 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
13749 p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
13750 p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
13751 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
13752 p8(gmock_p8) {\
13753 }\
13754 p0##_type p0;\
13755 p1##_type p1;\
13756 p2##_type p2;\
13757 p3##_type p3;\
13758 p4##_type p4;\
13759 p5##_type p5;\
13760 p6##_type p6;\
13761 p7##_type p7;\
13762 p8##_type p8;\
13763 private:\
13764 GTEST_DISALLOW_ASSIGN_(name##MatcherP9);\
13765 };\
13766 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13767 typename p3##_type, typename p4##_type, typename p5##_type, \
13768 typename p6##_type, typename p7##_type, typename p8##_type>\
13769 inline name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, \
13770 p4##_type, p5##_type, p6##_type, p7##_type, \
13771 p8##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
13772 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, \
13773 p8##_type p8) {\
13774 return name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, \
13775 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type>(p0, p1, p2, \
13776 p3, p4, p5, p6, p7, p8);\
13777 }\
13778 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13779 typename p3##_type, typename p4##_type, typename p5##_type, \
13780 typename p6##_type, typename p7##_type, typename p8##_type>\
13781 template <typename arg_type>\
13782 bool name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
13783 p5##_type, p6##_type, p7##_type, \
13784 p8##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
13785 arg_type arg, \
13786 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13787 const
13788
13789#define MATCHER_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, description)\
13790 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13791 typename p3##_type, typename p4##_type, typename p5##_type, \
13792 typename p6##_type, typename p7##_type, typename p8##_type, \
13793 typename p9##_type>\
13794 class name##MatcherP10 {\
13795 public:\
13796 template <typename arg_type>\
13797 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13798 public:\
13799 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
13800 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
13801 p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
13802 p9##_type gmock_p9)\
13803 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
13804 p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
13805 p8(gmock_p8), p9(gmock_p9) {}\
13806 virtual bool MatchAndExplain(\
13807 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13808 virtual void DescribeTo(::std::ostream* gmock_os) const {\
13809 *gmock_os << FormatDescription(false);\
13810 }\
13811 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13812 *gmock_os << FormatDescription(true);\
13813 }\
13814 p0##_type p0;\
13815 p1##_type p1;\
13816 p2##_type p2;\
13817 p3##_type p3;\
13818 p4##_type p4;\
13819 p5##_type p5;\
13820 p6##_type p6;\
13821 p7##_type p7;\
13822 p8##_type p8;\
13823 p9##_type p9;\
13824 private:\
13825 ::testing::internal::string FormatDescription(bool negation) const {\
13826 const ::testing::internal::string gmock_description = (description);\
13827 if (!gmock_description.empty())\
13828 return gmock_description;\
13829 return ::testing::internal::FormatMatcherDescription(\
13830 negation, #name, \
13831 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13832 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
13833 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
13834 p9##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)));\
13835 }\
13836 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13837 };\
13838 template <typename arg_type>\
13839 operator ::testing::Matcher<arg_type>() const {\
13840 return ::testing::Matcher<arg_type>(\
13841 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9));\
13842 }\
13843 name##MatcherP10(p0##_type gmock_p0, p1##_type gmock_p1, \
13844 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
13845 p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
13846 p8##_type gmock_p8, p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), \
13847 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
13848 p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {\
13849 }\
13850 p0##_type p0;\
13851 p1##_type p1;\
13852 p2##_type p2;\
13853 p3##_type p3;\
13854 p4##_type p4;\
13855 p5##_type p5;\
13856 p6##_type p6;\
13857 p7##_type p7;\
13858 p8##_type p8;\
13859 p9##_type p9;\
13860 private:\
13861 GTEST_DISALLOW_ASSIGN_(name##MatcherP10);\
13862 };\
13863 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13864 typename p3##_type, typename p4##_type, typename p5##_type, \
13865 typename p6##_type, typename p7##_type, typename p8##_type, \
13866 typename p9##_type>\
13867 inline name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \
13868 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
13869 p9##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
13870 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \
13871 p9##_type p9) {\
13872 return name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \
13873 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, p9##_type>(p0, \
13874 p1, p2, p3, p4, p5, p6, p7, p8, p9);\
13875 }\
13876 template <typename p0##_type, typename p1##_type, typename p2##_type, \
13877 typename p3##_type, typename p4##_type, typename p5##_type, \
13878 typename p6##_type, typename p7##_type, typename p8##_type, \
13879 typename p9##_type>\
13880 template <typename arg_type>\
13881 bool name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \
13882 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
13883 p9##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
13884 arg_type arg, \
13885 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13886 const
13887
13888#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
13889// Copyright 2007, Google Inc.
13890// All rights reserved.
13891//
13892// Redistribution and use in source and binary forms, with or without
13893// modification, are permitted provided that the following conditions are
13894// met:
13895//
13896// * Redistributions of source code must retain the above copyright
13897// notice, this list of conditions and the following disclaimer.
13898// * Redistributions in binary form must reproduce the above
13899// copyright notice, this list of conditions and the following disclaimer
13900// in the documentation and/or other materials provided with the
13901// distribution.
13902// * Neither the name of Google Inc. nor the names of its
13903// contributors may be used to endorse or promote products derived from
13904// this software without specific prior written permission.
13905//
13906// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13907// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
13908// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
13909// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
13910// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
13911// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
13912// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
13913// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13914// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13915// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13916// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13917//
13918// Author: wan@google.com (Zhanyong Wan)
13919
13920// Google Mock - a framework for writing C++ mock classes.
13921//
13922// This file implements some actions that depend on gmock-generated-actions.h.
13923
13924#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
13925#define GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
13926
13927#include <algorithm>
13928
13929
13930namespace testing {
13931namespace internal {
13932
13933// Implements the Invoke(f) action. The template argument
13934// FunctionImpl is the implementation type of f, which can be either a
13935// function pointer or a functor. Invoke(f) can be used as an
13936// Action<F> as long as f's type is compatible with F (i.e. f can be
13937// assigned to a tr1::function<F>).
13938template <typename FunctionImpl>
13939class InvokeAction {
13940 public:
13941 // The c'tor makes a copy of function_impl (either a function
13942 // pointer or a functor).
13943 explicit InvokeAction(FunctionImpl function_impl)
13944 : function_impl_(function_impl) {}
13945
13946 template <typename Result, typename ArgumentTuple>
13947 Result Perform(const ArgumentTuple& args) {
13948 return InvokeHelper<Result, ArgumentTuple>::Invoke(function_impl_, args);
13949 }
13950
13951 private:
13952 FunctionImpl function_impl_;
13953
13954 GTEST_DISALLOW_ASSIGN_(InvokeAction);
13955};
13956
13957// Implements the Invoke(object_ptr, &Class::Method) action.
13958template <class Class, typename MethodPtr>
13959class InvokeMethodAction {
13960 public:
13961 InvokeMethodAction(Class* obj_ptr, MethodPtr method_ptr)
13962 : obj_ptr_(obj_ptr), method_ptr_(method_ptr) {}
13963
13964 template <typename Result, typename ArgumentTuple>
13965 Result Perform(const ArgumentTuple& args) const {
13966 return InvokeHelper<Result, ArgumentTuple>::InvokeMethod(
13967 obj_ptr_, method_ptr_, args);
13968 }
13969
13970 private:
13971 Class* const obj_ptr_;
13972 const MethodPtr method_ptr_;
13973
13974 GTEST_DISALLOW_ASSIGN_(InvokeMethodAction);
13975};
13976
13977} // namespace internal
13978
13979// Various overloads for Invoke().
13980
13981// Creates an action that invokes 'function_impl' with the mock
13982// function's arguments.
13983template <typename FunctionImpl>
13984PolymorphicAction<internal::InvokeAction<FunctionImpl> > Invoke(
13985 FunctionImpl function_impl) {
13986 return MakePolymorphicAction(
13987 internal::InvokeAction<FunctionImpl>(function_impl));
13988}
13989
13990// Creates an action that invokes the given method on the given object
13991// with the mock function's arguments.
13992template <class Class, typename MethodPtr>
13993PolymorphicAction<internal::InvokeMethodAction<Class, MethodPtr> > Invoke(
13994 Class* obj_ptr, MethodPtr method_ptr) {
13995 return MakePolymorphicAction(
13996 internal::InvokeMethodAction<Class, MethodPtr>(obj_ptr, method_ptr));
13997}
13998
13999// WithoutArgs(inner_action) can be used in a mock function with a
14000// non-empty argument list to perform inner_action, which takes no
14001// argument. In other words, it adapts an action accepting no
14002// argument to one that accepts (and ignores) arguments.
14003template <typename InnerAction>
14004inline internal::WithArgsAction<InnerAction>
14005WithoutArgs(const InnerAction& action) {
14006 return internal::WithArgsAction<InnerAction>(action);
14007}
14008
14009// WithArg<k>(an_action) creates an action that passes the k-th
14010// (0-based) argument of the mock function to an_action and performs
14011// it. It adapts an action accepting one argument to one that accepts
14012// multiple arguments. For convenience, we also provide
14013// WithArgs<k>(an_action) (defined below) as a synonym.
14014template <int k, typename InnerAction>
14015inline internal::WithArgsAction<InnerAction, k>
14016WithArg(const InnerAction& action) {
14017 return internal::WithArgsAction<InnerAction, k>(action);
14018}
14019
14020// The ACTION*() macros trigger warning C4100 (unreferenced formal
14021// parameter) in MSVC with -W4. Unfortunately they cannot be fixed in
14022// the macro definition, as the warnings are generated when the macro
14023// is expanded and macro expansion cannot contain #pragma. Therefore
14024// we suppress them here.
14025#ifdef _MSC_VER
14026# pragma warning(push)
14027# pragma warning(disable:4100)
14028#endif
14029
14030// Action ReturnArg<k>() returns the k-th argument of the mock function.
14031ACTION_TEMPLATE(ReturnArg,
14032 HAS_1_TEMPLATE_PARAMS(int, k),
14033 AND_0_VALUE_PARAMS()) {
14034 return std::tr1::get<k>(args);
14035}
14036
14037// Action SaveArg<k>(pointer) saves the k-th (0-based) argument of the
14038// mock function to *pointer.
14039ACTION_TEMPLATE(SaveArg,
14040 HAS_1_TEMPLATE_PARAMS(int, k),
14041 AND_1_VALUE_PARAMS(pointer)) {
14042 *pointer = ::std::tr1::get<k>(args);
14043}
14044
14045// Action SaveArgPointee<k>(pointer) saves the value pointed to
14046// by the k-th (0-based) argument of the mock function to *pointer.
14047ACTION_TEMPLATE(SaveArgPointee,
14048 HAS_1_TEMPLATE_PARAMS(int, k),
14049 AND_1_VALUE_PARAMS(pointer)) {
14050 *pointer = *::std::tr1::get<k>(args);
14051}
14052
14053// Action SetArgReferee<k>(value) assigns 'value' to the variable
14054// referenced by the k-th (0-based) argument of the mock function.
14055ACTION_TEMPLATE(SetArgReferee,
14056 HAS_1_TEMPLATE_PARAMS(int, k),
14057 AND_1_VALUE_PARAMS(value)) {
14058 typedef typename ::std::tr1::tuple_element<k, args_type>::type argk_type;
14059 // Ensures that argument #k is a reference. If you get a compiler
14060 // error on the next line, you are using SetArgReferee<k>(value) in
14061 // a mock function whose k-th (0-based) argument is not a reference.
14062 GTEST_COMPILE_ASSERT_(internal::is_reference<argk_type>::value,
14063 SetArgReferee_must_be_used_with_a_reference_argument);
14064 ::std::tr1::get<k>(args) = value;
14065}
14066
14067// Action SetArrayArgument<k>(first, last) copies the elements in
14068// source range [first, last) to the array pointed to by the k-th
14069// (0-based) argument, which can be either a pointer or an
14070// iterator. The action does not take ownership of the elements in the
14071// source range.
14072ACTION_TEMPLATE(SetArrayArgument,
14073 HAS_1_TEMPLATE_PARAMS(int, k),
14074 AND_2_VALUE_PARAMS(first, last)) {
14075 // Microsoft compiler deprecates ::std::copy, so we want to suppress warning
14076 // 4996 (Function call with parameters that may be unsafe) there.
14077#ifdef _MSC_VER
14078# pragma warning(push) // Saves the current warning state.
14079# pragma warning(disable:4996) // Temporarily disables warning 4996.
14080#endif
14081 ::std::copy(first, last, ::std::tr1::get<k>(args));
14082#ifdef _MSC_VER
14083# pragma warning(pop) // Restores the warning state.
14084#endif
14085}
14086
14087// Action DeleteArg<k>() deletes the k-th (0-based) argument of the mock
14088// function.
14089ACTION_TEMPLATE(DeleteArg,
14090 HAS_1_TEMPLATE_PARAMS(int, k),
14091 AND_0_VALUE_PARAMS()) {
14092 delete ::std::tr1::get<k>(args);
14093}
14094
14095// This action returns the value pointed to by 'pointer'.
14096ACTION_P(ReturnPointee, pointer) { return *pointer; }
14097
14098// Action Throw(exception) can be used in a mock function of any type
14099// to throw the given exception. Any copyable value can be thrown.
14100#if GTEST_HAS_EXCEPTIONS
14101
14102// Suppresses the 'unreachable code' warning that VC generates in opt modes.
14103# ifdef _MSC_VER
14104# pragma warning(push) // Saves the current warning state.
14105# pragma warning(disable:4702) // Temporarily disables warning 4702.
14106# endif
14107ACTION_P(Throw, exception) { throw exception; }
14108# ifdef _MSC_VER
14109# pragma warning(pop) // Restores the warning state.
14110# endif
14111
14112#endif // GTEST_HAS_EXCEPTIONS
14113
14114#ifdef _MSC_VER
14115# pragma warning(pop)
14116#endif
14117
14118} // namespace testing
14119
14120#endif // GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
14121// Copyright 2013, Google Inc.
14122// All rights reserved.
14123//
14124// Redistribution and use in source and binary forms, with or without
14125// modification, are permitted provided that the following conditions are
14126// met:
14127//
14128// * Redistributions of source code must retain the above copyright
14129// notice, this list of conditions and the following disclaimer.
14130// * Redistributions in binary form must reproduce the above
14131// copyright notice, this list of conditions and the following disclaimer
14132// in the documentation and/or other materials provided with the
14133// distribution.
14134// * Neither the name of Google Inc. nor the names of its
14135// contributors may be used to endorse or promote products derived from
14136// this software without specific prior written permission.
14137//
14138// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14139// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14140// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
14141// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
14142// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
14143// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
14144// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
14145// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
14146// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14147// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14148// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14149//
14150// Author: marcus.boerger@google.com (Marcus Boerger)
14151
14152// Google Mock - a framework for writing C++ mock classes.
14153//
14154// This file implements some matchers that depend on gmock-generated-matchers.h.
14155//
14156// Note that tests are implemented in gmock-matchers_test.cc rather than
14157// gmock-more-matchers-test.cc.
14158
14159#ifndef GMOCK_GMOCK_MORE_MATCHERS_H_
14160#define GMOCK_GMOCK_MORE_MATCHERS_H_
14161
14162
14163namespace testing {
14164
14165// Defines a matcher that matches an empty container. The container must
14166// support both size() and empty(), which all STL-like containers provide.
14167MATCHER(IsEmpty, negation ? "isn't empty" : "is empty") {
14168 if (arg.empty()) {
14169 return true;
14170 }
14171 *result_listener << "whose size is " << arg.size();
14172 return false;
14173}
14174
14175} // namespace testing
14176
14177#endif // GMOCK_GMOCK_MORE_MATCHERS_H_
14178
14179namespace testing {
14180
14181// Declares Google Mock flags that we want a user to use programmatically.
14182GMOCK_DECLARE_bool_(catch_leaked_mocks);
14183GMOCK_DECLARE_string_(verbose);
14184
14185// Initializes Google Mock. This must be called before running the
14186// tests. In particular, it parses the command line for the flags
14187// that Google Mock recognizes. Whenever a Google Mock flag is seen,
14188// it is removed from argv, and *argc is decremented.
14189//
14190// No value is returned. Instead, the Google Mock flag variables are
14191// updated.
14192//
14193// Since Google Test is needed for Google Mock to work, this function
14194// also initializes Google Test and parses its flags, if that hasn't
14195// been done.
14196GTEST_API_ void InitGoogleMock(int* argc, char** argv);
14197
14198// This overloaded version can be used in Windows programs compiled in
14199// UNICODE mode.
14200GTEST_API_ void InitGoogleMock(int* argc, wchar_t** argv);
14201
14202} // namespace testing
14203
14204#endif // GMOCK_INCLUDE_GMOCK_GMOCK_H_