blob: cd54177897e6d80fe0c16baa5d2ec0bc4a626581 [file] [log] [blame]
Austin Schuh70cc9552019-01-21 19:46:48 -08001// 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// This file implements the following syntax:
40//
41// ON_CALL(mock_object.Method(...))
42// .With(...) ?
43// .WillByDefault(...);
44//
45// where With() is optional and WillByDefault() must appear exactly
46// once.
47//
48// EXPECT_CALL(mock_object.Method(...))
49// .With(...) ?
50// .Times(...) ?
51// .InSequence(...) *
52// .WillOnce(...) *
53// .WillRepeatedly(...) ?
54// .RetiresOnSaturation() ? ;
55//
56// where all clauses are optional and WillOnce() can be repeated.
57
58// Copyright 2007, Google Inc.
59// All rights reserved.
60//
61// Redistribution and use in source and binary forms, with or without
62// modification, are permitted provided that the following conditions are
63// met:
64//
65// * Redistributions of source code must retain the above copyright
66// notice, this list of conditions and the following disclaimer.
67// * Redistributions in binary form must reproduce the above
68// copyright notice, this list of conditions and the following disclaimer
69// in the documentation and/or other materials provided with the
70// distribution.
71// * Neither the name of Google Inc. nor the names of its
72// contributors may be used to endorse or promote products derived from
73// this software without specific prior written permission.
74//
75// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
76// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
77// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
78// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
79// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
80// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
81// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
82// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
83// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
84// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
85// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
86//
87// Author: wan@google.com (Zhanyong Wan)
88
89// Google Mock - a framework for writing C++ mock classes.
90//
91// This file implements some commonly used actions.
92
93#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
94#define GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
95
96#ifndef _WIN32_WCE
97# include <errno.h>
98#endif
99
100#include <algorithm>
101#include <string>
102
103// Copyright 2007, Google Inc.
104// All rights reserved.
105//
106// Redistribution and use in source and binary forms, with or without
107// modification, are permitted provided that the following conditions are
108// met:
109//
110// * Redistributions of source code must retain the above copyright
111// notice, this list of conditions and the following disclaimer.
112// * Redistributions in binary form must reproduce the above
113// copyright notice, this list of conditions and the following disclaimer
114// in the documentation and/or other materials provided with the
115// distribution.
116// * Neither the name of Google Inc. nor the names of its
117// contributors may be used to endorse or promote products derived from
118// this software without specific prior written permission.
119//
120// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
121// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
122// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
123// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
124// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
125// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
126// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
127// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
128// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
129// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
130// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
131//
132// Author: wan@google.com (Zhanyong Wan)
133
134// Google Mock - a framework for writing C++ mock classes.
135//
136// This file defines some utilities useful for implementing Google
137// Mock. They are subject to change without notice, so please DO NOT
138// USE THEM IN USER CODE.
139
140#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
141#define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
142
143#include <stdio.h>
144#include <ostream> // NOLINT
145#include <string>
146
147// This file was GENERATED by command:
148// pump.py gmock-generated-internal-utils.h.pump
149// DO NOT EDIT BY HAND!!!
150
151// Copyright 2007, Google Inc.
152// All rights reserved.
153//
154// Redistribution and use in source and binary forms, with or without
155// modification, are permitted provided that the following conditions are
156// met:
157//
158// * Redistributions of source code must retain the above copyright
159// notice, this list of conditions and the following disclaimer.
160// * Redistributions in binary form must reproduce the above
161// copyright notice, this list of conditions and the following disclaimer
162// in the documentation and/or other materials provided with the
163// distribution.
164// * Neither the name of Google Inc. nor the names of its
165// contributors may be used to endorse or promote products derived from
166// this software without specific prior written permission.
167//
168// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
169// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
170// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
171// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
172// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
173// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
174// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
175// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
176// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
177// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
178// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
179//
180// Author: wan@google.com (Zhanyong Wan)
181
182// Google Mock - a framework for writing C++ mock classes.
183//
184// This file contains template meta-programming utility classes needed
185// for implementing Google Mock.
186
187#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_
188#define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_
189
190// Copyright 2008, Google Inc.
191// All rights reserved.
192//
193// Redistribution and use in source and binary forms, with or without
194// modification, are permitted provided that the following conditions are
195// met:
196//
197// * Redistributions of source code must retain the above copyright
198// notice, this list of conditions and the following disclaimer.
199// * Redistributions in binary form must reproduce the above
200// copyright notice, this list of conditions and the following disclaimer
201// in the documentation and/or other materials provided with the
202// distribution.
203// * Neither the name of Google Inc. nor the names of its
204// contributors may be used to endorse or promote products derived from
205// this software without specific prior written permission.
206//
207// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
208// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
209// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
210// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
211// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
213// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
214// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
215// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
216// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
217// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
218//
219// Author: vadimb@google.com (Vadim Berman)
220//
221// Low-level types and utilities for porting Google Mock to various
222// platforms. All macros ending with _ and symbols defined in an
223// internal namespace are subject to change without notice. Code
224// outside Google Mock MUST NOT USE THEM DIRECTLY. Macros that don't
225// end with _ are part of Google Mock's public API and can be used by
226// code outside Google Mock.
227
228#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_
229#define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_
230
231#include <assert.h>
232#include <stdlib.h>
233#include <iostream>
234
235// Most of the utilities needed for porting Google Mock are also
236// required for Google Test and are defined in gtest-port.h.
237//
238// Note to maintainers: to reduce code duplication, prefer adding
239// portability utilities to Google Test's gtest-port.h instead of
240// here, as Google Mock depends on Google Test. Only add a utility
241// here if it's truly specific to Google Mock.
242#include "gtest/gtest.h"
243// Copyright 2015, Google Inc.
244// All rights reserved.
245//
246// Redistribution and use in source and binary forms, with or without
247// modification, are permitted provided that the following conditions are
248// met:
249//
250// * Redistributions of source code must retain the above copyright
251// notice, this list of conditions and the following disclaimer.
252// * Redistributions in binary form must reproduce the above
253// copyright notice, this list of conditions and the following disclaimer
254// in the documentation and/or other materials provided with the
255// distribution.
256// * Neither the name of Google Inc. nor the names of its
257// contributors may be used to endorse or promote products derived from
258// this software without specific prior written permission.
259//
260// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
261// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
262// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
263// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
264// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
265// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
266// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
267// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
268// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
269// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
270// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
271//
272// Injection point for custom user configurations.
273// The following macros can be defined:
274//
275// Flag related macros:
276// GMOCK_DECLARE_bool_(name)
277// GMOCK_DECLARE_int32_(name)
278// GMOCK_DECLARE_string_(name)
279// GMOCK_DEFINE_bool_(name, default_val, doc)
280// GMOCK_DEFINE_int32_(name, default_val, doc)
281// GMOCK_DEFINE_string_(name, default_val, doc)
282//
283// ** Custom implementation starts here **
284
285#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_
286#define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_
287
288#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_
289
290// To avoid conditional compilation everywhere, we make it
291// gmock-port.h's responsibility to #include the header implementing
292// tr1/tuple. gmock-port.h does this via gtest-port.h, which is
293// guaranteed to pull in the tuple header.
294
295// For MS Visual C++, check the compiler version. At least VS 2003 is
296// required to compile Google Mock.
297#if defined(_MSC_VER) && _MSC_VER < 1310
298# error "At least Visual C++ 2003 (7.1) is required to compile Google Mock."
299#endif
300
301// Macro for referencing flags. This is public as we want the user to
302// use this syntax to reference Google Mock flags.
303#define GMOCK_FLAG(name) FLAGS_gmock_##name
304
305#if !defined(GMOCK_DECLARE_bool_)
306
307// Macros for declaring flags.
308#define GMOCK_DECLARE_bool_(name) extern GTEST_API_ bool GMOCK_FLAG(name)
309#define GMOCK_DECLARE_int32_(name) \
310 extern GTEST_API_ ::testing::internal::Int32 GMOCK_FLAG(name)
311#define GMOCK_DECLARE_string_(name) \
312 extern GTEST_API_ ::std::string GMOCK_FLAG(name)
313
314// Macros for defining flags.
315#define GMOCK_DEFINE_bool_(name, default_val, doc) \
316 GTEST_API_ bool GMOCK_FLAG(name) = (default_val)
317#define GMOCK_DEFINE_int32_(name, default_val, doc) \
318 GTEST_API_ ::testing::internal::Int32 GMOCK_FLAG(name) = (default_val)
319#define GMOCK_DEFINE_string_(name, default_val, doc) \
320 GTEST_API_ ::std::string GMOCK_FLAG(name) = (default_val)
321
322#endif // !defined(GMOCK_DECLARE_bool_)
323
324#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_
325
326namespace testing {
327
328template <typename T>
329class Matcher;
330
331namespace internal {
332
333// An IgnoredValue object can be implicitly constructed from ANY value.
334// This is used in implementing the IgnoreResult(a) action.
335class IgnoredValue {
336 public:
337 // This constructor template allows any value to be implicitly
338 // converted to IgnoredValue. The object has no data member and
339 // doesn't try to remember anything about the argument. We
340 // deliberately omit the 'explicit' keyword in order to allow the
341 // conversion to be implicit.
342 template <typename T>
343 IgnoredValue(const T& /* ignored */) {} // NOLINT(runtime/explicit)
344};
345
346// MatcherTuple<T>::type is a tuple type where each field is a Matcher
347// for the corresponding field in tuple type T.
348template <typename Tuple>
349struct MatcherTuple;
350
351template <>
352struct MatcherTuple< ::testing::tuple<> > {
353 typedef ::testing::tuple< > type;
354};
355
356template <typename A1>
357struct MatcherTuple< ::testing::tuple<A1> > {
358 typedef ::testing::tuple<Matcher<A1> > type;
359};
360
361template <typename A1, typename A2>
362struct MatcherTuple< ::testing::tuple<A1, A2> > {
363 typedef ::testing::tuple<Matcher<A1>, Matcher<A2> > type;
364};
365
366template <typename A1, typename A2, typename A3>
367struct MatcherTuple< ::testing::tuple<A1, A2, A3> > {
368 typedef ::testing::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3> > type;
369};
370
371template <typename A1, typename A2, typename A3, typename A4>
372struct MatcherTuple< ::testing::tuple<A1, A2, A3, A4> > {
373 typedef ::testing::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>,
374 Matcher<A4> > type;
375};
376
377template <typename A1, typename A2, typename A3, typename A4, typename A5>
378struct MatcherTuple< ::testing::tuple<A1, A2, A3, A4, A5> > {
379 typedef ::testing::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
380 Matcher<A5> > type;
381};
382
383template <typename A1, typename A2, typename A3, typename A4, typename A5,
384 typename A6>
385struct MatcherTuple< ::testing::tuple<A1, A2, A3, A4, A5, A6> > {
386 typedef ::testing::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
387 Matcher<A5>, Matcher<A6> > type;
388};
389
390template <typename A1, typename A2, typename A3, typename A4, typename A5,
391 typename A6, typename A7>
392struct MatcherTuple< ::testing::tuple<A1, A2, A3, A4, A5, A6, A7> > {
393 typedef ::testing::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
394 Matcher<A5>, Matcher<A6>, Matcher<A7> > type;
395};
396
397template <typename A1, typename A2, typename A3, typename A4, typename A5,
398 typename A6, typename A7, typename A8>
399struct MatcherTuple< ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8> > {
400 typedef ::testing::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
401 Matcher<A5>, Matcher<A6>, Matcher<A7>, Matcher<A8> > type;
402};
403
404template <typename A1, typename A2, typename A3, typename A4, typename A5,
405 typename A6, typename A7, typename A8, typename A9>
406struct MatcherTuple< ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9> > {
407 typedef ::testing::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
408 Matcher<A5>, Matcher<A6>, Matcher<A7>, Matcher<A8>, Matcher<A9> > type;
409};
410
411template <typename A1, typename A2, typename A3, typename A4, typename A5,
412 typename A6, typename A7, typename A8, typename A9, typename A10>
413struct MatcherTuple< ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9,
414 A10> > {
415 typedef ::testing::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
416 Matcher<A5>, Matcher<A6>, Matcher<A7>, Matcher<A8>, Matcher<A9>,
417 Matcher<A10> > type;
418};
419
420// Template struct Function<F>, where F must be a function type, contains
421// the following typedefs:
422//
423// Result: the function's return type.
424// ArgumentN: the type of the N-th argument, where N starts with 1.
425// ArgumentTuple: the tuple type consisting of all parameters of F.
426// ArgumentMatcherTuple: the tuple type consisting of Matchers for all
427// parameters of F.
428// MakeResultVoid: the function type obtained by substituting void
429// for the return type of F.
430// MakeResultIgnoredValue:
431// the function type obtained by substituting Something
432// for the return type of F.
433template <typename F>
434struct Function;
435
436template <typename R>
437struct Function<R()> {
438 typedef R Result;
439 typedef ::testing::tuple<> ArgumentTuple;
440 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
441 typedef void MakeResultVoid();
442 typedef IgnoredValue MakeResultIgnoredValue();
443};
444
445template <typename R, typename A1>
446struct Function<R(A1)>
447 : Function<R()> {
448 typedef A1 Argument1;
449 typedef ::testing::tuple<A1> ArgumentTuple;
450 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
451 typedef void MakeResultVoid(A1);
452 typedef IgnoredValue MakeResultIgnoredValue(A1);
453};
454
455template <typename R, typename A1, typename A2>
456struct Function<R(A1, A2)>
457 : Function<R(A1)> {
458 typedef A2 Argument2;
459 typedef ::testing::tuple<A1, A2> ArgumentTuple;
460 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
461 typedef void MakeResultVoid(A1, A2);
462 typedef IgnoredValue MakeResultIgnoredValue(A1, A2);
463};
464
465template <typename R, typename A1, typename A2, typename A3>
466struct Function<R(A1, A2, A3)>
467 : Function<R(A1, A2)> {
468 typedef A3 Argument3;
469 typedef ::testing::tuple<A1, A2, A3> ArgumentTuple;
470 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
471 typedef void MakeResultVoid(A1, A2, A3);
472 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3);
473};
474
475template <typename R, typename A1, typename A2, typename A3, typename A4>
476struct Function<R(A1, A2, A3, A4)>
477 : Function<R(A1, A2, A3)> {
478 typedef A4 Argument4;
479 typedef ::testing::tuple<A1, A2, A3, A4> ArgumentTuple;
480 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
481 typedef void MakeResultVoid(A1, A2, A3, A4);
482 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4);
483};
484
485template <typename R, typename A1, typename A2, typename A3, typename A4,
486 typename A5>
487struct Function<R(A1, A2, A3, A4, A5)>
488 : Function<R(A1, A2, A3, A4)> {
489 typedef A5 Argument5;
490 typedef ::testing::tuple<A1, A2, A3, A4, A5> ArgumentTuple;
491 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
492 typedef void MakeResultVoid(A1, A2, A3, A4, A5);
493 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5);
494};
495
496template <typename R, typename A1, typename A2, typename A3, typename A4,
497 typename A5, typename A6>
498struct Function<R(A1, A2, A3, A4, A5, A6)>
499 : Function<R(A1, A2, A3, A4, A5)> {
500 typedef A6 Argument6;
501 typedef ::testing::tuple<A1, A2, A3, A4, A5, A6> ArgumentTuple;
502 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
503 typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6);
504 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6);
505};
506
507template <typename R, typename A1, typename A2, typename A3, typename A4,
508 typename A5, typename A6, typename A7>
509struct Function<R(A1, A2, A3, A4, A5, A6, A7)>
510 : Function<R(A1, A2, A3, A4, A5, A6)> {
511 typedef A7 Argument7;
512 typedef ::testing::tuple<A1, A2, A3, A4, A5, A6, A7> ArgumentTuple;
513 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
514 typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7);
515 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7);
516};
517
518template <typename R, typename A1, typename A2, typename A3, typename A4,
519 typename A5, typename A6, typename A7, typename A8>
520struct Function<R(A1, A2, A3, A4, A5, A6, A7, A8)>
521 : Function<R(A1, A2, A3, A4, A5, A6, A7)> {
522 typedef A8 Argument8;
523 typedef ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8> ArgumentTuple;
524 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
525 typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7, A8);
526 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7, A8);
527};
528
529template <typename R, typename A1, typename A2, typename A3, typename A4,
530 typename A5, typename A6, typename A7, typename A8, typename A9>
531struct Function<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)>
532 : Function<R(A1, A2, A3, A4, A5, A6, A7, A8)> {
533 typedef A9 Argument9;
534 typedef ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9> ArgumentTuple;
535 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
536 typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7, A8, A9);
537 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7, A8,
538 A9);
539};
540
541template <typename R, typename A1, typename A2, typename A3, typename A4,
542 typename A5, typename A6, typename A7, typename A8, typename A9,
543 typename A10>
544struct Function<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)>
545 : Function<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> {
546 typedef A10 Argument10;
547 typedef ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9,
548 A10> ArgumentTuple;
549 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
550 typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10);
551 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7, A8,
552 A9, A10);
553};
554
555} // namespace internal
556
557} // namespace testing
558
559#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_
560
561namespace testing {
562namespace internal {
563
564// Converts an identifier name to a space-separated list of lower-case
565// words. Each maximum substring of the form [A-Za-z][a-z]*|\d+ is
566// treated as one word. For example, both "FooBar123" and
567// "foo_bar_123" are converted to "foo bar 123".
568GTEST_API_ string ConvertIdentifierNameToWords(const char* id_name);
569
570// PointeeOf<Pointer>::type is the type of a value pointed to by a
571// Pointer, which can be either a smart pointer or a raw pointer. The
572// following default implementation is for the case where Pointer is a
573// smart pointer.
574template <typename Pointer>
575struct PointeeOf {
576 // Smart pointer classes define type element_type as the type of
577 // their pointees.
578 typedef typename Pointer::element_type type;
579};
580// This specialization is for the raw pointer case.
581template <typename T>
582struct PointeeOf<T*> { typedef T type; }; // NOLINT
583
584// GetRawPointer(p) returns the raw pointer underlying p when p is a
585// smart pointer, or returns p itself when p is already a raw pointer.
586// The following default implementation is for the smart pointer case.
587template <typename Pointer>
588inline const typename Pointer::element_type* GetRawPointer(const Pointer& p) {
589 return p.get();
590}
591// This overloaded version is for the raw pointer case.
592template <typename Element>
593inline Element* GetRawPointer(Element* p) { return p; }
594
595// This comparator allows linked_ptr to be stored in sets.
596template <typename T>
597struct LinkedPtrLessThan {
598 bool operator()(const ::testing::internal::linked_ptr<T>& lhs,
599 const ::testing::internal::linked_ptr<T>& rhs) const {
600 return lhs.get() < rhs.get();
601 }
602};
603
604// Symbian compilation can be done with wchar_t being either a native
605// type or a typedef. Using Google Mock with OpenC without wchar_t
606// should require the definition of _STLP_NO_WCHAR_T.
607//
608// MSVC treats wchar_t as a native type usually, but treats it as the
609// same as unsigned short when the compiler option /Zc:wchar_t- is
610// specified. It defines _NATIVE_WCHAR_T_DEFINED symbol when wchar_t
611// is a native type.
612#if (GTEST_OS_SYMBIAN && defined(_STLP_NO_WCHAR_T)) || \
613 (defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED))
614// wchar_t is a typedef.
615#else
616# define GMOCK_WCHAR_T_IS_NATIVE_ 1
617#endif
618
619// signed wchar_t and unsigned wchar_t are NOT in the C++ standard.
620// Using them is a bad practice and not portable. So DON'T use them.
621//
622// Still, Google Mock is designed to work even if the user uses signed
623// wchar_t or unsigned wchar_t (obviously, assuming the compiler
624// supports them).
625//
626// To gcc,
627// wchar_t == signed wchar_t != unsigned wchar_t == unsigned int
628#ifdef __GNUC__
629// signed/unsigned wchar_t are valid types.
630# define GMOCK_HAS_SIGNED_WCHAR_T_ 1
631#endif
632
633// In what follows, we use the term "kind" to indicate whether a type
634// is bool, an integer type (excluding bool), a floating-point type,
635// or none of them. This categorization is useful for determining
636// when a matcher argument type can be safely converted to another
637// type in the implementation of SafeMatcherCast.
638enum TypeKind {
639 kBool, kInteger, kFloatingPoint, kOther
640};
641
642// KindOf<T>::value is the kind of type T.
643template <typename T> struct KindOf {
644 enum { value = kOther }; // The default kind.
645};
646
647// This macro declares that the kind of 'type' is 'kind'.
648#define GMOCK_DECLARE_KIND_(type, kind) \
649 template <> struct KindOf<type> { enum { value = kind }; }
650
651GMOCK_DECLARE_KIND_(bool, kBool);
652
653// All standard integer types.
654GMOCK_DECLARE_KIND_(char, kInteger);
655GMOCK_DECLARE_KIND_(signed char, kInteger);
656GMOCK_DECLARE_KIND_(unsigned char, kInteger);
657GMOCK_DECLARE_KIND_(short, kInteger); // NOLINT
658GMOCK_DECLARE_KIND_(unsigned short, kInteger); // NOLINT
659GMOCK_DECLARE_KIND_(int, kInteger);
660GMOCK_DECLARE_KIND_(unsigned int, kInteger);
661GMOCK_DECLARE_KIND_(long, kInteger); // NOLINT
662GMOCK_DECLARE_KIND_(unsigned long, kInteger); // NOLINT
663
664#if GMOCK_WCHAR_T_IS_NATIVE_
665GMOCK_DECLARE_KIND_(wchar_t, kInteger);
666#endif
667
668// Non-standard integer types.
669GMOCK_DECLARE_KIND_(Int64, kInteger);
670GMOCK_DECLARE_KIND_(UInt64, kInteger);
671
672// All standard floating-point types.
673GMOCK_DECLARE_KIND_(float, kFloatingPoint);
674GMOCK_DECLARE_KIND_(double, kFloatingPoint);
675GMOCK_DECLARE_KIND_(long double, kFloatingPoint);
676
677#undef GMOCK_DECLARE_KIND_
678
679// Evaluates to the kind of 'type'.
680#define GMOCK_KIND_OF_(type) \
681 static_cast< ::testing::internal::TypeKind>( \
682 ::testing::internal::KindOf<type>::value)
683
684// Evaluates to true iff integer type T is signed.
685#define GMOCK_IS_SIGNED_(T) (static_cast<T>(-1) < 0)
686
687// LosslessArithmeticConvertibleImpl<kFromKind, From, kToKind, To>::value
688// is true iff arithmetic type From can be losslessly converted to
689// arithmetic type To.
690//
691// It's the user's responsibility to ensure that both From and To are
692// raw (i.e. has no CV modifier, is not a pointer, and is not a
693// reference) built-in arithmetic types, kFromKind is the kind of
694// From, and kToKind is the kind of To; the value is
695// implementation-defined when the above pre-condition is violated.
696template <TypeKind kFromKind, typename From, TypeKind kToKind, typename To>
697struct LosslessArithmeticConvertibleImpl : public false_type {};
698
699// Converting bool to bool is lossless.
700template <>
701struct LosslessArithmeticConvertibleImpl<kBool, bool, kBool, bool>
702 : public true_type {}; // NOLINT
703
704// Converting bool to any integer type is lossless.
705template <typename To>
706struct LosslessArithmeticConvertibleImpl<kBool, bool, kInteger, To>
707 : public true_type {}; // NOLINT
708
709// Converting bool to any floating-point type is lossless.
710template <typename To>
711struct LosslessArithmeticConvertibleImpl<kBool, bool, kFloatingPoint, To>
712 : public true_type {}; // NOLINT
713
714// Converting an integer to bool is lossy.
715template <typename From>
716struct LosslessArithmeticConvertibleImpl<kInteger, From, kBool, bool>
717 : public false_type {}; // NOLINT
718
719// Converting an integer to another non-bool integer is lossless iff
720// the target type's range encloses the source type's range.
721template <typename From, typename To>
722struct LosslessArithmeticConvertibleImpl<kInteger, From, kInteger, To>
723 : public bool_constant<
724 // When converting from a smaller size to a larger size, we are
725 // fine as long as we are not converting from signed to unsigned.
726 ((sizeof(From) < sizeof(To)) &&
727 (!GMOCK_IS_SIGNED_(From) || GMOCK_IS_SIGNED_(To))) ||
728 // When converting between the same size, the signedness must match.
729 ((sizeof(From) == sizeof(To)) &&
730 (GMOCK_IS_SIGNED_(From) == GMOCK_IS_SIGNED_(To)))> {}; // NOLINT
731
732#undef GMOCK_IS_SIGNED_
733
734// Converting an integer to a floating-point type may be lossy, since
735// the format of a floating-point number is implementation-defined.
736template <typename From, typename To>
737struct LosslessArithmeticConvertibleImpl<kInteger, From, kFloatingPoint, To>
738 : public false_type {}; // NOLINT
739
740// Converting a floating-point to bool is lossy.
741template <typename From>
742struct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kBool, bool>
743 : public false_type {}; // NOLINT
744
745// Converting a floating-point to an integer is lossy.
746template <typename From, typename To>
747struct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kInteger, To>
748 : public false_type {}; // NOLINT
749
750// Converting a floating-point to another floating-point is lossless
751// iff the target type is at least as big as the source type.
752template <typename From, typename To>
753struct LosslessArithmeticConvertibleImpl<
754 kFloatingPoint, From, kFloatingPoint, To>
755 : public bool_constant<sizeof(From) <= sizeof(To)> {}; // NOLINT
756
757// LosslessArithmeticConvertible<From, To>::value is true iff arithmetic
758// type From can be losslessly converted to arithmetic type To.
759//
760// It's the user's responsibility to ensure that both From and To are
761// raw (i.e. has no CV modifier, is not a pointer, and is not a
762// reference) built-in arithmetic types; the value is
763// implementation-defined when the above pre-condition is violated.
764template <typename From, typename To>
765struct LosslessArithmeticConvertible
766 : public LosslessArithmeticConvertibleImpl<
767 GMOCK_KIND_OF_(From), From, GMOCK_KIND_OF_(To), To> {}; // NOLINT
768
769// This interface knows how to report a Google Mock failure (either
770// non-fatal or fatal).
771class FailureReporterInterface {
772 public:
773 // The type of a failure (either non-fatal or fatal).
774 enum FailureType {
775 kNonfatal, kFatal
776 };
777
778 virtual ~FailureReporterInterface() {}
779
780 // Reports a failure that occurred at the given source file location.
781 virtual void ReportFailure(FailureType type, const char* file, int line,
782 const string& message) = 0;
783};
784
785// Returns the failure reporter used by Google Mock.
786GTEST_API_ FailureReporterInterface* GetFailureReporter();
787
788// Asserts that condition is true; aborts the process with the given
789// message if condition is false. We cannot use LOG(FATAL) or CHECK()
790// as Google Mock might be used to mock the log sink itself. We
791// inline this function to prevent it from showing up in the stack
792// trace.
793inline void Assert(bool condition, const char* file, int line,
794 const string& msg) {
795 if (!condition) {
796 GetFailureReporter()->ReportFailure(FailureReporterInterface::kFatal,
797 file, line, msg);
798 }
799}
800inline void Assert(bool condition, const char* file, int line) {
801 Assert(condition, file, line, "Assertion failed.");
802}
803
804// Verifies that condition is true; generates a non-fatal failure if
805// condition is false.
806inline void Expect(bool condition, const char* file, int line,
807 const string& msg) {
808 if (!condition) {
809 GetFailureReporter()->ReportFailure(FailureReporterInterface::kNonfatal,
810 file, line, msg);
811 }
812}
813inline void Expect(bool condition, const char* file, int line) {
814 Expect(condition, file, line, "Expectation failed.");
815}
816
817// Severity level of a log.
818enum LogSeverity {
819 kInfo = 0,
820 kWarning = 1
821};
822
823// Valid values for the --gmock_verbose flag.
824
825// All logs (informational and warnings) are printed.
826const char kInfoVerbosity[] = "info";
827// Only warnings are printed.
828const char kWarningVerbosity[] = "warning";
829// No logs are printed.
830const char kErrorVerbosity[] = "error";
831
832// Returns true iff a log with the given severity is visible according
833// to the --gmock_verbose flag.
834GTEST_API_ bool LogIsVisible(LogSeverity severity);
835
836// Prints the given message to stdout iff 'severity' >= the level
837// specified by the --gmock_verbose flag. If stack_frames_to_skip >=
838// 0, also prints the stack trace excluding the top
839// stack_frames_to_skip frames. In opt mode, any positive
840// stack_frames_to_skip is treated as 0, since we don't know which
841// function calls will be inlined by the compiler and need to be
842// conservative.
843GTEST_API_ void Log(LogSeverity severity,
844 const string& message,
845 int stack_frames_to_skip);
846
847// TODO(wan@google.com): group all type utilities together.
848
849// Type traits.
850
851// is_reference<T>::value is non-zero iff T is a reference type.
852template <typename T> struct is_reference : public false_type {};
853template <typename T> struct is_reference<T&> : public true_type {};
854
855// type_equals<T1, T2>::value is non-zero iff T1 and T2 are the same type.
856template <typename T1, typename T2> struct type_equals : public false_type {};
857template <typename T> struct type_equals<T, T> : public true_type {};
858
859// remove_reference<T>::type removes the reference from type T, if any.
860template <typename T> struct remove_reference { typedef T type; }; // NOLINT
861template <typename T> struct remove_reference<T&> { typedef T type; }; // NOLINT
862
863// DecayArray<T>::type turns an array type U[N] to const U* and preserves
864// other types. Useful for saving a copy of a function argument.
865template <typename T> struct DecayArray { typedef T type; }; // NOLINT
866template <typename T, size_t N> struct DecayArray<T[N]> {
867 typedef const T* type;
868};
869// Sometimes people use arrays whose size is not available at the use site
870// (e.g. extern const char kNamePrefix[]). This specialization covers that
871// case.
872template <typename T> struct DecayArray<T[]> {
873 typedef const T* type;
874};
875
876// Disable MSVC warnings for infinite recursion, since in this case the
877// the recursion is unreachable.
878#ifdef _MSC_VER
879# pragma warning(push)
880# pragma warning(disable:4717)
881#endif
882
883// Invalid<T>() is usable as an expression of type T, but will terminate
884// the program with an assertion failure if actually run. This is useful
885// when a value of type T is needed for compilation, but the statement
886// will not really be executed (or we don't care if the statement
887// crashes).
888template <typename T>
889inline T Invalid() {
890 Assert(false, "", -1, "Internal error: attempt to return invalid value");
891 // This statement is unreachable, and would never terminate even if it
892 // could be reached. It is provided only to placate compiler warnings
893 // about missing return statements.
894 return Invalid<T>();
895}
896
897#ifdef _MSC_VER
898# pragma warning(pop)
899#endif
900
901// Given a raw type (i.e. having no top-level reference or const
902// modifier) RawContainer that's either an STL-style container or a
903// native array, class StlContainerView<RawContainer> has the
904// following members:
905//
906// - type is a type that provides an STL-style container view to
907// (i.e. implements the STL container concept for) RawContainer;
908// - const_reference is a type that provides a reference to a const
909// RawContainer;
910// - ConstReference(raw_container) returns a const reference to an STL-style
911// container view to raw_container, which is a RawContainer.
912// - Copy(raw_container) returns an STL-style container view of a
913// copy of raw_container, which is a RawContainer.
914//
915// This generic version is used when RawContainer itself is already an
916// STL-style container.
917template <class RawContainer>
918class StlContainerView {
919 public:
920 typedef RawContainer type;
921 typedef const type& const_reference;
922
923 static const_reference ConstReference(const RawContainer& container) {
924 // Ensures that RawContainer is not a const type.
925 testing::StaticAssertTypeEq<RawContainer,
926 GTEST_REMOVE_CONST_(RawContainer)>();
927 return container;
928 }
929 static type Copy(const RawContainer& container) { return container; }
930};
931
932// This specialization is used when RawContainer is a native array type.
933template <typename Element, size_t N>
934class StlContainerView<Element[N]> {
935 public:
936 typedef GTEST_REMOVE_CONST_(Element) RawElement;
937 typedef internal::NativeArray<RawElement> type;
938 // NativeArray<T> can represent a native array either by value or by
939 // reference (selected by a constructor argument), so 'const type'
940 // can be used to reference a const native array. We cannot
941 // 'typedef const type& const_reference' here, as that would mean
942 // ConstReference() has to return a reference to a local variable.
943 typedef const type const_reference;
944
945 static const_reference ConstReference(const Element (&array)[N]) {
946 // Ensures that Element is not a const type.
947 testing::StaticAssertTypeEq<Element, RawElement>();
948#if GTEST_OS_SYMBIAN
949 // The Nokia Symbian compiler confuses itself in template instantiation
950 // for this call without the cast to Element*:
951 // function call '[testing::internal::NativeArray<char *>].NativeArray(
952 // {lval} const char *[4], long, testing::internal::RelationToSource)'
953 // does not match
954 // 'testing::internal::NativeArray<char *>::NativeArray(
955 // char *const *, unsigned int, testing::internal::RelationToSource)'
956 // (instantiating: 'testing::internal::ContainsMatcherImpl
957 // <const char * (&)[4]>::Matches(const char * (&)[4]) const')
958 // (instantiating: 'testing::internal::StlContainerView<char *[4]>::
959 // ConstReference(const char * (&)[4])')
960 // (and though the N parameter type is mismatched in the above explicit
961 // conversion of it doesn't help - only the conversion of the array).
962 return type(const_cast<Element*>(&array[0]), N,
963 RelationToSourceReference());
964#else
965 return type(array, N, RelationToSourceReference());
966#endif // GTEST_OS_SYMBIAN
967 }
968 static type Copy(const Element (&array)[N]) {
969#if GTEST_OS_SYMBIAN
970 return type(const_cast<Element*>(&array[0]), N, RelationToSourceCopy());
971#else
972 return type(array, N, RelationToSourceCopy());
973#endif // GTEST_OS_SYMBIAN
974 }
975};
976
977// This specialization is used when RawContainer is a native array
978// represented as a (pointer, size) tuple.
979template <typename ElementPointer, typename Size>
980class StlContainerView< ::testing::tuple<ElementPointer, Size> > {
981 public:
982 typedef GTEST_REMOVE_CONST_(
983 typename internal::PointeeOf<ElementPointer>::type) RawElement;
984 typedef internal::NativeArray<RawElement> type;
985 typedef const type const_reference;
986
987 static const_reference ConstReference(
988 const ::testing::tuple<ElementPointer, Size>& array) {
989 return type(get<0>(array), get<1>(array), RelationToSourceReference());
990 }
991 static type Copy(const ::testing::tuple<ElementPointer, Size>& array) {
992 return type(get<0>(array), get<1>(array), RelationToSourceCopy());
993 }
994};
995
996// The following specialization prevents the user from instantiating
997// StlContainer with a reference type.
998template <typename T> class StlContainerView<T&>;
999
1000// A type transform to remove constness from the first part of a pair.
1001// Pairs like that are used as the value_type of associative containers,
1002// and this transform produces a similar but assignable pair.
1003template <typename T>
1004struct RemoveConstFromKey {
1005 typedef T type;
1006};
1007
1008// Partially specialized to remove constness from std::pair<const K, V>.
1009template <typename K, typename V>
1010struct RemoveConstFromKey<std::pair<const K, V> > {
1011 typedef std::pair<K, V> type;
1012};
1013
1014// Mapping from booleans to types. Similar to boost::bool_<kValue> and
1015// std::integral_constant<bool, kValue>.
1016template <bool kValue>
1017struct BooleanConstant {};
1018
1019} // namespace internal
1020} // namespace testing
1021
1022#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
1023
1024
1025#if GTEST_HAS_STD_TYPE_TRAITS_ // Defined by gtest-port.h via gmock-port.h.
1026#include <type_traits>
1027#endif
1028
1029namespace testing {
1030
1031// To implement an action Foo, define:
1032// 1. a class FooAction that implements the ActionInterface interface, and
1033// 2. a factory function that creates an Action object from a
1034// const FooAction*.
1035//
1036// The two-level delegation design follows that of Matcher, providing
1037// consistency for extension developers. It also eases ownership
1038// management as Action objects can now be copied like plain values.
1039
1040namespace internal {
1041
1042template <typename F1, typename F2>
1043class ActionAdaptor;
1044
1045// BuiltInDefaultValueGetter<T, true>::Get() returns a
1046// default-constructed T value. BuiltInDefaultValueGetter<T,
1047// false>::Get() crashes with an error.
1048//
1049// This primary template is used when kDefaultConstructible is true.
1050template <typename T, bool kDefaultConstructible>
1051struct BuiltInDefaultValueGetter {
1052 static T Get() { return T(); }
1053};
1054template <typename T>
1055struct BuiltInDefaultValueGetter<T, false> {
1056 static T Get() {
1057 Assert(false, __FILE__, __LINE__,
1058 "Default action undefined for the function return type.");
1059 return internal::Invalid<T>();
1060 // The above statement will never be reached, but is required in
1061 // order for this function to compile.
1062 }
1063};
1064
1065// BuiltInDefaultValue<T>::Get() returns the "built-in" default value
1066// for type T, which is NULL when T is a raw pointer type, 0 when T is
1067// a numeric type, false when T is bool, or "" when T is string or
1068// std::string. In addition, in C++11 and above, it turns a
1069// default-constructed T value if T is default constructible. For any
1070// other type T, the built-in default T value is undefined, and the
1071// function will abort the process.
1072template <typename T>
1073class BuiltInDefaultValue {
1074 public:
1075#if GTEST_HAS_STD_TYPE_TRAITS_
1076 // This function returns true iff type T has a built-in default value.
1077 static bool Exists() {
1078 return ::std::is_default_constructible<T>::value;
1079 }
1080
1081 static T Get() {
1082 return BuiltInDefaultValueGetter<
1083 T, ::std::is_default_constructible<T>::value>::Get();
1084 }
1085
1086#else // GTEST_HAS_STD_TYPE_TRAITS_
1087 // This function returns true iff type T has a built-in default value.
1088 static bool Exists() {
1089 return false;
1090 }
1091
1092 static T Get() {
1093 return BuiltInDefaultValueGetter<T, false>::Get();
1094 }
1095
1096#endif // GTEST_HAS_STD_TYPE_TRAITS_
1097};
1098
1099// This partial specialization says that we use the same built-in
1100// default value for T and const T.
1101template <typename T>
1102class BuiltInDefaultValue<const T> {
1103 public:
1104 static bool Exists() { return BuiltInDefaultValue<T>::Exists(); }
1105 static T Get() { return BuiltInDefaultValue<T>::Get(); }
1106};
1107
1108// This partial specialization defines the default values for pointer
1109// types.
1110template <typename T>
1111class BuiltInDefaultValue<T*> {
1112 public:
1113 static bool Exists() { return true; }
1114 static T* Get() { return NULL; }
1115};
1116
1117// The following specializations define the default values for
1118// specific types we care about.
1119#define GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(type, value) \
1120 template <> \
1121 class BuiltInDefaultValue<type> { \
1122 public: \
1123 static bool Exists() { return true; } \
1124 static type Get() { return value; } \
1125 }
1126
1127GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(void, ); // NOLINT
1128#if GTEST_HAS_GLOBAL_STRING
1129GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(::string, "");
1130#endif // GTEST_HAS_GLOBAL_STRING
1131GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(::std::string, "");
1132GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(bool, false);
1133GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned char, '\0');
1134GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed char, '\0');
1135GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(char, '\0');
1136
1137// There's no need for a default action for signed wchar_t, as that
1138// type is the same as wchar_t for gcc, and invalid for MSVC.
1139//
1140// There's also no need for a default action for unsigned wchar_t, as
1141// that type is the same as unsigned int for gcc, and invalid for
1142// MSVC.
1143#if GMOCK_WCHAR_T_IS_NATIVE_
1144GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(wchar_t, 0U); // NOLINT
1145#endif
1146
1147GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned short, 0U); // NOLINT
1148GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed short, 0); // NOLINT
1149GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned int, 0U);
1150GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed int, 0);
1151GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned long, 0UL); // NOLINT
1152GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed long, 0L); // NOLINT
1153GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(UInt64, 0);
1154GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(Int64, 0);
1155GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(float, 0);
1156GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(double, 0);
1157
1158#undef GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_
1159
1160} // namespace internal
1161
1162// When an unexpected function call is encountered, Google Mock will
1163// let it return a default value if the user has specified one for its
1164// return type, or if the return type has a built-in default value;
1165// otherwise Google Mock won't know what value to return and will have
1166// to abort the process.
1167//
1168// The DefaultValue<T> class allows a user to specify the
1169// default value for a type T that is both copyable and publicly
1170// destructible (i.e. anything that can be used as a function return
1171// type). The usage is:
1172//
1173// // Sets the default value for type T to be foo.
1174// DefaultValue<T>::Set(foo);
1175template <typename T>
1176class DefaultValue {
1177 public:
1178 // Sets the default value for type T; requires T to be
1179 // copy-constructable and have a public destructor.
1180 static void Set(T x) {
1181 delete producer_;
1182 producer_ = new FixedValueProducer(x);
1183 }
1184
1185 // Provides a factory function to be called to generate the default value.
1186 // This method can be used even if T is only move-constructible, but it is not
1187 // limited to that case.
1188 typedef T (*FactoryFunction)();
1189 static void SetFactory(FactoryFunction factory) {
1190 delete producer_;
1191 producer_ = new FactoryValueProducer(factory);
1192 }
1193
1194 // Unsets the default value for type T.
1195 static void Clear() {
1196 delete producer_;
1197 producer_ = NULL;
1198 }
1199
1200 // Returns true iff the user has set the default value for type T.
1201 static bool IsSet() { return producer_ != NULL; }
1202
1203 // Returns true if T has a default return value set by the user or there
1204 // exists a built-in default value.
1205 static bool Exists() {
1206 return IsSet() || internal::BuiltInDefaultValue<T>::Exists();
1207 }
1208
1209 // Returns the default value for type T if the user has set one;
1210 // otherwise returns the built-in default value. Requires that Exists()
1211 // is true, which ensures that the return value is well-defined.
1212 static T Get() {
1213 return producer_ == NULL ?
1214 internal::BuiltInDefaultValue<T>::Get() : producer_->Produce();
1215 }
1216
1217 private:
1218 class ValueProducer {
1219 public:
1220 virtual ~ValueProducer() {}
1221 virtual T Produce() = 0;
1222 };
1223
1224 class FixedValueProducer : public ValueProducer {
1225 public:
1226 explicit FixedValueProducer(T value) : value_(value) {}
1227 virtual T Produce() { return value_; }
1228
1229 private:
1230 const T value_;
1231 GTEST_DISALLOW_COPY_AND_ASSIGN_(FixedValueProducer);
1232 };
1233
1234 class FactoryValueProducer : public ValueProducer {
1235 public:
1236 explicit FactoryValueProducer(FactoryFunction factory)
1237 : factory_(factory) {}
1238 virtual T Produce() { return factory_(); }
1239
1240 private:
1241 const FactoryFunction factory_;
1242 GTEST_DISALLOW_COPY_AND_ASSIGN_(FactoryValueProducer);
1243 };
1244
1245 static ValueProducer* producer_;
1246};
1247
1248// This partial specialization allows a user to set default values for
1249// reference types.
1250template <typename T>
1251class DefaultValue<T&> {
1252 public:
1253 // Sets the default value for type T&.
1254 static void Set(T& x) { // NOLINT
1255 address_ = &x;
1256 }
1257
1258 // Unsets the default value for type T&.
1259 static void Clear() {
1260 address_ = NULL;
1261 }
1262
1263 // Returns true iff the user has set the default value for type T&.
1264 static bool IsSet() { return address_ != NULL; }
1265
1266 // Returns true if T has a default return value set by the user or there
1267 // exists a built-in default value.
1268 static bool Exists() {
1269 return IsSet() || internal::BuiltInDefaultValue<T&>::Exists();
1270 }
1271
1272 // Returns the default value for type T& if the user has set one;
1273 // otherwise returns the built-in default value if there is one;
1274 // otherwise aborts the process.
1275 static T& Get() {
1276 return address_ == NULL ?
1277 internal::BuiltInDefaultValue<T&>::Get() : *address_;
1278 }
1279
1280 private:
1281 static T* address_;
1282};
1283
1284// This specialization allows DefaultValue<void>::Get() to
1285// compile.
1286template <>
1287class DefaultValue<void> {
1288 public:
1289 static bool Exists() { return true; }
1290 static void Get() {}
1291};
1292
1293// Points to the user-set default value for type T.
1294template <typename T>
1295typename DefaultValue<T>::ValueProducer* DefaultValue<T>::producer_ = NULL;
1296
1297// Points to the user-set default value for type T&.
1298template <typename T>
1299T* DefaultValue<T&>::address_ = NULL;
1300
1301// Implement this interface to define an action for function type F.
1302template <typename F>
1303class ActionInterface {
1304 public:
1305 typedef typename internal::Function<F>::Result Result;
1306 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
1307
1308 ActionInterface() {}
1309 virtual ~ActionInterface() {}
1310
1311 // Performs the action. This method is not const, as in general an
1312 // action can have side effects and be stateful. For example, a
1313 // get-the-next-element-from-the-collection action will need to
1314 // remember the current element.
1315 virtual Result Perform(const ArgumentTuple& args) = 0;
1316
1317 private:
1318 GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionInterface);
1319};
1320
1321// An Action<F> is a copyable and IMMUTABLE (except by assignment)
1322// object that represents an action to be taken when a mock function
1323// of type F is called. The implementation of Action<T> is just a
1324// linked_ptr to const ActionInterface<T>, so copying is fairly cheap.
1325// Don't inherit from Action!
1326//
1327// You can view an object implementing ActionInterface<F> as a
1328// concrete action (including its current state), and an Action<F>
1329// object as a handle to it.
1330template <typename F>
1331class Action {
1332 public:
1333 typedef typename internal::Function<F>::Result Result;
1334 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
1335
1336 // Constructs a null Action. Needed for storing Action objects in
1337 // STL containers.
1338 Action() : impl_(NULL) {}
1339
1340 // Constructs an Action from its implementation. A NULL impl is
1341 // used to represent the "do-default" action.
1342 explicit Action(ActionInterface<F>* impl) : impl_(impl) {}
1343
1344 // Copy constructor.
1345 Action(const Action& action) : impl_(action.impl_) {}
1346
1347 // This constructor allows us to turn an Action<Func> object into an
1348 // Action<F>, as long as F's arguments can be implicitly converted
1349 // to Func's and Func's return type can be implicitly converted to
1350 // F's.
1351 template <typename Func>
1352 explicit Action(const Action<Func>& action);
1353
1354 // Returns true iff this is the DoDefault() action.
1355 bool IsDoDefault() const { return impl_.get() == NULL; }
1356
1357 // Performs the action. Note that this method is const even though
1358 // the corresponding method in ActionInterface is not. The reason
1359 // is that a const Action<F> means that it cannot be re-bound to
1360 // another concrete action, not that the concrete action it binds to
1361 // cannot change state. (Think of the difference between a const
1362 // pointer and a pointer to const.)
1363 Result Perform(const ArgumentTuple& args) const {
1364 internal::Assert(
1365 !IsDoDefault(), __FILE__, __LINE__,
1366 "You are using DoDefault() inside a composite action like "
1367 "DoAll() or WithArgs(). This is not supported for technical "
1368 "reasons. Please instead spell out the default action, or "
1369 "assign the default action to an Action variable and use "
1370 "the variable in various places.");
1371 return impl_->Perform(args);
1372 }
1373
1374 private:
1375 template <typename F1, typename F2>
1376 friend class internal::ActionAdaptor;
1377
1378 internal::linked_ptr<ActionInterface<F> > impl_;
1379};
1380
1381// The PolymorphicAction class template makes it easy to implement a
1382// polymorphic action (i.e. an action that can be used in mock
1383// functions of than one type, e.g. Return()).
1384//
1385// To define a polymorphic action, a user first provides a COPYABLE
1386// implementation class that has a Perform() method template:
1387//
1388// class FooAction {
1389// public:
1390// template <typename Result, typename ArgumentTuple>
1391// Result Perform(const ArgumentTuple& args) const {
1392// // Processes the arguments and returns a result, using
1393// // tr1::get<N>(args) to get the N-th (0-based) argument in the tuple.
1394// }
1395// ...
1396// };
1397//
1398// Then the user creates the polymorphic action using
1399// MakePolymorphicAction(object) where object has type FooAction. See
1400// the definition of Return(void) and SetArgumentPointee<N>(value) for
1401// complete examples.
1402template <typename Impl>
1403class PolymorphicAction {
1404 public:
1405 explicit PolymorphicAction(const Impl& impl) : impl_(impl) {}
1406
1407 template <typename F>
1408 operator Action<F>() const {
1409 return Action<F>(new MonomorphicImpl<F>(impl_));
1410 }
1411
1412 private:
1413 template <typename F>
1414 class MonomorphicImpl : public ActionInterface<F> {
1415 public:
1416 typedef typename internal::Function<F>::Result Result;
1417 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
1418
1419 explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {}
1420
1421 virtual Result Perform(const ArgumentTuple& args) {
1422 return impl_.template Perform<Result>(args);
1423 }
1424
1425 private:
1426 Impl impl_;
1427
1428 GTEST_DISALLOW_ASSIGN_(MonomorphicImpl);
1429 };
1430
1431 Impl impl_;
1432
1433 GTEST_DISALLOW_ASSIGN_(PolymorphicAction);
1434};
1435
1436// Creates an Action from its implementation and returns it. The
1437// created Action object owns the implementation.
1438template <typename F>
1439Action<F> MakeAction(ActionInterface<F>* impl) {
1440 return Action<F>(impl);
1441}
1442
1443// Creates a polymorphic action from its implementation. This is
1444// easier to use than the PolymorphicAction<Impl> constructor as it
1445// doesn't require you to explicitly write the template argument, e.g.
1446//
1447// MakePolymorphicAction(foo);
1448// vs
1449// PolymorphicAction<TypeOfFoo>(foo);
1450template <typename Impl>
1451inline PolymorphicAction<Impl> MakePolymorphicAction(const Impl& impl) {
1452 return PolymorphicAction<Impl>(impl);
1453}
1454
1455namespace internal {
1456
1457// Allows an Action<F2> object to pose as an Action<F1>, as long as F2
1458// and F1 are compatible.
1459template <typename F1, typename F2>
1460class ActionAdaptor : public ActionInterface<F1> {
1461 public:
1462 typedef typename internal::Function<F1>::Result Result;
1463 typedef typename internal::Function<F1>::ArgumentTuple ArgumentTuple;
1464
1465 explicit ActionAdaptor(const Action<F2>& from) : impl_(from.impl_) {}
1466
1467 virtual Result Perform(const ArgumentTuple& args) {
1468 return impl_->Perform(args);
1469 }
1470
1471 private:
1472 const internal::linked_ptr<ActionInterface<F2> > impl_;
1473
1474 GTEST_DISALLOW_ASSIGN_(ActionAdaptor);
1475};
1476
1477// Helper struct to specialize ReturnAction to execute a move instead of a copy
1478// on return. Useful for move-only types, but could be used on any type.
1479template <typename T>
1480struct ByMoveWrapper {
1481 explicit ByMoveWrapper(T value) : payload(internal::move(value)) {}
1482 T payload;
1483};
1484
1485// Implements the polymorphic Return(x) action, which can be used in
1486// any function that returns the type of x, regardless of the argument
1487// types.
1488//
1489// Note: The value passed into Return must be converted into
1490// Function<F>::Result when this action is cast to Action<F> rather than
1491// when that action is performed. This is important in scenarios like
1492//
1493// MOCK_METHOD1(Method, T(U));
1494// ...
1495// {
1496// Foo foo;
1497// X x(&foo);
1498// EXPECT_CALL(mock, Method(_)).WillOnce(Return(x));
1499// }
1500//
1501// In the example above the variable x holds reference to foo which leaves
1502// scope and gets destroyed. If copying X just copies a reference to foo,
1503// that copy will be left with a hanging reference. If conversion to T
1504// makes a copy of foo, the above code is safe. To support that scenario, we
1505// need to make sure that the type conversion happens inside the EXPECT_CALL
1506// statement, and conversion of the result of Return to Action<T(U)> is a
1507// good place for that.
1508//
1509template <typename R>
1510class ReturnAction {
1511 public:
1512 // Constructs a ReturnAction object from the value to be returned.
1513 // 'value' is passed by value instead of by const reference in order
1514 // to allow Return("string literal") to compile.
1515 explicit ReturnAction(R value) : value_(new R(internal::move(value))) {}
1516
1517 // This template type conversion operator allows Return(x) to be
1518 // used in ANY function that returns x's type.
1519 template <typename F>
1520 operator Action<F>() const {
1521 // Assert statement belongs here because this is the best place to verify
1522 // conditions on F. It produces the clearest error messages
1523 // in most compilers.
1524 // Impl really belongs in this scope as a local class but can't
1525 // because MSVC produces duplicate symbols in different translation units
1526 // in this case. Until MS fixes that bug we put Impl into the class scope
1527 // and put the typedef both here (for use in assert statement) and
1528 // in the Impl class. But both definitions must be the same.
1529 typedef typename Function<F>::Result Result;
1530 GTEST_COMPILE_ASSERT_(
1531 !is_reference<Result>::value,
1532 use_ReturnRef_instead_of_Return_to_return_a_reference);
1533 return Action<F>(new Impl<R, F>(value_));
1534 }
1535
1536 private:
1537 // Implements the Return(x) action for a particular function type F.
1538 template <typename R_, typename F>
1539 class Impl : public ActionInterface<F> {
1540 public:
1541 typedef typename Function<F>::Result Result;
1542 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
1543
1544 // The implicit cast is necessary when Result has more than one
1545 // single-argument constructor (e.g. Result is std::vector<int>) and R
1546 // has a type conversion operator template. In that case, value_(value)
1547 // won't compile as the compiler doesn't known which constructor of
1548 // Result to call. ImplicitCast_ forces the compiler to convert R to
1549 // Result without considering explicit constructors, thus resolving the
1550 // ambiguity. value_ is then initialized using its copy constructor.
1551 explicit Impl(const linked_ptr<R>& value)
1552 : value_before_cast_(*value),
1553 value_(ImplicitCast_<Result>(value_before_cast_)) {}
1554
1555 virtual Result Perform(const ArgumentTuple&) { return value_; }
1556
1557 private:
1558 GTEST_COMPILE_ASSERT_(!is_reference<Result>::value,
1559 Result_cannot_be_a_reference_type);
1560 // We save the value before casting just in case it is being cast to a
1561 // wrapper type.
1562 R value_before_cast_;
1563 Result value_;
1564
1565 GTEST_DISALLOW_COPY_AND_ASSIGN_(Impl);
1566 };
1567
1568 // Partially specialize for ByMoveWrapper. This version of ReturnAction will
1569 // move its contents instead.
1570 template <typename R_, typename F>
1571 class Impl<ByMoveWrapper<R_>, F> : public ActionInterface<F> {
1572 public:
1573 typedef typename Function<F>::Result Result;
1574 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
1575
1576 explicit Impl(const linked_ptr<R>& wrapper)
1577 : performed_(false), wrapper_(wrapper) {}
1578
1579 virtual Result Perform(const ArgumentTuple&) {
1580 GTEST_CHECK_(!performed_)
1581 << "A ByMove() action should only be performed once.";
1582 performed_ = true;
1583 return internal::move(wrapper_->payload);
1584 }
1585
1586 private:
1587 bool performed_;
1588 const linked_ptr<R> wrapper_;
1589
1590 GTEST_DISALLOW_ASSIGN_(Impl);
1591 };
1592
1593 const linked_ptr<R> value_;
1594
1595 GTEST_DISALLOW_ASSIGN_(ReturnAction);
1596};
1597
1598// Implements the ReturnNull() action.
1599class ReturnNullAction {
1600 public:
1601 // Allows ReturnNull() to be used in any pointer-returning function. In C++11
1602 // this is enforced by returning nullptr, and in non-C++11 by asserting a
1603 // pointer type on compile time.
1604 template <typename Result, typename ArgumentTuple>
1605 static Result Perform(const ArgumentTuple&) {
1606#if GTEST_LANG_CXX11
1607 return nullptr;
1608#else
1609 GTEST_COMPILE_ASSERT_(internal::is_pointer<Result>::value,
1610 ReturnNull_can_be_used_to_return_a_pointer_only);
1611 return NULL;
1612#endif // GTEST_LANG_CXX11
1613 }
1614};
1615
1616// Implements the Return() action.
1617class ReturnVoidAction {
1618 public:
1619 // Allows Return() to be used in any void-returning function.
1620 template <typename Result, typename ArgumentTuple>
1621 static void Perform(const ArgumentTuple&) {
1622 CompileAssertTypesEqual<void, Result>();
1623 }
1624};
1625
1626// Implements the polymorphic ReturnRef(x) action, which can be used
1627// in any function that returns a reference to the type of x,
1628// regardless of the argument types.
1629template <typename T>
1630class ReturnRefAction {
1631 public:
1632 // Constructs a ReturnRefAction object from the reference to be returned.
1633 explicit ReturnRefAction(T& ref) : ref_(ref) {} // NOLINT
1634
1635 // This template type conversion operator allows ReturnRef(x) to be
1636 // used in ANY function that returns a reference to x's type.
1637 template <typename F>
1638 operator Action<F>() const {
1639 typedef typename Function<F>::Result Result;
1640 // Asserts that the function return type is a reference. This
1641 // catches the user error of using ReturnRef(x) when Return(x)
1642 // should be used, and generates some helpful error message.
1643 GTEST_COMPILE_ASSERT_(internal::is_reference<Result>::value,
1644 use_Return_instead_of_ReturnRef_to_return_a_value);
1645 return Action<F>(new Impl<F>(ref_));
1646 }
1647
1648 private:
1649 // Implements the ReturnRef(x) action for a particular function type F.
1650 template <typename F>
1651 class Impl : public ActionInterface<F> {
1652 public:
1653 typedef typename Function<F>::Result Result;
1654 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
1655
1656 explicit Impl(T& ref) : ref_(ref) {} // NOLINT
1657
1658 virtual Result Perform(const ArgumentTuple&) {
1659 return ref_;
1660 }
1661
1662 private:
1663 T& ref_;
1664
1665 GTEST_DISALLOW_ASSIGN_(Impl);
1666 };
1667
1668 T& ref_;
1669
1670 GTEST_DISALLOW_ASSIGN_(ReturnRefAction);
1671};
1672
1673// Implements the polymorphic ReturnRefOfCopy(x) action, which can be
1674// used in any function that returns a reference to the type of x,
1675// regardless of the argument types.
1676template <typename T>
1677class ReturnRefOfCopyAction {
1678 public:
1679 // Constructs a ReturnRefOfCopyAction object from the reference to
1680 // be returned.
1681 explicit ReturnRefOfCopyAction(const T& value) : value_(value) {} // NOLINT
1682
1683 // This template type conversion operator allows ReturnRefOfCopy(x) to be
1684 // used in ANY function that returns a reference to x's type.
1685 template <typename F>
1686 operator Action<F>() const {
1687 typedef typename Function<F>::Result Result;
1688 // Asserts that the function return type is a reference. This
1689 // catches the user error of using ReturnRefOfCopy(x) when Return(x)
1690 // should be used, and generates some helpful error message.
1691 GTEST_COMPILE_ASSERT_(
1692 internal::is_reference<Result>::value,
1693 use_Return_instead_of_ReturnRefOfCopy_to_return_a_value);
1694 return Action<F>(new Impl<F>(value_));
1695 }
1696
1697 private:
1698 // Implements the ReturnRefOfCopy(x) action for a particular function type F.
1699 template <typename F>
1700 class Impl : public ActionInterface<F> {
1701 public:
1702 typedef typename Function<F>::Result Result;
1703 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
1704
1705 explicit Impl(const T& value) : value_(value) {} // NOLINT
1706
1707 virtual Result Perform(const ArgumentTuple&) {
1708 return value_;
1709 }
1710
1711 private:
1712 T value_;
1713
1714 GTEST_DISALLOW_ASSIGN_(Impl);
1715 };
1716
1717 const T value_;
1718
1719 GTEST_DISALLOW_ASSIGN_(ReturnRefOfCopyAction);
1720};
1721
1722// Implements the polymorphic DoDefault() action.
1723class DoDefaultAction {
1724 public:
1725 // This template type conversion operator allows DoDefault() to be
1726 // used in any function.
1727 template <typename F>
1728 operator Action<F>() const { return Action<F>(NULL); }
1729};
1730
1731// Implements the Assign action to set a given pointer referent to a
1732// particular value.
1733template <typename T1, typename T2>
1734class AssignAction {
1735 public:
1736 AssignAction(T1* ptr, T2 value) : ptr_(ptr), value_(value) {}
1737
1738 template <typename Result, typename ArgumentTuple>
1739 void Perform(const ArgumentTuple& /* args */) const {
1740 *ptr_ = value_;
1741 }
1742
1743 private:
1744 T1* const ptr_;
1745 const T2 value_;
1746
1747 GTEST_DISALLOW_ASSIGN_(AssignAction);
1748};
1749
1750#if !GTEST_OS_WINDOWS_MOBILE
1751
1752// Implements the SetErrnoAndReturn action to simulate return from
1753// various system calls and libc functions.
1754template <typename T>
1755class SetErrnoAndReturnAction {
1756 public:
1757 SetErrnoAndReturnAction(int errno_value, T result)
1758 : errno_(errno_value),
1759 result_(result) {}
1760 template <typename Result, typename ArgumentTuple>
1761 Result Perform(const ArgumentTuple& /* args */) const {
1762 errno = errno_;
1763 return result_;
1764 }
1765
1766 private:
1767 const int errno_;
1768 const T result_;
1769
1770 GTEST_DISALLOW_ASSIGN_(SetErrnoAndReturnAction);
1771};
1772
1773#endif // !GTEST_OS_WINDOWS_MOBILE
1774
1775// Implements the SetArgumentPointee<N>(x) action for any function
1776// whose N-th argument (0-based) is a pointer to x's type. The
1777// template parameter kIsProto is true iff type A is ProtocolMessage,
1778// proto2::Message, or a sub-class of those.
1779template <size_t N, typename A, bool kIsProto>
1780class SetArgumentPointeeAction {
1781 public:
1782 // Constructs an action that sets the variable pointed to by the
1783 // N-th function argument to 'value'.
1784 explicit SetArgumentPointeeAction(const A& value) : value_(value) {}
1785
1786 template <typename Result, typename ArgumentTuple>
1787 void Perform(const ArgumentTuple& args) const {
1788 CompileAssertTypesEqual<void, Result>();
1789 *::testing::get<N>(args) = value_;
1790 }
1791
1792 private:
1793 const A value_;
1794
1795 GTEST_DISALLOW_ASSIGN_(SetArgumentPointeeAction);
1796};
1797
1798template <size_t N, typename Proto>
1799class SetArgumentPointeeAction<N, Proto, true> {
1800 public:
1801 // Constructs an action that sets the variable pointed to by the
1802 // N-th function argument to 'proto'. Both ProtocolMessage and
1803 // proto2::Message have the CopyFrom() method, so the same
1804 // implementation works for both.
1805 explicit SetArgumentPointeeAction(const Proto& proto) : proto_(new Proto) {
1806 proto_->CopyFrom(proto);
1807 }
1808
1809 template <typename Result, typename ArgumentTuple>
1810 void Perform(const ArgumentTuple& args) const {
1811 CompileAssertTypesEqual<void, Result>();
1812 ::testing::get<N>(args)->CopyFrom(*proto_);
1813 }
1814
1815 private:
1816 const internal::linked_ptr<Proto> proto_;
1817
1818 GTEST_DISALLOW_ASSIGN_(SetArgumentPointeeAction);
1819};
1820
1821// Implements the InvokeWithoutArgs(f) action. The template argument
1822// FunctionImpl is the implementation type of f, which can be either a
1823// function pointer or a functor. InvokeWithoutArgs(f) can be used as an
1824// Action<F> as long as f's type is compatible with F (i.e. f can be
1825// assigned to a tr1::function<F>).
1826template <typename FunctionImpl>
1827class InvokeWithoutArgsAction {
1828 public:
1829 // The c'tor makes a copy of function_impl (either a function
1830 // pointer or a functor).
1831 explicit InvokeWithoutArgsAction(FunctionImpl function_impl)
1832 : function_impl_(function_impl) {}
1833
1834 // Allows InvokeWithoutArgs(f) to be used as any action whose type is
1835 // compatible with f.
1836 template <typename Result, typename ArgumentTuple>
1837 Result Perform(const ArgumentTuple&) { return function_impl_(); }
1838
1839 private:
1840 FunctionImpl function_impl_;
1841
1842 GTEST_DISALLOW_ASSIGN_(InvokeWithoutArgsAction);
1843};
1844
1845// Implements the InvokeWithoutArgs(object_ptr, &Class::Method) action.
1846template <class Class, typename MethodPtr>
1847class InvokeMethodWithoutArgsAction {
1848 public:
1849 InvokeMethodWithoutArgsAction(Class* obj_ptr, MethodPtr method_ptr)
1850 : obj_ptr_(obj_ptr), method_ptr_(method_ptr) {}
1851
1852 template <typename Result, typename ArgumentTuple>
1853 Result Perform(const ArgumentTuple&) const {
1854 return (obj_ptr_->*method_ptr_)();
1855 }
1856
1857 private:
1858 Class* const obj_ptr_;
1859 const MethodPtr method_ptr_;
1860
1861 GTEST_DISALLOW_ASSIGN_(InvokeMethodWithoutArgsAction);
1862};
1863
1864// Implements the IgnoreResult(action) action.
1865template <typename A>
1866class IgnoreResultAction {
1867 public:
1868 explicit IgnoreResultAction(const A& action) : action_(action) {}
1869
1870 template <typename F>
1871 operator Action<F>() const {
1872 // Assert statement belongs here because this is the best place to verify
1873 // conditions on F. It produces the clearest error messages
1874 // in most compilers.
1875 // Impl really belongs in this scope as a local class but can't
1876 // because MSVC produces duplicate symbols in different translation units
1877 // in this case. Until MS fixes that bug we put Impl into the class scope
1878 // and put the typedef both here (for use in assert statement) and
1879 // in the Impl class. But both definitions must be the same.
1880 typedef typename internal::Function<F>::Result Result;
1881
1882 // Asserts at compile time that F returns void.
1883 CompileAssertTypesEqual<void, Result>();
1884
1885 return Action<F>(new Impl<F>(action_));
1886 }
1887
1888 private:
1889 template <typename F>
1890 class Impl : public ActionInterface<F> {
1891 public:
1892 typedef typename internal::Function<F>::Result Result;
1893 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
1894
1895 explicit Impl(const A& action) : action_(action) {}
1896
1897 virtual void Perform(const ArgumentTuple& args) {
1898 // Performs the action and ignores its result.
1899 action_.Perform(args);
1900 }
1901
1902 private:
1903 // Type OriginalFunction is the same as F except that its return
1904 // type is IgnoredValue.
1905 typedef typename internal::Function<F>::MakeResultIgnoredValue
1906 OriginalFunction;
1907
1908 const Action<OriginalFunction> action_;
1909
1910 GTEST_DISALLOW_ASSIGN_(Impl);
1911 };
1912
1913 const A action_;
1914
1915 GTEST_DISALLOW_ASSIGN_(IgnoreResultAction);
1916};
1917
1918// A ReferenceWrapper<T> object represents a reference to type T,
1919// which can be either const or not. It can be explicitly converted
1920// from, and implicitly converted to, a T&. Unlike a reference,
1921// ReferenceWrapper<T> can be copied and can survive template type
1922// inference. This is used to support by-reference arguments in the
1923// InvokeArgument<N>(...) action. The idea was from "reference
1924// wrappers" in tr1, which we don't have in our source tree yet.
1925template <typename T>
1926class ReferenceWrapper {
1927 public:
1928 // Constructs a ReferenceWrapper<T> object from a T&.
1929 explicit ReferenceWrapper(T& l_value) : pointer_(&l_value) {} // NOLINT
1930
1931 // Allows a ReferenceWrapper<T> object to be implicitly converted to
1932 // a T&.
1933 operator T&() const { return *pointer_; }
1934 private:
1935 T* pointer_;
1936};
1937
1938// Allows the expression ByRef(x) to be printed as a reference to x.
1939template <typename T>
1940void PrintTo(const ReferenceWrapper<T>& ref, ::std::ostream* os) {
1941 T& value = ref;
1942 UniversalPrinter<T&>::Print(value, os);
1943}
1944
1945// Does two actions sequentially. Used for implementing the DoAll(a1,
1946// a2, ...) action.
1947template <typename Action1, typename Action2>
1948class DoBothAction {
1949 public:
1950 DoBothAction(Action1 action1, Action2 action2)
1951 : action1_(action1), action2_(action2) {}
1952
1953 // This template type conversion operator allows DoAll(a1, ..., a_n)
1954 // to be used in ANY function of compatible type.
1955 template <typename F>
1956 operator Action<F>() const {
1957 return Action<F>(new Impl<F>(action1_, action2_));
1958 }
1959
1960 private:
1961 // Implements the DoAll(...) action for a particular function type F.
1962 template <typename F>
1963 class Impl : public ActionInterface<F> {
1964 public:
1965 typedef typename Function<F>::Result Result;
1966 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
1967 typedef typename Function<F>::MakeResultVoid VoidResult;
1968
1969 Impl(const Action<VoidResult>& action1, const Action<F>& action2)
1970 : action1_(action1), action2_(action2) {}
1971
1972 virtual Result Perform(const ArgumentTuple& args) {
1973 action1_.Perform(args);
1974 return action2_.Perform(args);
1975 }
1976
1977 private:
1978 const Action<VoidResult> action1_;
1979 const Action<F> action2_;
1980
1981 GTEST_DISALLOW_ASSIGN_(Impl);
1982 };
1983
1984 Action1 action1_;
1985 Action2 action2_;
1986
1987 GTEST_DISALLOW_ASSIGN_(DoBothAction);
1988};
1989
1990} // namespace internal
1991
1992// An Unused object can be implicitly constructed from ANY value.
1993// This is handy when defining actions that ignore some or all of the
1994// mock function arguments. For example, given
1995//
1996// MOCK_METHOD3(Foo, double(const string& label, double x, double y));
1997// MOCK_METHOD3(Bar, double(int index, double x, double y));
1998//
1999// instead of
2000//
2001// double DistanceToOriginWithLabel(const string& label, double x, double y) {
2002// return sqrt(x*x + y*y);
2003// }
2004// double DistanceToOriginWithIndex(int index, double x, double y) {
2005// return sqrt(x*x + y*y);
2006// }
2007// ...
2008// EXEPCT_CALL(mock, Foo("abc", _, _))
2009// .WillOnce(Invoke(DistanceToOriginWithLabel));
2010// EXEPCT_CALL(mock, Bar(5, _, _))
2011// .WillOnce(Invoke(DistanceToOriginWithIndex));
2012//
2013// you could write
2014//
2015// // We can declare any uninteresting argument as Unused.
2016// double DistanceToOrigin(Unused, double x, double y) {
2017// return sqrt(x*x + y*y);
2018// }
2019// ...
2020// EXEPCT_CALL(mock, Foo("abc", _, _)).WillOnce(Invoke(DistanceToOrigin));
2021// EXEPCT_CALL(mock, Bar(5, _, _)).WillOnce(Invoke(DistanceToOrigin));
2022typedef internal::IgnoredValue Unused;
2023
2024// This constructor allows us to turn an Action<From> object into an
2025// Action<To>, as long as To's arguments can be implicitly converted
2026// to From's and From's return type cann be implicitly converted to
2027// To's.
2028template <typename To>
2029template <typename From>
2030Action<To>::Action(const Action<From>& from)
2031 : impl_(new internal::ActionAdaptor<To, From>(from)) {}
2032
2033// Creates an action that returns 'value'. 'value' is passed by value
2034// instead of const reference - otherwise Return("string literal")
2035// will trigger a compiler error about using array as initializer.
2036template <typename R>
2037internal::ReturnAction<R> Return(R value) {
2038 return internal::ReturnAction<R>(internal::move(value));
2039}
2040
2041// Creates an action that returns NULL.
2042inline PolymorphicAction<internal::ReturnNullAction> ReturnNull() {
2043 return MakePolymorphicAction(internal::ReturnNullAction());
2044}
2045
2046// Creates an action that returns from a void function.
2047inline PolymorphicAction<internal::ReturnVoidAction> Return() {
2048 return MakePolymorphicAction(internal::ReturnVoidAction());
2049}
2050
2051// Creates an action that returns the reference to a variable.
2052template <typename R>
2053inline internal::ReturnRefAction<R> ReturnRef(R& x) { // NOLINT
2054 return internal::ReturnRefAction<R>(x);
2055}
2056
2057// Creates an action that returns the reference to a copy of the
2058// argument. The copy is created when the action is constructed and
2059// lives as long as the action.
2060template <typename R>
2061inline internal::ReturnRefOfCopyAction<R> ReturnRefOfCopy(const R& x) {
2062 return internal::ReturnRefOfCopyAction<R>(x);
2063}
2064
2065// Modifies the parent action (a Return() action) to perform a move of the
2066// argument instead of a copy.
2067// Return(ByMove()) actions can only be executed once and will assert this
2068// invariant.
2069template <typename R>
2070internal::ByMoveWrapper<R> ByMove(R x) {
2071 return internal::ByMoveWrapper<R>(internal::move(x));
2072}
2073
2074// Creates an action that does the default action for the give mock function.
2075inline internal::DoDefaultAction DoDefault() {
2076 return internal::DoDefaultAction();
2077}
2078
2079// Creates an action that sets the variable pointed by the N-th
2080// (0-based) function argument to 'value'.
2081template <size_t N, typename T>
2082PolymorphicAction<
2083 internal::SetArgumentPointeeAction<
2084 N, T, internal::IsAProtocolMessage<T>::value> >
2085SetArgPointee(const T& x) {
2086 return MakePolymorphicAction(internal::SetArgumentPointeeAction<
2087 N, T, internal::IsAProtocolMessage<T>::value>(x));
2088}
2089
2090#if !((GTEST_GCC_VER_ && GTEST_GCC_VER_ < 40000) || GTEST_OS_SYMBIAN)
2091// This overload allows SetArgPointee() to accept a string literal.
2092// GCC prior to the version 4.0 and Symbian C++ compiler cannot distinguish
2093// this overload from the templated version and emit a compile error.
2094template <size_t N>
2095PolymorphicAction<
2096 internal::SetArgumentPointeeAction<N, const char*, false> >
2097SetArgPointee(const char* p) {
2098 return MakePolymorphicAction(internal::SetArgumentPointeeAction<
2099 N, const char*, false>(p));
2100}
2101
2102template <size_t N>
2103PolymorphicAction<
2104 internal::SetArgumentPointeeAction<N, const wchar_t*, false> >
2105SetArgPointee(const wchar_t* p) {
2106 return MakePolymorphicAction(internal::SetArgumentPointeeAction<
2107 N, const wchar_t*, false>(p));
2108}
2109#endif
2110
2111// The following version is DEPRECATED.
2112template <size_t N, typename T>
2113PolymorphicAction<
2114 internal::SetArgumentPointeeAction<
2115 N, T, internal::IsAProtocolMessage<T>::value> >
2116SetArgumentPointee(const T& x) {
2117 return MakePolymorphicAction(internal::SetArgumentPointeeAction<
2118 N, T, internal::IsAProtocolMessage<T>::value>(x));
2119}
2120
2121// Creates an action that sets a pointer referent to a given value.
2122template <typename T1, typename T2>
2123PolymorphicAction<internal::AssignAction<T1, T2> > Assign(T1* ptr, T2 val) {
2124 return MakePolymorphicAction(internal::AssignAction<T1, T2>(ptr, val));
2125}
2126
2127#if !GTEST_OS_WINDOWS_MOBILE
2128
2129// Creates an action that sets errno and returns the appropriate error.
2130template <typename T>
2131PolymorphicAction<internal::SetErrnoAndReturnAction<T> >
2132SetErrnoAndReturn(int errval, T result) {
2133 return MakePolymorphicAction(
2134 internal::SetErrnoAndReturnAction<T>(errval, result));
2135}
2136
2137#endif // !GTEST_OS_WINDOWS_MOBILE
2138
2139// Various overloads for InvokeWithoutArgs().
2140
2141// Creates an action that invokes 'function_impl' with no argument.
2142template <typename FunctionImpl>
2143PolymorphicAction<internal::InvokeWithoutArgsAction<FunctionImpl> >
2144InvokeWithoutArgs(FunctionImpl function_impl) {
2145 return MakePolymorphicAction(
2146 internal::InvokeWithoutArgsAction<FunctionImpl>(function_impl));
2147}
2148
2149// Creates an action that invokes the given method on the given object
2150// with no argument.
2151template <class Class, typename MethodPtr>
2152PolymorphicAction<internal::InvokeMethodWithoutArgsAction<Class, MethodPtr> >
2153InvokeWithoutArgs(Class* obj_ptr, MethodPtr method_ptr) {
2154 return MakePolymorphicAction(
2155 internal::InvokeMethodWithoutArgsAction<Class, MethodPtr>(
2156 obj_ptr, method_ptr));
2157}
2158
2159// Creates an action that performs an_action and throws away its
2160// result. In other words, it changes the return type of an_action to
2161// void. an_action MUST NOT return void, or the code won't compile.
2162template <typename A>
2163inline internal::IgnoreResultAction<A> IgnoreResult(const A& an_action) {
2164 return internal::IgnoreResultAction<A>(an_action);
2165}
2166
2167// Creates a reference wrapper for the given L-value. If necessary,
2168// you can explicitly specify the type of the reference. For example,
2169// suppose 'derived' is an object of type Derived, ByRef(derived)
2170// would wrap a Derived&. If you want to wrap a const Base& instead,
2171// where Base is a base class of Derived, just write:
2172//
2173// ByRef<const Base>(derived)
2174template <typename T>
2175inline internal::ReferenceWrapper<T> ByRef(T& l_value) { // NOLINT
2176 return internal::ReferenceWrapper<T>(l_value);
2177}
2178
2179} // namespace testing
2180
2181#endif // GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
2182// Copyright 2007, Google Inc.
2183// All rights reserved.
2184//
2185// Redistribution and use in source and binary forms, with or without
2186// modification, are permitted provided that the following conditions are
2187// met:
2188//
2189// * Redistributions of source code must retain the above copyright
2190// notice, this list of conditions and the following disclaimer.
2191// * Redistributions in binary form must reproduce the above
2192// copyright notice, this list of conditions and the following disclaimer
2193// in the documentation and/or other materials provided with the
2194// distribution.
2195// * Neither the name of Google Inc. nor the names of its
2196// contributors may be used to endorse or promote products derived from
2197// this software without specific prior written permission.
2198//
2199// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2200// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2201// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2202// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2203// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2204// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2205// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2206// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2207// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2208// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2209// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2210//
2211// Author: wan@google.com (Zhanyong Wan)
2212
2213// Google Mock - a framework for writing C++ mock classes.
2214//
2215// This file implements some commonly used cardinalities. More
2216// cardinalities can be defined by the user implementing the
2217// CardinalityInterface interface if necessary.
2218
2219#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_
2220#define GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_
2221
2222#include <limits.h>
2223#include <ostream> // NOLINT
2224
2225namespace testing {
2226
2227// To implement a cardinality Foo, define:
2228// 1. a class FooCardinality that implements the
2229// CardinalityInterface interface, and
2230// 2. a factory function that creates a Cardinality object from a
2231// const FooCardinality*.
2232//
2233// The two-level delegation design follows that of Matcher, providing
2234// consistency for extension developers. It also eases ownership
2235// management as Cardinality objects can now be copied like plain values.
2236
2237// The implementation of a cardinality.
2238class CardinalityInterface {
2239 public:
2240 virtual ~CardinalityInterface() {}
2241
2242 // Conservative estimate on the lower/upper bound of the number of
2243 // calls allowed.
2244 virtual int ConservativeLowerBound() const { return 0; }
2245 virtual int ConservativeUpperBound() const { return INT_MAX; }
2246
2247 // Returns true iff call_count calls will satisfy this cardinality.
2248 virtual bool IsSatisfiedByCallCount(int call_count) const = 0;
2249
2250 // Returns true iff call_count calls will saturate this cardinality.
2251 virtual bool IsSaturatedByCallCount(int call_count) const = 0;
2252
2253 // Describes self to an ostream.
2254 virtual void DescribeTo(::std::ostream* os) const = 0;
2255};
2256
2257// A Cardinality is a copyable and IMMUTABLE (except by assignment)
2258// object that specifies how many times a mock function is expected to
2259// be called. The implementation of Cardinality is just a linked_ptr
2260// to const CardinalityInterface, so copying is fairly cheap.
2261// Don't inherit from Cardinality!
2262class GTEST_API_ Cardinality {
2263 public:
2264 // Constructs a null cardinality. Needed for storing Cardinality
2265 // objects in STL containers.
2266 Cardinality() {}
2267
2268 // Constructs a Cardinality from its implementation.
2269 explicit Cardinality(const CardinalityInterface* impl) : impl_(impl) {}
2270
2271 // Conservative estimate on the lower/upper bound of the number of
2272 // calls allowed.
2273 int ConservativeLowerBound() const { return impl_->ConservativeLowerBound(); }
2274 int ConservativeUpperBound() const { return impl_->ConservativeUpperBound(); }
2275
2276 // Returns true iff call_count calls will satisfy this cardinality.
2277 bool IsSatisfiedByCallCount(int call_count) const {
2278 return impl_->IsSatisfiedByCallCount(call_count);
2279 }
2280
2281 // Returns true iff call_count calls will saturate this cardinality.
2282 bool IsSaturatedByCallCount(int call_count) const {
2283 return impl_->IsSaturatedByCallCount(call_count);
2284 }
2285
2286 // Returns true iff call_count calls will over-saturate this
2287 // cardinality, i.e. exceed the maximum number of allowed calls.
2288 bool IsOverSaturatedByCallCount(int call_count) const {
2289 return impl_->IsSaturatedByCallCount(call_count) &&
2290 !impl_->IsSatisfiedByCallCount(call_count);
2291 }
2292
2293 // Describes self to an ostream
2294 void DescribeTo(::std::ostream* os) const { impl_->DescribeTo(os); }
2295
2296 // Describes the given actual call count to an ostream.
2297 static void DescribeActualCallCountTo(int actual_call_count,
2298 ::std::ostream* os);
2299
2300 private:
2301 internal::linked_ptr<const CardinalityInterface> impl_;
2302};
2303
2304// Creates a cardinality that allows at least n calls.
2305GTEST_API_ Cardinality AtLeast(int n);
2306
2307// Creates a cardinality that allows at most n calls.
2308GTEST_API_ Cardinality AtMost(int n);
2309
2310// Creates a cardinality that allows any number of calls.
2311GTEST_API_ Cardinality AnyNumber();
2312
2313// Creates a cardinality that allows between min and max calls.
2314GTEST_API_ Cardinality Between(int min, int max);
2315
2316// Creates a cardinality that allows exactly n calls.
2317GTEST_API_ Cardinality Exactly(int n);
2318
2319// Creates a cardinality from its implementation.
2320inline Cardinality MakeCardinality(const CardinalityInterface* c) {
2321 return Cardinality(c);
2322}
2323
2324} // namespace testing
2325
2326#endif // GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_
2327// This file was GENERATED by a script. DO NOT EDIT BY HAND!!!
2328
2329// Copyright 2007, Google Inc.
2330// All rights reserved.
2331//
2332// Redistribution and use in source and binary forms, with or without
2333// modification, are permitted provided that the following conditions are
2334// met:
2335//
2336// * Redistributions of source code must retain the above copyright
2337// notice, this list of conditions and the following disclaimer.
2338// * Redistributions in binary form must reproduce the above
2339// copyright notice, this list of conditions and the following disclaimer
2340// in the documentation and/or other materials provided with the
2341// distribution.
2342// * Neither the name of Google Inc. nor the names of its
2343// contributors may be used to endorse or promote products derived from
2344// this software without specific prior written permission.
2345//
2346// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2347// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2348// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2349// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2350// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2351// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2352// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2353// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2354// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2355// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2356// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2357//
2358// Author: wan@google.com (Zhanyong Wan)
2359
2360// Google Mock - a framework for writing C++ mock classes.
2361//
2362// This file implements some commonly used variadic actions.
2363
2364#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
2365#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
2366
2367
2368namespace testing {
2369namespace internal {
2370
2371// InvokeHelper<F> knows how to unpack an N-tuple and invoke an N-ary
2372// function or method with the unpacked values, where F is a function
2373// type that takes N arguments.
2374template <typename Result, typename ArgumentTuple>
2375class InvokeHelper;
2376
2377template <typename R>
2378class InvokeHelper<R, ::testing::tuple<> > {
2379 public:
2380 template <typename Function>
2381 static R Invoke(Function function, const ::testing::tuple<>&) {
2382 return function();
2383 }
2384
2385 template <class Class, typename MethodPtr>
2386 static R InvokeMethod(Class* obj_ptr,
2387 MethodPtr method_ptr,
2388 const ::testing::tuple<>&) {
2389 return (obj_ptr->*method_ptr)();
2390 }
2391};
2392
2393template <typename R, typename A1>
2394class InvokeHelper<R, ::testing::tuple<A1> > {
2395 public:
2396 template <typename Function>
2397 static R Invoke(Function function, const ::testing::tuple<A1>& args) {
2398 return function(get<0>(args));
2399 }
2400
2401 template <class Class, typename MethodPtr>
2402 static R InvokeMethod(Class* obj_ptr,
2403 MethodPtr method_ptr,
2404 const ::testing::tuple<A1>& args) {
2405 return (obj_ptr->*method_ptr)(get<0>(args));
2406 }
2407};
2408
2409template <typename R, typename A1, typename A2>
2410class InvokeHelper<R, ::testing::tuple<A1, A2> > {
2411 public:
2412 template <typename Function>
2413 static R Invoke(Function function, const ::testing::tuple<A1, A2>& args) {
2414 return function(get<0>(args), get<1>(args));
2415 }
2416
2417 template <class Class, typename MethodPtr>
2418 static R InvokeMethod(Class* obj_ptr,
2419 MethodPtr method_ptr,
2420 const ::testing::tuple<A1, A2>& args) {
2421 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args));
2422 }
2423};
2424
2425template <typename R, typename A1, typename A2, typename A3>
2426class InvokeHelper<R, ::testing::tuple<A1, A2, A3> > {
2427 public:
2428 template <typename Function>
2429 static R Invoke(Function function, const ::testing::tuple<A1, A2, A3>& args) {
2430 return function(get<0>(args), get<1>(args), get<2>(args));
2431 }
2432
2433 template <class Class, typename MethodPtr>
2434 static R InvokeMethod(Class* obj_ptr,
2435 MethodPtr method_ptr,
2436 const ::testing::tuple<A1, A2, A3>& args) {
2437 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args),
2438 get<2>(args));
2439 }
2440};
2441
2442template <typename R, typename A1, typename A2, typename A3, typename A4>
2443class InvokeHelper<R, ::testing::tuple<A1, A2, A3, A4> > {
2444 public:
2445 template <typename Function>
2446 static R Invoke(Function function, const ::testing::tuple<A1, A2, A3,
2447 A4>& args) {
2448 return function(get<0>(args), get<1>(args), get<2>(args),
2449 get<3>(args));
2450 }
2451
2452 template <class Class, typename MethodPtr>
2453 static R InvokeMethod(Class* obj_ptr,
2454 MethodPtr method_ptr,
2455 const ::testing::tuple<A1, A2, A3, A4>& args) {
2456 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args),
2457 get<2>(args), get<3>(args));
2458 }
2459};
2460
2461template <typename R, typename A1, typename A2, typename A3, typename A4,
2462 typename A5>
2463class InvokeHelper<R, ::testing::tuple<A1, A2, A3, A4, A5> > {
2464 public:
2465 template <typename Function>
2466 static R Invoke(Function function, const ::testing::tuple<A1, A2, A3, A4,
2467 A5>& args) {
2468 return function(get<0>(args), get<1>(args), get<2>(args),
2469 get<3>(args), get<4>(args));
2470 }
2471
2472 template <class Class, typename MethodPtr>
2473 static R InvokeMethod(Class* obj_ptr,
2474 MethodPtr method_ptr,
2475 const ::testing::tuple<A1, A2, A3, A4, A5>& args) {
2476 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args),
2477 get<2>(args), get<3>(args), get<4>(args));
2478 }
2479};
2480
2481template <typename R, typename A1, typename A2, typename A3, typename A4,
2482 typename A5, typename A6>
2483class InvokeHelper<R, ::testing::tuple<A1, A2, A3, A4, A5, A6> > {
2484 public:
2485 template <typename Function>
2486 static R Invoke(Function function, const ::testing::tuple<A1, A2, A3, A4, A5,
2487 A6>& args) {
2488 return function(get<0>(args), get<1>(args), get<2>(args),
2489 get<3>(args), get<4>(args), get<5>(args));
2490 }
2491
2492 template <class Class, typename MethodPtr>
2493 static R InvokeMethod(Class* obj_ptr,
2494 MethodPtr method_ptr,
2495 const ::testing::tuple<A1, A2, A3, A4, A5, A6>& args) {
2496 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args),
2497 get<2>(args), get<3>(args), get<4>(args), get<5>(args));
2498 }
2499};
2500
2501template <typename R, typename A1, typename A2, typename A3, typename A4,
2502 typename A5, typename A6, typename A7>
2503class InvokeHelper<R, ::testing::tuple<A1, A2, A3, A4, A5, A6, A7> > {
2504 public:
2505 template <typename Function>
2506 static R Invoke(Function function, const ::testing::tuple<A1, A2, A3, A4, A5,
2507 A6, A7>& args) {
2508 return function(get<0>(args), get<1>(args), get<2>(args),
2509 get<3>(args), get<4>(args), get<5>(args), get<6>(args));
2510 }
2511
2512 template <class Class, typename MethodPtr>
2513 static R InvokeMethod(Class* obj_ptr,
2514 MethodPtr method_ptr,
2515 const ::testing::tuple<A1, A2, A3, A4, A5, A6,
2516 A7>& args) {
2517 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args),
2518 get<2>(args), get<3>(args), get<4>(args), get<5>(args),
2519 get<6>(args));
2520 }
2521};
2522
2523template <typename R, typename A1, typename A2, typename A3, typename A4,
2524 typename A5, typename A6, typename A7, typename A8>
2525class InvokeHelper<R, ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8> > {
2526 public:
2527 template <typename Function>
2528 static R Invoke(Function function, const ::testing::tuple<A1, A2, A3, A4, A5,
2529 A6, A7, A8>& args) {
2530 return function(get<0>(args), get<1>(args), get<2>(args),
2531 get<3>(args), get<4>(args), get<5>(args), get<6>(args),
2532 get<7>(args));
2533 }
2534
2535 template <class Class, typename MethodPtr>
2536 static R InvokeMethod(Class* obj_ptr,
2537 MethodPtr method_ptr,
2538 const ::testing::tuple<A1, A2, A3, A4, A5, A6, A7,
2539 A8>& args) {
2540 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args),
2541 get<2>(args), get<3>(args), get<4>(args), get<5>(args),
2542 get<6>(args), get<7>(args));
2543 }
2544};
2545
2546template <typename R, typename A1, typename A2, typename A3, typename A4,
2547 typename A5, typename A6, typename A7, typename A8, typename A9>
2548class InvokeHelper<R, ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9> > {
2549 public:
2550 template <typename Function>
2551 static R Invoke(Function function, const ::testing::tuple<A1, A2, A3, A4, A5,
2552 A6, A7, A8, A9>& args) {
2553 return function(get<0>(args), get<1>(args), get<2>(args),
2554 get<3>(args), get<4>(args), get<5>(args), get<6>(args),
2555 get<7>(args), get<8>(args));
2556 }
2557
2558 template <class Class, typename MethodPtr>
2559 static R InvokeMethod(Class* obj_ptr,
2560 MethodPtr method_ptr,
2561 const ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8,
2562 A9>& args) {
2563 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args),
2564 get<2>(args), get<3>(args), get<4>(args), get<5>(args),
2565 get<6>(args), get<7>(args), get<8>(args));
2566 }
2567};
2568
2569template <typename R, typename A1, typename A2, typename A3, typename A4,
2570 typename A5, typename A6, typename A7, typename A8, typename A9,
2571 typename A10>
2572class InvokeHelper<R, ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9,
2573 A10> > {
2574 public:
2575 template <typename Function>
2576 static R Invoke(Function function, const ::testing::tuple<A1, A2, A3, A4, A5,
2577 A6, A7, A8, A9, A10>& args) {
2578 return function(get<0>(args), get<1>(args), get<2>(args),
2579 get<3>(args), get<4>(args), get<5>(args), get<6>(args),
2580 get<7>(args), get<8>(args), get<9>(args));
2581 }
2582
2583 template <class Class, typename MethodPtr>
2584 static R InvokeMethod(Class* obj_ptr,
2585 MethodPtr method_ptr,
2586 const ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8,
2587 A9, A10>& args) {
2588 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args),
2589 get<2>(args), get<3>(args), get<4>(args), get<5>(args),
2590 get<6>(args), get<7>(args), get<8>(args), get<9>(args));
2591 }
2592};
2593
2594// An INTERNAL macro for extracting the type of a tuple field. It's
2595// subject to change without notice - DO NOT USE IN USER CODE!
2596#define GMOCK_FIELD_(Tuple, N) \
2597 typename ::testing::tuple_element<N, Tuple>::type
2598
2599// SelectArgs<Result, ArgumentTuple, k1, k2, ..., k_n>::type is the
2600// type of an n-ary function whose i-th (1-based) argument type is the
2601// k{i}-th (0-based) field of ArgumentTuple, which must be a tuple
2602// type, and whose return type is Result. For example,
2603// SelectArgs<int, ::testing::tuple<bool, char, double, long>, 0, 3>::type
2604// is int(bool, long).
2605//
2606// SelectArgs<Result, ArgumentTuple, k1, k2, ..., k_n>::Select(args)
2607// returns the selected fields (k1, k2, ..., k_n) of args as a tuple.
2608// For example,
2609// SelectArgs<int, tuple<bool, char, double>, 2, 0>::Select(
2610// ::testing::make_tuple(true, 'a', 2.5))
2611// returns tuple (2.5, true).
2612//
2613// The numbers in list k1, k2, ..., k_n must be >= 0, where n can be
2614// in the range [0, 10]. Duplicates are allowed and they don't have
2615// to be in an ascending or descending order.
2616
2617template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
2618 int k4, int k5, int k6, int k7, int k8, int k9, int k10>
2619class SelectArgs {
2620 public:
2621 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
2622 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
2623 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5),
2624 GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7),
2625 GMOCK_FIELD_(ArgumentTuple, k8), GMOCK_FIELD_(ArgumentTuple, k9),
2626 GMOCK_FIELD_(ArgumentTuple, k10));
2627 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2628 static SelectedArgs Select(const ArgumentTuple& args) {
2629 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
2630 get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args),
2631 get<k8>(args), get<k9>(args), get<k10>(args));
2632 }
2633};
2634
2635template <typename Result, typename ArgumentTuple>
2636class SelectArgs<Result, ArgumentTuple,
2637 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1> {
2638 public:
2639 typedef Result type();
2640 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2641 static SelectedArgs Select(const ArgumentTuple& /* args */) {
2642 return SelectedArgs();
2643 }
2644};
2645
2646template <typename Result, typename ArgumentTuple, int k1>
2647class SelectArgs<Result, ArgumentTuple,
2648 k1, -1, -1, -1, -1, -1, -1, -1, -1, -1> {
2649 public:
2650 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1));
2651 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2652 static SelectedArgs Select(const ArgumentTuple& args) {
2653 return SelectedArgs(get<k1>(args));
2654 }
2655};
2656
2657template <typename Result, typename ArgumentTuple, int k1, int k2>
2658class SelectArgs<Result, ArgumentTuple,
2659 k1, k2, -1, -1, -1, -1, -1, -1, -1, -1> {
2660 public:
2661 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
2662 GMOCK_FIELD_(ArgumentTuple, k2));
2663 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2664 static SelectedArgs Select(const ArgumentTuple& args) {
2665 return SelectedArgs(get<k1>(args), get<k2>(args));
2666 }
2667};
2668
2669template <typename Result, typename ArgumentTuple, int k1, int k2, int k3>
2670class SelectArgs<Result, ArgumentTuple,
2671 k1, k2, k3, -1, -1, -1, -1, -1, -1, -1> {
2672 public:
2673 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
2674 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3));
2675 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2676 static SelectedArgs Select(const ArgumentTuple& args) {
2677 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args));
2678 }
2679};
2680
2681template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
2682 int k4>
2683class SelectArgs<Result, ArgumentTuple,
2684 k1, k2, k3, k4, -1, -1, -1, -1, -1, -1> {
2685 public:
2686 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
2687 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
2688 GMOCK_FIELD_(ArgumentTuple, k4));
2689 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2690 static SelectedArgs Select(const ArgumentTuple& args) {
2691 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
2692 get<k4>(args));
2693 }
2694};
2695
2696template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
2697 int k4, int k5>
2698class SelectArgs<Result, ArgumentTuple,
2699 k1, k2, k3, k4, k5, -1, -1, -1, -1, -1> {
2700 public:
2701 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
2702 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
2703 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5));
2704 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2705 static SelectedArgs Select(const ArgumentTuple& args) {
2706 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
2707 get<k4>(args), get<k5>(args));
2708 }
2709};
2710
2711template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
2712 int k4, int k5, int k6>
2713class SelectArgs<Result, ArgumentTuple,
2714 k1, k2, k3, k4, k5, k6, -1, -1, -1, -1> {
2715 public:
2716 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
2717 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
2718 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5),
2719 GMOCK_FIELD_(ArgumentTuple, k6));
2720 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2721 static SelectedArgs Select(const ArgumentTuple& args) {
2722 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
2723 get<k4>(args), get<k5>(args), get<k6>(args));
2724 }
2725};
2726
2727template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
2728 int k4, int k5, int k6, int k7>
2729class SelectArgs<Result, ArgumentTuple,
2730 k1, k2, k3, k4, k5, k6, k7, -1, -1, -1> {
2731 public:
2732 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
2733 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
2734 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5),
2735 GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7));
2736 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2737 static SelectedArgs Select(const ArgumentTuple& args) {
2738 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
2739 get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args));
2740 }
2741};
2742
2743template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
2744 int k4, int k5, int k6, int k7, int k8>
2745class SelectArgs<Result, ArgumentTuple,
2746 k1, k2, k3, k4, k5, k6, k7, k8, -1, -1> {
2747 public:
2748 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
2749 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
2750 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5),
2751 GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7),
2752 GMOCK_FIELD_(ArgumentTuple, k8));
2753 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2754 static SelectedArgs Select(const ArgumentTuple& args) {
2755 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
2756 get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args),
2757 get<k8>(args));
2758 }
2759};
2760
2761template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
2762 int k4, int k5, int k6, int k7, int k8, int k9>
2763class SelectArgs<Result, ArgumentTuple,
2764 k1, k2, k3, k4, k5, k6, k7, k8, k9, -1> {
2765 public:
2766 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
2767 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
2768 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5),
2769 GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7),
2770 GMOCK_FIELD_(ArgumentTuple, k8), GMOCK_FIELD_(ArgumentTuple, k9));
2771 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2772 static SelectedArgs Select(const ArgumentTuple& args) {
2773 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
2774 get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args),
2775 get<k8>(args), get<k9>(args));
2776 }
2777};
2778
2779#undef GMOCK_FIELD_
2780
2781// Implements the WithArgs action.
2782template <typename InnerAction, int k1 = -1, int k2 = -1, int k3 = -1,
2783 int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1, int k8 = -1,
2784 int k9 = -1, int k10 = -1>
2785class WithArgsAction {
2786 public:
2787 explicit WithArgsAction(const InnerAction& action) : action_(action) {}
2788
2789 template <typename F>
2790 operator Action<F>() const { return MakeAction(new Impl<F>(action_)); }
2791
2792 private:
2793 template <typename F>
2794 class Impl : public ActionInterface<F> {
2795 public:
2796 typedef typename Function<F>::Result Result;
2797 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
2798
2799 explicit Impl(const InnerAction& action) : action_(action) {}
2800
2801 virtual Result Perform(const ArgumentTuple& args) {
2802 return action_.Perform(SelectArgs<Result, ArgumentTuple, k1, k2, k3, k4,
2803 k5, k6, k7, k8, k9, k10>::Select(args));
2804 }
2805
2806 private:
2807 typedef typename SelectArgs<Result, ArgumentTuple,
2808 k1, k2, k3, k4, k5, k6, k7, k8, k9, k10>::type InnerFunctionType;
2809
2810 Action<InnerFunctionType> action_;
2811 };
2812
2813 const InnerAction action_;
2814
2815 GTEST_DISALLOW_ASSIGN_(WithArgsAction);
2816};
2817
2818// A macro from the ACTION* family (defined later in this file)
2819// defines an action that can be used in a mock function. Typically,
2820// these actions only care about a subset of the arguments of the mock
2821// function. For example, if such an action only uses the second
2822// argument, it can be used in any mock function that takes >= 2
2823// arguments where the type of the second argument is compatible.
2824//
2825// Therefore, the action implementation must be prepared to take more
2826// arguments than it needs. The ExcessiveArg type is used to
2827// represent those excessive arguments. In order to keep the compiler
2828// error messages tractable, we define it in the testing namespace
2829// instead of testing::internal. However, this is an INTERNAL TYPE
2830// and subject to change without notice, so a user MUST NOT USE THIS
2831// TYPE DIRECTLY.
2832struct ExcessiveArg {};
2833
2834// A helper class needed for implementing the ACTION* macros.
2835template <typename Result, class Impl>
2836class ActionHelper {
2837 public:
2838 static Result Perform(Impl* impl, const ::testing::tuple<>& args) {
2839 return impl->template gmock_PerformImpl<>(args, ExcessiveArg(),
2840 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2841 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2842 ExcessiveArg());
2843 }
2844
2845 template <typename A0>
2846 static Result Perform(Impl* impl, const ::testing::tuple<A0>& args) {
2847 return impl->template gmock_PerformImpl<A0>(args, get<0>(args),
2848 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2849 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2850 ExcessiveArg());
2851 }
2852
2853 template <typename A0, typename A1>
2854 static Result Perform(Impl* impl, const ::testing::tuple<A0, A1>& args) {
2855 return impl->template gmock_PerformImpl<A0, A1>(args, get<0>(args),
2856 get<1>(args), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2857 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2858 ExcessiveArg());
2859 }
2860
2861 template <typename A0, typename A1, typename A2>
2862 static Result Perform(Impl* impl, const ::testing::tuple<A0, A1, A2>& args) {
2863 return impl->template gmock_PerformImpl<A0, A1, A2>(args, get<0>(args),
2864 get<1>(args), get<2>(args), ExcessiveArg(), ExcessiveArg(),
2865 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2866 ExcessiveArg());
2867 }
2868
2869 template <typename A0, typename A1, typename A2, typename A3>
2870 static Result Perform(Impl* impl, const ::testing::tuple<A0, A1, A2,
2871 A3>& args) {
2872 return impl->template gmock_PerformImpl<A0, A1, A2, A3>(args, get<0>(args),
2873 get<1>(args), get<2>(args), get<3>(args), ExcessiveArg(),
2874 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2875 ExcessiveArg());
2876 }
2877
2878 template <typename A0, typename A1, typename A2, typename A3, typename A4>
2879 static Result Perform(Impl* impl, const ::testing::tuple<A0, A1, A2, A3,
2880 A4>& args) {
2881 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4>(args,
2882 get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args),
2883 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2884 ExcessiveArg());
2885 }
2886
2887 template <typename A0, typename A1, typename A2, typename A3, typename A4,
2888 typename A5>
2889 static Result Perform(Impl* impl, const ::testing::tuple<A0, A1, A2, A3, A4,
2890 A5>& args) {
2891 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5>(args,
2892 get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args),
2893 get<5>(args), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2894 ExcessiveArg());
2895 }
2896
2897 template <typename A0, typename A1, typename A2, typename A3, typename A4,
2898 typename A5, typename A6>
2899 static Result Perform(Impl* impl, const ::testing::tuple<A0, A1, A2, A3, A4,
2900 A5, A6>& args) {
2901 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6>(args,
2902 get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args),
2903 get<5>(args), get<6>(args), ExcessiveArg(), ExcessiveArg(),
2904 ExcessiveArg());
2905 }
2906
2907 template <typename A0, typename A1, typename A2, typename A3, typename A4,
2908 typename A5, typename A6, typename A7>
2909 static Result Perform(Impl* impl, const ::testing::tuple<A0, A1, A2, A3, A4,
2910 A5, A6, A7>& args) {
2911 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6,
2912 A7>(args, get<0>(args), get<1>(args), get<2>(args), get<3>(args),
2913 get<4>(args), get<5>(args), get<6>(args), get<7>(args), ExcessiveArg(),
2914 ExcessiveArg());
2915 }
2916
2917 template <typename A0, typename A1, typename A2, typename A3, typename A4,
2918 typename A5, typename A6, typename A7, typename A8>
2919 static Result Perform(Impl* impl, const ::testing::tuple<A0, A1, A2, A3, A4,
2920 A5, A6, A7, A8>& args) {
2921 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6, A7,
2922 A8>(args, get<0>(args), get<1>(args), get<2>(args), get<3>(args),
2923 get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args),
2924 ExcessiveArg());
2925 }
2926
2927 template <typename A0, typename A1, typename A2, typename A3, typename A4,
2928 typename A5, typename A6, typename A7, typename A8, typename A9>
2929 static Result Perform(Impl* impl, const ::testing::tuple<A0, A1, A2, A3, A4,
2930 A5, A6, A7, A8, A9>& args) {
2931 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6, A7, A8,
2932 A9>(args, get<0>(args), get<1>(args), get<2>(args), get<3>(args),
2933 get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args),
2934 get<9>(args));
2935 }
2936};
2937
2938} // namespace internal
2939
2940// Various overloads for Invoke().
2941
2942// WithArgs<N1, N2, ..., Nk>(an_action) creates an action that passes
2943// the selected arguments of the mock function to an_action and
2944// performs it. It serves as an adaptor between actions with
2945// different argument lists. C++ doesn't support default arguments for
2946// function templates, so we have to overload it.
2947template <int k1, typename InnerAction>
2948inline internal::WithArgsAction<InnerAction, k1>
2949WithArgs(const InnerAction& action) {
2950 return internal::WithArgsAction<InnerAction, k1>(action);
2951}
2952
2953template <int k1, int k2, typename InnerAction>
2954inline internal::WithArgsAction<InnerAction, k1, k2>
2955WithArgs(const InnerAction& action) {
2956 return internal::WithArgsAction<InnerAction, k1, k2>(action);
2957}
2958
2959template <int k1, int k2, int k3, typename InnerAction>
2960inline internal::WithArgsAction<InnerAction, k1, k2, k3>
2961WithArgs(const InnerAction& action) {
2962 return internal::WithArgsAction<InnerAction, k1, k2, k3>(action);
2963}
2964
2965template <int k1, int k2, int k3, int k4, typename InnerAction>
2966inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4>
2967WithArgs(const InnerAction& action) {
2968 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4>(action);
2969}
2970
2971template <int k1, int k2, int k3, int k4, int k5, typename InnerAction>
2972inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5>
2973WithArgs(const InnerAction& action) {
2974 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5>(action);
2975}
2976
2977template <int k1, int k2, int k3, int k4, int k5, int k6, typename InnerAction>
2978inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6>
2979WithArgs(const InnerAction& action) {
2980 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6>(action);
2981}
2982
2983template <int k1, int k2, int k3, int k4, int k5, int k6, int k7,
2984 typename InnerAction>
2985inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7>
2986WithArgs(const InnerAction& action) {
2987 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6,
2988 k7>(action);
2989}
2990
2991template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
2992 typename InnerAction>
2993inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8>
2994WithArgs(const InnerAction& action) {
2995 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7,
2996 k8>(action);
2997}
2998
2999template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
3000 int k9, typename InnerAction>
3001inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8, k9>
3002WithArgs(const InnerAction& action) {
3003 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8,
3004 k9>(action);
3005}
3006
3007template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
3008 int k9, int k10, typename InnerAction>
3009inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8,
3010 k9, k10>
3011WithArgs(const InnerAction& action) {
3012 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8,
3013 k9, k10>(action);
3014}
3015
3016// Creates an action that does actions a1, a2, ..., sequentially in
3017// each invocation.
3018template <typename Action1, typename Action2>
3019inline internal::DoBothAction<Action1, Action2>
3020DoAll(Action1 a1, Action2 a2) {
3021 return internal::DoBothAction<Action1, Action2>(a1, a2);
3022}
3023
3024template <typename Action1, typename Action2, typename Action3>
3025inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
3026 Action3> >
3027DoAll(Action1 a1, Action2 a2, Action3 a3) {
3028 return DoAll(a1, DoAll(a2, a3));
3029}
3030
3031template <typename Action1, typename Action2, typename Action3,
3032 typename Action4>
3033inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
3034 internal::DoBothAction<Action3, Action4> > >
3035DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4) {
3036 return DoAll(a1, DoAll(a2, a3, a4));
3037}
3038
3039template <typename Action1, typename Action2, typename Action3,
3040 typename Action4, typename Action5>
3041inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
3042 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
3043 Action5> > > >
3044DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5) {
3045 return DoAll(a1, DoAll(a2, a3, a4, a5));
3046}
3047
3048template <typename Action1, typename Action2, typename Action3,
3049 typename Action4, typename Action5, typename Action6>
3050inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
3051 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
3052 internal::DoBothAction<Action5, Action6> > > > >
3053DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6) {
3054 return DoAll(a1, DoAll(a2, a3, a4, a5, a6));
3055}
3056
3057template <typename Action1, typename Action2, typename Action3,
3058 typename Action4, typename Action5, typename Action6, typename Action7>
3059inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
3060 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
3061 internal::DoBothAction<Action5, internal::DoBothAction<Action6,
3062 Action7> > > > > >
3063DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
3064 Action7 a7) {
3065 return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7));
3066}
3067
3068template <typename Action1, typename Action2, typename Action3,
3069 typename Action4, typename Action5, typename Action6, typename Action7,
3070 typename Action8>
3071inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
3072 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
3073 internal::DoBothAction<Action5, internal::DoBothAction<Action6,
3074 internal::DoBothAction<Action7, Action8> > > > > > >
3075DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
3076 Action7 a7, Action8 a8) {
3077 return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8));
3078}
3079
3080template <typename Action1, typename Action2, typename Action3,
3081 typename Action4, typename Action5, typename Action6, typename Action7,
3082 typename Action8, typename Action9>
3083inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
3084 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
3085 internal::DoBothAction<Action5, internal::DoBothAction<Action6,
3086 internal::DoBothAction<Action7, internal::DoBothAction<Action8,
3087 Action9> > > > > > > >
3088DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
3089 Action7 a7, Action8 a8, Action9 a9) {
3090 return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8, a9));
3091}
3092
3093template <typename Action1, typename Action2, typename Action3,
3094 typename Action4, typename Action5, typename Action6, typename Action7,
3095 typename Action8, typename Action9, typename Action10>
3096inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
3097 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
3098 internal::DoBothAction<Action5, internal::DoBothAction<Action6,
3099 internal::DoBothAction<Action7, internal::DoBothAction<Action8,
3100 internal::DoBothAction<Action9, Action10> > > > > > > > >
3101DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
3102 Action7 a7, Action8 a8, Action9 a9, Action10 a10) {
3103 return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8, a9, a10));
3104}
3105
3106} // namespace testing
3107
3108// The ACTION* family of macros can be used in a namespace scope to
3109// define custom actions easily. The syntax:
3110//
3111// ACTION(name) { statements; }
3112//
3113// will define an action with the given name that executes the
3114// statements. The value returned by the statements will be used as
3115// the return value of the action. Inside the statements, you can
3116// refer to the K-th (0-based) argument of the mock function by
3117// 'argK', and refer to its type by 'argK_type'. For example:
3118//
3119// ACTION(IncrementArg1) {
3120// arg1_type temp = arg1;
3121// return ++(*temp);
3122// }
3123//
3124// allows you to write
3125//
3126// ...WillOnce(IncrementArg1());
3127//
3128// You can also refer to the entire argument tuple and its type by
3129// 'args' and 'args_type', and refer to the mock function type and its
3130// return type by 'function_type' and 'return_type'.
3131//
3132// Note that you don't need to specify the types of the mock function
3133// arguments. However rest assured that your code is still type-safe:
3134// you'll get a compiler error if *arg1 doesn't support the ++
3135// operator, or if the type of ++(*arg1) isn't compatible with the
3136// mock function's return type, for example.
3137//
3138// Sometimes you'll want to parameterize the action. For that you can use
3139// another macro:
3140//
3141// ACTION_P(name, param_name) { statements; }
3142//
3143// For example:
3144//
3145// ACTION_P(Add, n) { return arg0 + n; }
3146//
3147// will allow you to write:
3148//
3149// ...WillOnce(Add(5));
3150//
3151// Note that you don't need to provide the type of the parameter
3152// either. If you need to reference the type of a parameter named
3153// 'foo', you can write 'foo_type'. For example, in the body of
3154// ACTION_P(Add, n) above, you can write 'n_type' to refer to the type
3155// of 'n'.
3156//
3157// We also provide ACTION_P2, ACTION_P3, ..., up to ACTION_P10 to support
3158// multi-parameter actions.
3159//
3160// For the purpose of typing, you can view
3161//
3162// ACTION_Pk(Foo, p1, ..., pk) { ... }
3163//
3164// as shorthand for
3165//
3166// template <typename p1_type, ..., typename pk_type>
3167// FooActionPk<p1_type, ..., pk_type> Foo(p1_type p1, ..., pk_type pk) { ... }
3168//
3169// In particular, you can provide the template type arguments
3170// explicitly when invoking Foo(), as in Foo<long, bool>(5, false);
3171// although usually you can rely on the compiler to infer the types
3172// for you automatically. You can assign the result of expression
3173// Foo(p1, ..., pk) to a variable of type FooActionPk<p1_type, ...,
3174// pk_type>. This can be useful when composing actions.
3175//
3176// You can also overload actions with different numbers of parameters:
3177//
3178// ACTION_P(Plus, a) { ... }
3179// ACTION_P2(Plus, a, b) { ... }
3180//
3181// While it's tempting to always use the ACTION* macros when defining
3182// a new action, you should also consider implementing ActionInterface
3183// or using MakePolymorphicAction() instead, especially if you need to
3184// use the action a lot. While these approaches require more work,
3185// they give you more control on the types of the mock function
3186// arguments and the action parameters, which in general leads to
3187// better compiler error messages that pay off in the long run. They
3188// also allow overloading actions based on parameter types (as opposed
3189// to just based on the number of parameters).
3190//
3191// CAVEAT:
3192//
3193// ACTION*() can only be used in a namespace scope. The reason is
3194// that C++ doesn't yet allow function-local types to be used to
3195// instantiate templates. The up-coming C++0x standard will fix this.
3196// Once that's done, we'll consider supporting using ACTION*() inside
3197// a function.
3198//
3199// MORE INFORMATION:
3200//
3201// To learn more about using these macros, please search for 'ACTION'
3202// on http://code.google.com/p/googlemock/wiki/CookBook.
3203
3204// An internal macro needed for implementing ACTION*().
3205#define GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_\
3206 const args_type& args GTEST_ATTRIBUTE_UNUSED_, \
3207 arg0_type arg0 GTEST_ATTRIBUTE_UNUSED_, \
3208 arg1_type arg1 GTEST_ATTRIBUTE_UNUSED_, \
3209 arg2_type arg2 GTEST_ATTRIBUTE_UNUSED_, \
3210 arg3_type arg3 GTEST_ATTRIBUTE_UNUSED_, \
3211 arg4_type arg4 GTEST_ATTRIBUTE_UNUSED_, \
3212 arg5_type arg5 GTEST_ATTRIBUTE_UNUSED_, \
3213 arg6_type arg6 GTEST_ATTRIBUTE_UNUSED_, \
3214 arg7_type arg7 GTEST_ATTRIBUTE_UNUSED_, \
3215 arg8_type arg8 GTEST_ATTRIBUTE_UNUSED_, \
3216 arg9_type arg9 GTEST_ATTRIBUTE_UNUSED_
3217
3218// Sometimes you want to give an action explicit template parameters
3219// that cannot be inferred from its value parameters. ACTION() and
3220// ACTION_P*() don't support that. ACTION_TEMPLATE() remedies that
3221// and can be viewed as an extension to ACTION() and ACTION_P*().
3222//
3223// The syntax:
3224//
3225// ACTION_TEMPLATE(ActionName,
3226// HAS_m_TEMPLATE_PARAMS(kind1, name1, ..., kind_m, name_m),
3227// AND_n_VALUE_PARAMS(p1, ..., p_n)) { statements; }
3228//
3229// defines an action template that takes m explicit template
3230// parameters and n value parameters. name_i is the name of the i-th
3231// template parameter, and kind_i specifies whether it's a typename,
3232// an integral constant, or a template. p_i is the name of the i-th
3233// value parameter.
3234//
3235// Example:
3236//
3237// // DuplicateArg<k, T>(output) converts the k-th argument of the mock
3238// // function to type T and copies it to *output.
3239// ACTION_TEMPLATE(DuplicateArg,
3240// HAS_2_TEMPLATE_PARAMS(int, k, typename, T),
3241// AND_1_VALUE_PARAMS(output)) {
3242// *output = T(::testing::get<k>(args));
3243// }
3244// ...
3245// int n;
3246// EXPECT_CALL(mock, Foo(_, _))
3247// .WillOnce(DuplicateArg<1, unsigned char>(&n));
3248//
3249// To create an instance of an action template, write:
3250//
3251// ActionName<t1, ..., t_m>(v1, ..., v_n)
3252//
3253// where the ts are the template arguments and the vs are the value
3254// arguments. The value argument types are inferred by the compiler.
3255// If you want to explicitly specify the value argument types, you can
3256// provide additional template arguments:
3257//
3258// ActionName<t1, ..., t_m, u1, ..., u_k>(v1, ..., v_n)
3259//
3260// where u_i is the desired type of v_i.
3261//
3262// ACTION_TEMPLATE and ACTION/ACTION_P* can be overloaded on the
3263// number of value parameters, but not on the number of template
3264// parameters. Without the restriction, the meaning of the following
3265// is unclear:
3266//
3267// OverloadedAction<int, bool>(x);
3268//
3269// Are we using a single-template-parameter action where 'bool' refers
3270// to the type of x, or are we using a two-template-parameter action
3271// where the compiler is asked to infer the type of x?
3272//
3273// Implementation notes:
3274//
3275// GMOCK_INTERNAL_*_HAS_m_TEMPLATE_PARAMS and
3276// GMOCK_INTERNAL_*_AND_n_VALUE_PARAMS are internal macros for
3277// implementing ACTION_TEMPLATE. The main trick we use is to create
3278// new macro invocations when expanding a macro. For example, we have
3279//
3280// #define ACTION_TEMPLATE(name, template_params, value_params)
3281// ... GMOCK_INTERNAL_DECL_##template_params ...
3282//
3283// which causes ACTION_TEMPLATE(..., HAS_1_TEMPLATE_PARAMS(typename, T), ...)
3284// to expand to
3285//
3286// ... GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(typename, T) ...
3287//
3288// Since GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS is a macro, the
3289// preprocessor will continue to expand it to
3290//
3291// ... typename T ...
3292//
3293// This technique conforms to the C++ standard and is portable. It
3294// allows us to implement action templates using O(N) code, where N is
3295// the maximum number of template/value parameters supported. Without
3296// using it, we'd have to devote O(N^2) amount of code to implement all
3297// combinations of m and n.
3298
3299// Declares the template parameters.
3300#define GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(kind0, name0) kind0 name0
3301#define GMOCK_INTERNAL_DECL_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, \
3302 name1) kind0 name0, kind1 name1
3303#define GMOCK_INTERNAL_DECL_HAS_3_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3304 kind2, name2) kind0 name0, kind1 name1, kind2 name2
3305#define GMOCK_INTERNAL_DECL_HAS_4_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3306 kind2, name2, kind3, name3) kind0 name0, kind1 name1, kind2 name2, \
3307 kind3 name3
3308#define GMOCK_INTERNAL_DECL_HAS_5_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3309 kind2, name2, kind3, name3, kind4, name4) kind0 name0, kind1 name1, \
3310 kind2 name2, kind3 name3, kind4 name4
3311#define GMOCK_INTERNAL_DECL_HAS_6_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3312 kind2, name2, kind3, name3, kind4, name4, kind5, name5) kind0 name0, \
3313 kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5
3314#define GMOCK_INTERNAL_DECL_HAS_7_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3315 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
3316 name6) kind0 name0, kind1 name1, kind2 name2, kind3 name3, kind4 name4, \
3317 kind5 name5, kind6 name6
3318#define GMOCK_INTERNAL_DECL_HAS_8_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3319 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
3320 kind7, name7) kind0 name0, kind1 name1, kind2 name2, kind3 name3, \
3321 kind4 name4, kind5 name5, kind6 name6, kind7 name7
3322#define GMOCK_INTERNAL_DECL_HAS_9_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3323 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
3324 kind7, name7, kind8, name8) kind0 name0, kind1 name1, kind2 name2, \
3325 kind3 name3, kind4 name4, kind5 name5, kind6 name6, kind7 name7, \
3326 kind8 name8
3327#define GMOCK_INTERNAL_DECL_HAS_10_TEMPLATE_PARAMS(kind0, name0, kind1, \
3328 name1, kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
3329 name6, kind7, name7, kind8, name8, kind9, name9) kind0 name0, \
3330 kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5, \
3331 kind6 name6, kind7 name7, kind8 name8, kind9 name9
3332
3333// Lists the template parameters.
3334#define GMOCK_INTERNAL_LIST_HAS_1_TEMPLATE_PARAMS(kind0, name0) name0
3335#define GMOCK_INTERNAL_LIST_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, \
3336 name1) name0, name1
3337#define GMOCK_INTERNAL_LIST_HAS_3_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3338 kind2, name2) name0, name1, name2
3339#define GMOCK_INTERNAL_LIST_HAS_4_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3340 kind2, name2, kind3, name3) name0, name1, name2, name3
3341#define GMOCK_INTERNAL_LIST_HAS_5_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3342 kind2, name2, kind3, name3, kind4, name4) name0, name1, name2, name3, \
3343 name4
3344#define GMOCK_INTERNAL_LIST_HAS_6_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3345 kind2, name2, kind3, name3, kind4, name4, kind5, name5) name0, name1, \
3346 name2, name3, name4, name5
3347#define GMOCK_INTERNAL_LIST_HAS_7_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3348 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
3349 name6) name0, name1, name2, name3, name4, name5, name6
3350#define GMOCK_INTERNAL_LIST_HAS_8_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3351 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
3352 kind7, name7) name0, name1, name2, name3, name4, name5, name6, name7
3353#define GMOCK_INTERNAL_LIST_HAS_9_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3354 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
3355 kind7, name7, kind8, name8) name0, name1, name2, name3, name4, name5, \
3356 name6, name7, name8
3357#define GMOCK_INTERNAL_LIST_HAS_10_TEMPLATE_PARAMS(kind0, name0, kind1, \
3358 name1, kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
3359 name6, kind7, name7, kind8, name8, kind9, name9) name0, name1, name2, \
3360 name3, name4, name5, name6, name7, name8, name9
3361
3362// Declares the types of value parameters.
3363#define GMOCK_INTERNAL_DECL_TYPE_AND_0_VALUE_PARAMS()
3364#define GMOCK_INTERNAL_DECL_TYPE_AND_1_VALUE_PARAMS(p0) , typename p0##_type
3365#define GMOCK_INTERNAL_DECL_TYPE_AND_2_VALUE_PARAMS(p0, p1) , \
3366 typename p0##_type, typename p1##_type
3367#define GMOCK_INTERNAL_DECL_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) , \
3368 typename p0##_type, typename p1##_type, typename p2##_type
3369#define GMOCK_INTERNAL_DECL_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) , \
3370 typename p0##_type, typename p1##_type, typename p2##_type, \
3371 typename p3##_type
3372#define GMOCK_INTERNAL_DECL_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) , \
3373 typename p0##_type, typename p1##_type, typename p2##_type, \
3374 typename p3##_type, typename p4##_type
3375#define GMOCK_INTERNAL_DECL_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) , \
3376 typename p0##_type, typename p1##_type, typename p2##_type, \
3377 typename p3##_type, typename p4##_type, typename p5##_type
3378#define GMOCK_INTERNAL_DECL_TYPE_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3379 p6) , typename p0##_type, typename p1##_type, typename p2##_type, \
3380 typename p3##_type, typename p4##_type, typename p5##_type, \
3381 typename p6##_type
3382#define GMOCK_INTERNAL_DECL_TYPE_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3383 p6, p7) , typename p0##_type, typename p1##_type, typename p2##_type, \
3384 typename p3##_type, typename p4##_type, typename p5##_type, \
3385 typename p6##_type, typename p7##_type
3386#define GMOCK_INTERNAL_DECL_TYPE_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3387 p6, p7, p8) , typename p0##_type, typename p1##_type, typename p2##_type, \
3388 typename p3##_type, typename p4##_type, typename p5##_type, \
3389 typename p6##_type, typename p7##_type, typename p8##_type
3390#define GMOCK_INTERNAL_DECL_TYPE_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3391 p6, p7, p8, p9) , typename p0##_type, typename p1##_type, \
3392 typename p2##_type, typename p3##_type, typename p4##_type, \
3393 typename p5##_type, typename p6##_type, typename p7##_type, \
3394 typename p8##_type, typename p9##_type
3395
3396// Initializes the value parameters.
3397#define GMOCK_INTERNAL_INIT_AND_0_VALUE_PARAMS()\
3398 ()
3399#define GMOCK_INTERNAL_INIT_AND_1_VALUE_PARAMS(p0)\
3400 (p0##_type gmock_p0) : p0(gmock_p0)
3401#define GMOCK_INTERNAL_INIT_AND_2_VALUE_PARAMS(p0, p1)\
3402 (p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), p1(gmock_p1)
3403#define GMOCK_INTERNAL_INIT_AND_3_VALUE_PARAMS(p0, p1, p2)\
3404 (p0##_type gmock_p0, p1##_type gmock_p1, \
3405 p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2)
3406#define GMOCK_INTERNAL_INIT_AND_4_VALUE_PARAMS(p0, p1, p2, p3)\
3407 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3408 p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
3409 p3(gmock_p3)
3410#define GMOCK_INTERNAL_INIT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)\
3411 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3412 p3##_type gmock_p3, p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), \
3413 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4)
3414#define GMOCK_INTERNAL_INIT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)\
3415 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3416 p3##_type gmock_p3, p4##_type gmock_p4, \
3417 p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
3418 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5)
3419#define GMOCK_INTERNAL_INIT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)\
3420 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3421 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
3422 p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
3423 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6)
3424#define GMOCK_INTERNAL_INIT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)\
3425 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3426 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
3427 p6##_type gmock_p6, p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), \
3428 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
3429 p7(gmock_p7)
3430#define GMOCK_INTERNAL_INIT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3431 p7, p8)\
3432 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3433 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
3434 p6##_type gmock_p6, p7##_type gmock_p7, \
3435 p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
3436 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
3437 p8(gmock_p8)
3438#define GMOCK_INTERNAL_INIT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3439 p7, p8, p9)\
3440 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3441 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
3442 p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
3443 p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
3444 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
3445 p8(gmock_p8), p9(gmock_p9)
3446
3447// Declares the fields for storing the value parameters.
3448#define GMOCK_INTERNAL_DEFN_AND_0_VALUE_PARAMS()
3449#define GMOCK_INTERNAL_DEFN_AND_1_VALUE_PARAMS(p0) p0##_type p0;
3450#define GMOCK_INTERNAL_DEFN_AND_2_VALUE_PARAMS(p0, p1) p0##_type p0; \
3451 p1##_type p1;
3452#define GMOCK_INTERNAL_DEFN_AND_3_VALUE_PARAMS(p0, p1, p2) p0##_type p0; \
3453 p1##_type p1; p2##_type p2;
3454#define GMOCK_INTERNAL_DEFN_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0##_type p0; \
3455 p1##_type p1; p2##_type p2; p3##_type p3;
3456#define GMOCK_INTERNAL_DEFN_AND_5_VALUE_PARAMS(p0, p1, p2, p3, \
3457 p4) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4;
3458#define GMOCK_INTERNAL_DEFN_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, \
3459 p5) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \
3460 p5##_type p5;
3461#define GMOCK_INTERNAL_DEFN_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3462 p6) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \
3463 p5##_type p5; p6##_type p6;
3464#define GMOCK_INTERNAL_DEFN_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3465 p7) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \
3466 p5##_type p5; p6##_type p6; p7##_type p7;
3467#define GMOCK_INTERNAL_DEFN_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3468 p7, p8) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; \
3469 p4##_type p4; p5##_type p5; p6##_type p6; p7##_type p7; p8##_type p8;
3470#define GMOCK_INTERNAL_DEFN_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3471 p7, p8, p9) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; \
3472 p4##_type p4; p5##_type p5; p6##_type p6; p7##_type p7; p8##_type p8; \
3473 p9##_type p9;
3474
3475// Lists the value parameters.
3476#define GMOCK_INTERNAL_LIST_AND_0_VALUE_PARAMS()
3477#define GMOCK_INTERNAL_LIST_AND_1_VALUE_PARAMS(p0) p0
3478#define GMOCK_INTERNAL_LIST_AND_2_VALUE_PARAMS(p0, p1) p0, p1
3479#define GMOCK_INTERNAL_LIST_AND_3_VALUE_PARAMS(p0, p1, p2) p0, p1, p2
3480#define GMOCK_INTERNAL_LIST_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0, p1, p2, p3
3481#define GMOCK_INTERNAL_LIST_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) p0, p1, \
3482 p2, p3, p4
3483#define GMOCK_INTERNAL_LIST_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) p0, \
3484 p1, p2, p3, p4, p5
3485#define GMOCK_INTERNAL_LIST_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3486 p6) p0, p1, p2, p3, p4, p5, p6
3487#define GMOCK_INTERNAL_LIST_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3488 p7) p0, p1, p2, p3, p4, p5, p6, p7
3489#define GMOCK_INTERNAL_LIST_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3490 p7, p8) p0, p1, p2, p3, p4, p5, p6, p7, p8
3491#define GMOCK_INTERNAL_LIST_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3492 p7, p8, p9) p0, p1, p2, p3, p4, p5, p6, p7, p8, p9
3493
3494// Lists the value parameter types.
3495#define GMOCK_INTERNAL_LIST_TYPE_AND_0_VALUE_PARAMS()
3496#define GMOCK_INTERNAL_LIST_TYPE_AND_1_VALUE_PARAMS(p0) , p0##_type
3497#define GMOCK_INTERNAL_LIST_TYPE_AND_2_VALUE_PARAMS(p0, p1) , p0##_type, \
3498 p1##_type
3499#define GMOCK_INTERNAL_LIST_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) , p0##_type, \
3500 p1##_type, p2##_type
3501#define GMOCK_INTERNAL_LIST_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) , \
3502 p0##_type, p1##_type, p2##_type, p3##_type
3503#define GMOCK_INTERNAL_LIST_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) , \
3504 p0##_type, p1##_type, p2##_type, p3##_type, p4##_type
3505#define GMOCK_INTERNAL_LIST_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) , \
3506 p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type
3507#define GMOCK_INTERNAL_LIST_TYPE_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3508 p6) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type, \
3509 p6##_type
3510#define GMOCK_INTERNAL_LIST_TYPE_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3511 p6, p7) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
3512 p5##_type, p6##_type, p7##_type
3513#define GMOCK_INTERNAL_LIST_TYPE_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3514 p6, p7, p8) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
3515 p5##_type, p6##_type, p7##_type, p8##_type
3516#define GMOCK_INTERNAL_LIST_TYPE_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3517 p6, p7, p8, p9) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
3518 p5##_type, p6##_type, p7##_type, p8##_type, p9##_type
3519
3520// Declares the value parameters.
3521#define GMOCK_INTERNAL_DECL_AND_0_VALUE_PARAMS()
3522#define GMOCK_INTERNAL_DECL_AND_1_VALUE_PARAMS(p0) p0##_type p0
3523#define GMOCK_INTERNAL_DECL_AND_2_VALUE_PARAMS(p0, p1) p0##_type p0, \
3524 p1##_type p1
3525#define GMOCK_INTERNAL_DECL_AND_3_VALUE_PARAMS(p0, p1, p2) p0##_type p0, \
3526 p1##_type p1, p2##_type p2
3527#define GMOCK_INTERNAL_DECL_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0##_type p0, \
3528 p1##_type p1, p2##_type p2, p3##_type p3
3529#define GMOCK_INTERNAL_DECL_AND_5_VALUE_PARAMS(p0, p1, p2, p3, \
3530 p4) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4
3531#define GMOCK_INTERNAL_DECL_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, \
3532 p5) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \
3533 p5##_type p5
3534#define GMOCK_INTERNAL_DECL_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3535 p6) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \
3536 p5##_type p5, p6##_type p6
3537#define GMOCK_INTERNAL_DECL_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3538 p7) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \
3539 p5##_type p5, p6##_type p6, p7##_type p7
3540#define GMOCK_INTERNAL_DECL_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3541 p7, p8) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
3542 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8
3543#define GMOCK_INTERNAL_DECL_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3544 p7, p8, p9) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
3545 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \
3546 p9##_type p9
3547
3548// The suffix of the class template implementing the action template.
3549#define GMOCK_INTERNAL_COUNT_AND_0_VALUE_PARAMS()
3550#define GMOCK_INTERNAL_COUNT_AND_1_VALUE_PARAMS(p0) P
3551#define GMOCK_INTERNAL_COUNT_AND_2_VALUE_PARAMS(p0, p1) P2
3552#define GMOCK_INTERNAL_COUNT_AND_3_VALUE_PARAMS(p0, p1, p2) P3
3553#define GMOCK_INTERNAL_COUNT_AND_4_VALUE_PARAMS(p0, p1, p2, p3) P4
3554#define GMOCK_INTERNAL_COUNT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) P5
3555#define GMOCK_INTERNAL_COUNT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) P6
3556#define GMOCK_INTERNAL_COUNT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6) P7
3557#define GMOCK_INTERNAL_COUNT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3558 p7) P8
3559#define GMOCK_INTERNAL_COUNT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3560 p7, p8) P9
3561#define GMOCK_INTERNAL_COUNT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3562 p7, p8, p9) P10
3563
3564// The name of the class template implementing the action template.
3565#define GMOCK_ACTION_CLASS_(name, value_params)\
3566 GTEST_CONCAT_TOKEN_(name##Action, GMOCK_INTERNAL_COUNT_##value_params)
3567
3568#define ACTION_TEMPLATE(name, template_params, value_params)\
3569 template <GMOCK_INTERNAL_DECL_##template_params\
3570 GMOCK_INTERNAL_DECL_TYPE_##value_params>\
3571 class GMOCK_ACTION_CLASS_(name, value_params) {\
3572 public:\
3573 explicit GMOCK_ACTION_CLASS_(name, value_params)\
3574 GMOCK_INTERNAL_INIT_##value_params {}\
3575 template <typename F>\
3576 class gmock_Impl : public ::testing::ActionInterface<F> {\
3577 public:\
3578 typedef F function_type;\
3579 typedef typename ::testing::internal::Function<F>::Result return_type;\
3580 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
3581 args_type;\
3582 explicit gmock_Impl GMOCK_INTERNAL_INIT_##value_params {}\
3583 virtual return_type Perform(const args_type& args) {\
3584 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
3585 Perform(this, args);\
3586 }\
3587 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3588 typename arg3_type, typename arg4_type, typename arg5_type, \
3589 typename arg6_type, typename arg7_type, typename arg8_type, \
3590 typename arg9_type>\
3591 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
3592 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
3593 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
3594 arg9_type arg9) const;\
3595 GMOCK_INTERNAL_DEFN_##value_params\
3596 private:\
3597 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
3598 };\
3599 template <typename F> operator ::testing::Action<F>() const {\
3600 return ::testing::Action<F>(\
3601 new gmock_Impl<F>(GMOCK_INTERNAL_LIST_##value_params));\
3602 }\
3603 GMOCK_INTERNAL_DEFN_##value_params\
3604 private:\
3605 GTEST_DISALLOW_ASSIGN_(GMOCK_ACTION_CLASS_(name, value_params));\
3606 };\
3607 template <GMOCK_INTERNAL_DECL_##template_params\
3608 GMOCK_INTERNAL_DECL_TYPE_##value_params>\
3609 inline GMOCK_ACTION_CLASS_(name, value_params)<\
3610 GMOCK_INTERNAL_LIST_##template_params\
3611 GMOCK_INTERNAL_LIST_TYPE_##value_params> name(\
3612 GMOCK_INTERNAL_DECL_##value_params) {\
3613 return GMOCK_ACTION_CLASS_(name, value_params)<\
3614 GMOCK_INTERNAL_LIST_##template_params\
3615 GMOCK_INTERNAL_LIST_TYPE_##value_params>(\
3616 GMOCK_INTERNAL_LIST_##value_params);\
3617 }\
3618 template <GMOCK_INTERNAL_DECL_##template_params\
3619 GMOCK_INTERNAL_DECL_TYPE_##value_params>\
3620 template <typename F>\
3621 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3622 typename arg3_type, typename arg4_type, typename arg5_type, \
3623 typename arg6_type, typename arg7_type, typename arg8_type, \
3624 typename arg9_type>\
3625 typename ::testing::internal::Function<F>::Result\
3626 GMOCK_ACTION_CLASS_(name, value_params)<\
3627 GMOCK_INTERNAL_LIST_##template_params\
3628 GMOCK_INTERNAL_LIST_TYPE_##value_params>::gmock_Impl<F>::\
3629 gmock_PerformImpl(\
3630 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
3631
3632#define ACTION(name)\
3633 class name##Action {\
3634 public:\
3635 name##Action() {}\
3636 template <typename F>\
3637 class gmock_Impl : public ::testing::ActionInterface<F> {\
3638 public:\
3639 typedef F function_type;\
3640 typedef typename ::testing::internal::Function<F>::Result return_type;\
3641 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
3642 args_type;\
3643 gmock_Impl() {}\
3644 virtual return_type Perform(const args_type& args) {\
3645 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
3646 Perform(this, args);\
3647 }\
3648 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3649 typename arg3_type, typename arg4_type, typename arg5_type, \
3650 typename arg6_type, typename arg7_type, typename arg8_type, \
3651 typename arg9_type>\
3652 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
3653 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
3654 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
3655 arg9_type arg9) const;\
3656 private:\
3657 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
3658 };\
3659 template <typename F> operator ::testing::Action<F>() const {\
3660 return ::testing::Action<F>(new gmock_Impl<F>());\
3661 }\
3662 private:\
3663 GTEST_DISALLOW_ASSIGN_(name##Action);\
3664 };\
3665 inline name##Action name() {\
3666 return name##Action();\
3667 }\
3668 template <typename F>\
3669 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3670 typename arg3_type, typename arg4_type, typename arg5_type, \
3671 typename arg6_type, typename arg7_type, typename arg8_type, \
3672 typename arg9_type>\
3673 typename ::testing::internal::Function<F>::Result\
3674 name##Action::gmock_Impl<F>::gmock_PerformImpl(\
3675 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
3676
3677#define ACTION_P(name, p0)\
3678 template <typename p0##_type>\
3679 class name##ActionP {\
3680 public:\
3681 explicit name##ActionP(p0##_type gmock_p0) : p0(gmock_p0) {}\
3682 template <typename F>\
3683 class gmock_Impl : public ::testing::ActionInterface<F> {\
3684 public:\
3685 typedef F function_type;\
3686 typedef typename ::testing::internal::Function<F>::Result return_type;\
3687 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
3688 args_type;\
3689 explicit gmock_Impl(p0##_type gmock_p0) : p0(gmock_p0) {}\
3690 virtual return_type Perform(const args_type& args) {\
3691 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
3692 Perform(this, args);\
3693 }\
3694 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3695 typename arg3_type, typename arg4_type, typename arg5_type, \
3696 typename arg6_type, typename arg7_type, typename arg8_type, \
3697 typename arg9_type>\
3698 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
3699 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
3700 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
3701 arg9_type arg9) const;\
3702 p0##_type p0;\
3703 private:\
3704 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
3705 };\
3706 template <typename F> operator ::testing::Action<F>() const {\
3707 return ::testing::Action<F>(new gmock_Impl<F>(p0));\
3708 }\
3709 p0##_type p0;\
3710 private:\
3711 GTEST_DISALLOW_ASSIGN_(name##ActionP);\
3712 };\
3713 template <typename p0##_type>\
3714 inline name##ActionP<p0##_type> name(p0##_type p0) {\
3715 return name##ActionP<p0##_type>(p0);\
3716 }\
3717 template <typename p0##_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##ActionP<p0##_type>::gmock_Impl<F>::gmock_PerformImpl(\
3725 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
3726
3727#define ACTION_P2(name, p0, p1)\
3728 template <typename p0##_type, typename p1##_type>\
3729 class name##ActionP2 {\
3730 public:\
3731 name##ActionP2(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \
3732 p1(gmock_p1) {}\
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) : p0(gmock_p0), \
3741 p1(gmock_p1) {}\
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 private:\
3757 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
3758 };\
3759 template <typename F> operator ::testing::Action<F>() const {\
3760 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1));\
3761 }\
3762 p0##_type p0;\
3763 p1##_type p1;\
3764 private:\
3765 GTEST_DISALLOW_ASSIGN_(name##ActionP2);\
3766 };\
3767 template <typename p0##_type, typename p1##_type>\
3768 inline name##ActionP2<p0##_type, p1##_type> name(p0##_type p0, \
3769 p1##_type p1) {\
3770 return name##ActionP2<p0##_type, p1##_type>(p0, p1);\
3771 }\
3772 template <typename p0##_type, typename p1##_type>\
3773 template <typename F>\
3774 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3775 typename arg3_type, typename arg4_type, typename arg5_type, \
3776 typename arg6_type, typename arg7_type, typename arg8_type, \
3777 typename arg9_type>\
3778 typename ::testing::internal::Function<F>::Result\
3779 name##ActionP2<p0##_type, p1##_type>::gmock_Impl<F>::gmock_PerformImpl(\
3780 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
3781
3782#define ACTION_P3(name, p0, p1, p2)\
3783 template <typename p0##_type, typename p1##_type, typename p2##_type>\
3784 class name##ActionP3 {\
3785 public:\
3786 name##ActionP3(p0##_type gmock_p0, p1##_type gmock_p1, \
3787 p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\
3788 template <typename F>\
3789 class gmock_Impl : public ::testing::ActionInterface<F> {\
3790 public:\
3791 typedef F function_type;\
3792 typedef typename ::testing::internal::Function<F>::Result return_type;\
3793 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
3794 args_type;\
3795 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, \
3796 p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\
3797 virtual return_type Perform(const args_type& args) {\
3798 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
3799 Perform(this, args);\
3800 }\
3801 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3802 typename arg3_type, typename arg4_type, typename arg5_type, \
3803 typename arg6_type, typename arg7_type, typename arg8_type, \
3804 typename arg9_type>\
3805 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
3806 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
3807 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
3808 arg9_type arg9) const;\
3809 p0##_type p0;\
3810 p1##_type p1;\
3811 p2##_type p2;\
3812 private:\
3813 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
3814 };\
3815 template <typename F> operator ::testing::Action<F>() const {\
3816 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2));\
3817 }\
3818 p0##_type p0;\
3819 p1##_type p1;\
3820 p2##_type p2;\
3821 private:\
3822 GTEST_DISALLOW_ASSIGN_(name##ActionP3);\
3823 };\
3824 template <typename p0##_type, typename p1##_type, typename p2##_type>\
3825 inline name##ActionP3<p0##_type, p1##_type, p2##_type> name(p0##_type p0, \
3826 p1##_type p1, p2##_type p2) {\
3827 return name##ActionP3<p0##_type, p1##_type, p2##_type>(p0, p1, p2);\
3828 }\
3829 template <typename p0##_type, typename p1##_type, typename p2##_type>\
3830 template <typename F>\
3831 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3832 typename arg3_type, typename arg4_type, typename arg5_type, \
3833 typename arg6_type, typename arg7_type, typename arg8_type, \
3834 typename arg9_type>\
3835 typename ::testing::internal::Function<F>::Result\
3836 name##ActionP3<p0##_type, p1##_type, \
3837 p2##_type>::gmock_Impl<F>::gmock_PerformImpl(\
3838 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
3839
3840#define ACTION_P4(name, p0, p1, p2, p3)\
3841 template <typename p0##_type, typename p1##_type, typename p2##_type, \
3842 typename p3##_type>\
3843 class name##ActionP4 {\
3844 public:\
3845 name##ActionP4(p0##_type gmock_p0, p1##_type gmock_p1, \
3846 p2##_type gmock_p2, p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), \
3847 p2(gmock_p2), p3(gmock_p3) {}\
3848 template <typename F>\
3849 class gmock_Impl : public ::testing::ActionInterface<F> {\
3850 public:\
3851 typedef F function_type;\
3852 typedef typename ::testing::internal::Function<F>::Result return_type;\
3853 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
3854 args_type;\
3855 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3856 p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
3857 p3(gmock_p3) {}\
3858 virtual return_type Perform(const args_type& args) {\
3859 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
3860 Perform(this, args);\
3861 }\
3862 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3863 typename arg3_type, typename arg4_type, typename arg5_type, \
3864 typename arg6_type, typename arg7_type, typename arg8_type, \
3865 typename arg9_type>\
3866 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
3867 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
3868 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
3869 arg9_type arg9) const;\
3870 p0##_type p0;\
3871 p1##_type p1;\
3872 p2##_type p2;\
3873 p3##_type p3;\
3874 private:\
3875 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
3876 };\
3877 template <typename F> operator ::testing::Action<F>() const {\
3878 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3));\
3879 }\
3880 p0##_type p0;\
3881 p1##_type p1;\
3882 p2##_type p2;\
3883 p3##_type p3;\
3884 private:\
3885 GTEST_DISALLOW_ASSIGN_(name##ActionP4);\
3886 };\
3887 template <typename p0##_type, typename p1##_type, typename p2##_type, \
3888 typename p3##_type>\
3889 inline name##ActionP4<p0##_type, p1##_type, p2##_type, \
3890 p3##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
3891 p3##_type p3) {\
3892 return name##ActionP4<p0##_type, p1##_type, p2##_type, p3##_type>(p0, p1, \
3893 p2, p3);\
3894 }\
3895 template <typename p0##_type, typename p1##_type, typename p2##_type, \
3896 typename p3##_type>\
3897 template <typename F>\
3898 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3899 typename arg3_type, typename arg4_type, typename arg5_type, \
3900 typename arg6_type, typename arg7_type, typename arg8_type, \
3901 typename arg9_type>\
3902 typename ::testing::internal::Function<F>::Result\
3903 name##ActionP4<p0##_type, p1##_type, p2##_type, \
3904 p3##_type>::gmock_Impl<F>::gmock_PerformImpl(\
3905 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
3906
3907#define ACTION_P5(name, p0, p1, p2, p3, p4)\
3908 template <typename p0##_type, typename p1##_type, typename p2##_type, \
3909 typename p3##_type, typename p4##_type>\
3910 class name##ActionP5 {\
3911 public:\
3912 name##ActionP5(p0##_type gmock_p0, p1##_type gmock_p1, \
3913 p2##_type gmock_p2, p3##_type gmock_p3, \
3914 p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
3915 p3(gmock_p3), p4(gmock_p4) {}\
3916 template <typename F>\
3917 class gmock_Impl : public ::testing::ActionInterface<F> {\
3918 public:\
3919 typedef F function_type;\
3920 typedef typename ::testing::internal::Function<F>::Result return_type;\
3921 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
3922 args_type;\
3923 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3924 p3##_type gmock_p3, p4##_type gmock_p4) : p0(gmock_p0), \
3925 p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), p4(gmock_p4) {}\
3926 virtual return_type Perform(const args_type& args) {\
3927 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
3928 Perform(this, args);\
3929 }\
3930 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3931 typename arg3_type, typename arg4_type, typename arg5_type, \
3932 typename arg6_type, typename arg7_type, typename arg8_type, \
3933 typename arg9_type>\
3934 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
3935 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
3936 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
3937 arg9_type arg9) const;\
3938 p0##_type p0;\
3939 p1##_type p1;\
3940 p2##_type p2;\
3941 p3##_type p3;\
3942 p4##_type p4;\
3943 private:\
3944 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
3945 };\
3946 template <typename F> operator ::testing::Action<F>() const {\
3947 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4));\
3948 }\
3949 p0##_type p0;\
3950 p1##_type p1;\
3951 p2##_type p2;\
3952 p3##_type p3;\
3953 p4##_type p4;\
3954 private:\
3955 GTEST_DISALLOW_ASSIGN_(name##ActionP5);\
3956 };\
3957 template <typename p0##_type, typename p1##_type, typename p2##_type, \
3958 typename p3##_type, typename p4##_type>\
3959 inline name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \
3960 p4##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
3961 p4##_type p4) {\
3962 return name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \
3963 p4##_type>(p0, p1, p2, p3, p4);\
3964 }\
3965 template <typename p0##_type, typename p1##_type, typename p2##_type, \
3966 typename p3##_type, typename p4##_type>\
3967 template <typename F>\
3968 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3969 typename arg3_type, typename arg4_type, typename arg5_type, \
3970 typename arg6_type, typename arg7_type, typename arg8_type, \
3971 typename arg9_type>\
3972 typename ::testing::internal::Function<F>::Result\
3973 name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \
3974 p4##_type>::gmock_Impl<F>::gmock_PerformImpl(\
3975 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
3976
3977#define ACTION_P6(name, p0, p1, p2, p3, p4, p5)\
3978 template <typename p0##_type, typename p1##_type, typename p2##_type, \
3979 typename p3##_type, typename p4##_type, typename p5##_type>\
3980 class name##ActionP6 {\
3981 public:\
3982 name##ActionP6(p0##_type gmock_p0, p1##_type gmock_p1, \
3983 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
3984 p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
3985 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {}\
3986 template <typename F>\
3987 class gmock_Impl : public ::testing::ActionInterface<F> {\
3988 public:\
3989 typedef F function_type;\
3990 typedef typename ::testing::internal::Function<F>::Result return_type;\
3991 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
3992 args_type;\
3993 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3994 p3##_type gmock_p3, p4##_type gmock_p4, \
3995 p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
3996 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {}\
3997 virtual return_type Perform(const args_type& args) {\
3998 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
3999 Perform(this, args);\
4000 }\
4001 template <typename arg0_type, typename arg1_type, typename arg2_type, \
4002 typename arg3_type, typename arg4_type, typename arg5_type, \
4003 typename arg6_type, typename arg7_type, typename arg8_type, \
4004 typename arg9_type>\
4005 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
4006 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
4007 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
4008 arg9_type arg9) const;\
4009 p0##_type p0;\
4010 p1##_type p1;\
4011 p2##_type p2;\
4012 p3##_type p3;\
4013 p4##_type p4;\
4014 p5##_type p5;\
4015 private:\
4016 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
4017 };\
4018 template <typename F> operator ::testing::Action<F>() const {\
4019 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5));\
4020 }\
4021 p0##_type p0;\
4022 p1##_type p1;\
4023 p2##_type p2;\
4024 p3##_type p3;\
4025 p4##_type p4;\
4026 p5##_type p5;\
4027 private:\
4028 GTEST_DISALLOW_ASSIGN_(name##ActionP6);\
4029 };\
4030 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4031 typename p3##_type, typename p4##_type, typename p5##_type>\
4032 inline name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, \
4033 p4##_type, p5##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
4034 p3##_type p3, p4##_type p4, p5##_type p5) {\
4035 return name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, \
4036 p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5);\
4037 }\
4038 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4039 typename p3##_type, typename p4##_type, typename p5##_type>\
4040 template <typename F>\
4041 template <typename arg0_type, typename arg1_type, typename arg2_type, \
4042 typename arg3_type, typename arg4_type, typename arg5_type, \
4043 typename arg6_type, typename arg7_type, typename arg8_type, \
4044 typename arg9_type>\
4045 typename ::testing::internal::Function<F>::Result\
4046 name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
4047 p5##_type>::gmock_Impl<F>::gmock_PerformImpl(\
4048 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
4049
4050#define ACTION_P7(name, p0, p1, p2, p3, p4, p5, p6)\
4051 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4052 typename p3##_type, typename p4##_type, typename p5##_type, \
4053 typename p6##_type>\
4054 class name##ActionP7 {\
4055 public:\
4056 name##ActionP7(p0##_type gmock_p0, p1##_type gmock_p1, \
4057 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
4058 p5##_type gmock_p5, p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), \
4059 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), \
4060 p6(gmock_p6) {}\
4061 template <typename F>\
4062 class gmock_Impl : public ::testing::ActionInterface<F> {\
4063 public:\
4064 typedef F function_type;\
4065 typedef typename ::testing::internal::Function<F>::Result return_type;\
4066 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
4067 args_type;\
4068 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
4069 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
4070 p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
4071 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6) {}\
4072 virtual return_type Perform(const args_type& args) {\
4073 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
4074 Perform(this, args);\
4075 }\
4076 template <typename arg0_type, typename arg1_type, typename arg2_type, \
4077 typename arg3_type, typename arg4_type, typename arg5_type, \
4078 typename arg6_type, typename arg7_type, typename arg8_type, \
4079 typename arg9_type>\
4080 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
4081 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
4082 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
4083 arg9_type arg9) const;\
4084 p0##_type p0;\
4085 p1##_type p1;\
4086 p2##_type p2;\
4087 p3##_type p3;\
4088 p4##_type p4;\
4089 p5##_type p5;\
4090 p6##_type p6;\
4091 private:\
4092 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
4093 };\
4094 template <typename F> operator ::testing::Action<F>() const {\
4095 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
4096 p6));\
4097 }\
4098 p0##_type p0;\
4099 p1##_type p1;\
4100 p2##_type p2;\
4101 p3##_type p3;\
4102 p4##_type p4;\
4103 p5##_type p5;\
4104 p6##_type p6;\
4105 private:\
4106 GTEST_DISALLOW_ASSIGN_(name##ActionP7);\
4107 };\
4108 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4109 typename p3##_type, typename p4##_type, typename p5##_type, \
4110 typename p6##_type>\
4111 inline name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, \
4112 p4##_type, p5##_type, p6##_type> name(p0##_type p0, p1##_type p1, \
4113 p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
4114 p6##_type p6) {\
4115 return name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, \
4116 p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, p6);\
4117 }\
4118 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4119 typename p3##_type, typename p4##_type, typename p5##_type, \
4120 typename p6##_type>\
4121 template <typename F>\
4122 template <typename arg0_type, typename arg1_type, typename arg2_type, \
4123 typename arg3_type, typename arg4_type, typename arg5_type, \
4124 typename arg6_type, typename arg7_type, typename arg8_type, \
4125 typename arg9_type>\
4126 typename ::testing::internal::Function<F>::Result\
4127 name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
4128 p5##_type, p6##_type>::gmock_Impl<F>::gmock_PerformImpl(\
4129 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
4130
4131#define ACTION_P8(name, p0, p1, p2, p3, p4, p5, p6, p7)\
4132 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4133 typename p3##_type, typename p4##_type, typename p5##_type, \
4134 typename p6##_type, typename p7##_type>\
4135 class name##ActionP8 {\
4136 public:\
4137 name##ActionP8(p0##_type gmock_p0, p1##_type gmock_p1, \
4138 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
4139 p5##_type gmock_p5, p6##_type gmock_p6, \
4140 p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
4141 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
4142 p7(gmock_p7) {}\
4143 template <typename F>\
4144 class gmock_Impl : public ::testing::ActionInterface<F> {\
4145 public:\
4146 typedef F function_type;\
4147 typedef typename ::testing::internal::Function<F>::Result return_type;\
4148 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
4149 args_type;\
4150 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
4151 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
4152 p6##_type gmock_p6, p7##_type gmock_p7) : p0(gmock_p0), \
4153 p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), \
4154 p5(gmock_p5), p6(gmock_p6), p7(gmock_p7) {}\
4155 virtual return_type Perform(const args_type& args) {\
4156 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
4157 Perform(this, args);\
4158 }\
4159 template <typename arg0_type, typename arg1_type, typename arg2_type, \
4160 typename arg3_type, typename arg4_type, typename arg5_type, \
4161 typename arg6_type, typename arg7_type, typename arg8_type, \
4162 typename arg9_type>\
4163 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
4164 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
4165 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
4166 arg9_type arg9) const;\
4167 p0##_type p0;\
4168 p1##_type p1;\
4169 p2##_type p2;\
4170 p3##_type p3;\
4171 p4##_type p4;\
4172 p5##_type p5;\
4173 p6##_type p6;\
4174 p7##_type p7;\
4175 private:\
4176 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
4177 };\
4178 template <typename F> operator ::testing::Action<F>() const {\
4179 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
4180 p6, p7));\
4181 }\
4182 p0##_type p0;\
4183 p1##_type p1;\
4184 p2##_type p2;\
4185 p3##_type p3;\
4186 p4##_type p4;\
4187 p5##_type p5;\
4188 p6##_type p6;\
4189 p7##_type p7;\
4190 private:\
4191 GTEST_DISALLOW_ASSIGN_(name##ActionP8);\
4192 };\
4193 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4194 typename p3##_type, typename p4##_type, typename p5##_type, \
4195 typename p6##_type, typename p7##_type>\
4196 inline name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, \
4197 p4##_type, p5##_type, p6##_type, p7##_type> name(p0##_type p0, \
4198 p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
4199 p6##_type p6, p7##_type p7) {\
4200 return name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, \
4201 p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, p3, p4, p5, \
4202 p6, p7);\
4203 }\
4204 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4205 typename p3##_type, typename p4##_type, typename p5##_type, \
4206 typename p6##_type, typename p7##_type>\
4207 template <typename F>\
4208 template <typename arg0_type, typename arg1_type, typename arg2_type, \
4209 typename arg3_type, typename arg4_type, typename arg5_type, \
4210 typename arg6_type, typename arg7_type, typename arg8_type, \
4211 typename arg9_type>\
4212 typename ::testing::internal::Function<F>::Result\
4213 name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
4214 p5##_type, p6##_type, \
4215 p7##_type>::gmock_Impl<F>::gmock_PerformImpl(\
4216 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
4217
4218#define ACTION_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8)\
4219 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4220 typename p3##_type, typename p4##_type, typename p5##_type, \
4221 typename p6##_type, typename p7##_type, typename p8##_type>\
4222 class name##ActionP9 {\
4223 public:\
4224 name##ActionP9(p0##_type gmock_p0, p1##_type gmock_p1, \
4225 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
4226 p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
4227 p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
4228 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
4229 p8(gmock_p8) {}\
4230 template <typename F>\
4231 class gmock_Impl : public ::testing::ActionInterface<F> {\
4232 public:\
4233 typedef F function_type;\
4234 typedef typename ::testing::internal::Function<F>::Result return_type;\
4235 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
4236 args_type;\
4237 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
4238 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
4239 p6##_type gmock_p6, p7##_type gmock_p7, \
4240 p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
4241 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
4242 p7(gmock_p7), p8(gmock_p8) {}\
4243 virtual return_type Perform(const args_type& args) {\
4244 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
4245 Perform(this, args);\
4246 }\
4247 template <typename arg0_type, typename arg1_type, typename arg2_type, \
4248 typename arg3_type, typename arg4_type, typename arg5_type, \
4249 typename arg6_type, typename arg7_type, typename arg8_type, \
4250 typename arg9_type>\
4251 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
4252 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
4253 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
4254 arg9_type arg9) const;\
4255 p0##_type p0;\
4256 p1##_type p1;\
4257 p2##_type p2;\
4258 p3##_type p3;\
4259 p4##_type p4;\
4260 p5##_type p5;\
4261 p6##_type p6;\
4262 p7##_type p7;\
4263 p8##_type p8;\
4264 private:\
4265 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
4266 };\
4267 template <typename F> operator ::testing::Action<F>() const {\
4268 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
4269 p6, p7, p8));\
4270 }\
4271 p0##_type p0;\
4272 p1##_type p1;\
4273 p2##_type p2;\
4274 p3##_type p3;\
4275 p4##_type p4;\
4276 p5##_type p5;\
4277 p6##_type p6;\
4278 p7##_type p7;\
4279 p8##_type p8;\
4280 private:\
4281 GTEST_DISALLOW_ASSIGN_(name##ActionP9);\
4282 };\
4283 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4284 typename p3##_type, typename p4##_type, typename p5##_type, \
4285 typename p6##_type, typename p7##_type, typename p8##_type>\
4286 inline name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, \
4287 p4##_type, p5##_type, p6##_type, p7##_type, \
4288 p8##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
4289 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, \
4290 p8##_type p8) {\
4291 return name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, \
4292 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type>(p0, p1, p2, \
4293 p3, p4, p5, p6, p7, p8);\
4294 }\
4295 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4296 typename p3##_type, typename p4##_type, typename p5##_type, \
4297 typename p6##_type, typename p7##_type, typename p8##_type>\
4298 template <typename F>\
4299 template <typename arg0_type, typename arg1_type, typename arg2_type, \
4300 typename arg3_type, typename arg4_type, typename arg5_type, \
4301 typename arg6_type, typename arg7_type, typename arg8_type, \
4302 typename arg9_type>\
4303 typename ::testing::internal::Function<F>::Result\
4304 name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
4305 p5##_type, p6##_type, p7##_type, \
4306 p8##_type>::gmock_Impl<F>::gmock_PerformImpl(\
4307 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
4308
4309#define ACTION_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)\
4310 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4311 typename p3##_type, typename p4##_type, typename p5##_type, \
4312 typename p6##_type, typename p7##_type, typename p8##_type, \
4313 typename p9##_type>\
4314 class name##ActionP10 {\
4315 public:\
4316 name##ActionP10(p0##_type gmock_p0, p1##_type gmock_p1, \
4317 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
4318 p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
4319 p8##_type gmock_p8, p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), \
4320 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
4321 p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {}\
4322 template <typename F>\
4323 class gmock_Impl : public ::testing::ActionInterface<F> {\
4324 public:\
4325 typedef F function_type;\
4326 typedef typename ::testing::internal::Function<F>::Result return_type;\
4327 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
4328 args_type;\
4329 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
4330 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
4331 p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
4332 p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
4333 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
4334 p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {}\
4335 virtual return_type Perform(const args_type& args) {\
4336 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
4337 Perform(this, args);\
4338 }\
4339 template <typename arg0_type, typename arg1_type, typename arg2_type, \
4340 typename arg3_type, typename arg4_type, typename arg5_type, \
4341 typename arg6_type, typename arg7_type, typename arg8_type, \
4342 typename arg9_type>\
4343 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
4344 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
4345 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
4346 arg9_type arg9) const;\
4347 p0##_type p0;\
4348 p1##_type p1;\
4349 p2##_type p2;\
4350 p3##_type p3;\
4351 p4##_type p4;\
4352 p5##_type p5;\
4353 p6##_type p6;\
4354 p7##_type p7;\
4355 p8##_type p8;\
4356 p9##_type p9;\
4357 private:\
4358 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
4359 };\
4360 template <typename F> operator ::testing::Action<F>() const {\
4361 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
4362 p6, p7, p8, p9));\
4363 }\
4364 p0##_type p0;\
4365 p1##_type p1;\
4366 p2##_type p2;\
4367 p3##_type p3;\
4368 p4##_type p4;\
4369 p5##_type p5;\
4370 p6##_type p6;\
4371 p7##_type p7;\
4372 p8##_type p8;\
4373 p9##_type p9;\
4374 private:\
4375 GTEST_DISALLOW_ASSIGN_(name##ActionP10);\
4376 };\
4377 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4378 typename p3##_type, typename p4##_type, typename p5##_type, \
4379 typename p6##_type, typename p7##_type, typename p8##_type, \
4380 typename p9##_type>\
4381 inline name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, \
4382 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
4383 p9##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
4384 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \
4385 p9##_type p9) {\
4386 return name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, \
4387 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, p9##_type>(p0, \
4388 p1, p2, p3, p4, p5, p6, p7, p8, p9);\
4389 }\
4390 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4391 typename p3##_type, typename p4##_type, typename p5##_type, \
4392 typename p6##_type, typename p7##_type, typename p8##_type, \
4393 typename p9##_type>\
4394 template <typename F>\
4395 template <typename arg0_type, typename arg1_type, typename arg2_type, \
4396 typename arg3_type, typename arg4_type, typename arg5_type, \
4397 typename arg6_type, typename arg7_type, typename arg8_type, \
4398 typename arg9_type>\
4399 typename ::testing::internal::Function<F>::Result\
4400 name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
4401 p5##_type, p6##_type, p7##_type, p8##_type, \
4402 p9##_type>::gmock_Impl<F>::gmock_PerformImpl(\
4403 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
4404
4405namespace testing {
4406
4407
4408// The ACTION*() macros trigger warning C4100 (unreferenced formal
4409// parameter) in MSVC with -W4. Unfortunately they cannot be fixed in
4410// the macro definition, as the warnings are generated when the macro
4411// is expanded and macro expansion cannot contain #pragma. Therefore
4412// we suppress them here.
4413#ifdef _MSC_VER
4414# pragma warning(push)
4415# pragma warning(disable:4100)
4416#endif
4417
4418// Various overloads for InvokeArgument<N>().
4419//
4420// The InvokeArgument<N>(a1, a2, ..., a_k) action invokes the N-th
4421// (0-based) argument, which must be a k-ary callable, of the mock
4422// function, with arguments a1, a2, ..., a_k.
4423//
4424// Notes:
4425//
4426// 1. The arguments are passed by value by default. If you need to
4427// pass an argument by reference, wrap it inside ByRef(). For
4428// example,
4429//
4430// InvokeArgument<1>(5, string("Hello"), ByRef(foo))
4431//
4432// passes 5 and string("Hello") by value, and passes foo by
4433// reference.
4434//
4435// 2. If the callable takes an argument by reference but ByRef() is
4436// not used, it will receive the reference to a copy of the value,
4437// instead of the original value. For example, when the 0-th
4438// argument of the mock function takes a const string&, the action
4439//
4440// InvokeArgument<0>(string("Hello"))
4441//
4442// makes a copy of the temporary string("Hello") object and passes a
4443// reference of the copy, instead of the original temporary object,
4444// to the callable. This makes it easy for a user to define an
4445// InvokeArgument action from temporary values and have it performed
4446// later.
4447
4448namespace internal {
4449namespace invoke_argument {
4450
4451// Appears in InvokeArgumentAdl's argument list to help avoid
4452// accidental calls to user functions of the same name.
4453struct AdlTag {};
4454
4455// InvokeArgumentAdl - a helper for InvokeArgument.
4456// The basic overloads are provided here for generic functors.
4457// Overloads for other custom-callables are provided in the
4458// internal/custom/callback-actions.h header.
4459
4460template <typename R, typename F>
4461R InvokeArgumentAdl(AdlTag, F f) {
4462 return f();
4463}
4464template <typename R, typename F, typename A1>
4465R InvokeArgumentAdl(AdlTag, F f, A1 a1) {
4466 return f(a1);
4467}
4468template <typename R, typename F, typename A1, typename A2>
4469R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2) {
4470 return f(a1, a2);
4471}
4472template <typename R, typename F, typename A1, typename A2, typename A3>
4473R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3) {
4474 return f(a1, a2, a3);
4475}
4476template <typename R, typename F, typename A1, typename A2, typename A3,
4477 typename A4>
4478R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4) {
4479 return f(a1, a2, a3, a4);
4480}
4481template <typename R, typename F, typename A1, typename A2, typename A3,
4482 typename A4, typename A5>
4483R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) {
4484 return f(a1, a2, a3, a4, a5);
4485}
4486template <typename R, typename F, typename A1, typename A2, typename A3,
4487 typename A4, typename A5, typename A6>
4488R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) {
4489 return f(a1, a2, a3, a4, a5, a6);
4490}
4491template <typename R, typename F, typename A1, typename A2, typename A3,
4492 typename A4, typename A5, typename A6, typename A7>
4493R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
4494 A7 a7) {
4495 return f(a1, a2, a3, a4, a5, a6, a7);
4496}
4497template <typename R, typename F, typename A1, typename A2, typename A3,
4498 typename A4, typename A5, typename A6, typename A7, typename A8>
4499R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
4500 A7 a7, A8 a8) {
4501 return f(a1, a2, a3, a4, a5, a6, a7, a8);
4502}
4503template <typename R, typename F, typename A1, typename A2, typename A3,
4504 typename A4, typename A5, typename A6, typename A7, typename A8,
4505 typename A9>
4506R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
4507 A7 a7, A8 a8, A9 a9) {
4508 return f(a1, a2, a3, a4, a5, a6, a7, a8, a9);
4509}
4510template <typename R, typename F, typename A1, typename A2, typename A3,
4511 typename A4, typename A5, typename A6, typename A7, typename A8,
4512 typename A9, typename A10>
4513R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
4514 A7 a7, A8 a8, A9 a9, A10 a10) {
4515 return f(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
4516}
4517} // namespace invoke_argument
4518} // namespace internal
4519
4520ACTION_TEMPLATE(InvokeArgument,
4521 HAS_1_TEMPLATE_PARAMS(int, k),
4522 AND_0_VALUE_PARAMS()) {
4523 using internal::invoke_argument::InvokeArgumentAdl;
4524 return InvokeArgumentAdl<return_type>(
4525 internal::invoke_argument::AdlTag(),
4526 ::testing::get<k>(args));
4527}
4528
4529ACTION_TEMPLATE(InvokeArgument,
4530 HAS_1_TEMPLATE_PARAMS(int, k),
4531 AND_1_VALUE_PARAMS(p0)) {
4532 using internal::invoke_argument::InvokeArgumentAdl;
4533 return InvokeArgumentAdl<return_type>(
4534 internal::invoke_argument::AdlTag(),
4535 ::testing::get<k>(args), p0);
4536}
4537
4538ACTION_TEMPLATE(InvokeArgument,
4539 HAS_1_TEMPLATE_PARAMS(int, k),
4540 AND_2_VALUE_PARAMS(p0, p1)) {
4541 using internal::invoke_argument::InvokeArgumentAdl;
4542 return InvokeArgumentAdl<return_type>(
4543 internal::invoke_argument::AdlTag(),
4544 ::testing::get<k>(args), p0, p1);
4545}
4546
4547ACTION_TEMPLATE(InvokeArgument,
4548 HAS_1_TEMPLATE_PARAMS(int, k),
4549 AND_3_VALUE_PARAMS(p0, p1, p2)) {
4550 using internal::invoke_argument::InvokeArgumentAdl;
4551 return InvokeArgumentAdl<return_type>(
4552 internal::invoke_argument::AdlTag(),
4553 ::testing::get<k>(args), p0, p1, p2);
4554}
4555
4556ACTION_TEMPLATE(InvokeArgument,
4557 HAS_1_TEMPLATE_PARAMS(int, k),
4558 AND_4_VALUE_PARAMS(p0, p1, p2, p3)) {
4559 using internal::invoke_argument::InvokeArgumentAdl;
4560 return InvokeArgumentAdl<return_type>(
4561 internal::invoke_argument::AdlTag(),
4562 ::testing::get<k>(args), p0, p1, p2, p3);
4563}
4564
4565ACTION_TEMPLATE(InvokeArgument,
4566 HAS_1_TEMPLATE_PARAMS(int, k),
4567 AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)) {
4568 using internal::invoke_argument::InvokeArgumentAdl;
4569 return InvokeArgumentAdl<return_type>(
4570 internal::invoke_argument::AdlTag(),
4571 ::testing::get<k>(args), p0, p1, p2, p3, p4);
4572}
4573
4574ACTION_TEMPLATE(InvokeArgument,
4575 HAS_1_TEMPLATE_PARAMS(int, k),
4576 AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)) {
4577 using internal::invoke_argument::InvokeArgumentAdl;
4578 return InvokeArgumentAdl<return_type>(
4579 internal::invoke_argument::AdlTag(),
4580 ::testing::get<k>(args), p0, p1, p2, p3, p4, p5);
4581}
4582
4583ACTION_TEMPLATE(InvokeArgument,
4584 HAS_1_TEMPLATE_PARAMS(int, k),
4585 AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)) {
4586 using internal::invoke_argument::InvokeArgumentAdl;
4587 return InvokeArgumentAdl<return_type>(
4588 internal::invoke_argument::AdlTag(),
4589 ::testing::get<k>(args), p0, p1, p2, p3, p4, p5, p6);
4590}
4591
4592ACTION_TEMPLATE(InvokeArgument,
4593 HAS_1_TEMPLATE_PARAMS(int, k),
4594 AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)) {
4595 using internal::invoke_argument::InvokeArgumentAdl;
4596 return InvokeArgumentAdl<return_type>(
4597 internal::invoke_argument::AdlTag(),
4598 ::testing::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7);
4599}
4600
4601ACTION_TEMPLATE(InvokeArgument,
4602 HAS_1_TEMPLATE_PARAMS(int, k),
4603 AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8)) {
4604 using internal::invoke_argument::InvokeArgumentAdl;
4605 return InvokeArgumentAdl<return_type>(
4606 internal::invoke_argument::AdlTag(),
4607 ::testing::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7, p8);
4608}
4609
4610ACTION_TEMPLATE(InvokeArgument,
4611 HAS_1_TEMPLATE_PARAMS(int, k),
4612 AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)) {
4613 using internal::invoke_argument::InvokeArgumentAdl;
4614 return InvokeArgumentAdl<return_type>(
4615 internal::invoke_argument::AdlTag(),
4616 ::testing::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7, p8, p9);
4617}
4618
4619// Various overloads for ReturnNew<T>().
4620//
4621// The ReturnNew<T>(a1, a2, ..., a_k) action returns a pointer to a new
4622// instance of type T, constructed on the heap with constructor arguments
4623// a1, a2, ..., and a_k. The caller assumes ownership of the returned value.
4624ACTION_TEMPLATE(ReturnNew,
4625 HAS_1_TEMPLATE_PARAMS(typename, T),
4626 AND_0_VALUE_PARAMS()) {
4627 return new T();
4628}
4629
4630ACTION_TEMPLATE(ReturnNew,
4631 HAS_1_TEMPLATE_PARAMS(typename, T),
4632 AND_1_VALUE_PARAMS(p0)) {
4633 return new T(p0);
4634}
4635
4636ACTION_TEMPLATE(ReturnNew,
4637 HAS_1_TEMPLATE_PARAMS(typename, T),
4638 AND_2_VALUE_PARAMS(p0, p1)) {
4639 return new T(p0, p1);
4640}
4641
4642ACTION_TEMPLATE(ReturnNew,
4643 HAS_1_TEMPLATE_PARAMS(typename, T),
4644 AND_3_VALUE_PARAMS(p0, p1, p2)) {
4645 return new T(p0, p1, p2);
4646}
4647
4648ACTION_TEMPLATE(ReturnNew,
4649 HAS_1_TEMPLATE_PARAMS(typename, T),
4650 AND_4_VALUE_PARAMS(p0, p1, p2, p3)) {
4651 return new T(p0, p1, p2, p3);
4652}
4653
4654ACTION_TEMPLATE(ReturnNew,
4655 HAS_1_TEMPLATE_PARAMS(typename, T),
4656 AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)) {
4657 return new T(p0, p1, p2, p3, p4);
4658}
4659
4660ACTION_TEMPLATE(ReturnNew,
4661 HAS_1_TEMPLATE_PARAMS(typename, T),
4662 AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)) {
4663 return new T(p0, p1, p2, p3, p4, p5);
4664}
4665
4666ACTION_TEMPLATE(ReturnNew,
4667 HAS_1_TEMPLATE_PARAMS(typename, T),
4668 AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)) {
4669 return new T(p0, p1, p2, p3, p4, p5, p6);
4670}
4671
4672ACTION_TEMPLATE(ReturnNew,
4673 HAS_1_TEMPLATE_PARAMS(typename, T),
4674 AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)) {
4675 return new T(p0, p1, p2, p3, p4, p5, p6, p7);
4676}
4677
4678ACTION_TEMPLATE(ReturnNew,
4679 HAS_1_TEMPLATE_PARAMS(typename, T),
4680 AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8)) {
4681 return new T(p0, p1, p2, p3, p4, p5, p6, p7, p8);
4682}
4683
4684ACTION_TEMPLATE(ReturnNew,
4685 HAS_1_TEMPLATE_PARAMS(typename, T),
4686 AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)) {
4687 return new T(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9);
4688}
4689
4690#ifdef _MSC_VER
4691# pragma warning(pop)
4692#endif
4693
4694} // namespace testing
4695
4696// Include any custom actions added by the local installation.
4697// We must include this header at the end to make sure it can use the
4698// declarations from this file.
4699// This file was GENERATED by command:
4700// pump.py gmock-generated-actions.h.pump
4701// DO NOT EDIT BY HAND!!!
4702
4703#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
4704#define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
4705
4706#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
4707
4708#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
4709// This file was GENERATED by command:
4710// pump.py gmock-generated-function-mockers.h.pump
4711// DO NOT EDIT BY HAND!!!
4712
4713// Copyright 2007, Google Inc.
4714// All rights reserved.
4715//
4716// Redistribution and use in source and binary forms, with or without
4717// modification, are permitted provided that the following conditions are
4718// met:
4719//
4720// * Redistributions of source code must retain the above copyright
4721// notice, this list of conditions and the following disclaimer.
4722// * Redistributions in binary form must reproduce the above
4723// copyright notice, this list of conditions and the following disclaimer
4724// in the documentation and/or other materials provided with the
4725// distribution.
4726// * Neither the name of Google Inc. nor the names of its
4727// contributors may be used to endorse or promote products derived from
4728// this software without specific prior written permission.
4729//
4730// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4731// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
4732// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
4733// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
4734// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
4735// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
4736// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
4737// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
4738// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
4739// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
4740// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4741//
4742// Author: wan@google.com (Zhanyong Wan)
4743
4744// Google Mock - a framework for writing C++ mock classes.
4745//
4746// This file implements function mockers of various arities.
4747
4748#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
4749#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
4750
4751// Copyright 2007, Google Inc.
4752// All rights reserved.
4753//
4754// Redistribution and use in source and binary forms, with or without
4755// modification, are permitted provided that the following conditions are
4756// met:
4757//
4758// * Redistributions of source code must retain the above copyright
4759// notice, this list of conditions and the following disclaimer.
4760// * Redistributions in binary form must reproduce the above
4761// copyright notice, this list of conditions and the following disclaimer
4762// in the documentation and/or other materials provided with the
4763// distribution.
4764// * Neither the name of Google Inc. nor the names of its
4765// contributors may be used to endorse or promote products derived from
4766// this software without specific prior written permission.
4767//
4768// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4769// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
4770// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
4771// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
4772// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
4773// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
4774// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
4775// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
4776// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
4777// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
4778// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4779//
4780// Author: wan@google.com (Zhanyong Wan)
4781
4782// Google Mock - a framework for writing C++ mock classes.
4783//
4784// This file implements the ON_CALL() and EXPECT_CALL() macros.
4785//
4786// A user can use the ON_CALL() macro to specify the default action of
4787// a mock method. The syntax is:
4788//
4789// ON_CALL(mock_object, Method(argument-matchers))
4790// .With(multi-argument-matcher)
4791// .WillByDefault(action);
4792//
4793// where the .With() clause is optional.
4794//
4795// A user can use the EXPECT_CALL() macro to specify an expectation on
4796// a mock method. The syntax is:
4797//
4798// EXPECT_CALL(mock_object, Method(argument-matchers))
4799// .With(multi-argument-matchers)
4800// .Times(cardinality)
4801// .InSequence(sequences)
4802// .After(expectations)
4803// .WillOnce(action)
4804// .WillRepeatedly(action)
4805// .RetiresOnSaturation();
4806//
4807// where all clauses are optional, and .InSequence()/.After()/
4808// .WillOnce() can appear any number of times.
4809
4810#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_
4811#define GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_
4812
4813#include <map>
4814#include <set>
4815#include <sstream>
4816#include <string>
4817#include <vector>
4818
4819#if GTEST_HAS_EXCEPTIONS
4820# include <stdexcept> // NOLINT
4821#endif
4822
4823// Copyright 2007, Google Inc.
4824// All rights reserved.
4825//
4826// Redistribution and use in source and binary forms, with or without
4827// modification, are permitted provided that the following conditions are
4828// met:
4829//
4830// * Redistributions of source code must retain the above copyright
4831// notice, this list of conditions and the following disclaimer.
4832// * Redistributions in binary form must reproduce the above
4833// copyright notice, this list of conditions and the following disclaimer
4834// in the documentation and/or other materials provided with the
4835// distribution.
4836// * Neither the name of Google Inc. nor the names of its
4837// contributors may be used to endorse or promote products derived from
4838// this software without specific prior written permission.
4839//
4840// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4841// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
4842// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
4843// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
4844// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
4845// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
4846// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
4847// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
4848// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
4849// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
4850// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4851//
4852// Author: wan@google.com (Zhanyong Wan)
4853
4854// Google Mock - a framework for writing C++ mock classes.
4855//
4856// This file implements some commonly used argument matchers. More
4857// matchers can be defined by the user implementing the
4858// MatcherInterface<T> interface if necessary.
4859
4860#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
4861#define GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
4862
4863#include <math.h>
4864#include <algorithm>
4865#include <iterator>
4866#include <limits>
4867#include <ostream> // NOLINT
4868#include <sstream>
4869#include <string>
4870#include <utility>
4871#include <vector>
4872
4873
4874#if GTEST_HAS_STD_INITIALIZER_LIST_
4875# include <initializer_list> // NOLINT -- must be after gtest.h
4876#endif
4877
4878namespace testing {
4879
4880// To implement a matcher Foo for type T, define:
4881// 1. a class FooMatcherImpl that implements the
4882// MatcherInterface<T> interface, and
4883// 2. a factory function that creates a Matcher<T> object from a
4884// FooMatcherImpl*.
4885//
4886// The two-level delegation design makes it possible to allow a user
4887// to write "v" instead of "Eq(v)" where a Matcher is expected, which
4888// is impossible if we pass matchers by pointers. It also eases
4889// ownership management as Matcher objects can now be copied like
4890// plain values.
4891
4892// MatchResultListener is an abstract class. Its << operator can be
4893// used by a matcher to explain why a value matches or doesn't match.
4894//
4895// TODO(wan@google.com): add method
4896// bool InterestedInWhy(bool result) const;
4897// to indicate whether the listener is interested in why the match
4898// result is 'result'.
4899class MatchResultListener {
4900 public:
4901 // Creates a listener object with the given underlying ostream. The
4902 // listener does not own the ostream, and does not dereference it
4903 // in the constructor or destructor.
4904 explicit MatchResultListener(::std::ostream* os) : stream_(os) {}
4905 virtual ~MatchResultListener() = 0; // Makes this class abstract.
4906
4907 // Streams x to the underlying ostream; does nothing if the ostream
4908 // is NULL.
4909 template <typename T>
4910 MatchResultListener& operator<<(const T& x) {
4911 if (stream_ != NULL)
4912 *stream_ << x;
4913 return *this;
4914 }
4915
4916 // Returns the underlying ostream.
4917 ::std::ostream* stream() { return stream_; }
4918
4919 // Returns true iff the listener is interested in an explanation of
4920 // the match result. A matcher's MatchAndExplain() method can use
4921 // this information to avoid generating the explanation when no one
4922 // intends to hear it.
4923 bool IsInterested() const { return stream_ != NULL; }
4924
4925 private:
4926 ::std::ostream* const stream_;
4927
4928 GTEST_DISALLOW_COPY_AND_ASSIGN_(MatchResultListener);
4929};
4930
4931inline MatchResultListener::~MatchResultListener() {
4932}
4933
4934// An instance of a subclass of this knows how to describe itself as a
4935// matcher.
4936class MatcherDescriberInterface {
4937 public:
4938 virtual ~MatcherDescriberInterface() {}
4939
4940 // Describes this matcher to an ostream. The function should print
4941 // a verb phrase that describes the property a value matching this
4942 // matcher should have. The subject of the verb phrase is the value
4943 // being matched. For example, the DescribeTo() method of the Gt(7)
4944 // matcher prints "is greater than 7".
4945 virtual void DescribeTo(::std::ostream* os) const = 0;
4946
4947 // Describes the negation of this matcher to an ostream. For
4948 // example, if the description of this matcher is "is greater than
4949 // 7", the negated description could be "is not greater than 7".
4950 // You are not required to override this when implementing
4951 // MatcherInterface, but it is highly advised so that your matcher
4952 // can produce good error messages.
4953 virtual void DescribeNegationTo(::std::ostream* os) const {
4954 *os << "not (";
4955 DescribeTo(os);
4956 *os << ")";
4957 }
4958};
4959
4960// The implementation of a matcher.
4961template <typename T>
4962class MatcherInterface : public MatcherDescriberInterface {
4963 public:
4964 // Returns true iff the matcher matches x; also explains the match
4965 // result to 'listener' if necessary (see the next paragraph), in
4966 // the form of a non-restrictive relative clause ("which ...",
4967 // "whose ...", etc) that describes x. For example, the
4968 // MatchAndExplain() method of the Pointee(...) matcher should
4969 // generate an explanation like "which points to ...".
4970 //
4971 // Implementations of MatchAndExplain() should add an explanation of
4972 // the match result *if and only if* they can provide additional
4973 // information that's not already present (or not obvious) in the
4974 // print-out of x and the matcher's description. Whether the match
4975 // succeeds is not a factor in deciding whether an explanation is
4976 // needed, as sometimes the caller needs to print a failure message
4977 // when the match succeeds (e.g. when the matcher is used inside
4978 // Not()).
4979 //
4980 // For example, a "has at least 10 elements" matcher should explain
4981 // what the actual element count is, regardless of the match result,
4982 // as it is useful information to the reader; on the other hand, an
4983 // "is empty" matcher probably only needs to explain what the actual
4984 // size is when the match fails, as it's redundant to say that the
4985 // size is 0 when the value is already known to be empty.
4986 //
4987 // You should override this method when defining a new matcher.
4988 //
4989 // It's the responsibility of the caller (Google Mock) to guarantee
4990 // that 'listener' is not NULL. This helps to simplify a matcher's
4991 // implementation when it doesn't care about the performance, as it
4992 // can talk to 'listener' without checking its validity first.
4993 // However, in order to implement dummy listeners efficiently,
4994 // listener->stream() may be NULL.
4995 virtual bool MatchAndExplain(T x, MatchResultListener* listener) const = 0;
4996
4997 // Inherits these methods from MatcherDescriberInterface:
4998 // virtual void DescribeTo(::std::ostream* os) const = 0;
4999 // virtual void DescribeNegationTo(::std::ostream* os) const;
5000};
5001
5002// A match result listener that stores the explanation in a string.
5003class StringMatchResultListener : public MatchResultListener {
5004 public:
5005 StringMatchResultListener() : MatchResultListener(&ss_) {}
5006
5007 // Returns the explanation accumulated so far.
5008 internal::string str() const { return ss_.str(); }
5009
5010 // Clears the explanation accumulated so far.
5011 void Clear() { ss_.str(""); }
5012
5013 private:
5014 ::std::stringstream ss_;
5015
5016 GTEST_DISALLOW_COPY_AND_ASSIGN_(StringMatchResultListener);
5017};
5018
5019namespace internal {
5020
5021struct AnyEq {
5022 template <typename A, typename B>
5023 bool operator()(const A& a, const B& b) const { return a == b; }
5024};
5025struct AnyNe {
5026 template <typename A, typename B>
5027 bool operator()(const A& a, const B& b) const { return a != b; }
5028};
5029struct AnyLt {
5030 template <typename A, typename B>
5031 bool operator()(const A& a, const B& b) const { return a < b; }
5032};
5033struct AnyGt {
5034 template <typename A, typename B>
5035 bool operator()(const A& a, const B& b) const { return a > b; }
5036};
5037struct AnyLe {
5038 template <typename A, typename B>
5039 bool operator()(const A& a, const B& b) const { return a <= b; }
5040};
5041struct AnyGe {
5042 template <typename A, typename B>
5043 bool operator()(const A& a, const B& b) const { return a >= b; }
5044};
5045
5046// A match result listener that ignores the explanation.
5047class DummyMatchResultListener : public MatchResultListener {
5048 public:
5049 DummyMatchResultListener() : MatchResultListener(NULL) {}
5050
5051 private:
5052 GTEST_DISALLOW_COPY_AND_ASSIGN_(DummyMatchResultListener);
5053};
5054
5055// A match result listener that forwards the explanation to a given
5056// ostream. The difference between this and MatchResultListener is
5057// that the former is concrete.
5058class StreamMatchResultListener : public MatchResultListener {
5059 public:
5060 explicit StreamMatchResultListener(::std::ostream* os)
5061 : MatchResultListener(os) {}
5062
5063 private:
5064 GTEST_DISALLOW_COPY_AND_ASSIGN_(StreamMatchResultListener);
5065};
5066
5067// An internal class for implementing Matcher<T>, which will derive
5068// from it. We put functionalities common to all Matcher<T>
5069// specializations here to avoid code duplication.
5070template <typename T>
5071class MatcherBase {
5072 public:
5073 // Returns true iff the matcher matches x; also explains the match
5074 // result to 'listener'.
5075 bool MatchAndExplain(T x, MatchResultListener* listener) const {
5076 return impl_->MatchAndExplain(x, listener);
5077 }
5078
5079 // Returns true iff this matcher matches x.
5080 bool Matches(T x) const {
5081 DummyMatchResultListener dummy;
5082 return MatchAndExplain(x, &dummy);
5083 }
5084
5085 // Describes this matcher to an ostream.
5086 void DescribeTo(::std::ostream* os) const { impl_->DescribeTo(os); }
5087
5088 // Describes the negation of this matcher to an ostream.
5089 void DescribeNegationTo(::std::ostream* os) const {
5090 impl_->DescribeNegationTo(os);
5091 }
5092
5093 // Explains why x matches, or doesn't match, the matcher.
5094 void ExplainMatchResultTo(T x, ::std::ostream* os) const {
5095 StreamMatchResultListener listener(os);
5096 MatchAndExplain(x, &listener);
5097 }
5098
5099 // Returns the describer for this matcher object; retains ownership
5100 // of the describer, which is only guaranteed to be alive when
5101 // this matcher object is alive.
5102 const MatcherDescriberInterface* GetDescriber() const {
5103 return impl_.get();
5104 }
5105
5106 protected:
5107 MatcherBase() {}
5108
5109 // Constructs a matcher from its implementation.
5110 explicit MatcherBase(const MatcherInterface<T>* impl)
5111 : impl_(impl) {}
5112
5113 virtual ~MatcherBase() {}
5114
5115 private:
5116 // shared_ptr (util/gtl/shared_ptr.h) and linked_ptr have similar
5117 // interfaces. The former dynamically allocates a chunk of memory
5118 // to hold the reference count, while the latter tracks all
5119 // references using a circular linked list without allocating
5120 // memory. It has been observed that linked_ptr performs better in
5121 // typical scenarios. However, shared_ptr can out-perform
5122 // linked_ptr when there are many more uses of the copy constructor
5123 // than the default constructor.
5124 //
5125 // If performance becomes a problem, we should see if using
5126 // shared_ptr helps.
5127 ::testing::internal::linked_ptr<const MatcherInterface<T> > impl_;
5128};
5129
5130} // namespace internal
5131
5132// A Matcher<T> is a copyable and IMMUTABLE (except by assignment)
5133// object that can check whether a value of type T matches. The
5134// implementation of Matcher<T> is just a linked_ptr to const
5135// MatcherInterface<T>, so copying is fairly cheap. Don't inherit
5136// from Matcher!
5137template <typename T>
5138class Matcher : public internal::MatcherBase<T> {
5139 public:
5140 // Constructs a null matcher. Needed for storing Matcher objects in STL
5141 // containers. A default-constructed matcher is not yet initialized. You
5142 // cannot use it until a valid value has been assigned to it.
5143 explicit Matcher() {} // NOLINT
5144
5145 // Constructs a matcher from its implementation.
5146 explicit Matcher(const MatcherInterface<T>* impl)
5147 : internal::MatcherBase<T>(impl) {}
5148
5149 // Implicit constructor here allows people to write
5150 // EXPECT_CALL(foo, Bar(5)) instead of EXPECT_CALL(foo, Bar(Eq(5))) sometimes
5151 Matcher(T value); // NOLINT
5152};
5153
5154// The following two specializations allow the user to write str
5155// instead of Eq(str) and "foo" instead of Eq("foo") when a string
5156// matcher is expected.
5157template <>
5158class GTEST_API_ Matcher<const internal::string&>
5159 : public internal::MatcherBase<const internal::string&> {
5160 public:
5161 Matcher() {}
5162
5163 explicit Matcher(const MatcherInterface<const internal::string&>* impl)
5164 : internal::MatcherBase<const internal::string&>(impl) {}
5165
5166 // Allows the user to write str instead of Eq(str) sometimes, where
5167 // str is a string object.
5168 Matcher(const internal::string& s); // NOLINT
5169
5170 // Allows the user to write "foo" instead of Eq("foo") sometimes.
5171 Matcher(const char* s); // NOLINT
5172};
5173
5174template <>
5175class GTEST_API_ Matcher<internal::string>
5176 : public internal::MatcherBase<internal::string> {
5177 public:
5178 Matcher() {}
5179
5180 explicit Matcher(const MatcherInterface<internal::string>* impl)
5181 : internal::MatcherBase<internal::string>(impl) {}
5182
5183 // Allows the user to write str instead of Eq(str) sometimes, where
5184 // str is a string object.
5185 Matcher(const internal::string& s); // NOLINT
5186
5187 // Allows the user to write "foo" instead of Eq("foo") sometimes.
5188 Matcher(const char* s); // NOLINT
5189};
5190
5191#if GTEST_HAS_STRING_PIECE_
5192// The following two specializations allow the user to write str
5193// instead of Eq(str) and "foo" instead of Eq("foo") when a StringPiece
5194// matcher is expected.
5195template <>
5196class GTEST_API_ Matcher<const StringPiece&>
5197 : public internal::MatcherBase<const StringPiece&> {
5198 public:
5199 Matcher() {}
5200
5201 explicit Matcher(const MatcherInterface<const StringPiece&>* impl)
5202 : internal::MatcherBase<const StringPiece&>(impl) {}
5203
5204 // Allows the user to write str instead of Eq(str) sometimes, where
5205 // str is a string object.
5206 Matcher(const internal::string& s); // NOLINT
5207
5208 // Allows the user to write "foo" instead of Eq("foo") sometimes.
5209 Matcher(const char* s); // NOLINT
5210
5211 // Allows the user to pass StringPieces directly.
5212 Matcher(StringPiece s); // NOLINT
5213};
5214
5215template <>
5216class GTEST_API_ Matcher<StringPiece>
5217 : public internal::MatcherBase<StringPiece> {
5218 public:
5219 Matcher() {}
5220
5221 explicit Matcher(const MatcherInterface<StringPiece>* impl)
5222 : internal::MatcherBase<StringPiece>(impl) {}
5223
5224 // Allows the user to write str instead of Eq(str) sometimes, where
5225 // str is a string object.
5226 Matcher(const internal::string& s); // NOLINT
5227
5228 // Allows the user to write "foo" instead of Eq("foo") sometimes.
5229 Matcher(const char* s); // NOLINT
5230
5231 // Allows the user to pass StringPieces directly.
5232 Matcher(StringPiece s); // NOLINT
5233};
5234#endif // GTEST_HAS_STRING_PIECE_
5235
5236// The PolymorphicMatcher class template makes it easy to implement a
5237// polymorphic matcher (i.e. a matcher that can match values of more
5238// than one type, e.g. Eq(n) and NotNull()).
5239//
5240// To define a polymorphic matcher, a user should provide an Impl
5241// class that has a DescribeTo() method and a DescribeNegationTo()
5242// method, and define a member function (or member function template)
5243//
5244// bool MatchAndExplain(const Value& value,
5245// MatchResultListener* listener) const;
5246//
5247// See the definition of NotNull() for a complete example.
5248template <class Impl>
5249class PolymorphicMatcher {
5250 public:
5251 explicit PolymorphicMatcher(const Impl& an_impl) : impl_(an_impl) {}
5252
5253 // Returns a mutable reference to the underlying matcher
5254 // implementation object.
5255 Impl& mutable_impl() { return impl_; }
5256
5257 // Returns an immutable reference to the underlying matcher
5258 // implementation object.
5259 const Impl& impl() const { return impl_; }
5260
5261 template <typename T>
5262 operator Matcher<T>() const {
5263 return Matcher<T>(new MonomorphicImpl<T>(impl_));
5264 }
5265
5266 private:
5267 template <typename T>
5268 class MonomorphicImpl : public MatcherInterface<T> {
5269 public:
5270 explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {}
5271
5272 virtual void DescribeTo(::std::ostream* os) const {
5273 impl_.DescribeTo(os);
5274 }
5275
5276 virtual void DescribeNegationTo(::std::ostream* os) const {
5277 impl_.DescribeNegationTo(os);
5278 }
5279
5280 virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
5281 return impl_.MatchAndExplain(x, listener);
5282 }
5283
5284 private:
5285 const Impl impl_;
5286
5287 GTEST_DISALLOW_ASSIGN_(MonomorphicImpl);
5288 };
5289
5290 Impl impl_;
5291
5292 GTEST_DISALLOW_ASSIGN_(PolymorphicMatcher);
5293};
5294
5295// Creates a matcher from its implementation. This is easier to use
5296// than the Matcher<T> constructor as it doesn't require you to
5297// explicitly write the template argument, e.g.
5298//
5299// MakeMatcher(foo);
5300// vs
5301// Matcher<const string&>(foo);
5302template <typename T>
5303inline Matcher<T> MakeMatcher(const MatcherInterface<T>* impl) {
5304 return Matcher<T>(impl);
5305}
5306
5307// Creates a polymorphic matcher from its implementation. This is
5308// easier to use than the PolymorphicMatcher<Impl> constructor as it
5309// doesn't require you to explicitly write the template argument, e.g.
5310//
5311// MakePolymorphicMatcher(foo);
5312// vs
5313// PolymorphicMatcher<TypeOfFoo>(foo);
5314template <class Impl>
5315inline PolymorphicMatcher<Impl> MakePolymorphicMatcher(const Impl& impl) {
5316 return PolymorphicMatcher<Impl>(impl);
5317}
5318
5319// Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION
5320// and MUST NOT BE USED IN USER CODE!!!
5321namespace internal {
5322
5323// The MatcherCastImpl class template is a helper for implementing
5324// MatcherCast(). We need this helper in order to partially
5325// specialize the implementation of MatcherCast() (C++ allows
5326// class/struct templates to be partially specialized, but not
5327// function templates.).
5328
5329// This general version is used when MatcherCast()'s argument is a
5330// polymorphic matcher (i.e. something that can be converted to a
5331// Matcher but is not one yet; for example, Eq(value)) or a value (for
5332// example, "hello").
5333template <typename T, typename M>
5334class MatcherCastImpl {
5335 public:
5336 static Matcher<T> Cast(const M& polymorphic_matcher_or_value) {
5337 // M can be a polymorhic matcher, in which case we want to use
5338 // its conversion operator to create Matcher<T>. Or it can be a value
5339 // that should be passed to the Matcher<T>'s constructor.
5340 //
5341 // We can't call Matcher<T>(polymorphic_matcher_or_value) when M is a
5342 // polymorphic matcher because it'll be ambiguous if T has an implicit
5343 // constructor from M (this usually happens when T has an implicit
5344 // constructor from any type).
5345 //
5346 // It won't work to unconditionally implict_cast
5347 // polymorphic_matcher_or_value to Matcher<T> because it won't trigger
5348 // a user-defined conversion from M to T if one exists (assuming M is
5349 // a value).
5350 return CastImpl(
5351 polymorphic_matcher_or_value,
5352 BooleanConstant<
5353 internal::ImplicitlyConvertible<M, Matcher<T> >::value>());
5354 }
5355
5356 private:
5357 static Matcher<T> CastImpl(const M& value, BooleanConstant<false>) {
5358 // M can't be implicitly converted to Matcher<T>, so M isn't a polymorphic
5359 // matcher. It must be a value then. Use direct initialization to create
5360 // a matcher.
5361 return Matcher<T>(ImplicitCast_<T>(value));
5362 }
5363
5364 static Matcher<T> CastImpl(const M& polymorphic_matcher_or_value,
5365 BooleanConstant<true>) {
5366 // M is implicitly convertible to Matcher<T>, which means that either
5367 // M is a polymorhpic matcher or Matcher<T> has an implicit constructor
5368 // from M. In both cases using the implicit conversion will produce a
5369 // matcher.
5370 //
5371 // Even if T has an implicit constructor from M, it won't be called because
5372 // creating Matcher<T> would require a chain of two user-defined conversions
5373 // (first to create T from M and then to create Matcher<T> from T).
5374 return polymorphic_matcher_or_value;
5375 }
5376};
5377
5378// This more specialized version is used when MatcherCast()'s argument
5379// is already a Matcher. This only compiles when type T can be
5380// statically converted to type U.
5381template <typename T, typename U>
5382class MatcherCastImpl<T, Matcher<U> > {
5383 public:
5384 static Matcher<T> Cast(const Matcher<U>& source_matcher) {
5385 return Matcher<T>(new Impl(source_matcher));
5386 }
5387
5388 private:
5389 class Impl : public MatcherInterface<T> {
5390 public:
5391 explicit Impl(const Matcher<U>& source_matcher)
5392 : source_matcher_(source_matcher) {}
5393
5394 // We delegate the matching logic to the source matcher.
5395 virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
5396 return source_matcher_.MatchAndExplain(static_cast<U>(x), listener);
5397 }
5398
5399 virtual void DescribeTo(::std::ostream* os) const {
5400 source_matcher_.DescribeTo(os);
5401 }
5402
5403 virtual void DescribeNegationTo(::std::ostream* os) const {
5404 source_matcher_.DescribeNegationTo(os);
5405 }
5406
5407 private:
5408 const Matcher<U> source_matcher_;
5409
5410 GTEST_DISALLOW_ASSIGN_(Impl);
5411 };
5412};
5413
5414// This even more specialized version is used for efficiently casting
5415// a matcher to its own type.
5416template <typename T>
5417class MatcherCastImpl<T, Matcher<T> > {
5418 public:
5419 static Matcher<T> Cast(const Matcher<T>& matcher) { return matcher; }
5420};
5421
5422} // namespace internal
5423
5424// In order to be safe and clear, casting between different matcher
5425// types is done explicitly via MatcherCast<T>(m), which takes a
5426// matcher m and returns a Matcher<T>. It compiles only when T can be
5427// statically converted to the argument type of m.
5428template <typename T, typename M>
5429inline Matcher<T> MatcherCast(const M& matcher) {
5430 return internal::MatcherCastImpl<T, M>::Cast(matcher);
5431}
5432
5433// Implements SafeMatcherCast().
5434//
5435// We use an intermediate class to do the actual safe casting as Nokia's
5436// Symbian compiler cannot decide between
5437// template <T, M> ... (M) and
5438// template <T, U> ... (const Matcher<U>&)
5439// for function templates but can for member function templates.
5440template <typename T>
5441class SafeMatcherCastImpl {
5442 public:
5443 // This overload handles polymorphic matchers and values only since
5444 // monomorphic matchers are handled by the next one.
5445 template <typename M>
5446 static inline Matcher<T> Cast(const M& polymorphic_matcher_or_value) {
5447 return internal::MatcherCastImpl<T, M>::Cast(polymorphic_matcher_or_value);
5448 }
5449
5450 // This overload handles monomorphic matchers.
5451 //
5452 // In general, if type T can be implicitly converted to type U, we can
5453 // safely convert a Matcher<U> to a Matcher<T> (i.e. Matcher is
5454 // contravariant): just keep a copy of the original Matcher<U>, convert the
5455 // argument from type T to U, and then pass it to the underlying Matcher<U>.
5456 // The only exception is when U is a reference and T is not, as the
5457 // underlying Matcher<U> may be interested in the argument's address, which
5458 // is not preserved in the conversion from T to U.
5459 template <typename U>
5460 static inline Matcher<T> Cast(const Matcher<U>& matcher) {
5461 // Enforce that T can be implicitly converted to U.
5462 GTEST_COMPILE_ASSERT_((internal::ImplicitlyConvertible<T, U>::value),
5463 T_must_be_implicitly_convertible_to_U);
5464 // Enforce that we are not converting a non-reference type T to a reference
5465 // type U.
5466 GTEST_COMPILE_ASSERT_(
5467 internal::is_reference<T>::value || !internal::is_reference<U>::value,
5468 cannot_convert_non_referentce_arg_to_reference);
5469 // In case both T and U are arithmetic types, enforce that the
5470 // conversion is not lossy.
5471 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(T) RawT;
5472 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(U) RawU;
5473 const bool kTIsOther = GMOCK_KIND_OF_(RawT) == internal::kOther;
5474 const bool kUIsOther = GMOCK_KIND_OF_(RawU) == internal::kOther;
5475 GTEST_COMPILE_ASSERT_(
5476 kTIsOther || kUIsOther ||
5477 (internal::LosslessArithmeticConvertible<RawT, RawU>::value),
5478 conversion_of_arithmetic_types_must_be_lossless);
5479 return MatcherCast<T>(matcher);
5480 }
5481};
5482
5483template <typename T, typename M>
5484inline Matcher<T> SafeMatcherCast(const M& polymorphic_matcher) {
5485 return SafeMatcherCastImpl<T>::Cast(polymorphic_matcher);
5486}
5487
5488// A<T>() returns a matcher that matches any value of type T.
5489template <typename T>
5490Matcher<T> A();
5491
5492// Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION
5493// and MUST NOT BE USED IN USER CODE!!!
5494namespace internal {
5495
5496// If the explanation is not empty, prints it to the ostream.
5497inline void PrintIfNotEmpty(const internal::string& explanation,
5498 ::std::ostream* os) {
5499 if (explanation != "" && os != NULL) {
5500 *os << ", " << explanation;
5501 }
5502}
5503
5504// Returns true if the given type name is easy to read by a human.
5505// This is used to decide whether printing the type of a value might
5506// be helpful.
5507inline bool IsReadableTypeName(const string& type_name) {
5508 // We consider a type name readable if it's short or doesn't contain
5509 // a template or function type.
5510 return (type_name.length() <= 20 ||
5511 type_name.find_first_of("<(") == string::npos);
5512}
5513
5514// Matches the value against the given matcher, prints the value and explains
5515// the match result to the listener. Returns the match result.
5516// 'listener' must not be NULL.
5517// Value cannot be passed by const reference, because some matchers take a
5518// non-const argument.
5519template <typename Value, typename T>
5520bool MatchPrintAndExplain(Value& value, const Matcher<T>& matcher,
5521 MatchResultListener* listener) {
5522 if (!listener->IsInterested()) {
5523 // If the listener is not interested, we do not need to construct the
5524 // inner explanation.
5525 return matcher.Matches(value);
5526 }
5527
5528 StringMatchResultListener inner_listener;
5529 const bool match = matcher.MatchAndExplain(value, &inner_listener);
5530
5531 UniversalPrint(value, listener->stream());
5532#if GTEST_HAS_RTTI
5533 const string& type_name = GetTypeName<Value>();
5534 if (IsReadableTypeName(type_name))
5535 *listener->stream() << " (of type " << type_name << ")";
5536#endif
5537 PrintIfNotEmpty(inner_listener.str(), listener->stream());
5538
5539 return match;
5540}
5541
5542// An internal helper class for doing compile-time loop on a tuple's
5543// fields.
5544template <size_t N>
5545class TuplePrefix {
5546 public:
5547 // TuplePrefix<N>::Matches(matcher_tuple, value_tuple) returns true
5548 // iff the first N fields of matcher_tuple matches the first N
5549 // fields of value_tuple, respectively.
5550 template <typename MatcherTuple, typename ValueTuple>
5551 static bool Matches(const MatcherTuple& matcher_tuple,
5552 const ValueTuple& value_tuple) {
5553 return TuplePrefix<N - 1>::Matches(matcher_tuple, value_tuple)
5554 && get<N - 1>(matcher_tuple).Matches(get<N - 1>(value_tuple));
5555 }
5556
5557 // TuplePrefix<N>::ExplainMatchFailuresTo(matchers, values, os)
5558 // describes failures in matching the first N fields of matchers
5559 // against the first N fields of values. If there is no failure,
5560 // nothing will be streamed to os.
5561 template <typename MatcherTuple, typename ValueTuple>
5562 static void ExplainMatchFailuresTo(const MatcherTuple& matchers,
5563 const ValueTuple& values,
5564 ::std::ostream* os) {
5565 // First, describes failures in the first N - 1 fields.
5566 TuplePrefix<N - 1>::ExplainMatchFailuresTo(matchers, values, os);
5567
5568 // Then describes the failure (if any) in the (N - 1)-th (0-based)
5569 // field.
5570 typename tuple_element<N - 1, MatcherTuple>::type matcher =
5571 get<N - 1>(matchers);
5572 typedef typename tuple_element<N - 1, ValueTuple>::type Value;
5573 Value value = get<N - 1>(values);
5574 StringMatchResultListener listener;
5575 if (!matcher.MatchAndExplain(value, &listener)) {
5576 // TODO(wan): include in the message the name of the parameter
5577 // as used in MOCK_METHOD*() when possible.
5578 *os << " Expected arg #" << N - 1 << ": ";
5579 get<N - 1>(matchers).DescribeTo(os);
5580 *os << "\n Actual: ";
5581 // We remove the reference in type Value to prevent the
5582 // universal printer from printing the address of value, which
5583 // isn't interesting to the user most of the time. The
5584 // matcher's MatchAndExplain() method handles the case when
5585 // the address is interesting.
5586 internal::UniversalPrint(value, os);
5587 PrintIfNotEmpty(listener.str(), os);
5588 *os << "\n";
5589 }
5590 }
5591};
5592
5593// The base case.
5594template <>
5595class TuplePrefix<0> {
5596 public:
5597 template <typename MatcherTuple, typename ValueTuple>
5598 static bool Matches(const MatcherTuple& /* matcher_tuple */,
5599 const ValueTuple& /* value_tuple */) {
5600 return true;
5601 }
5602
5603 template <typename MatcherTuple, typename ValueTuple>
5604 static void ExplainMatchFailuresTo(const MatcherTuple& /* matchers */,
5605 const ValueTuple& /* values */,
5606 ::std::ostream* /* os */) {}
5607};
5608
5609// TupleMatches(matcher_tuple, value_tuple) returns true iff all
5610// matchers in matcher_tuple match the corresponding fields in
5611// value_tuple. It is a compiler error if matcher_tuple and
5612// value_tuple have different number of fields or incompatible field
5613// types.
5614template <typename MatcherTuple, typename ValueTuple>
5615bool TupleMatches(const MatcherTuple& matcher_tuple,
5616 const ValueTuple& value_tuple) {
5617 // Makes sure that matcher_tuple and value_tuple have the same
5618 // number of fields.
5619 GTEST_COMPILE_ASSERT_(tuple_size<MatcherTuple>::value ==
5620 tuple_size<ValueTuple>::value,
5621 matcher_and_value_have_different_numbers_of_fields);
5622 return TuplePrefix<tuple_size<ValueTuple>::value>::
5623 Matches(matcher_tuple, value_tuple);
5624}
5625
5626// Describes failures in matching matchers against values. If there
5627// is no failure, nothing will be streamed to os.
5628template <typename MatcherTuple, typename ValueTuple>
5629void ExplainMatchFailureTupleTo(const MatcherTuple& matchers,
5630 const ValueTuple& values,
5631 ::std::ostream* os) {
5632 TuplePrefix<tuple_size<MatcherTuple>::value>::ExplainMatchFailuresTo(
5633 matchers, values, os);
5634}
5635
5636// TransformTupleValues and its helper.
5637//
5638// TransformTupleValuesHelper hides the internal machinery that
5639// TransformTupleValues uses to implement a tuple traversal.
5640template <typename Tuple, typename Func, typename OutIter>
5641class TransformTupleValuesHelper {
5642 private:
5643 typedef ::testing::tuple_size<Tuple> TupleSize;
5644
5645 public:
5646 // For each member of tuple 't', taken in order, evaluates '*out++ = f(t)'.
5647 // Returns the final value of 'out' in case the caller needs it.
5648 static OutIter Run(Func f, const Tuple& t, OutIter out) {
5649 return IterateOverTuple<Tuple, TupleSize::value>()(f, t, out);
5650 }
5651
5652 private:
5653 template <typename Tup, size_t kRemainingSize>
5654 struct IterateOverTuple {
5655 OutIter operator() (Func f, const Tup& t, OutIter out) const {
5656 *out++ = f(::testing::get<TupleSize::value - kRemainingSize>(t));
5657 return IterateOverTuple<Tup, kRemainingSize - 1>()(f, t, out);
5658 }
5659 };
5660 template <typename Tup>
5661 struct IterateOverTuple<Tup, 0> {
5662 OutIter operator() (Func /* f */, const Tup& /* t */, OutIter out) const {
5663 return out;
5664 }
5665 };
5666};
5667
5668// Successively invokes 'f(element)' on each element of the tuple 't',
5669// appending each result to the 'out' iterator. Returns the final value
5670// of 'out'.
5671template <typename Tuple, typename Func, typename OutIter>
5672OutIter TransformTupleValues(Func f, const Tuple& t, OutIter out) {
5673 return TransformTupleValuesHelper<Tuple, Func, OutIter>::Run(f, t, out);
5674}
5675
5676// Implements A<T>().
5677template <typename T>
5678class AnyMatcherImpl : public MatcherInterface<T> {
5679 public:
5680 virtual bool MatchAndExplain(
5681 T /* x */, MatchResultListener* /* listener */) const { return true; }
5682 virtual void DescribeTo(::std::ostream* os) const { *os << "is anything"; }
5683 virtual void DescribeNegationTo(::std::ostream* os) const {
5684 // This is mostly for completeness' safe, as it's not very useful
5685 // to write Not(A<bool>()). However we cannot completely rule out
5686 // such a possibility, and it doesn't hurt to be prepared.
5687 *os << "never matches";
5688 }
5689};
5690
5691// Implements _, a matcher that matches any value of any
5692// type. This is a polymorphic matcher, so we need a template type
5693// conversion operator to make it appearing as a Matcher<T> for any
5694// type T.
5695class AnythingMatcher {
5696 public:
5697 template <typename T>
5698 operator Matcher<T>() const { return A<T>(); }
5699};
5700
5701// Implements a matcher that compares a given value with a
5702// pre-supplied value using one of the ==, <=, <, etc, operators. The
5703// two values being compared don't have to have the same type.
5704//
5705// The matcher defined here is polymorphic (for example, Eq(5) can be
5706// used to match an int, a short, a double, etc). Therefore we use
5707// a template type conversion operator in the implementation.
5708//
5709// The following template definition assumes that the Rhs parameter is
5710// a "bare" type (i.e. neither 'const T' nor 'T&').
5711template <typename D, typename Rhs, typename Op>
5712class ComparisonBase {
5713 public:
5714 explicit ComparisonBase(const Rhs& rhs) : rhs_(rhs) {}
5715 template <typename Lhs>
5716 operator Matcher<Lhs>() const {
5717 return MakeMatcher(new Impl<Lhs>(rhs_));
5718 }
5719
5720 private:
5721 template <typename Lhs>
5722 class Impl : public MatcherInterface<Lhs> {
5723 public:
5724 explicit Impl(const Rhs& rhs) : rhs_(rhs) {}
5725 virtual bool MatchAndExplain(
5726 Lhs lhs, MatchResultListener* /* listener */) const {
5727 return Op()(lhs, rhs_);
5728 }
5729 virtual void DescribeTo(::std::ostream* os) const {
5730 *os << D::Desc() << " ";
5731 UniversalPrint(rhs_, os);
5732 }
5733 virtual void DescribeNegationTo(::std::ostream* os) const {
5734 *os << D::NegatedDesc() << " ";
5735 UniversalPrint(rhs_, os);
5736 }
5737 private:
5738 Rhs rhs_;
5739 GTEST_DISALLOW_ASSIGN_(Impl);
5740 };
5741 Rhs rhs_;
5742 GTEST_DISALLOW_ASSIGN_(ComparisonBase);
5743};
5744
5745template <typename Rhs>
5746class EqMatcher : public ComparisonBase<EqMatcher<Rhs>, Rhs, AnyEq> {
5747 public:
5748 explicit EqMatcher(const Rhs& rhs)
5749 : ComparisonBase<EqMatcher<Rhs>, Rhs, AnyEq>(rhs) { }
5750 static const char* Desc() { return "is equal to"; }
5751 static const char* NegatedDesc() { return "isn't equal to"; }
5752};
5753template <typename Rhs>
5754class NeMatcher : public ComparisonBase<NeMatcher<Rhs>, Rhs, AnyNe> {
5755 public:
5756 explicit NeMatcher(const Rhs& rhs)
5757 : ComparisonBase<NeMatcher<Rhs>, Rhs, AnyNe>(rhs) { }
5758 static const char* Desc() { return "isn't equal to"; }
5759 static const char* NegatedDesc() { return "is equal to"; }
5760};
5761template <typename Rhs>
5762class LtMatcher : public ComparisonBase<LtMatcher<Rhs>, Rhs, AnyLt> {
5763 public:
5764 explicit LtMatcher(const Rhs& rhs)
5765 : ComparisonBase<LtMatcher<Rhs>, Rhs, AnyLt>(rhs) { }
5766 static const char* Desc() { return "is <"; }
5767 static const char* NegatedDesc() { return "isn't <"; }
5768};
5769template <typename Rhs>
5770class GtMatcher : public ComparisonBase<GtMatcher<Rhs>, Rhs, AnyGt> {
5771 public:
5772 explicit GtMatcher(const Rhs& rhs)
5773 : ComparisonBase<GtMatcher<Rhs>, Rhs, AnyGt>(rhs) { }
5774 static const char* Desc() { return "is >"; }
5775 static const char* NegatedDesc() { return "isn't >"; }
5776};
5777template <typename Rhs>
5778class LeMatcher : public ComparisonBase<LeMatcher<Rhs>, Rhs, AnyLe> {
5779 public:
5780 explicit LeMatcher(const Rhs& rhs)
5781 : ComparisonBase<LeMatcher<Rhs>, Rhs, AnyLe>(rhs) { }
5782 static const char* Desc() { return "is <="; }
5783 static const char* NegatedDesc() { return "isn't <="; }
5784};
5785template <typename Rhs>
5786class GeMatcher : public ComparisonBase<GeMatcher<Rhs>, Rhs, AnyGe> {
5787 public:
5788 explicit GeMatcher(const Rhs& rhs)
5789 : ComparisonBase<GeMatcher<Rhs>, Rhs, AnyGe>(rhs) { }
5790 static const char* Desc() { return "is >="; }
5791 static const char* NegatedDesc() { return "isn't >="; }
5792};
5793
5794// Implements the polymorphic IsNull() matcher, which matches any raw or smart
5795// pointer that is NULL.
5796class IsNullMatcher {
5797 public:
5798 template <typename Pointer>
5799 bool MatchAndExplain(const Pointer& p,
5800 MatchResultListener* /* listener */) const {
5801#if GTEST_LANG_CXX11
5802 return p == nullptr;
5803#else // GTEST_LANG_CXX11
5804 return GetRawPointer(p) == NULL;
5805#endif // GTEST_LANG_CXX11
5806 }
5807
5808 void DescribeTo(::std::ostream* os) const { *os << "is NULL"; }
5809 void DescribeNegationTo(::std::ostream* os) const {
5810 *os << "isn't NULL";
5811 }
5812};
5813
5814// Implements the polymorphic NotNull() matcher, which matches any raw or smart
5815// pointer that is not NULL.
5816class NotNullMatcher {
5817 public:
5818 template <typename Pointer>
5819 bool MatchAndExplain(const Pointer& p,
5820 MatchResultListener* /* listener */) const {
5821#if GTEST_LANG_CXX11
5822 return p != nullptr;
5823#else // GTEST_LANG_CXX11
5824 return GetRawPointer(p) != NULL;
5825#endif // GTEST_LANG_CXX11
5826 }
5827
5828 void DescribeTo(::std::ostream* os) const { *os << "isn't NULL"; }
5829 void DescribeNegationTo(::std::ostream* os) const {
5830 *os << "is NULL";
5831 }
5832};
5833
5834// Ref(variable) matches any argument that is a reference to
5835// 'variable'. This matcher is polymorphic as it can match any
5836// super type of the type of 'variable'.
5837//
5838// The RefMatcher template class implements Ref(variable). It can
5839// only be instantiated with a reference type. This prevents a user
5840// from mistakenly using Ref(x) to match a non-reference function
5841// argument. For example, the following will righteously cause a
5842// compiler error:
5843//
5844// int n;
5845// Matcher<int> m1 = Ref(n); // This won't compile.
5846// Matcher<int&> m2 = Ref(n); // This will compile.
5847template <typename T>
5848class RefMatcher;
5849
5850template <typename T>
5851class RefMatcher<T&> {
5852 // Google Mock is a generic framework and thus needs to support
5853 // mocking any function types, including those that take non-const
5854 // reference arguments. Therefore the template parameter T (and
5855 // Super below) can be instantiated to either a const type or a
5856 // non-const type.
5857 public:
5858 // RefMatcher() takes a T& instead of const T&, as we want the
5859 // compiler to catch using Ref(const_value) as a matcher for a
5860 // non-const reference.
5861 explicit RefMatcher(T& x) : object_(x) {} // NOLINT
5862
5863 template <typename Super>
5864 operator Matcher<Super&>() const {
5865 // By passing object_ (type T&) to Impl(), which expects a Super&,
5866 // we make sure that Super is a super type of T. In particular,
5867 // this catches using Ref(const_value) as a matcher for a
5868 // non-const reference, as you cannot implicitly convert a const
5869 // reference to a non-const reference.
5870 return MakeMatcher(new Impl<Super>(object_));
5871 }
5872
5873 private:
5874 template <typename Super>
5875 class Impl : public MatcherInterface<Super&> {
5876 public:
5877 explicit Impl(Super& x) : object_(x) {} // NOLINT
5878
5879 // MatchAndExplain() takes a Super& (as opposed to const Super&)
5880 // in order to match the interface MatcherInterface<Super&>.
5881 virtual bool MatchAndExplain(
5882 Super& x, MatchResultListener* listener) const {
5883 *listener << "which is located @" << static_cast<const void*>(&x);
5884 return &x == &object_;
5885 }
5886
5887 virtual void DescribeTo(::std::ostream* os) const {
5888 *os << "references the variable ";
5889 UniversalPrinter<Super&>::Print(object_, os);
5890 }
5891
5892 virtual void DescribeNegationTo(::std::ostream* os) const {
5893 *os << "does not reference the variable ";
5894 UniversalPrinter<Super&>::Print(object_, os);
5895 }
5896
5897 private:
5898 const Super& object_;
5899
5900 GTEST_DISALLOW_ASSIGN_(Impl);
5901 };
5902
5903 T& object_;
5904
5905 GTEST_DISALLOW_ASSIGN_(RefMatcher);
5906};
5907
5908// Polymorphic helper functions for narrow and wide string matchers.
5909inline bool CaseInsensitiveCStringEquals(const char* lhs, const char* rhs) {
5910 return String::CaseInsensitiveCStringEquals(lhs, rhs);
5911}
5912
5913inline bool CaseInsensitiveCStringEquals(const wchar_t* lhs,
5914 const wchar_t* rhs) {
5915 return String::CaseInsensitiveWideCStringEquals(lhs, rhs);
5916}
5917
5918// String comparison for narrow or wide strings that can have embedded NUL
5919// characters.
5920template <typename StringType>
5921bool CaseInsensitiveStringEquals(const StringType& s1,
5922 const StringType& s2) {
5923 // Are the heads equal?
5924 if (!CaseInsensitiveCStringEquals(s1.c_str(), s2.c_str())) {
5925 return false;
5926 }
5927
5928 // Skip the equal heads.
5929 const typename StringType::value_type nul = 0;
5930 const size_t i1 = s1.find(nul), i2 = s2.find(nul);
5931
5932 // Are we at the end of either s1 or s2?
5933 if (i1 == StringType::npos || i2 == StringType::npos) {
5934 return i1 == i2;
5935 }
5936
5937 // Are the tails equal?
5938 return CaseInsensitiveStringEquals(s1.substr(i1 + 1), s2.substr(i2 + 1));
5939}
5940
5941// String matchers.
5942
5943// Implements equality-based string matchers like StrEq, StrCaseNe, and etc.
5944template <typename StringType>
5945class StrEqualityMatcher {
5946 public:
5947 StrEqualityMatcher(const StringType& str, bool expect_eq,
5948 bool case_sensitive)
5949 : string_(str), expect_eq_(expect_eq), case_sensitive_(case_sensitive) {}
5950
5951 // Accepts pointer types, particularly:
5952 // const char*
5953 // char*
5954 // const wchar_t*
5955 // wchar_t*
5956 template <typename CharType>
5957 bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
5958 if (s == NULL) {
5959 return !expect_eq_;
5960 }
5961 return MatchAndExplain(StringType(s), listener);
5962 }
5963
5964 // Matches anything that can convert to StringType.
5965 //
5966 // This is a template, not just a plain function with const StringType&,
5967 // because StringPiece has some interfering non-explicit constructors.
5968 template <typename MatcheeStringType>
5969 bool MatchAndExplain(const MatcheeStringType& s,
5970 MatchResultListener* /* listener */) const {
5971 const StringType& s2(s);
5972 const bool eq = case_sensitive_ ? s2 == string_ :
5973 CaseInsensitiveStringEquals(s2, string_);
5974 return expect_eq_ == eq;
5975 }
5976
5977 void DescribeTo(::std::ostream* os) const {
5978 DescribeToHelper(expect_eq_, os);
5979 }
5980
5981 void DescribeNegationTo(::std::ostream* os) const {
5982 DescribeToHelper(!expect_eq_, os);
5983 }
5984
5985 private:
5986 void DescribeToHelper(bool expect_eq, ::std::ostream* os) const {
5987 *os << (expect_eq ? "is " : "isn't ");
5988 *os << "equal to ";
5989 if (!case_sensitive_) {
5990 *os << "(ignoring case) ";
5991 }
5992 UniversalPrint(string_, os);
5993 }
5994
5995 const StringType string_;
5996 const bool expect_eq_;
5997 const bool case_sensitive_;
5998
5999 GTEST_DISALLOW_ASSIGN_(StrEqualityMatcher);
6000};
6001
6002// Implements the polymorphic HasSubstr(substring) matcher, which
6003// can be used as a Matcher<T> as long as T can be converted to a
6004// string.
6005template <typename StringType>
6006class HasSubstrMatcher {
6007 public:
6008 explicit HasSubstrMatcher(const StringType& substring)
6009 : substring_(substring) {}
6010
6011 // Accepts pointer types, particularly:
6012 // const char*
6013 // char*
6014 // const wchar_t*
6015 // wchar_t*
6016 template <typename CharType>
6017 bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
6018 return s != NULL && MatchAndExplain(StringType(s), listener);
6019 }
6020
6021 // Matches anything that can convert to StringType.
6022 //
6023 // This is a template, not just a plain function with const StringType&,
6024 // because StringPiece has some interfering non-explicit constructors.
6025 template <typename MatcheeStringType>
6026 bool MatchAndExplain(const MatcheeStringType& s,
6027 MatchResultListener* /* listener */) const {
6028 const StringType& s2(s);
6029 return s2.find(substring_) != StringType::npos;
6030 }
6031
6032 // Describes what this matcher matches.
6033 void DescribeTo(::std::ostream* os) const {
6034 *os << "has substring ";
6035 UniversalPrint(substring_, os);
6036 }
6037
6038 void DescribeNegationTo(::std::ostream* os) const {
6039 *os << "has no substring ";
6040 UniversalPrint(substring_, os);
6041 }
6042
6043 private:
6044 const StringType substring_;
6045
6046 GTEST_DISALLOW_ASSIGN_(HasSubstrMatcher);
6047};
6048
6049// Implements the polymorphic StartsWith(substring) matcher, which
6050// can be used as a Matcher<T> as long as T can be converted to a
6051// string.
6052template <typename StringType>
6053class StartsWithMatcher {
6054 public:
6055 explicit StartsWithMatcher(const StringType& prefix) : prefix_(prefix) {
6056 }
6057
6058 // Accepts pointer types, particularly:
6059 // const char*
6060 // char*
6061 // const wchar_t*
6062 // wchar_t*
6063 template <typename CharType>
6064 bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
6065 return s != NULL && MatchAndExplain(StringType(s), listener);
6066 }
6067
6068 // Matches anything that can convert to StringType.
6069 //
6070 // This is a template, not just a plain function with const StringType&,
6071 // because StringPiece has some interfering non-explicit constructors.
6072 template <typename MatcheeStringType>
6073 bool MatchAndExplain(const MatcheeStringType& s,
6074 MatchResultListener* /* listener */) const {
6075 const StringType& s2(s);
6076 return s2.length() >= prefix_.length() &&
6077 s2.substr(0, prefix_.length()) == prefix_;
6078 }
6079
6080 void DescribeTo(::std::ostream* os) const {
6081 *os << "starts with ";
6082 UniversalPrint(prefix_, os);
6083 }
6084
6085 void DescribeNegationTo(::std::ostream* os) const {
6086 *os << "doesn't start with ";
6087 UniversalPrint(prefix_, os);
6088 }
6089
6090 private:
6091 const StringType prefix_;
6092
6093 GTEST_DISALLOW_ASSIGN_(StartsWithMatcher);
6094};
6095
6096// Implements the polymorphic EndsWith(substring) matcher, which
6097// can be used as a Matcher<T> as long as T can be converted to a
6098// string.
6099template <typename StringType>
6100class EndsWithMatcher {
6101 public:
6102 explicit EndsWithMatcher(const StringType& suffix) : suffix_(suffix) {}
6103
6104 // Accepts pointer types, particularly:
6105 // const char*
6106 // char*
6107 // const wchar_t*
6108 // wchar_t*
6109 template <typename CharType>
6110 bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
6111 return s != NULL && MatchAndExplain(StringType(s), listener);
6112 }
6113
6114 // Matches anything that can convert to StringType.
6115 //
6116 // This is a template, not just a plain function with const StringType&,
6117 // because StringPiece has some interfering non-explicit constructors.
6118 template <typename MatcheeStringType>
6119 bool MatchAndExplain(const MatcheeStringType& s,
6120 MatchResultListener* /* listener */) const {
6121 const StringType& s2(s);
6122 return s2.length() >= suffix_.length() &&
6123 s2.substr(s2.length() - suffix_.length()) == suffix_;
6124 }
6125
6126 void DescribeTo(::std::ostream* os) const {
6127 *os << "ends with ";
6128 UniversalPrint(suffix_, os);
6129 }
6130
6131 void DescribeNegationTo(::std::ostream* os) const {
6132 *os << "doesn't end with ";
6133 UniversalPrint(suffix_, os);
6134 }
6135
6136 private:
6137 const StringType suffix_;
6138
6139 GTEST_DISALLOW_ASSIGN_(EndsWithMatcher);
6140};
6141
6142// Implements polymorphic matchers MatchesRegex(regex) and
6143// ContainsRegex(regex), which can be used as a Matcher<T> as long as
6144// T can be converted to a string.
6145class MatchesRegexMatcher {
6146 public:
6147 MatchesRegexMatcher(const RE* regex, bool full_match)
6148 : regex_(regex), full_match_(full_match) {}
6149
6150 // Accepts pointer types, particularly:
6151 // const char*
6152 // char*
6153 // const wchar_t*
6154 // wchar_t*
6155 template <typename CharType>
6156 bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
6157 return s != NULL && MatchAndExplain(internal::string(s), listener);
6158 }
6159
6160 // Matches anything that can convert to internal::string.
6161 //
6162 // This is a template, not just a plain function with const internal::string&,
6163 // because StringPiece has some interfering non-explicit constructors.
6164 template <class MatcheeStringType>
6165 bool MatchAndExplain(const MatcheeStringType& s,
6166 MatchResultListener* /* listener */) const {
6167 const internal::string& s2(s);
6168 return full_match_ ? RE::FullMatch(s2, *regex_) :
6169 RE::PartialMatch(s2, *regex_);
6170 }
6171
6172 void DescribeTo(::std::ostream* os) const {
6173 *os << (full_match_ ? "matches" : "contains")
6174 << " regular expression ";
6175 UniversalPrinter<internal::string>::Print(regex_->pattern(), os);
6176 }
6177
6178 void DescribeNegationTo(::std::ostream* os) const {
6179 *os << "doesn't " << (full_match_ ? "match" : "contain")
6180 << " regular expression ";
6181 UniversalPrinter<internal::string>::Print(regex_->pattern(), os);
6182 }
6183
6184 private:
6185 const internal::linked_ptr<const RE> regex_;
6186 const bool full_match_;
6187
6188 GTEST_DISALLOW_ASSIGN_(MatchesRegexMatcher);
6189};
6190
6191// Implements a matcher that compares the two fields of a 2-tuple
6192// using one of the ==, <=, <, etc, operators. The two fields being
6193// compared don't have to have the same type.
6194//
6195// The matcher defined here is polymorphic (for example, Eq() can be
6196// used to match a tuple<int, short>, a tuple<const long&, double>,
6197// etc). Therefore we use a template type conversion operator in the
6198// implementation.
6199template <typename D, typename Op>
6200class PairMatchBase {
6201 public:
6202 template <typename T1, typename T2>
6203 operator Matcher< ::testing::tuple<T1, T2> >() const {
6204 return MakeMatcher(new Impl< ::testing::tuple<T1, T2> >);
6205 }
6206 template <typename T1, typename T2>
6207 operator Matcher<const ::testing::tuple<T1, T2>&>() const {
6208 return MakeMatcher(new Impl<const ::testing::tuple<T1, T2>&>);
6209 }
6210
6211 private:
6212 static ::std::ostream& GetDesc(::std::ostream& os) { // NOLINT
6213 return os << D::Desc();
6214 }
6215
6216 template <typename Tuple>
6217 class Impl : public MatcherInterface<Tuple> {
6218 public:
6219 virtual bool MatchAndExplain(
6220 Tuple args,
6221 MatchResultListener* /* listener */) const {
6222 return Op()(::testing::get<0>(args), ::testing::get<1>(args));
6223 }
6224 virtual void DescribeTo(::std::ostream* os) const {
6225 *os << "are " << GetDesc;
6226 }
6227 virtual void DescribeNegationTo(::std::ostream* os) const {
6228 *os << "aren't " << GetDesc;
6229 }
6230 };
6231};
6232
6233class Eq2Matcher : public PairMatchBase<Eq2Matcher, AnyEq> {
6234 public:
6235 static const char* Desc() { return "an equal pair"; }
6236};
6237class Ne2Matcher : public PairMatchBase<Ne2Matcher, AnyNe> {
6238 public:
6239 static const char* Desc() { return "an unequal pair"; }
6240};
6241class Lt2Matcher : public PairMatchBase<Lt2Matcher, AnyLt> {
6242 public:
6243 static const char* Desc() { return "a pair where the first < the second"; }
6244};
6245class Gt2Matcher : public PairMatchBase<Gt2Matcher, AnyGt> {
6246 public:
6247 static const char* Desc() { return "a pair where the first > the second"; }
6248};
6249class Le2Matcher : public PairMatchBase<Le2Matcher, AnyLe> {
6250 public:
6251 static const char* Desc() { return "a pair where the first <= the second"; }
6252};
6253class Ge2Matcher : public PairMatchBase<Ge2Matcher, AnyGe> {
6254 public:
6255 static const char* Desc() { return "a pair where the first >= the second"; }
6256};
6257
6258// Implements the Not(...) matcher for a particular argument type T.
6259// We do not nest it inside the NotMatcher class template, as that
6260// will prevent different instantiations of NotMatcher from sharing
6261// the same NotMatcherImpl<T> class.
6262template <typename T>
6263class NotMatcherImpl : public MatcherInterface<T> {
6264 public:
6265 explicit NotMatcherImpl(const Matcher<T>& matcher)
6266 : matcher_(matcher) {}
6267
6268 virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
6269 return !matcher_.MatchAndExplain(x, listener);
6270 }
6271
6272 virtual void DescribeTo(::std::ostream* os) const {
6273 matcher_.DescribeNegationTo(os);
6274 }
6275
6276 virtual void DescribeNegationTo(::std::ostream* os) const {
6277 matcher_.DescribeTo(os);
6278 }
6279
6280 private:
6281 const Matcher<T> matcher_;
6282
6283 GTEST_DISALLOW_ASSIGN_(NotMatcherImpl);
6284};
6285
6286// Implements the Not(m) matcher, which matches a value that doesn't
6287// match matcher m.
6288template <typename InnerMatcher>
6289class NotMatcher {
6290 public:
6291 explicit NotMatcher(InnerMatcher matcher) : matcher_(matcher) {}
6292
6293 // This template type conversion operator allows Not(m) to be used
6294 // to match any type m can match.
6295 template <typename T>
6296 operator Matcher<T>() const {
6297 return Matcher<T>(new NotMatcherImpl<T>(SafeMatcherCast<T>(matcher_)));
6298 }
6299
6300 private:
6301 InnerMatcher matcher_;
6302
6303 GTEST_DISALLOW_ASSIGN_(NotMatcher);
6304};
6305
6306// Implements the AllOf(m1, m2) matcher for a particular argument type
6307// T. We do not nest it inside the BothOfMatcher class template, as
6308// that will prevent different instantiations of BothOfMatcher from
6309// sharing the same BothOfMatcherImpl<T> class.
6310template <typename T>
6311class BothOfMatcherImpl : public MatcherInterface<T> {
6312 public:
6313 BothOfMatcherImpl(const Matcher<T>& matcher1, const Matcher<T>& matcher2)
6314 : matcher1_(matcher1), matcher2_(matcher2) {}
6315
6316 virtual void DescribeTo(::std::ostream* os) const {
6317 *os << "(";
6318 matcher1_.DescribeTo(os);
6319 *os << ") and (";
6320 matcher2_.DescribeTo(os);
6321 *os << ")";
6322 }
6323
6324 virtual void DescribeNegationTo(::std::ostream* os) const {
6325 *os << "(";
6326 matcher1_.DescribeNegationTo(os);
6327 *os << ") or (";
6328 matcher2_.DescribeNegationTo(os);
6329 *os << ")";
6330 }
6331
6332 virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
6333 // If either matcher1_ or matcher2_ doesn't match x, we only need
6334 // to explain why one of them fails.
6335 StringMatchResultListener listener1;
6336 if (!matcher1_.MatchAndExplain(x, &listener1)) {
6337 *listener << listener1.str();
6338 return false;
6339 }
6340
6341 StringMatchResultListener listener2;
6342 if (!matcher2_.MatchAndExplain(x, &listener2)) {
6343 *listener << listener2.str();
6344 return false;
6345 }
6346
6347 // Otherwise we need to explain why *both* of them match.
6348 const internal::string s1 = listener1.str();
6349 const internal::string s2 = listener2.str();
6350
6351 if (s1 == "") {
6352 *listener << s2;
6353 } else {
6354 *listener << s1;
6355 if (s2 != "") {
6356 *listener << ", and " << s2;
6357 }
6358 }
6359 return true;
6360 }
6361
6362 private:
6363 const Matcher<T> matcher1_;
6364 const Matcher<T> matcher2_;
6365
6366 GTEST_DISALLOW_ASSIGN_(BothOfMatcherImpl);
6367};
6368
6369#if GTEST_LANG_CXX11
6370// MatcherList provides mechanisms for storing a variable number of matchers in
6371// a list structure (ListType) and creating a combining matcher from such a
6372// list.
6373// The template is defined recursively using the following template paramters:
6374// * kSize is the length of the MatcherList.
6375// * Head is the type of the first matcher of the list.
6376// * Tail denotes the types of the remaining matchers of the list.
6377template <int kSize, typename Head, typename... Tail>
6378struct MatcherList {
6379 typedef MatcherList<kSize - 1, Tail...> MatcherListTail;
6380 typedef ::std::pair<Head, typename MatcherListTail::ListType> ListType;
6381
6382 // BuildList stores variadic type values in a nested pair structure.
6383 // Example:
6384 // MatcherList<3, int, string, float>::BuildList(5, "foo", 2.0) will return
6385 // the corresponding result of type pair<int, pair<string, float>>.
6386 static ListType BuildList(const Head& matcher, const Tail&... tail) {
6387 return ListType(matcher, MatcherListTail::BuildList(tail...));
6388 }
6389
6390 // CreateMatcher<T> creates a Matcher<T> from a given list of matchers (built
6391 // by BuildList()). CombiningMatcher<T> is used to combine the matchers of the
6392 // list. CombiningMatcher<T> must implement MatcherInterface<T> and have a
6393 // constructor taking two Matcher<T>s as input.
6394 template <typename T, template <typename /* T */> class CombiningMatcher>
6395 static Matcher<T> CreateMatcher(const ListType& matchers) {
6396 return Matcher<T>(new CombiningMatcher<T>(
6397 SafeMatcherCast<T>(matchers.first),
6398 MatcherListTail::template CreateMatcher<T, CombiningMatcher>(
6399 matchers.second)));
6400 }
6401};
6402
6403// The following defines the base case for the recursive definition of
6404// MatcherList.
6405template <typename Matcher1, typename Matcher2>
6406struct MatcherList<2, Matcher1, Matcher2> {
6407 typedef ::std::pair<Matcher1, Matcher2> ListType;
6408
6409 static ListType BuildList(const Matcher1& matcher1,
6410 const Matcher2& matcher2) {
6411 return ::std::pair<Matcher1, Matcher2>(matcher1, matcher2);
6412 }
6413
6414 template <typename T, template <typename /* T */> class CombiningMatcher>
6415 static Matcher<T> CreateMatcher(const ListType& matchers) {
6416 return Matcher<T>(new CombiningMatcher<T>(
6417 SafeMatcherCast<T>(matchers.first),
6418 SafeMatcherCast<T>(matchers.second)));
6419 }
6420};
6421
6422// VariadicMatcher is used for the variadic implementation of
6423// AllOf(m_1, m_2, ...) and AnyOf(m_1, m_2, ...).
6424// CombiningMatcher<T> is used to recursively combine the provided matchers
6425// (of type Args...).
6426template <template <typename T> class CombiningMatcher, typename... Args>
6427class VariadicMatcher {
6428 public:
6429 VariadicMatcher(const Args&... matchers) // NOLINT
6430 : matchers_(MatcherListType::BuildList(matchers...)) {}
6431
6432 // This template type conversion operator allows an
6433 // VariadicMatcher<Matcher1, Matcher2...> object to match any type that
6434 // all of the provided matchers (Matcher1, Matcher2, ...) can match.
6435 template <typename T>
6436 operator Matcher<T>() const {
6437 return MatcherListType::template CreateMatcher<T, CombiningMatcher>(
6438 matchers_);
6439 }
6440
6441 private:
6442 typedef MatcherList<sizeof...(Args), Args...> MatcherListType;
6443
6444 const typename MatcherListType::ListType matchers_;
6445
6446 GTEST_DISALLOW_ASSIGN_(VariadicMatcher);
6447};
6448
6449template <typename... Args>
6450using AllOfMatcher = VariadicMatcher<BothOfMatcherImpl, Args...>;
6451
6452#endif // GTEST_LANG_CXX11
6453
6454// Used for implementing the AllOf(m_1, ..., m_n) matcher, which
6455// matches a value that matches all of the matchers m_1, ..., and m_n.
6456template <typename Matcher1, typename Matcher2>
6457class BothOfMatcher {
6458 public:
6459 BothOfMatcher(Matcher1 matcher1, Matcher2 matcher2)
6460 : matcher1_(matcher1), matcher2_(matcher2) {}
6461
6462 // This template type conversion operator allows a
6463 // BothOfMatcher<Matcher1, Matcher2> object to match any type that
6464 // both Matcher1 and Matcher2 can match.
6465 template <typename T>
6466 operator Matcher<T>() const {
6467 return Matcher<T>(new BothOfMatcherImpl<T>(SafeMatcherCast<T>(matcher1_),
6468 SafeMatcherCast<T>(matcher2_)));
6469 }
6470
6471 private:
6472 Matcher1 matcher1_;
6473 Matcher2 matcher2_;
6474
6475 GTEST_DISALLOW_ASSIGN_(BothOfMatcher);
6476};
6477
6478// Implements the AnyOf(m1, m2) matcher for a particular argument type
6479// T. We do not nest it inside the AnyOfMatcher class template, as
6480// that will prevent different instantiations of AnyOfMatcher from
6481// sharing the same EitherOfMatcherImpl<T> class.
6482template <typename T>
6483class EitherOfMatcherImpl : public MatcherInterface<T> {
6484 public:
6485 EitherOfMatcherImpl(const Matcher<T>& matcher1, const Matcher<T>& matcher2)
6486 : matcher1_(matcher1), matcher2_(matcher2) {}
6487
6488 virtual void DescribeTo(::std::ostream* os) const {
6489 *os << "(";
6490 matcher1_.DescribeTo(os);
6491 *os << ") or (";
6492 matcher2_.DescribeTo(os);
6493 *os << ")";
6494 }
6495
6496 virtual void DescribeNegationTo(::std::ostream* os) const {
6497 *os << "(";
6498 matcher1_.DescribeNegationTo(os);
6499 *os << ") and (";
6500 matcher2_.DescribeNegationTo(os);
6501 *os << ")";
6502 }
6503
6504 virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
6505 // If either matcher1_ or matcher2_ matches x, we just need to
6506 // explain why *one* of them matches.
6507 StringMatchResultListener listener1;
6508 if (matcher1_.MatchAndExplain(x, &listener1)) {
6509 *listener << listener1.str();
6510 return true;
6511 }
6512
6513 StringMatchResultListener listener2;
6514 if (matcher2_.MatchAndExplain(x, &listener2)) {
6515 *listener << listener2.str();
6516 return true;
6517 }
6518
6519 // Otherwise we need to explain why *both* of them fail.
6520 const internal::string s1 = listener1.str();
6521 const internal::string s2 = listener2.str();
6522
6523 if (s1 == "") {
6524 *listener << s2;
6525 } else {
6526 *listener << s1;
6527 if (s2 != "") {
6528 *listener << ", and " << s2;
6529 }
6530 }
6531 return false;
6532 }
6533
6534 private:
6535 const Matcher<T> matcher1_;
6536 const Matcher<T> matcher2_;
6537
6538 GTEST_DISALLOW_ASSIGN_(EitherOfMatcherImpl);
6539};
6540
6541#if GTEST_LANG_CXX11
6542// AnyOfMatcher is used for the variadic implementation of AnyOf(m_1, m_2, ...).
6543template <typename... Args>
6544using AnyOfMatcher = VariadicMatcher<EitherOfMatcherImpl, Args...>;
6545
6546#endif // GTEST_LANG_CXX11
6547
6548// Used for implementing the AnyOf(m_1, ..., m_n) matcher, which
6549// matches a value that matches at least one of the matchers m_1, ...,
6550// and m_n.
6551template <typename Matcher1, typename Matcher2>
6552class EitherOfMatcher {
6553 public:
6554 EitherOfMatcher(Matcher1 matcher1, Matcher2 matcher2)
6555 : matcher1_(matcher1), matcher2_(matcher2) {}
6556
6557 // This template type conversion operator allows a
6558 // EitherOfMatcher<Matcher1, Matcher2> object to match any type that
6559 // both Matcher1 and Matcher2 can match.
6560 template <typename T>
6561 operator Matcher<T>() const {
6562 return Matcher<T>(new EitherOfMatcherImpl<T>(
6563 SafeMatcherCast<T>(matcher1_), SafeMatcherCast<T>(matcher2_)));
6564 }
6565
6566 private:
6567 Matcher1 matcher1_;
6568 Matcher2 matcher2_;
6569
6570 GTEST_DISALLOW_ASSIGN_(EitherOfMatcher);
6571};
6572
6573// Used for implementing Truly(pred), which turns a predicate into a
6574// matcher.
6575template <typename Predicate>
6576class TrulyMatcher {
6577 public:
6578 explicit TrulyMatcher(Predicate pred) : predicate_(pred) {}
6579
6580 // This method template allows Truly(pred) to be used as a matcher
6581 // for type T where T is the argument type of predicate 'pred'. The
6582 // argument is passed by reference as the predicate may be
6583 // interested in the address of the argument.
6584 template <typename T>
6585 bool MatchAndExplain(T& x, // NOLINT
6586 MatchResultListener* /* listener */) const {
6587 // Without the if-statement, MSVC sometimes warns about converting
6588 // a value to bool (warning 4800).
6589 //
6590 // We cannot write 'return !!predicate_(x);' as that doesn't work
6591 // when predicate_(x) returns a class convertible to bool but
6592 // having no operator!().
6593 if (predicate_(x))
6594 return true;
6595 return false;
6596 }
6597
6598 void DescribeTo(::std::ostream* os) const {
6599 *os << "satisfies the given predicate";
6600 }
6601
6602 void DescribeNegationTo(::std::ostream* os) const {
6603 *os << "doesn't satisfy the given predicate";
6604 }
6605
6606 private:
6607 Predicate predicate_;
6608
6609 GTEST_DISALLOW_ASSIGN_(TrulyMatcher);
6610};
6611
6612// Used for implementing Matches(matcher), which turns a matcher into
6613// a predicate.
6614template <typename M>
6615class MatcherAsPredicate {
6616 public:
6617 explicit MatcherAsPredicate(M matcher) : matcher_(matcher) {}
6618
6619 // This template operator() allows Matches(m) to be used as a
6620 // predicate on type T where m is a matcher on type T.
6621 //
6622 // The argument x is passed by reference instead of by value, as
6623 // some matcher may be interested in its address (e.g. as in
6624 // Matches(Ref(n))(x)).
6625 template <typename T>
6626 bool operator()(const T& x) const {
6627 // We let matcher_ commit to a particular type here instead of
6628 // when the MatcherAsPredicate object was constructed. This
6629 // allows us to write Matches(m) where m is a polymorphic matcher
6630 // (e.g. Eq(5)).
6631 //
6632 // If we write Matcher<T>(matcher_).Matches(x) here, it won't
6633 // compile when matcher_ has type Matcher<const T&>; if we write
6634 // Matcher<const T&>(matcher_).Matches(x) here, it won't compile
6635 // when matcher_ has type Matcher<T>; if we just write
6636 // matcher_.Matches(x), it won't compile when matcher_ is
6637 // polymorphic, e.g. Eq(5).
6638 //
6639 // MatcherCast<const T&>() is necessary for making the code work
6640 // in all of the above situations.
6641 return MatcherCast<const T&>(matcher_).Matches(x);
6642 }
6643
6644 private:
6645 M matcher_;
6646
6647 GTEST_DISALLOW_ASSIGN_(MatcherAsPredicate);
6648};
6649
6650// For implementing ASSERT_THAT() and EXPECT_THAT(). The template
6651// argument M must be a type that can be converted to a matcher.
6652template <typename M>
6653class PredicateFormatterFromMatcher {
6654 public:
6655 explicit PredicateFormatterFromMatcher(M m) : matcher_(internal::move(m)) {}
6656
6657 // This template () operator allows a PredicateFormatterFromMatcher
6658 // object to act as a predicate-formatter suitable for using with
6659 // Google Test's EXPECT_PRED_FORMAT1() macro.
6660 template <typename T>
6661 AssertionResult operator()(const char* value_text, const T& x) const {
6662 // We convert matcher_ to a Matcher<const T&> *now* instead of
6663 // when the PredicateFormatterFromMatcher object was constructed,
6664 // as matcher_ may be polymorphic (e.g. NotNull()) and we won't
6665 // know which type to instantiate it to until we actually see the
6666 // type of x here.
6667 //
6668 // We write SafeMatcherCast<const T&>(matcher_) instead of
6669 // Matcher<const T&>(matcher_), as the latter won't compile when
6670 // matcher_ has type Matcher<T> (e.g. An<int>()).
6671 // We don't write MatcherCast<const T&> either, as that allows
6672 // potentially unsafe downcasting of the matcher argument.
6673 const Matcher<const T&> matcher = SafeMatcherCast<const T&>(matcher_);
6674 StringMatchResultListener listener;
6675 if (MatchPrintAndExplain(x, matcher, &listener))
6676 return AssertionSuccess();
6677
6678 ::std::stringstream ss;
6679 ss << "Value of: " << value_text << "\n"
6680 << "Expected: ";
6681 matcher.DescribeTo(&ss);
6682 ss << "\n Actual: " << listener.str();
6683 return AssertionFailure() << ss.str();
6684 }
6685
6686 private:
6687 const M matcher_;
6688
6689 GTEST_DISALLOW_ASSIGN_(PredicateFormatterFromMatcher);
6690};
6691
6692// A helper function for converting a matcher to a predicate-formatter
6693// without the user needing to explicitly write the type. This is
6694// used for implementing ASSERT_THAT() and EXPECT_THAT().
6695// Implementation detail: 'matcher' is received by-value to force decaying.
6696template <typename M>
6697inline PredicateFormatterFromMatcher<M>
6698MakePredicateFormatterFromMatcher(M matcher) {
6699 return PredicateFormatterFromMatcher<M>(internal::move(matcher));
6700}
6701
6702// Implements the polymorphic floating point equality matcher, which matches
6703// two float values using ULP-based approximation or, optionally, a
6704// user-specified epsilon. The template is meant to be instantiated with
6705// FloatType being either float or double.
6706template <typename FloatType>
6707class FloatingEqMatcher {
6708 public:
6709 // Constructor for FloatingEqMatcher.
6710 // The matcher's input will be compared with expected. The matcher treats two
6711 // NANs as equal if nan_eq_nan is true. Otherwise, under IEEE standards,
6712 // equality comparisons between NANs will always return false. We specify a
6713 // negative max_abs_error_ term to indicate that ULP-based approximation will
6714 // be used for comparison.
6715 FloatingEqMatcher(FloatType expected, bool nan_eq_nan) :
6716 expected_(expected), nan_eq_nan_(nan_eq_nan), max_abs_error_(-1) {
6717 }
6718
6719 // Constructor that supports a user-specified max_abs_error that will be used
6720 // for comparison instead of ULP-based approximation. The max absolute
6721 // should be non-negative.
6722 FloatingEqMatcher(FloatType expected, bool nan_eq_nan,
6723 FloatType max_abs_error)
6724 : expected_(expected),
6725 nan_eq_nan_(nan_eq_nan),
6726 max_abs_error_(max_abs_error) {
6727 GTEST_CHECK_(max_abs_error >= 0)
6728 << ", where max_abs_error is" << max_abs_error;
6729 }
6730
6731 // Implements floating point equality matcher as a Matcher<T>.
6732 template <typename T>
6733 class Impl : public MatcherInterface<T> {
6734 public:
6735 Impl(FloatType expected, bool nan_eq_nan, FloatType max_abs_error)
6736 : expected_(expected),
6737 nan_eq_nan_(nan_eq_nan),
6738 max_abs_error_(max_abs_error) {}
6739
6740 virtual bool MatchAndExplain(T value,
6741 MatchResultListener* listener) const {
6742 const FloatingPoint<FloatType> actual(value), expected(expected_);
6743
6744 // Compares NaNs first, if nan_eq_nan_ is true.
6745 if (actual.is_nan() || expected.is_nan()) {
6746 if (actual.is_nan() && expected.is_nan()) {
6747 return nan_eq_nan_;
6748 }
6749 // One is nan; the other is not nan.
6750 return false;
6751 }
6752 if (HasMaxAbsError()) {
6753 // We perform an equality check so that inf will match inf, regardless
6754 // of error bounds. If the result of value - expected_ would result in
6755 // overflow or if either value is inf, the default result is infinity,
6756 // which should only match if max_abs_error_ is also infinity.
6757 if (value == expected_) {
6758 return true;
6759 }
6760
6761 const FloatType diff = value - expected_;
6762 if (fabs(diff) <= max_abs_error_) {
6763 return true;
6764 }
6765
6766 if (listener->IsInterested()) {
6767 *listener << "which is " << diff << " from " << expected_;
6768 }
6769 return false;
6770 } else {
6771 return actual.AlmostEquals(expected);
6772 }
6773 }
6774
6775 virtual void DescribeTo(::std::ostream* os) const {
6776 // os->precision() returns the previously set precision, which we
6777 // store to restore the ostream to its original configuration
6778 // after outputting.
6779 const ::std::streamsize old_precision = os->precision(
6780 ::std::numeric_limits<FloatType>::digits10 + 2);
6781 if (FloatingPoint<FloatType>(expected_).is_nan()) {
6782 if (nan_eq_nan_) {
6783 *os << "is NaN";
6784 } else {
6785 *os << "never matches";
6786 }
6787 } else {
6788 *os << "is approximately " << expected_;
6789 if (HasMaxAbsError()) {
6790 *os << " (absolute error <= " << max_abs_error_ << ")";
6791 }
6792 }
6793 os->precision(old_precision);
6794 }
6795
6796 virtual void DescribeNegationTo(::std::ostream* os) const {
6797 // As before, get original precision.
6798 const ::std::streamsize old_precision = os->precision(
6799 ::std::numeric_limits<FloatType>::digits10 + 2);
6800 if (FloatingPoint<FloatType>(expected_).is_nan()) {
6801 if (nan_eq_nan_) {
6802 *os << "isn't NaN";
6803 } else {
6804 *os << "is anything";
6805 }
6806 } else {
6807 *os << "isn't approximately " << expected_;
6808 if (HasMaxAbsError()) {
6809 *os << " (absolute error > " << max_abs_error_ << ")";
6810 }
6811 }
6812 // Restore original precision.
6813 os->precision(old_precision);
6814 }
6815
6816 private:
6817 bool HasMaxAbsError() const {
6818 return max_abs_error_ >= 0;
6819 }
6820
6821 const FloatType expected_;
6822 const bool nan_eq_nan_;
6823 // max_abs_error will be used for value comparison when >= 0.
6824 const FloatType max_abs_error_;
6825
6826 GTEST_DISALLOW_ASSIGN_(Impl);
6827 };
6828
6829 // The following 3 type conversion operators allow FloatEq(expected) and
6830 // NanSensitiveFloatEq(expected) to be used as a Matcher<float>, a
6831 // Matcher<const float&>, or a Matcher<float&>, but nothing else.
6832 // (While Google's C++ coding style doesn't allow arguments passed
6833 // by non-const reference, we may see them in code not conforming to
6834 // the style. Therefore Google Mock needs to support them.)
6835 operator Matcher<FloatType>() const {
6836 return MakeMatcher(
6837 new Impl<FloatType>(expected_, nan_eq_nan_, max_abs_error_));
6838 }
6839
6840 operator Matcher<const FloatType&>() const {
6841 return MakeMatcher(
6842 new Impl<const FloatType&>(expected_, nan_eq_nan_, max_abs_error_));
6843 }
6844
6845 operator Matcher<FloatType&>() const {
6846 return MakeMatcher(
6847 new Impl<FloatType&>(expected_, nan_eq_nan_, max_abs_error_));
6848 }
6849
6850 private:
6851 const FloatType expected_;
6852 const bool nan_eq_nan_;
6853 // max_abs_error will be used for value comparison when >= 0.
6854 const FloatType max_abs_error_;
6855
6856 GTEST_DISALLOW_ASSIGN_(FloatingEqMatcher);
6857};
6858
6859// Implements the Pointee(m) matcher for matching a pointer whose
6860// pointee matches matcher m. The pointer can be either raw or smart.
6861template <typename InnerMatcher>
6862class PointeeMatcher {
6863 public:
6864 explicit PointeeMatcher(const InnerMatcher& matcher) : matcher_(matcher) {}
6865
6866 // This type conversion operator template allows Pointee(m) to be
6867 // used as a matcher for any pointer type whose pointee type is
6868 // compatible with the inner matcher, where type Pointer can be
6869 // either a raw pointer or a smart pointer.
6870 //
6871 // The reason we do this instead of relying on
6872 // MakePolymorphicMatcher() is that the latter is not flexible
6873 // enough for implementing the DescribeTo() method of Pointee().
6874 template <typename Pointer>
6875 operator Matcher<Pointer>() const {
6876 return MakeMatcher(new Impl<Pointer>(matcher_));
6877 }
6878
6879 private:
6880 // The monomorphic implementation that works for a particular pointer type.
6881 template <typename Pointer>
6882 class Impl : public MatcherInterface<Pointer> {
6883 public:
6884 typedef typename PointeeOf<GTEST_REMOVE_CONST_( // NOLINT
6885 GTEST_REMOVE_REFERENCE_(Pointer))>::type Pointee;
6886
6887 explicit Impl(const InnerMatcher& matcher)
6888 : matcher_(MatcherCast<const Pointee&>(matcher)) {}
6889
6890 virtual void DescribeTo(::std::ostream* os) const {
6891 *os << "points to a value that ";
6892 matcher_.DescribeTo(os);
6893 }
6894
6895 virtual void DescribeNegationTo(::std::ostream* os) const {
6896 *os << "does not point to a value that ";
6897 matcher_.DescribeTo(os);
6898 }
6899
6900 virtual bool MatchAndExplain(Pointer pointer,
6901 MatchResultListener* listener) const {
6902 if (GetRawPointer(pointer) == NULL)
6903 return false;
6904
6905 *listener << "which points to ";
6906 return MatchPrintAndExplain(*pointer, matcher_, listener);
6907 }
6908
6909 private:
6910 const Matcher<const Pointee&> matcher_;
6911
6912 GTEST_DISALLOW_ASSIGN_(Impl);
6913 };
6914
6915 const InnerMatcher matcher_;
6916
6917 GTEST_DISALLOW_ASSIGN_(PointeeMatcher);
6918};
6919
6920// Implements the WhenDynamicCastTo<T>(m) matcher that matches a pointer or
6921// reference that matches inner_matcher when dynamic_cast<T> is applied.
6922// The result of dynamic_cast<To> is forwarded to the inner matcher.
6923// If To is a pointer and the cast fails, the inner matcher will receive NULL.
6924// If To is a reference and the cast fails, this matcher returns false
6925// immediately.
6926template <typename To>
6927class WhenDynamicCastToMatcherBase {
6928 public:
6929 explicit WhenDynamicCastToMatcherBase(const Matcher<To>& matcher)
6930 : matcher_(matcher) {}
6931
6932 void DescribeTo(::std::ostream* os) const {
6933 GetCastTypeDescription(os);
6934 matcher_.DescribeTo(os);
6935 }
6936
6937 void DescribeNegationTo(::std::ostream* os) const {
6938 GetCastTypeDescription(os);
6939 matcher_.DescribeNegationTo(os);
6940 }
6941
6942 protected:
6943 const Matcher<To> matcher_;
6944
6945 static string GetToName() {
6946#if GTEST_HAS_RTTI
6947 return GetTypeName<To>();
6948#else // GTEST_HAS_RTTI
6949 return "the target type";
6950#endif // GTEST_HAS_RTTI
6951 }
6952
6953 private:
6954 static void GetCastTypeDescription(::std::ostream* os) {
6955 *os << "when dynamic_cast to " << GetToName() << ", ";
6956 }
6957
6958 GTEST_DISALLOW_ASSIGN_(WhenDynamicCastToMatcherBase);
6959};
6960
6961// Primary template.
6962// To is a pointer. Cast and forward the result.
6963template <typename To>
6964class WhenDynamicCastToMatcher : public WhenDynamicCastToMatcherBase<To> {
6965 public:
6966 explicit WhenDynamicCastToMatcher(const Matcher<To>& matcher)
6967 : WhenDynamicCastToMatcherBase<To>(matcher) {}
6968
6969 template <typename From>
6970 bool MatchAndExplain(From from, MatchResultListener* listener) const {
6971 // TODO(sbenza): Add more detail on failures. ie did the dyn_cast fail?
6972 To to = dynamic_cast<To>(from);
6973 return MatchPrintAndExplain(to, this->matcher_, listener);
6974 }
6975};
6976
6977// Specialize for references.
6978// In this case we return false if the dynamic_cast fails.
6979template <typename To>
6980class WhenDynamicCastToMatcher<To&> : public WhenDynamicCastToMatcherBase<To&> {
6981 public:
6982 explicit WhenDynamicCastToMatcher(const Matcher<To&>& matcher)
6983 : WhenDynamicCastToMatcherBase<To&>(matcher) {}
6984
6985 template <typename From>
6986 bool MatchAndExplain(From& from, MatchResultListener* listener) const {
6987 // We don't want an std::bad_cast here, so do the cast with pointers.
6988 To* to = dynamic_cast<To*>(&from);
6989 if (to == NULL) {
6990 *listener << "which cannot be dynamic_cast to " << this->GetToName();
6991 return false;
6992 }
6993 return MatchPrintAndExplain(*to, this->matcher_, listener);
6994 }
6995};
6996
6997// Implements the Field() matcher for matching a field (i.e. member
6998// variable) of an object.
6999template <typename Class, typename FieldType>
7000class FieldMatcher {
7001 public:
7002 FieldMatcher(FieldType Class::*field,
7003 const Matcher<const FieldType&>& matcher)
7004 : field_(field), matcher_(matcher) {}
7005
7006 void DescribeTo(::std::ostream* os) const {
7007 *os << "is an object whose given field ";
7008 matcher_.DescribeTo(os);
7009 }
7010
7011 void DescribeNegationTo(::std::ostream* os) const {
7012 *os << "is an object whose given field ";
7013 matcher_.DescribeNegationTo(os);
7014 }
7015
7016 template <typename T>
7017 bool MatchAndExplain(const T& value, MatchResultListener* listener) const {
7018 return MatchAndExplainImpl(
7019 typename ::testing::internal::
7020 is_pointer<GTEST_REMOVE_CONST_(T)>::type(),
7021 value, listener);
7022 }
7023
7024 private:
7025 // The first argument of MatchAndExplainImpl() is needed to help
7026 // Symbian's C++ compiler choose which overload to use. Its type is
7027 // true_type iff the Field() matcher is used to match a pointer.
7028 bool MatchAndExplainImpl(false_type /* is_not_pointer */, const Class& obj,
7029 MatchResultListener* listener) const {
7030 *listener << "whose given field is ";
7031 return MatchPrintAndExplain(obj.*field_, matcher_, listener);
7032 }
7033
7034 bool MatchAndExplainImpl(true_type /* is_pointer */, const Class* p,
7035 MatchResultListener* listener) const {
7036 if (p == NULL)
7037 return false;
7038
7039 *listener << "which points to an object ";
7040 // Since *p has a field, it must be a class/struct/union type and
7041 // thus cannot be a pointer. Therefore we pass false_type() as
7042 // the first argument.
7043 return MatchAndExplainImpl(false_type(), *p, listener);
7044 }
7045
7046 const FieldType Class::*field_;
7047 const Matcher<const FieldType&> matcher_;
7048
7049 GTEST_DISALLOW_ASSIGN_(FieldMatcher);
7050};
7051
7052// Implements the Property() matcher for matching a property
7053// (i.e. return value of a getter method) of an object.
7054template <typename Class, typename PropertyType>
7055class PropertyMatcher {
7056 public:
7057 // The property may have a reference type, so 'const PropertyType&'
7058 // may cause double references and fail to compile. That's why we
7059 // need GTEST_REFERENCE_TO_CONST, which works regardless of
7060 // PropertyType being a reference or not.
7061 typedef GTEST_REFERENCE_TO_CONST_(PropertyType) RefToConstProperty;
7062
7063 PropertyMatcher(PropertyType (Class::*property)() const,
7064 const Matcher<RefToConstProperty>& matcher)
7065 : property_(property), matcher_(matcher) {}
7066
7067 void DescribeTo(::std::ostream* os) const {
7068 *os << "is an object whose given property ";
7069 matcher_.DescribeTo(os);
7070 }
7071
7072 void DescribeNegationTo(::std::ostream* os) const {
7073 *os << "is an object whose given property ";
7074 matcher_.DescribeNegationTo(os);
7075 }
7076
7077 template <typename T>
7078 bool MatchAndExplain(const T&value, MatchResultListener* listener) const {
7079 return MatchAndExplainImpl(
7080 typename ::testing::internal::
7081 is_pointer<GTEST_REMOVE_CONST_(T)>::type(),
7082 value, listener);
7083 }
7084
7085 private:
7086 // The first argument of MatchAndExplainImpl() is needed to help
7087 // Symbian's C++ compiler choose which overload to use. Its type is
7088 // true_type iff the Property() matcher is used to match a pointer.
7089 bool MatchAndExplainImpl(false_type /* is_not_pointer */, const Class& obj,
7090 MatchResultListener* listener) const {
7091 *listener << "whose given property is ";
7092 // Cannot pass the return value (for example, int) to MatchPrintAndExplain,
7093 // which takes a non-const reference as argument.
7094#if defined(_PREFAST_ ) && _MSC_VER == 1800
7095 // Workaround bug in VC++ 2013's /analyze parser.
7096 // https://connect.microsoft.com/VisualStudio/feedback/details/1106363/internal-compiler-error-with-analyze-due-to-failure-to-infer-move
7097 posix::Abort(); // To make sure it is never run.
7098 return false;
7099#else
7100 RefToConstProperty result = (obj.*property_)();
7101 return MatchPrintAndExplain(result, matcher_, listener);
7102#endif
7103 }
7104
7105 bool MatchAndExplainImpl(true_type /* is_pointer */, const Class* p,
7106 MatchResultListener* listener) const {
7107 if (p == NULL)
7108 return false;
7109
7110 *listener << "which points to an object ";
7111 // Since *p has a property method, it must be a class/struct/union
7112 // type and thus cannot be a pointer. Therefore we pass
7113 // false_type() as the first argument.
7114 return MatchAndExplainImpl(false_type(), *p, listener);
7115 }
7116
7117 PropertyType (Class::*property_)() const;
7118 const Matcher<RefToConstProperty> matcher_;
7119
7120 GTEST_DISALLOW_ASSIGN_(PropertyMatcher);
7121};
7122
7123// Type traits specifying various features of different functors for ResultOf.
7124// The default template specifies features for functor objects.
7125// Functor classes have to typedef argument_type and result_type
7126// to be compatible with ResultOf.
7127template <typename Functor>
7128struct CallableTraits {
7129 typedef typename Functor::result_type ResultType;
7130 typedef Functor StorageType;
7131
7132 static void CheckIsValid(Functor /* functor */) {}
7133 template <typename T>
7134 static ResultType Invoke(Functor f, T arg) { return f(arg); }
7135};
7136
7137// Specialization for function pointers.
7138template <typename ArgType, typename ResType>
7139struct CallableTraits<ResType(*)(ArgType)> {
7140 typedef ResType ResultType;
7141 typedef ResType(*StorageType)(ArgType);
7142
7143 static void CheckIsValid(ResType(*f)(ArgType)) {
7144 GTEST_CHECK_(f != NULL)
7145 << "NULL function pointer is passed into ResultOf().";
7146 }
7147 template <typename T>
7148 static ResType Invoke(ResType(*f)(ArgType), T arg) {
7149 return (*f)(arg);
7150 }
7151};
7152
7153// Implements the ResultOf() matcher for matching a return value of a
7154// unary function of an object.
7155template <typename Callable>
7156class ResultOfMatcher {
7157 public:
7158 typedef typename CallableTraits<Callable>::ResultType ResultType;
7159
7160 ResultOfMatcher(Callable callable, const Matcher<ResultType>& matcher)
7161 : callable_(callable), matcher_(matcher) {
7162 CallableTraits<Callable>::CheckIsValid(callable_);
7163 }
7164
7165 template <typename T>
7166 operator Matcher<T>() const {
7167 return Matcher<T>(new Impl<T>(callable_, matcher_));
7168 }
7169
7170 private:
7171 typedef typename CallableTraits<Callable>::StorageType CallableStorageType;
7172
7173 template <typename T>
7174 class Impl : public MatcherInterface<T> {
7175 public:
7176 Impl(CallableStorageType callable, const Matcher<ResultType>& matcher)
7177 : callable_(callable), matcher_(matcher) {}
7178
7179 virtual void DescribeTo(::std::ostream* os) const {
7180 *os << "is mapped by the given callable to a value that ";
7181 matcher_.DescribeTo(os);
7182 }
7183
7184 virtual void DescribeNegationTo(::std::ostream* os) const {
7185 *os << "is mapped by the given callable to a value that ";
7186 matcher_.DescribeNegationTo(os);
7187 }
7188
7189 virtual bool MatchAndExplain(T obj, MatchResultListener* listener) const {
7190 *listener << "which is mapped by the given callable to ";
7191 // Cannot pass the return value (for example, int) to
7192 // MatchPrintAndExplain, which takes a non-const reference as argument.
7193 ResultType result =
7194 CallableTraits<Callable>::template Invoke<T>(callable_, obj);
7195 return MatchPrintAndExplain(result, matcher_, listener);
7196 }
7197
7198 private:
7199 // Functors often define operator() as non-const method even though
7200 // they are actualy stateless. But we need to use them even when
7201 // 'this' is a const pointer. It's the user's responsibility not to
7202 // use stateful callables with ResultOf(), which does't guarantee
7203 // how many times the callable will be invoked.
7204 mutable CallableStorageType callable_;
7205 const Matcher<ResultType> matcher_;
7206
7207 GTEST_DISALLOW_ASSIGN_(Impl);
7208 }; // class Impl
7209
7210 const CallableStorageType callable_;
7211 const Matcher<ResultType> matcher_;
7212
7213 GTEST_DISALLOW_ASSIGN_(ResultOfMatcher);
7214};
7215
7216// Implements a matcher that checks the size of an STL-style container.
7217template <typename SizeMatcher>
7218class SizeIsMatcher {
7219 public:
7220 explicit SizeIsMatcher(const SizeMatcher& size_matcher)
7221 : size_matcher_(size_matcher) {
7222 }
7223
7224 template <typename Container>
7225 operator Matcher<Container>() const {
7226 return MakeMatcher(new Impl<Container>(size_matcher_));
7227 }
7228
7229 template <typename Container>
7230 class Impl : public MatcherInterface<Container> {
7231 public:
7232 typedef internal::StlContainerView<
7233 GTEST_REMOVE_REFERENCE_AND_CONST_(Container)> ContainerView;
7234 typedef typename ContainerView::type::size_type SizeType;
7235 explicit Impl(const SizeMatcher& size_matcher)
7236 : size_matcher_(MatcherCast<SizeType>(size_matcher)) {}
7237
7238 virtual void DescribeTo(::std::ostream* os) const {
7239 *os << "size ";
7240 size_matcher_.DescribeTo(os);
7241 }
7242 virtual void DescribeNegationTo(::std::ostream* os) const {
7243 *os << "size ";
7244 size_matcher_.DescribeNegationTo(os);
7245 }
7246
7247 virtual bool MatchAndExplain(Container container,
7248 MatchResultListener* listener) const {
7249 SizeType size = container.size();
7250 StringMatchResultListener size_listener;
7251 const bool result = size_matcher_.MatchAndExplain(size, &size_listener);
7252 *listener
7253 << "whose size " << size << (result ? " matches" : " doesn't match");
7254 PrintIfNotEmpty(size_listener.str(), listener->stream());
7255 return result;
7256 }
7257
7258 private:
7259 const Matcher<SizeType> size_matcher_;
7260 GTEST_DISALLOW_ASSIGN_(Impl);
7261 };
7262
7263 private:
7264 const SizeMatcher size_matcher_;
7265 GTEST_DISALLOW_ASSIGN_(SizeIsMatcher);
7266};
7267
7268// Implements a matcher that checks the begin()..end() distance of an STL-style
7269// container.
7270template <typename DistanceMatcher>
7271class BeginEndDistanceIsMatcher {
7272 public:
7273 explicit BeginEndDistanceIsMatcher(const DistanceMatcher& distance_matcher)
7274 : distance_matcher_(distance_matcher) {}
7275
7276 template <typename Container>
7277 operator Matcher<Container>() const {
7278 return MakeMatcher(new Impl<Container>(distance_matcher_));
7279 }
7280
7281 template <typename Container>
7282 class Impl : public MatcherInterface<Container> {
7283 public:
7284 typedef internal::StlContainerView<
7285 GTEST_REMOVE_REFERENCE_AND_CONST_(Container)> ContainerView;
7286 typedef typename std::iterator_traits<
7287 typename ContainerView::type::const_iterator>::difference_type
7288 DistanceType;
7289 explicit Impl(const DistanceMatcher& distance_matcher)
7290 : distance_matcher_(MatcherCast<DistanceType>(distance_matcher)) {}
7291
7292 virtual void DescribeTo(::std::ostream* os) const {
7293 *os << "distance between begin() and end() ";
7294 distance_matcher_.DescribeTo(os);
7295 }
7296 virtual void DescribeNegationTo(::std::ostream* os) const {
7297 *os << "distance between begin() and end() ";
7298 distance_matcher_.DescribeNegationTo(os);
7299 }
7300
7301 virtual bool MatchAndExplain(Container container,
7302 MatchResultListener* listener) const {
7303#if GTEST_HAS_STD_BEGIN_AND_END_
7304 using std::begin;
7305 using std::end;
7306 DistanceType distance = std::distance(begin(container), end(container));
7307#else
7308 DistanceType distance = std::distance(container.begin(), container.end());
7309#endif
7310 StringMatchResultListener distance_listener;
7311 const bool result =
7312 distance_matcher_.MatchAndExplain(distance, &distance_listener);
7313 *listener << "whose distance between begin() and end() " << distance
7314 << (result ? " matches" : " doesn't match");
7315 PrintIfNotEmpty(distance_listener.str(), listener->stream());
7316 return result;
7317 }
7318
7319 private:
7320 const Matcher<DistanceType> distance_matcher_;
7321 GTEST_DISALLOW_ASSIGN_(Impl);
7322 };
7323
7324 private:
7325 const DistanceMatcher distance_matcher_;
7326 GTEST_DISALLOW_ASSIGN_(BeginEndDistanceIsMatcher);
7327};
7328
7329// Implements an equality matcher for any STL-style container whose elements
7330// support ==. This matcher is like Eq(), but its failure explanations provide
7331// more detailed information that is useful when the container is used as a set.
7332// The failure message reports elements that are in one of the operands but not
7333// the other. The failure messages do not report duplicate or out-of-order
7334// elements in the containers (which don't properly matter to sets, but can
7335// occur if the containers are vectors or lists, for example).
7336//
7337// Uses the container's const_iterator, value_type, operator ==,
7338// begin(), and end().
7339template <typename Container>
7340class ContainerEqMatcher {
7341 public:
7342 typedef internal::StlContainerView<Container> View;
7343 typedef typename View::type StlContainer;
7344 typedef typename View::const_reference StlContainerReference;
7345
7346 // We make a copy of expected in case the elements in it are modified
7347 // after this matcher is created.
7348 explicit ContainerEqMatcher(const Container& expected)
7349 : expected_(View::Copy(expected)) {
7350 // Makes sure the user doesn't instantiate this class template
7351 // with a const or reference type.
7352 (void)testing::StaticAssertTypeEq<Container,
7353 GTEST_REMOVE_REFERENCE_AND_CONST_(Container)>();
7354 }
7355
7356 void DescribeTo(::std::ostream* os) const {
7357 *os << "equals ";
7358 UniversalPrint(expected_, os);
7359 }
7360 void DescribeNegationTo(::std::ostream* os) const {
7361 *os << "does not equal ";
7362 UniversalPrint(expected_, os);
7363 }
7364
7365 template <typename LhsContainer>
7366 bool MatchAndExplain(const LhsContainer& lhs,
7367 MatchResultListener* listener) const {
7368 // GTEST_REMOVE_CONST_() is needed to work around an MSVC 8.0 bug
7369 // that causes LhsContainer to be a const type sometimes.
7370 typedef internal::StlContainerView<GTEST_REMOVE_CONST_(LhsContainer)>
7371 LhsView;
7372 typedef typename LhsView::type LhsStlContainer;
7373 StlContainerReference lhs_stl_container = LhsView::ConstReference(lhs);
7374 if (lhs_stl_container == expected_)
7375 return true;
7376
7377 ::std::ostream* const os = listener->stream();
7378 if (os != NULL) {
7379 // Something is different. Check for extra values first.
7380 bool printed_header = false;
7381 for (typename LhsStlContainer::const_iterator it =
7382 lhs_stl_container.begin();
7383 it != lhs_stl_container.end(); ++it) {
7384 if (internal::ArrayAwareFind(expected_.begin(), expected_.end(), *it) ==
7385 expected_.end()) {
7386 if (printed_header) {
7387 *os << ", ";
7388 } else {
7389 *os << "which has these unexpected elements: ";
7390 printed_header = true;
7391 }
7392 UniversalPrint(*it, os);
7393 }
7394 }
7395
7396 // Now check for missing values.
7397 bool printed_header2 = false;
7398 for (typename StlContainer::const_iterator it = expected_.begin();
7399 it != expected_.end(); ++it) {
7400 if (internal::ArrayAwareFind(
7401 lhs_stl_container.begin(), lhs_stl_container.end(), *it) ==
7402 lhs_stl_container.end()) {
7403 if (printed_header2) {
7404 *os << ", ";
7405 } else {
7406 *os << (printed_header ? ",\nand" : "which")
7407 << " doesn't have these expected elements: ";
7408 printed_header2 = true;
7409 }
7410 UniversalPrint(*it, os);
7411 }
7412 }
7413 }
7414
7415 return false;
7416 }
7417
7418 private:
7419 const StlContainer expected_;
7420
7421 GTEST_DISALLOW_ASSIGN_(ContainerEqMatcher);
7422};
7423
7424// A comparator functor that uses the < operator to compare two values.
7425struct LessComparator {
7426 template <typename T, typename U>
7427 bool operator()(const T& lhs, const U& rhs) const { return lhs < rhs; }
7428};
7429
7430// Implements WhenSortedBy(comparator, container_matcher).
7431template <typename Comparator, typename ContainerMatcher>
7432class WhenSortedByMatcher {
7433 public:
7434 WhenSortedByMatcher(const Comparator& comparator,
7435 const ContainerMatcher& matcher)
7436 : comparator_(comparator), matcher_(matcher) {}
7437
7438 template <typename LhsContainer>
7439 operator Matcher<LhsContainer>() const {
7440 return MakeMatcher(new Impl<LhsContainer>(comparator_, matcher_));
7441 }
7442
7443 template <typename LhsContainer>
7444 class Impl : public MatcherInterface<LhsContainer> {
7445 public:
7446 typedef internal::StlContainerView<
7447 GTEST_REMOVE_REFERENCE_AND_CONST_(LhsContainer)> LhsView;
7448 typedef typename LhsView::type LhsStlContainer;
7449 typedef typename LhsView::const_reference LhsStlContainerReference;
7450 // Transforms std::pair<const Key, Value> into std::pair<Key, Value>
7451 // so that we can match associative containers.
7452 typedef typename RemoveConstFromKey<
7453 typename LhsStlContainer::value_type>::type LhsValue;
7454
7455 Impl(const Comparator& comparator, const ContainerMatcher& matcher)
7456 : comparator_(comparator), matcher_(matcher) {}
7457
7458 virtual void DescribeTo(::std::ostream* os) const {
7459 *os << "(when sorted) ";
7460 matcher_.DescribeTo(os);
7461 }
7462
7463 virtual void DescribeNegationTo(::std::ostream* os) const {
7464 *os << "(when sorted) ";
7465 matcher_.DescribeNegationTo(os);
7466 }
7467
7468 virtual bool MatchAndExplain(LhsContainer lhs,
7469 MatchResultListener* listener) const {
7470 LhsStlContainerReference lhs_stl_container = LhsView::ConstReference(lhs);
7471 ::std::vector<LhsValue> sorted_container(lhs_stl_container.begin(),
7472 lhs_stl_container.end());
7473 ::std::sort(
7474 sorted_container.begin(), sorted_container.end(), comparator_);
7475
7476 if (!listener->IsInterested()) {
7477 // If the listener is not interested, we do not need to
7478 // construct the inner explanation.
7479 return matcher_.Matches(sorted_container);
7480 }
7481
7482 *listener << "which is ";
7483 UniversalPrint(sorted_container, listener->stream());
7484 *listener << " when sorted";
7485
7486 StringMatchResultListener inner_listener;
7487 const bool match = matcher_.MatchAndExplain(sorted_container,
7488 &inner_listener);
7489 PrintIfNotEmpty(inner_listener.str(), listener->stream());
7490 return match;
7491 }
7492
7493 private:
7494 const Comparator comparator_;
7495 const Matcher<const ::std::vector<LhsValue>&> matcher_;
7496
7497 GTEST_DISALLOW_COPY_AND_ASSIGN_(Impl);
7498 };
7499
7500 private:
7501 const Comparator comparator_;
7502 const ContainerMatcher matcher_;
7503
7504 GTEST_DISALLOW_ASSIGN_(WhenSortedByMatcher);
7505};
7506
7507// Implements Pointwise(tuple_matcher, rhs_container). tuple_matcher
7508// must be able to be safely cast to Matcher<tuple<const T1&, const
7509// T2&> >, where T1 and T2 are the types of elements in the LHS
7510// container and the RHS container respectively.
7511template <typename TupleMatcher, typename RhsContainer>
7512class PointwiseMatcher {
7513 public:
7514 typedef internal::StlContainerView<RhsContainer> RhsView;
7515 typedef typename RhsView::type RhsStlContainer;
7516 typedef typename RhsStlContainer::value_type RhsValue;
7517
7518 // Like ContainerEq, we make a copy of rhs in case the elements in
7519 // it are modified after this matcher is created.
7520 PointwiseMatcher(const TupleMatcher& tuple_matcher, const RhsContainer& rhs)
7521 : tuple_matcher_(tuple_matcher), rhs_(RhsView::Copy(rhs)) {
7522 // Makes sure the user doesn't instantiate this class template
7523 // with a const or reference type.
7524 (void)testing::StaticAssertTypeEq<RhsContainer,
7525 GTEST_REMOVE_REFERENCE_AND_CONST_(RhsContainer)>();
7526 }
7527
7528 template <typename LhsContainer>
7529 operator Matcher<LhsContainer>() const {
7530 return MakeMatcher(new Impl<LhsContainer>(tuple_matcher_, rhs_));
7531 }
7532
7533 template <typename LhsContainer>
7534 class Impl : public MatcherInterface<LhsContainer> {
7535 public:
7536 typedef internal::StlContainerView<
7537 GTEST_REMOVE_REFERENCE_AND_CONST_(LhsContainer)> LhsView;
7538 typedef typename LhsView::type LhsStlContainer;
7539 typedef typename LhsView::const_reference LhsStlContainerReference;
7540 typedef typename LhsStlContainer::value_type LhsValue;
7541 // We pass the LHS value and the RHS value to the inner matcher by
7542 // reference, as they may be expensive to copy. We must use tuple
7543 // instead of pair here, as a pair cannot hold references (C++ 98,
7544 // 20.2.2 [lib.pairs]).
7545 typedef ::testing::tuple<const LhsValue&, const RhsValue&> InnerMatcherArg;
7546
7547 Impl(const TupleMatcher& tuple_matcher, const RhsStlContainer& rhs)
7548 // mono_tuple_matcher_ holds a monomorphic version of the tuple matcher.
7549 : mono_tuple_matcher_(SafeMatcherCast<InnerMatcherArg>(tuple_matcher)),
7550 rhs_(rhs) {}
7551
7552 virtual void DescribeTo(::std::ostream* os) const {
7553 *os << "contains " << rhs_.size()
7554 << " values, where each value and its corresponding value in ";
7555 UniversalPrinter<RhsStlContainer>::Print(rhs_, os);
7556 *os << " ";
7557 mono_tuple_matcher_.DescribeTo(os);
7558 }
7559 virtual void DescribeNegationTo(::std::ostream* os) const {
7560 *os << "doesn't contain exactly " << rhs_.size()
7561 << " values, or contains a value x at some index i"
7562 << " where x and the i-th value of ";
7563 UniversalPrint(rhs_, os);
7564 *os << " ";
7565 mono_tuple_matcher_.DescribeNegationTo(os);
7566 }
7567
7568 virtual bool MatchAndExplain(LhsContainer lhs,
7569 MatchResultListener* listener) const {
7570 LhsStlContainerReference lhs_stl_container = LhsView::ConstReference(lhs);
7571 const size_t actual_size = lhs_stl_container.size();
7572 if (actual_size != rhs_.size()) {
7573 *listener << "which contains " << actual_size << " values";
7574 return false;
7575 }
7576
7577 typename LhsStlContainer::const_iterator left = lhs_stl_container.begin();
7578 typename RhsStlContainer::const_iterator right = rhs_.begin();
7579 for (size_t i = 0; i != actual_size; ++i, ++left, ++right) {
7580 const InnerMatcherArg value_pair(*left, *right);
7581
7582 if (listener->IsInterested()) {
7583 StringMatchResultListener inner_listener;
7584 if (!mono_tuple_matcher_.MatchAndExplain(
7585 value_pair, &inner_listener)) {
7586 *listener << "where the value pair (";
7587 UniversalPrint(*left, listener->stream());
7588 *listener << ", ";
7589 UniversalPrint(*right, listener->stream());
7590 *listener << ") at index #" << i << " don't match";
7591 PrintIfNotEmpty(inner_listener.str(), listener->stream());
7592 return false;
7593 }
7594 } else {
7595 if (!mono_tuple_matcher_.Matches(value_pair))
7596 return false;
7597 }
7598 }
7599
7600 return true;
7601 }
7602
7603 private:
7604 const Matcher<InnerMatcherArg> mono_tuple_matcher_;
7605 const RhsStlContainer rhs_;
7606
7607 GTEST_DISALLOW_ASSIGN_(Impl);
7608 };
7609
7610 private:
7611 const TupleMatcher tuple_matcher_;
7612 const RhsStlContainer rhs_;
7613
7614 GTEST_DISALLOW_ASSIGN_(PointwiseMatcher);
7615};
7616
7617// Holds the logic common to ContainsMatcherImpl and EachMatcherImpl.
7618template <typename Container>
7619class QuantifierMatcherImpl : public MatcherInterface<Container> {
7620 public:
7621 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
7622 typedef StlContainerView<RawContainer> View;
7623 typedef typename View::type StlContainer;
7624 typedef typename View::const_reference StlContainerReference;
7625 typedef typename StlContainer::value_type Element;
7626
7627 template <typename InnerMatcher>
7628 explicit QuantifierMatcherImpl(InnerMatcher inner_matcher)
7629 : inner_matcher_(
7630 testing::SafeMatcherCast<const Element&>(inner_matcher)) {}
7631
7632 // Checks whether:
7633 // * All elements in the container match, if all_elements_should_match.
7634 // * Any element in the container matches, if !all_elements_should_match.
7635 bool MatchAndExplainImpl(bool all_elements_should_match,
7636 Container container,
7637 MatchResultListener* listener) const {
7638 StlContainerReference stl_container = View::ConstReference(container);
7639 size_t i = 0;
7640 for (typename StlContainer::const_iterator it = stl_container.begin();
7641 it != stl_container.end(); ++it, ++i) {
7642 StringMatchResultListener inner_listener;
7643 const bool matches = inner_matcher_.MatchAndExplain(*it, &inner_listener);
7644
7645 if (matches != all_elements_should_match) {
7646 *listener << "whose element #" << i
7647 << (matches ? " matches" : " doesn't match");
7648 PrintIfNotEmpty(inner_listener.str(), listener->stream());
7649 return !all_elements_should_match;
7650 }
7651 }
7652 return all_elements_should_match;
7653 }
7654
7655 protected:
7656 const Matcher<const Element&> inner_matcher_;
7657
7658 GTEST_DISALLOW_ASSIGN_(QuantifierMatcherImpl);
7659};
7660
7661// Implements Contains(element_matcher) for the given argument type Container.
7662// Symmetric to EachMatcherImpl.
7663template <typename Container>
7664class ContainsMatcherImpl : public QuantifierMatcherImpl<Container> {
7665 public:
7666 template <typename InnerMatcher>
7667 explicit ContainsMatcherImpl(InnerMatcher inner_matcher)
7668 : QuantifierMatcherImpl<Container>(inner_matcher) {}
7669
7670 // Describes what this matcher does.
7671 virtual void DescribeTo(::std::ostream* os) const {
7672 *os << "contains at least one element that ";
7673 this->inner_matcher_.DescribeTo(os);
7674 }
7675
7676 virtual void DescribeNegationTo(::std::ostream* os) const {
7677 *os << "doesn't contain any element that ";
7678 this->inner_matcher_.DescribeTo(os);
7679 }
7680
7681 virtual bool MatchAndExplain(Container container,
7682 MatchResultListener* listener) const {
7683 return this->MatchAndExplainImpl(false, container, listener);
7684 }
7685
7686 private:
7687 GTEST_DISALLOW_ASSIGN_(ContainsMatcherImpl);
7688};
7689
7690// Implements Each(element_matcher) for the given argument type Container.
7691// Symmetric to ContainsMatcherImpl.
7692template <typename Container>
7693class EachMatcherImpl : public QuantifierMatcherImpl<Container> {
7694 public:
7695 template <typename InnerMatcher>
7696 explicit EachMatcherImpl(InnerMatcher inner_matcher)
7697 : QuantifierMatcherImpl<Container>(inner_matcher) {}
7698
7699 // Describes what this matcher does.
7700 virtual void DescribeTo(::std::ostream* os) const {
7701 *os << "only contains elements that ";
7702 this->inner_matcher_.DescribeTo(os);
7703 }
7704
7705 virtual void DescribeNegationTo(::std::ostream* os) const {
7706 *os << "contains some element that ";
7707 this->inner_matcher_.DescribeNegationTo(os);
7708 }
7709
7710 virtual bool MatchAndExplain(Container container,
7711 MatchResultListener* listener) const {
7712 return this->MatchAndExplainImpl(true, container, listener);
7713 }
7714
7715 private:
7716 GTEST_DISALLOW_ASSIGN_(EachMatcherImpl);
7717};
7718
7719// Implements polymorphic Contains(element_matcher).
7720template <typename M>
7721class ContainsMatcher {
7722 public:
7723 explicit ContainsMatcher(M m) : inner_matcher_(m) {}
7724
7725 template <typename Container>
7726 operator Matcher<Container>() const {
7727 return MakeMatcher(new ContainsMatcherImpl<Container>(inner_matcher_));
7728 }
7729
7730 private:
7731 const M inner_matcher_;
7732
7733 GTEST_DISALLOW_ASSIGN_(ContainsMatcher);
7734};
7735
7736// Implements polymorphic Each(element_matcher).
7737template <typename M>
7738class EachMatcher {
7739 public:
7740 explicit EachMatcher(M m) : inner_matcher_(m) {}
7741
7742 template <typename Container>
7743 operator Matcher<Container>() const {
7744 return MakeMatcher(new EachMatcherImpl<Container>(inner_matcher_));
7745 }
7746
7747 private:
7748 const M inner_matcher_;
7749
7750 GTEST_DISALLOW_ASSIGN_(EachMatcher);
7751};
7752
7753// Implements Key(inner_matcher) for the given argument pair type.
7754// Key(inner_matcher) matches an std::pair whose 'first' field matches
7755// inner_matcher. For example, Contains(Key(Ge(5))) can be used to match an
7756// std::map that contains at least one element whose key is >= 5.
7757template <typename PairType>
7758class KeyMatcherImpl : public MatcherInterface<PairType> {
7759 public:
7760 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(PairType) RawPairType;
7761 typedef typename RawPairType::first_type KeyType;
7762
7763 template <typename InnerMatcher>
7764 explicit KeyMatcherImpl(InnerMatcher inner_matcher)
7765 : inner_matcher_(
7766 testing::SafeMatcherCast<const KeyType&>(inner_matcher)) {
7767 }
7768
7769 // Returns true iff 'key_value.first' (the key) matches the inner matcher.
7770 virtual bool MatchAndExplain(PairType key_value,
7771 MatchResultListener* listener) const {
7772 StringMatchResultListener inner_listener;
7773 const bool match = inner_matcher_.MatchAndExplain(key_value.first,
7774 &inner_listener);
7775 const internal::string explanation = inner_listener.str();
7776 if (explanation != "") {
7777 *listener << "whose first field is a value " << explanation;
7778 }
7779 return match;
7780 }
7781
7782 // Describes what this matcher does.
7783 virtual void DescribeTo(::std::ostream* os) const {
7784 *os << "has a key that ";
7785 inner_matcher_.DescribeTo(os);
7786 }
7787
7788 // Describes what the negation of this matcher does.
7789 virtual void DescribeNegationTo(::std::ostream* os) const {
7790 *os << "doesn't have a key that ";
7791 inner_matcher_.DescribeTo(os);
7792 }
7793
7794 private:
7795 const Matcher<const KeyType&> inner_matcher_;
7796
7797 GTEST_DISALLOW_ASSIGN_(KeyMatcherImpl);
7798};
7799
7800// Implements polymorphic Key(matcher_for_key).
7801template <typename M>
7802class KeyMatcher {
7803 public:
7804 explicit KeyMatcher(M m) : matcher_for_key_(m) {}
7805
7806 template <typename PairType>
7807 operator Matcher<PairType>() const {
7808 return MakeMatcher(new KeyMatcherImpl<PairType>(matcher_for_key_));
7809 }
7810
7811 private:
7812 const M matcher_for_key_;
7813
7814 GTEST_DISALLOW_ASSIGN_(KeyMatcher);
7815};
7816
7817// Implements Pair(first_matcher, second_matcher) for the given argument pair
7818// type with its two matchers. See Pair() function below.
7819template <typename PairType>
7820class PairMatcherImpl : public MatcherInterface<PairType> {
7821 public:
7822 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(PairType) RawPairType;
7823 typedef typename RawPairType::first_type FirstType;
7824 typedef typename RawPairType::second_type SecondType;
7825
7826 template <typename FirstMatcher, typename SecondMatcher>
7827 PairMatcherImpl(FirstMatcher first_matcher, SecondMatcher second_matcher)
7828 : first_matcher_(
7829 testing::SafeMatcherCast<const FirstType&>(first_matcher)),
7830 second_matcher_(
7831 testing::SafeMatcherCast<const SecondType&>(second_matcher)) {
7832 }
7833
7834 // Describes what this matcher does.
7835 virtual void DescribeTo(::std::ostream* os) const {
7836 *os << "has a first field that ";
7837 first_matcher_.DescribeTo(os);
7838 *os << ", and has a second field that ";
7839 second_matcher_.DescribeTo(os);
7840 }
7841
7842 // Describes what the negation of this matcher does.
7843 virtual void DescribeNegationTo(::std::ostream* os) const {
7844 *os << "has a first field that ";
7845 first_matcher_.DescribeNegationTo(os);
7846 *os << ", or has a second field that ";
7847 second_matcher_.DescribeNegationTo(os);
7848 }
7849
7850 // Returns true iff 'a_pair.first' matches first_matcher and 'a_pair.second'
7851 // matches second_matcher.
7852 virtual bool MatchAndExplain(PairType a_pair,
7853 MatchResultListener* listener) const {
7854 if (!listener->IsInterested()) {
7855 // If the listener is not interested, we don't need to construct the
7856 // explanation.
7857 return first_matcher_.Matches(a_pair.first) &&
7858 second_matcher_.Matches(a_pair.second);
7859 }
7860 StringMatchResultListener first_inner_listener;
7861 if (!first_matcher_.MatchAndExplain(a_pair.first,
7862 &first_inner_listener)) {
7863 *listener << "whose first field does not match";
7864 PrintIfNotEmpty(first_inner_listener.str(), listener->stream());
7865 return false;
7866 }
7867 StringMatchResultListener second_inner_listener;
7868 if (!second_matcher_.MatchAndExplain(a_pair.second,
7869 &second_inner_listener)) {
7870 *listener << "whose second field does not match";
7871 PrintIfNotEmpty(second_inner_listener.str(), listener->stream());
7872 return false;
7873 }
7874 ExplainSuccess(first_inner_listener.str(), second_inner_listener.str(),
7875 listener);
7876 return true;
7877 }
7878
7879 private:
7880 void ExplainSuccess(const internal::string& first_explanation,
7881 const internal::string& second_explanation,
7882 MatchResultListener* listener) const {
7883 *listener << "whose both fields match";
7884 if (first_explanation != "") {
7885 *listener << ", where the first field is a value " << first_explanation;
7886 }
7887 if (second_explanation != "") {
7888 *listener << ", ";
7889 if (first_explanation != "") {
7890 *listener << "and ";
7891 } else {
7892 *listener << "where ";
7893 }
7894 *listener << "the second field is a value " << second_explanation;
7895 }
7896 }
7897
7898 const Matcher<const FirstType&> first_matcher_;
7899 const Matcher<const SecondType&> second_matcher_;
7900
7901 GTEST_DISALLOW_ASSIGN_(PairMatcherImpl);
7902};
7903
7904// Implements polymorphic Pair(first_matcher, second_matcher).
7905template <typename FirstMatcher, typename SecondMatcher>
7906class PairMatcher {
7907 public:
7908 PairMatcher(FirstMatcher first_matcher, SecondMatcher second_matcher)
7909 : first_matcher_(first_matcher), second_matcher_(second_matcher) {}
7910
7911 template <typename PairType>
7912 operator Matcher<PairType> () const {
7913 return MakeMatcher(
7914 new PairMatcherImpl<PairType>(
7915 first_matcher_, second_matcher_));
7916 }
7917
7918 private:
7919 const FirstMatcher first_matcher_;
7920 const SecondMatcher second_matcher_;
7921
7922 GTEST_DISALLOW_ASSIGN_(PairMatcher);
7923};
7924
7925// Implements ElementsAre() and ElementsAreArray().
7926template <typename Container>
7927class ElementsAreMatcherImpl : public MatcherInterface<Container> {
7928 public:
7929 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
7930 typedef internal::StlContainerView<RawContainer> View;
7931 typedef typename View::type StlContainer;
7932 typedef typename View::const_reference StlContainerReference;
7933 typedef typename StlContainer::value_type Element;
7934
7935 // Constructs the matcher from a sequence of element values or
7936 // element matchers.
7937 template <typename InputIter>
7938 ElementsAreMatcherImpl(InputIter first, InputIter last) {
7939 while (first != last) {
7940 matchers_.push_back(MatcherCast<const Element&>(*first++));
7941 }
7942 }
7943
7944 // Describes what this matcher does.
7945 virtual void DescribeTo(::std::ostream* os) const {
7946 if (count() == 0) {
7947 *os << "is empty";
7948 } else if (count() == 1) {
7949 *os << "has 1 element that ";
7950 matchers_[0].DescribeTo(os);
7951 } else {
7952 *os << "has " << Elements(count()) << " where\n";
7953 for (size_t i = 0; i != count(); ++i) {
7954 *os << "element #" << i << " ";
7955 matchers_[i].DescribeTo(os);
7956 if (i + 1 < count()) {
7957 *os << ",\n";
7958 }
7959 }
7960 }
7961 }
7962
7963 // Describes what the negation of this matcher does.
7964 virtual void DescribeNegationTo(::std::ostream* os) const {
7965 if (count() == 0) {
7966 *os << "isn't empty";
7967 return;
7968 }
7969
7970 *os << "doesn't have " << Elements(count()) << ", or\n";
7971 for (size_t i = 0; i != count(); ++i) {
7972 *os << "element #" << i << " ";
7973 matchers_[i].DescribeNegationTo(os);
7974 if (i + 1 < count()) {
7975 *os << ", or\n";
7976 }
7977 }
7978 }
7979
7980 virtual bool MatchAndExplain(Container container,
7981 MatchResultListener* listener) const {
7982 // To work with stream-like "containers", we must only walk
7983 // through the elements in one pass.
7984
7985 const bool listener_interested = listener->IsInterested();
7986
7987 // explanations[i] is the explanation of the element at index i.
7988 ::std::vector<internal::string> explanations(count());
7989 StlContainerReference stl_container = View::ConstReference(container);
7990 typename StlContainer::const_iterator it = stl_container.begin();
7991 size_t exam_pos = 0;
7992 bool mismatch_found = false; // Have we found a mismatched element yet?
7993
7994 // Go through the elements and matchers in pairs, until we reach
7995 // the end of either the elements or the matchers, or until we find a
7996 // mismatch.
7997 for (; it != stl_container.end() && exam_pos != count(); ++it, ++exam_pos) {
7998 bool match; // Does the current element match the current matcher?
7999 if (listener_interested) {
8000 StringMatchResultListener s;
8001 match = matchers_[exam_pos].MatchAndExplain(*it, &s);
8002 explanations[exam_pos] = s.str();
8003 } else {
8004 match = matchers_[exam_pos].Matches(*it);
8005 }
8006
8007 if (!match) {
8008 mismatch_found = true;
8009 break;
8010 }
8011 }
8012 // If mismatch_found is true, 'exam_pos' is the index of the mismatch.
8013
8014 // Find how many elements the actual container has. We avoid
8015 // calling size() s.t. this code works for stream-like "containers"
8016 // that don't define size().
8017 size_t actual_count = exam_pos;
8018 for (; it != stl_container.end(); ++it) {
8019 ++actual_count;
8020 }
8021
8022 if (actual_count != count()) {
8023 // The element count doesn't match. If the container is empty,
8024 // there's no need to explain anything as Google Mock already
8025 // prints the empty container. Otherwise we just need to show
8026 // how many elements there actually are.
8027 if (listener_interested && (actual_count != 0)) {
8028 *listener << "which has " << Elements(actual_count);
8029 }
8030 return false;
8031 }
8032
8033 if (mismatch_found) {
8034 // The element count matches, but the exam_pos-th element doesn't match.
8035 if (listener_interested) {
8036 *listener << "whose element #" << exam_pos << " doesn't match";
8037 PrintIfNotEmpty(explanations[exam_pos], listener->stream());
8038 }
8039 return false;
8040 }
8041
8042 // Every element matches its expectation. We need to explain why
8043 // (the obvious ones can be skipped).
8044 if (listener_interested) {
8045 bool reason_printed = false;
8046 for (size_t i = 0; i != count(); ++i) {
8047 const internal::string& s = explanations[i];
8048 if (!s.empty()) {
8049 if (reason_printed) {
8050 *listener << ",\nand ";
8051 }
8052 *listener << "whose element #" << i << " matches, " << s;
8053 reason_printed = true;
8054 }
8055 }
8056 }
8057 return true;
8058 }
8059
8060 private:
8061 static Message Elements(size_t count) {
8062 return Message() << count << (count == 1 ? " element" : " elements");
8063 }
8064
8065 size_t count() const { return matchers_.size(); }
8066
8067 ::std::vector<Matcher<const Element&> > matchers_;
8068
8069 GTEST_DISALLOW_ASSIGN_(ElementsAreMatcherImpl);
8070};
8071
8072// Connectivity matrix of (elements X matchers), in element-major order.
8073// Initially, there are no edges.
8074// Use NextGraph() to iterate over all possible edge configurations.
8075// Use Randomize() to generate a random edge configuration.
8076class GTEST_API_ MatchMatrix {
8077 public:
8078 MatchMatrix(size_t num_elements, size_t num_matchers)
8079 : num_elements_(num_elements),
8080 num_matchers_(num_matchers),
8081 matched_(num_elements_* num_matchers_, 0) {
8082 }
8083
8084 size_t LhsSize() const { return num_elements_; }
8085 size_t RhsSize() const { return num_matchers_; }
8086 bool HasEdge(size_t ilhs, size_t irhs) const {
8087 return matched_[SpaceIndex(ilhs, irhs)] == 1;
8088 }
8089 void SetEdge(size_t ilhs, size_t irhs, bool b) {
8090 matched_[SpaceIndex(ilhs, irhs)] = b ? 1 : 0;
8091 }
8092
8093 // Treating the connectivity matrix as a (LhsSize()*RhsSize())-bit number,
8094 // adds 1 to that number; returns false if incrementing the graph left it
8095 // empty.
8096 bool NextGraph();
8097
8098 void Randomize();
8099
8100 string DebugString() const;
8101
8102 private:
8103 size_t SpaceIndex(size_t ilhs, size_t irhs) const {
8104 return ilhs * num_matchers_ + irhs;
8105 }
8106
8107 size_t num_elements_;
8108 size_t num_matchers_;
8109
8110 // Each element is a char interpreted as bool. They are stored as a
8111 // flattened array in lhs-major order, use 'SpaceIndex()' to translate
8112 // a (ilhs, irhs) matrix coordinate into an offset.
8113 ::std::vector<char> matched_;
8114};
8115
8116typedef ::std::pair<size_t, size_t> ElementMatcherPair;
8117typedef ::std::vector<ElementMatcherPair> ElementMatcherPairs;
8118
8119// Returns a maximum bipartite matching for the specified graph 'g'.
8120// The matching is represented as a vector of {element, matcher} pairs.
8121GTEST_API_ ElementMatcherPairs
8122FindMaxBipartiteMatching(const MatchMatrix& g);
8123
8124GTEST_API_ bool FindPairing(const MatchMatrix& matrix,
8125 MatchResultListener* listener);
8126
8127// Untyped base class for implementing UnorderedElementsAre. By
8128// putting logic that's not specific to the element type here, we
8129// reduce binary bloat and increase compilation speed.
8130class GTEST_API_ UnorderedElementsAreMatcherImplBase {
8131 protected:
8132 // A vector of matcher describers, one for each element matcher.
8133 // Does not own the describers (and thus can be used only when the
8134 // element matchers are alive).
8135 typedef ::std::vector<const MatcherDescriberInterface*> MatcherDescriberVec;
8136
8137 // Describes this UnorderedElementsAre matcher.
8138 void DescribeToImpl(::std::ostream* os) const;
8139
8140 // Describes the negation of this UnorderedElementsAre matcher.
8141 void DescribeNegationToImpl(::std::ostream* os) const;
8142
8143 bool VerifyAllElementsAndMatchersAreMatched(
8144 const ::std::vector<string>& element_printouts,
8145 const MatchMatrix& matrix,
8146 MatchResultListener* listener) const;
8147
8148 MatcherDescriberVec& matcher_describers() {
8149 return matcher_describers_;
8150 }
8151
8152 static Message Elements(size_t n) {
8153 return Message() << n << " element" << (n == 1 ? "" : "s");
8154 }
8155
8156 private:
8157 MatcherDescriberVec matcher_describers_;
8158
8159 GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreMatcherImplBase);
8160};
8161
8162// Implements unordered ElementsAre and unordered ElementsAreArray.
8163template <typename Container>
8164class UnorderedElementsAreMatcherImpl
8165 : public MatcherInterface<Container>,
8166 public UnorderedElementsAreMatcherImplBase {
8167 public:
8168 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
8169 typedef internal::StlContainerView<RawContainer> View;
8170 typedef typename View::type StlContainer;
8171 typedef typename View::const_reference StlContainerReference;
8172 typedef typename StlContainer::const_iterator StlContainerConstIterator;
8173 typedef typename StlContainer::value_type Element;
8174
8175 // Constructs the matcher from a sequence of element values or
8176 // element matchers.
8177 template <typename InputIter>
8178 UnorderedElementsAreMatcherImpl(InputIter first, InputIter last) {
8179 for (; first != last; ++first) {
8180 matchers_.push_back(MatcherCast<const Element&>(*first));
8181 matcher_describers().push_back(matchers_.back().GetDescriber());
8182 }
8183 }
8184
8185 // Describes what this matcher does.
8186 virtual void DescribeTo(::std::ostream* os) const {
8187 return UnorderedElementsAreMatcherImplBase::DescribeToImpl(os);
8188 }
8189
8190 // Describes what the negation of this matcher does.
8191 virtual void DescribeNegationTo(::std::ostream* os) const {
8192 return UnorderedElementsAreMatcherImplBase::DescribeNegationToImpl(os);
8193 }
8194
8195 virtual bool MatchAndExplain(Container container,
8196 MatchResultListener* listener) const {
8197 StlContainerReference stl_container = View::ConstReference(container);
8198 ::std::vector<string> element_printouts;
8199 MatchMatrix matrix = AnalyzeElements(stl_container.begin(),
8200 stl_container.end(),
8201 &element_printouts,
8202 listener);
8203
8204 const size_t actual_count = matrix.LhsSize();
8205 if (actual_count == 0 && matchers_.empty()) {
8206 return true;
8207 }
8208 if (actual_count != matchers_.size()) {
8209 // The element count doesn't match. If the container is empty,
8210 // there's no need to explain anything as Google Mock already
8211 // prints the empty container. Otherwise we just need to show
8212 // how many elements there actually are.
8213 if (actual_count != 0 && listener->IsInterested()) {
8214 *listener << "which has " << Elements(actual_count);
8215 }
8216 return false;
8217 }
8218
8219 return VerifyAllElementsAndMatchersAreMatched(element_printouts,
8220 matrix, listener) &&
8221 FindPairing(matrix, listener);
8222 }
8223
8224 private:
8225 typedef ::std::vector<Matcher<const Element&> > MatcherVec;
8226
8227 template <typename ElementIter>
8228 MatchMatrix AnalyzeElements(ElementIter elem_first, ElementIter elem_last,
8229 ::std::vector<string>* element_printouts,
8230 MatchResultListener* listener) const {
8231 element_printouts->clear();
8232 ::std::vector<char> did_match;
8233 size_t num_elements = 0;
8234 for (; elem_first != elem_last; ++num_elements, ++elem_first) {
8235 if (listener->IsInterested()) {
8236 element_printouts->push_back(PrintToString(*elem_first));
8237 }
8238 for (size_t irhs = 0; irhs != matchers_.size(); ++irhs) {
8239 did_match.push_back(Matches(matchers_[irhs])(*elem_first));
8240 }
8241 }
8242
8243 MatchMatrix matrix(num_elements, matchers_.size());
8244 ::std::vector<char>::const_iterator did_match_iter = did_match.begin();
8245 for (size_t ilhs = 0; ilhs != num_elements; ++ilhs) {
8246 for (size_t irhs = 0; irhs != matchers_.size(); ++irhs) {
8247 matrix.SetEdge(ilhs, irhs, *did_match_iter++ != 0);
8248 }
8249 }
8250 return matrix;
8251 }
8252
8253 MatcherVec matchers_;
8254
8255 GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreMatcherImpl);
8256};
8257
8258// Functor for use in TransformTuple.
8259// Performs MatcherCast<Target> on an input argument of any type.
8260template <typename Target>
8261struct CastAndAppendTransform {
8262 template <typename Arg>
8263 Matcher<Target> operator()(const Arg& a) const {
8264 return MatcherCast<Target>(a);
8265 }
8266};
8267
8268// Implements UnorderedElementsAre.
8269template <typename MatcherTuple>
8270class UnorderedElementsAreMatcher {
8271 public:
8272 explicit UnorderedElementsAreMatcher(const MatcherTuple& args)
8273 : matchers_(args) {}
8274
8275 template <typename Container>
8276 operator Matcher<Container>() const {
8277 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
8278 typedef typename internal::StlContainerView<RawContainer>::type View;
8279 typedef typename View::value_type Element;
8280 typedef ::std::vector<Matcher<const Element&> > MatcherVec;
8281 MatcherVec matchers;
8282 matchers.reserve(::testing::tuple_size<MatcherTuple>::value);
8283 TransformTupleValues(CastAndAppendTransform<const Element&>(), matchers_,
8284 ::std::back_inserter(matchers));
8285 return MakeMatcher(new UnorderedElementsAreMatcherImpl<Container>(
8286 matchers.begin(), matchers.end()));
8287 }
8288
8289 private:
8290 const MatcherTuple matchers_;
8291 GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreMatcher);
8292};
8293
8294// Implements ElementsAre.
8295template <typename MatcherTuple>
8296class ElementsAreMatcher {
8297 public:
8298 explicit ElementsAreMatcher(const MatcherTuple& args) : matchers_(args) {}
8299
8300 template <typename Container>
8301 operator Matcher<Container>() const {
8302 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
8303 typedef typename internal::StlContainerView<RawContainer>::type View;
8304 typedef typename View::value_type Element;
8305 typedef ::std::vector<Matcher<const Element&> > MatcherVec;
8306 MatcherVec matchers;
8307 matchers.reserve(::testing::tuple_size<MatcherTuple>::value);
8308 TransformTupleValues(CastAndAppendTransform<const Element&>(), matchers_,
8309 ::std::back_inserter(matchers));
8310 return MakeMatcher(new ElementsAreMatcherImpl<Container>(
8311 matchers.begin(), matchers.end()));
8312 }
8313
8314 private:
8315 const MatcherTuple matchers_;
8316 GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher);
8317};
8318
8319// Implements UnorderedElementsAreArray().
8320template <typename T>
8321class UnorderedElementsAreArrayMatcher {
8322 public:
8323 UnorderedElementsAreArrayMatcher() {}
8324
8325 template <typename Iter>
8326 UnorderedElementsAreArrayMatcher(Iter first, Iter last)
8327 : matchers_(first, last) {}
8328
8329 template <typename Container>
8330 operator Matcher<Container>() const {
8331 return MakeMatcher(
8332 new UnorderedElementsAreMatcherImpl<Container>(matchers_.begin(),
8333 matchers_.end()));
8334 }
8335
8336 private:
8337 ::std::vector<T> matchers_;
8338
8339 GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreArrayMatcher);
8340};
8341
8342// Implements ElementsAreArray().
8343template <typename T>
8344class ElementsAreArrayMatcher {
8345 public:
8346 template <typename Iter>
8347 ElementsAreArrayMatcher(Iter first, Iter last) : matchers_(first, last) {}
8348
8349 template <typename Container>
8350 operator Matcher<Container>() const {
8351 return MakeMatcher(new ElementsAreMatcherImpl<Container>(
8352 matchers_.begin(), matchers_.end()));
8353 }
8354
8355 private:
8356 const ::std::vector<T> matchers_;
8357
8358 GTEST_DISALLOW_ASSIGN_(ElementsAreArrayMatcher);
8359};
8360
8361// Given a 2-tuple matcher tm of type Tuple2Matcher and a value second
8362// of type Second, BoundSecondMatcher<Tuple2Matcher, Second>(tm,
8363// second) is a polymorphic matcher that matches a value x iff tm
8364// matches tuple (x, second). Useful for implementing
8365// UnorderedPointwise() in terms of UnorderedElementsAreArray().
8366//
8367// BoundSecondMatcher is copyable and assignable, as we need to put
8368// instances of this class in a vector when implementing
8369// UnorderedPointwise().
8370template <typename Tuple2Matcher, typename Second>
8371class BoundSecondMatcher {
8372 public:
8373 BoundSecondMatcher(const Tuple2Matcher& tm, const Second& second)
8374 : tuple2_matcher_(tm), second_value_(second) {}
8375
8376 template <typename T>
8377 operator Matcher<T>() const {
8378 return MakeMatcher(new Impl<T>(tuple2_matcher_, second_value_));
8379 }
8380
8381 // We have to define this for UnorderedPointwise() to compile in
8382 // C++98 mode, as it puts BoundSecondMatcher instances in a vector,
8383 // which requires the elements to be assignable in C++98. The
8384 // compiler cannot generate the operator= for us, as Tuple2Matcher
8385 // and Second may not be assignable.
8386 //
8387 // However, this should never be called, so the implementation just
8388 // need to assert.
8389 void operator=(const BoundSecondMatcher& /*rhs*/) {
8390 GTEST_LOG_(FATAL) << "BoundSecondMatcher should never be assigned.";
8391 }
8392
8393 private:
8394 template <typename T>
8395 class Impl : public MatcherInterface<T> {
8396 public:
8397 typedef ::testing::tuple<T, Second> ArgTuple;
8398
8399 Impl(const Tuple2Matcher& tm, const Second& second)
8400 : mono_tuple2_matcher_(SafeMatcherCast<const ArgTuple&>(tm)),
8401 second_value_(second) {}
8402
8403 virtual void DescribeTo(::std::ostream* os) const {
8404 *os << "and ";
8405 UniversalPrint(second_value_, os);
8406 *os << " ";
8407 mono_tuple2_matcher_.DescribeTo(os);
8408 }
8409
8410 virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
8411 return mono_tuple2_matcher_.MatchAndExplain(ArgTuple(x, second_value_),
8412 listener);
8413 }
8414
8415 private:
8416 const Matcher<const ArgTuple&> mono_tuple2_matcher_;
8417 const Second second_value_;
8418
8419 GTEST_DISALLOW_ASSIGN_(Impl);
8420 };
8421
8422 const Tuple2Matcher tuple2_matcher_;
8423 const Second second_value_;
8424};
8425
8426// Given a 2-tuple matcher tm and a value second,
8427// MatcherBindSecond(tm, second) returns a matcher that matches a
8428// value x iff tm matches tuple (x, second). Useful for implementing
8429// UnorderedPointwise() in terms of UnorderedElementsAreArray().
8430template <typename Tuple2Matcher, typename Second>
8431BoundSecondMatcher<Tuple2Matcher, Second> MatcherBindSecond(
8432 const Tuple2Matcher& tm, const Second& second) {
8433 return BoundSecondMatcher<Tuple2Matcher, Second>(tm, second);
8434}
8435
8436// Returns the description for a matcher defined using the MATCHER*()
8437// macro where the user-supplied description string is "", if
8438// 'negation' is false; otherwise returns the description of the
8439// negation of the matcher. 'param_values' contains a list of strings
8440// that are the print-out of the matcher's parameters.
8441GTEST_API_ string FormatMatcherDescription(bool negation,
8442 const char* matcher_name,
8443 const Strings& param_values);
8444
8445} // namespace internal
8446
8447// ElementsAreArray(first, last)
8448// ElementsAreArray(pointer, count)
8449// ElementsAreArray(array)
8450// ElementsAreArray(container)
8451// ElementsAreArray({ e1, e2, ..., en })
8452//
8453// The ElementsAreArray() functions are like ElementsAre(...), except
8454// that they are given a homogeneous sequence rather than taking each
8455// element as a function argument. The sequence can be specified as an
8456// array, a pointer and count, a vector, an initializer list, or an
8457// STL iterator range. In each of these cases, the underlying sequence
8458// can be either a sequence of values or a sequence of matchers.
8459//
8460// All forms of ElementsAreArray() make a copy of the input matcher sequence.
8461
8462template <typename Iter>
8463inline internal::ElementsAreArrayMatcher<
8464 typename ::std::iterator_traits<Iter>::value_type>
8465ElementsAreArray(Iter first, Iter last) {
8466 typedef typename ::std::iterator_traits<Iter>::value_type T;
8467 return internal::ElementsAreArrayMatcher<T>(first, last);
8468}
8469
8470template <typename T>
8471inline internal::ElementsAreArrayMatcher<T> ElementsAreArray(
8472 const T* pointer, size_t count) {
8473 return ElementsAreArray(pointer, pointer + count);
8474}
8475
8476template <typename T, size_t N>
8477inline internal::ElementsAreArrayMatcher<T> ElementsAreArray(
8478 const T (&array)[N]) {
8479 return ElementsAreArray(array, N);
8480}
8481
8482template <typename Container>
8483inline internal::ElementsAreArrayMatcher<typename Container::value_type>
8484ElementsAreArray(const Container& container) {
8485 return ElementsAreArray(container.begin(), container.end());
8486}
8487
8488#if GTEST_HAS_STD_INITIALIZER_LIST_
8489template <typename T>
8490inline internal::ElementsAreArrayMatcher<T>
8491ElementsAreArray(::std::initializer_list<T> xs) {
8492 return ElementsAreArray(xs.begin(), xs.end());
8493}
8494#endif
8495
8496// UnorderedElementsAreArray(first, last)
8497// UnorderedElementsAreArray(pointer, count)
8498// UnorderedElementsAreArray(array)
8499// UnorderedElementsAreArray(container)
8500// UnorderedElementsAreArray({ e1, e2, ..., en })
8501//
8502// The UnorderedElementsAreArray() functions are like
8503// ElementsAreArray(...), but allow matching the elements in any order.
8504template <typename Iter>
8505inline internal::UnorderedElementsAreArrayMatcher<
8506 typename ::std::iterator_traits<Iter>::value_type>
8507UnorderedElementsAreArray(Iter first, Iter last) {
8508 typedef typename ::std::iterator_traits<Iter>::value_type T;
8509 return internal::UnorderedElementsAreArrayMatcher<T>(first, last);
8510}
8511
8512template <typename T>
8513inline internal::UnorderedElementsAreArrayMatcher<T>
8514UnorderedElementsAreArray(const T* pointer, size_t count) {
8515 return UnorderedElementsAreArray(pointer, pointer + count);
8516}
8517
8518template <typename T, size_t N>
8519inline internal::UnorderedElementsAreArrayMatcher<T>
8520UnorderedElementsAreArray(const T (&array)[N]) {
8521 return UnorderedElementsAreArray(array, N);
8522}
8523
8524template <typename Container>
8525inline internal::UnorderedElementsAreArrayMatcher<
8526 typename Container::value_type>
8527UnorderedElementsAreArray(const Container& container) {
8528 return UnorderedElementsAreArray(container.begin(), container.end());
8529}
8530
8531#if GTEST_HAS_STD_INITIALIZER_LIST_
8532template <typename T>
8533inline internal::UnorderedElementsAreArrayMatcher<T>
8534UnorderedElementsAreArray(::std::initializer_list<T> xs) {
8535 return UnorderedElementsAreArray(xs.begin(), xs.end());
8536}
8537#endif
8538
8539// _ is a matcher that matches anything of any type.
8540//
8541// This definition is fine as:
8542//
8543// 1. The C++ standard permits using the name _ in a namespace that
8544// is not the global namespace or ::std.
8545// 2. The AnythingMatcher class has no data member or constructor,
8546// so it's OK to create global variables of this type.
8547// 3. c-style has approved of using _ in this case.
8548const internal::AnythingMatcher _ = {};
8549// Creates a matcher that matches any value of the given type T.
8550template <typename T>
8551inline Matcher<T> A() { return MakeMatcher(new internal::AnyMatcherImpl<T>()); }
8552
8553// Creates a matcher that matches any value of the given type T.
8554template <typename T>
8555inline Matcher<T> An() { return A<T>(); }
8556
8557// Creates a polymorphic matcher that matches anything equal to x.
8558// Note: if the parameter of Eq() were declared as const T&, Eq("foo")
8559// wouldn't compile.
8560template <typename T>
8561inline internal::EqMatcher<T> Eq(T x) { return internal::EqMatcher<T>(x); }
8562
8563// Constructs a Matcher<T> from a 'value' of type T. The constructed
8564// matcher matches any value that's equal to 'value'.
8565template <typename T>
8566Matcher<T>::Matcher(T value) { *this = Eq(value); }
8567
8568// Creates a monomorphic matcher that matches anything with type Lhs
8569// and equal to rhs. A user may need to use this instead of Eq(...)
8570// in order to resolve an overloading ambiguity.
8571//
8572// TypedEq<T>(x) is just a convenient short-hand for Matcher<T>(Eq(x))
8573// or Matcher<T>(x), but more readable than the latter.
8574//
8575// We could define similar monomorphic matchers for other comparison
8576// operations (e.g. TypedLt, TypedGe, and etc), but decided not to do
8577// it yet as those are used much less than Eq() in practice. A user
8578// can always write Matcher<T>(Lt(5)) to be explicit about the type,
8579// for example.
8580template <typename Lhs, typename Rhs>
8581inline Matcher<Lhs> TypedEq(const Rhs& rhs) { return Eq(rhs); }
8582
8583// Creates a polymorphic matcher that matches anything >= x.
8584template <typename Rhs>
8585inline internal::GeMatcher<Rhs> Ge(Rhs x) {
8586 return internal::GeMatcher<Rhs>(x);
8587}
8588
8589// Creates a polymorphic matcher that matches anything > x.
8590template <typename Rhs>
8591inline internal::GtMatcher<Rhs> Gt(Rhs x) {
8592 return internal::GtMatcher<Rhs>(x);
8593}
8594
8595// Creates a polymorphic matcher that matches anything <= x.
8596template <typename Rhs>
8597inline internal::LeMatcher<Rhs> Le(Rhs x) {
8598 return internal::LeMatcher<Rhs>(x);
8599}
8600
8601// Creates a polymorphic matcher that matches anything < x.
8602template <typename Rhs>
8603inline internal::LtMatcher<Rhs> Lt(Rhs x) {
8604 return internal::LtMatcher<Rhs>(x);
8605}
8606
8607// Creates a polymorphic matcher that matches anything != x.
8608template <typename Rhs>
8609inline internal::NeMatcher<Rhs> Ne(Rhs x) {
8610 return internal::NeMatcher<Rhs>(x);
8611}
8612
8613// Creates a polymorphic matcher that matches any NULL pointer.
8614inline PolymorphicMatcher<internal::IsNullMatcher > IsNull() {
8615 return MakePolymorphicMatcher(internal::IsNullMatcher());
8616}
8617
8618// Creates a polymorphic matcher that matches any non-NULL pointer.
8619// This is convenient as Not(NULL) doesn't compile (the compiler
8620// thinks that that expression is comparing a pointer with an integer).
8621inline PolymorphicMatcher<internal::NotNullMatcher > NotNull() {
8622 return MakePolymorphicMatcher(internal::NotNullMatcher());
8623}
8624
8625// Creates a polymorphic matcher that matches any argument that
8626// references variable x.
8627template <typename T>
8628inline internal::RefMatcher<T&> Ref(T& x) { // NOLINT
8629 return internal::RefMatcher<T&>(x);
8630}
8631
8632// Creates a matcher that matches any double argument approximately
8633// equal to rhs, where two NANs are considered unequal.
8634inline internal::FloatingEqMatcher<double> DoubleEq(double rhs) {
8635 return internal::FloatingEqMatcher<double>(rhs, false);
8636}
8637
8638// Creates a matcher that matches any double argument approximately
8639// equal to rhs, including NaN values when rhs is NaN.
8640inline internal::FloatingEqMatcher<double> NanSensitiveDoubleEq(double rhs) {
8641 return internal::FloatingEqMatcher<double>(rhs, true);
8642}
8643
8644// Creates a matcher that matches any double argument approximately equal to
8645// rhs, up to the specified max absolute error bound, where two NANs are
8646// considered unequal. The max absolute error bound must be non-negative.
8647inline internal::FloatingEqMatcher<double> DoubleNear(
8648 double rhs, double max_abs_error) {
8649 return internal::FloatingEqMatcher<double>(rhs, false, max_abs_error);
8650}
8651
8652// Creates a matcher that matches any double argument approximately equal to
8653// rhs, up to the specified max absolute error bound, including NaN values when
8654// rhs is NaN. The max absolute error bound must be non-negative.
8655inline internal::FloatingEqMatcher<double> NanSensitiveDoubleNear(
8656 double rhs, double max_abs_error) {
8657 return internal::FloatingEqMatcher<double>(rhs, true, max_abs_error);
8658}
8659
8660// Creates a matcher that matches any float argument approximately
8661// equal to rhs, where two NANs are considered unequal.
8662inline internal::FloatingEqMatcher<float> FloatEq(float rhs) {
8663 return internal::FloatingEqMatcher<float>(rhs, false);
8664}
8665
8666// Creates a matcher that matches any float argument approximately
8667// equal to rhs, including NaN values when rhs is NaN.
8668inline internal::FloatingEqMatcher<float> NanSensitiveFloatEq(float rhs) {
8669 return internal::FloatingEqMatcher<float>(rhs, true);
8670}
8671
8672// Creates a matcher that matches any float argument approximately equal to
8673// rhs, up to the specified max absolute error bound, where two NANs are
8674// considered unequal. The max absolute error bound must be non-negative.
8675inline internal::FloatingEqMatcher<float> FloatNear(
8676 float rhs, float max_abs_error) {
8677 return internal::FloatingEqMatcher<float>(rhs, false, max_abs_error);
8678}
8679
8680// Creates a matcher that matches any float argument approximately equal to
8681// rhs, up to the specified max absolute error bound, including NaN values when
8682// rhs is NaN. The max absolute error bound must be non-negative.
8683inline internal::FloatingEqMatcher<float> NanSensitiveFloatNear(
8684 float rhs, float max_abs_error) {
8685 return internal::FloatingEqMatcher<float>(rhs, true, max_abs_error);
8686}
8687
8688// Creates a matcher that matches a pointer (raw or smart) that points
8689// to a value that matches inner_matcher.
8690template <typename InnerMatcher>
8691inline internal::PointeeMatcher<InnerMatcher> Pointee(
8692 const InnerMatcher& inner_matcher) {
8693 return internal::PointeeMatcher<InnerMatcher>(inner_matcher);
8694}
8695
8696// Creates a matcher that matches a pointer or reference that matches
8697// inner_matcher when dynamic_cast<To> is applied.
8698// The result of dynamic_cast<To> is forwarded to the inner matcher.
8699// If To is a pointer and the cast fails, the inner matcher will receive NULL.
8700// If To is a reference and the cast fails, this matcher returns false
8701// immediately.
8702template <typename To>
8703inline PolymorphicMatcher<internal::WhenDynamicCastToMatcher<To> >
8704WhenDynamicCastTo(const Matcher<To>& inner_matcher) {
8705 return MakePolymorphicMatcher(
8706 internal::WhenDynamicCastToMatcher<To>(inner_matcher));
8707}
8708
8709// Creates a matcher that matches an object whose given field matches
8710// 'matcher'. For example,
8711// Field(&Foo::number, Ge(5))
8712// matches a Foo object x iff x.number >= 5.
8713template <typename Class, typename FieldType, typename FieldMatcher>
8714inline PolymorphicMatcher<
8715 internal::FieldMatcher<Class, FieldType> > Field(
8716 FieldType Class::*field, const FieldMatcher& matcher) {
8717 return MakePolymorphicMatcher(
8718 internal::FieldMatcher<Class, FieldType>(
8719 field, MatcherCast<const FieldType&>(matcher)));
8720 // The call to MatcherCast() is required for supporting inner
8721 // matchers of compatible types. For example, it allows
8722 // Field(&Foo::bar, m)
8723 // to compile where bar is an int32 and m is a matcher for int64.
8724}
8725
8726// Creates a matcher that matches an object whose given property
8727// matches 'matcher'. For example,
8728// Property(&Foo::str, StartsWith("hi"))
8729// matches a Foo object x iff x.str() starts with "hi".
8730template <typename Class, typename PropertyType, typename PropertyMatcher>
8731inline PolymorphicMatcher<
8732 internal::PropertyMatcher<Class, PropertyType> > Property(
8733 PropertyType (Class::*property)() const, const PropertyMatcher& matcher) {
8734 return MakePolymorphicMatcher(
8735 internal::PropertyMatcher<Class, PropertyType>(
8736 property,
8737 MatcherCast<GTEST_REFERENCE_TO_CONST_(PropertyType)>(matcher)));
8738 // The call to MatcherCast() is required for supporting inner
8739 // matchers of compatible types. For example, it allows
8740 // Property(&Foo::bar, m)
8741 // to compile where bar() returns an int32 and m is a matcher for int64.
8742}
8743
8744// Creates a matcher that matches an object iff the result of applying
8745// a callable to x matches 'matcher'.
8746// For example,
8747// ResultOf(f, StartsWith("hi"))
8748// matches a Foo object x iff f(x) starts with "hi".
8749// callable parameter can be a function, function pointer, or a functor.
8750// Callable has to satisfy the following conditions:
8751// * It is required to keep no state affecting the results of
8752// the calls on it and make no assumptions about how many calls
8753// will be made. Any state it keeps must be protected from the
8754// concurrent access.
8755// * If it is a function object, it has to define type result_type.
8756// We recommend deriving your functor classes from std::unary_function.
8757template <typename Callable, typename ResultOfMatcher>
8758internal::ResultOfMatcher<Callable> ResultOf(
8759 Callable callable, const ResultOfMatcher& matcher) {
8760 return internal::ResultOfMatcher<Callable>(
8761 callable,
8762 MatcherCast<typename internal::CallableTraits<Callable>::ResultType>(
8763 matcher));
8764 // The call to MatcherCast() is required for supporting inner
8765 // matchers of compatible types. For example, it allows
8766 // ResultOf(Function, m)
8767 // to compile where Function() returns an int32 and m is a matcher for int64.
8768}
8769
8770// String matchers.
8771
8772// Matches a string equal to str.
8773inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> >
8774 StrEq(const internal::string& str) {
8775 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>(
8776 str, true, true));
8777}
8778
8779// Matches a string not equal to str.
8780inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> >
8781 StrNe(const internal::string& str) {
8782 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>(
8783 str, false, true));
8784}
8785
8786// Matches a string equal to str, ignoring case.
8787inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> >
8788 StrCaseEq(const internal::string& str) {
8789 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>(
8790 str, true, false));
8791}
8792
8793// Matches a string not equal to str, ignoring case.
8794inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> >
8795 StrCaseNe(const internal::string& str) {
8796 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>(
8797 str, false, false));
8798}
8799
8800// Creates a matcher that matches any string, std::string, or C string
8801// that contains the given substring.
8802inline PolymorphicMatcher<internal::HasSubstrMatcher<internal::string> >
8803 HasSubstr(const internal::string& substring) {
8804 return MakePolymorphicMatcher(internal::HasSubstrMatcher<internal::string>(
8805 substring));
8806}
8807
8808// Matches a string that starts with 'prefix' (case-sensitive).
8809inline PolymorphicMatcher<internal::StartsWithMatcher<internal::string> >
8810 StartsWith(const internal::string& prefix) {
8811 return MakePolymorphicMatcher(internal::StartsWithMatcher<internal::string>(
8812 prefix));
8813}
8814
8815// Matches a string that ends with 'suffix' (case-sensitive).
8816inline PolymorphicMatcher<internal::EndsWithMatcher<internal::string> >
8817 EndsWith(const internal::string& suffix) {
8818 return MakePolymorphicMatcher(internal::EndsWithMatcher<internal::string>(
8819 suffix));
8820}
8821
8822// Matches a string that fully matches regular expression 'regex'.
8823// The matcher takes ownership of 'regex'.
8824inline PolymorphicMatcher<internal::MatchesRegexMatcher> MatchesRegex(
8825 const internal::RE* regex) {
8826 return MakePolymorphicMatcher(internal::MatchesRegexMatcher(regex, true));
8827}
8828inline PolymorphicMatcher<internal::MatchesRegexMatcher> MatchesRegex(
8829 const internal::string& regex) {
8830 return MatchesRegex(new internal::RE(regex));
8831}
8832
8833// Matches a string that contains regular expression 'regex'.
8834// The matcher takes ownership of 'regex'.
8835inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex(
8836 const internal::RE* regex) {
8837 return MakePolymorphicMatcher(internal::MatchesRegexMatcher(regex, false));
8838}
8839inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex(
8840 const internal::string& regex) {
8841 return ContainsRegex(new internal::RE(regex));
8842}
8843
8844#if GTEST_HAS_GLOBAL_WSTRING || GTEST_HAS_STD_WSTRING
8845// Wide string matchers.
8846
8847// Matches a string equal to str.
8848inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> >
8849 StrEq(const internal::wstring& str) {
8850 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstring>(
8851 str, true, true));
8852}
8853
8854// Matches a string not equal to str.
8855inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> >
8856 StrNe(const internal::wstring& str) {
8857 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstring>(
8858 str, false, true));
8859}
8860
8861// Matches a string equal to str, ignoring case.
8862inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> >
8863 StrCaseEq(const internal::wstring& str) {
8864 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstring>(
8865 str, true, false));
8866}
8867
8868// Matches a string not equal to str, ignoring case.
8869inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> >
8870 StrCaseNe(const internal::wstring& str) {
8871 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstring>(
8872 str, false, false));
8873}
8874
8875// Creates a matcher that matches any wstring, std::wstring, or C wide string
8876// that contains the given substring.
8877inline PolymorphicMatcher<internal::HasSubstrMatcher<internal::wstring> >
8878 HasSubstr(const internal::wstring& substring) {
8879 return MakePolymorphicMatcher(internal::HasSubstrMatcher<internal::wstring>(
8880 substring));
8881}
8882
8883// Matches a string that starts with 'prefix' (case-sensitive).
8884inline PolymorphicMatcher<internal::StartsWithMatcher<internal::wstring> >
8885 StartsWith(const internal::wstring& prefix) {
8886 return MakePolymorphicMatcher(internal::StartsWithMatcher<internal::wstring>(
8887 prefix));
8888}
8889
8890// Matches a string that ends with 'suffix' (case-sensitive).
8891inline PolymorphicMatcher<internal::EndsWithMatcher<internal::wstring> >
8892 EndsWith(const internal::wstring& suffix) {
8893 return MakePolymorphicMatcher(internal::EndsWithMatcher<internal::wstring>(
8894 suffix));
8895}
8896
8897#endif // GTEST_HAS_GLOBAL_WSTRING || GTEST_HAS_STD_WSTRING
8898
8899// Creates a polymorphic matcher that matches a 2-tuple where the
8900// first field == the second field.
8901inline internal::Eq2Matcher Eq() { return internal::Eq2Matcher(); }
8902
8903// Creates a polymorphic matcher that matches a 2-tuple where the
8904// first field >= the second field.
8905inline internal::Ge2Matcher Ge() { return internal::Ge2Matcher(); }
8906
8907// Creates a polymorphic matcher that matches a 2-tuple where the
8908// first field > the second field.
8909inline internal::Gt2Matcher Gt() { return internal::Gt2Matcher(); }
8910
8911// Creates a polymorphic matcher that matches a 2-tuple where the
8912// first field <= the second field.
8913inline internal::Le2Matcher Le() { return internal::Le2Matcher(); }
8914
8915// Creates a polymorphic matcher that matches a 2-tuple where the
8916// first field < the second field.
8917inline internal::Lt2Matcher Lt() { return internal::Lt2Matcher(); }
8918
8919// Creates a polymorphic matcher that matches a 2-tuple where the
8920// first field != the second field.
8921inline internal::Ne2Matcher Ne() { return internal::Ne2Matcher(); }
8922
8923// Creates a matcher that matches any value of type T that m doesn't
8924// match.
8925template <typename InnerMatcher>
8926inline internal::NotMatcher<InnerMatcher> Not(InnerMatcher m) {
8927 return internal::NotMatcher<InnerMatcher>(m);
8928}
8929
8930// Returns a matcher that matches anything that satisfies the given
8931// predicate. The predicate can be any unary function or functor
8932// whose return type can be implicitly converted to bool.
8933template <typename Predicate>
8934inline PolymorphicMatcher<internal::TrulyMatcher<Predicate> >
8935Truly(Predicate pred) {
8936 return MakePolymorphicMatcher(internal::TrulyMatcher<Predicate>(pred));
8937}
8938
8939// Returns a matcher that matches the container size. The container must
8940// support both size() and size_type which all STL-like containers provide.
8941// Note that the parameter 'size' can be a value of type size_type as well as
8942// matcher. For instance:
8943// EXPECT_THAT(container, SizeIs(2)); // Checks container has 2 elements.
8944// EXPECT_THAT(container, SizeIs(Le(2)); // Checks container has at most 2.
8945template <typename SizeMatcher>
8946inline internal::SizeIsMatcher<SizeMatcher>
8947SizeIs(const SizeMatcher& size_matcher) {
8948 return internal::SizeIsMatcher<SizeMatcher>(size_matcher);
8949}
8950
8951// Returns a matcher that matches the distance between the container's begin()
8952// iterator and its end() iterator, i.e. the size of the container. This matcher
8953// can be used instead of SizeIs with containers such as std::forward_list which
8954// do not implement size(). The container must provide const_iterator (with
8955// valid iterator_traits), begin() and end().
8956template <typename DistanceMatcher>
8957inline internal::BeginEndDistanceIsMatcher<DistanceMatcher>
8958BeginEndDistanceIs(const DistanceMatcher& distance_matcher) {
8959 return internal::BeginEndDistanceIsMatcher<DistanceMatcher>(distance_matcher);
8960}
8961
8962// Returns a matcher that matches an equal container.
8963// This matcher behaves like Eq(), but in the event of mismatch lists the
8964// values that are included in one container but not the other. (Duplicate
8965// values and order differences are not explained.)
8966template <typename Container>
8967inline PolymorphicMatcher<internal::ContainerEqMatcher< // NOLINT
8968 GTEST_REMOVE_CONST_(Container)> >
8969 ContainerEq(const Container& rhs) {
8970 // This following line is for working around a bug in MSVC 8.0,
8971 // which causes Container to be a const type sometimes.
8972 typedef GTEST_REMOVE_CONST_(Container) RawContainer;
8973 return MakePolymorphicMatcher(
8974 internal::ContainerEqMatcher<RawContainer>(rhs));
8975}
8976
8977// Returns a matcher that matches a container that, when sorted using
8978// the given comparator, matches container_matcher.
8979template <typename Comparator, typename ContainerMatcher>
8980inline internal::WhenSortedByMatcher<Comparator, ContainerMatcher>
8981WhenSortedBy(const Comparator& comparator,
8982 const ContainerMatcher& container_matcher) {
8983 return internal::WhenSortedByMatcher<Comparator, ContainerMatcher>(
8984 comparator, container_matcher);
8985}
8986
8987// Returns a matcher that matches a container that, when sorted using
8988// the < operator, matches container_matcher.
8989template <typename ContainerMatcher>
8990inline internal::WhenSortedByMatcher<internal::LessComparator, ContainerMatcher>
8991WhenSorted(const ContainerMatcher& container_matcher) {
8992 return
8993 internal::WhenSortedByMatcher<internal::LessComparator, ContainerMatcher>(
8994 internal::LessComparator(), container_matcher);
8995}
8996
8997// Matches an STL-style container or a native array that contains the
8998// same number of elements as in rhs, where its i-th element and rhs's
8999// i-th element (as a pair) satisfy the given pair matcher, for all i.
9000// TupleMatcher must be able to be safely cast to Matcher<tuple<const
9001// T1&, const T2&> >, where T1 and T2 are the types of elements in the
9002// LHS container and the RHS container respectively.
9003template <typename TupleMatcher, typename Container>
9004inline internal::PointwiseMatcher<TupleMatcher,
9005 GTEST_REMOVE_CONST_(Container)>
9006Pointwise(const TupleMatcher& tuple_matcher, const Container& rhs) {
9007 // This following line is for working around a bug in MSVC 8.0,
9008 // which causes Container to be a const type sometimes (e.g. when
9009 // rhs is a const int[])..
9010 typedef GTEST_REMOVE_CONST_(Container) RawContainer;
9011 return internal::PointwiseMatcher<TupleMatcher, RawContainer>(
9012 tuple_matcher, rhs);
9013}
9014
9015#if GTEST_HAS_STD_INITIALIZER_LIST_
9016
9017// Supports the Pointwise(m, {a, b, c}) syntax.
9018template <typename TupleMatcher, typename T>
9019inline internal::PointwiseMatcher<TupleMatcher, std::vector<T> > Pointwise(
9020 const TupleMatcher& tuple_matcher, std::initializer_list<T> rhs) {
9021 return Pointwise(tuple_matcher, std::vector<T>(rhs));
9022}
9023
9024#endif // GTEST_HAS_STD_INITIALIZER_LIST_
9025
9026// UnorderedPointwise(pair_matcher, rhs) matches an STL-style
9027// container or a native array that contains the same number of
9028// elements as in rhs, where in some permutation of the container, its
9029// i-th element and rhs's i-th element (as a pair) satisfy the given
9030// pair matcher, for all i. Tuple2Matcher must be able to be safely
9031// cast to Matcher<tuple<const T1&, const T2&> >, where T1 and T2 are
9032// the types of elements in the LHS container and the RHS container
9033// respectively.
9034//
9035// This is like Pointwise(pair_matcher, rhs), except that the element
9036// order doesn't matter.
9037template <typename Tuple2Matcher, typename RhsContainer>
9038inline internal::UnorderedElementsAreArrayMatcher<
9039 typename internal::BoundSecondMatcher<
9040 Tuple2Matcher, typename internal::StlContainerView<GTEST_REMOVE_CONST_(
9041 RhsContainer)>::type::value_type> >
9042UnorderedPointwise(const Tuple2Matcher& tuple2_matcher,
9043 const RhsContainer& rhs_container) {
9044 // This following line is for working around a bug in MSVC 8.0,
9045 // which causes RhsContainer to be a const type sometimes (e.g. when
9046 // rhs_container is a const int[]).
9047 typedef GTEST_REMOVE_CONST_(RhsContainer) RawRhsContainer;
9048
9049 // RhsView allows the same code to handle RhsContainer being a
9050 // STL-style container and it being a native C-style array.
9051 typedef typename internal::StlContainerView<RawRhsContainer> RhsView;
9052 typedef typename RhsView::type RhsStlContainer;
9053 typedef typename RhsStlContainer::value_type Second;
9054 const RhsStlContainer& rhs_stl_container =
9055 RhsView::ConstReference(rhs_container);
9056
9057 // Create a matcher for each element in rhs_container.
9058 ::std::vector<internal::BoundSecondMatcher<Tuple2Matcher, Second> > matchers;
9059 for (typename RhsStlContainer::const_iterator it = rhs_stl_container.begin();
9060 it != rhs_stl_container.end(); ++it) {
9061 matchers.push_back(
9062 internal::MatcherBindSecond(tuple2_matcher, *it));
9063 }
9064
9065 // Delegate the work to UnorderedElementsAreArray().
9066 return UnorderedElementsAreArray(matchers);
9067}
9068
9069#if GTEST_HAS_STD_INITIALIZER_LIST_
9070
9071// Supports the UnorderedPointwise(m, {a, b, c}) syntax.
9072template <typename Tuple2Matcher, typename T>
9073inline internal::UnorderedElementsAreArrayMatcher<
9074 typename internal::BoundSecondMatcher<Tuple2Matcher, T> >
9075UnorderedPointwise(const Tuple2Matcher& tuple2_matcher,
9076 std::initializer_list<T> rhs) {
9077 return UnorderedPointwise(tuple2_matcher, std::vector<T>(rhs));
9078}
9079
9080#endif // GTEST_HAS_STD_INITIALIZER_LIST_
9081
9082// Matches an STL-style container or a native array that contains at
9083// least one element matching the given value or matcher.
9084//
9085// Examples:
9086// ::std::set<int> page_ids;
9087// page_ids.insert(3);
9088// page_ids.insert(1);
9089// EXPECT_THAT(page_ids, Contains(1));
9090// EXPECT_THAT(page_ids, Contains(Gt(2)));
9091// EXPECT_THAT(page_ids, Not(Contains(4)));
9092//
9093// ::std::map<int, size_t> page_lengths;
9094// page_lengths[1] = 100;
9095// EXPECT_THAT(page_lengths,
9096// Contains(::std::pair<const int, size_t>(1, 100)));
9097//
9098// const char* user_ids[] = { "joe", "mike", "tom" };
9099// EXPECT_THAT(user_ids, Contains(Eq(::std::string("tom"))));
9100template <typename M>
9101inline internal::ContainsMatcher<M> Contains(M matcher) {
9102 return internal::ContainsMatcher<M>(matcher);
9103}
9104
9105// Matches an STL-style container or a native array that contains only
9106// elements matching the given value or matcher.
9107//
9108// Each(m) is semantically equivalent to Not(Contains(Not(m))). Only
9109// the messages are different.
9110//
9111// Examples:
9112// ::std::set<int> page_ids;
9113// // Each(m) matches an empty container, regardless of what m is.
9114// EXPECT_THAT(page_ids, Each(Eq(1)));
9115// EXPECT_THAT(page_ids, Each(Eq(77)));
9116//
9117// page_ids.insert(3);
9118// EXPECT_THAT(page_ids, Each(Gt(0)));
9119// EXPECT_THAT(page_ids, Not(Each(Gt(4))));
9120// page_ids.insert(1);
9121// EXPECT_THAT(page_ids, Not(Each(Lt(2))));
9122//
9123// ::std::map<int, size_t> page_lengths;
9124// page_lengths[1] = 100;
9125// page_lengths[2] = 200;
9126// page_lengths[3] = 300;
9127// EXPECT_THAT(page_lengths, Not(Each(Pair(1, 100))));
9128// EXPECT_THAT(page_lengths, Each(Key(Le(3))));
9129//
9130// const char* user_ids[] = { "joe", "mike", "tom" };
9131// EXPECT_THAT(user_ids, Not(Each(Eq(::std::string("tom")))));
9132template <typename M>
9133inline internal::EachMatcher<M> Each(M matcher) {
9134 return internal::EachMatcher<M>(matcher);
9135}
9136
9137// Key(inner_matcher) matches an std::pair whose 'first' field matches
9138// inner_matcher. For example, Contains(Key(Ge(5))) can be used to match an
9139// std::map that contains at least one element whose key is >= 5.
9140template <typename M>
9141inline internal::KeyMatcher<M> Key(M inner_matcher) {
9142 return internal::KeyMatcher<M>(inner_matcher);
9143}
9144
9145// Pair(first_matcher, second_matcher) matches a std::pair whose 'first' field
9146// matches first_matcher and whose 'second' field matches second_matcher. For
9147// example, EXPECT_THAT(map_type, ElementsAre(Pair(Ge(5), "foo"))) can be used
9148// to match a std::map<int, string> that contains exactly one element whose key
9149// is >= 5 and whose value equals "foo".
9150template <typename FirstMatcher, typename SecondMatcher>
9151inline internal::PairMatcher<FirstMatcher, SecondMatcher>
9152Pair(FirstMatcher first_matcher, SecondMatcher second_matcher) {
9153 return internal::PairMatcher<FirstMatcher, SecondMatcher>(
9154 first_matcher, second_matcher);
9155}
9156
9157// Returns a predicate that is satisfied by anything that matches the
9158// given matcher.
9159template <typename M>
9160inline internal::MatcherAsPredicate<M> Matches(M matcher) {
9161 return internal::MatcherAsPredicate<M>(matcher);
9162}
9163
9164// Returns true iff the value matches the matcher.
9165template <typename T, typename M>
9166inline bool Value(const T& value, M matcher) {
9167 return testing::Matches(matcher)(value);
9168}
9169
9170// Matches the value against the given matcher and explains the match
9171// result to listener.
9172template <typename T, typename M>
9173inline bool ExplainMatchResult(
9174 M matcher, const T& value, MatchResultListener* listener) {
9175 return SafeMatcherCast<const T&>(matcher).MatchAndExplain(value, listener);
9176}
9177
9178#if GTEST_LANG_CXX11
9179// Define variadic matcher versions. They are overloaded in
9180// gmock-generated-matchers.h for the cases supported by pre C++11 compilers.
9181template <typename... Args>
9182inline internal::AllOfMatcher<Args...> AllOf(const Args&... matchers) {
9183 return internal::AllOfMatcher<Args...>(matchers...);
9184}
9185
9186template <typename... Args>
9187inline internal::AnyOfMatcher<Args...> AnyOf(const Args&... matchers) {
9188 return internal::AnyOfMatcher<Args...>(matchers...);
9189}
9190
9191#endif // GTEST_LANG_CXX11
9192
9193// AllArgs(m) is a synonym of m. This is useful in
9194//
9195// EXPECT_CALL(foo, Bar(_, _)).With(AllArgs(Eq()));
9196//
9197// which is easier to read than
9198//
9199// EXPECT_CALL(foo, Bar(_, _)).With(Eq());
9200template <typename InnerMatcher>
9201inline InnerMatcher AllArgs(const InnerMatcher& matcher) { return matcher; }
9202
9203// These macros allow using matchers to check values in Google Test
9204// tests. ASSERT_THAT(value, matcher) and EXPECT_THAT(value, matcher)
9205// succeed iff the value matches the matcher. If the assertion fails,
9206// the value and the description of the matcher will be printed.
9207#define ASSERT_THAT(value, matcher) ASSERT_PRED_FORMAT1(\
9208 ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value)
9209#define EXPECT_THAT(value, matcher) EXPECT_PRED_FORMAT1(\
9210 ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value)
9211
9212} // namespace testing
9213
9214// Include any custom callback matchers added by the local installation.
9215// We must include this header at the end to make sure it can use the
9216// declarations from this file.
9217// Copyright 2015, Google Inc.
9218// All rights reserved.
9219//
9220// Redistribution and use in source and binary forms, with or without
9221// modification, are permitted provided that the following conditions are
9222// met:
9223//
9224// * Redistributions of source code must retain the above copyright
9225// notice, this list of conditions and the following disclaimer.
9226// * Redistributions in binary form must reproduce the above
9227// copyright notice, this list of conditions and the following disclaimer
9228// in the documentation and/or other materials provided with the
9229// distribution.
9230// * Neither the name of Google Inc. nor the names of its
9231// contributors may be used to endorse or promote products derived from
9232// this software without specific prior written permission.
9233//
9234// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
9235// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
9236// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
9237// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9238// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9239// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9240// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
9241// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
9242// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
9243// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
9244// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9245//
9246// ============================================================
9247// An installation-specific extension point for gmock-matchers.h.
9248// ============================================================
9249//
9250// Adds google3 callback support to CallableTraits.
9251//
9252#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_CALLBACK_MATCHERS_H_
9253#define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_CALLBACK_MATCHERS_H_
9254
9255#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_CALLBACK_MATCHERS_H_
9256#endif // GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
9257
9258namespace testing {
9259
9260// An abstract handle of an expectation.
9261class Expectation;
9262
9263// A set of expectation handles.
9264class ExpectationSet;
9265
9266// Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION
9267// and MUST NOT BE USED IN USER CODE!!!
9268namespace internal {
9269
9270// Implements a mock function.
9271template <typename F> class FunctionMocker;
9272
9273// Base class for expectations.
9274class ExpectationBase;
9275
9276// Implements an expectation.
9277template <typename F> class TypedExpectation;
9278
9279// Helper class for testing the Expectation class template.
9280class ExpectationTester;
9281
9282// Base class for function mockers.
9283template <typename F> class FunctionMockerBase;
9284
9285// Protects the mock object registry (in class Mock), all function
9286// mockers, and all expectations.
9287//
9288// The reason we don't use more fine-grained protection is: when a
9289// mock function Foo() is called, it needs to consult its expectations
9290// to see which one should be picked. If another thread is allowed to
9291// call a mock function (either Foo() or a different one) at the same
9292// time, it could affect the "retired" attributes of Foo()'s
9293// expectations when InSequence() is used, and thus affect which
9294// expectation gets picked. Therefore, we sequence all mock function
9295// calls to ensure the integrity of the mock objects' states.
9296GTEST_API_ GTEST_DECLARE_STATIC_MUTEX_(g_gmock_mutex);
9297
9298// Untyped base class for ActionResultHolder<R>.
9299class UntypedActionResultHolderBase;
9300
9301// Abstract base class of FunctionMockerBase. This is the
9302// type-agnostic part of the function mocker interface. Its pure
9303// virtual methods are implemented by FunctionMockerBase.
9304class GTEST_API_ UntypedFunctionMockerBase {
9305 public:
9306 UntypedFunctionMockerBase();
9307 virtual ~UntypedFunctionMockerBase();
9308
9309 // Verifies that all expectations on this mock function have been
9310 // satisfied. Reports one or more Google Test non-fatal failures
9311 // and returns false if not.
9312 bool VerifyAndClearExpectationsLocked()
9313 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
9314
9315 // Clears the ON_CALL()s set on this mock function.
9316 virtual void ClearDefaultActionsLocked()
9317 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) = 0;
9318
9319 // In all of the following Untyped* functions, it's the caller's
9320 // responsibility to guarantee the correctness of the arguments'
9321 // types.
9322
9323 // Performs the default action with the given arguments and returns
9324 // the action's result. The call description string will be used in
9325 // the error message to describe the call in the case the default
9326 // action fails.
9327 // L = *
9328 virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction(
9329 const void* untyped_args,
9330 const string& call_description) const = 0;
9331
9332 // Performs the given action with the given arguments and returns
9333 // the action's result.
9334 // L = *
9335 virtual UntypedActionResultHolderBase* UntypedPerformAction(
9336 const void* untyped_action,
9337 const void* untyped_args) const = 0;
9338
9339 // Writes a message that the call is uninteresting (i.e. neither
9340 // explicitly expected nor explicitly unexpected) to the given
9341 // ostream.
9342 virtual void UntypedDescribeUninterestingCall(
9343 const void* untyped_args,
9344 ::std::ostream* os) const
9345 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) = 0;
9346
9347 // Returns the expectation that matches the given function arguments
9348 // (or NULL is there's no match); when a match is found,
9349 // untyped_action is set to point to the action that should be
9350 // performed (or NULL if the action is "do default"), and
9351 // is_excessive is modified to indicate whether the call exceeds the
9352 // expected number.
9353 virtual const ExpectationBase* UntypedFindMatchingExpectation(
9354 const void* untyped_args,
9355 const void** untyped_action, bool* is_excessive,
9356 ::std::ostream* what, ::std::ostream* why)
9357 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) = 0;
9358
9359 // Prints the given function arguments to the ostream.
9360 virtual void UntypedPrintArgs(const void* untyped_args,
9361 ::std::ostream* os) const = 0;
9362
9363 // Sets the mock object this mock method belongs to, and registers
9364 // this information in the global mock registry. Will be called
9365 // whenever an EXPECT_CALL() or ON_CALL() is executed on this mock
9366 // method.
9367 // TODO(wan@google.com): rename to SetAndRegisterOwner().
9368 void RegisterOwner(const void* mock_obj)
9369 GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
9370
9371 // Sets the mock object this mock method belongs to, and sets the
9372 // name of the mock function. Will be called upon each invocation
9373 // of this mock function.
9374 void SetOwnerAndName(const void* mock_obj, const char* name)
9375 GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
9376
9377 // Returns the mock object this mock method belongs to. Must be
9378 // called after RegisterOwner() or SetOwnerAndName() has been
9379 // called.
9380 const void* MockObject() const
9381 GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
9382
9383 // Returns the name of this mock method. Must be called after
9384 // SetOwnerAndName() has been called.
9385 const char* Name() const
9386 GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
9387
9388 // Returns the result of invoking this mock function with the given
9389 // arguments. This function can be safely called from multiple
9390 // threads concurrently. The caller is responsible for deleting the
9391 // result.
9392 UntypedActionResultHolderBase* UntypedInvokeWith(
9393 const void* untyped_args)
9394 GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
9395
9396 protected:
9397 typedef std::vector<const void*> UntypedOnCallSpecs;
9398
9399 typedef std::vector<internal::linked_ptr<ExpectationBase> >
9400 UntypedExpectations;
9401
9402 // Returns an Expectation object that references and co-owns exp,
9403 // which must be an expectation on this mock function.
9404 Expectation GetHandleOf(ExpectationBase* exp);
9405
9406 // Address of the mock object this mock method belongs to. Only
9407 // valid after this mock method has been called or
9408 // ON_CALL/EXPECT_CALL has been invoked on it.
9409 const void* mock_obj_; // Protected by g_gmock_mutex.
9410
9411 // Name of the function being mocked. Only valid after this mock
9412 // method has been called.
9413 const char* name_; // Protected by g_gmock_mutex.
9414
9415 // All default action specs for this function mocker.
9416 UntypedOnCallSpecs untyped_on_call_specs_;
9417
9418 // All expectations for this function mocker.
9419 UntypedExpectations untyped_expectations_;
9420}; // class UntypedFunctionMockerBase
9421
9422// Untyped base class for OnCallSpec<F>.
9423class UntypedOnCallSpecBase {
9424 public:
9425 // The arguments are the location of the ON_CALL() statement.
9426 UntypedOnCallSpecBase(const char* a_file, int a_line)
9427 : file_(a_file), line_(a_line), last_clause_(kNone) {}
9428
9429 // Where in the source file was the default action spec defined?
9430 const char* file() const { return file_; }
9431 int line() const { return line_; }
9432
9433 protected:
9434 // Gives each clause in the ON_CALL() statement a name.
9435 enum Clause {
9436 // Do not change the order of the enum members! The run-time
9437 // syntax checking relies on it.
9438 kNone,
9439 kWith,
9440 kWillByDefault
9441 };
9442
9443 // Asserts that the ON_CALL() statement has a certain property.
9444 void AssertSpecProperty(bool property, const string& failure_message) const {
9445 Assert(property, file_, line_, failure_message);
9446 }
9447
9448 // Expects that the ON_CALL() statement has a certain property.
9449 void ExpectSpecProperty(bool property, const string& failure_message) const {
9450 Expect(property, file_, line_, failure_message);
9451 }
9452
9453 const char* file_;
9454 int line_;
9455
9456 // The last clause in the ON_CALL() statement as seen so far.
9457 // Initially kNone and changes as the statement is parsed.
9458 Clause last_clause_;
9459}; // class UntypedOnCallSpecBase
9460
9461// This template class implements an ON_CALL spec.
9462template <typename F>
9463class OnCallSpec : public UntypedOnCallSpecBase {
9464 public:
9465 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
9466 typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple;
9467
9468 // Constructs an OnCallSpec object from the information inside
9469 // the parenthesis of an ON_CALL() statement.
9470 OnCallSpec(const char* a_file, int a_line,
9471 const ArgumentMatcherTuple& matchers)
9472 : UntypedOnCallSpecBase(a_file, a_line),
9473 matchers_(matchers),
9474 // By default, extra_matcher_ should match anything. However,
9475 // we cannot initialize it with _ as that triggers a compiler
9476 // bug in Symbian's C++ compiler (cannot decide between two
9477 // overloaded constructors of Matcher<const ArgumentTuple&>).
9478 extra_matcher_(A<const ArgumentTuple&>()) {
9479 }
9480
9481 // Implements the .With() clause.
9482 OnCallSpec& With(const Matcher<const ArgumentTuple&>& m) {
9483 // Makes sure this is called at most once.
9484 ExpectSpecProperty(last_clause_ < kWith,
9485 ".With() cannot appear "
9486 "more than once in an ON_CALL().");
9487 last_clause_ = kWith;
9488
9489 extra_matcher_ = m;
9490 return *this;
9491 }
9492
9493 // Implements the .WillByDefault() clause.
9494 OnCallSpec& WillByDefault(const Action<F>& action) {
9495 ExpectSpecProperty(last_clause_ < kWillByDefault,
9496 ".WillByDefault() must appear "
9497 "exactly once in an ON_CALL().");
9498 last_clause_ = kWillByDefault;
9499
9500 ExpectSpecProperty(!action.IsDoDefault(),
9501 "DoDefault() cannot be used in ON_CALL().");
9502 action_ = action;
9503 return *this;
9504 }
9505
9506 // Returns true iff the given arguments match the matchers.
9507 bool Matches(const ArgumentTuple& args) const {
9508 return TupleMatches(matchers_, args) && extra_matcher_.Matches(args);
9509 }
9510
9511 // Returns the action specified by the user.
9512 const Action<F>& GetAction() const {
9513 AssertSpecProperty(last_clause_ == kWillByDefault,
9514 ".WillByDefault() must appear exactly "
9515 "once in an ON_CALL().");
9516 return action_;
9517 }
9518
9519 private:
9520 // The information in statement
9521 //
9522 // ON_CALL(mock_object, Method(matchers))
9523 // .With(multi-argument-matcher)
9524 // .WillByDefault(action);
9525 //
9526 // is recorded in the data members like this:
9527 //
9528 // source file that contains the statement => file_
9529 // line number of the statement => line_
9530 // matchers => matchers_
9531 // multi-argument-matcher => extra_matcher_
9532 // action => action_
9533 ArgumentMatcherTuple matchers_;
9534 Matcher<const ArgumentTuple&> extra_matcher_;
9535 Action<F> action_;
9536}; // class OnCallSpec
9537
9538// Possible reactions on uninteresting calls.
9539enum CallReaction {
9540 kAllow,
9541 kWarn,
9542 kFail,
9543 kDefault = kWarn // By default, warn about uninteresting calls.
9544};
9545
9546} // namespace internal
9547
9548// Utilities for manipulating mock objects.
9549class GTEST_API_ Mock {
9550 public:
9551 // The following public methods can be called concurrently.
9552
9553 // Tells Google Mock to ignore mock_obj when checking for leaked
9554 // mock objects.
9555 static void AllowLeak(const void* mock_obj)
9556 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
9557
9558 // Verifies and clears all expectations on the given mock object.
9559 // If the expectations aren't satisfied, generates one or more
9560 // Google Test non-fatal failures and returns false.
9561 static bool VerifyAndClearExpectations(void* mock_obj)
9562 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
9563
9564 // Verifies all expectations on the given mock object and clears its
9565 // default actions and expectations. Returns true iff the
9566 // verification was successful.
9567 static bool VerifyAndClear(void* mock_obj)
9568 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
9569
9570 private:
9571 friend class internal::UntypedFunctionMockerBase;
9572
9573 // Needed for a function mocker to register itself (so that we know
9574 // how to clear a mock object).
9575 template <typename F>
9576 friend class internal::FunctionMockerBase;
9577
9578 template <typename M>
9579 friend class NiceMock;
9580
9581 template <typename M>
9582 friend class NaggyMock;
9583
9584 template <typename M>
9585 friend class StrictMock;
9586
9587 // Tells Google Mock to allow uninteresting calls on the given mock
9588 // object.
9589 static void AllowUninterestingCalls(const void* mock_obj)
9590 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
9591
9592 // Tells Google Mock to warn the user about uninteresting calls on
9593 // the given mock object.
9594 static void WarnUninterestingCalls(const void* mock_obj)
9595 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
9596
9597 // Tells Google Mock to fail uninteresting calls on the given mock
9598 // object.
9599 static void FailUninterestingCalls(const void* mock_obj)
9600 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
9601
9602 // Tells Google Mock the given mock object is being destroyed and
9603 // its entry in the call-reaction table should be removed.
9604 static void UnregisterCallReaction(const void* mock_obj)
9605 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
9606
9607 // Returns the reaction Google Mock will have on uninteresting calls
9608 // made on the given mock object.
9609 static internal::CallReaction GetReactionOnUninterestingCalls(
9610 const void* mock_obj)
9611 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
9612
9613 // Verifies that all expectations on the given mock object have been
9614 // satisfied. Reports one or more Google Test non-fatal failures
9615 // and returns false if not.
9616 static bool VerifyAndClearExpectationsLocked(void* mock_obj)
9617 GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex);
9618
9619 // Clears all ON_CALL()s set on the given mock object.
9620 static void ClearDefaultActionsLocked(void* mock_obj)
9621 GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex);
9622
9623 // Registers a mock object and a mock method it owns.
9624 static void Register(
9625 const void* mock_obj,
9626 internal::UntypedFunctionMockerBase* mocker)
9627 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
9628
9629 // Tells Google Mock where in the source code mock_obj is used in an
9630 // ON_CALL or EXPECT_CALL. In case mock_obj is leaked, this
9631 // information helps the user identify which object it is.
9632 static void RegisterUseByOnCallOrExpectCall(
9633 const void* mock_obj, const char* file, int line)
9634 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
9635
9636 // Unregisters a mock method; removes the owning mock object from
9637 // the registry when the last mock method associated with it has
9638 // been unregistered. This is called only in the destructor of
9639 // FunctionMockerBase.
9640 static void UnregisterLocked(internal::UntypedFunctionMockerBase* mocker)
9641 GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex);
9642}; // class Mock
9643
9644// An abstract handle of an expectation. Useful in the .After()
9645// clause of EXPECT_CALL() for setting the (partial) order of
9646// expectations. The syntax:
9647//
9648// Expectation e1 = EXPECT_CALL(...)...;
9649// EXPECT_CALL(...).After(e1)...;
9650//
9651// sets two expectations where the latter can only be matched after
9652// the former has been satisfied.
9653//
9654// Notes:
9655// - This class is copyable and has value semantics.
9656// - Constness is shallow: a const Expectation object itself cannot
9657// be modified, but the mutable methods of the ExpectationBase
9658// object it references can be called via expectation_base().
9659// - The constructors and destructor are defined out-of-line because
9660// the Symbian WINSCW compiler wants to otherwise instantiate them
9661// when it sees this class definition, at which point it doesn't have
9662// ExpectationBase available yet, leading to incorrect destruction
9663// in the linked_ptr (or compilation errors if using a checking
9664// linked_ptr).
9665class GTEST_API_ Expectation {
9666 public:
9667 // Constructs a null object that doesn't reference any expectation.
9668 Expectation();
9669
9670 ~Expectation();
9671
9672 // This single-argument ctor must not be explicit, in order to support the
9673 // Expectation e = EXPECT_CALL(...);
9674 // syntax.
9675 //
9676 // A TypedExpectation object stores its pre-requisites as
9677 // Expectation objects, and needs to call the non-const Retire()
9678 // method on the ExpectationBase objects they reference. Therefore
9679 // Expectation must receive a *non-const* reference to the
9680 // ExpectationBase object.
9681 Expectation(internal::ExpectationBase& exp); // NOLINT
9682
9683 // The compiler-generated copy ctor and operator= work exactly as
9684 // intended, so we don't need to define our own.
9685
9686 // Returns true iff rhs references the same expectation as this object does.
9687 bool operator==(const Expectation& rhs) const {
9688 return expectation_base_ == rhs.expectation_base_;
9689 }
9690
9691 bool operator!=(const Expectation& rhs) const { return !(*this == rhs); }
9692
9693 private:
9694 friend class ExpectationSet;
9695 friend class Sequence;
9696 friend class ::testing::internal::ExpectationBase;
9697 friend class ::testing::internal::UntypedFunctionMockerBase;
9698
9699 template <typename F>
9700 friend class ::testing::internal::FunctionMockerBase;
9701
9702 template <typename F>
9703 friend class ::testing::internal::TypedExpectation;
9704
9705 // This comparator is needed for putting Expectation objects into a set.
9706 class Less {
9707 public:
9708 bool operator()(const Expectation& lhs, const Expectation& rhs) const {
9709 return lhs.expectation_base_.get() < rhs.expectation_base_.get();
9710 }
9711 };
9712
9713 typedef ::std::set<Expectation, Less> Set;
9714
9715 Expectation(
9716 const internal::linked_ptr<internal::ExpectationBase>& expectation_base);
9717
9718 // Returns the expectation this object references.
9719 const internal::linked_ptr<internal::ExpectationBase>&
9720 expectation_base() const {
9721 return expectation_base_;
9722 }
9723
9724 // A linked_ptr that co-owns the expectation this handle references.
9725 internal::linked_ptr<internal::ExpectationBase> expectation_base_;
9726};
9727
9728// A set of expectation handles. Useful in the .After() clause of
9729// EXPECT_CALL() for setting the (partial) order of expectations. The
9730// syntax:
9731//
9732// ExpectationSet es;
9733// es += EXPECT_CALL(...)...;
9734// es += EXPECT_CALL(...)...;
9735// EXPECT_CALL(...).After(es)...;
9736//
9737// sets three expectations where the last one can only be matched
9738// after the first two have both been satisfied.
9739//
9740// This class is copyable and has value semantics.
9741class ExpectationSet {
9742 public:
9743 // A bidirectional iterator that can read a const element in the set.
9744 typedef Expectation::Set::const_iterator const_iterator;
9745
9746 // An object stored in the set. This is an alias of Expectation.
9747 typedef Expectation::Set::value_type value_type;
9748
9749 // Constructs an empty set.
9750 ExpectationSet() {}
9751
9752 // This single-argument ctor must not be explicit, in order to support the
9753 // ExpectationSet es = EXPECT_CALL(...);
9754 // syntax.
9755 ExpectationSet(internal::ExpectationBase& exp) { // NOLINT
9756 *this += Expectation(exp);
9757 }
9758
9759 // This single-argument ctor implements implicit conversion from
9760 // Expectation and thus must not be explicit. This allows either an
9761 // Expectation or an ExpectationSet to be used in .After().
9762 ExpectationSet(const Expectation& e) { // NOLINT
9763 *this += e;
9764 }
9765
9766 // The compiler-generator ctor and operator= works exactly as
9767 // intended, so we don't need to define our own.
9768
9769 // Returns true iff rhs contains the same set of Expectation objects
9770 // as this does.
9771 bool operator==(const ExpectationSet& rhs) const {
9772 return expectations_ == rhs.expectations_;
9773 }
9774
9775 bool operator!=(const ExpectationSet& rhs) const { return !(*this == rhs); }
9776
9777 // Implements the syntax
9778 // expectation_set += EXPECT_CALL(...);
9779 ExpectationSet& operator+=(const Expectation& e) {
9780 expectations_.insert(e);
9781 return *this;
9782 }
9783
9784 int size() const { return static_cast<int>(expectations_.size()); }
9785
9786 const_iterator begin() const { return expectations_.begin(); }
9787 const_iterator end() const { return expectations_.end(); }
9788
9789 private:
9790 Expectation::Set expectations_;
9791};
9792
9793
9794// Sequence objects are used by a user to specify the relative order
9795// in which the expectations should match. They are copyable (we rely
9796// on the compiler-defined copy constructor and assignment operator).
9797class GTEST_API_ Sequence {
9798 public:
9799 // Constructs an empty sequence.
9800 Sequence() : last_expectation_(new Expectation) {}
9801
9802 // Adds an expectation to this sequence. The caller must ensure
9803 // that no other thread is accessing this Sequence object.
9804 void AddExpectation(const Expectation& expectation) const;
9805
9806 private:
9807 // The last expectation in this sequence. We use a linked_ptr here
9808 // because Sequence objects are copyable and we want the copies to
9809 // be aliases. The linked_ptr allows the copies to co-own and share
9810 // the same Expectation object.
9811 internal::linked_ptr<Expectation> last_expectation_;
9812}; // class Sequence
9813
9814// An object of this type causes all EXPECT_CALL() statements
9815// encountered in its scope to be put in an anonymous sequence. The
9816// work is done in the constructor and destructor. You should only
9817// create an InSequence object on the stack.
9818//
9819// The sole purpose for this class is to support easy definition of
9820// sequential expectations, e.g.
9821//
9822// {
9823// InSequence dummy; // The name of the object doesn't matter.
9824//
9825// // The following expectations must match in the order they appear.
9826// EXPECT_CALL(a, Bar())...;
9827// EXPECT_CALL(a, Baz())...;
9828// ...
9829// EXPECT_CALL(b, Xyz())...;
9830// }
9831//
9832// You can create InSequence objects in multiple threads, as long as
9833// they are used to affect different mock objects. The idea is that
9834// each thread can create and set up its own mocks as if it's the only
9835// thread. However, for clarity of your tests we recommend you to set
9836// up mocks in the main thread unless you have a good reason not to do
9837// so.
9838class GTEST_API_ InSequence {
9839 public:
9840 InSequence();
9841 ~InSequence();
9842 private:
9843 bool sequence_created_;
9844
9845 GTEST_DISALLOW_COPY_AND_ASSIGN_(InSequence); // NOLINT
9846} GTEST_ATTRIBUTE_UNUSED_;
9847
9848namespace internal {
9849
9850// Points to the implicit sequence introduced by a living InSequence
9851// object (if any) in the current thread or NULL.
9852GTEST_API_ extern ThreadLocal<Sequence*> g_gmock_implicit_sequence;
9853
9854// Base class for implementing expectations.
9855//
9856// There are two reasons for having a type-agnostic base class for
9857// Expectation:
9858//
9859// 1. We need to store collections of expectations of different
9860// types (e.g. all pre-requisites of a particular expectation, all
9861// expectations in a sequence). Therefore these expectation objects
9862// must share a common base class.
9863//
9864// 2. We can avoid binary code bloat by moving methods not depending
9865// on the template argument of Expectation to the base class.
9866//
9867// This class is internal and mustn't be used by user code directly.
9868class GTEST_API_ ExpectationBase {
9869 public:
9870 // source_text is the EXPECT_CALL(...) source that created this Expectation.
9871 ExpectationBase(const char* file, int line, const string& source_text);
9872
9873 virtual ~ExpectationBase();
9874
9875 // Where in the source file was the expectation spec defined?
9876 const char* file() const { return file_; }
9877 int line() const { return line_; }
9878 const char* source_text() const { return source_text_.c_str(); }
9879 // Returns the cardinality specified in the expectation spec.
9880 const Cardinality& cardinality() const { return cardinality_; }
9881
9882 // Describes the source file location of this expectation.
9883 void DescribeLocationTo(::std::ostream* os) const {
9884 *os << FormatFileLocation(file(), line()) << " ";
9885 }
9886
9887 // Describes how many times a function call matching this
9888 // expectation has occurred.
9889 void DescribeCallCountTo(::std::ostream* os) const
9890 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
9891
9892 // If this mock method has an extra matcher (i.e. .With(matcher)),
9893 // describes it to the ostream.
9894 virtual void MaybeDescribeExtraMatcherTo(::std::ostream* os) = 0;
9895
9896 protected:
9897 friend class ::testing::Expectation;
9898 friend class UntypedFunctionMockerBase;
9899
9900 enum Clause {
9901 // Don't change the order of the enum members!
9902 kNone,
9903 kWith,
9904 kTimes,
9905 kInSequence,
9906 kAfter,
9907 kWillOnce,
9908 kWillRepeatedly,
9909 kRetiresOnSaturation
9910 };
9911
9912 typedef std::vector<const void*> UntypedActions;
9913
9914 // Returns an Expectation object that references and co-owns this
9915 // expectation.
9916 virtual Expectation GetHandle() = 0;
9917
9918 // Asserts that the EXPECT_CALL() statement has the given property.
9919 void AssertSpecProperty(bool property, const string& failure_message) const {
9920 Assert(property, file_, line_, failure_message);
9921 }
9922
9923 // Expects that the EXPECT_CALL() statement has the given property.
9924 void ExpectSpecProperty(bool property, const string& failure_message) const {
9925 Expect(property, file_, line_, failure_message);
9926 }
9927
9928 // Explicitly specifies the cardinality of this expectation. Used
9929 // by the subclasses to implement the .Times() clause.
9930 void SpecifyCardinality(const Cardinality& cardinality);
9931
9932 // Returns true iff the user specified the cardinality explicitly
9933 // using a .Times().
9934 bool cardinality_specified() const { return cardinality_specified_; }
9935
9936 // Sets the cardinality of this expectation spec.
9937 void set_cardinality(const Cardinality& a_cardinality) {
9938 cardinality_ = a_cardinality;
9939 }
9940
9941 // The following group of methods should only be called after the
9942 // EXPECT_CALL() statement, and only when g_gmock_mutex is held by
9943 // the current thread.
9944
9945 // Retires all pre-requisites of this expectation.
9946 void RetireAllPreRequisites()
9947 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
9948
9949 // Returns true iff this expectation is retired.
9950 bool is_retired() const
9951 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9952 g_gmock_mutex.AssertHeld();
9953 return retired_;
9954 }
9955
9956 // Retires this expectation.
9957 void Retire()
9958 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9959 g_gmock_mutex.AssertHeld();
9960 retired_ = true;
9961 }
9962
9963 // Returns true iff this expectation is satisfied.
9964 bool IsSatisfied() const
9965 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9966 g_gmock_mutex.AssertHeld();
9967 return cardinality().IsSatisfiedByCallCount(call_count_);
9968 }
9969
9970 // Returns true iff this expectation is saturated.
9971 bool IsSaturated() const
9972 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9973 g_gmock_mutex.AssertHeld();
9974 return cardinality().IsSaturatedByCallCount(call_count_);
9975 }
9976
9977 // Returns true iff this expectation is over-saturated.
9978 bool IsOverSaturated() const
9979 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9980 g_gmock_mutex.AssertHeld();
9981 return cardinality().IsOverSaturatedByCallCount(call_count_);
9982 }
9983
9984 // Returns true iff all pre-requisites of this expectation are satisfied.
9985 bool AllPrerequisitesAreSatisfied() const
9986 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
9987
9988 // Adds unsatisfied pre-requisites of this expectation to 'result'.
9989 void FindUnsatisfiedPrerequisites(ExpectationSet* result) const
9990 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
9991
9992 // Returns the number this expectation has been invoked.
9993 int call_count() const
9994 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9995 g_gmock_mutex.AssertHeld();
9996 return call_count_;
9997 }
9998
9999 // Increments the number this expectation has been invoked.
10000 void IncrementCallCount()
10001 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
10002 g_gmock_mutex.AssertHeld();
10003 call_count_++;
10004 }
10005
10006 // Checks the action count (i.e. the number of WillOnce() and
10007 // WillRepeatedly() clauses) against the cardinality if this hasn't
10008 // been done before. Prints a warning if there are too many or too
10009 // few actions.
10010 void CheckActionCountIfNotDone() const
10011 GTEST_LOCK_EXCLUDED_(mutex_);
10012
10013 friend class ::testing::Sequence;
10014 friend class ::testing::internal::ExpectationTester;
10015
10016 template <typename Function>
10017 friend class TypedExpectation;
10018
10019 // Implements the .Times() clause.
10020 void UntypedTimes(const Cardinality& a_cardinality);
10021
10022 // This group of fields are part of the spec and won't change after
10023 // an EXPECT_CALL() statement finishes.
10024 const char* file_; // The file that contains the expectation.
10025 int line_; // The line number of the expectation.
10026 const string source_text_; // The EXPECT_CALL(...) source text.
10027 // True iff the cardinality is specified explicitly.
10028 bool cardinality_specified_;
10029 Cardinality cardinality_; // The cardinality of the expectation.
10030 // The immediate pre-requisites (i.e. expectations that must be
10031 // satisfied before this expectation can be matched) of this
10032 // expectation. We use linked_ptr in the set because we want an
10033 // Expectation object to be co-owned by its FunctionMocker and its
10034 // successors. This allows multiple mock objects to be deleted at
10035 // different times.
10036 ExpectationSet immediate_prerequisites_;
10037
10038 // This group of fields are the current state of the expectation,
10039 // and can change as the mock function is called.
10040 int call_count_; // How many times this expectation has been invoked.
10041 bool retired_; // True iff this expectation has retired.
10042 UntypedActions untyped_actions_;
10043 bool extra_matcher_specified_;
10044 bool repeated_action_specified_; // True if a WillRepeatedly() was specified.
10045 bool retires_on_saturation_;
10046 Clause last_clause_;
10047 mutable bool action_count_checked_; // Under mutex_.
10048 mutable Mutex mutex_; // Protects action_count_checked_.
10049
10050 GTEST_DISALLOW_ASSIGN_(ExpectationBase);
10051}; // class ExpectationBase
10052
10053// Impements an expectation for the given function type.
10054template <typename F>
10055class TypedExpectation : public ExpectationBase {
10056 public:
10057 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
10058 typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple;
10059 typedef typename Function<F>::Result Result;
10060
10061 TypedExpectation(FunctionMockerBase<F>* owner,
10062 const char* a_file, int a_line, const string& a_source_text,
10063 const ArgumentMatcherTuple& m)
10064 : ExpectationBase(a_file, a_line, a_source_text),
10065 owner_(owner),
10066 matchers_(m),
10067 // By default, extra_matcher_ should match anything. However,
10068 // we cannot initialize it with _ as that triggers a compiler
10069 // bug in Symbian's C++ compiler (cannot decide between two
10070 // overloaded constructors of Matcher<const ArgumentTuple&>).
10071 extra_matcher_(A<const ArgumentTuple&>()),
10072 repeated_action_(DoDefault()) {}
10073
10074 virtual ~TypedExpectation() {
10075 // Check the validity of the action count if it hasn't been done
10076 // yet (for example, if the expectation was never used).
10077 CheckActionCountIfNotDone();
10078 for (UntypedActions::const_iterator it = untyped_actions_.begin();
10079 it != untyped_actions_.end(); ++it) {
10080 delete static_cast<const Action<F>*>(*it);
10081 }
10082 }
10083
10084 // Implements the .With() clause.
10085 TypedExpectation& With(const Matcher<const ArgumentTuple&>& m) {
10086 if (last_clause_ == kWith) {
10087 ExpectSpecProperty(false,
10088 ".With() cannot appear "
10089 "more than once in an EXPECT_CALL().");
10090 } else {
10091 ExpectSpecProperty(last_clause_ < kWith,
10092 ".With() must be the first "
10093 "clause in an EXPECT_CALL().");
10094 }
10095 last_clause_ = kWith;
10096
10097 extra_matcher_ = m;
10098 extra_matcher_specified_ = true;
10099 return *this;
10100 }
10101
10102 // Implements the .Times() clause.
10103 TypedExpectation& Times(const Cardinality& a_cardinality) {
10104 ExpectationBase::UntypedTimes(a_cardinality);
10105 return *this;
10106 }
10107
10108 // Implements the .Times() clause.
10109 TypedExpectation& Times(int n) {
10110 return Times(Exactly(n));
10111 }
10112
10113 // Implements the .InSequence() clause.
10114 TypedExpectation& InSequence(const Sequence& s) {
10115 ExpectSpecProperty(last_clause_ <= kInSequence,
10116 ".InSequence() cannot appear after .After(),"
10117 " .WillOnce(), .WillRepeatedly(), or "
10118 ".RetiresOnSaturation().");
10119 last_clause_ = kInSequence;
10120
10121 s.AddExpectation(GetHandle());
10122 return *this;
10123 }
10124 TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2) {
10125 return InSequence(s1).InSequence(s2);
10126 }
10127 TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2,
10128 const Sequence& s3) {
10129 return InSequence(s1, s2).InSequence(s3);
10130 }
10131 TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2,
10132 const Sequence& s3, const Sequence& s4) {
10133 return InSequence(s1, s2, s3).InSequence(s4);
10134 }
10135 TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2,
10136 const Sequence& s3, const Sequence& s4,
10137 const Sequence& s5) {
10138 return InSequence(s1, s2, s3, s4).InSequence(s5);
10139 }
10140
10141 // Implements that .After() clause.
10142 TypedExpectation& After(const ExpectationSet& s) {
10143 ExpectSpecProperty(last_clause_ <= kAfter,
10144 ".After() cannot appear after .WillOnce(),"
10145 " .WillRepeatedly(), or "
10146 ".RetiresOnSaturation().");
10147 last_clause_ = kAfter;
10148
10149 for (ExpectationSet::const_iterator it = s.begin(); it != s.end(); ++it) {
10150 immediate_prerequisites_ += *it;
10151 }
10152 return *this;
10153 }
10154 TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2) {
10155 return After(s1).After(s2);
10156 }
10157 TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2,
10158 const ExpectationSet& s3) {
10159 return After(s1, s2).After(s3);
10160 }
10161 TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2,
10162 const ExpectationSet& s3, const ExpectationSet& s4) {
10163 return After(s1, s2, s3).After(s4);
10164 }
10165 TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2,
10166 const ExpectationSet& s3, const ExpectationSet& s4,
10167 const ExpectationSet& s5) {
10168 return After(s1, s2, s3, s4).After(s5);
10169 }
10170
10171 // Implements the .WillOnce() clause.
10172 TypedExpectation& WillOnce(const Action<F>& action) {
10173 ExpectSpecProperty(last_clause_ <= kWillOnce,
10174 ".WillOnce() cannot appear after "
10175 ".WillRepeatedly() or .RetiresOnSaturation().");
10176 last_clause_ = kWillOnce;
10177
10178 untyped_actions_.push_back(new Action<F>(action));
10179 if (!cardinality_specified()) {
10180 set_cardinality(Exactly(static_cast<int>(untyped_actions_.size())));
10181 }
10182 return *this;
10183 }
10184
10185 // Implements the .WillRepeatedly() clause.
10186 TypedExpectation& WillRepeatedly(const Action<F>& action) {
10187 if (last_clause_ == kWillRepeatedly) {
10188 ExpectSpecProperty(false,
10189 ".WillRepeatedly() cannot appear "
10190 "more than once in an EXPECT_CALL().");
10191 } else {
10192 ExpectSpecProperty(last_clause_ < kWillRepeatedly,
10193 ".WillRepeatedly() cannot appear "
10194 "after .RetiresOnSaturation().");
10195 }
10196 last_clause_ = kWillRepeatedly;
10197 repeated_action_specified_ = true;
10198
10199 repeated_action_ = action;
10200 if (!cardinality_specified()) {
10201 set_cardinality(AtLeast(static_cast<int>(untyped_actions_.size())));
10202 }
10203
10204 // Now that no more action clauses can be specified, we check
10205 // whether their count makes sense.
10206 CheckActionCountIfNotDone();
10207 return *this;
10208 }
10209
10210 // Implements the .RetiresOnSaturation() clause.
10211 TypedExpectation& RetiresOnSaturation() {
10212 ExpectSpecProperty(last_clause_ < kRetiresOnSaturation,
10213 ".RetiresOnSaturation() cannot appear "
10214 "more than once.");
10215 last_clause_ = kRetiresOnSaturation;
10216 retires_on_saturation_ = true;
10217
10218 // Now that no more action clauses can be specified, we check
10219 // whether their count makes sense.
10220 CheckActionCountIfNotDone();
10221 return *this;
10222 }
10223
10224 // Returns the matchers for the arguments as specified inside the
10225 // EXPECT_CALL() macro.
10226 const ArgumentMatcherTuple& matchers() const {
10227 return matchers_;
10228 }
10229
10230 // Returns the matcher specified by the .With() clause.
10231 const Matcher<const ArgumentTuple&>& extra_matcher() const {
10232 return extra_matcher_;
10233 }
10234
10235 // Returns the action specified by the .WillRepeatedly() clause.
10236 const Action<F>& repeated_action() const { return repeated_action_; }
10237
10238 // If this mock method has an extra matcher (i.e. .With(matcher)),
10239 // describes it to the ostream.
10240 virtual void MaybeDescribeExtraMatcherTo(::std::ostream* os) {
10241 if (extra_matcher_specified_) {
10242 *os << " Expected args: ";
10243 extra_matcher_.DescribeTo(os);
10244 *os << "\n";
10245 }
10246 }
10247
10248 private:
10249 template <typename Function>
10250 friend class FunctionMockerBase;
10251
10252 // Returns an Expectation object that references and co-owns this
10253 // expectation.
10254 virtual Expectation GetHandle() {
10255 return owner_->GetHandleOf(this);
10256 }
10257
10258 // The following methods will be called only after the EXPECT_CALL()
10259 // statement finishes and when the current thread holds
10260 // g_gmock_mutex.
10261
10262 // Returns true iff this expectation matches the given arguments.
10263 bool Matches(const ArgumentTuple& args) const
10264 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
10265 g_gmock_mutex.AssertHeld();
10266 return TupleMatches(matchers_, args) && extra_matcher_.Matches(args);
10267 }
10268
10269 // Returns true iff this expectation should handle the given arguments.
10270 bool ShouldHandleArguments(const ArgumentTuple& args) const
10271 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
10272 g_gmock_mutex.AssertHeld();
10273
10274 // In case the action count wasn't checked when the expectation
10275 // was defined (e.g. if this expectation has no WillRepeatedly()
10276 // or RetiresOnSaturation() clause), we check it when the
10277 // expectation is used for the first time.
10278 CheckActionCountIfNotDone();
10279 return !is_retired() && AllPrerequisitesAreSatisfied() && Matches(args);
10280 }
10281
10282 // Describes the result of matching the arguments against this
10283 // expectation to the given ostream.
10284 void ExplainMatchResultTo(
10285 const ArgumentTuple& args,
10286 ::std::ostream* os) const
10287 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
10288 g_gmock_mutex.AssertHeld();
10289
10290 if (is_retired()) {
10291 *os << " Expected: the expectation is active\n"
10292 << " Actual: it is retired\n";
10293 } else if (!Matches(args)) {
10294 if (!TupleMatches(matchers_, args)) {
10295 ExplainMatchFailureTupleTo(matchers_, args, os);
10296 }
10297 StringMatchResultListener listener;
10298 if (!extra_matcher_.MatchAndExplain(args, &listener)) {
10299 *os << " Expected args: ";
10300 extra_matcher_.DescribeTo(os);
10301 *os << "\n Actual: don't match";
10302
10303 internal::PrintIfNotEmpty(listener.str(), os);
10304 *os << "\n";
10305 }
10306 } else if (!AllPrerequisitesAreSatisfied()) {
10307 *os << " Expected: all pre-requisites are satisfied\n"
10308 << " Actual: the following immediate pre-requisites "
10309 << "are not satisfied:\n";
10310 ExpectationSet unsatisfied_prereqs;
10311 FindUnsatisfiedPrerequisites(&unsatisfied_prereqs);
10312 int i = 0;
10313 for (ExpectationSet::const_iterator it = unsatisfied_prereqs.begin();
10314 it != unsatisfied_prereqs.end(); ++it) {
10315 it->expectation_base()->DescribeLocationTo(os);
10316 *os << "pre-requisite #" << i++ << "\n";
10317 }
10318 *os << " (end of pre-requisites)\n";
10319 } else {
10320 // This line is here just for completeness' sake. It will never
10321 // be executed as currently the ExplainMatchResultTo() function
10322 // is called only when the mock function call does NOT match the
10323 // expectation.
10324 *os << "The call matches the expectation.\n";
10325 }
10326 }
10327
10328 // Returns the action that should be taken for the current invocation.
10329 const Action<F>& GetCurrentAction(
10330 const FunctionMockerBase<F>* mocker,
10331 const ArgumentTuple& args) const
10332 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
10333 g_gmock_mutex.AssertHeld();
10334 const int count = call_count();
10335 Assert(count >= 1, __FILE__, __LINE__,
10336 "call_count() is <= 0 when GetCurrentAction() is "
10337 "called - this should never happen.");
10338
10339 const int action_count = static_cast<int>(untyped_actions_.size());
10340 if (action_count > 0 && !repeated_action_specified_ &&
10341 count > action_count) {
10342 // If there is at least one WillOnce() and no WillRepeatedly(),
10343 // we warn the user when the WillOnce() clauses ran out.
10344 ::std::stringstream ss;
10345 DescribeLocationTo(&ss);
10346 ss << "Actions ran out in " << source_text() << "...\n"
10347 << "Called " << count << " times, but only "
10348 << action_count << " WillOnce()"
10349 << (action_count == 1 ? " is" : "s are") << " specified - ";
10350 mocker->DescribeDefaultActionTo(args, &ss);
10351 Log(kWarning, ss.str(), 1);
10352 }
10353
10354 return count <= action_count ?
10355 *static_cast<const Action<F>*>(untyped_actions_[count - 1]) :
10356 repeated_action();
10357 }
10358
10359 // Given the arguments of a mock function call, if the call will
10360 // over-saturate this expectation, returns the default action;
10361 // otherwise, returns the next action in this expectation. Also
10362 // describes *what* happened to 'what', and explains *why* Google
10363 // Mock does it to 'why'. This method is not const as it calls
10364 // IncrementCallCount(). A return value of NULL means the default
10365 // action.
10366 const Action<F>* GetActionForArguments(
10367 const FunctionMockerBase<F>* mocker,
10368 const ArgumentTuple& args,
10369 ::std::ostream* what,
10370 ::std::ostream* why)
10371 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
10372 g_gmock_mutex.AssertHeld();
10373 if (IsSaturated()) {
10374 // We have an excessive call.
10375 IncrementCallCount();
10376 *what << "Mock function called more times than expected - ";
10377 mocker->DescribeDefaultActionTo(args, what);
10378 DescribeCallCountTo(why);
10379
10380 // TODO(wan@google.com): allow the user to control whether
10381 // unexpected calls should fail immediately or continue using a
10382 // flag --gmock_unexpected_calls_are_fatal.
10383 return NULL;
10384 }
10385
10386 IncrementCallCount();
10387 RetireAllPreRequisites();
10388
10389 if (retires_on_saturation_ && IsSaturated()) {
10390 Retire();
10391 }
10392
10393 // Must be done after IncrementCount()!
10394 *what << "Mock function call matches " << source_text() <<"...\n";
10395 return &(GetCurrentAction(mocker, args));
10396 }
10397
10398 // All the fields below won't change once the EXPECT_CALL()
10399 // statement finishes.
10400 FunctionMockerBase<F>* const owner_;
10401 ArgumentMatcherTuple matchers_;
10402 Matcher<const ArgumentTuple&> extra_matcher_;
10403 Action<F> repeated_action_;
10404
10405 GTEST_DISALLOW_COPY_AND_ASSIGN_(TypedExpectation);
10406}; // class TypedExpectation
10407
10408// A MockSpec object is used by ON_CALL() or EXPECT_CALL() for
10409// specifying the default behavior of, or expectation on, a mock
10410// function.
10411
10412// Note: class MockSpec really belongs to the ::testing namespace.
10413// However if we define it in ::testing, MSVC will complain when
10414// classes in ::testing::internal declare it as a friend class
10415// template. To workaround this compiler bug, we define MockSpec in
10416// ::testing::internal and import it into ::testing.
10417
10418// Logs a message including file and line number information.
10419GTEST_API_ void LogWithLocation(testing::internal::LogSeverity severity,
10420 const char* file, int line,
10421 const string& message);
10422
10423template <typename F>
10424class MockSpec {
10425 public:
10426 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
10427 typedef typename internal::Function<F>::ArgumentMatcherTuple
10428 ArgumentMatcherTuple;
10429
10430 // Constructs a MockSpec object, given the function mocker object
10431 // that the spec is associated with.
10432 explicit MockSpec(internal::FunctionMockerBase<F>* function_mocker)
10433 : function_mocker_(function_mocker) {}
10434
10435 // Adds a new default action spec to the function mocker and returns
10436 // the newly created spec.
10437 internal::OnCallSpec<F>& InternalDefaultActionSetAt(
10438 const char* file, int line, const char* obj, const char* call) {
10439 LogWithLocation(internal::kInfo, file, line,
10440 string("ON_CALL(") + obj + ", " + call + ") invoked");
10441 return function_mocker_->AddNewOnCallSpec(file, line, matchers_);
10442 }
10443
10444 // Adds a new expectation spec to the function mocker and returns
10445 // the newly created spec.
10446 internal::TypedExpectation<F>& InternalExpectedAt(
10447 const char* file, int line, const char* obj, const char* call) {
10448 const string source_text(string("EXPECT_CALL(") + obj + ", " + call + ")");
10449 LogWithLocation(internal::kInfo, file, line, source_text + " invoked");
10450 return function_mocker_->AddNewExpectation(
10451 file, line, source_text, matchers_);
10452 }
10453
10454 private:
10455 template <typename Function>
10456 friend class internal::FunctionMocker;
10457
10458 void SetMatchers(const ArgumentMatcherTuple& matchers) {
10459 matchers_ = matchers;
10460 }
10461
10462 // The function mocker that owns this spec.
10463 internal::FunctionMockerBase<F>* const function_mocker_;
10464 // The argument matchers specified in the spec.
10465 ArgumentMatcherTuple matchers_;
10466
10467 GTEST_DISALLOW_ASSIGN_(MockSpec);
10468}; // class MockSpec
10469
10470// Wrapper type for generically holding an ordinary value or lvalue reference.
10471// If T is not a reference type, it must be copyable or movable.
10472// ReferenceOrValueWrapper<T> is movable, and will also be copyable unless
10473// T is a move-only value type (which means that it will always be copyable
10474// if the current platform does not support move semantics).
10475//
10476// The primary template defines handling for values, but function header
10477// comments describe the contract for the whole template (including
10478// specializations).
10479template <typename T>
10480class ReferenceOrValueWrapper {
10481 public:
10482 // Constructs a wrapper from the given value/reference.
10483 explicit ReferenceOrValueWrapper(T value)
10484 : value_(::testing::internal::move(value)) {
10485 }
10486
10487 // Unwraps and returns the underlying value/reference, exactly as
10488 // originally passed. The behavior of calling this more than once on
10489 // the same object is unspecified.
10490 T Unwrap() { return ::testing::internal::move(value_); }
10491
10492 // Provides nondestructive access to the underlying value/reference.
10493 // Always returns a const reference (more precisely,
10494 // const RemoveReference<T>&). The behavior of calling this after
10495 // calling Unwrap on the same object is unspecified.
10496 const T& Peek() const {
10497 return value_;
10498 }
10499
10500 private:
10501 T value_;
10502};
10503
10504// Specialization for lvalue reference types. See primary template
10505// for documentation.
10506template <typename T>
10507class ReferenceOrValueWrapper<T&> {
10508 public:
10509 // Workaround for debatable pass-by-reference lint warning (c-library-team
10510 // policy precludes NOLINT in this context)
10511 typedef T& reference;
10512 explicit ReferenceOrValueWrapper(reference ref)
10513 : value_ptr_(&ref) {}
10514 T& Unwrap() { return *value_ptr_; }
10515 const T& Peek() const { return *value_ptr_; }
10516
10517 private:
10518 T* value_ptr_;
10519};
10520
10521// MSVC warns about using 'this' in base member initializer list, so
10522// we need to temporarily disable the warning. We have to do it for
10523// the entire class to suppress the warning, even though it's about
10524// the constructor only.
10525
10526#ifdef _MSC_VER
10527# pragma warning(push) // Saves the current warning state.
10528# pragma warning(disable:4355) // Temporarily disables warning 4355.
10529#endif // _MSV_VER
10530
10531// C++ treats the void type specially. For example, you cannot define
10532// a void-typed variable or pass a void value to a function.
10533// ActionResultHolder<T> holds a value of type T, where T must be a
10534// copyable type or void (T doesn't need to be default-constructable).
10535// It hides the syntactic difference between void and other types, and
10536// is used to unify the code for invoking both void-returning and
10537// non-void-returning mock functions.
10538
10539// Untyped base class for ActionResultHolder<T>.
10540class UntypedActionResultHolderBase {
10541 public:
10542 virtual ~UntypedActionResultHolderBase() {}
10543
10544 // Prints the held value as an action's result to os.
10545 virtual void PrintAsActionResult(::std::ostream* os) const = 0;
10546};
10547
10548// This generic definition is used when T is not void.
10549template <typename T>
10550class ActionResultHolder : public UntypedActionResultHolderBase {
10551 public:
10552 // Returns the held value. Must not be called more than once.
10553 T Unwrap() {
10554 return result_.Unwrap();
10555 }
10556
10557 // Prints the held value as an action's result to os.
10558 virtual void PrintAsActionResult(::std::ostream* os) const {
10559 *os << "\n Returns: ";
10560 // T may be a reference type, so we don't use UniversalPrint().
10561 UniversalPrinter<T>::Print(result_.Peek(), os);
10562 }
10563
10564 // Performs the given mock function's default action and returns the
10565 // result in a new-ed ActionResultHolder.
10566 template <typename F>
10567 static ActionResultHolder* PerformDefaultAction(
10568 const FunctionMockerBase<F>* func_mocker,
10569 const typename Function<F>::ArgumentTuple& args,
10570 const string& call_description) {
10571 return new ActionResultHolder(Wrapper(
10572 func_mocker->PerformDefaultAction(args, call_description)));
10573 }
10574
10575 // Performs the given action and returns the result in a new-ed
10576 // ActionResultHolder.
10577 template <typename F>
10578 static ActionResultHolder*
10579 PerformAction(const Action<F>& action,
10580 const typename Function<F>::ArgumentTuple& args) {
10581 return new ActionResultHolder(Wrapper(action.Perform(args)));
10582 }
10583
10584 private:
10585 typedef ReferenceOrValueWrapper<T> Wrapper;
10586
10587 explicit ActionResultHolder(Wrapper result)
10588 : result_(::testing::internal::move(result)) {
10589 }
10590
10591 Wrapper result_;
10592
10593 GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionResultHolder);
10594};
10595
10596// Specialization for T = void.
10597template <>
10598class ActionResultHolder<void> : public UntypedActionResultHolderBase {
10599 public:
10600 void Unwrap() { }
10601
10602 virtual void PrintAsActionResult(::std::ostream* /* os */) const {}
10603
10604 // Performs the given mock function's default action and returns ownership
10605 // of an empty ActionResultHolder*.
10606 template <typename F>
10607 static ActionResultHolder* PerformDefaultAction(
10608 const FunctionMockerBase<F>* func_mocker,
10609 const typename Function<F>::ArgumentTuple& args,
10610 const string& call_description) {
10611 func_mocker->PerformDefaultAction(args, call_description);
10612 return new ActionResultHolder;
10613 }
10614
10615 // Performs the given action and returns ownership of an empty
10616 // ActionResultHolder*.
10617 template <typename F>
10618 static ActionResultHolder* PerformAction(
10619 const Action<F>& action,
10620 const typename Function<F>::ArgumentTuple& args) {
10621 action.Perform(args);
10622 return new ActionResultHolder;
10623 }
10624
10625 private:
10626 ActionResultHolder() {}
10627 GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionResultHolder);
10628};
10629
10630// The base of the function mocker class for the given function type.
10631// We put the methods in this class instead of its child to avoid code
10632// bloat.
10633template <typename F>
10634class FunctionMockerBase : public UntypedFunctionMockerBase {
10635 public:
10636 typedef typename Function<F>::Result Result;
10637 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
10638 typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple;
10639
10640 FunctionMockerBase() : current_spec_(this) {}
10641
10642 // The destructor verifies that all expectations on this mock
10643 // function have been satisfied. If not, it will report Google Test
10644 // non-fatal failures for the violations.
10645 virtual ~FunctionMockerBase()
10646 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
10647 MutexLock l(&g_gmock_mutex);
10648 VerifyAndClearExpectationsLocked();
10649 Mock::UnregisterLocked(this);
10650 ClearDefaultActionsLocked();
10651 }
10652
10653 // Returns the ON_CALL spec that matches this mock function with the
10654 // given arguments; returns NULL if no matching ON_CALL is found.
10655 // L = *
10656 const OnCallSpec<F>* FindOnCallSpec(
10657 const ArgumentTuple& args) const {
10658 for (UntypedOnCallSpecs::const_reverse_iterator it
10659 = untyped_on_call_specs_.rbegin();
10660 it != untyped_on_call_specs_.rend(); ++it) {
10661 const OnCallSpec<F>* spec = static_cast<const OnCallSpec<F>*>(*it);
10662 if (spec->Matches(args))
10663 return spec;
10664 }
10665
10666 return NULL;
10667 }
10668
10669 // Performs the default action of this mock function on the given
10670 // arguments and returns the result. Asserts (or throws if
10671 // exceptions are enabled) with a helpful call descrption if there
10672 // is no valid return value. This method doesn't depend on the
10673 // mutable state of this object, and thus can be called concurrently
10674 // without locking.
10675 // L = *
10676 Result PerformDefaultAction(const ArgumentTuple& args,
10677 const string& call_description) const {
10678 const OnCallSpec<F>* const spec =
10679 this->FindOnCallSpec(args);
10680 if (spec != NULL) {
10681 return spec->GetAction().Perform(args);
10682 }
10683 const string message = call_description +
10684 "\n The mock function has no default action "
10685 "set, and its return type has no default value set.";
10686#if GTEST_HAS_EXCEPTIONS
10687 if (!DefaultValue<Result>::Exists()) {
10688 throw std::runtime_error(message);
10689 }
10690#else
10691 Assert(DefaultValue<Result>::Exists(), "", -1, message);
10692#endif
10693 return DefaultValue<Result>::Get();
10694 }
10695
10696 // Performs the default action with the given arguments and returns
10697 // the action's result. The call description string will be used in
10698 // the error message to describe the call in the case the default
10699 // action fails. The caller is responsible for deleting the result.
10700 // L = *
10701 virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction(
10702 const void* untyped_args, // must point to an ArgumentTuple
10703 const string& call_description) const {
10704 const ArgumentTuple& args =
10705 *static_cast<const ArgumentTuple*>(untyped_args);
10706 return ResultHolder::PerformDefaultAction(this, args, call_description);
10707 }
10708
10709 // Performs the given action with the given arguments and returns
10710 // the action's result. The caller is responsible for deleting the
10711 // result.
10712 // L = *
10713 virtual UntypedActionResultHolderBase* UntypedPerformAction(
10714 const void* untyped_action, const void* untyped_args) const {
10715 // Make a copy of the action before performing it, in case the
10716 // action deletes the mock object (and thus deletes itself).
10717 const Action<F> action = *static_cast<const Action<F>*>(untyped_action);
10718 const ArgumentTuple& args =
10719 *static_cast<const ArgumentTuple*>(untyped_args);
10720 return ResultHolder::PerformAction(action, args);
10721 }
10722
10723 // Implements UntypedFunctionMockerBase::ClearDefaultActionsLocked():
10724 // clears the ON_CALL()s set on this mock function.
10725 virtual void ClearDefaultActionsLocked()
10726 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
10727 g_gmock_mutex.AssertHeld();
10728
10729 // Deleting our default actions may trigger other mock objects to be
10730 // deleted, for example if an action contains a reference counted smart
10731 // pointer to that mock object, and that is the last reference. So if we
10732 // delete our actions within the context of the global mutex we may deadlock
10733 // when this method is called again. Instead, make a copy of the set of
10734 // actions to delete, clear our set within the mutex, and then delete the
10735 // actions outside of the mutex.
10736 UntypedOnCallSpecs specs_to_delete;
10737 untyped_on_call_specs_.swap(specs_to_delete);
10738
10739 g_gmock_mutex.Unlock();
10740 for (UntypedOnCallSpecs::const_iterator it =
10741 specs_to_delete.begin();
10742 it != specs_to_delete.end(); ++it) {
10743 delete static_cast<const OnCallSpec<F>*>(*it);
10744 }
10745
10746 // Lock the mutex again, since the caller expects it to be locked when we
10747 // return.
10748 g_gmock_mutex.Lock();
10749 }
10750
10751 protected:
10752 template <typename Function>
10753 friend class MockSpec;
10754
10755 typedef ActionResultHolder<Result> ResultHolder;
10756
10757 // Returns the result of invoking this mock function with the given
10758 // arguments. This function can be safely called from multiple
10759 // threads concurrently.
10760 Result InvokeWith(const ArgumentTuple& args)
10761 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
10762 scoped_ptr<ResultHolder> holder(
10763 DownCast_<ResultHolder*>(this->UntypedInvokeWith(&args)));
10764 return holder->Unwrap();
10765 }
10766
10767 // Adds and returns a default action spec for this mock function.
10768 OnCallSpec<F>& AddNewOnCallSpec(
10769 const char* file, int line,
10770 const ArgumentMatcherTuple& m)
10771 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
10772 Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line);
10773 OnCallSpec<F>* const on_call_spec = new OnCallSpec<F>(file, line, m);
10774 untyped_on_call_specs_.push_back(on_call_spec);
10775 return *on_call_spec;
10776 }
10777
10778 // Adds and returns an expectation spec for this mock function.
10779 TypedExpectation<F>& AddNewExpectation(
10780 const char* file,
10781 int line,
10782 const string& source_text,
10783 const ArgumentMatcherTuple& m)
10784 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
10785 Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line);
10786 TypedExpectation<F>* const expectation =
10787 new TypedExpectation<F>(this, file, line, source_text, m);
10788 const linked_ptr<ExpectationBase> untyped_expectation(expectation);
10789 untyped_expectations_.push_back(untyped_expectation);
10790
10791 // Adds this expectation into the implicit sequence if there is one.
10792 Sequence* const implicit_sequence = g_gmock_implicit_sequence.get();
10793 if (implicit_sequence != NULL) {
10794 implicit_sequence->AddExpectation(Expectation(untyped_expectation));
10795 }
10796
10797 return *expectation;
10798 }
10799
10800 // The current spec (either default action spec or expectation spec)
10801 // being described on this function mocker.
10802 MockSpec<F>& current_spec() { return current_spec_; }
10803
10804 private:
10805 template <typename Func> friend class TypedExpectation;
10806
10807 // Some utilities needed for implementing UntypedInvokeWith().
10808
10809 // Describes what default action will be performed for the given
10810 // arguments.
10811 // L = *
10812 void DescribeDefaultActionTo(const ArgumentTuple& args,
10813 ::std::ostream* os) const {
10814 const OnCallSpec<F>* const spec = FindOnCallSpec(args);
10815
10816 if (spec == NULL) {
10817 *os << (internal::type_equals<Result, void>::value ?
10818 "returning directly.\n" :
10819 "returning default value.\n");
10820 } else {
10821 *os << "taking default action specified at:\n"
10822 << FormatFileLocation(spec->file(), spec->line()) << "\n";
10823 }
10824 }
10825
10826 // Writes a message that the call is uninteresting (i.e. neither
10827 // explicitly expected nor explicitly unexpected) to the given
10828 // ostream.
10829 virtual void UntypedDescribeUninterestingCall(
10830 const void* untyped_args,
10831 ::std::ostream* os) const
10832 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
10833 const ArgumentTuple& args =
10834 *static_cast<const ArgumentTuple*>(untyped_args);
10835 *os << "Uninteresting mock function call - ";
10836 DescribeDefaultActionTo(args, os);
10837 *os << " Function call: " << Name();
10838 UniversalPrint(args, os);
10839 }
10840
10841 // Returns the expectation that matches the given function arguments
10842 // (or NULL is there's no match); when a match is found,
10843 // untyped_action is set to point to the action that should be
10844 // performed (or NULL if the action is "do default"), and
10845 // is_excessive is modified to indicate whether the call exceeds the
10846 // expected number.
10847 //
10848 // Critical section: We must find the matching expectation and the
10849 // corresponding action that needs to be taken in an ATOMIC
10850 // transaction. Otherwise another thread may call this mock
10851 // method in the middle and mess up the state.
10852 //
10853 // However, performing the action has to be left out of the critical
10854 // section. The reason is that we have no control on what the
10855 // action does (it can invoke an arbitrary user function or even a
10856 // mock function) and excessive locking could cause a dead lock.
10857 virtual const ExpectationBase* UntypedFindMatchingExpectation(
10858 const void* untyped_args,
10859 const void** untyped_action, bool* is_excessive,
10860 ::std::ostream* what, ::std::ostream* why)
10861 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
10862 const ArgumentTuple& args =
10863 *static_cast<const ArgumentTuple*>(untyped_args);
10864 MutexLock l(&g_gmock_mutex);
10865 TypedExpectation<F>* exp = this->FindMatchingExpectationLocked(args);
10866 if (exp == NULL) { // A match wasn't found.
10867 this->FormatUnexpectedCallMessageLocked(args, what, why);
10868 return NULL;
10869 }
10870
10871 // This line must be done before calling GetActionForArguments(),
10872 // which will increment the call count for *exp and thus affect
10873 // its saturation status.
10874 *is_excessive = exp->IsSaturated();
10875 const Action<F>* action = exp->GetActionForArguments(this, args, what, why);
10876 if (action != NULL && action->IsDoDefault())
10877 action = NULL; // Normalize "do default" to NULL.
10878 *untyped_action = action;
10879 return exp;
10880 }
10881
10882 // Prints the given function arguments to the ostream.
10883 virtual void UntypedPrintArgs(const void* untyped_args,
10884 ::std::ostream* os) const {
10885 const ArgumentTuple& args =
10886 *static_cast<const ArgumentTuple*>(untyped_args);
10887 UniversalPrint(args, os);
10888 }
10889
10890 // Returns the expectation that matches the arguments, or NULL if no
10891 // expectation matches them.
10892 TypedExpectation<F>* FindMatchingExpectationLocked(
10893 const ArgumentTuple& args) const
10894 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
10895 g_gmock_mutex.AssertHeld();
10896 for (typename UntypedExpectations::const_reverse_iterator it =
10897 untyped_expectations_.rbegin();
10898 it != untyped_expectations_.rend(); ++it) {
10899 TypedExpectation<F>* const exp =
10900 static_cast<TypedExpectation<F>*>(it->get());
10901 if (exp->ShouldHandleArguments(args)) {
10902 return exp;
10903 }
10904 }
10905 return NULL;
10906 }
10907
10908 // Returns a message that the arguments don't match any expectation.
10909 void FormatUnexpectedCallMessageLocked(
10910 const ArgumentTuple& args,
10911 ::std::ostream* os,
10912 ::std::ostream* why) const
10913 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
10914 g_gmock_mutex.AssertHeld();
10915 *os << "\nUnexpected mock function call - ";
10916 DescribeDefaultActionTo(args, os);
10917 PrintTriedExpectationsLocked(args, why);
10918 }
10919
10920 // Prints a list of expectations that have been tried against the
10921 // current mock function call.
10922 void PrintTriedExpectationsLocked(
10923 const ArgumentTuple& args,
10924 ::std::ostream* why) const
10925 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
10926 g_gmock_mutex.AssertHeld();
10927 const int count = static_cast<int>(untyped_expectations_.size());
10928 *why << "Google Mock tried the following " << count << " "
10929 << (count == 1 ? "expectation, but it didn't match" :
10930 "expectations, but none matched")
10931 << ":\n";
10932 for (int i = 0; i < count; i++) {
10933 TypedExpectation<F>* const expectation =
10934 static_cast<TypedExpectation<F>*>(untyped_expectations_[i].get());
10935 *why << "\n";
10936 expectation->DescribeLocationTo(why);
10937 if (count > 1) {
10938 *why << "tried expectation #" << i << ": ";
10939 }
10940 *why << expectation->source_text() << "...\n";
10941 expectation->ExplainMatchResultTo(args, why);
10942 expectation->DescribeCallCountTo(why);
10943 }
10944 }
10945
10946 // The current spec (either default action spec or expectation spec)
10947 // being described on this function mocker.
10948 MockSpec<F> current_spec_;
10949
10950 // There is no generally useful and implementable semantics of
10951 // copying a mock object, so copying a mock is usually a user error.
10952 // Thus we disallow copying function mockers. If the user really
10953 // wants to copy a mock object, he should implement his own copy
10954 // operation, for example:
10955 //
10956 // class MockFoo : public Foo {
10957 // public:
10958 // // Defines a copy constructor explicitly.
10959 // MockFoo(const MockFoo& src) {}
10960 // ...
10961 // };
10962 GTEST_DISALLOW_COPY_AND_ASSIGN_(FunctionMockerBase);
10963}; // class FunctionMockerBase
10964
10965#ifdef _MSC_VER
10966# pragma warning(pop) // Restores the warning state.
10967#endif // _MSV_VER
10968
10969// Implements methods of FunctionMockerBase.
10970
10971// Verifies that all expectations on this mock function have been
10972// satisfied. Reports one or more Google Test non-fatal failures and
10973// returns false if not.
10974
10975// Reports an uninteresting call (whose description is in msg) in the
10976// manner specified by 'reaction'.
10977void ReportUninterestingCall(CallReaction reaction, const string& msg);
10978
10979} // namespace internal
10980
10981// The style guide prohibits "using" statements in a namespace scope
10982// inside a header file. However, the MockSpec class template is
10983// meant to be defined in the ::testing namespace. The following line
10984// is just a trick for working around a bug in MSVC 8.0, which cannot
10985// handle it if we define MockSpec in ::testing.
10986using internal::MockSpec;
10987
10988// Const(x) is a convenient function for obtaining a const reference
10989// to x. This is useful for setting expectations on an overloaded
10990// const mock method, e.g.
10991//
10992// class MockFoo : public FooInterface {
10993// public:
10994// MOCK_METHOD0(Bar, int());
10995// MOCK_CONST_METHOD0(Bar, int&());
10996// };
10997//
10998// MockFoo foo;
10999// // Expects a call to non-const MockFoo::Bar().
11000// EXPECT_CALL(foo, Bar());
11001// // Expects a call to const MockFoo::Bar().
11002// EXPECT_CALL(Const(foo), Bar());
11003template <typename T>
11004inline const T& Const(const T& x) { return x; }
11005
11006// Constructs an Expectation object that references and co-owns exp.
11007inline Expectation::Expectation(internal::ExpectationBase& exp) // NOLINT
11008 : expectation_base_(exp.GetHandle().expectation_base()) {}
11009
11010} // namespace testing
11011
11012// A separate macro is required to avoid compile errors when the name
11013// of the method used in call is a result of macro expansion.
11014// See CompilesWithMethodNameExpandedFromMacro tests in
11015// internal/gmock-spec-builders_test.cc for more details.
11016#define GMOCK_ON_CALL_IMPL_(obj, call) \
11017 ((obj).gmock_##call).InternalDefaultActionSetAt(__FILE__, __LINE__, \
11018 #obj, #call)
11019#define ON_CALL(obj, call) GMOCK_ON_CALL_IMPL_(obj, call)
11020
11021#define GMOCK_EXPECT_CALL_IMPL_(obj, call) \
11022 ((obj).gmock_##call).InternalExpectedAt(__FILE__, __LINE__, #obj, #call)
11023#define EXPECT_CALL(obj, call) GMOCK_EXPECT_CALL_IMPL_(obj, call)
11024
11025#endif // GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_
11026
11027#if GTEST_HAS_STD_FUNCTION_
11028# include <functional>
11029#endif
11030
11031namespace testing {
11032namespace internal {
11033
11034template <typename F>
11035class FunctionMockerBase;
11036
11037// Note: class FunctionMocker really belongs to the ::testing
11038// namespace. However if we define it in ::testing, MSVC will
11039// complain when classes in ::testing::internal declare it as a
11040// friend class template. To workaround this compiler bug, we define
11041// FunctionMocker in ::testing::internal and import it into ::testing.
11042template <typename F>
11043class FunctionMocker;
11044
11045template <typename R>
11046class FunctionMocker<R()> : public
11047 internal::FunctionMockerBase<R()> {
11048 public:
11049 typedef R F();
11050 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
11051
11052 MockSpec<F>& With() {
11053 return this->current_spec();
11054 }
11055
11056 R Invoke() {
11057 // Even though gcc and MSVC don't enforce it, 'this->' is required
11058 // by the C++ standard [14.6.4] here, as the base class type is
11059 // dependent on the template argument (and thus shouldn't be
11060 // looked into when resolving InvokeWith).
11061 return this->InvokeWith(ArgumentTuple());
11062 }
11063};
11064
11065template <typename R, typename A1>
11066class FunctionMocker<R(A1)> : public
11067 internal::FunctionMockerBase<R(A1)> {
11068 public:
11069 typedef R F(A1);
11070 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
11071
11072 MockSpec<F>& With(const Matcher<A1>& m1) {
11073 this->current_spec().SetMatchers(::testing::make_tuple(m1));
11074 return this->current_spec();
11075 }
11076
11077 R Invoke(A1 a1) {
11078 // Even though gcc and MSVC don't enforce it, 'this->' is required
11079 // by the C++ standard [14.6.4] here, as the base class type is
11080 // dependent on the template argument (and thus shouldn't be
11081 // looked into when resolving InvokeWith).
11082 return this->InvokeWith(ArgumentTuple(a1));
11083 }
11084};
11085
11086template <typename R, typename A1, typename A2>
11087class FunctionMocker<R(A1, A2)> : public
11088 internal::FunctionMockerBase<R(A1, A2)> {
11089 public:
11090 typedef R F(A1, A2);
11091 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
11092
11093 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2) {
11094 this->current_spec().SetMatchers(::testing::make_tuple(m1, m2));
11095 return this->current_spec();
11096 }
11097
11098 R Invoke(A1 a1, A2 a2) {
11099 // Even though gcc and MSVC don't enforce it, 'this->' is required
11100 // by the C++ standard [14.6.4] here, as the base class type is
11101 // dependent on the template argument (and thus shouldn't be
11102 // looked into when resolving InvokeWith).
11103 return this->InvokeWith(ArgumentTuple(a1, a2));
11104 }
11105};
11106
11107template <typename R, typename A1, typename A2, typename A3>
11108class FunctionMocker<R(A1, A2, A3)> : public
11109 internal::FunctionMockerBase<R(A1, A2, A3)> {
11110 public:
11111 typedef R F(A1, A2, A3);
11112 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
11113
11114 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
11115 const Matcher<A3>& m3) {
11116 this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3));
11117 return this->current_spec();
11118 }
11119
11120 R Invoke(A1 a1, A2 a2, A3 a3) {
11121 // Even though gcc and MSVC don't enforce it, 'this->' is required
11122 // by the C++ standard [14.6.4] here, as the base class type is
11123 // dependent on the template argument (and thus shouldn't be
11124 // looked into when resolving InvokeWith).
11125 return this->InvokeWith(ArgumentTuple(a1, a2, a3));
11126 }
11127};
11128
11129template <typename R, typename A1, typename A2, typename A3, typename A4>
11130class FunctionMocker<R(A1, A2, A3, A4)> : public
11131 internal::FunctionMockerBase<R(A1, A2, A3, A4)> {
11132 public:
11133 typedef R F(A1, A2, A3, A4);
11134 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
11135
11136 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
11137 const Matcher<A3>& m3, const Matcher<A4>& m4) {
11138 this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3, m4));
11139 return this->current_spec();
11140 }
11141
11142 R Invoke(A1 a1, A2 a2, A3 a3, A4 a4) {
11143 // Even though gcc and MSVC don't enforce it, 'this->' is required
11144 // by the C++ standard [14.6.4] here, as the base class type is
11145 // dependent on the template argument (and thus shouldn't be
11146 // looked into when resolving InvokeWith).
11147 return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4));
11148 }
11149};
11150
11151template <typename R, typename A1, typename A2, typename A3, typename A4,
11152 typename A5>
11153class FunctionMocker<R(A1, A2, A3, A4, A5)> : public
11154 internal::FunctionMockerBase<R(A1, A2, A3, A4, A5)> {
11155 public:
11156 typedef R F(A1, A2, A3, A4, A5);
11157 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
11158
11159 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
11160 const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5) {
11161 this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3, m4, m5));
11162 return this->current_spec();
11163 }
11164
11165 R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) {
11166 // Even though gcc and MSVC don't enforce it, 'this->' is required
11167 // by the C++ standard [14.6.4] here, as the base class type is
11168 // dependent on the template argument (and thus shouldn't be
11169 // looked into when resolving InvokeWith).
11170 return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5));
11171 }
11172};
11173
11174template <typename R, typename A1, typename A2, typename A3, typename A4,
11175 typename A5, typename A6>
11176class FunctionMocker<R(A1, A2, A3, A4, A5, A6)> : public
11177 internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6)> {
11178 public:
11179 typedef R F(A1, A2, A3, A4, A5, A6);
11180 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
11181
11182 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
11183 const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5,
11184 const Matcher<A6>& m6) {
11185 this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3, m4, m5,
11186 m6));
11187 return this->current_spec();
11188 }
11189
11190 R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) {
11191 // Even though gcc and MSVC don't enforce it, 'this->' is required
11192 // by the C++ standard [14.6.4] here, as the base class type is
11193 // dependent on the template argument (and thus shouldn't be
11194 // looked into when resolving InvokeWith).
11195 return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6));
11196 }
11197};
11198
11199template <typename R, typename A1, typename A2, typename A3, typename A4,
11200 typename A5, typename A6, typename A7>
11201class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7)> : public
11202 internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6, A7)> {
11203 public:
11204 typedef R F(A1, A2, A3, A4, A5, A6, A7);
11205 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
11206
11207 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
11208 const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5,
11209 const Matcher<A6>& m6, const Matcher<A7>& m7) {
11210 this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3, m4, m5,
11211 m6, m7));
11212 return this->current_spec();
11213 }
11214
11215 R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) {
11216 // Even though gcc and MSVC don't enforce it, 'this->' is required
11217 // by the C++ standard [14.6.4] here, as the base class type is
11218 // dependent on the template argument (and thus shouldn't be
11219 // looked into when resolving InvokeWith).
11220 return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7));
11221 }
11222};
11223
11224template <typename R, typename A1, typename A2, typename A3, typename A4,
11225 typename A5, typename A6, typename A7, typename A8>
11226class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8)> : public
11227 internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6, A7, A8)> {
11228 public:
11229 typedef R F(A1, A2, A3, A4, A5, A6, A7, A8);
11230 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
11231
11232 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
11233 const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5,
11234 const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8) {
11235 this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3, m4, m5,
11236 m6, m7, m8));
11237 return this->current_spec();
11238 }
11239
11240 R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) {
11241 // Even though gcc and MSVC don't enforce it, 'this->' is required
11242 // by the C++ standard [14.6.4] here, as the base class type is
11243 // dependent on the template argument (and thus shouldn't be
11244 // looked into when resolving InvokeWith).
11245 return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8));
11246 }
11247};
11248
11249template <typename R, typename A1, typename A2, typename A3, typename A4,
11250 typename A5, typename A6, typename A7, typename A8, typename A9>
11251class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> : public
11252 internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> {
11253 public:
11254 typedef R F(A1, A2, A3, A4, A5, A6, A7, A8, A9);
11255 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
11256
11257 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
11258 const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5,
11259 const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8,
11260 const Matcher<A9>& m9) {
11261 this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3, m4, m5,
11262 m6, m7, m8, m9));
11263 return this->current_spec();
11264 }
11265
11266 R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) {
11267 // Even though gcc and MSVC don't enforce it, 'this->' is required
11268 // by the C++ standard [14.6.4] here, as the base class type is
11269 // dependent on the template argument (and thus shouldn't be
11270 // looked into when resolving InvokeWith).
11271 return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8, a9));
11272 }
11273};
11274
11275template <typename R, typename A1, typename A2, typename A3, typename A4,
11276 typename A5, typename A6, typename A7, typename A8, typename A9,
11277 typename A10>
11278class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> : public
11279 internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> {
11280 public:
11281 typedef R F(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10);
11282 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
11283
11284 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
11285 const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5,
11286 const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8,
11287 const Matcher<A9>& m9, const Matcher<A10>& m10) {
11288 this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3, m4, m5,
11289 m6, m7, m8, m9, m10));
11290 return this->current_spec();
11291 }
11292
11293 R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9,
11294 A10 a10) {
11295 // Even though gcc and MSVC don't enforce it, 'this->' is required
11296 // by the C++ standard [14.6.4] here, as the base class type is
11297 // dependent on the template argument (and thus shouldn't be
11298 // looked into when resolving InvokeWith).
11299 return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8, a9,
11300 a10));
11301 }
11302};
11303
11304} // namespace internal
11305
11306// The style guide prohibits "using" statements in a namespace scope
11307// inside a header file. However, the FunctionMocker class template
11308// is meant to be defined in the ::testing namespace. The following
11309// line is just a trick for working around a bug in MSVC 8.0, which
11310// cannot handle it if we define FunctionMocker in ::testing.
11311using internal::FunctionMocker;
11312
11313// GMOCK_RESULT_(tn, F) expands to the result type of function type F.
11314// We define this as a variadic macro in case F contains unprotected
11315// commas (the same reason that we use variadic macros in other places
11316// in this file).
11317// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
11318#define GMOCK_RESULT_(tn, ...) \
11319 tn ::testing::internal::Function<__VA_ARGS__>::Result
11320
11321// The type of argument N of the given function type.
11322// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
11323#define GMOCK_ARG_(tn, N, ...) \
11324 tn ::testing::internal::Function<__VA_ARGS__>::Argument##N
11325
11326// The matcher type for argument N of the given function type.
11327// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
11328#define GMOCK_MATCHER_(tn, N, ...) \
11329 const ::testing::Matcher<GMOCK_ARG_(tn, N, __VA_ARGS__)>&
11330
11331// The variable for mocking the given method.
11332// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
11333#define GMOCK_MOCKER_(arity, constness, Method) \
11334 GTEST_CONCAT_TOKEN_(gmock##constness##arity##_##Method##_, __LINE__)
11335
11336// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
11337#define GMOCK_METHOD0_(tn, constness, ct, Method, ...) \
11338 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
11339 ) constness { \
11340 GTEST_COMPILE_ASSERT_((::testing::tuple_size< \
11341 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
11342 == 0), \
11343 this_method_does_not_take_0_arguments); \
11344 GMOCK_MOCKER_(0, constness, Method).SetOwnerAndName(this, #Method); \
11345 return GMOCK_MOCKER_(0, constness, Method).Invoke(); \
11346 } \
11347 ::testing::MockSpec<__VA_ARGS__>& \
11348 gmock_##Method() constness { \
11349 GMOCK_MOCKER_(0, constness, Method).RegisterOwner(this); \
11350 return GMOCK_MOCKER_(0, constness, Method).With(); \
11351 } \
11352 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(0, constness, \
11353 Method)
11354
11355// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
11356#define GMOCK_METHOD1_(tn, constness, ct, Method, ...) \
11357 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
11358 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1) constness { \
11359 GTEST_COMPILE_ASSERT_((::testing::tuple_size< \
11360 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
11361 == 1), \
11362 this_method_does_not_take_1_argument); \
11363 GMOCK_MOCKER_(1, constness, Method).SetOwnerAndName(this, #Method); \
11364 return GMOCK_MOCKER_(1, constness, Method).Invoke(gmock_a1); \
11365 } \
11366 ::testing::MockSpec<__VA_ARGS__>& \
11367 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1) constness { \
11368 GMOCK_MOCKER_(1, constness, Method).RegisterOwner(this); \
11369 return GMOCK_MOCKER_(1, constness, Method).With(gmock_a1); \
11370 } \
11371 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(1, constness, \
11372 Method)
11373
11374// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
11375#define GMOCK_METHOD2_(tn, constness, ct, Method, ...) \
11376 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
11377 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
11378 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2) constness { \
11379 GTEST_COMPILE_ASSERT_((::testing::tuple_size< \
11380 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
11381 == 2), \
11382 this_method_does_not_take_2_arguments); \
11383 GMOCK_MOCKER_(2, constness, Method).SetOwnerAndName(this, #Method); \
11384 return GMOCK_MOCKER_(2, constness, Method).Invoke(gmock_a1, gmock_a2); \
11385 } \
11386 ::testing::MockSpec<__VA_ARGS__>& \
11387 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
11388 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2) constness { \
11389 GMOCK_MOCKER_(2, constness, Method).RegisterOwner(this); \
11390 return GMOCK_MOCKER_(2, constness, Method).With(gmock_a1, gmock_a2); \
11391 } \
11392 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(2, constness, \
11393 Method)
11394
11395// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
11396#define GMOCK_METHOD3_(tn, constness, ct, Method, ...) \
11397 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
11398 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
11399 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
11400 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3) constness { \
11401 GTEST_COMPILE_ASSERT_((::testing::tuple_size< \
11402 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
11403 == 3), \
11404 this_method_does_not_take_3_arguments); \
11405 GMOCK_MOCKER_(3, constness, Method).SetOwnerAndName(this, #Method); \
11406 return GMOCK_MOCKER_(3, constness, Method).Invoke(gmock_a1, gmock_a2, \
11407 gmock_a3); \
11408 } \
11409 ::testing::MockSpec<__VA_ARGS__>& \
11410 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
11411 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
11412 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3) constness { \
11413 GMOCK_MOCKER_(3, constness, Method).RegisterOwner(this); \
11414 return GMOCK_MOCKER_(3, constness, Method).With(gmock_a1, gmock_a2, \
11415 gmock_a3); \
11416 } \
11417 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(3, constness, \
11418 Method)
11419
11420// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
11421#define GMOCK_METHOD4_(tn, constness, ct, Method, ...) \
11422 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
11423 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
11424 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
11425 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
11426 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4) constness { \
11427 GTEST_COMPILE_ASSERT_((::testing::tuple_size< \
11428 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
11429 == 4), \
11430 this_method_does_not_take_4_arguments); \
11431 GMOCK_MOCKER_(4, constness, Method).SetOwnerAndName(this, #Method); \
11432 return GMOCK_MOCKER_(4, constness, Method).Invoke(gmock_a1, gmock_a2, \
11433 gmock_a3, gmock_a4); \
11434 } \
11435 ::testing::MockSpec<__VA_ARGS__>& \
11436 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
11437 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
11438 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
11439 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4) constness { \
11440 GMOCK_MOCKER_(4, constness, Method).RegisterOwner(this); \
11441 return GMOCK_MOCKER_(4, constness, Method).With(gmock_a1, gmock_a2, \
11442 gmock_a3, gmock_a4); \
11443 } \
11444 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(4, constness, \
11445 Method)
11446
11447// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
11448#define GMOCK_METHOD5_(tn, constness, ct, Method, ...) \
11449 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
11450 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
11451 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
11452 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
11453 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \
11454 GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5) constness { \
11455 GTEST_COMPILE_ASSERT_((::testing::tuple_size< \
11456 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
11457 == 5), \
11458 this_method_does_not_take_5_arguments); \
11459 GMOCK_MOCKER_(5, constness, Method).SetOwnerAndName(this, #Method); \
11460 return GMOCK_MOCKER_(5, constness, Method).Invoke(gmock_a1, gmock_a2, \
11461 gmock_a3, gmock_a4, gmock_a5); \
11462 } \
11463 ::testing::MockSpec<__VA_ARGS__>& \
11464 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
11465 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
11466 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
11467 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
11468 GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5) constness { \
11469 GMOCK_MOCKER_(5, constness, Method).RegisterOwner(this); \
11470 return GMOCK_MOCKER_(5, constness, Method).With(gmock_a1, gmock_a2, \
11471 gmock_a3, gmock_a4, gmock_a5); \
11472 } \
11473 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(5, constness, \
11474 Method)
11475
11476// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
11477#define GMOCK_METHOD6_(tn, constness, ct, Method, ...) \
11478 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
11479 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
11480 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
11481 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
11482 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \
11483 GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \
11484 GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6) constness { \
11485 GTEST_COMPILE_ASSERT_((::testing::tuple_size< \
11486 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
11487 == 6), \
11488 this_method_does_not_take_6_arguments); \
11489 GMOCK_MOCKER_(6, constness, Method).SetOwnerAndName(this, #Method); \
11490 return GMOCK_MOCKER_(6, constness, Method).Invoke(gmock_a1, gmock_a2, \
11491 gmock_a3, gmock_a4, gmock_a5, gmock_a6); \
11492 } \
11493 ::testing::MockSpec<__VA_ARGS__>& \
11494 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
11495 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
11496 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
11497 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
11498 GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \
11499 GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6) constness { \
11500 GMOCK_MOCKER_(6, constness, Method).RegisterOwner(this); \
11501 return GMOCK_MOCKER_(6, constness, Method).With(gmock_a1, gmock_a2, \
11502 gmock_a3, gmock_a4, gmock_a5, gmock_a6); \
11503 } \
11504 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(6, constness, \
11505 Method)
11506
11507// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
11508#define GMOCK_METHOD7_(tn, constness, ct, Method, ...) \
11509 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
11510 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
11511 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
11512 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
11513 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \
11514 GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \
11515 GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
11516 GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7) constness { \
11517 GTEST_COMPILE_ASSERT_((::testing::tuple_size< \
11518 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
11519 == 7), \
11520 this_method_does_not_take_7_arguments); \
11521 GMOCK_MOCKER_(7, constness, Method).SetOwnerAndName(this, #Method); \
11522 return GMOCK_MOCKER_(7, constness, Method).Invoke(gmock_a1, gmock_a2, \
11523 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7); \
11524 } \
11525 ::testing::MockSpec<__VA_ARGS__>& \
11526 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
11527 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
11528 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
11529 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
11530 GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \
11531 GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \
11532 GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7) constness { \
11533 GMOCK_MOCKER_(7, constness, Method).RegisterOwner(this); \
11534 return GMOCK_MOCKER_(7, constness, Method).With(gmock_a1, gmock_a2, \
11535 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7); \
11536 } \
11537 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(7, constness, \
11538 Method)
11539
11540// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
11541#define GMOCK_METHOD8_(tn, constness, ct, Method, ...) \
11542 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
11543 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
11544 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
11545 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
11546 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \
11547 GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \
11548 GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
11549 GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \
11550 GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8) constness { \
11551 GTEST_COMPILE_ASSERT_((::testing::tuple_size< \
11552 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
11553 == 8), \
11554 this_method_does_not_take_8_arguments); \
11555 GMOCK_MOCKER_(8, constness, Method).SetOwnerAndName(this, #Method); \
11556 return GMOCK_MOCKER_(8, constness, Method).Invoke(gmock_a1, gmock_a2, \
11557 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8); \
11558 } \
11559 ::testing::MockSpec<__VA_ARGS__>& \
11560 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
11561 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
11562 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
11563 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
11564 GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \
11565 GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \
11566 GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \
11567 GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8) constness { \
11568 GMOCK_MOCKER_(8, constness, Method).RegisterOwner(this); \
11569 return GMOCK_MOCKER_(8, constness, Method).With(gmock_a1, gmock_a2, \
11570 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8); \
11571 } \
11572 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(8, constness, \
11573 Method)
11574
11575// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
11576#define GMOCK_METHOD9_(tn, constness, ct, Method, ...) \
11577 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
11578 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
11579 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
11580 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
11581 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \
11582 GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \
11583 GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
11584 GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \
11585 GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8, \
11586 GMOCK_ARG_(tn, 9, __VA_ARGS__) gmock_a9) constness { \
11587 GTEST_COMPILE_ASSERT_((::testing::tuple_size< \
11588 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
11589 == 9), \
11590 this_method_does_not_take_9_arguments); \
11591 GMOCK_MOCKER_(9, constness, Method).SetOwnerAndName(this, #Method); \
11592 return GMOCK_MOCKER_(9, constness, Method).Invoke(gmock_a1, gmock_a2, \
11593 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, \
11594 gmock_a9); \
11595 } \
11596 ::testing::MockSpec<__VA_ARGS__>& \
11597 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
11598 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
11599 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
11600 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
11601 GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \
11602 GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \
11603 GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \
11604 GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8, \
11605 GMOCK_MATCHER_(tn, 9, __VA_ARGS__) gmock_a9) constness { \
11606 GMOCK_MOCKER_(9, constness, Method).RegisterOwner(this); \
11607 return GMOCK_MOCKER_(9, constness, Method).With(gmock_a1, gmock_a2, \
11608 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, \
11609 gmock_a9); \
11610 } \
11611 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(9, constness, \
11612 Method)
11613
11614// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
11615#define GMOCK_METHOD10_(tn, constness, ct, Method, ...) \
11616 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
11617 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
11618 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
11619 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
11620 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \
11621 GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \
11622 GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
11623 GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \
11624 GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8, \
11625 GMOCK_ARG_(tn, 9, __VA_ARGS__) gmock_a9, \
11626 GMOCK_ARG_(tn, 10, __VA_ARGS__) gmock_a10) constness { \
11627 GTEST_COMPILE_ASSERT_((::testing::tuple_size< \
11628 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
11629 == 10), \
11630 this_method_does_not_take_10_arguments); \
11631 GMOCK_MOCKER_(10, constness, Method).SetOwnerAndName(this, #Method); \
11632 return GMOCK_MOCKER_(10, constness, Method).Invoke(gmock_a1, gmock_a2, \
11633 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, gmock_a9, \
11634 gmock_a10); \
11635 } \
11636 ::testing::MockSpec<__VA_ARGS__>& \
11637 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
11638 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
11639 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
11640 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
11641 GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \
11642 GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \
11643 GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \
11644 GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8, \
11645 GMOCK_MATCHER_(tn, 9, __VA_ARGS__) gmock_a9, \
11646 GMOCK_MATCHER_(tn, 10, \
11647 __VA_ARGS__) gmock_a10) constness { \
11648 GMOCK_MOCKER_(10, constness, Method).RegisterOwner(this); \
11649 return GMOCK_MOCKER_(10, constness, Method).With(gmock_a1, gmock_a2, \
11650 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, gmock_a9, \
11651 gmock_a10); \
11652 } \
11653 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(10, constness, \
11654 Method)
11655
11656#define MOCK_METHOD0(m, ...) GMOCK_METHOD0_(, , , m, __VA_ARGS__)
11657#define MOCK_METHOD1(m, ...) GMOCK_METHOD1_(, , , m, __VA_ARGS__)
11658#define MOCK_METHOD2(m, ...) GMOCK_METHOD2_(, , , m, __VA_ARGS__)
11659#define MOCK_METHOD3(m, ...) GMOCK_METHOD3_(, , , m, __VA_ARGS__)
11660#define MOCK_METHOD4(m, ...) GMOCK_METHOD4_(, , , m, __VA_ARGS__)
11661#define MOCK_METHOD5(m, ...) GMOCK_METHOD5_(, , , m, __VA_ARGS__)
11662#define MOCK_METHOD6(m, ...) GMOCK_METHOD6_(, , , m, __VA_ARGS__)
11663#define MOCK_METHOD7(m, ...) GMOCK_METHOD7_(, , , m, __VA_ARGS__)
11664#define MOCK_METHOD8(m, ...) GMOCK_METHOD8_(, , , m, __VA_ARGS__)
11665#define MOCK_METHOD9(m, ...) GMOCK_METHOD9_(, , , m, __VA_ARGS__)
11666#define MOCK_METHOD10(m, ...) GMOCK_METHOD10_(, , , m, __VA_ARGS__)
11667
11668#define MOCK_CONST_METHOD0(m, ...) GMOCK_METHOD0_(, const, , m, __VA_ARGS__)
11669#define MOCK_CONST_METHOD1(m, ...) GMOCK_METHOD1_(, const, , m, __VA_ARGS__)
11670#define MOCK_CONST_METHOD2(m, ...) GMOCK_METHOD2_(, const, , m, __VA_ARGS__)
11671#define MOCK_CONST_METHOD3(m, ...) GMOCK_METHOD3_(, const, , m, __VA_ARGS__)
11672#define MOCK_CONST_METHOD4(m, ...) GMOCK_METHOD4_(, const, , m, __VA_ARGS__)
11673#define MOCK_CONST_METHOD5(m, ...) GMOCK_METHOD5_(, const, , m, __VA_ARGS__)
11674#define MOCK_CONST_METHOD6(m, ...) GMOCK_METHOD6_(, const, , m, __VA_ARGS__)
11675#define MOCK_CONST_METHOD7(m, ...) GMOCK_METHOD7_(, const, , m, __VA_ARGS__)
11676#define MOCK_CONST_METHOD8(m, ...) GMOCK_METHOD8_(, const, , m, __VA_ARGS__)
11677#define MOCK_CONST_METHOD9(m, ...) GMOCK_METHOD9_(, const, , m, __VA_ARGS__)
11678#define MOCK_CONST_METHOD10(m, ...) GMOCK_METHOD10_(, const, , m, __VA_ARGS__)
11679
11680#define MOCK_METHOD0_T(m, ...) GMOCK_METHOD0_(typename, , , m, __VA_ARGS__)
11681#define MOCK_METHOD1_T(m, ...) GMOCK_METHOD1_(typename, , , m, __VA_ARGS__)
11682#define MOCK_METHOD2_T(m, ...) GMOCK_METHOD2_(typename, , , m, __VA_ARGS__)
11683#define MOCK_METHOD3_T(m, ...) GMOCK_METHOD3_(typename, , , m, __VA_ARGS__)
11684#define MOCK_METHOD4_T(m, ...) GMOCK_METHOD4_(typename, , , m, __VA_ARGS__)
11685#define MOCK_METHOD5_T(m, ...) GMOCK_METHOD5_(typename, , , m, __VA_ARGS__)
11686#define MOCK_METHOD6_T(m, ...) GMOCK_METHOD6_(typename, , , m, __VA_ARGS__)
11687#define MOCK_METHOD7_T(m, ...) GMOCK_METHOD7_(typename, , , m, __VA_ARGS__)
11688#define MOCK_METHOD8_T(m, ...) GMOCK_METHOD8_(typename, , , m, __VA_ARGS__)
11689#define MOCK_METHOD9_T(m, ...) GMOCK_METHOD9_(typename, , , m, __VA_ARGS__)
11690#define MOCK_METHOD10_T(m, ...) GMOCK_METHOD10_(typename, , , m, __VA_ARGS__)
11691
11692#define MOCK_CONST_METHOD0_T(m, ...) \
11693 GMOCK_METHOD0_(typename, const, , m, __VA_ARGS__)
11694#define MOCK_CONST_METHOD1_T(m, ...) \
11695 GMOCK_METHOD1_(typename, const, , m, __VA_ARGS__)
11696#define MOCK_CONST_METHOD2_T(m, ...) \
11697 GMOCK_METHOD2_(typename, const, , m, __VA_ARGS__)
11698#define MOCK_CONST_METHOD3_T(m, ...) \
11699 GMOCK_METHOD3_(typename, const, , m, __VA_ARGS__)
11700#define MOCK_CONST_METHOD4_T(m, ...) \
11701 GMOCK_METHOD4_(typename, const, , m, __VA_ARGS__)
11702#define MOCK_CONST_METHOD5_T(m, ...) \
11703 GMOCK_METHOD5_(typename, const, , m, __VA_ARGS__)
11704#define MOCK_CONST_METHOD6_T(m, ...) \
11705 GMOCK_METHOD6_(typename, const, , m, __VA_ARGS__)
11706#define MOCK_CONST_METHOD7_T(m, ...) \
11707 GMOCK_METHOD7_(typename, const, , m, __VA_ARGS__)
11708#define MOCK_CONST_METHOD8_T(m, ...) \
11709 GMOCK_METHOD8_(typename, const, , m, __VA_ARGS__)
11710#define MOCK_CONST_METHOD9_T(m, ...) \
11711 GMOCK_METHOD9_(typename, const, , m, __VA_ARGS__)
11712#define MOCK_CONST_METHOD10_T(m, ...) \
11713 GMOCK_METHOD10_(typename, const, , m, __VA_ARGS__)
11714
11715#define MOCK_METHOD0_WITH_CALLTYPE(ct, m, ...) \
11716 GMOCK_METHOD0_(, , ct, m, __VA_ARGS__)
11717#define MOCK_METHOD1_WITH_CALLTYPE(ct, m, ...) \
11718 GMOCK_METHOD1_(, , ct, m, __VA_ARGS__)
11719#define MOCK_METHOD2_WITH_CALLTYPE(ct, m, ...) \
11720 GMOCK_METHOD2_(, , ct, m, __VA_ARGS__)
11721#define MOCK_METHOD3_WITH_CALLTYPE(ct, m, ...) \
11722 GMOCK_METHOD3_(, , ct, m, __VA_ARGS__)
11723#define MOCK_METHOD4_WITH_CALLTYPE(ct, m, ...) \
11724 GMOCK_METHOD4_(, , ct, m, __VA_ARGS__)
11725#define MOCK_METHOD5_WITH_CALLTYPE(ct, m, ...) \
11726 GMOCK_METHOD5_(, , ct, m, __VA_ARGS__)
11727#define MOCK_METHOD6_WITH_CALLTYPE(ct, m, ...) \
11728 GMOCK_METHOD6_(, , ct, m, __VA_ARGS__)
11729#define MOCK_METHOD7_WITH_CALLTYPE(ct, m, ...) \
11730 GMOCK_METHOD7_(, , ct, m, __VA_ARGS__)
11731#define MOCK_METHOD8_WITH_CALLTYPE(ct, m, ...) \
11732 GMOCK_METHOD8_(, , ct, m, __VA_ARGS__)
11733#define MOCK_METHOD9_WITH_CALLTYPE(ct, m, ...) \
11734 GMOCK_METHOD9_(, , ct, m, __VA_ARGS__)
11735#define MOCK_METHOD10_WITH_CALLTYPE(ct, m, ...) \
11736 GMOCK_METHOD10_(, , ct, m, __VA_ARGS__)
11737
11738#define MOCK_CONST_METHOD0_WITH_CALLTYPE(ct, m, ...) \
11739 GMOCK_METHOD0_(, const, ct, m, __VA_ARGS__)
11740#define MOCK_CONST_METHOD1_WITH_CALLTYPE(ct, m, ...) \
11741 GMOCK_METHOD1_(, const, ct, m, __VA_ARGS__)
11742#define MOCK_CONST_METHOD2_WITH_CALLTYPE(ct, m, ...) \
11743 GMOCK_METHOD2_(, const, ct, m, __VA_ARGS__)
11744#define MOCK_CONST_METHOD3_WITH_CALLTYPE(ct, m, ...) \
11745 GMOCK_METHOD3_(, const, ct, m, __VA_ARGS__)
11746#define MOCK_CONST_METHOD4_WITH_CALLTYPE(ct, m, ...) \
11747 GMOCK_METHOD4_(, const, ct, m, __VA_ARGS__)
11748#define MOCK_CONST_METHOD5_WITH_CALLTYPE(ct, m, ...) \
11749 GMOCK_METHOD5_(, const, ct, m, __VA_ARGS__)
11750#define MOCK_CONST_METHOD6_WITH_CALLTYPE(ct, m, ...) \
11751 GMOCK_METHOD6_(, const, ct, m, __VA_ARGS__)
11752#define MOCK_CONST_METHOD7_WITH_CALLTYPE(ct, m, ...) \
11753 GMOCK_METHOD7_(, const, ct, m, __VA_ARGS__)
11754#define MOCK_CONST_METHOD8_WITH_CALLTYPE(ct, m, ...) \
11755 GMOCK_METHOD8_(, const, ct, m, __VA_ARGS__)
11756#define MOCK_CONST_METHOD9_WITH_CALLTYPE(ct, m, ...) \
11757 GMOCK_METHOD9_(, const, ct, m, __VA_ARGS__)
11758#define MOCK_CONST_METHOD10_WITH_CALLTYPE(ct, m, ...) \
11759 GMOCK_METHOD10_(, const, ct, m, __VA_ARGS__)
11760
11761#define MOCK_METHOD0_T_WITH_CALLTYPE(ct, m, ...) \
11762 GMOCK_METHOD0_(typename, , ct, m, __VA_ARGS__)
11763#define MOCK_METHOD1_T_WITH_CALLTYPE(ct, m, ...) \
11764 GMOCK_METHOD1_(typename, , ct, m, __VA_ARGS__)
11765#define MOCK_METHOD2_T_WITH_CALLTYPE(ct, m, ...) \
11766 GMOCK_METHOD2_(typename, , ct, m, __VA_ARGS__)
11767#define MOCK_METHOD3_T_WITH_CALLTYPE(ct, m, ...) \
11768 GMOCK_METHOD3_(typename, , ct, m, __VA_ARGS__)
11769#define MOCK_METHOD4_T_WITH_CALLTYPE(ct, m, ...) \
11770 GMOCK_METHOD4_(typename, , ct, m, __VA_ARGS__)
11771#define MOCK_METHOD5_T_WITH_CALLTYPE(ct, m, ...) \
11772 GMOCK_METHOD5_(typename, , ct, m, __VA_ARGS__)
11773#define MOCK_METHOD6_T_WITH_CALLTYPE(ct, m, ...) \
11774 GMOCK_METHOD6_(typename, , ct, m, __VA_ARGS__)
11775#define MOCK_METHOD7_T_WITH_CALLTYPE(ct, m, ...) \
11776 GMOCK_METHOD7_(typename, , ct, m, __VA_ARGS__)
11777#define MOCK_METHOD8_T_WITH_CALLTYPE(ct, m, ...) \
11778 GMOCK_METHOD8_(typename, , ct, m, __VA_ARGS__)
11779#define MOCK_METHOD9_T_WITH_CALLTYPE(ct, m, ...) \
11780 GMOCK_METHOD9_(typename, , ct, m, __VA_ARGS__)
11781#define MOCK_METHOD10_T_WITH_CALLTYPE(ct, m, ...) \
11782 GMOCK_METHOD10_(typename, , ct, m, __VA_ARGS__)
11783
11784#define MOCK_CONST_METHOD0_T_WITH_CALLTYPE(ct, m, ...) \
11785 GMOCK_METHOD0_(typename, const, ct, m, __VA_ARGS__)
11786#define MOCK_CONST_METHOD1_T_WITH_CALLTYPE(ct, m, ...) \
11787 GMOCK_METHOD1_(typename, const, ct, m, __VA_ARGS__)
11788#define MOCK_CONST_METHOD2_T_WITH_CALLTYPE(ct, m, ...) \
11789 GMOCK_METHOD2_(typename, const, ct, m, __VA_ARGS__)
11790#define MOCK_CONST_METHOD3_T_WITH_CALLTYPE(ct, m, ...) \
11791 GMOCK_METHOD3_(typename, const, ct, m, __VA_ARGS__)
11792#define MOCK_CONST_METHOD4_T_WITH_CALLTYPE(ct, m, ...) \
11793 GMOCK_METHOD4_(typename, const, ct, m, __VA_ARGS__)
11794#define MOCK_CONST_METHOD5_T_WITH_CALLTYPE(ct, m, ...) \
11795 GMOCK_METHOD5_(typename, const, ct, m, __VA_ARGS__)
11796#define MOCK_CONST_METHOD6_T_WITH_CALLTYPE(ct, m, ...) \
11797 GMOCK_METHOD6_(typename, const, ct, m, __VA_ARGS__)
11798#define MOCK_CONST_METHOD7_T_WITH_CALLTYPE(ct, m, ...) \
11799 GMOCK_METHOD7_(typename, const, ct, m, __VA_ARGS__)
11800#define MOCK_CONST_METHOD8_T_WITH_CALLTYPE(ct, m, ...) \
11801 GMOCK_METHOD8_(typename, const, ct, m, __VA_ARGS__)
11802#define MOCK_CONST_METHOD9_T_WITH_CALLTYPE(ct, m, ...) \
11803 GMOCK_METHOD9_(typename, const, ct, m, __VA_ARGS__)
11804#define MOCK_CONST_METHOD10_T_WITH_CALLTYPE(ct, m, ...) \
11805 GMOCK_METHOD10_(typename, const, ct, m, __VA_ARGS__)
11806
11807// A MockFunction<F> class has one mock method whose type is F. It is
11808// useful when you just want your test code to emit some messages and
11809// have Google Mock verify the right messages are sent (and perhaps at
11810// the right times). For example, if you are exercising code:
11811//
11812// Foo(1);
11813// Foo(2);
11814// Foo(3);
11815//
11816// and want to verify that Foo(1) and Foo(3) both invoke
11817// mock.Bar("a"), but Foo(2) doesn't invoke anything, you can write:
11818//
11819// TEST(FooTest, InvokesBarCorrectly) {
11820// MyMock mock;
11821// MockFunction<void(string check_point_name)> check;
11822// {
11823// InSequence s;
11824//
11825// EXPECT_CALL(mock, Bar("a"));
11826// EXPECT_CALL(check, Call("1"));
11827// EXPECT_CALL(check, Call("2"));
11828// EXPECT_CALL(mock, Bar("a"));
11829// }
11830// Foo(1);
11831// check.Call("1");
11832// Foo(2);
11833// check.Call("2");
11834// Foo(3);
11835// }
11836//
11837// The expectation spec says that the first Bar("a") must happen
11838// before check point "1", the second Bar("a") must happen after check
11839// point "2", and nothing should happen between the two check
11840// points. The explicit check points make it easy to tell which
11841// Bar("a") is called by which call to Foo().
11842//
11843// MockFunction<F> can also be used to exercise code that accepts
11844// std::function<F> callbacks. To do so, use AsStdFunction() method
11845// to create std::function proxy forwarding to original object's Call.
11846// Example:
11847//
11848// TEST(FooTest, RunsCallbackWithBarArgument) {
11849// MockFunction<int(string)> callback;
11850// EXPECT_CALL(callback, Call("bar")).WillOnce(Return(1));
11851// Foo(callback.AsStdFunction());
11852// }
11853template <typename F>
11854class MockFunction;
11855
11856template <typename R>
11857class MockFunction<R()> {
11858 public:
11859 MockFunction() {}
11860
11861 MOCK_METHOD0_T(Call, R());
11862
11863#if GTEST_HAS_STD_FUNCTION_
11864 std::function<R()> AsStdFunction() {
11865 return [this]() -> R {
11866 return this->Call();
11867 };
11868 }
11869#endif // GTEST_HAS_STD_FUNCTION_
11870
11871 private:
11872 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11873};
11874
11875template <typename R, typename A0>
11876class MockFunction<R(A0)> {
11877 public:
11878 MockFunction() {}
11879
11880 MOCK_METHOD1_T(Call, R(A0));
11881
11882#if GTEST_HAS_STD_FUNCTION_
11883 std::function<R(A0)> AsStdFunction() {
11884 return [this](A0 a0) -> R {
11885 return this->Call(a0);
11886 };
11887 }
11888#endif // GTEST_HAS_STD_FUNCTION_
11889
11890 private:
11891 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11892};
11893
11894template <typename R, typename A0, typename A1>
11895class MockFunction<R(A0, A1)> {
11896 public:
11897 MockFunction() {}
11898
11899 MOCK_METHOD2_T(Call, R(A0, A1));
11900
11901#if GTEST_HAS_STD_FUNCTION_
11902 std::function<R(A0, A1)> AsStdFunction() {
11903 return [this](A0 a0, A1 a1) -> R {
11904 return this->Call(a0, a1);
11905 };
11906 }
11907#endif // GTEST_HAS_STD_FUNCTION_
11908
11909 private:
11910 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11911};
11912
11913template <typename R, typename A0, typename A1, typename A2>
11914class MockFunction<R(A0, A1, A2)> {
11915 public:
11916 MockFunction() {}
11917
11918 MOCK_METHOD3_T(Call, R(A0, A1, A2));
11919
11920#if GTEST_HAS_STD_FUNCTION_
11921 std::function<R(A0, A1, A2)> AsStdFunction() {
11922 return [this](A0 a0, A1 a1, A2 a2) -> R {
11923 return this->Call(a0, a1, a2);
11924 };
11925 }
11926#endif // GTEST_HAS_STD_FUNCTION_
11927
11928 private:
11929 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11930};
11931
11932template <typename R, typename A0, typename A1, typename A2, typename A3>
11933class MockFunction<R(A0, A1, A2, A3)> {
11934 public:
11935 MockFunction() {}
11936
11937 MOCK_METHOD4_T(Call, R(A0, A1, A2, A3));
11938
11939#if GTEST_HAS_STD_FUNCTION_
11940 std::function<R(A0, A1, A2, A3)> AsStdFunction() {
11941 return [this](A0 a0, A1 a1, A2 a2, A3 a3) -> R {
11942 return this->Call(a0, a1, a2, a3);
11943 };
11944 }
11945#endif // GTEST_HAS_STD_FUNCTION_
11946
11947 private:
11948 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11949};
11950
11951template <typename R, typename A0, typename A1, typename A2, typename A3,
11952 typename A4>
11953class MockFunction<R(A0, A1, A2, A3, A4)> {
11954 public:
11955 MockFunction() {}
11956
11957 MOCK_METHOD5_T(Call, R(A0, A1, A2, A3, A4));
11958
11959#if GTEST_HAS_STD_FUNCTION_
11960 std::function<R(A0, A1, A2, A3, A4)> AsStdFunction() {
11961 return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) -> R {
11962 return this->Call(a0, a1, a2, a3, a4);
11963 };
11964 }
11965#endif // GTEST_HAS_STD_FUNCTION_
11966
11967 private:
11968 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11969};
11970
11971template <typename R, typename A0, typename A1, typename A2, typename A3,
11972 typename A4, typename A5>
11973class MockFunction<R(A0, A1, A2, A3, A4, A5)> {
11974 public:
11975 MockFunction() {}
11976
11977 MOCK_METHOD6_T(Call, R(A0, A1, A2, A3, A4, A5));
11978
11979#if GTEST_HAS_STD_FUNCTION_
11980 std::function<R(A0, A1, A2, A3, A4, A5)> AsStdFunction() {
11981 return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) -> R {
11982 return this->Call(a0, a1, a2, a3, a4, a5);
11983 };
11984 }
11985#endif // GTEST_HAS_STD_FUNCTION_
11986
11987 private:
11988 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11989};
11990
11991template <typename R, typename A0, typename A1, typename A2, typename A3,
11992 typename A4, typename A5, typename A6>
11993class MockFunction<R(A0, A1, A2, A3, A4, A5, A6)> {
11994 public:
11995 MockFunction() {}
11996
11997 MOCK_METHOD7_T(Call, R(A0, A1, A2, A3, A4, A5, A6));
11998
11999#if GTEST_HAS_STD_FUNCTION_
12000 std::function<R(A0, A1, A2, A3, A4, A5, A6)> AsStdFunction() {
12001 return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) -> R {
12002 return this->Call(a0, a1, a2, a3, a4, a5, a6);
12003 };
12004 }
12005#endif // GTEST_HAS_STD_FUNCTION_
12006
12007 private:
12008 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
12009};
12010
12011template <typename R, typename A0, typename A1, typename A2, typename A3,
12012 typename A4, typename A5, typename A6, typename A7>
12013class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7)> {
12014 public:
12015 MockFunction() {}
12016
12017 MOCK_METHOD8_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7));
12018
12019#if GTEST_HAS_STD_FUNCTION_
12020 std::function<R(A0, A1, A2, A3, A4, A5, A6, A7)> AsStdFunction() {
12021 return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) -> R {
12022 return this->Call(a0, a1, a2, a3, a4, a5, a6, a7);
12023 };
12024 }
12025#endif // GTEST_HAS_STD_FUNCTION_
12026
12027 private:
12028 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
12029};
12030
12031template <typename R, typename A0, typename A1, typename A2, typename A3,
12032 typename A4, typename A5, typename A6, typename A7, typename A8>
12033class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7, A8)> {
12034 public:
12035 MockFunction() {}
12036
12037 MOCK_METHOD9_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7, A8));
12038
12039#if GTEST_HAS_STD_FUNCTION_
12040 std::function<R(A0, A1, A2, A3, A4, A5, A6, A7, A8)> AsStdFunction() {
12041 return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7,
12042 A8 a8) -> R {
12043 return this->Call(a0, a1, a2, a3, a4, a5, a6, a7, a8);
12044 };
12045 }
12046#endif // GTEST_HAS_STD_FUNCTION_
12047
12048 private:
12049 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
12050};
12051
12052template <typename R, typename A0, typename A1, typename A2, typename A3,
12053 typename A4, typename A5, typename A6, typename A7, typename A8,
12054 typename A9>
12055class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9)> {
12056 public:
12057 MockFunction() {}
12058
12059 MOCK_METHOD10_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9));
12060
12061#if GTEST_HAS_STD_FUNCTION_
12062 std::function<R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9)> AsStdFunction() {
12063 return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7,
12064 A8 a8, A9 a9) -> R {
12065 return this->Call(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9);
12066 };
12067 }
12068#endif // GTEST_HAS_STD_FUNCTION_
12069
12070 private:
12071 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
12072};
12073
12074} // namespace testing
12075
12076#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
12077// This file was GENERATED by command:
12078// pump.py gmock-generated-nice-strict.h.pump
12079// DO NOT EDIT BY HAND!!!
12080
12081// Copyright 2008, Google Inc.
12082// All rights reserved.
12083//
12084// Redistribution and use in source and binary forms, with or without
12085// modification, are permitted provided that the following conditions are
12086// met:
12087//
12088// * Redistributions of source code must retain the above copyright
12089// notice, this list of conditions and the following disclaimer.
12090// * Redistributions in binary form must reproduce the above
12091// copyright notice, this list of conditions and the following disclaimer
12092// in the documentation and/or other materials provided with the
12093// distribution.
12094// * Neither the name of Google Inc. nor the names of its
12095// contributors may be used to endorse or promote products derived from
12096// this software without specific prior written permission.
12097//
12098// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
12099// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
12100// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
12101// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
12102// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
12103// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
12104// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12105// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12106// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12107// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
12108// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12109//
12110// Author: wan@google.com (Zhanyong Wan)
12111
12112// Implements class templates NiceMock, NaggyMock, and StrictMock.
12113//
12114// Given a mock class MockFoo that is created using Google Mock,
12115// NiceMock<MockFoo> is a subclass of MockFoo that allows
12116// uninteresting calls (i.e. calls to mock methods that have no
12117// EXPECT_CALL specs), NaggyMock<MockFoo> is a subclass of MockFoo
12118// that prints a warning when an uninteresting call occurs, and
12119// StrictMock<MockFoo> is a subclass of MockFoo that treats all
12120// uninteresting calls as errors.
12121//
12122// Currently a mock is naggy by default, so MockFoo and
12123// NaggyMock<MockFoo> behave like the same. However, we will soon
12124// switch the default behavior of mocks to be nice, as that in general
12125// leads to more maintainable tests. When that happens, MockFoo will
12126// stop behaving like NaggyMock<MockFoo> and start behaving like
12127// NiceMock<MockFoo>.
12128//
12129// NiceMock, NaggyMock, and StrictMock "inherit" the constructors of
12130// their respective base class, with up-to 10 arguments. Therefore
12131// you can write NiceMock<MockFoo>(5, "a") to construct a nice mock
12132// where MockFoo has a constructor that accepts (int, const char*),
12133// for example.
12134//
12135// A known limitation is that NiceMock<MockFoo>, NaggyMock<MockFoo>,
12136// and StrictMock<MockFoo> only works for mock methods defined using
12137// the MOCK_METHOD* family of macros DIRECTLY in the MockFoo class.
12138// If a mock method is defined in a base class of MockFoo, the "nice"
12139// or "strict" modifier may not affect it, depending on the compiler.
12140// In particular, nesting NiceMock, NaggyMock, and StrictMock is NOT
12141// supported.
12142//
12143// Another known limitation is that the constructors of the base mock
12144// cannot have arguments passed by non-const reference, which are
12145// banned by the Google C++ style guide anyway.
12146
12147#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
12148#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
12149
12150
12151namespace testing {
12152
12153template <class MockClass>
12154class NiceMock : public MockClass {
12155 public:
12156 // We don't factor out the constructor body to a common method, as
12157 // we have to avoid a possible clash with members of MockClass.
12158 NiceMock() {
12159 ::testing::Mock::AllowUninterestingCalls(
12160 internal::ImplicitCast_<MockClass*>(this));
12161 }
12162
12163 // C++ doesn't (yet) allow inheritance of constructors, so we have
12164 // to define it for each arity.
12165 template <typename A1>
12166 explicit NiceMock(const A1& a1) : MockClass(a1) {
12167 ::testing::Mock::AllowUninterestingCalls(
12168 internal::ImplicitCast_<MockClass*>(this));
12169 }
12170 template <typename A1, typename A2>
12171 NiceMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {
12172 ::testing::Mock::AllowUninterestingCalls(
12173 internal::ImplicitCast_<MockClass*>(this));
12174 }
12175
12176 template <typename A1, typename A2, typename A3>
12177 NiceMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {
12178 ::testing::Mock::AllowUninterestingCalls(
12179 internal::ImplicitCast_<MockClass*>(this));
12180 }
12181
12182 template <typename A1, typename A2, typename A3, typename A4>
12183 NiceMock(const A1& a1, const A2& a2, const A3& a3,
12184 const A4& a4) : MockClass(a1, a2, a3, a4) {
12185 ::testing::Mock::AllowUninterestingCalls(
12186 internal::ImplicitCast_<MockClass*>(this));
12187 }
12188
12189 template <typename A1, typename A2, typename A3, typename A4, typename A5>
12190 NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
12191 const A5& a5) : MockClass(a1, a2, a3, a4, a5) {
12192 ::testing::Mock::AllowUninterestingCalls(
12193 internal::ImplicitCast_<MockClass*>(this));
12194 }
12195
12196 template <typename A1, typename A2, typename A3, typename A4, typename A5,
12197 typename A6>
12198 NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
12199 const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {
12200 ::testing::Mock::AllowUninterestingCalls(
12201 internal::ImplicitCast_<MockClass*>(this));
12202 }
12203
12204 template <typename A1, typename A2, typename A3, typename A4, typename A5,
12205 typename A6, typename A7>
12206 NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
12207 const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5,
12208 a6, a7) {
12209 ::testing::Mock::AllowUninterestingCalls(
12210 internal::ImplicitCast_<MockClass*>(this));
12211 }
12212
12213 template <typename A1, typename A2, typename A3, typename A4, typename A5,
12214 typename A6, typename A7, typename A8>
12215 NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
12216 const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1,
12217 a2, a3, a4, a5, a6, a7, a8) {
12218 ::testing::Mock::AllowUninterestingCalls(
12219 internal::ImplicitCast_<MockClass*>(this));
12220 }
12221
12222 template <typename A1, typename A2, typename A3, typename A4, typename A5,
12223 typename A6, typename A7, typename A8, typename A9>
12224 NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
12225 const A5& a5, const A6& a6, const A7& a7, const A8& a8,
12226 const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
12227 ::testing::Mock::AllowUninterestingCalls(
12228 internal::ImplicitCast_<MockClass*>(this));
12229 }
12230
12231 template <typename A1, typename A2, typename A3, typename A4, typename A5,
12232 typename A6, typename A7, typename A8, typename A9, typename A10>
12233 NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
12234 const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9,
12235 const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {
12236 ::testing::Mock::AllowUninterestingCalls(
12237 internal::ImplicitCast_<MockClass*>(this));
12238 }
12239
12240 virtual ~NiceMock() {
12241 ::testing::Mock::UnregisterCallReaction(
12242 internal::ImplicitCast_<MockClass*>(this));
12243 }
12244
12245 private:
12246 GTEST_DISALLOW_COPY_AND_ASSIGN_(NiceMock);
12247};
12248
12249template <class MockClass>
12250class NaggyMock : public MockClass {
12251 public:
12252 // We don't factor out the constructor body to a common method, as
12253 // we have to avoid a possible clash with members of MockClass.
12254 NaggyMock() {
12255 ::testing::Mock::WarnUninterestingCalls(
12256 internal::ImplicitCast_<MockClass*>(this));
12257 }
12258
12259 // C++ doesn't (yet) allow inheritance of constructors, so we have
12260 // to define it for each arity.
12261 template <typename A1>
12262 explicit NaggyMock(const A1& a1) : MockClass(a1) {
12263 ::testing::Mock::WarnUninterestingCalls(
12264 internal::ImplicitCast_<MockClass*>(this));
12265 }
12266 template <typename A1, typename A2>
12267 NaggyMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {
12268 ::testing::Mock::WarnUninterestingCalls(
12269 internal::ImplicitCast_<MockClass*>(this));
12270 }
12271
12272 template <typename A1, typename A2, typename A3>
12273 NaggyMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {
12274 ::testing::Mock::WarnUninterestingCalls(
12275 internal::ImplicitCast_<MockClass*>(this));
12276 }
12277
12278 template <typename A1, typename A2, typename A3, typename A4>
12279 NaggyMock(const A1& a1, const A2& a2, const A3& a3,
12280 const A4& a4) : MockClass(a1, a2, a3, a4) {
12281 ::testing::Mock::WarnUninterestingCalls(
12282 internal::ImplicitCast_<MockClass*>(this));
12283 }
12284
12285 template <typename A1, typename A2, typename A3, typename A4, typename A5>
12286 NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
12287 const A5& a5) : MockClass(a1, a2, a3, a4, a5) {
12288 ::testing::Mock::WarnUninterestingCalls(
12289 internal::ImplicitCast_<MockClass*>(this));
12290 }
12291
12292 template <typename A1, typename A2, typename A3, typename A4, typename A5,
12293 typename A6>
12294 NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
12295 const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {
12296 ::testing::Mock::WarnUninterestingCalls(
12297 internal::ImplicitCast_<MockClass*>(this));
12298 }
12299
12300 template <typename A1, typename A2, typename A3, typename A4, typename A5,
12301 typename A6, typename A7>
12302 NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
12303 const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5,
12304 a6, a7) {
12305 ::testing::Mock::WarnUninterestingCalls(
12306 internal::ImplicitCast_<MockClass*>(this));
12307 }
12308
12309 template <typename A1, typename A2, typename A3, typename A4, typename A5,
12310 typename A6, typename A7, typename A8>
12311 NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
12312 const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1,
12313 a2, a3, a4, a5, a6, a7, a8) {
12314 ::testing::Mock::WarnUninterestingCalls(
12315 internal::ImplicitCast_<MockClass*>(this));
12316 }
12317
12318 template <typename A1, typename A2, typename A3, typename A4, typename A5,
12319 typename A6, typename A7, typename A8, typename A9>
12320 NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
12321 const A5& a5, const A6& a6, const A7& a7, const A8& a8,
12322 const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
12323 ::testing::Mock::WarnUninterestingCalls(
12324 internal::ImplicitCast_<MockClass*>(this));
12325 }
12326
12327 template <typename A1, typename A2, typename A3, typename A4, typename A5,
12328 typename A6, typename A7, typename A8, typename A9, typename A10>
12329 NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
12330 const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9,
12331 const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {
12332 ::testing::Mock::WarnUninterestingCalls(
12333 internal::ImplicitCast_<MockClass*>(this));
12334 }
12335
12336 virtual ~NaggyMock() {
12337 ::testing::Mock::UnregisterCallReaction(
12338 internal::ImplicitCast_<MockClass*>(this));
12339 }
12340
12341 private:
12342 GTEST_DISALLOW_COPY_AND_ASSIGN_(NaggyMock);
12343};
12344
12345template <class MockClass>
12346class StrictMock : public MockClass {
12347 public:
12348 // We don't factor out the constructor body to a common method, as
12349 // we have to avoid a possible clash with members of MockClass.
12350 StrictMock() {
12351 ::testing::Mock::FailUninterestingCalls(
12352 internal::ImplicitCast_<MockClass*>(this));
12353 }
12354
12355 // C++ doesn't (yet) allow inheritance of constructors, so we have
12356 // to define it for each arity.
12357 template <typename A1>
12358 explicit StrictMock(const A1& a1) : MockClass(a1) {
12359 ::testing::Mock::FailUninterestingCalls(
12360 internal::ImplicitCast_<MockClass*>(this));
12361 }
12362 template <typename A1, typename A2>
12363 StrictMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {
12364 ::testing::Mock::FailUninterestingCalls(
12365 internal::ImplicitCast_<MockClass*>(this));
12366 }
12367
12368 template <typename A1, typename A2, typename A3>
12369 StrictMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {
12370 ::testing::Mock::FailUninterestingCalls(
12371 internal::ImplicitCast_<MockClass*>(this));
12372 }
12373
12374 template <typename A1, typename A2, typename A3, typename A4>
12375 StrictMock(const A1& a1, const A2& a2, const A3& a3,
12376 const A4& a4) : MockClass(a1, a2, a3, a4) {
12377 ::testing::Mock::FailUninterestingCalls(
12378 internal::ImplicitCast_<MockClass*>(this));
12379 }
12380
12381 template <typename A1, typename A2, typename A3, typename A4, typename A5>
12382 StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
12383 const A5& a5) : MockClass(a1, a2, a3, a4, a5) {
12384 ::testing::Mock::FailUninterestingCalls(
12385 internal::ImplicitCast_<MockClass*>(this));
12386 }
12387
12388 template <typename A1, typename A2, typename A3, typename A4, typename A5,
12389 typename A6>
12390 StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
12391 const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {
12392 ::testing::Mock::FailUninterestingCalls(
12393 internal::ImplicitCast_<MockClass*>(this));
12394 }
12395
12396 template <typename A1, typename A2, typename A3, typename A4, typename A5,
12397 typename A6, typename A7>
12398 StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
12399 const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5,
12400 a6, a7) {
12401 ::testing::Mock::FailUninterestingCalls(
12402 internal::ImplicitCast_<MockClass*>(this));
12403 }
12404
12405 template <typename A1, typename A2, typename A3, typename A4, typename A5,
12406 typename A6, typename A7, typename A8>
12407 StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
12408 const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1,
12409 a2, a3, a4, a5, a6, a7, a8) {
12410 ::testing::Mock::FailUninterestingCalls(
12411 internal::ImplicitCast_<MockClass*>(this));
12412 }
12413
12414 template <typename A1, typename A2, typename A3, typename A4, typename A5,
12415 typename A6, typename A7, typename A8, typename A9>
12416 StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
12417 const A5& a5, const A6& a6, const A7& a7, const A8& a8,
12418 const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
12419 ::testing::Mock::FailUninterestingCalls(
12420 internal::ImplicitCast_<MockClass*>(this));
12421 }
12422
12423 template <typename A1, typename A2, typename A3, typename A4, typename A5,
12424 typename A6, typename A7, typename A8, typename A9, typename A10>
12425 StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
12426 const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9,
12427 const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {
12428 ::testing::Mock::FailUninterestingCalls(
12429 internal::ImplicitCast_<MockClass*>(this));
12430 }
12431
12432 virtual ~StrictMock() {
12433 ::testing::Mock::UnregisterCallReaction(
12434 internal::ImplicitCast_<MockClass*>(this));
12435 }
12436
12437 private:
12438 GTEST_DISALLOW_COPY_AND_ASSIGN_(StrictMock);
12439};
12440
12441// The following specializations catch some (relatively more common)
12442// user errors of nesting nice and strict mocks. They do NOT catch
12443// all possible errors.
12444
12445// These specializations are declared but not defined, as NiceMock,
12446// NaggyMock, and StrictMock cannot be nested.
12447
12448template <typename MockClass>
12449class NiceMock<NiceMock<MockClass> >;
12450template <typename MockClass>
12451class NiceMock<NaggyMock<MockClass> >;
12452template <typename MockClass>
12453class NiceMock<StrictMock<MockClass> >;
12454
12455template <typename MockClass>
12456class NaggyMock<NiceMock<MockClass> >;
12457template <typename MockClass>
12458class NaggyMock<NaggyMock<MockClass> >;
12459template <typename MockClass>
12460class NaggyMock<StrictMock<MockClass> >;
12461
12462template <typename MockClass>
12463class StrictMock<NiceMock<MockClass> >;
12464template <typename MockClass>
12465class StrictMock<NaggyMock<MockClass> >;
12466template <typename MockClass>
12467class StrictMock<StrictMock<MockClass> >;
12468
12469} // namespace testing
12470
12471#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
12472// This file was GENERATED by command:
12473// pump.py gmock-generated-matchers.h.pump
12474// DO NOT EDIT BY HAND!!!
12475
12476// Copyright 2008, Google Inc.
12477// All rights reserved.
12478//
12479// Redistribution and use in source and binary forms, with or without
12480// modification, are permitted provided that the following conditions are
12481// met:
12482//
12483// * Redistributions of source code must retain the above copyright
12484// notice, this list of conditions and the following disclaimer.
12485// * Redistributions in binary form must reproduce the above
12486// copyright notice, this list of conditions and the following disclaimer
12487// in the documentation and/or other materials provided with the
12488// distribution.
12489// * Neither the name of Google Inc. nor the names of its
12490// contributors may be used to endorse or promote products derived from
12491// this software without specific prior written permission.
12492//
12493// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
12494// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
12495// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
12496// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
12497// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
12498// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
12499// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12500// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12501// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12502// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
12503// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12504
12505// Google Mock - a framework for writing C++ mock classes.
12506//
12507// This file implements some commonly used variadic matchers.
12508
12509#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
12510#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
12511
12512#include <iterator>
12513#include <sstream>
12514#include <string>
12515#include <vector>
12516
12517namespace testing {
12518namespace internal {
12519
12520// The type of the i-th (0-based) field of Tuple.
12521#define GMOCK_FIELD_TYPE_(Tuple, i) \
12522 typename ::testing::tuple_element<i, Tuple>::type
12523
12524// TupleFields<Tuple, k0, ..., kn> is for selecting fields from a
12525// tuple of type Tuple. It has two members:
12526//
12527// type: a tuple type whose i-th field is the ki-th field of Tuple.
12528// GetSelectedFields(t): returns fields k0, ..., and kn of t as a tuple.
12529//
12530// For example, in class TupleFields<tuple<bool, char, int>, 2, 0>, we have:
12531//
12532// type is tuple<int, bool>, and
12533// GetSelectedFields(make_tuple(true, 'a', 42)) is (42, true).
12534
12535template <class Tuple, int k0 = -1, int k1 = -1, int k2 = -1, int k3 = -1,
12536 int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1, int k8 = -1,
12537 int k9 = -1>
12538class TupleFields;
12539
12540// This generic version is used when there are 10 selectors.
12541template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6,
12542 int k7, int k8, int k9>
12543class TupleFields {
12544 public:
12545 typedef ::testing::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
12546 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
12547 GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4),
12548 GMOCK_FIELD_TYPE_(Tuple, k5), GMOCK_FIELD_TYPE_(Tuple, k6),
12549 GMOCK_FIELD_TYPE_(Tuple, k7), GMOCK_FIELD_TYPE_(Tuple, k8),
12550 GMOCK_FIELD_TYPE_(Tuple, k9)> type;
12551 static type GetSelectedFields(const Tuple& t) {
12552 return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t),
12553 get<k5>(t), get<k6>(t), get<k7>(t), get<k8>(t), get<k9>(t));
12554 }
12555};
12556
12557// The following specialization is used for 0 ~ 9 selectors.
12558
12559template <class Tuple>
12560class TupleFields<Tuple, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1> {
12561 public:
12562 typedef ::testing::tuple<> type;
12563 static type GetSelectedFields(const Tuple& /* t */) {
12564 return type();
12565 }
12566};
12567
12568template <class Tuple, int k0>
12569class TupleFields<Tuple, k0, -1, -1, -1, -1, -1, -1, -1, -1, -1> {
12570 public:
12571 typedef ::testing::tuple<GMOCK_FIELD_TYPE_(Tuple, k0)> type;
12572 static type GetSelectedFields(const Tuple& t) {
12573 return type(get<k0>(t));
12574 }
12575};
12576
12577template <class Tuple, int k0, int k1>
12578class TupleFields<Tuple, k0, k1, -1, -1, -1, -1, -1, -1, -1, -1> {
12579 public:
12580 typedef ::testing::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
12581 GMOCK_FIELD_TYPE_(Tuple, k1)> type;
12582 static type GetSelectedFields(const Tuple& t) {
12583 return type(get<k0>(t), get<k1>(t));
12584 }
12585};
12586
12587template <class Tuple, int k0, int k1, int k2>
12588class TupleFields<Tuple, k0, k1, k2, -1, -1, -1, -1, -1, -1, -1> {
12589 public:
12590 typedef ::testing::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
12591 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2)> type;
12592 static type GetSelectedFields(const Tuple& t) {
12593 return type(get<k0>(t), get<k1>(t), get<k2>(t));
12594 }
12595};
12596
12597template <class Tuple, int k0, int k1, int k2, int k3>
12598class TupleFields<Tuple, k0, k1, k2, k3, -1, -1, -1, -1, -1, -1> {
12599 public:
12600 typedef ::testing::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
12601 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
12602 GMOCK_FIELD_TYPE_(Tuple, k3)> type;
12603 static type GetSelectedFields(const Tuple& t) {
12604 return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t));
12605 }
12606};
12607
12608template <class Tuple, int k0, int k1, int k2, int k3, int k4>
12609class TupleFields<Tuple, k0, k1, k2, k3, k4, -1, -1, -1, -1, -1> {
12610 public:
12611 typedef ::testing::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
12612 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
12613 GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4)> type;
12614 static type GetSelectedFields(const Tuple& t) {
12615 return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t));
12616 }
12617};
12618
12619template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5>
12620class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, -1, -1, -1, -1> {
12621 public:
12622 typedef ::testing::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
12623 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
12624 GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4),
12625 GMOCK_FIELD_TYPE_(Tuple, k5)> type;
12626 static type GetSelectedFields(const Tuple& t) {
12627 return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t),
12628 get<k5>(t));
12629 }
12630};
12631
12632template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6>
12633class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, k6, -1, -1, -1> {
12634 public:
12635 typedef ::testing::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
12636 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
12637 GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4),
12638 GMOCK_FIELD_TYPE_(Tuple, k5), GMOCK_FIELD_TYPE_(Tuple, k6)> type;
12639 static type GetSelectedFields(const Tuple& t) {
12640 return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t),
12641 get<k5>(t), get<k6>(t));
12642 }
12643};
12644
12645template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6,
12646 int k7>
12647class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, k6, k7, -1, -1> {
12648 public:
12649 typedef ::testing::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
12650 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
12651 GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4),
12652 GMOCK_FIELD_TYPE_(Tuple, k5), GMOCK_FIELD_TYPE_(Tuple, k6),
12653 GMOCK_FIELD_TYPE_(Tuple, k7)> type;
12654 static type GetSelectedFields(const Tuple& t) {
12655 return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t),
12656 get<k5>(t), get<k6>(t), get<k7>(t));
12657 }
12658};
12659
12660template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6,
12661 int k7, int k8>
12662class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, k6, k7, k8, -1> {
12663 public:
12664 typedef ::testing::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
12665 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
12666 GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4),
12667 GMOCK_FIELD_TYPE_(Tuple, k5), GMOCK_FIELD_TYPE_(Tuple, k6),
12668 GMOCK_FIELD_TYPE_(Tuple, k7), GMOCK_FIELD_TYPE_(Tuple, k8)> type;
12669 static type GetSelectedFields(const Tuple& t) {
12670 return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t),
12671 get<k5>(t), get<k6>(t), get<k7>(t), get<k8>(t));
12672 }
12673};
12674
12675#undef GMOCK_FIELD_TYPE_
12676
12677// Implements the Args() matcher.
12678template <class ArgsTuple, int k0 = -1, int k1 = -1, int k2 = -1, int k3 = -1,
12679 int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1, int k8 = -1,
12680 int k9 = -1>
12681class ArgsMatcherImpl : public MatcherInterface<ArgsTuple> {
12682 public:
12683 // ArgsTuple may have top-level const or reference modifiers.
12684 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(ArgsTuple) RawArgsTuple;
12685 typedef typename internal::TupleFields<RawArgsTuple, k0, k1, k2, k3, k4, k5,
12686 k6, k7, k8, k9>::type SelectedArgs;
12687 typedef Matcher<const SelectedArgs&> MonomorphicInnerMatcher;
12688
12689 template <typename InnerMatcher>
12690 explicit ArgsMatcherImpl(const InnerMatcher& inner_matcher)
12691 : inner_matcher_(SafeMatcherCast<const SelectedArgs&>(inner_matcher)) {}
12692
12693 virtual bool MatchAndExplain(ArgsTuple args,
12694 MatchResultListener* listener) const {
12695 const SelectedArgs& selected_args = GetSelectedArgs(args);
12696 if (!listener->IsInterested())
12697 return inner_matcher_.Matches(selected_args);
12698
12699 PrintIndices(listener->stream());
12700 *listener << "are " << PrintToString(selected_args);
12701
12702 StringMatchResultListener inner_listener;
12703 const bool match = inner_matcher_.MatchAndExplain(selected_args,
12704 &inner_listener);
12705 PrintIfNotEmpty(inner_listener.str(), listener->stream());
12706 return match;
12707 }
12708
12709 virtual void DescribeTo(::std::ostream* os) const {
12710 *os << "are a tuple ";
12711 PrintIndices(os);
12712 inner_matcher_.DescribeTo(os);
12713 }
12714
12715 virtual void DescribeNegationTo(::std::ostream* os) const {
12716 *os << "are a tuple ";
12717 PrintIndices(os);
12718 inner_matcher_.DescribeNegationTo(os);
12719 }
12720
12721 private:
12722 static SelectedArgs GetSelectedArgs(ArgsTuple args) {
12723 return TupleFields<RawArgsTuple, k0, k1, k2, k3, k4, k5, k6, k7, k8,
12724 k9>::GetSelectedFields(args);
12725 }
12726
12727 // Prints the indices of the selected fields.
12728 static void PrintIndices(::std::ostream* os) {
12729 *os << "whose fields (";
12730 const int indices[10] = { k0, k1, k2, k3, k4, k5, k6, k7, k8, k9 };
12731 for (int i = 0; i < 10; i++) {
12732 if (indices[i] < 0)
12733 break;
12734
12735 if (i >= 1)
12736 *os << ", ";
12737
12738 *os << "#" << indices[i];
12739 }
12740 *os << ") ";
12741 }
12742
12743 const MonomorphicInnerMatcher inner_matcher_;
12744
12745 GTEST_DISALLOW_ASSIGN_(ArgsMatcherImpl);
12746};
12747
12748template <class InnerMatcher, int k0 = -1, int k1 = -1, int k2 = -1,
12749 int k3 = -1, int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1,
12750 int k8 = -1, int k9 = -1>
12751class ArgsMatcher {
12752 public:
12753 explicit ArgsMatcher(const InnerMatcher& inner_matcher)
12754 : inner_matcher_(inner_matcher) {}
12755
12756 template <typename ArgsTuple>
12757 operator Matcher<ArgsTuple>() const {
12758 return MakeMatcher(new ArgsMatcherImpl<ArgsTuple, k0, k1, k2, k3, k4, k5,
12759 k6, k7, k8, k9>(inner_matcher_));
12760 }
12761
12762 private:
12763 const InnerMatcher inner_matcher_;
12764
12765 GTEST_DISALLOW_ASSIGN_(ArgsMatcher);
12766};
12767
12768// A set of metafunctions for computing the result type of AllOf.
12769// AllOf(m1, ..., mN) returns
12770// AllOfResultN<decltype(m1), ..., decltype(mN)>::type.
12771
12772// Although AllOf isn't defined for one argument, AllOfResult1 is defined
12773// to simplify the implementation.
12774template <typename M1>
12775struct AllOfResult1 {
12776 typedef M1 type;
12777};
12778
12779template <typename M1, typename M2>
12780struct AllOfResult2 {
12781 typedef BothOfMatcher<
12782 typename AllOfResult1<M1>::type,
12783 typename AllOfResult1<M2>::type
12784 > type;
12785};
12786
12787template <typename M1, typename M2, typename M3>
12788struct AllOfResult3 {
12789 typedef BothOfMatcher<
12790 typename AllOfResult1<M1>::type,
12791 typename AllOfResult2<M2, M3>::type
12792 > type;
12793};
12794
12795template <typename M1, typename M2, typename M3, typename M4>
12796struct AllOfResult4 {
12797 typedef BothOfMatcher<
12798 typename AllOfResult2<M1, M2>::type,
12799 typename AllOfResult2<M3, M4>::type
12800 > type;
12801};
12802
12803template <typename M1, typename M2, typename M3, typename M4, typename M5>
12804struct AllOfResult5 {
12805 typedef BothOfMatcher<
12806 typename AllOfResult2<M1, M2>::type,
12807 typename AllOfResult3<M3, M4, M5>::type
12808 > type;
12809};
12810
12811template <typename M1, typename M2, typename M3, typename M4, typename M5,
12812 typename M6>
12813struct AllOfResult6 {
12814 typedef BothOfMatcher<
12815 typename AllOfResult3<M1, M2, M3>::type,
12816 typename AllOfResult3<M4, M5, M6>::type
12817 > type;
12818};
12819
12820template <typename M1, typename M2, typename M3, typename M4, typename M5,
12821 typename M6, typename M7>
12822struct AllOfResult7 {
12823 typedef BothOfMatcher<
12824 typename AllOfResult3<M1, M2, M3>::type,
12825 typename AllOfResult4<M4, M5, M6, M7>::type
12826 > type;
12827};
12828
12829template <typename M1, typename M2, typename M3, typename M4, typename M5,
12830 typename M6, typename M7, typename M8>
12831struct AllOfResult8 {
12832 typedef BothOfMatcher<
12833 typename AllOfResult4<M1, M2, M3, M4>::type,
12834 typename AllOfResult4<M5, M6, M7, M8>::type
12835 > type;
12836};
12837
12838template <typename M1, typename M2, typename M3, typename M4, typename M5,
12839 typename M6, typename M7, typename M8, typename M9>
12840struct AllOfResult9 {
12841 typedef BothOfMatcher<
12842 typename AllOfResult4<M1, M2, M3, M4>::type,
12843 typename AllOfResult5<M5, M6, M7, M8, M9>::type
12844 > type;
12845};
12846
12847template <typename M1, typename M2, typename M3, typename M4, typename M5,
12848 typename M6, typename M7, typename M8, typename M9, typename M10>
12849struct AllOfResult10 {
12850 typedef BothOfMatcher<
12851 typename AllOfResult5<M1, M2, M3, M4, M5>::type,
12852 typename AllOfResult5<M6, M7, M8, M9, M10>::type
12853 > type;
12854};
12855
12856// A set of metafunctions for computing the result type of AnyOf.
12857// AnyOf(m1, ..., mN) returns
12858// AnyOfResultN<decltype(m1), ..., decltype(mN)>::type.
12859
12860// Although AnyOf isn't defined for one argument, AnyOfResult1 is defined
12861// to simplify the implementation.
12862template <typename M1>
12863struct AnyOfResult1 {
12864 typedef M1 type;
12865};
12866
12867template <typename M1, typename M2>
12868struct AnyOfResult2 {
12869 typedef EitherOfMatcher<
12870 typename AnyOfResult1<M1>::type,
12871 typename AnyOfResult1<M2>::type
12872 > type;
12873};
12874
12875template <typename M1, typename M2, typename M3>
12876struct AnyOfResult3 {
12877 typedef EitherOfMatcher<
12878 typename AnyOfResult1<M1>::type,
12879 typename AnyOfResult2<M2, M3>::type
12880 > type;
12881};
12882
12883template <typename M1, typename M2, typename M3, typename M4>
12884struct AnyOfResult4 {
12885 typedef EitherOfMatcher<
12886 typename AnyOfResult2<M1, M2>::type,
12887 typename AnyOfResult2<M3, M4>::type
12888 > type;
12889};
12890
12891template <typename M1, typename M2, typename M3, typename M4, typename M5>
12892struct AnyOfResult5 {
12893 typedef EitherOfMatcher<
12894 typename AnyOfResult2<M1, M2>::type,
12895 typename AnyOfResult3<M3, M4, M5>::type
12896 > type;
12897};
12898
12899template <typename M1, typename M2, typename M3, typename M4, typename M5,
12900 typename M6>
12901struct AnyOfResult6 {
12902 typedef EitherOfMatcher<
12903 typename AnyOfResult3<M1, M2, M3>::type,
12904 typename AnyOfResult3<M4, M5, M6>::type
12905 > type;
12906};
12907
12908template <typename M1, typename M2, typename M3, typename M4, typename M5,
12909 typename M6, typename M7>
12910struct AnyOfResult7 {
12911 typedef EitherOfMatcher<
12912 typename AnyOfResult3<M1, M2, M3>::type,
12913 typename AnyOfResult4<M4, M5, M6, M7>::type
12914 > type;
12915};
12916
12917template <typename M1, typename M2, typename M3, typename M4, typename M5,
12918 typename M6, typename M7, typename M8>
12919struct AnyOfResult8 {
12920 typedef EitherOfMatcher<
12921 typename AnyOfResult4<M1, M2, M3, M4>::type,
12922 typename AnyOfResult4<M5, M6, M7, M8>::type
12923 > type;
12924};
12925
12926template <typename M1, typename M2, typename M3, typename M4, typename M5,
12927 typename M6, typename M7, typename M8, typename M9>
12928struct AnyOfResult9 {
12929 typedef EitherOfMatcher<
12930 typename AnyOfResult4<M1, M2, M3, M4>::type,
12931 typename AnyOfResult5<M5, M6, M7, M8, M9>::type
12932 > type;
12933};
12934
12935template <typename M1, typename M2, typename M3, typename M4, typename M5,
12936 typename M6, typename M7, typename M8, typename M9, typename M10>
12937struct AnyOfResult10 {
12938 typedef EitherOfMatcher<
12939 typename AnyOfResult5<M1, M2, M3, M4, M5>::type,
12940 typename AnyOfResult5<M6, M7, M8, M9, M10>::type
12941 > type;
12942};
12943
12944} // namespace internal
12945
12946// Args<N1, N2, ..., Nk>(a_matcher) matches a tuple if the selected
12947// fields of it matches a_matcher. C++ doesn't support default
12948// arguments for function templates, so we have to overload it.
12949template <typename InnerMatcher>
12950inline internal::ArgsMatcher<InnerMatcher>
12951Args(const InnerMatcher& matcher) {
12952 return internal::ArgsMatcher<InnerMatcher>(matcher);
12953}
12954
12955template <int k1, typename InnerMatcher>
12956inline internal::ArgsMatcher<InnerMatcher, k1>
12957Args(const InnerMatcher& matcher) {
12958 return internal::ArgsMatcher<InnerMatcher, k1>(matcher);
12959}
12960
12961template <int k1, int k2, typename InnerMatcher>
12962inline internal::ArgsMatcher<InnerMatcher, k1, k2>
12963Args(const InnerMatcher& matcher) {
12964 return internal::ArgsMatcher<InnerMatcher, k1, k2>(matcher);
12965}
12966
12967template <int k1, int k2, int k3, typename InnerMatcher>
12968inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3>
12969Args(const InnerMatcher& matcher) {
12970 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3>(matcher);
12971}
12972
12973template <int k1, int k2, int k3, int k4, typename InnerMatcher>
12974inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4>
12975Args(const InnerMatcher& matcher) {
12976 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4>(matcher);
12977}
12978
12979template <int k1, int k2, int k3, int k4, int k5, typename InnerMatcher>
12980inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5>
12981Args(const InnerMatcher& matcher) {
12982 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5>(matcher);
12983}
12984
12985template <int k1, int k2, int k3, int k4, int k5, int k6, typename InnerMatcher>
12986inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6>
12987Args(const InnerMatcher& matcher) {
12988 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6>(matcher);
12989}
12990
12991template <int k1, int k2, int k3, int k4, int k5, int k6, int k7,
12992 typename InnerMatcher>
12993inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7>
12994Args(const InnerMatcher& matcher) {
12995 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6,
12996 k7>(matcher);
12997}
12998
12999template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
13000 typename InnerMatcher>
13001inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8>
13002Args(const InnerMatcher& matcher) {
13003 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7,
13004 k8>(matcher);
13005}
13006
13007template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
13008 int k9, typename InnerMatcher>
13009inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8, k9>
13010Args(const InnerMatcher& matcher) {
13011 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8,
13012 k9>(matcher);
13013}
13014
13015template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
13016 int k9, int k10, typename InnerMatcher>
13017inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8, k9,
13018 k10>
13019Args(const InnerMatcher& matcher) {
13020 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8,
13021 k9, k10>(matcher);
13022}
13023
13024// ElementsAre(e_1, e_2, ... e_n) matches an STL-style container with
13025// n elements, where the i-th element in the container must
13026// match the i-th argument in the list. Each argument of
13027// ElementsAre() can be either a value or a matcher. We support up to
13028// 10 arguments.
13029//
13030// The use of DecayArray in the implementation allows ElementsAre()
13031// to accept string literals, whose type is const char[N], but we
13032// want to treat them as const char*.
13033//
13034// NOTE: Since ElementsAre() cares about the order of the elements, it
13035// must not be used with containers whose elements's order is
13036// undefined (e.g. hash_map).
13037
13038inline internal::ElementsAreMatcher<
13039 ::testing::tuple<> >
13040ElementsAre() {
13041 typedef ::testing::tuple<> Args;
13042 return internal::ElementsAreMatcher<Args>(Args());
13043}
13044
13045template <typename T1>
13046inline internal::ElementsAreMatcher<
13047 ::testing::tuple<
13048 typename internal::DecayArray<T1>::type> >
13049ElementsAre(const T1& e1) {
13050 typedef ::testing::tuple<
13051 typename internal::DecayArray<T1>::type> Args;
13052 return internal::ElementsAreMatcher<Args>(Args(e1));
13053}
13054
13055template <typename T1, typename T2>
13056inline internal::ElementsAreMatcher<
13057 ::testing::tuple<
13058 typename internal::DecayArray<T1>::type,
13059 typename internal::DecayArray<T2>::type> >
13060ElementsAre(const T1& e1, const T2& e2) {
13061 typedef ::testing::tuple<
13062 typename internal::DecayArray<T1>::type,
13063 typename internal::DecayArray<T2>::type> Args;
13064 return internal::ElementsAreMatcher<Args>(Args(e1, e2));
13065}
13066
13067template <typename T1, typename T2, typename T3>
13068inline internal::ElementsAreMatcher<
13069 ::testing::tuple<
13070 typename internal::DecayArray<T1>::type,
13071 typename internal::DecayArray<T2>::type,
13072 typename internal::DecayArray<T3>::type> >
13073ElementsAre(const T1& e1, const T2& e2, const T3& e3) {
13074 typedef ::testing::tuple<
13075 typename internal::DecayArray<T1>::type,
13076 typename internal::DecayArray<T2>::type,
13077 typename internal::DecayArray<T3>::type> Args;
13078 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3));
13079}
13080
13081template <typename T1, typename T2, typename T3, typename T4>
13082inline internal::ElementsAreMatcher<
13083 ::testing::tuple<
13084 typename internal::DecayArray<T1>::type,
13085 typename internal::DecayArray<T2>::type,
13086 typename internal::DecayArray<T3>::type,
13087 typename internal::DecayArray<T4>::type> >
13088ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4) {
13089 typedef ::testing::tuple<
13090 typename internal::DecayArray<T1>::type,
13091 typename internal::DecayArray<T2>::type,
13092 typename internal::DecayArray<T3>::type,
13093 typename internal::DecayArray<T4>::type> Args;
13094 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4));
13095}
13096
13097template <typename T1, typename T2, typename T3, typename T4, typename T5>
13098inline internal::ElementsAreMatcher<
13099 ::testing::tuple<
13100 typename internal::DecayArray<T1>::type,
13101 typename internal::DecayArray<T2>::type,
13102 typename internal::DecayArray<T3>::type,
13103 typename internal::DecayArray<T4>::type,
13104 typename internal::DecayArray<T5>::type> >
13105ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
13106 const T5& e5) {
13107 typedef ::testing::tuple<
13108 typename internal::DecayArray<T1>::type,
13109 typename internal::DecayArray<T2>::type,
13110 typename internal::DecayArray<T3>::type,
13111 typename internal::DecayArray<T4>::type,
13112 typename internal::DecayArray<T5>::type> Args;
13113 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5));
13114}
13115
13116template <typename T1, typename T2, typename T3, typename T4, typename T5,
13117 typename T6>
13118inline internal::ElementsAreMatcher<
13119 ::testing::tuple<
13120 typename internal::DecayArray<T1>::type,
13121 typename internal::DecayArray<T2>::type,
13122 typename internal::DecayArray<T3>::type,
13123 typename internal::DecayArray<T4>::type,
13124 typename internal::DecayArray<T5>::type,
13125 typename internal::DecayArray<T6>::type> >
13126ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
13127 const T5& e5, const T6& e6) {
13128 typedef ::testing::tuple<
13129 typename internal::DecayArray<T1>::type,
13130 typename internal::DecayArray<T2>::type,
13131 typename internal::DecayArray<T3>::type,
13132 typename internal::DecayArray<T4>::type,
13133 typename internal::DecayArray<T5>::type,
13134 typename internal::DecayArray<T6>::type> Args;
13135 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, e6));
13136}
13137
13138template <typename T1, typename T2, typename T3, typename T4, typename T5,
13139 typename T6, typename T7>
13140inline internal::ElementsAreMatcher<
13141 ::testing::tuple<
13142 typename internal::DecayArray<T1>::type,
13143 typename internal::DecayArray<T2>::type,
13144 typename internal::DecayArray<T3>::type,
13145 typename internal::DecayArray<T4>::type,
13146 typename internal::DecayArray<T5>::type,
13147 typename internal::DecayArray<T6>::type,
13148 typename internal::DecayArray<T7>::type> >
13149ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
13150 const T5& e5, const T6& e6, const T7& e7) {
13151 typedef ::testing::tuple<
13152 typename internal::DecayArray<T1>::type,
13153 typename internal::DecayArray<T2>::type,
13154 typename internal::DecayArray<T3>::type,
13155 typename internal::DecayArray<T4>::type,
13156 typename internal::DecayArray<T5>::type,
13157 typename internal::DecayArray<T6>::type,
13158 typename internal::DecayArray<T7>::type> Args;
13159 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, e6, e7));
13160}
13161
13162template <typename T1, typename T2, typename T3, typename T4, typename T5,
13163 typename T6, typename T7, typename T8>
13164inline internal::ElementsAreMatcher<
13165 ::testing::tuple<
13166 typename internal::DecayArray<T1>::type,
13167 typename internal::DecayArray<T2>::type,
13168 typename internal::DecayArray<T3>::type,
13169 typename internal::DecayArray<T4>::type,
13170 typename internal::DecayArray<T5>::type,
13171 typename internal::DecayArray<T6>::type,
13172 typename internal::DecayArray<T7>::type,
13173 typename internal::DecayArray<T8>::type> >
13174ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
13175 const T5& e5, const T6& e6, const T7& e7, const T8& e8) {
13176 typedef ::testing::tuple<
13177 typename internal::DecayArray<T1>::type,
13178 typename internal::DecayArray<T2>::type,
13179 typename internal::DecayArray<T3>::type,
13180 typename internal::DecayArray<T4>::type,
13181 typename internal::DecayArray<T5>::type,
13182 typename internal::DecayArray<T6>::type,
13183 typename internal::DecayArray<T7>::type,
13184 typename internal::DecayArray<T8>::type> Args;
13185 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, e6, e7,
13186 e8));
13187}
13188
13189template <typename T1, typename T2, typename T3, typename T4, typename T5,
13190 typename T6, typename T7, typename T8, typename T9>
13191inline internal::ElementsAreMatcher<
13192 ::testing::tuple<
13193 typename internal::DecayArray<T1>::type,
13194 typename internal::DecayArray<T2>::type,
13195 typename internal::DecayArray<T3>::type,
13196 typename internal::DecayArray<T4>::type,
13197 typename internal::DecayArray<T5>::type,
13198 typename internal::DecayArray<T6>::type,
13199 typename internal::DecayArray<T7>::type,
13200 typename internal::DecayArray<T8>::type,
13201 typename internal::DecayArray<T9>::type> >
13202ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
13203 const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9) {
13204 typedef ::testing::tuple<
13205 typename internal::DecayArray<T1>::type,
13206 typename internal::DecayArray<T2>::type,
13207 typename internal::DecayArray<T3>::type,
13208 typename internal::DecayArray<T4>::type,
13209 typename internal::DecayArray<T5>::type,
13210 typename internal::DecayArray<T6>::type,
13211 typename internal::DecayArray<T7>::type,
13212 typename internal::DecayArray<T8>::type,
13213 typename internal::DecayArray<T9>::type> Args;
13214 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, e6, e7,
13215 e8, e9));
13216}
13217
13218template <typename T1, typename T2, typename T3, typename T4, typename T5,
13219 typename T6, typename T7, typename T8, typename T9, typename T10>
13220inline internal::ElementsAreMatcher<
13221 ::testing::tuple<
13222 typename internal::DecayArray<T1>::type,
13223 typename internal::DecayArray<T2>::type,
13224 typename internal::DecayArray<T3>::type,
13225 typename internal::DecayArray<T4>::type,
13226 typename internal::DecayArray<T5>::type,
13227 typename internal::DecayArray<T6>::type,
13228 typename internal::DecayArray<T7>::type,
13229 typename internal::DecayArray<T8>::type,
13230 typename internal::DecayArray<T9>::type,
13231 typename internal::DecayArray<T10>::type> >
13232ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
13233 const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9,
13234 const T10& e10) {
13235 typedef ::testing::tuple<
13236 typename internal::DecayArray<T1>::type,
13237 typename internal::DecayArray<T2>::type,
13238 typename internal::DecayArray<T3>::type,
13239 typename internal::DecayArray<T4>::type,
13240 typename internal::DecayArray<T5>::type,
13241 typename internal::DecayArray<T6>::type,
13242 typename internal::DecayArray<T7>::type,
13243 typename internal::DecayArray<T8>::type,
13244 typename internal::DecayArray<T9>::type,
13245 typename internal::DecayArray<T10>::type> Args;
13246 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, e6, e7,
13247 e8, e9, e10));
13248}
13249
13250// UnorderedElementsAre(e_1, e_2, ..., e_n) is an ElementsAre extension
13251// that matches n elements in any order. We support up to n=10 arguments.
13252
13253inline internal::UnorderedElementsAreMatcher<
13254 ::testing::tuple<> >
13255UnorderedElementsAre() {
13256 typedef ::testing::tuple<> Args;
13257 return internal::UnorderedElementsAreMatcher<Args>(Args());
13258}
13259
13260template <typename T1>
13261inline internal::UnorderedElementsAreMatcher<
13262 ::testing::tuple<
13263 typename internal::DecayArray<T1>::type> >
13264UnorderedElementsAre(const T1& e1) {
13265 typedef ::testing::tuple<
13266 typename internal::DecayArray<T1>::type> Args;
13267 return internal::UnorderedElementsAreMatcher<Args>(Args(e1));
13268}
13269
13270template <typename T1, typename T2>
13271inline internal::UnorderedElementsAreMatcher<
13272 ::testing::tuple<
13273 typename internal::DecayArray<T1>::type,
13274 typename internal::DecayArray<T2>::type> >
13275UnorderedElementsAre(const T1& e1, const T2& e2) {
13276 typedef ::testing::tuple<
13277 typename internal::DecayArray<T1>::type,
13278 typename internal::DecayArray<T2>::type> Args;
13279 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2));
13280}
13281
13282template <typename T1, typename T2, typename T3>
13283inline internal::UnorderedElementsAreMatcher<
13284 ::testing::tuple<
13285 typename internal::DecayArray<T1>::type,
13286 typename internal::DecayArray<T2>::type,
13287 typename internal::DecayArray<T3>::type> >
13288UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3) {
13289 typedef ::testing::tuple<
13290 typename internal::DecayArray<T1>::type,
13291 typename internal::DecayArray<T2>::type,
13292 typename internal::DecayArray<T3>::type> Args;
13293 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3));
13294}
13295
13296template <typename T1, typename T2, typename T3, typename T4>
13297inline internal::UnorderedElementsAreMatcher<
13298 ::testing::tuple<
13299 typename internal::DecayArray<T1>::type,
13300 typename internal::DecayArray<T2>::type,
13301 typename internal::DecayArray<T3>::type,
13302 typename internal::DecayArray<T4>::type> >
13303UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4) {
13304 typedef ::testing::tuple<
13305 typename internal::DecayArray<T1>::type,
13306 typename internal::DecayArray<T2>::type,
13307 typename internal::DecayArray<T3>::type,
13308 typename internal::DecayArray<T4>::type> Args;
13309 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4));
13310}
13311
13312template <typename T1, typename T2, typename T3, typename T4, typename T5>
13313inline internal::UnorderedElementsAreMatcher<
13314 ::testing::tuple<
13315 typename internal::DecayArray<T1>::type,
13316 typename internal::DecayArray<T2>::type,
13317 typename internal::DecayArray<T3>::type,
13318 typename internal::DecayArray<T4>::type,
13319 typename internal::DecayArray<T5>::type> >
13320UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
13321 const T5& e5) {
13322 typedef ::testing::tuple<
13323 typename internal::DecayArray<T1>::type,
13324 typename internal::DecayArray<T2>::type,
13325 typename internal::DecayArray<T3>::type,
13326 typename internal::DecayArray<T4>::type,
13327 typename internal::DecayArray<T5>::type> Args;
13328 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5));
13329}
13330
13331template <typename T1, typename T2, typename T3, typename T4, typename T5,
13332 typename T6>
13333inline internal::UnorderedElementsAreMatcher<
13334 ::testing::tuple<
13335 typename internal::DecayArray<T1>::type,
13336 typename internal::DecayArray<T2>::type,
13337 typename internal::DecayArray<T3>::type,
13338 typename internal::DecayArray<T4>::type,
13339 typename internal::DecayArray<T5>::type,
13340 typename internal::DecayArray<T6>::type> >
13341UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
13342 const T5& e5, const T6& e6) {
13343 typedef ::testing::tuple<
13344 typename internal::DecayArray<T1>::type,
13345 typename internal::DecayArray<T2>::type,
13346 typename internal::DecayArray<T3>::type,
13347 typename internal::DecayArray<T4>::type,
13348 typename internal::DecayArray<T5>::type,
13349 typename internal::DecayArray<T6>::type> Args;
13350 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5,
13351 e6));
13352}
13353
13354template <typename T1, typename T2, typename T3, typename T4, typename T5,
13355 typename T6, typename T7>
13356inline internal::UnorderedElementsAreMatcher<
13357 ::testing::tuple<
13358 typename internal::DecayArray<T1>::type,
13359 typename internal::DecayArray<T2>::type,
13360 typename internal::DecayArray<T3>::type,
13361 typename internal::DecayArray<T4>::type,
13362 typename internal::DecayArray<T5>::type,
13363 typename internal::DecayArray<T6>::type,
13364 typename internal::DecayArray<T7>::type> >
13365UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
13366 const T5& e5, const T6& e6, const T7& e7) {
13367 typedef ::testing::tuple<
13368 typename internal::DecayArray<T1>::type,
13369 typename internal::DecayArray<T2>::type,
13370 typename internal::DecayArray<T3>::type,
13371 typename internal::DecayArray<T4>::type,
13372 typename internal::DecayArray<T5>::type,
13373 typename internal::DecayArray<T6>::type,
13374 typename internal::DecayArray<T7>::type> Args;
13375 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5,
13376 e6, e7));
13377}
13378
13379template <typename T1, typename T2, typename T3, typename T4, typename T5,
13380 typename T6, typename T7, typename T8>
13381inline internal::UnorderedElementsAreMatcher<
13382 ::testing::tuple<
13383 typename internal::DecayArray<T1>::type,
13384 typename internal::DecayArray<T2>::type,
13385 typename internal::DecayArray<T3>::type,
13386 typename internal::DecayArray<T4>::type,
13387 typename internal::DecayArray<T5>::type,
13388 typename internal::DecayArray<T6>::type,
13389 typename internal::DecayArray<T7>::type,
13390 typename internal::DecayArray<T8>::type> >
13391UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
13392 const T5& e5, const T6& e6, const T7& e7, const T8& e8) {
13393 typedef ::testing::tuple<
13394 typename internal::DecayArray<T1>::type,
13395 typename internal::DecayArray<T2>::type,
13396 typename internal::DecayArray<T3>::type,
13397 typename internal::DecayArray<T4>::type,
13398 typename internal::DecayArray<T5>::type,
13399 typename internal::DecayArray<T6>::type,
13400 typename internal::DecayArray<T7>::type,
13401 typename internal::DecayArray<T8>::type> Args;
13402 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5,
13403 e6, e7, e8));
13404}
13405
13406template <typename T1, typename T2, typename T3, typename T4, typename T5,
13407 typename T6, typename T7, typename T8, typename T9>
13408inline internal::UnorderedElementsAreMatcher<
13409 ::testing::tuple<
13410 typename internal::DecayArray<T1>::type,
13411 typename internal::DecayArray<T2>::type,
13412 typename internal::DecayArray<T3>::type,
13413 typename internal::DecayArray<T4>::type,
13414 typename internal::DecayArray<T5>::type,
13415 typename internal::DecayArray<T6>::type,
13416 typename internal::DecayArray<T7>::type,
13417 typename internal::DecayArray<T8>::type,
13418 typename internal::DecayArray<T9>::type> >
13419UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
13420 const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9) {
13421 typedef ::testing::tuple<
13422 typename internal::DecayArray<T1>::type,
13423 typename internal::DecayArray<T2>::type,
13424 typename internal::DecayArray<T3>::type,
13425 typename internal::DecayArray<T4>::type,
13426 typename internal::DecayArray<T5>::type,
13427 typename internal::DecayArray<T6>::type,
13428 typename internal::DecayArray<T7>::type,
13429 typename internal::DecayArray<T8>::type,
13430 typename internal::DecayArray<T9>::type> Args;
13431 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5,
13432 e6, e7, e8, e9));
13433}
13434
13435template <typename T1, typename T2, typename T3, typename T4, typename T5,
13436 typename T6, typename T7, typename T8, typename T9, typename T10>
13437inline internal::UnorderedElementsAreMatcher<
13438 ::testing::tuple<
13439 typename internal::DecayArray<T1>::type,
13440 typename internal::DecayArray<T2>::type,
13441 typename internal::DecayArray<T3>::type,
13442 typename internal::DecayArray<T4>::type,
13443 typename internal::DecayArray<T5>::type,
13444 typename internal::DecayArray<T6>::type,
13445 typename internal::DecayArray<T7>::type,
13446 typename internal::DecayArray<T8>::type,
13447 typename internal::DecayArray<T9>::type,
13448 typename internal::DecayArray<T10>::type> >
13449UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
13450 const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9,
13451 const T10& e10) {
13452 typedef ::testing::tuple<
13453 typename internal::DecayArray<T1>::type,
13454 typename internal::DecayArray<T2>::type,
13455 typename internal::DecayArray<T3>::type,
13456 typename internal::DecayArray<T4>::type,
13457 typename internal::DecayArray<T5>::type,
13458 typename internal::DecayArray<T6>::type,
13459 typename internal::DecayArray<T7>::type,
13460 typename internal::DecayArray<T8>::type,
13461 typename internal::DecayArray<T9>::type,
13462 typename internal::DecayArray<T10>::type> Args;
13463 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5,
13464 e6, e7, e8, e9, e10));
13465}
13466
13467// AllOf(m1, m2, ..., mk) matches any value that matches all of the given
13468// sub-matchers. AllOf is called fully qualified to prevent ADL from firing.
13469
13470template <typename M1, typename M2>
13471inline typename internal::AllOfResult2<M1, M2>::type
13472AllOf(M1 m1, M2 m2) {
13473 return typename internal::AllOfResult2<M1, M2>::type(
13474 m1,
13475 m2);
13476}
13477
13478template <typename M1, typename M2, typename M3>
13479inline typename internal::AllOfResult3<M1, M2, M3>::type
13480AllOf(M1 m1, M2 m2, M3 m3) {
13481 return typename internal::AllOfResult3<M1, M2, M3>::type(
13482 m1,
13483 ::testing::AllOf(m2, m3));
13484}
13485
13486template <typename M1, typename M2, typename M3, typename M4>
13487inline typename internal::AllOfResult4<M1, M2, M3, M4>::type
13488AllOf(M1 m1, M2 m2, M3 m3, M4 m4) {
13489 return typename internal::AllOfResult4<M1, M2, M3, M4>::type(
13490 ::testing::AllOf(m1, m2),
13491 ::testing::AllOf(m3, m4));
13492}
13493
13494template <typename M1, typename M2, typename M3, typename M4, typename M5>
13495inline typename internal::AllOfResult5<M1, M2, M3, M4, M5>::type
13496AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5) {
13497 return typename internal::AllOfResult5<M1, M2, M3, M4, M5>::type(
13498 ::testing::AllOf(m1, m2),
13499 ::testing::AllOf(m3, m4, m5));
13500}
13501
13502template <typename M1, typename M2, typename M3, typename M4, typename M5,
13503 typename M6>
13504inline typename internal::AllOfResult6<M1, M2, M3, M4, M5, M6>::type
13505AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6) {
13506 return typename internal::AllOfResult6<M1, M2, M3, M4, M5, M6>::type(
13507 ::testing::AllOf(m1, m2, m3),
13508 ::testing::AllOf(m4, m5, m6));
13509}
13510
13511template <typename M1, typename M2, typename M3, typename M4, typename M5,
13512 typename M6, typename M7>
13513inline typename internal::AllOfResult7<M1, M2, M3, M4, M5, M6, M7>::type
13514AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7) {
13515 return typename internal::AllOfResult7<M1, M2, M3, M4, M5, M6, M7>::type(
13516 ::testing::AllOf(m1, m2, m3),
13517 ::testing::AllOf(m4, m5, m6, m7));
13518}
13519
13520template <typename M1, typename M2, typename M3, typename M4, typename M5,
13521 typename M6, typename M7, typename M8>
13522inline typename internal::AllOfResult8<M1, M2, M3, M4, M5, M6, M7, M8>::type
13523AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8) {
13524 return typename internal::AllOfResult8<M1, M2, M3, M4, M5, M6, M7, M8>::type(
13525 ::testing::AllOf(m1, m2, m3, m4),
13526 ::testing::AllOf(m5, m6, m7, m8));
13527}
13528
13529template <typename M1, typename M2, typename M3, typename M4, typename M5,
13530 typename M6, typename M7, typename M8, typename M9>
13531inline typename internal::AllOfResult9<M1, M2, M3, M4, M5, M6, M7, M8, M9>::type
13532AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9) {
13533 return typename internal::AllOfResult9<M1, M2, M3, M4, M5, M6, M7, M8,
13534 M9>::type(
13535 ::testing::AllOf(m1, m2, m3, m4),
13536 ::testing::AllOf(m5, m6, m7, m8, m9));
13537}
13538
13539template <typename M1, typename M2, typename M3, typename M4, typename M5,
13540 typename M6, typename M7, typename M8, typename M9, typename M10>
13541inline typename internal::AllOfResult10<M1, M2, M3, M4, M5, M6, M7, M8, M9,
13542 M10>::type
13543AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
13544 return typename internal::AllOfResult10<M1, M2, M3, M4, M5, M6, M7, M8, M9,
13545 M10>::type(
13546 ::testing::AllOf(m1, m2, m3, m4, m5),
13547 ::testing::AllOf(m6, m7, m8, m9, m10));
13548}
13549
13550// AnyOf(m1, m2, ..., mk) matches any value that matches any of the given
13551// sub-matchers. AnyOf is called fully qualified to prevent ADL from firing.
13552
13553template <typename M1, typename M2>
13554inline typename internal::AnyOfResult2<M1, M2>::type
13555AnyOf(M1 m1, M2 m2) {
13556 return typename internal::AnyOfResult2<M1, M2>::type(
13557 m1,
13558 m2);
13559}
13560
13561template <typename M1, typename M2, typename M3>
13562inline typename internal::AnyOfResult3<M1, M2, M3>::type
13563AnyOf(M1 m1, M2 m2, M3 m3) {
13564 return typename internal::AnyOfResult3<M1, M2, M3>::type(
13565 m1,
13566 ::testing::AnyOf(m2, m3));
13567}
13568
13569template <typename M1, typename M2, typename M3, typename M4>
13570inline typename internal::AnyOfResult4<M1, M2, M3, M4>::type
13571AnyOf(M1 m1, M2 m2, M3 m3, M4 m4) {
13572 return typename internal::AnyOfResult4<M1, M2, M3, M4>::type(
13573 ::testing::AnyOf(m1, m2),
13574 ::testing::AnyOf(m3, m4));
13575}
13576
13577template <typename M1, typename M2, typename M3, typename M4, typename M5>
13578inline typename internal::AnyOfResult5<M1, M2, M3, M4, M5>::type
13579AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5) {
13580 return typename internal::AnyOfResult5<M1, M2, M3, M4, M5>::type(
13581 ::testing::AnyOf(m1, m2),
13582 ::testing::AnyOf(m3, m4, m5));
13583}
13584
13585template <typename M1, typename M2, typename M3, typename M4, typename M5,
13586 typename M6>
13587inline typename internal::AnyOfResult6<M1, M2, M3, M4, M5, M6>::type
13588AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6) {
13589 return typename internal::AnyOfResult6<M1, M2, M3, M4, M5, M6>::type(
13590 ::testing::AnyOf(m1, m2, m3),
13591 ::testing::AnyOf(m4, m5, m6));
13592}
13593
13594template <typename M1, typename M2, typename M3, typename M4, typename M5,
13595 typename M6, typename M7>
13596inline typename internal::AnyOfResult7<M1, M2, M3, M4, M5, M6, M7>::type
13597AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7) {
13598 return typename internal::AnyOfResult7<M1, M2, M3, M4, M5, M6, M7>::type(
13599 ::testing::AnyOf(m1, m2, m3),
13600 ::testing::AnyOf(m4, m5, m6, m7));
13601}
13602
13603template <typename M1, typename M2, typename M3, typename M4, typename M5,
13604 typename M6, typename M7, typename M8>
13605inline typename internal::AnyOfResult8<M1, M2, M3, M4, M5, M6, M7, M8>::type
13606AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8) {
13607 return typename internal::AnyOfResult8<M1, M2, M3, M4, M5, M6, M7, M8>::type(
13608 ::testing::AnyOf(m1, m2, m3, m4),
13609 ::testing::AnyOf(m5, m6, m7, m8));
13610}
13611
13612template <typename M1, typename M2, typename M3, typename M4, typename M5,
13613 typename M6, typename M7, typename M8, typename M9>
13614inline typename internal::AnyOfResult9<M1, M2, M3, M4, M5, M6, M7, M8, M9>::type
13615AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9) {
13616 return typename internal::AnyOfResult9<M1, M2, M3, M4, M5, M6, M7, M8,
13617 M9>::type(
13618 ::testing::AnyOf(m1, m2, m3, m4),
13619 ::testing::AnyOf(m5, m6, m7, m8, m9));
13620}
13621
13622template <typename M1, typename M2, typename M3, typename M4, typename M5,
13623 typename M6, typename M7, typename M8, typename M9, typename M10>
13624inline typename internal::AnyOfResult10<M1, M2, M3, M4, M5, M6, M7, M8, M9,
13625 M10>::type
13626AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
13627 return typename internal::AnyOfResult10<M1, M2, M3, M4, M5, M6, M7, M8, M9,
13628 M10>::type(
13629 ::testing::AnyOf(m1, m2, m3, m4, m5),
13630 ::testing::AnyOf(m6, m7, m8, m9, m10));
13631}
13632
13633} // namespace testing
13634
13635
13636// The MATCHER* family of macros can be used in a namespace scope to
13637// define custom matchers easily.
13638//
13639// Basic Usage
13640// ===========
13641//
13642// The syntax
13643//
13644// MATCHER(name, description_string) { statements; }
13645//
13646// defines a matcher with the given name that executes the statements,
13647// which must return a bool to indicate if the match succeeds. Inside
13648// the statements, you can refer to the value being matched by 'arg',
13649// and refer to its type by 'arg_type'.
13650//
13651// The description string documents what the matcher does, and is used
13652// to generate the failure message when the match fails. Since a
13653// MATCHER() is usually defined in a header file shared by multiple
13654// C++ source files, we require the description to be a C-string
13655// literal to avoid possible side effects. It can be empty, in which
13656// case we'll use the sequence of words in the matcher name as the
13657// description.
13658//
13659// For example:
13660//
13661// MATCHER(IsEven, "") { return (arg % 2) == 0; }
13662//
13663// allows you to write
13664//
13665// // Expects mock_foo.Bar(n) to be called where n is even.
13666// EXPECT_CALL(mock_foo, Bar(IsEven()));
13667//
13668// or,
13669//
13670// // Verifies that the value of some_expression is even.
13671// EXPECT_THAT(some_expression, IsEven());
13672//
13673// If the above assertion fails, it will print something like:
13674//
13675// Value of: some_expression
13676// Expected: is even
13677// Actual: 7
13678//
13679// where the description "is even" is automatically calculated from the
13680// matcher name IsEven.
13681//
13682// Argument Type
13683// =============
13684//
13685// Note that the type of the value being matched (arg_type) is
13686// determined by the context in which you use the matcher and is
13687// supplied to you by the compiler, so you don't need to worry about
13688// declaring it (nor can you). This allows the matcher to be
13689// polymorphic. For example, IsEven() can be used to match any type
13690// where the value of "(arg % 2) == 0" can be implicitly converted to
13691// a bool. In the "Bar(IsEven())" example above, if method Bar()
13692// takes an int, 'arg_type' will be int; if it takes an unsigned long,
13693// 'arg_type' will be unsigned long; and so on.
13694//
13695// Parameterizing Matchers
13696// =======================
13697//
13698// Sometimes you'll want to parameterize the matcher. For that you
13699// can use another macro:
13700//
13701// MATCHER_P(name, param_name, description_string) { statements; }
13702//
13703// For example:
13704//
13705// MATCHER_P(HasAbsoluteValue, value, "") { return abs(arg) == value; }
13706//
13707// will allow you to write:
13708//
13709// EXPECT_THAT(Blah("a"), HasAbsoluteValue(n));
13710//
13711// which may lead to this message (assuming n is 10):
13712//
13713// Value of: Blah("a")
13714// Expected: has absolute value 10
13715// Actual: -9
13716//
13717// Note that both the matcher description and its parameter are
13718// printed, making the message human-friendly.
13719//
13720// In the matcher definition body, you can write 'foo_type' to
13721// reference the type of a parameter named 'foo'. For example, in the
13722// body of MATCHER_P(HasAbsoluteValue, value) above, you can write
13723// 'value_type' to refer to the type of 'value'.
13724//
13725// We also provide MATCHER_P2, MATCHER_P3, ..., up to MATCHER_P10 to
13726// support multi-parameter matchers.
13727//
13728// Describing Parameterized Matchers
13729// =================================
13730//
13731// The last argument to MATCHER*() is a string-typed expression. The
13732// expression can reference all of the matcher's parameters and a
13733// special bool-typed variable named 'negation'. When 'negation' is
13734// false, the expression should evaluate to the matcher's description;
13735// otherwise it should evaluate to the description of the negation of
13736// the matcher. For example,
13737//
13738// using testing::PrintToString;
13739//
13740// MATCHER_P2(InClosedRange, low, hi,
13741// string(negation ? "is not" : "is") + " in range [" +
13742// PrintToString(low) + ", " + PrintToString(hi) + "]") {
13743// return low <= arg && arg <= hi;
13744// }
13745// ...
13746// EXPECT_THAT(3, InClosedRange(4, 6));
13747// EXPECT_THAT(3, Not(InClosedRange(2, 4)));
13748//
13749// would generate two failures that contain the text:
13750//
13751// Expected: is in range [4, 6]
13752// ...
13753// Expected: is not in range [2, 4]
13754//
13755// If you specify "" as the description, the failure message will
13756// contain the sequence of words in the matcher name followed by the
13757// parameter values printed as a tuple. For example,
13758//
13759// MATCHER_P2(InClosedRange, low, hi, "") { ... }
13760// ...
13761// EXPECT_THAT(3, InClosedRange(4, 6));
13762// EXPECT_THAT(3, Not(InClosedRange(2, 4)));
13763//
13764// would generate two failures that contain the text:
13765//
13766// Expected: in closed range (4, 6)
13767// ...
13768// Expected: not (in closed range (2, 4))
13769//
13770// Types of Matcher Parameters
13771// ===========================
13772//
13773// For the purpose of typing, you can view
13774//
13775// MATCHER_Pk(Foo, p1, ..., pk, description_string) { ... }
13776//
13777// as shorthand for
13778//
13779// template <typename p1_type, ..., typename pk_type>
13780// FooMatcherPk<p1_type, ..., pk_type>
13781// Foo(p1_type p1, ..., pk_type pk) { ... }
13782//
13783// When you write Foo(v1, ..., vk), the compiler infers the types of
13784// the parameters v1, ..., and vk for you. If you are not happy with
13785// the result of the type inference, you can specify the types by
13786// explicitly instantiating the template, as in Foo<long, bool>(5,
13787// false). As said earlier, you don't get to (or need to) specify
13788// 'arg_type' as that's determined by the context in which the matcher
13789// is used. You can assign the result of expression Foo(p1, ..., pk)
13790// to a variable of type FooMatcherPk<p1_type, ..., pk_type>. This
13791// can be useful when composing matchers.
13792//
13793// While you can instantiate a matcher template with reference types,
13794// passing the parameters by pointer usually makes your code more
13795// readable. If, however, you still want to pass a parameter by
13796// reference, be aware that in the failure message generated by the
13797// matcher you will see the value of the referenced object but not its
13798// address.
13799//
13800// Explaining Match Results
13801// ========================
13802//
13803// Sometimes the matcher description alone isn't enough to explain why
13804// the match has failed or succeeded. For example, when expecting a
13805// long string, it can be very helpful to also print the diff between
13806// the expected string and the actual one. To achieve that, you can
13807// optionally stream additional information to a special variable
13808// named result_listener, whose type is a pointer to class
13809// MatchResultListener:
13810//
13811// MATCHER_P(EqualsLongString, str, "") {
13812// if (arg == str) return true;
13813//
13814// *result_listener << "the difference: "
13815/// << DiffStrings(str, arg);
13816// return false;
13817// }
13818//
13819// Overloading Matchers
13820// ====================
13821//
13822// You can overload matchers with different numbers of parameters:
13823//
13824// MATCHER_P(Blah, a, description_string1) { ... }
13825// MATCHER_P2(Blah, a, b, description_string2) { ... }
13826//
13827// Caveats
13828// =======
13829//
13830// When defining a new matcher, you should also consider implementing
13831// MatcherInterface or using MakePolymorphicMatcher(). These
13832// approaches require more work than the MATCHER* macros, but also
13833// give you more control on the types of the value being matched and
13834// the matcher parameters, which may leads to better compiler error
13835// messages when the matcher is used wrong. They also allow
13836// overloading matchers based on parameter types (as opposed to just
13837// based on the number of parameters).
13838//
13839// MATCHER*() can only be used in a namespace scope. The reason is
13840// that C++ doesn't yet allow function-local types to be used to
13841// instantiate templates. The up-coming C++0x standard will fix this.
13842// Once that's done, we'll consider supporting using MATCHER*() inside
13843// a function.
13844//
13845// More Information
13846// ================
13847//
13848// To learn more about using these macros, please search for 'MATCHER'
13849// on http://code.google.com/p/googlemock/wiki/CookBook.
13850
13851#define MATCHER(name, description)\
13852 class name##Matcher {\
13853 public:\
13854 template <typename arg_type>\
13855 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13856 public:\
13857 gmock_Impl()\
13858 {}\
13859 virtual bool MatchAndExplain(\
13860 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13861 virtual void DescribeTo(::std::ostream* gmock_os) const {\
13862 *gmock_os << FormatDescription(false);\
13863 }\
13864 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13865 *gmock_os << FormatDescription(true);\
13866 }\
13867 private:\
13868 ::testing::internal::string FormatDescription(bool negation) const {\
13869 const ::testing::internal::string gmock_description = (description);\
13870 if (!gmock_description.empty())\
13871 return gmock_description;\
13872 return ::testing::internal::FormatMatcherDescription(\
13873 negation, #name, \
13874 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13875 ::testing::tuple<>()));\
13876 }\
13877 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13878 };\
13879 template <typename arg_type>\
13880 operator ::testing::Matcher<arg_type>() const {\
13881 return ::testing::Matcher<arg_type>(\
13882 new gmock_Impl<arg_type>());\
13883 }\
13884 name##Matcher() {\
13885 }\
13886 private:\
13887 GTEST_DISALLOW_ASSIGN_(name##Matcher);\
13888 };\
13889 inline name##Matcher name() {\
13890 return name##Matcher();\
13891 }\
13892 template <typename arg_type>\
13893 bool name##Matcher::gmock_Impl<arg_type>::MatchAndExplain(\
13894 arg_type arg, \
13895 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13896 const
13897
13898#define MATCHER_P(name, p0, description)\
13899 template <typename p0##_type>\
13900 class name##MatcherP {\
13901 public:\
13902 template <typename arg_type>\
13903 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13904 public:\
13905 explicit gmock_Impl(p0##_type gmock_p0)\
13906 : p0(gmock_p0) {}\
13907 virtual bool MatchAndExplain(\
13908 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13909 virtual void DescribeTo(::std::ostream* gmock_os) const {\
13910 *gmock_os << FormatDescription(false);\
13911 }\
13912 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13913 *gmock_os << FormatDescription(true);\
13914 }\
13915 p0##_type p0;\
13916 private:\
13917 ::testing::internal::string FormatDescription(bool negation) const {\
13918 const ::testing::internal::string gmock_description = (description);\
13919 if (!gmock_description.empty())\
13920 return gmock_description;\
13921 return ::testing::internal::FormatMatcherDescription(\
13922 negation, #name, \
13923 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13924 ::testing::tuple<p0##_type>(p0)));\
13925 }\
13926 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13927 };\
13928 template <typename arg_type>\
13929 operator ::testing::Matcher<arg_type>() const {\
13930 return ::testing::Matcher<arg_type>(\
13931 new gmock_Impl<arg_type>(p0));\
13932 }\
13933 explicit name##MatcherP(p0##_type gmock_p0) : p0(gmock_p0) {\
13934 }\
13935 p0##_type p0;\
13936 private:\
13937 GTEST_DISALLOW_ASSIGN_(name##MatcherP);\
13938 };\
13939 template <typename p0##_type>\
13940 inline name##MatcherP<p0##_type> name(p0##_type p0) {\
13941 return name##MatcherP<p0##_type>(p0);\
13942 }\
13943 template <typename p0##_type>\
13944 template <typename arg_type>\
13945 bool name##MatcherP<p0##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
13946 arg_type arg, \
13947 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13948 const
13949
13950#define MATCHER_P2(name, p0, p1, description)\
13951 template <typename p0##_type, typename p1##_type>\
13952 class name##MatcherP2 {\
13953 public:\
13954 template <typename arg_type>\
13955 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13956 public:\
13957 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1)\
13958 : p0(gmock_p0), p1(gmock_p1) {}\
13959 virtual bool MatchAndExplain(\
13960 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13961 virtual void DescribeTo(::std::ostream* gmock_os) const {\
13962 *gmock_os << FormatDescription(false);\
13963 }\
13964 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13965 *gmock_os << FormatDescription(true);\
13966 }\
13967 p0##_type p0;\
13968 p1##_type p1;\
13969 private:\
13970 ::testing::internal::string FormatDescription(bool negation) const {\
13971 const ::testing::internal::string gmock_description = (description);\
13972 if (!gmock_description.empty())\
13973 return gmock_description;\
13974 return ::testing::internal::FormatMatcherDescription(\
13975 negation, #name, \
13976 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13977 ::testing::tuple<p0##_type, p1##_type>(p0, p1)));\
13978 }\
13979 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13980 };\
13981 template <typename arg_type>\
13982 operator ::testing::Matcher<arg_type>() const {\
13983 return ::testing::Matcher<arg_type>(\
13984 new gmock_Impl<arg_type>(p0, p1));\
13985 }\
13986 name##MatcherP2(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \
13987 p1(gmock_p1) {\
13988 }\
13989 p0##_type p0;\
13990 p1##_type p1;\
13991 private:\
13992 GTEST_DISALLOW_ASSIGN_(name##MatcherP2);\
13993 };\
13994 template <typename p0##_type, typename p1##_type>\
13995 inline name##MatcherP2<p0##_type, p1##_type> name(p0##_type p0, \
13996 p1##_type p1) {\
13997 return name##MatcherP2<p0##_type, p1##_type>(p0, p1);\
13998 }\
13999 template <typename p0##_type, typename p1##_type>\
14000 template <typename arg_type>\
14001 bool name##MatcherP2<p0##_type, \
14002 p1##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
14003 arg_type arg, \
14004 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
14005 const
14006
14007#define MATCHER_P3(name, p0, p1, p2, description)\
14008 template <typename p0##_type, typename p1##_type, typename p2##_type>\
14009 class name##MatcherP3 {\
14010 public:\
14011 template <typename arg_type>\
14012 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
14013 public:\
14014 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2)\
14015 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\
14016 virtual bool MatchAndExplain(\
14017 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
14018 virtual void DescribeTo(::std::ostream* gmock_os) const {\
14019 *gmock_os << FormatDescription(false);\
14020 }\
14021 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
14022 *gmock_os << FormatDescription(true);\
14023 }\
14024 p0##_type p0;\
14025 p1##_type p1;\
14026 p2##_type p2;\
14027 private:\
14028 ::testing::internal::string FormatDescription(bool negation) const {\
14029 const ::testing::internal::string gmock_description = (description);\
14030 if (!gmock_description.empty())\
14031 return gmock_description;\
14032 return ::testing::internal::FormatMatcherDescription(\
14033 negation, #name, \
14034 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
14035 ::testing::tuple<p0##_type, p1##_type, p2##_type>(p0, p1, \
14036 p2)));\
14037 }\
14038 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
14039 };\
14040 template <typename arg_type>\
14041 operator ::testing::Matcher<arg_type>() const {\
14042 return ::testing::Matcher<arg_type>(\
14043 new gmock_Impl<arg_type>(p0, p1, p2));\
14044 }\
14045 name##MatcherP3(p0##_type gmock_p0, p1##_type gmock_p1, \
14046 p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {\
14047 }\
14048 p0##_type p0;\
14049 p1##_type p1;\
14050 p2##_type p2;\
14051 private:\
14052 GTEST_DISALLOW_ASSIGN_(name##MatcherP3);\
14053 };\
14054 template <typename p0##_type, typename p1##_type, typename p2##_type>\
14055 inline name##MatcherP3<p0##_type, p1##_type, p2##_type> name(p0##_type p0, \
14056 p1##_type p1, p2##_type p2) {\
14057 return name##MatcherP3<p0##_type, p1##_type, p2##_type>(p0, p1, p2);\
14058 }\
14059 template <typename p0##_type, typename p1##_type, typename p2##_type>\
14060 template <typename arg_type>\
14061 bool name##MatcherP3<p0##_type, p1##_type, \
14062 p2##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
14063 arg_type arg, \
14064 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
14065 const
14066
14067#define MATCHER_P4(name, p0, p1, p2, p3, description)\
14068 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14069 typename p3##_type>\
14070 class name##MatcherP4 {\
14071 public:\
14072 template <typename arg_type>\
14073 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
14074 public:\
14075 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
14076 p3##_type gmock_p3)\
14077 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3) {}\
14078 virtual bool MatchAndExplain(\
14079 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
14080 virtual void DescribeTo(::std::ostream* gmock_os) const {\
14081 *gmock_os << FormatDescription(false);\
14082 }\
14083 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
14084 *gmock_os << FormatDescription(true);\
14085 }\
14086 p0##_type p0;\
14087 p1##_type p1;\
14088 p2##_type p2;\
14089 p3##_type p3;\
14090 private:\
14091 ::testing::internal::string FormatDescription(bool negation) const {\
14092 const ::testing::internal::string gmock_description = (description);\
14093 if (!gmock_description.empty())\
14094 return gmock_description;\
14095 return ::testing::internal::FormatMatcherDescription(\
14096 negation, #name, \
14097 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
14098 ::testing::tuple<p0##_type, p1##_type, p2##_type, \
14099 p3##_type>(p0, p1, p2, p3)));\
14100 }\
14101 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
14102 };\
14103 template <typename arg_type>\
14104 operator ::testing::Matcher<arg_type>() const {\
14105 return ::testing::Matcher<arg_type>(\
14106 new gmock_Impl<arg_type>(p0, p1, p2, p3));\
14107 }\
14108 name##MatcherP4(p0##_type gmock_p0, p1##_type gmock_p1, \
14109 p2##_type gmock_p2, p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), \
14110 p2(gmock_p2), p3(gmock_p3) {\
14111 }\
14112 p0##_type p0;\
14113 p1##_type p1;\
14114 p2##_type p2;\
14115 p3##_type p3;\
14116 private:\
14117 GTEST_DISALLOW_ASSIGN_(name##MatcherP4);\
14118 };\
14119 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14120 typename p3##_type>\
14121 inline name##MatcherP4<p0##_type, p1##_type, p2##_type, \
14122 p3##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
14123 p3##_type p3) {\
14124 return name##MatcherP4<p0##_type, p1##_type, p2##_type, p3##_type>(p0, \
14125 p1, p2, p3);\
14126 }\
14127 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14128 typename p3##_type>\
14129 template <typename arg_type>\
14130 bool name##MatcherP4<p0##_type, p1##_type, p2##_type, \
14131 p3##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
14132 arg_type arg, \
14133 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
14134 const
14135
14136#define MATCHER_P5(name, p0, p1, p2, p3, p4, description)\
14137 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14138 typename p3##_type, typename p4##_type>\
14139 class name##MatcherP5 {\
14140 public:\
14141 template <typename arg_type>\
14142 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
14143 public:\
14144 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
14145 p3##_type gmock_p3, p4##_type gmock_p4)\
14146 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
14147 p4(gmock_p4) {}\
14148 virtual bool MatchAndExplain(\
14149 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
14150 virtual void DescribeTo(::std::ostream* gmock_os) const {\
14151 *gmock_os << FormatDescription(false);\
14152 }\
14153 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
14154 *gmock_os << FormatDescription(true);\
14155 }\
14156 p0##_type p0;\
14157 p1##_type p1;\
14158 p2##_type p2;\
14159 p3##_type p3;\
14160 p4##_type p4;\
14161 private:\
14162 ::testing::internal::string FormatDescription(bool negation) const {\
14163 const ::testing::internal::string gmock_description = (description);\
14164 if (!gmock_description.empty())\
14165 return gmock_description;\
14166 return ::testing::internal::FormatMatcherDescription(\
14167 negation, #name, \
14168 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
14169 ::testing::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
14170 p4##_type>(p0, p1, p2, p3, p4)));\
14171 }\
14172 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
14173 };\
14174 template <typename arg_type>\
14175 operator ::testing::Matcher<arg_type>() const {\
14176 return ::testing::Matcher<arg_type>(\
14177 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4));\
14178 }\
14179 name##MatcherP5(p0##_type gmock_p0, p1##_type gmock_p1, \
14180 p2##_type gmock_p2, p3##_type gmock_p3, \
14181 p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
14182 p3(gmock_p3), p4(gmock_p4) {\
14183 }\
14184 p0##_type p0;\
14185 p1##_type p1;\
14186 p2##_type p2;\
14187 p3##_type p3;\
14188 p4##_type p4;\
14189 private:\
14190 GTEST_DISALLOW_ASSIGN_(name##MatcherP5);\
14191 };\
14192 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14193 typename p3##_type, typename p4##_type>\
14194 inline name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \
14195 p4##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
14196 p4##_type p4) {\
14197 return name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \
14198 p4##_type>(p0, p1, p2, p3, p4);\
14199 }\
14200 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14201 typename p3##_type, typename p4##_type>\
14202 template <typename arg_type>\
14203 bool name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \
14204 p4##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
14205 arg_type arg, \
14206 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
14207 const
14208
14209#define MATCHER_P6(name, p0, p1, p2, p3, p4, p5, description)\
14210 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14211 typename p3##_type, typename p4##_type, typename p5##_type>\
14212 class name##MatcherP6 {\
14213 public:\
14214 template <typename arg_type>\
14215 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
14216 public:\
14217 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
14218 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5)\
14219 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
14220 p4(gmock_p4), p5(gmock_p5) {}\
14221 virtual bool MatchAndExplain(\
14222 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
14223 virtual void DescribeTo(::std::ostream* gmock_os) const {\
14224 *gmock_os << FormatDescription(false);\
14225 }\
14226 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
14227 *gmock_os << FormatDescription(true);\
14228 }\
14229 p0##_type p0;\
14230 p1##_type p1;\
14231 p2##_type p2;\
14232 p3##_type p3;\
14233 p4##_type p4;\
14234 p5##_type p5;\
14235 private:\
14236 ::testing::internal::string FormatDescription(bool negation) const {\
14237 const ::testing::internal::string gmock_description = (description);\
14238 if (!gmock_description.empty())\
14239 return gmock_description;\
14240 return ::testing::internal::FormatMatcherDescription(\
14241 negation, #name, \
14242 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
14243 ::testing::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
14244 p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5)));\
14245 }\
14246 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
14247 };\
14248 template <typename arg_type>\
14249 operator ::testing::Matcher<arg_type>() const {\
14250 return ::testing::Matcher<arg_type>(\
14251 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5));\
14252 }\
14253 name##MatcherP6(p0##_type gmock_p0, p1##_type gmock_p1, \
14254 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
14255 p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
14256 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {\
14257 }\
14258 p0##_type p0;\
14259 p1##_type p1;\
14260 p2##_type p2;\
14261 p3##_type p3;\
14262 p4##_type p4;\
14263 p5##_type p5;\
14264 private:\
14265 GTEST_DISALLOW_ASSIGN_(name##MatcherP6);\
14266 };\
14267 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14268 typename p3##_type, typename p4##_type, typename p5##_type>\
14269 inline name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, \
14270 p4##_type, p5##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
14271 p3##_type p3, p4##_type p4, p5##_type p5) {\
14272 return name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, \
14273 p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5);\
14274 }\
14275 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14276 typename p3##_type, typename p4##_type, typename p5##_type>\
14277 template <typename arg_type>\
14278 bool name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
14279 p5##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
14280 arg_type arg, \
14281 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
14282 const
14283
14284#define MATCHER_P7(name, p0, p1, p2, p3, p4, p5, p6, description)\
14285 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14286 typename p3##_type, typename p4##_type, typename p5##_type, \
14287 typename p6##_type>\
14288 class name##MatcherP7 {\
14289 public:\
14290 template <typename arg_type>\
14291 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
14292 public:\
14293 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
14294 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
14295 p6##_type gmock_p6)\
14296 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
14297 p4(gmock_p4), p5(gmock_p5), p6(gmock_p6) {}\
14298 virtual bool MatchAndExplain(\
14299 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
14300 virtual void DescribeTo(::std::ostream* gmock_os) const {\
14301 *gmock_os << FormatDescription(false);\
14302 }\
14303 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
14304 *gmock_os << FormatDescription(true);\
14305 }\
14306 p0##_type p0;\
14307 p1##_type p1;\
14308 p2##_type p2;\
14309 p3##_type p3;\
14310 p4##_type p4;\
14311 p5##_type p5;\
14312 p6##_type p6;\
14313 private:\
14314 ::testing::internal::string FormatDescription(bool negation) const {\
14315 const ::testing::internal::string gmock_description = (description);\
14316 if (!gmock_description.empty())\
14317 return gmock_description;\
14318 return ::testing::internal::FormatMatcherDescription(\
14319 negation, #name, \
14320 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
14321 ::testing::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
14322 p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, \
14323 p6)));\
14324 }\
14325 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
14326 };\
14327 template <typename arg_type>\
14328 operator ::testing::Matcher<arg_type>() const {\
14329 return ::testing::Matcher<arg_type>(\
14330 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6));\
14331 }\
14332 name##MatcherP7(p0##_type gmock_p0, p1##_type gmock_p1, \
14333 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
14334 p5##_type gmock_p5, p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), \
14335 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), \
14336 p6(gmock_p6) {\
14337 }\
14338 p0##_type p0;\
14339 p1##_type p1;\
14340 p2##_type p2;\
14341 p3##_type p3;\
14342 p4##_type p4;\
14343 p5##_type p5;\
14344 p6##_type p6;\
14345 private:\
14346 GTEST_DISALLOW_ASSIGN_(name##MatcherP7);\
14347 };\
14348 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14349 typename p3##_type, typename p4##_type, typename p5##_type, \
14350 typename p6##_type>\
14351 inline name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, \
14352 p4##_type, p5##_type, p6##_type> name(p0##_type p0, p1##_type p1, \
14353 p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
14354 p6##_type p6) {\
14355 return name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, \
14356 p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, p6);\
14357 }\
14358 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14359 typename p3##_type, typename p4##_type, typename p5##_type, \
14360 typename p6##_type>\
14361 template <typename arg_type>\
14362 bool name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
14363 p5##_type, p6##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
14364 arg_type arg, \
14365 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
14366 const
14367
14368#define MATCHER_P8(name, p0, p1, p2, p3, p4, p5, p6, p7, description)\
14369 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14370 typename p3##_type, typename p4##_type, typename p5##_type, \
14371 typename p6##_type, typename p7##_type>\
14372 class name##MatcherP8 {\
14373 public:\
14374 template <typename arg_type>\
14375 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
14376 public:\
14377 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
14378 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
14379 p6##_type gmock_p6, p7##_type gmock_p7)\
14380 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
14381 p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7) {}\
14382 virtual bool MatchAndExplain(\
14383 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
14384 virtual void DescribeTo(::std::ostream* gmock_os) const {\
14385 *gmock_os << FormatDescription(false);\
14386 }\
14387 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
14388 *gmock_os << FormatDescription(true);\
14389 }\
14390 p0##_type p0;\
14391 p1##_type p1;\
14392 p2##_type p2;\
14393 p3##_type p3;\
14394 p4##_type p4;\
14395 p5##_type p5;\
14396 p6##_type p6;\
14397 p7##_type p7;\
14398 private:\
14399 ::testing::internal::string FormatDescription(bool negation) const {\
14400 const ::testing::internal::string gmock_description = (description);\
14401 if (!gmock_description.empty())\
14402 return gmock_description;\
14403 return ::testing::internal::FormatMatcherDescription(\
14404 negation, #name, \
14405 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
14406 ::testing::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
14407 p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, \
14408 p3, p4, p5, p6, p7)));\
14409 }\
14410 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
14411 };\
14412 template <typename arg_type>\
14413 operator ::testing::Matcher<arg_type>() const {\
14414 return ::testing::Matcher<arg_type>(\
14415 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7));\
14416 }\
14417 name##MatcherP8(p0##_type gmock_p0, p1##_type gmock_p1, \
14418 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
14419 p5##_type gmock_p5, p6##_type gmock_p6, \
14420 p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
14421 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
14422 p7(gmock_p7) {\
14423 }\
14424 p0##_type p0;\
14425 p1##_type p1;\
14426 p2##_type p2;\
14427 p3##_type p3;\
14428 p4##_type p4;\
14429 p5##_type p5;\
14430 p6##_type p6;\
14431 p7##_type p7;\
14432 private:\
14433 GTEST_DISALLOW_ASSIGN_(name##MatcherP8);\
14434 };\
14435 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14436 typename p3##_type, typename p4##_type, typename p5##_type, \
14437 typename p6##_type, typename p7##_type>\
14438 inline name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, \
14439 p4##_type, p5##_type, p6##_type, p7##_type> name(p0##_type p0, \
14440 p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
14441 p6##_type p6, p7##_type p7) {\
14442 return name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, \
14443 p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, p3, p4, p5, \
14444 p6, p7);\
14445 }\
14446 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14447 typename p3##_type, typename p4##_type, typename p5##_type, \
14448 typename p6##_type, typename p7##_type>\
14449 template <typename arg_type>\
14450 bool name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
14451 p5##_type, p6##_type, \
14452 p7##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
14453 arg_type arg, \
14454 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
14455 const
14456
14457#define MATCHER_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, description)\
14458 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14459 typename p3##_type, typename p4##_type, typename p5##_type, \
14460 typename p6##_type, typename p7##_type, typename p8##_type>\
14461 class name##MatcherP9 {\
14462 public:\
14463 template <typename arg_type>\
14464 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
14465 public:\
14466 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
14467 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
14468 p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8)\
14469 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
14470 p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
14471 p8(gmock_p8) {}\
14472 virtual bool MatchAndExplain(\
14473 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
14474 virtual void DescribeTo(::std::ostream* gmock_os) const {\
14475 *gmock_os << FormatDescription(false);\
14476 }\
14477 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
14478 *gmock_os << FormatDescription(true);\
14479 }\
14480 p0##_type p0;\
14481 p1##_type p1;\
14482 p2##_type p2;\
14483 p3##_type p3;\
14484 p4##_type p4;\
14485 p5##_type p5;\
14486 p6##_type p6;\
14487 p7##_type p7;\
14488 p8##_type p8;\
14489 private:\
14490 ::testing::internal::string FormatDescription(bool negation) const {\
14491 const ::testing::internal::string gmock_description = (description);\
14492 if (!gmock_description.empty())\
14493 return gmock_description;\
14494 return ::testing::internal::FormatMatcherDescription(\
14495 negation, #name, \
14496 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
14497 ::testing::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
14498 p4##_type, p5##_type, p6##_type, p7##_type, \
14499 p8##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8)));\
14500 }\
14501 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
14502 };\
14503 template <typename arg_type>\
14504 operator ::testing::Matcher<arg_type>() const {\
14505 return ::testing::Matcher<arg_type>(\
14506 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8));\
14507 }\
14508 name##MatcherP9(p0##_type gmock_p0, p1##_type gmock_p1, \
14509 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
14510 p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
14511 p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
14512 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
14513 p8(gmock_p8) {\
14514 }\
14515 p0##_type p0;\
14516 p1##_type p1;\
14517 p2##_type p2;\
14518 p3##_type p3;\
14519 p4##_type p4;\
14520 p5##_type p5;\
14521 p6##_type p6;\
14522 p7##_type p7;\
14523 p8##_type p8;\
14524 private:\
14525 GTEST_DISALLOW_ASSIGN_(name##MatcherP9);\
14526 };\
14527 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14528 typename p3##_type, typename p4##_type, typename p5##_type, \
14529 typename p6##_type, typename p7##_type, typename p8##_type>\
14530 inline name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, \
14531 p4##_type, p5##_type, p6##_type, p7##_type, \
14532 p8##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
14533 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, \
14534 p8##_type p8) {\
14535 return name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, \
14536 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type>(p0, p1, p2, \
14537 p3, p4, p5, p6, p7, p8);\
14538 }\
14539 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14540 typename p3##_type, typename p4##_type, typename p5##_type, \
14541 typename p6##_type, typename p7##_type, typename p8##_type>\
14542 template <typename arg_type>\
14543 bool name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
14544 p5##_type, p6##_type, p7##_type, \
14545 p8##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
14546 arg_type arg, \
14547 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
14548 const
14549
14550#define MATCHER_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, description)\
14551 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14552 typename p3##_type, typename p4##_type, typename p5##_type, \
14553 typename p6##_type, typename p7##_type, typename p8##_type, \
14554 typename p9##_type>\
14555 class name##MatcherP10 {\
14556 public:\
14557 template <typename arg_type>\
14558 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
14559 public:\
14560 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
14561 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
14562 p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
14563 p9##_type gmock_p9)\
14564 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
14565 p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
14566 p8(gmock_p8), p9(gmock_p9) {}\
14567 virtual bool MatchAndExplain(\
14568 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
14569 virtual void DescribeTo(::std::ostream* gmock_os) const {\
14570 *gmock_os << FormatDescription(false);\
14571 }\
14572 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
14573 *gmock_os << FormatDescription(true);\
14574 }\
14575 p0##_type p0;\
14576 p1##_type p1;\
14577 p2##_type p2;\
14578 p3##_type p3;\
14579 p4##_type p4;\
14580 p5##_type p5;\
14581 p6##_type p6;\
14582 p7##_type p7;\
14583 p8##_type p8;\
14584 p9##_type p9;\
14585 private:\
14586 ::testing::internal::string FormatDescription(bool negation) const {\
14587 const ::testing::internal::string gmock_description = (description);\
14588 if (!gmock_description.empty())\
14589 return gmock_description;\
14590 return ::testing::internal::FormatMatcherDescription(\
14591 negation, #name, \
14592 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
14593 ::testing::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
14594 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
14595 p9##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)));\
14596 }\
14597 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
14598 };\
14599 template <typename arg_type>\
14600 operator ::testing::Matcher<arg_type>() const {\
14601 return ::testing::Matcher<arg_type>(\
14602 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9));\
14603 }\
14604 name##MatcherP10(p0##_type gmock_p0, p1##_type gmock_p1, \
14605 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
14606 p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
14607 p8##_type gmock_p8, p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), \
14608 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
14609 p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {\
14610 }\
14611 p0##_type p0;\
14612 p1##_type p1;\
14613 p2##_type p2;\
14614 p3##_type p3;\
14615 p4##_type p4;\
14616 p5##_type p5;\
14617 p6##_type p6;\
14618 p7##_type p7;\
14619 p8##_type p8;\
14620 p9##_type p9;\
14621 private:\
14622 GTEST_DISALLOW_ASSIGN_(name##MatcherP10);\
14623 };\
14624 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14625 typename p3##_type, typename p4##_type, typename p5##_type, \
14626 typename p6##_type, typename p7##_type, typename p8##_type, \
14627 typename p9##_type>\
14628 inline name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \
14629 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
14630 p9##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
14631 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \
14632 p9##_type p9) {\
14633 return name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \
14634 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, p9##_type>(p0, \
14635 p1, p2, p3, p4, p5, p6, p7, p8, p9);\
14636 }\
14637 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14638 typename p3##_type, typename p4##_type, typename p5##_type, \
14639 typename p6##_type, typename p7##_type, typename p8##_type, \
14640 typename p9##_type>\
14641 template <typename arg_type>\
14642 bool name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \
14643 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
14644 p9##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
14645 arg_type arg, \
14646 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
14647 const
14648
14649#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
14650// Copyright 2007, Google Inc.
14651// All rights reserved.
14652//
14653// Redistribution and use in source and binary forms, with or without
14654// modification, are permitted provided that the following conditions are
14655// met:
14656//
14657// * Redistributions of source code must retain the above copyright
14658// notice, this list of conditions and the following disclaimer.
14659// * Redistributions in binary form must reproduce the above
14660// copyright notice, this list of conditions and the following disclaimer
14661// in the documentation and/or other materials provided with the
14662// distribution.
14663// * Neither the name of Google Inc. nor the names of its
14664// contributors may be used to endorse or promote products derived from
14665// this software without specific prior written permission.
14666//
14667// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14668// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14669// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
14670// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
14671// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
14672// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
14673// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
14674// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
14675// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14676// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14677// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14678//
14679// Author: wan@google.com (Zhanyong Wan)
14680
14681// Google Mock - a framework for writing C++ mock classes.
14682//
14683// This file implements some actions that depend on gmock-generated-actions.h.
14684
14685#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
14686#define GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
14687
14688#include <algorithm>
14689
14690
14691namespace testing {
14692namespace internal {
14693
14694// Implements the Invoke(f) action. The template argument
14695// FunctionImpl is the implementation type of f, which can be either a
14696// function pointer or a functor. Invoke(f) can be used as an
14697// Action<F> as long as f's type is compatible with F (i.e. f can be
14698// assigned to a tr1::function<F>).
14699template <typename FunctionImpl>
14700class InvokeAction {
14701 public:
14702 // The c'tor makes a copy of function_impl (either a function
14703 // pointer or a functor).
14704 explicit InvokeAction(FunctionImpl function_impl)
14705 : function_impl_(function_impl) {}
14706
14707 template <typename Result, typename ArgumentTuple>
14708 Result Perform(const ArgumentTuple& args) {
14709 return InvokeHelper<Result, ArgumentTuple>::Invoke(function_impl_, args);
14710 }
14711
14712 private:
14713 FunctionImpl function_impl_;
14714
14715 GTEST_DISALLOW_ASSIGN_(InvokeAction);
14716};
14717
14718// Implements the Invoke(object_ptr, &Class::Method) action.
14719template <class Class, typename MethodPtr>
14720class InvokeMethodAction {
14721 public:
14722 InvokeMethodAction(Class* obj_ptr, MethodPtr method_ptr)
14723 : method_ptr_(method_ptr), obj_ptr_(obj_ptr) {}
14724
14725 template <typename Result, typename ArgumentTuple>
14726 Result Perform(const ArgumentTuple& args) const {
14727 return InvokeHelper<Result, ArgumentTuple>::InvokeMethod(
14728 obj_ptr_, method_ptr_, args);
14729 }
14730
14731 private:
14732 // The order of these members matters. Reversing the order can trigger
14733 // warning C4121 in MSVC (see
14734 // http://computer-programming-forum.com/7-vc.net/6fbc30265f860ad1.htm ).
14735 const MethodPtr method_ptr_;
14736 Class* const obj_ptr_;
14737
14738 GTEST_DISALLOW_ASSIGN_(InvokeMethodAction);
14739};
14740
14741// An internal replacement for std::copy which mimics its behavior. This is
14742// necessary because Visual Studio deprecates ::std::copy, issuing warning 4996.
14743// However Visual Studio 2010 and later do not honor #pragmas which disable that
14744// warning.
14745template<typename InputIterator, typename OutputIterator>
14746inline OutputIterator CopyElements(InputIterator first,
14747 InputIterator last,
14748 OutputIterator output) {
14749 for (; first != last; ++first, ++output) {
14750 *output = *first;
14751 }
14752 return output;
14753}
14754
14755} // namespace internal
14756
14757// Various overloads for Invoke().
14758
14759// Creates an action that invokes 'function_impl' with the mock
14760// function's arguments.
14761template <typename FunctionImpl>
14762PolymorphicAction<internal::InvokeAction<FunctionImpl> > Invoke(
14763 FunctionImpl function_impl) {
14764 return MakePolymorphicAction(
14765 internal::InvokeAction<FunctionImpl>(function_impl));
14766}
14767
14768// Creates an action that invokes the given method on the given object
14769// with the mock function's arguments.
14770template <class Class, typename MethodPtr>
14771PolymorphicAction<internal::InvokeMethodAction<Class, MethodPtr> > Invoke(
14772 Class* obj_ptr, MethodPtr method_ptr) {
14773 return MakePolymorphicAction(
14774 internal::InvokeMethodAction<Class, MethodPtr>(obj_ptr, method_ptr));
14775}
14776
14777// WithoutArgs(inner_action) can be used in a mock function with a
14778// non-empty argument list to perform inner_action, which takes no
14779// argument. In other words, it adapts an action accepting no
14780// argument to one that accepts (and ignores) arguments.
14781template <typename InnerAction>
14782inline internal::WithArgsAction<InnerAction>
14783WithoutArgs(const InnerAction& action) {
14784 return internal::WithArgsAction<InnerAction>(action);
14785}
14786
14787// WithArg<k>(an_action) creates an action that passes the k-th
14788// (0-based) argument of the mock function to an_action and performs
14789// it. It adapts an action accepting one argument to one that accepts
14790// multiple arguments. For convenience, we also provide
14791// WithArgs<k>(an_action) (defined below) as a synonym.
14792template <int k, typename InnerAction>
14793inline internal::WithArgsAction<InnerAction, k>
14794WithArg(const InnerAction& action) {
14795 return internal::WithArgsAction<InnerAction, k>(action);
14796}
14797
14798// The ACTION*() macros trigger warning C4100 (unreferenced formal
14799// parameter) in MSVC with -W4. Unfortunately they cannot be fixed in
14800// the macro definition, as the warnings are generated when the macro
14801// is expanded and macro expansion cannot contain #pragma. Therefore
14802// we suppress them here.
14803#ifdef _MSC_VER
14804# pragma warning(push)
14805# pragma warning(disable:4100)
14806#endif
14807
14808// Action ReturnArg<k>() returns the k-th argument of the mock function.
14809ACTION_TEMPLATE(ReturnArg,
14810 HAS_1_TEMPLATE_PARAMS(int, k),
14811 AND_0_VALUE_PARAMS()) {
14812 return ::testing::get<k>(args);
14813}
14814
14815// Action SaveArg<k>(pointer) saves the k-th (0-based) argument of the
14816// mock function to *pointer.
14817ACTION_TEMPLATE(SaveArg,
14818 HAS_1_TEMPLATE_PARAMS(int, k),
14819 AND_1_VALUE_PARAMS(pointer)) {
14820 *pointer = ::testing::get<k>(args);
14821}
14822
14823// Action SaveArgPointee<k>(pointer) saves the value pointed to
14824// by the k-th (0-based) argument of the mock function to *pointer.
14825ACTION_TEMPLATE(SaveArgPointee,
14826 HAS_1_TEMPLATE_PARAMS(int, k),
14827 AND_1_VALUE_PARAMS(pointer)) {
14828 *pointer = *::testing::get<k>(args);
14829}
14830
14831// Action SetArgReferee<k>(value) assigns 'value' to the variable
14832// referenced by the k-th (0-based) argument of the mock function.
14833ACTION_TEMPLATE(SetArgReferee,
14834 HAS_1_TEMPLATE_PARAMS(int, k),
14835 AND_1_VALUE_PARAMS(value)) {
14836 typedef typename ::testing::tuple_element<k, args_type>::type argk_type;
14837 // Ensures that argument #k is a reference. If you get a compiler
14838 // error on the next line, you are using SetArgReferee<k>(value) in
14839 // a mock function whose k-th (0-based) argument is not a reference.
14840 GTEST_COMPILE_ASSERT_(internal::is_reference<argk_type>::value,
14841 SetArgReferee_must_be_used_with_a_reference_argument);
14842 ::testing::get<k>(args) = value;
14843}
14844
14845// Action SetArrayArgument<k>(first, last) copies the elements in
14846// source range [first, last) to the array pointed to by the k-th
14847// (0-based) argument, which can be either a pointer or an
14848// iterator. The action does not take ownership of the elements in the
14849// source range.
14850ACTION_TEMPLATE(SetArrayArgument,
14851 HAS_1_TEMPLATE_PARAMS(int, k),
14852 AND_2_VALUE_PARAMS(first, last)) {
14853 // Visual Studio deprecates ::std::copy, so we use our own copy in that case.
14854#ifdef _MSC_VER
14855 internal::CopyElements(first, last, ::testing::get<k>(args));
14856#else
14857 ::std::copy(first, last, ::testing::get<k>(args));
14858#endif
14859}
14860
14861// Action DeleteArg<k>() deletes the k-th (0-based) argument of the mock
14862// function.
14863ACTION_TEMPLATE(DeleteArg,
14864 HAS_1_TEMPLATE_PARAMS(int, k),
14865 AND_0_VALUE_PARAMS()) {
14866 delete ::testing::get<k>(args);
14867}
14868
14869// This action returns the value pointed to by 'pointer'.
14870ACTION_P(ReturnPointee, pointer) { return *pointer; }
14871
14872// Action Throw(exception) can be used in a mock function of any type
14873// to throw the given exception. Any copyable value can be thrown.
14874#if GTEST_HAS_EXCEPTIONS
14875
14876// Suppresses the 'unreachable code' warning that VC generates in opt modes.
14877# ifdef _MSC_VER
14878# pragma warning(push) // Saves the current warning state.
14879# pragma warning(disable:4702) // Temporarily disables warning 4702.
14880# endif
14881ACTION_P(Throw, exception) { throw exception; }
14882# ifdef _MSC_VER
14883# pragma warning(pop) // Restores the warning state.
14884# endif
14885
14886#endif // GTEST_HAS_EXCEPTIONS
14887
14888#ifdef _MSC_VER
14889# pragma warning(pop)
14890#endif
14891
14892} // namespace testing
14893
14894#endif // GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
14895// Copyright 2013, Google Inc.
14896// All rights reserved.
14897//
14898// Redistribution and use in source and binary forms, with or without
14899// modification, are permitted provided that the following conditions are
14900// met:
14901//
14902// * Redistributions of source code must retain the above copyright
14903// notice, this list of conditions and the following disclaimer.
14904// * Redistributions in binary form must reproduce the above
14905// copyright notice, this list of conditions and the following disclaimer
14906// in the documentation and/or other materials provided with the
14907// distribution.
14908// * Neither the name of Google Inc. nor the names of its
14909// contributors may be used to endorse or promote products derived from
14910// this software without specific prior written permission.
14911//
14912// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14913// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14914// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
14915// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
14916// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
14917// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
14918// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
14919// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
14920// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14921// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14922// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14923//
14924// Author: marcus.boerger@google.com (Marcus Boerger)
14925
14926// Google Mock - a framework for writing C++ mock classes.
14927//
14928// This file implements some matchers that depend on gmock-generated-matchers.h.
14929//
14930// Note that tests are implemented in gmock-matchers_test.cc rather than
14931// gmock-more-matchers-test.cc.
14932
14933#ifndef GMOCK_GMOCK_MORE_MATCHERS_H_
14934#define GMOCK_GMOCK_MORE_MATCHERS_H_
14935
14936
14937namespace testing {
14938
14939// Defines a matcher that matches an empty container. The container must
14940// support both size() and empty(), which all STL-like containers provide.
14941MATCHER(IsEmpty, negation ? "isn't empty" : "is empty") {
14942 if (arg.empty()) {
14943 return true;
14944 }
14945 *result_listener << "whose size is " << arg.size();
14946 return false;
14947}
14948
14949} // namespace testing
14950
14951#endif // GMOCK_GMOCK_MORE_MATCHERS_H_
14952
14953namespace testing {
14954
14955// Declares Google Mock flags that we want a user to use programmatically.
14956GMOCK_DECLARE_bool_(catch_leaked_mocks);
14957GMOCK_DECLARE_string_(verbose);
14958
14959// Initializes Google Mock. This must be called before running the
14960// tests. In particular, it parses the command line for the flags
14961// that Google Mock recognizes. Whenever a Google Mock flag is seen,
14962// it is removed from argv, and *argc is decremented.
14963//
14964// No value is returned. Instead, the Google Mock flag variables are
14965// updated.
14966//
14967// Since Google Test is needed for Google Mock to work, this function
14968// also initializes Google Test and parses its flags, if that hasn't
14969// been done.
14970GTEST_API_ void InitGoogleMock(int* argc, char** argv);
14971
14972// This overloaded version can be used in Windows programs compiled in
14973// UNICODE mode.
14974GTEST_API_ void InitGoogleMock(int* argc, wchar_t** argv);
14975
14976} // namespace testing
14977
14978#endif // GMOCK_INCLUDE_GMOCK_GMOCK_H_