blob: 2180319ddb1dd0300dfc3594f991b85972e3eebe [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.
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080029
Austin Schuh70cc9552019-01-21 19:46:48 -080030
31// Google Mock - a framework for writing C++ mock classes.
32//
33// This is the main header file a user should include.
34
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080035// GOOGLETEST_CM0002 DO NOT DELETE
36
Austin Schuh70cc9552019-01-21 19:46:48 -080037#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_H_
38#define GMOCK_INCLUDE_GMOCK_GMOCK_H_
39
40// This file implements the following syntax:
41//
42// ON_CALL(mock_object.Method(...))
43// .With(...) ?
44// .WillByDefault(...);
45//
46// where With() is optional and WillByDefault() must appear exactly
47// once.
48//
49// EXPECT_CALL(mock_object.Method(...))
50// .With(...) ?
51// .Times(...) ?
52// .InSequence(...) *
53// .WillOnce(...) *
54// .WillRepeatedly(...) ?
55// .RetiresOnSaturation() ? ;
56//
57// where all clauses are optional and WillOnce() can be repeated.
58
59// Copyright 2007, Google Inc.
60// All rights reserved.
61//
62// Redistribution and use in source and binary forms, with or without
63// modification, are permitted provided that the following conditions are
64// met:
65//
66// * Redistributions of source code must retain the above copyright
67// notice, this list of conditions and the following disclaimer.
68// * Redistributions in binary form must reproduce the above
69// copyright notice, this list of conditions and the following disclaimer
70// in the documentation and/or other materials provided with the
71// distribution.
72// * Neither the name of Google Inc. nor the names of its
73// contributors may be used to endorse or promote products derived from
74// this software without specific prior written permission.
75//
76// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
77// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
78// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
79// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
80// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
81// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
82// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
83// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
84// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
85// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
86// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080087
Austin Schuh70cc9552019-01-21 19:46:48 -080088
89// Google Mock - a framework for writing C++ mock classes.
90//
91// This file implements some commonly used actions.
92
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080093// GOOGLETEST_CM0002 DO NOT DELETE
94
Austin Schuh70cc9552019-01-21 19:46:48 -080095#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
96#define GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
97
98#ifndef _WIN32_WCE
99# include <errno.h>
100#endif
101
102#include <algorithm>
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800103#include <functional>
104#include <memory>
Austin Schuh70cc9552019-01-21 19:46:48 -0800105#include <string>
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800106#include <type_traits>
107#include <utility>
Austin Schuh70cc9552019-01-21 19:46:48 -0800108
109// Copyright 2007, Google Inc.
110// All rights reserved.
111//
112// Redistribution and use in source and binary forms, with or without
113// modification, are permitted provided that the following conditions are
114// met:
115//
116// * Redistributions of source code must retain the above copyright
117// notice, this list of conditions and the following disclaimer.
118// * Redistributions in binary form must reproduce the above
119// copyright notice, this list of conditions and the following disclaimer
120// in the documentation and/or other materials provided with the
121// distribution.
122// * Neither the name of Google Inc. nor the names of its
123// contributors may be used to endorse or promote products derived from
124// this software without specific prior written permission.
125//
126// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
127// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
128// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
129// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
130// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
131// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
132// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
133// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
134// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
135// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
136// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800137
Austin Schuh70cc9552019-01-21 19:46:48 -0800138
139// Google Mock - a framework for writing C++ mock classes.
140//
141// This file defines some utilities useful for implementing Google
142// Mock. They are subject to change without notice, so please DO NOT
143// USE THEM IN USER CODE.
144
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800145// GOOGLETEST_CM0002 DO NOT DELETE
146
Austin Schuh70cc9552019-01-21 19:46:48 -0800147#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
148#define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
149
150#include <stdio.h>
151#include <ostream> // NOLINT
152#include <string>
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800153#include <type_traits>
Austin Schuh70cc9552019-01-21 19:46:48 -0800154// Copyright 2008, Google Inc.
155// All rights reserved.
156//
157// Redistribution and use in source and binary forms, with or without
158// modification, are permitted provided that the following conditions are
159// met:
160//
161// * Redistributions of source code must retain the above copyright
162// notice, this list of conditions and the following disclaimer.
163// * Redistributions in binary form must reproduce the above
164// copyright notice, this list of conditions and the following disclaimer
165// in the documentation and/or other materials provided with the
166// distribution.
167// * Neither the name of Google Inc. nor the names of its
168// contributors may be used to endorse or promote products derived from
169// this software without specific prior written permission.
170//
171// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
173// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
174// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
175// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
176// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
177// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
178// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
179// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
180// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
181// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800182
Austin Schuh70cc9552019-01-21 19:46:48 -0800183//
184// Low-level types and utilities for porting Google Mock to various
185// platforms. All macros ending with _ and symbols defined in an
186// internal namespace are subject to change without notice. Code
187// outside Google Mock MUST NOT USE THEM DIRECTLY. Macros that don't
188// end with _ are part of Google Mock's public API and can be used by
189// code outside Google Mock.
190
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800191// GOOGLETEST_CM0002 DO NOT DELETE
192
Austin Schuh70cc9552019-01-21 19:46:48 -0800193#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_
194#define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_
195
196#include <assert.h>
197#include <stdlib.h>
198#include <iostream>
199
200// Most of the utilities needed for porting Google Mock are also
201// required for Google Test and are defined in gtest-port.h.
202//
203// Note to maintainers: to reduce code duplication, prefer adding
204// portability utilities to Google Test's gtest-port.h instead of
205// here, as Google Mock depends on Google Test. Only add a utility
206// here if it's truly specific to Google Mock.
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800207
Austin Schuh70cc9552019-01-21 19:46:48 -0800208#include "gtest/gtest.h"
209// Copyright 2015, Google Inc.
210// All rights reserved.
211//
212// Redistribution and use in source and binary forms, with or without
213// modification, are permitted provided that the following conditions are
214// met:
215//
216// * Redistributions of source code must retain the above copyright
217// notice, this list of conditions and the following disclaimer.
218// * Redistributions in binary form must reproduce the above
219// copyright notice, this list of conditions and the following disclaimer
220// in the documentation and/or other materials provided with the
221// distribution.
222// * Neither the name of Google Inc. nor the names of its
223// contributors may be used to endorse or promote products derived from
224// this software without specific prior written permission.
225//
226// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
227// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
228// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
229// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
230// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
231// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
232// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
233// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
234// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
235// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
236// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
237//
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800238// Injection point for custom user configurations. See README for details
Austin Schuh70cc9552019-01-21 19:46:48 -0800239//
240// ** Custom implementation starts here **
241
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800242// GOOGLETEST_CM0002 DO NOT DELETE
243
Austin Schuh70cc9552019-01-21 19:46:48 -0800244#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_
245#define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_
246
247#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_
248
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800249// For MS Visual C++, check the compiler version. At least VS 2015 is
Austin Schuh70cc9552019-01-21 19:46:48 -0800250// required to compile Google Mock.
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800251#if defined(_MSC_VER) && _MSC_VER < 1900
252# error "At least Visual C++ 2015 (14.0) is required to compile Google Mock."
Austin Schuh70cc9552019-01-21 19:46:48 -0800253#endif
254
255// Macro for referencing flags. This is public as we want the user to
256// use this syntax to reference Google Mock flags.
257#define GMOCK_FLAG(name) FLAGS_gmock_##name
258
259#if !defined(GMOCK_DECLARE_bool_)
260
261// Macros for declaring flags.
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800262# define GMOCK_DECLARE_bool_(name) extern GTEST_API_ bool GMOCK_FLAG(name)
263# define GMOCK_DECLARE_int32_(name) \
Austin Schuh70cc9552019-01-21 19:46:48 -0800264 extern GTEST_API_ ::testing::internal::Int32 GMOCK_FLAG(name)
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800265# define GMOCK_DECLARE_string_(name) \
Austin Schuh70cc9552019-01-21 19:46:48 -0800266 extern GTEST_API_ ::std::string GMOCK_FLAG(name)
267
268// Macros for defining flags.
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800269# define GMOCK_DEFINE_bool_(name, default_val, doc) \
Austin Schuh70cc9552019-01-21 19:46:48 -0800270 GTEST_API_ bool GMOCK_FLAG(name) = (default_val)
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800271# define GMOCK_DEFINE_int32_(name, default_val, doc) \
Austin Schuh70cc9552019-01-21 19:46:48 -0800272 GTEST_API_ ::testing::internal::Int32 GMOCK_FLAG(name) = (default_val)
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800273# define GMOCK_DEFINE_string_(name, default_val, doc) \
Austin Schuh70cc9552019-01-21 19:46:48 -0800274 GTEST_API_ ::std::string GMOCK_FLAG(name) = (default_val)
275
276#endif // !defined(GMOCK_DECLARE_bool_)
277
278#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_
279
280namespace testing {
281
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800282template <typename>
Austin Schuh70cc9552019-01-21 19:46:48 -0800283class Matcher;
284
285namespace internal {
286
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800287// Silence MSVC C4100 (unreferenced formal parameter) and
288// C4805('==': unsafe mix of type 'const int' and type 'const bool')
289#ifdef _MSC_VER
290# pragma warning(push)
291# pragma warning(disable:4100)
292# pragma warning(disable:4805)
293#endif
Austin Schuh70cc9552019-01-21 19:46:48 -0800294
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800295// Joins a vector of strings as if they are fields of a tuple; returns
296// the joined string.
297GTEST_API_ std::string JoinAsTuple(const Strings& fields);
Austin Schuh70cc9552019-01-21 19:46:48 -0800298
299// Converts an identifier name to a space-separated list of lower-case
300// words. Each maximum substring of the form [A-Za-z][a-z]*|\d+ is
301// treated as one word. For example, both "FooBar123" and
302// "foo_bar_123" are converted to "foo bar 123".
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800303GTEST_API_ std::string ConvertIdentifierNameToWords(const char* id_name);
Austin Schuh70cc9552019-01-21 19:46:48 -0800304
305// PointeeOf<Pointer>::type is the type of a value pointed to by a
306// Pointer, which can be either a smart pointer or a raw pointer. The
307// following default implementation is for the case where Pointer is a
308// smart pointer.
309template <typename Pointer>
310struct PointeeOf {
311 // Smart pointer classes define type element_type as the type of
312 // their pointees.
313 typedef typename Pointer::element_type type;
314};
315// This specialization is for the raw pointer case.
316template <typename T>
317struct PointeeOf<T*> { typedef T type; }; // NOLINT
318
319// GetRawPointer(p) returns the raw pointer underlying p when p is a
320// smart pointer, or returns p itself when p is already a raw pointer.
321// The following default implementation is for the smart pointer case.
322template <typename Pointer>
323inline const typename Pointer::element_type* GetRawPointer(const Pointer& p) {
324 return p.get();
325}
326// This overloaded version is for the raw pointer case.
327template <typename Element>
328inline Element* GetRawPointer(Element* p) { return p; }
329
Austin Schuh70cc9552019-01-21 19:46:48 -0800330// MSVC treats wchar_t as a native type usually, but treats it as the
331// same as unsigned short when the compiler option /Zc:wchar_t- is
332// specified. It defines _NATIVE_WCHAR_T_DEFINED symbol when wchar_t
333// is a native type.
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800334#if defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED)
Austin Schuh70cc9552019-01-21 19:46:48 -0800335// wchar_t is a typedef.
336#else
337# define GMOCK_WCHAR_T_IS_NATIVE_ 1
338#endif
339
340// signed wchar_t and unsigned wchar_t are NOT in the C++ standard.
341// Using them is a bad practice and not portable. So DON'T use them.
342//
343// Still, Google Mock is designed to work even if the user uses signed
344// wchar_t or unsigned wchar_t (obviously, assuming the compiler
345// supports them).
346//
347// To gcc,
348// wchar_t == signed wchar_t != unsigned wchar_t == unsigned int
349#ifdef __GNUC__
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800350#if !defined(__WCHAR_UNSIGNED__)
Austin Schuh70cc9552019-01-21 19:46:48 -0800351// signed/unsigned wchar_t are valid types.
352# define GMOCK_HAS_SIGNED_WCHAR_T_ 1
353#endif
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800354#endif
Austin Schuh70cc9552019-01-21 19:46:48 -0800355
356// In what follows, we use the term "kind" to indicate whether a type
357// is bool, an integer type (excluding bool), a floating-point type,
358// or none of them. This categorization is useful for determining
359// when a matcher argument type can be safely converted to another
360// type in the implementation of SafeMatcherCast.
361enum TypeKind {
362 kBool, kInteger, kFloatingPoint, kOther
363};
364
365// KindOf<T>::value is the kind of type T.
366template <typename T> struct KindOf {
367 enum { value = kOther }; // The default kind.
368};
369
370// This macro declares that the kind of 'type' is 'kind'.
371#define GMOCK_DECLARE_KIND_(type, kind) \
372 template <> struct KindOf<type> { enum { value = kind }; }
373
374GMOCK_DECLARE_KIND_(bool, kBool);
375
376// All standard integer types.
377GMOCK_DECLARE_KIND_(char, kInteger);
378GMOCK_DECLARE_KIND_(signed char, kInteger);
379GMOCK_DECLARE_KIND_(unsigned char, kInteger);
380GMOCK_DECLARE_KIND_(short, kInteger); // NOLINT
381GMOCK_DECLARE_KIND_(unsigned short, kInteger); // NOLINT
382GMOCK_DECLARE_KIND_(int, kInteger);
383GMOCK_DECLARE_KIND_(unsigned int, kInteger);
384GMOCK_DECLARE_KIND_(long, kInteger); // NOLINT
385GMOCK_DECLARE_KIND_(unsigned long, kInteger); // NOLINT
386
387#if GMOCK_WCHAR_T_IS_NATIVE_
388GMOCK_DECLARE_KIND_(wchar_t, kInteger);
389#endif
390
391// Non-standard integer types.
392GMOCK_DECLARE_KIND_(Int64, kInteger);
393GMOCK_DECLARE_KIND_(UInt64, kInteger);
394
395// All standard floating-point types.
396GMOCK_DECLARE_KIND_(float, kFloatingPoint);
397GMOCK_DECLARE_KIND_(double, kFloatingPoint);
398GMOCK_DECLARE_KIND_(long double, kFloatingPoint);
399
400#undef GMOCK_DECLARE_KIND_
401
402// Evaluates to the kind of 'type'.
403#define GMOCK_KIND_OF_(type) \
404 static_cast< ::testing::internal::TypeKind>( \
405 ::testing::internal::KindOf<type>::value)
406
407// Evaluates to true iff integer type T is signed.
408#define GMOCK_IS_SIGNED_(T) (static_cast<T>(-1) < 0)
409
410// LosslessArithmeticConvertibleImpl<kFromKind, From, kToKind, To>::value
411// is true iff arithmetic type From can be losslessly converted to
412// arithmetic type To.
413//
414// It's the user's responsibility to ensure that both From and To are
415// raw (i.e. has no CV modifier, is not a pointer, and is not a
416// reference) built-in arithmetic types, kFromKind is the kind of
417// From, and kToKind is the kind of To; the value is
418// implementation-defined when the above pre-condition is violated.
419template <TypeKind kFromKind, typename From, TypeKind kToKind, typename To>
420struct LosslessArithmeticConvertibleImpl : public false_type {};
421
422// Converting bool to bool is lossless.
423template <>
424struct LosslessArithmeticConvertibleImpl<kBool, bool, kBool, bool>
425 : public true_type {}; // NOLINT
426
427// Converting bool to any integer type is lossless.
428template <typename To>
429struct LosslessArithmeticConvertibleImpl<kBool, bool, kInteger, To>
430 : public true_type {}; // NOLINT
431
432// Converting bool to any floating-point type is lossless.
433template <typename To>
434struct LosslessArithmeticConvertibleImpl<kBool, bool, kFloatingPoint, To>
435 : public true_type {}; // NOLINT
436
437// Converting an integer to bool is lossy.
438template <typename From>
439struct LosslessArithmeticConvertibleImpl<kInteger, From, kBool, bool>
440 : public false_type {}; // NOLINT
441
442// Converting an integer to another non-bool integer is lossless iff
443// the target type's range encloses the source type's range.
444template <typename From, typename To>
445struct LosslessArithmeticConvertibleImpl<kInteger, From, kInteger, To>
446 : public bool_constant<
447 // When converting from a smaller size to a larger size, we are
448 // fine as long as we are not converting from signed to unsigned.
449 ((sizeof(From) < sizeof(To)) &&
450 (!GMOCK_IS_SIGNED_(From) || GMOCK_IS_SIGNED_(To))) ||
451 // When converting between the same size, the signedness must match.
452 ((sizeof(From) == sizeof(To)) &&
453 (GMOCK_IS_SIGNED_(From) == GMOCK_IS_SIGNED_(To)))> {}; // NOLINT
454
455#undef GMOCK_IS_SIGNED_
456
457// Converting an integer to a floating-point type may be lossy, since
458// the format of a floating-point number is implementation-defined.
459template <typename From, typename To>
460struct LosslessArithmeticConvertibleImpl<kInteger, From, kFloatingPoint, To>
461 : public false_type {}; // NOLINT
462
463// Converting a floating-point to bool is lossy.
464template <typename From>
465struct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kBool, bool>
466 : public false_type {}; // NOLINT
467
468// Converting a floating-point to an integer is lossy.
469template <typename From, typename To>
470struct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kInteger, To>
471 : public false_type {}; // NOLINT
472
473// Converting a floating-point to another floating-point is lossless
474// iff the target type is at least as big as the source type.
475template <typename From, typename To>
476struct LosslessArithmeticConvertibleImpl<
477 kFloatingPoint, From, kFloatingPoint, To>
478 : public bool_constant<sizeof(From) <= sizeof(To)> {}; // NOLINT
479
480// LosslessArithmeticConvertible<From, To>::value is true iff arithmetic
481// type From can be losslessly converted to arithmetic type To.
482//
483// It's the user's responsibility to ensure that both From and To are
484// raw (i.e. has no CV modifier, is not a pointer, and is not a
485// reference) built-in arithmetic types; the value is
486// implementation-defined when the above pre-condition is violated.
487template <typename From, typename To>
488struct LosslessArithmeticConvertible
489 : public LosslessArithmeticConvertibleImpl<
490 GMOCK_KIND_OF_(From), From, GMOCK_KIND_OF_(To), To> {}; // NOLINT
491
492// This interface knows how to report a Google Mock failure (either
493// non-fatal or fatal).
494class FailureReporterInterface {
495 public:
496 // The type of a failure (either non-fatal or fatal).
497 enum FailureType {
498 kNonfatal, kFatal
499 };
500
501 virtual ~FailureReporterInterface() {}
502
503 // Reports a failure that occurred at the given source file location.
504 virtual void ReportFailure(FailureType type, const char* file, int line,
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800505 const std::string& message) = 0;
Austin Schuh70cc9552019-01-21 19:46:48 -0800506};
507
508// Returns the failure reporter used by Google Mock.
509GTEST_API_ FailureReporterInterface* GetFailureReporter();
510
511// Asserts that condition is true; aborts the process with the given
512// message if condition is false. We cannot use LOG(FATAL) or CHECK()
513// as Google Mock might be used to mock the log sink itself. We
514// inline this function to prevent it from showing up in the stack
515// trace.
516inline void Assert(bool condition, const char* file, int line,
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800517 const std::string& msg) {
Austin Schuh70cc9552019-01-21 19:46:48 -0800518 if (!condition) {
519 GetFailureReporter()->ReportFailure(FailureReporterInterface::kFatal,
520 file, line, msg);
521 }
522}
523inline void Assert(bool condition, const char* file, int line) {
524 Assert(condition, file, line, "Assertion failed.");
525}
526
527// Verifies that condition is true; generates a non-fatal failure if
528// condition is false.
529inline void Expect(bool condition, const char* file, int line,
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800530 const std::string& msg) {
Austin Schuh70cc9552019-01-21 19:46:48 -0800531 if (!condition) {
532 GetFailureReporter()->ReportFailure(FailureReporterInterface::kNonfatal,
533 file, line, msg);
534 }
535}
536inline void Expect(bool condition, const char* file, int line) {
537 Expect(condition, file, line, "Expectation failed.");
538}
539
540// Severity level of a log.
541enum LogSeverity {
542 kInfo = 0,
543 kWarning = 1
544};
545
546// Valid values for the --gmock_verbose flag.
547
548// All logs (informational and warnings) are printed.
549const char kInfoVerbosity[] = "info";
550// Only warnings are printed.
551const char kWarningVerbosity[] = "warning";
552// No logs are printed.
553const char kErrorVerbosity[] = "error";
554
555// Returns true iff a log with the given severity is visible according
556// to the --gmock_verbose flag.
557GTEST_API_ bool LogIsVisible(LogSeverity severity);
558
559// Prints the given message to stdout iff 'severity' >= the level
560// specified by the --gmock_verbose flag. If stack_frames_to_skip >=
561// 0, also prints the stack trace excluding the top
562// stack_frames_to_skip frames. In opt mode, any positive
563// stack_frames_to_skip is treated as 0, since we don't know which
564// function calls will be inlined by the compiler and need to be
565// conservative.
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800566GTEST_API_ void Log(LogSeverity severity, const std::string& message,
Austin Schuh70cc9552019-01-21 19:46:48 -0800567 int stack_frames_to_skip);
568
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800569// A marker class that is used to resolve parameterless expectations to the
570// correct overload. This must not be instantiable, to prevent client code from
571// accidentally resolving to the overload; for example:
572//
573// ON_CALL(mock, Method({}, nullptr))...
574//
575class WithoutMatchers {
576 private:
577 WithoutMatchers() {}
578 friend GTEST_API_ WithoutMatchers GetWithoutMatchers();
579};
580
581// Internal use only: access the singleton instance of WithoutMatchers.
582GTEST_API_ WithoutMatchers GetWithoutMatchers();
Austin Schuh70cc9552019-01-21 19:46:48 -0800583
584// Type traits.
585
586// is_reference<T>::value is non-zero iff T is a reference type.
587template <typename T> struct is_reference : public false_type {};
588template <typename T> struct is_reference<T&> : public true_type {};
589
590// type_equals<T1, T2>::value is non-zero iff T1 and T2 are the same type.
591template <typename T1, typename T2> struct type_equals : public false_type {};
592template <typename T> struct type_equals<T, T> : public true_type {};
593
594// remove_reference<T>::type removes the reference from type T, if any.
595template <typename T> struct remove_reference { typedef T type; }; // NOLINT
596template <typename T> struct remove_reference<T&> { typedef T type; }; // NOLINT
597
598// DecayArray<T>::type turns an array type U[N] to const U* and preserves
599// other types. Useful for saving a copy of a function argument.
600template <typename T> struct DecayArray { typedef T type; }; // NOLINT
601template <typename T, size_t N> struct DecayArray<T[N]> {
602 typedef const T* type;
603};
604// Sometimes people use arrays whose size is not available at the use site
605// (e.g. extern const char kNamePrefix[]). This specialization covers that
606// case.
607template <typename T> struct DecayArray<T[]> {
608 typedef const T* type;
609};
610
611// Disable MSVC warnings for infinite recursion, since in this case the
612// the recursion is unreachable.
613#ifdef _MSC_VER
614# pragma warning(push)
615# pragma warning(disable:4717)
616#endif
617
618// Invalid<T>() is usable as an expression of type T, but will terminate
619// the program with an assertion failure if actually run. This is useful
620// when a value of type T is needed for compilation, but the statement
621// will not really be executed (or we don't care if the statement
622// crashes).
623template <typename T>
624inline T Invalid() {
625 Assert(false, "", -1, "Internal error: attempt to return invalid value");
626 // This statement is unreachable, and would never terminate even if it
627 // could be reached. It is provided only to placate compiler warnings
628 // about missing return statements.
629 return Invalid<T>();
630}
631
632#ifdef _MSC_VER
633# pragma warning(pop)
634#endif
635
636// Given a raw type (i.e. having no top-level reference or const
637// modifier) RawContainer that's either an STL-style container or a
638// native array, class StlContainerView<RawContainer> has the
639// following members:
640//
641// - type is a type that provides an STL-style container view to
642// (i.e. implements the STL container concept for) RawContainer;
643// - const_reference is a type that provides a reference to a const
644// RawContainer;
645// - ConstReference(raw_container) returns a const reference to an STL-style
646// container view to raw_container, which is a RawContainer.
647// - Copy(raw_container) returns an STL-style container view of a
648// copy of raw_container, which is a RawContainer.
649//
650// This generic version is used when RawContainer itself is already an
651// STL-style container.
652template <class RawContainer>
653class StlContainerView {
654 public:
655 typedef RawContainer type;
656 typedef const type& const_reference;
657
658 static const_reference ConstReference(const RawContainer& container) {
659 // Ensures that RawContainer is not a const type.
660 testing::StaticAssertTypeEq<RawContainer,
661 GTEST_REMOVE_CONST_(RawContainer)>();
662 return container;
663 }
664 static type Copy(const RawContainer& container) { return container; }
665};
666
667// This specialization is used when RawContainer is a native array type.
668template <typename Element, size_t N>
669class StlContainerView<Element[N]> {
670 public:
671 typedef GTEST_REMOVE_CONST_(Element) RawElement;
672 typedef internal::NativeArray<RawElement> type;
673 // NativeArray<T> can represent a native array either by value or by
674 // reference (selected by a constructor argument), so 'const type'
675 // can be used to reference a const native array. We cannot
676 // 'typedef const type& const_reference' here, as that would mean
677 // ConstReference() has to return a reference to a local variable.
678 typedef const type const_reference;
679
680 static const_reference ConstReference(const Element (&array)[N]) {
681 // Ensures that Element is not a const type.
682 testing::StaticAssertTypeEq<Element, RawElement>();
Austin Schuh70cc9552019-01-21 19:46:48 -0800683 return type(array, N, RelationToSourceReference());
Austin Schuh70cc9552019-01-21 19:46:48 -0800684 }
685 static type Copy(const Element (&array)[N]) {
Austin Schuh70cc9552019-01-21 19:46:48 -0800686 return type(array, N, RelationToSourceCopy());
Austin Schuh70cc9552019-01-21 19:46:48 -0800687 }
688};
689
690// This specialization is used when RawContainer is a native array
691// represented as a (pointer, size) tuple.
692template <typename ElementPointer, typename Size>
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800693class StlContainerView< ::std::tuple<ElementPointer, Size> > {
Austin Schuh70cc9552019-01-21 19:46:48 -0800694 public:
695 typedef GTEST_REMOVE_CONST_(
696 typename internal::PointeeOf<ElementPointer>::type) RawElement;
697 typedef internal::NativeArray<RawElement> type;
698 typedef const type const_reference;
699
700 static const_reference ConstReference(
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800701 const ::std::tuple<ElementPointer, Size>& array) {
702 return type(std::get<0>(array), std::get<1>(array),
703 RelationToSourceReference());
Austin Schuh70cc9552019-01-21 19:46:48 -0800704 }
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800705 static type Copy(const ::std::tuple<ElementPointer, Size>& array) {
706 return type(std::get<0>(array), std::get<1>(array), RelationToSourceCopy());
Austin Schuh70cc9552019-01-21 19:46:48 -0800707 }
708};
709
710// The following specialization prevents the user from instantiating
711// StlContainer with a reference type.
712template <typename T> class StlContainerView<T&>;
713
714// A type transform to remove constness from the first part of a pair.
715// Pairs like that are used as the value_type of associative containers,
716// and this transform produces a similar but assignable pair.
717template <typename T>
718struct RemoveConstFromKey {
719 typedef T type;
720};
721
722// Partially specialized to remove constness from std::pair<const K, V>.
723template <typename K, typename V>
724struct RemoveConstFromKey<std::pair<const K, V> > {
725 typedef std::pair<K, V> type;
726};
727
728// Mapping from booleans to types. Similar to boost::bool_<kValue> and
729// std::integral_constant<bool, kValue>.
730template <bool kValue>
731struct BooleanConstant {};
732
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800733// Emit an assertion failure due to incorrect DoDefault() usage. Out-of-lined to
734// reduce code size.
735GTEST_API_ void IllegalDoDefault(const char* file, int line);
736
737// Helper types for Apply() below.
738template <size_t... Is> struct int_pack { typedef int_pack type; };
739
740template <class Pack, size_t I> struct append;
741template <size_t... Is, size_t I>
742struct append<int_pack<Is...>, I> : int_pack<Is..., I> {};
743
744template <size_t C>
745struct make_int_pack : append<typename make_int_pack<C - 1>::type, C - 1> {};
746template <> struct make_int_pack<0> : int_pack<> {};
747
748template <typename F, typename Tuple, size_t... Idx>
749auto ApplyImpl(F&& f, Tuple&& args, int_pack<Idx...>) -> decltype(
750 std::forward<F>(f)(std::get<Idx>(std::forward<Tuple>(args))...)) {
751 return std::forward<F>(f)(std::get<Idx>(std::forward<Tuple>(args))...);
752}
753
754// Apply the function to a tuple of arguments.
755template <typename F, typename Tuple>
756auto Apply(F&& f, Tuple&& args)
757 -> decltype(ApplyImpl(std::forward<F>(f), std::forward<Tuple>(args),
758 make_int_pack<std::tuple_size<Tuple>::value>())) {
759 return ApplyImpl(std::forward<F>(f), std::forward<Tuple>(args),
760 make_int_pack<std::tuple_size<Tuple>::value>());
761}
762
763// Template struct Function<F>, where F must be a function type, contains
764// the following typedefs:
765//
766// Result: the function's return type.
767// Arg<N>: the type of the N-th argument, where N starts with 0.
768// ArgumentTuple: the tuple type consisting of all parameters of F.
769// ArgumentMatcherTuple: the tuple type consisting of Matchers for all
770// parameters of F.
771// MakeResultVoid: the function type obtained by substituting void
772// for the return type of F.
773// MakeResultIgnoredValue:
774// the function type obtained by substituting Something
775// for the return type of F.
776template <typename T>
777struct Function;
778
779template <typename R, typename... Args>
780struct Function<R(Args...)> {
781 using Result = R;
782 static constexpr size_t ArgumentCount = sizeof...(Args);
783 template <size_t I>
784 using Arg = ElemFromList<I, typename MakeIndexSequence<sizeof...(Args)>::type,
785 Args...>;
786 using ArgumentTuple = std::tuple<Args...>;
787 using ArgumentMatcherTuple = std::tuple<Matcher<Args>...>;
788 using MakeResultVoid = void(Args...);
789 using MakeResultIgnoredValue = IgnoredValue(Args...);
790};
791
792template <typename R, typename... Args>
793constexpr size_t Function<R(Args...)>::ArgumentCount;
794
795#ifdef _MSC_VER
796# pragma warning(pop)
797#endif
798
Austin Schuh70cc9552019-01-21 19:46:48 -0800799} // namespace internal
800} // namespace testing
801
802#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
803
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800804#ifdef _MSC_VER
805# pragma warning(push)
806# pragma warning(disable:4100)
Austin Schuh70cc9552019-01-21 19:46:48 -0800807#endif
808
809namespace testing {
810
811// To implement an action Foo, define:
812// 1. a class FooAction that implements the ActionInterface interface, and
813// 2. a factory function that creates an Action object from a
814// const FooAction*.
815//
816// The two-level delegation design follows that of Matcher, providing
817// consistency for extension developers. It also eases ownership
818// management as Action objects can now be copied like plain values.
819
820namespace internal {
821
Austin Schuh70cc9552019-01-21 19:46:48 -0800822// BuiltInDefaultValueGetter<T, true>::Get() returns a
823// default-constructed T value. BuiltInDefaultValueGetter<T,
824// false>::Get() crashes with an error.
825//
826// This primary template is used when kDefaultConstructible is true.
827template <typename T, bool kDefaultConstructible>
828struct BuiltInDefaultValueGetter {
829 static T Get() { return T(); }
830};
831template <typename T>
832struct BuiltInDefaultValueGetter<T, false> {
833 static T Get() {
834 Assert(false, __FILE__, __LINE__,
835 "Default action undefined for the function return type.");
836 return internal::Invalid<T>();
837 // The above statement will never be reached, but is required in
838 // order for this function to compile.
839 }
840};
841
842// BuiltInDefaultValue<T>::Get() returns the "built-in" default value
843// for type T, which is NULL when T is a raw pointer type, 0 when T is
844// a numeric type, false when T is bool, or "" when T is string or
845// std::string. In addition, in C++11 and above, it turns a
846// default-constructed T value if T is default constructible. For any
847// other type T, the built-in default T value is undefined, and the
848// function will abort the process.
849template <typename T>
850class BuiltInDefaultValue {
851 public:
Austin Schuh70cc9552019-01-21 19:46:48 -0800852 // This function returns true iff type T has a built-in default value.
853 static bool Exists() {
854 return ::std::is_default_constructible<T>::value;
855 }
856
857 static T Get() {
858 return BuiltInDefaultValueGetter<
859 T, ::std::is_default_constructible<T>::value>::Get();
860 }
Austin Schuh70cc9552019-01-21 19:46:48 -0800861};
862
863// This partial specialization says that we use the same built-in
864// default value for T and const T.
865template <typename T>
866class BuiltInDefaultValue<const T> {
867 public:
868 static bool Exists() { return BuiltInDefaultValue<T>::Exists(); }
869 static T Get() { return BuiltInDefaultValue<T>::Get(); }
870};
871
872// This partial specialization defines the default values for pointer
873// types.
874template <typename T>
875class BuiltInDefaultValue<T*> {
876 public:
877 static bool Exists() { return true; }
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800878 static T* Get() { return nullptr; }
Austin Schuh70cc9552019-01-21 19:46:48 -0800879};
880
881// The following specializations define the default values for
882// specific types we care about.
883#define GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(type, value) \
884 template <> \
885 class BuiltInDefaultValue<type> { \
886 public: \
887 static bool Exists() { return true; } \
888 static type Get() { return value; } \
889 }
890
891GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(void, ); // NOLINT
892#if GTEST_HAS_GLOBAL_STRING
893GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(::string, "");
894#endif // GTEST_HAS_GLOBAL_STRING
895GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(::std::string, "");
896GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(bool, false);
897GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned char, '\0');
898GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed char, '\0');
899GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(char, '\0');
900
901// There's no need for a default action for signed wchar_t, as that
902// type is the same as wchar_t for gcc, and invalid for MSVC.
903//
904// There's also no need for a default action for unsigned wchar_t, as
905// that type is the same as unsigned int for gcc, and invalid for
906// MSVC.
907#if GMOCK_WCHAR_T_IS_NATIVE_
908GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(wchar_t, 0U); // NOLINT
909#endif
910
911GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned short, 0U); // NOLINT
912GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed short, 0); // NOLINT
913GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned int, 0U);
914GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed int, 0);
915GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned long, 0UL); // NOLINT
916GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed long, 0L); // NOLINT
917GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(UInt64, 0);
918GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(Int64, 0);
919GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(float, 0);
920GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(double, 0);
921
922#undef GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_
923
924} // namespace internal
925
926// When an unexpected function call is encountered, Google Mock will
927// let it return a default value if the user has specified one for its
928// return type, or if the return type has a built-in default value;
929// otherwise Google Mock won't know what value to return and will have
930// to abort the process.
931//
932// The DefaultValue<T> class allows a user to specify the
933// default value for a type T that is both copyable and publicly
934// destructible (i.e. anything that can be used as a function return
935// type). The usage is:
936//
937// // Sets the default value for type T to be foo.
938// DefaultValue<T>::Set(foo);
939template <typename T>
940class DefaultValue {
941 public:
942 // Sets the default value for type T; requires T to be
943 // copy-constructable and have a public destructor.
944 static void Set(T x) {
945 delete producer_;
946 producer_ = new FixedValueProducer(x);
947 }
948
949 // Provides a factory function to be called to generate the default value.
950 // This method can be used even if T is only move-constructible, but it is not
951 // limited to that case.
952 typedef T (*FactoryFunction)();
953 static void SetFactory(FactoryFunction factory) {
954 delete producer_;
955 producer_ = new FactoryValueProducer(factory);
956 }
957
958 // Unsets the default value for type T.
959 static void Clear() {
960 delete producer_;
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800961 producer_ = nullptr;
Austin Schuh70cc9552019-01-21 19:46:48 -0800962 }
963
964 // Returns true iff the user has set the default value for type T.
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800965 static bool IsSet() { return producer_ != nullptr; }
Austin Schuh70cc9552019-01-21 19:46:48 -0800966
967 // Returns true if T has a default return value set by the user or there
968 // exists a built-in default value.
969 static bool Exists() {
970 return IsSet() || internal::BuiltInDefaultValue<T>::Exists();
971 }
972
973 // Returns the default value for type T if the user has set one;
974 // otherwise returns the built-in default value. Requires that Exists()
975 // is true, which ensures that the return value is well-defined.
976 static T Get() {
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800977 return producer_ == nullptr ? internal::BuiltInDefaultValue<T>::Get()
978 : producer_->Produce();
Austin Schuh70cc9552019-01-21 19:46:48 -0800979 }
980
981 private:
982 class ValueProducer {
983 public:
984 virtual ~ValueProducer() {}
985 virtual T Produce() = 0;
986 };
987
988 class FixedValueProducer : public ValueProducer {
989 public:
990 explicit FixedValueProducer(T value) : value_(value) {}
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800991 T Produce() override { return value_; }
Austin Schuh70cc9552019-01-21 19:46:48 -0800992
993 private:
994 const T value_;
995 GTEST_DISALLOW_COPY_AND_ASSIGN_(FixedValueProducer);
996 };
997
998 class FactoryValueProducer : public ValueProducer {
999 public:
1000 explicit FactoryValueProducer(FactoryFunction factory)
1001 : factory_(factory) {}
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001002 T Produce() override { return factory_(); }
Austin Schuh70cc9552019-01-21 19:46:48 -08001003
1004 private:
1005 const FactoryFunction factory_;
1006 GTEST_DISALLOW_COPY_AND_ASSIGN_(FactoryValueProducer);
1007 };
1008
1009 static ValueProducer* producer_;
1010};
1011
1012// This partial specialization allows a user to set default values for
1013// reference types.
1014template <typename T>
1015class DefaultValue<T&> {
1016 public:
1017 // Sets the default value for type T&.
1018 static void Set(T& x) { // NOLINT
1019 address_ = &x;
1020 }
1021
1022 // Unsets the default value for type T&.
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001023 static void Clear() { address_ = nullptr; }
Austin Schuh70cc9552019-01-21 19:46:48 -08001024
1025 // Returns true iff the user has set the default value for type T&.
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001026 static bool IsSet() { return address_ != nullptr; }
Austin Schuh70cc9552019-01-21 19:46:48 -08001027
1028 // Returns true if T has a default return value set by the user or there
1029 // exists a built-in default value.
1030 static bool Exists() {
1031 return IsSet() || internal::BuiltInDefaultValue<T&>::Exists();
1032 }
1033
1034 // Returns the default value for type T& if the user has set one;
1035 // otherwise returns the built-in default value if there is one;
1036 // otherwise aborts the process.
1037 static T& Get() {
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001038 return address_ == nullptr ? internal::BuiltInDefaultValue<T&>::Get()
1039 : *address_;
Austin Schuh70cc9552019-01-21 19:46:48 -08001040 }
1041
1042 private:
1043 static T* address_;
1044};
1045
1046// This specialization allows DefaultValue<void>::Get() to
1047// compile.
1048template <>
1049class DefaultValue<void> {
1050 public:
1051 static bool Exists() { return true; }
1052 static void Get() {}
1053};
1054
1055// Points to the user-set default value for type T.
1056template <typename T>
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001057typename DefaultValue<T>::ValueProducer* DefaultValue<T>::producer_ = nullptr;
Austin Schuh70cc9552019-01-21 19:46:48 -08001058
1059// Points to the user-set default value for type T&.
1060template <typename T>
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001061T* DefaultValue<T&>::address_ = nullptr;
Austin Schuh70cc9552019-01-21 19:46:48 -08001062
1063// Implement this interface to define an action for function type F.
1064template <typename F>
1065class ActionInterface {
1066 public:
1067 typedef typename internal::Function<F>::Result Result;
1068 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
1069
1070 ActionInterface() {}
1071 virtual ~ActionInterface() {}
1072
1073 // Performs the action. This method is not const, as in general an
1074 // action can have side effects and be stateful. For example, a
1075 // get-the-next-element-from-the-collection action will need to
1076 // remember the current element.
1077 virtual Result Perform(const ArgumentTuple& args) = 0;
1078
1079 private:
1080 GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionInterface);
1081};
1082
1083// An Action<F> is a copyable and IMMUTABLE (except by assignment)
1084// object that represents an action to be taken when a mock function
1085// of type F is called. The implementation of Action<T> is just a
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001086// std::shared_ptr to const ActionInterface<T>. Don't inherit from Action!
Austin Schuh70cc9552019-01-21 19:46:48 -08001087// You can view an object implementing ActionInterface<F> as a
1088// concrete action (including its current state), and an Action<F>
1089// object as a handle to it.
1090template <typename F>
1091class Action {
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001092 // Adapter class to allow constructing Action from a legacy ActionInterface.
1093 // New code should create Actions from functors instead.
1094 struct ActionAdapter {
1095 // Adapter must be copyable to satisfy std::function requirements.
1096 ::std::shared_ptr<ActionInterface<F>> impl_;
1097
1098 template <typename... Args>
1099 typename internal::Function<F>::Result operator()(Args&&... args) {
1100 return impl_->Perform(
1101 ::std::forward_as_tuple(::std::forward<Args>(args)...));
1102 }
1103 };
1104
Austin Schuh70cc9552019-01-21 19:46:48 -08001105 public:
1106 typedef typename internal::Function<F>::Result Result;
1107 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
1108
1109 // Constructs a null Action. Needed for storing Action objects in
1110 // STL containers.
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001111 Action() {}
Austin Schuh70cc9552019-01-21 19:46:48 -08001112
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001113 // Construct an Action from a specified callable.
1114 // This cannot take std::function directly, because then Action would not be
1115 // directly constructible from lambda (it would require two conversions).
1116 template <typename G,
1117 typename = typename ::std::enable_if<
1118 ::std::is_constructible<::std::function<F>, G>::value>::type>
1119 Action(G&& fun) : fun_(::std::forward<G>(fun)) {} // NOLINT
Austin Schuh70cc9552019-01-21 19:46:48 -08001120
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001121 // Constructs an Action from its implementation.
1122 explicit Action(ActionInterface<F>* impl)
1123 : fun_(ActionAdapter{::std::shared_ptr<ActionInterface<F>>(impl)}) {}
Austin Schuh70cc9552019-01-21 19:46:48 -08001124
1125 // This constructor allows us to turn an Action<Func> object into an
1126 // Action<F>, as long as F's arguments can be implicitly converted
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001127 // to Func's and Func's return type can be implicitly converted to F's.
Austin Schuh70cc9552019-01-21 19:46:48 -08001128 template <typename Func>
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001129 explicit Action(const Action<Func>& action) : fun_(action.fun_) {}
Austin Schuh70cc9552019-01-21 19:46:48 -08001130
1131 // Returns true iff this is the DoDefault() action.
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001132 bool IsDoDefault() const { return fun_ == nullptr; }
Austin Schuh70cc9552019-01-21 19:46:48 -08001133
1134 // Performs the action. Note that this method is const even though
1135 // the corresponding method in ActionInterface is not. The reason
1136 // is that a const Action<F> means that it cannot be re-bound to
1137 // another concrete action, not that the concrete action it binds to
1138 // cannot change state. (Think of the difference between a const
1139 // pointer and a pointer to const.)
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001140 Result Perform(ArgumentTuple args) const {
1141 if (IsDoDefault()) {
1142 internal::IllegalDoDefault(__FILE__, __LINE__);
1143 }
1144 return internal::Apply(fun_, ::std::move(args));
Austin Schuh70cc9552019-01-21 19:46:48 -08001145 }
1146
1147 private:
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001148 template <typename G>
1149 friend class Action;
Austin Schuh70cc9552019-01-21 19:46:48 -08001150
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001151 // fun_ is an empty function iff this is the DoDefault() action.
1152 ::std::function<F> fun_;
Austin Schuh70cc9552019-01-21 19:46:48 -08001153};
1154
1155// The PolymorphicAction class template makes it easy to implement a
1156// polymorphic action (i.e. an action that can be used in mock
1157// functions of than one type, e.g. Return()).
1158//
1159// To define a polymorphic action, a user first provides a COPYABLE
1160// implementation class that has a Perform() method template:
1161//
1162// class FooAction {
1163// public:
1164// template <typename Result, typename ArgumentTuple>
1165// Result Perform(const ArgumentTuple& args) const {
1166// // Processes the arguments and returns a result, using
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001167// // std::get<N>(args) to get the N-th (0-based) argument in the tuple.
Austin Schuh70cc9552019-01-21 19:46:48 -08001168// }
1169// ...
1170// };
1171//
1172// Then the user creates the polymorphic action using
1173// MakePolymorphicAction(object) where object has type FooAction. See
1174// the definition of Return(void) and SetArgumentPointee<N>(value) for
1175// complete examples.
1176template <typename Impl>
1177class PolymorphicAction {
1178 public:
1179 explicit PolymorphicAction(const Impl& impl) : impl_(impl) {}
1180
1181 template <typename F>
1182 operator Action<F>() const {
1183 return Action<F>(new MonomorphicImpl<F>(impl_));
1184 }
1185
1186 private:
1187 template <typename F>
1188 class MonomorphicImpl : public ActionInterface<F> {
1189 public:
1190 typedef typename internal::Function<F>::Result Result;
1191 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
1192
1193 explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {}
1194
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001195 Result Perform(const ArgumentTuple& args) override {
Austin Schuh70cc9552019-01-21 19:46:48 -08001196 return impl_.template Perform<Result>(args);
1197 }
1198
1199 private:
1200 Impl impl_;
1201
1202 GTEST_DISALLOW_ASSIGN_(MonomorphicImpl);
1203 };
1204
1205 Impl impl_;
1206
1207 GTEST_DISALLOW_ASSIGN_(PolymorphicAction);
1208};
1209
1210// Creates an Action from its implementation and returns it. The
1211// created Action object owns the implementation.
1212template <typename F>
1213Action<F> MakeAction(ActionInterface<F>* impl) {
1214 return Action<F>(impl);
1215}
1216
1217// Creates a polymorphic action from its implementation. This is
1218// easier to use than the PolymorphicAction<Impl> constructor as it
1219// doesn't require you to explicitly write the template argument, e.g.
1220//
1221// MakePolymorphicAction(foo);
1222// vs
1223// PolymorphicAction<TypeOfFoo>(foo);
1224template <typename Impl>
1225inline PolymorphicAction<Impl> MakePolymorphicAction(const Impl& impl) {
1226 return PolymorphicAction<Impl>(impl);
1227}
1228
1229namespace internal {
1230
Austin Schuh70cc9552019-01-21 19:46:48 -08001231// Helper struct to specialize ReturnAction to execute a move instead of a copy
1232// on return. Useful for move-only types, but could be used on any type.
1233template <typename T>
1234struct ByMoveWrapper {
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001235 explicit ByMoveWrapper(T value) : payload(std::move(value)) {}
Austin Schuh70cc9552019-01-21 19:46:48 -08001236 T payload;
1237};
1238
1239// Implements the polymorphic Return(x) action, which can be used in
1240// any function that returns the type of x, regardless of the argument
1241// types.
1242//
1243// Note: The value passed into Return must be converted into
1244// Function<F>::Result when this action is cast to Action<F> rather than
1245// when that action is performed. This is important in scenarios like
1246//
1247// MOCK_METHOD1(Method, T(U));
1248// ...
1249// {
1250// Foo foo;
1251// X x(&foo);
1252// EXPECT_CALL(mock, Method(_)).WillOnce(Return(x));
1253// }
1254//
1255// In the example above the variable x holds reference to foo which leaves
1256// scope and gets destroyed. If copying X just copies a reference to foo,
1257// that copy will be left with a hanging reference. If conversion to T
1258// makes a copy of foo, the above code is safe. To support that scenario, we
1259// need to make sure that the type conversion happens inside the EXPECT_CALL
1260// statement, and conversion of the result of Return to Action<T(U)> is a
1261// good place for that.
1262//
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001263// The real life example of the above scenario happens when an invocation
1264// of gtl::Container() is passed into Return.
1265//
Austin Schuh70cc9552019-01-21 19:46:48 -08001266template <typename R>
1267class ReturnAction {
1268 public:
1269 // Constructs a ReturnAction object from the value to be returned.
1270 // 'value' is passed by value instead of by const reference in order
1271 // to allow Return("string literal") to compile.
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001272 explicit ReturnAction(R value) : value_(new R(std::move(value))) {}
Austin Schuh70cc9552019-01-21 19:46:48 -08001273
1274 // This template type conversion operator allows Return(x) to be
1275 // used in ANY function that returns x's type.
1276 template <typename F>
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001277 operator Action<F>() const { // NOLINT
Austin Schuh70cc9552019-01-21 19:46:48 -08001278 // Assert statement belongs here because this is the best place to verify
1279 // conditions on F. It produces the clearest error messages
1280 // in most compilers.
1281 // Impl really belongs in this scope as a local class but can't
1282 // because MSVC produces duplicate symbols in different translation units
1283 // in this case. Until MS fixes that bug we put Impl into the class scope
1284 // and put the typedef both here (for use in assert statement) and
1285 // in the Impl class. But both definitions must be the same.
1286 typedef typename Function<F>::Result Result;
1287 GTEST_COMPILE_ASSERT_(
1288 !is_reference<Result>::value,
1289 use_ReturnRef_instead_of_Return_to_return_a_reference);
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001290 static_assert(!std::is_void<Result>::value,
1291 "Can't use Return() on an action expected to return `void`.");
Austin Schuh70cc9552019-01-21 19:46:48 -08001292 return Action<F>(new Impl<R, F>(value_));
1293 }
1294
1295 private:
1296 // Implements the Return(x) action for a particular function type F.
1297 template <typename R_, typename F>
1298 class Impl : public ActionInterface<F> {
1299 public:
1300 typedef typename Function<F>::Result Result;
1301 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
1302
1303 // The implicit cast is necessary when Result has more than one
1304 // single-argument constructor (e.g. Result is std::vector<int>) and R
1305 // has a type conversion operator template. In that case, value_(value)
1306 // won't compile as the compiler doesn't known which constructor of
1307 // Result to call. ImplicitCast_ forces the compiler to convert R to
1308 // Result without considering explicit constructors, thus resolving the
1309 // ambiguity. value_ is then initialized using its copy constructor.
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001310 explicit Impl(const std::shared_ptr<R>& value)
Austin Schuh70cc9552019-01-21 19:46:48 -08001311 : value_before_cast_(*value),
1312 value_(ImplicitCast_<Result>(value_before_cast_)) {}
1313
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001314 Result Perform(const ArgumentTuple&) override { return value_; }
Austin Schuh70cc9552019-01-21 19:46:48 -08001315
1316 private:
1317 GTEST_COMPILE_ASSERT_(!is_reference<Result>::value,
1318 Result_cannot_be_a_reference_type);
1319 // We save the value before casting just in case it is being cast to a
1320 // wrapper type.
1321 R value_before_cast_;
1322 Result value_;
1323
1324 GTEST_DISALLOW_COPY_AND_ASSIGN_(Impl);
1325 };
1326
1327 // Partially specialize for ByMoveWrapper. This version of ReturnAction will
1328 // move its contents instead.
1329 template <typename R_, typename F>
1330 class Impl<ByMoveWrapper<R_>, F> : public ActionInterface<F> {
1331 public:
1332 typedef typename Function<F>::Result Result;
1333 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
1334
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001335 explicit Impl(const std::shared_ptr<R>& wrapper)
Austin Schuh70cc9552019-01-21 19:46:48 -08001336 : performed_(false), wrapper_(wrapper) {}
1337
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001338 Result Perform(const ArgumentTuple&) override {
Austin Schuh70cc9552019-01-21 19:46:48 -08001339 GTEST_CHECK_(!performed_)
1340 << "A ByMove() action should only be performed once.";
1341 performed_ = true;
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001342 return std::move(wrapper_->payload);
Austin Schuh70cc9552019-01-21 19:46:48 -08001343 }
1344
1345 private:
1346 bool performed_;
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001347 const std::shared_ptr<R> wrapper_;
Austin Schuh70cc9552019-01-21 19:46:48 -08001348
1349 GTEST_DISALLOW_ASSIGN_(Impl);
1350 };
1351
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001352 const std::shared_ptr<R> value_;
Austin Schuh70cc9552019-01-21 19:46:48 -08001353
1354 GTEST_DISALLOW_ASSIGN_(ReturnAction);
1355};
1356
1357// Implements the ReturnNull() action.
1358class ReturnNullAction {
1359 public:
1360 // Allows ReturnNull() to be used in any pointer-returning function. In C++11
1361 // this is enforced by returning nullptr, and in non-C++11 by asserting a
1362 // pointer type on compile time.
1363 template <typename Result, typename ArgumentTuple>
1364 static Result Perform(const ArgumentTuple&) {
Austin Schuh70cc9552019-01-21 19:46:48 -08001365 return nullptr;
Austin Schuh70cc9552019-01-21 19:46:48 -08001366 }
1367};
1368
1369// Implements the Return() action.
1370class ReturnVoidAction {
1371 public:
1372 // Allows Return() to be used in any void-returning function.
1373 template <typename Result, typename ArgumentTuple>
1374 static void Perform(const ArgumentTuple&) {
1375 CompileAssertTypesEqual<void, Result>();
1376 }
1377};
1378
1379// Implements the polymorphic ReturnRef(x) action, which can be used
1380// in any function that returns a reference to the type of x,
1381// regardless of the argument types.
1382template <typename T>
1383class ReturnRefAction {
1384 public:
1385 // Constructs a ReturnRefAction object from the reference to be returned.
1386 explicit ReturnRefAction(T& ref) : ref_(ref) {} // NOLINT
1387
1388 // This template type conversion operator allows ReturnRef(x) to be
1389 // used in ANY function that returns a reference to x's type.
1390 template <typename F>
1391 operator Action<F>() const {
1392 typedef typename Function<F>::Result Result;
1393 // Asserts that the function return type is a reference. This
1394 // catches the user error of using ReturnRef(x) when Return(x)
1395 // should be used, and generates some helpful error message.
1396 GTEST_COMPILE_ASSERT_(internal::is_reference<Result>::value,
1397 use_Return_instead_of_ReturnRef_to_return_a_value);
1398 return Action<F>(new Impl<F>(ref_));
1399 }
1400
1401 private:
1402 // Implements the ReturnRef(x) action for a particular function type F.
1403 template <typename F>
1404 class Impl : public ActionInterface<F> {
1405 public:
1406 typedef typename Function<F>::Result Result;
1407 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
1408
1409 explicit Impl(T& ref) : ref_(ref) {} // NOLINT
1410
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001411 Result Perform(const ArgumentTuple&) override { return ref_; }
Austin Schuh70cc9552019-01-21 19:46:48 -08001412
1413 private:
1414 T& ref_;
1415
1416 GTEST_DISALLOW_ASSIGN_(Impl);
1417 };
1418
1419 T& ref_;
1420
1421 GTEST_DISALLOW_ASSIGN_(ReturnRefAction);
1422};
1423
1424// Implements the polymorphic ReturnRefOfCopy(x) action, which can be
1425// used in any function that returns a reference to the type of x,
1426// regardless of the argument types.
1427template <typename T>
1428class ReturnRefOfCopyAction {
1429 public:
1430 // Constructs a ReturnRefOfCopyAction object from the reference to
1431 // be returned.
1432 explicit ReturnRefOfCopyAction(const T& value) : value_(value) {} // NOLINT
1433
1434 // This template type conversion operator allows ReturnRefOfCopy(x) to be
1435 // used in ANY function that returns a reference to x's type.
1436 template <typename F>
1437 operator Action<F>() const {
1438 typedef typename Function<F>::Result Result;
1439 // Asserts that the function return type is a reference. This
1440 // catches the user error of using ReturnRefOfCopy(x) when Return(x)
1441 // should be used, and generates some helpful error message.
1442 GTEST_COMPILE_ASSERT_(
1443 internal::is_reference<Result>::value,
1444 use_Return_instead_of_ReturnRefOfCopy_to_return_a_value);
1445 return Action<F>(new Impl<F>(value_));
1446 }
1447
1448 private:
1449 // Implements the ReturnRefOfCopy(x) action for a particular function type F.
1450 template <typename F>
1451 class Impl : public ActionInterface<F> {
1452 public:
1453 typedef typename Function<F>::Result Result;
1454 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
1455
1456 explicit Impl(const T& value) : value_(value) {} // NOLINT
1457
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001458 Result Perform(const ArgumentTuple&) override { return value_; }
Austin Schuh70cc9552019-01-21 19:46:48 -08001459
1460 private:
1461 T value_;
1462
1463 GTEST_DISALLOW_ASSIGN_(Impl);
1464 };
1465
1466 const T value_;
1467
1468 GTEST_DISALLOW_ASSIGN_(ReturnRefOfCopyAction);
1469};
1470
1471// Implements the polymorphic DoDefault() action.
1472class DoDefaultAction {
1473 public:
1474 // This template type conversion operator allows DoDefault() to be
1475 // used in any function.
1476 template <typename F>
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001477 operator Action<F>() const { return Action<F>(); } // NOLINT
Austin Schuh70cc9552019-01-21 19:46:48 -08001478};
1479
1480// Implements the Assign action to set a given pointer referent to a
1481// particular value.
1482template <typename T1, typename T2>
1483class AssignAction {
1484 public:
1485 AssignAction(T1* ptr, T2 value) : ptr_(ptr), value_(value) {}
1486
1487 template <typename Result, typename ArgumentTuple>
1488 void Perform(const ArgumentTuple& /* args */) const {
1489 *ptr_ = value_;
1490 }
1491
1492 private:
1493 T1* const ptr_;
1494 const T2 value_;
1495
1496 GTEST_DISALLOW_ASSIGN_(AssignAction);
1497};
1498
1499#if !GTEST_OS_WINDOWS_MOBILE
1500
1501// Implements the SetErrnoAndReturn action to simulate return from
1502// various system calls and libc functions.
1503template <typename T>
1504class SetErrnoAndReturnAction {
1505 public:
1506 SetErrnoAndReturnAction(int errno_value, T result)
1507 : errno_(errno_value),
1508 result_(result) {}
1509 template <typename Result, typename ArgumentTuple>
1510 Result Perform(const ArgumentTuple& /* args */) const {
1511 errno = errno_;
1512 return result_;
1513 }
1514
1515 private:
1516 const int errno_;
1517 const T result_;
1518
1519 GTEST_DISALLOW_ASSIGN_(SetErrnoAndReturnAction);
1520};
1521
1522#endif // !GTEST_OS_WINDOWS_MOBILE
1523
1524// Implements the SetArgumentPointee<N>(x) action for any function
1525// whose N-th argument (0-based) is a pointer to x's type. The
1526// template parameter kIsProto is true iff type A is ProtocolMessage,
1527// proto2::Message, or a sub-class of those.
1528template <size_t N, typename A, bool kIsProto>
1529class SetArgumentPointeeAction {
1530 public:
1531 // Constructs an action that sets the variable pointed to by the
1532 // N-th function argument to 'value'.
1533 explicit SetArgumentPointeeAction(const A& value) : value_(value) {}
1534
1535 template <typename Result, typename ArgumentTuple>
1536 void Perform(const ArgumentTuple& args) const {
1537 CompileAssertTypesEqual<void, Result>();
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001538 *::std::get<N>(args) = value_;
Austin Schuh70cc9552019-01-21 19:46:48 -08001539 }
1540
1541 private:
1542 const A value_;
1543
1544 GTEST_DISALLOW_ASSIGN_(SetArgumentPointeeAction);
1545};
1546
1547template <size_t N, typename Proto>
1548class SetArgumentPointeeAction<N, Proto, true> {
1549 public:
1550 // Constructs an action that sets the variable pointed to by the
1551 // N-th function argument to 'proto'. Both ProtocolMessage and
1552 // proto2::Message have the CopyFrom() method, so the same
1553 // implementation works for both.
1554 explicit SetArgumentPointeeAction(const Proto& proto) : proto_(new Proto) {
1555 proto_->CopyFrom(proto);
1556 }
1557
1558 template <typename Result, typename ArgumentTuple>
1559 void Perform(const ArgumentTuple& args) const {
1560 CompileAssertTypesEqual<void, Result>();
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001561 ::std::get<N>(args)->CopyFrom(*proto_);
Austin Schuh70cc9552019-01-21 19:46:48 -08001562 }
1563
1564 private:
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001565 const std::shared_ptr<Proto> proto_;
Austin Schuh70cc9552019-01-21 19:46:48 -08001566
1567 GTEST_DISALLOW_ASSIGN_(SetArgumentPointeeAction);
1568};
1569
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001570// Implements the Invoke(object_ptr, &Class::Method) action.
1571template <class Class, typename MethodPtr>
1572struct InvokeMethodAction {
1573 Class* const obj_ptr;
1574 const MethodPtr method_ptr;
1575
1576 template <typename... Args>
1577 auto operator()(Args&&... args) const
1578 -> decltype((obj_ptr->*method_ptr)(std::forward<Args>(args)...)) {
1579 return (obj_ptr->*method_ptr)(std::forward<Args>(args)...);
1580 }
1581};
1582
Austin Schuh70cc9552019-01-21 19:46:48 -08001583// Implements the InvokeWithoutArgs(f) action. The template argument
1584// FunctionImpl is the implementation type of f, which can be either a
1585// function pointer or a functor. InvokeWithoutArgs(f) can be used as an
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001586// Action<F> as long as f's type is compatible with F.
Austin Schuh70cc9552019-01-21 19:46:48 -08001587template <typename FunctionImpl>
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001588struct InvokeWithoutArgsAction {
1589 FunctionImpl function_impl;
Austin Schuh70cc9552019-01-21 19:46:48 -08001590
1591 // Allows InvokeWithoutArgs(f) to be used as any action whose type is
1592 // compatible with f.
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001593 template <typename... Args>
1594 auto operator()(const Args&...) -> decltype(function_impl()) {
1595 return function_impl();
1596 }
Austin Schuh70cc9552019-01-21 19:46:48 -08001597};
1598
1599// Implements the InvokeWithoutArgs(object_ptr, &Class::Method) action.
1600template <class Class, typename MethodPtr>
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001601struct InvokeMethodWithoutArgsAction {
1602 Class* const obj_ptr;
1603 const MethodPtr method_ptr;
Austin Schuh70cc9552019-01-21 19:46:48 -08001604
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001605 using ReturnType = typename std::result_of<MethodPtr(Class*)>::type;
1606
1607 template <typename... Args>
1608 ReturnType operator()(const Args&...) const {
1609 return (obj_ptr->*method_ptr)();
Austin Schuh70cc9552019-01-21 19:46:48 -08001610 }
Austin Schuh70cc9552019-01-21 19:46:48 -08001611};
1612
1613// Implements the IgnoreResult(action) action.
1614template <typename A>
1615class IgnoreResultAction {
1616 public:
1617 explicit IgnoreResultAction(const A& action) : action_(action) {}
1618
1619 template <typename F>
1620 operator Action<F>() const {
1621 // Assert statement belongs here because this is the best place to verify
1622 // conditions on F. It produces the clearest error messages
1623 // in most compilers.
1624 // Impl really belongs in this scope as a local class but can't
1625 // because MSVC produces duplicate symbols in different translation units
1626 // in this case. Until MS fixes that bug we put Impl into the class scope
1627 // and put the typedef both here (for use in assert statement) and
1628 // in the Impl class. But both definitions must be the same.
1629 typedef typename internal::Function<F>::Result Result;
1630
1631 // Asserts at compile time that F returns void.
1632 CompileAssertTypesEqual<void, Result>();
1633
1634 return Action<F>(new Impl<F>(action_));
1635 }
1636
1637 private:
1638 template <typename F>
1639 class Impl : public ActionInterface<F> {
1640 public:
1641 typedef typename internal::Function<F>::Result Result;
1642 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
1643
1644 explicit Impl(const A& action) : action_(action) {}
1645
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001646 void Perform(const ArgumentTuple& args) override {
Austin Schuh70cc9552019-01-21 19:46:48 -08001647 // Performs the action and ignores its result.
1648 action_.Perform(args);
1649 }
1650
1651 private:
1652 // Type OriginalFunction is the same as F except that its return
1653 // type is IgnoredValue.
1654 typedef typename internal::Function<F>::MakeResultIgnoredValue
1655 OriginalFunction;
1656
1657 const Action<OriginalFunction> action_;
1658
1659 GTEST_DISALLOW_ASSIGN_(Impl);
1660 };
1661
1662 const A action_;
1663
1664 GTEST_DISALLOW_ASSIGN_(IgnoreResultAction);
1665};
1666
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001667template <typename InnerAction, size_t... I>
1668struct WithArgsAction {
1669 InnerAction action;
Austin Schuh70cc9552019-01-21 19:46:48 -08001670
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001671 // The inner action could be anything convertible to Action<X>.
1672 // We use the conversion operator to detect the signature of the inner Action.
1673 template <typename R, typename... Args>
1674 operator Action<R(Args...)>() const { // NOLINT
1675 Action<R(typename std::tuple_element<I, std::tuple<Args...>>::type...)>
1676 converted(action);
1677
1678 return [converted](Args... args) -> R {
1679 return converted.Perform(std::forward_as_tuple(
1680 std::get<I>(std::forward_as_tuple(std::forward<Args>(args)...))...));
1681 };
1682 }
Austin Schuh70cc9552019-01-21 19:46:48 -08001683};
1684
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001685template <typename... Actions>
1686struct DoAllAction {
1687 private:
1688 template <typename... Args, size_t... I>
1689 std::vector<Action<void(Args...)>> Convert(IndexSequence<I...>) const {
1690 return {std::get<I>(actions)...};
Austin Schuh70cc9552019-01-21 19:46:48 -08001691 }
1692
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001693 public:
1694 std::tuple<Actions...> actions;
Austin Schuh70cc9552019-01-21 19:46:48 -08001695
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001696 template <typename R, typename... Args>
1697 operator Action<R(Args...)>() const { // NOLINT
1698 struct Op {
1699 std::vector<Action<void(Args...)>> converted;
1700 Action<R(Args...)> last;
1701 R operator()(Args... args) const {
1702 auto tuple_args = std::forward_as_tuple(std::forward<Args>(args)...);
1703 for (auto& a : converted) {
1704 a.Perform(tuple_args);
1705 }
1706 return last.Perform(tuple_args);
1707 }
1708 };
1709 return Op{Convert<Args...>(MakeIndexSequence<sizeof...(Actions) - 1>()),
1710 std::get<sizeof...(Actions) - 1>(actions)};
1711 }
Austin Schuh70cc9552019-01-21 19:46:48 -08001712};
1713
1714} // namespace internal
1715
1716// An Unused object can be implicitly constructed from ANY value.
1717// This is handy when defining actions that ignore some or all of the
1718// mock function arguments. For example, given
1719//
1720// MOCK_METHOD3(Foo, double(const string& label, double x, double y));
1721// MOCK_METHOD3(Bar, double(int index, double x, double y));
1722//
1723// instead of
1724//
1725// double DistanceToOriginWithLabel(const string& label, double x, double y) {
1726// return sqrt(x*x + y*y);
1727// }
1728// double DistanceToOriginWithIndex(int index, double x, double y) {
1729// return sqrt(x*x + y*y);
1730// }
1731// ...
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001732// EXPECT_CALL(mock, Foo("abc", _, _))
Austin Schuh70cc9552019-01-21 19:46:48 -08001733// .WillOnce(Invoke(DistanceToOriginWithLabel));
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001734// EXPECT_CALL(mock, Bar(5, _, _))
Austin Schuh70cc9552019-01-21 19:46:48 -08001735// .WillOnce(Invoke(DistanceToOriginWithIndex));
1736//
1737// you could write
1738//
1739// // We can declare any uninteresting argument as Unused.
1740// double DistanceToOrigin(Unused, double x, double y) {
1741// return sqrt(x*x + y*y);
1742// }
1743// ...
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001744// EXPECT_CALL(mock, Foo("abc", _, _)).WillOnce(Invoke(DistanceToOrigin));
1745// EXPECT_CALL(mock, Bar(5, _, _)).WillOnce(Invoke(DistanceToOrigin));
Austin Schuh70cc9552019-01-21 19:46:48 -08001746typedef internal::IgnoredValue Unused;
1747
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001748// Creates an action that does actions a1, a2, ..., sequentially in
1749// each invocation.
1750template <typename... Action>
1751internal::DoAllAction<typename std::decay<Action>::type...> DoAll(
1752 Action&&... action) {
1753 return {std::forward_as_tuple(std::forward<Action>(action)...)};
1754}
1755
1756// WithArg<k>(an_action) creates an action that passes the k-th
1757// (0-based) argument of the mock function to an_action and performs
1758// it. It adapts an action accepting one argument to one that accepts
1759// multiple arguments. For convenience, we also provide
1760// WithArgs<k>(an_action) (defined below) as a synonym.
1761template <size_t k, typename InnerAction>
1762internal::WithArgsAction<typename std::decay<InnerAction>::type, k>
1763WithArg(InnerAction&& action) {
1764 return {std::forward<InnerAction>(action)};
1765}
1766
1767// WithArgs<N1, N2, ..., Nk>(an_action) creates an action that passes
1768// the selected arguments of the mock function to an_action and
1769// performs it. It serves as an adaptor between actions with
1770// different argument lists.
1771template <size_t k, size_t... ks, typename InnerAction>
1772internal::WithArgsAction<typename std::decay<InnerAction>::type, k, ks...>
1773WithArgs(InnerAction&& action) {
1774 return {std::forward<InnerAction>(action)};
1775}
1776
1777// WithoutArgs(inner_action) can be used in a mock function with a
1778// non-empty argument list to perform inner_action, which takes no
1779// argument. In other words, it adapts an action accepting no
1780// argument to one that accepts (and ignores) arguments.
1781template <typename InnerAction>
1782internal::WithArgsAction<typename std::decay<InnerAction>::type>
1783WithoutArgs(InnerAction&& action) {
1784 return {std::forward<InnerAction>(action)};
1785}
Austin Schuh70cc9552019-01-21 19:46:48 -08001786
1787// Creates an action that returns 'value'. 'value' is passed by value
1788// instead of const reference - otherwise Return("string literal")
1789// will trigger a compiler error about using array as initializer.
1790template <typename R>
1791internal::ReturnAction<R> Return(R value) {
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001792 return internal::ReturnAction<R>(std::move(value));
Austin Schuh70cc9552019-01-21 19:46:48 -08001793}
1794
1795// Creates an action that returns NULL.
1796inline PolymorphicAction<internal::ReturnNullAction> ReturnNull() {
1797 return MakePolymorphicAction(internal::ReturnNullAction());
1798}
1799
1800// Creates an action that returns from a void function.
1801inline PolymorphicAction<internal::ReturnVoidAction> Return() {
1802 return MakePolymorphicAction(internal::ReturnVoidAction());
1803}
1804
1805// Creates an action that returns the reference to a variable.
1806template <typename R>
1807inline internal::ReturnRefAction<R> ReturnRef(R& x) { // NOLINT
1808 return internal::ReturnRefAction<R>(x);
1809}
1810
1811// Creates an action that returns the reference to a copy of the
1812// argument. The copy is created when the action is constructed and
1813// lives as long as the action.
1814template <typename R>
1815inline internal::ReturnRefOfCopyAction<R> ReturnRefOfCopy(const R& x) {
1816 return internal::ReturnRefOfCopyAction<R>(x);
1817}
1818
1819// Modifies the parent action (a Return() action) to perform a move of the
1820// argument instead of a copy.
1821// Return(ByMove()) actions can only be executed once and will assert this
1822// invariant.
1823template <typename R>
1824internal::ByMoveWrapper<R> ByMove(R x) {
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001825 return internal::ByMoveWrapper<R>(std::move(x));
Austin Schuh70cc9552019-01-21 19:46:48 -08001826}
1827
1828// Creates an action that does the default action for the give mock function.
1829inline internal::DoDefaultAction DoDefault() {
1830 return internal::DoDefaultAction();
1831}
1832
1833// Creates an action that sets the variable pointed by the N-th
1834// (0-based) function argument to 'value'.
1835template <size_t N, typename T>
1836PolymorphicAction<
1837 internal::SetArgumentPointeeAction<
1838 N, T, internal::IsAProtocolMessage<T>::value> >
1839SetArgPointee(const T& x) {
1840 return MakePolymorphicAction(internal::SetArgumentPointeeAction<
1841 N, T, internal::IsAProtocolMessage<T>::value>(x));
1842}
1843
Austin Schuh70cc9552019-01-21 19:46:48 -08001844template <size_t N>
1845PolymorphicAction<
1846 internal::SetArgumentPointeeAction<N, const char*, false> >
1847SetArgPointee(const char* p) {
1848 return MakePolymorphicAction(internal::SetArgumentPointeeAction<
1849 N, const char*, false>(p));
1850}
1851
1852template <size_t N>
1853PolymorphicAction<
1854 internal::SetArgumentPointeeAction<N, const wchar_t*, false> >
1855SetArgPointee(const wchar_t* p) {
1856 return MakePolymorphicAction(internal::SetArgumentPointeeAction<
1857 N, const wchar_t*, false>(p));
1858}
Austin Schuh70cc9552019-01-21 19:46:48 -08001859
1860// The following version is DEPRECATED.
1861template <size_t N, typename T>
1862PolymorphicAction<
1863 internal::SetArgumentPointeeAction<
1864 N, T, internal::IsAProtocolMessage<T>::value> >
1865SetArgumentPointee(const T& x) {
1866 return MakePolymorphicAction(internal::SetArgumentPointeeAction<
1867 N, T, internal::IsAProtocolMessage<T>::value>(x));
1868}
1869
1870// Creates an action that sets a pointer referent to a given value.
1871template <typename T1, typename T2>
1872PolymorphicAction<internal::AssignAction<T1, T2> > Assign(T1* ptr, T2 val) {
1873 return MakePolymorphicAction(internal::AssignAction<T1, T2>(ptr, val));
1874}
1875
1876#if !GTEST_OS_WINDOWS_MOBILE
1877
1878// Creates an action that sets errno and returns the appropriate error.
1879template <typename T>
1880PolymorphicAction<internal::SetErrnoAndReturnAction<T> >
1881SetErrnoAndReturn(int errval, T result) {
1882 return MakePolymorphicAction(
1883 internal::SetErrnoAndReturnAction<T>(errval, result));
1884}
1885
1886#endif // !GTEST_OS_WINDOWS_MOBILE
1887
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001888// Various overloads for Invoke().
1889
1890// Legacy function.
1891// Actions can now be implicitly constructed from callables. No need to create
1892// wrapper objects.
1893// This function exists for backwards compatibility.
1894template <typename FunctionImpl>
1895typename std::decay<FunctionImpl>::type Invoke(FunctionImpl&& function_impl) {
1896 return std::forward<FunctionImpl>(function_impl);
1897}
1898
1899// Creates an action that invokes the given method on the given object
1900// with the mock function's arguments.
1901template <class Class, typename MethodPtr>
1902internal::InvokeMethodAction<Class, MethodPtr> Invoke(Class* obj_ptr,
1903 MethodPtr method_ptr) {
1904 return {obj_ptr, method_ptr};
1905}
Austin Schuh70cc9552019-01-21 19:46:48 -08001906
1907// Creates an action that invokes 'function_impl' with no argument.
1908template <typename FunctionImpl>
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001909internal::InvokeWithoutArgsAction<typename std::decay<FunctionImpl>::type>
Austin Schuh70cc9552019-01-21 19:46:48 -08001910InvokeWithoutArgs(FunctionImpl function_impl) {
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001911 return {std::move(function_impl)};
Austin Schuh70cc9552019-01-21 19:46:48 -08001912}
1913
1914// Creates an action that invokes the given method on the given object
1915// with no argument.
1916template <class Class, typename MethodPtr>
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001917internal::InvokeMethodWithoutArgsAction<Class, MethodPtr> InvokeWithoutArgs(
1918 Class* obj_ptr, MethodPtr method_ptr) {
1919 return {obj_ptr, method_ptr};
Austin Schuh70cc9552019-01-21 19:46:48 -08001920}
1921
1922// Creates an action that performs an_action and throws away its
1923// result. In other words, it changes the return type of an_action to
1924// void. an_action MUST NOT return void, or the code won't compile.
1925template <typename A>
1926inline internal::IgnoreResultAction<A> IgnoreResult(const A& an_action) {
1927 return internal::IgnoreResultAction<A>(an_action);
1928}
1929
1930// Creates a reference wrapper for the given L-value. If necessary,
1931// you can explicitly specify the type of the reference. For example,
1932// suppose 'derived' is an object of type Derived, ByRef(derived)
1933// would wrap a Derived&. If you want to wrap a const Base& instead,
1934// where Base is a base class of Derived, just write:
1935//
1936// ByRef<const Base>(derived)
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001937//
1938// N.B. ByRef is redundant with std::ref, std::cref and std::reference_wrapper.
1939// However, it may still be used for consistency with ByMove().
Austin Schuh70cc9552019-01-21 19:46:48 -08001940template <typename T>
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001941inline ::std::reference_wrapper<T> ByRef(T& l_value) { // NOLINT
1942 return ::std::reference_wrapper<T>(l_value);
Austin Schuh70cc9552019-01-21 19:46:48 -08001943}
1944
1945} // namespace testing
1946
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001947#ifdef _MSC_VER
1948# pragma warning(pop)
1949#endif
1950
1951
Austin Schuh70cc9552019-01-21 19:46:48 -08001952#endif // GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
1953// Copyright 2007, Google Inc.
1954// All rights reserved.
1955//
1956// Redistribution and use in source and binary forms, with or without
1957// modification, are permitted provided that the following conditions are
1958// met:
1959//
1960// * Redistributions of source code must retain the above copyright
1961// notice, this list of conditions and the following disclaimer.
1962// * Redistributions in binary form must reproduce the above
1963// copyright notice, this list of conditions and the following disclaimer
1964// in the documentation and/or other materials provided with the
1965// distribution.
1966// * Neither the name of Google Inc. nor the names of its
1967// contributors may be used to endorse or promote products derived from
1968// this software without specific prior written permission.
1969//
1970// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1971// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1972// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1973// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1974// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1975// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1976// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1977// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1978// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1979// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1980// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001981
Austin Schuh70cc9552019-01-21 19:46:48 -08001982
1983// Google Mock - a framework for writing C++ mock classes.
1984//
1985// This file implements some commonly used cardinalities. More
1986// cardinalities can be defined by the user implementing the
1987// CardinalityInterface interface if necessary.
1988
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001989// GOOGLETEST_CM0002 DO NOT DELETE
1990
Austin Schuh70cc9552019-01-21 19:46:48 -08001991#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_
1992#define GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_
1993
1994#include <limits.h>
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001995#include <memory>
Austin Schuh70cc9552019-01-21 19:46:48 -08001996#include <ostream> // NOLINT
1997
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001998GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
1999/* class A needs to have dll-interface to be used by clients of class B */)
2000
Austin Schuh70cc9552019-01-21 19:46:48 -08002001namespace testing {
2002
2003// To implement a cardinality Foo, define:
2004// 1. a class FooCardinality that implements the
2005// CardinalityInterface interface, and
2006// 2. a factory function that creates a Cardinality object from a
2007// const FooCardinality*.
2008//
2009// The two-level delegation design follows that of Matcher, providing
2010// consistency for extension developers. It also eases ownership
2011// management as Cardinality objects can now be copied like plain values.
2012
2013// The implementation of a cardinality.
2014class CardinalityInterface {
2015 public:
2016 virtual ~CardinalityInterface() {}
2017
2018 // Conservative estimate on the lower/upper bound of the number of
2019 // calls allowed.
2020 virtual int ConservativeLowerBound() const { return 0; }
2021 virtual int ConservativeUpperBound() const { return INT_MAX; }
2022
2023 // Returns true iff call_count calls will satisfy this cardinality.
2024 virtual bool IsSatisfiedByCallCount(int call_count) const = 0;
2025
2026 // Returns true iff call_count calls will saturate this cardinality.
2027 virtual bool IsSaturatedByCallCount(int call_count) const = 0;
2028
2029 // Describes self to an ostream.
2030 virtual void DescribeTo(::std::ostream* os) const = 0;
2031};
2032
2033// A Cardinality is a copyable and IMMUTABLE (except by assignment)
2034// object that specifies how many times a mock function is expected to
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08002035// be called. The implementation of Cardinality is just a std::shared_ptr
2036// to const CardinalityInterface. Don't inherit from Cardinality!
Austin Schuh70cc9552019-01-21 19:46:48 -08002037class GTEST_API_ Cardinality {
2038 public:
2039 // Constructs a null cardinality. Needed for storing Cardinality
2040 // objects in STL containers.
2041 Cardinality() {}
2042
2043 // Constructs a Cardinality from its implementation.
2044 explicit Cardinality(const CardinalityInterface* impl) : impl_(impl) {}
2045
2046 // Conservative estimate on the lower/upper bound of the number of
2047 // calls allowed.
2048 int ConservativeLowerBound() const { return impl_->ConservativeLowerBound(); }
2049 int ConservativeUpperBound() const { return impl_->ConservativeUpperBound(); }
2050
2051 // Returns true iff call_count calls will satisfy this cardinality.
2052 bool IsSatisfiedByCallCount(int call_count) const {
2053 return impl_->IsSatisfiedByCallCount(call_count);
2054 }
2055
2056 // Returns true iff call_count calls will saturate this cardinality.
2057 bool IsSaturatedByCallCount(int call_count) const {
2058 return impl_->IsSaturatedByCallCount(call_count);
2059 }
2060
2061 // Returns true iff call_count calls will over-saturate this
2062 // cardinality, i.e. exceed the maximum number of allowed calls.
2063 bool IsOverSaturatedByCallCount(int call_count) const {
2064 return impl_->IsSaturatedByCallCount(call_count) &&
2065 !impl_->IsSatisfiedByCallCount(call_count);
2066 }
2067
2068 // Describes self to an ostream
2069 void DescribeTo(::std::ostream* os) const { impl_->DescribeTo(os); }
2070
2071 // Describes the given actual call count to an ostream.
2072 static void DescribeActualCallCountTo(int actual_call_count,
2073 ::std::ostream* os);
2074
2075 private:
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08002076 std::shared_ptr<const CardinalityInterface> impl_;
Austin Schuh70cc9552019-01-21 19:46:48 -08002077};
2078
2079// Creates a cardinality that allows at least n calls.
2080GTEST_API_ Cardinality AtLeast(int n);
2081
2082// Creates a cardinality that allows at most n calls.
2083GTEST_API_ Cardinality AtMost(int n);
2084
2085// Creates a cardinality that allows any number of calls.
2086GTEST_API_ Cardinality AnyNumber();
2087
2088// Creates a cardinality that allows between min and max calls.
2089GTEST_API_ Cardinality Between(int min, int max);
2090
2091// Creates a cardinality that allows exactly n calls.
2092GTEST_API_ Cardinality Exactly(int n);
2093
2094// Creates a cardinality from its implementation.
2095inline Cardinality MakeCardinality(const CardinalityInterface* c) {
2096 return Cardinality(c);
2097}
2098
2099} // namespace testing
2100
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08002101GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
2102
Austin Schuh70cc9552019-01-21 19:46:48 -08002103#endif // GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08002104#ifndef THIRD_PARTY_GOOGLETEST_GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_FUNCTION_MOCKER_H_ // NOLINT
2105#define THIRD_PARTY_GOOGLETEST_GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_FUNCTION_MOCKER_H_ // NOLINT
2106
2107// This file was GENERATED by command:
2108// pump.py gmock-generated-function-mockers.h.pump
2109// DO NOT EDIT BY HAND!!!
Austin Schuh70cc9552019-01-21 19:46:48 -08002110
2111// Copyright 2007, Google Inc.
2112// All rights reserved.
2113//
2114// Redistribution and use in source and binary forms, with or without
2115// modification, are permitted provided that the following conditions are
2116// met:
2117//
2118// * Redistributions of source code must retain the above copyright
2119// notice, this list of conditions and the following disclaimer.
2120// * Redistributions in binary form must reproduce the above
2121// copyright notice, this list of conditions and the following disclaimer
2122// in the documentation and/or other materials provided with the
2123// distribution.
2124// * Neither the name of Google Inc. nor the names of its
2125// contributors may be used to endorse or promote products derived from
2126// this software without specific prior written permission.
2127//
2128// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2129// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2130// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2131// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2132// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2133// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2134// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2135// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2136// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2137// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2138// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08002139
2140
2141// Google Mock - a framework for writing C++ mock classes.
Austin Schuh70cc9552019-01-21 19:46:48 -08002142//
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08002143// This file implements function mockers of various arities.
2144
2145// GOOGLETEST_CM0002 DO NOT DELETE
2146
2147#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
2148#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
2149
2150#include <functional>
2151#include <utility>
2152
2153// Copyright 2007, Google Inc.
2154// All rights reserved.
2155//
2156// Redistribution and use in source and binary forms, with or without
2157// modification, are permitted provided that the following conditions are
2158// met:
2159//
2160// * Redistributions of source code must retain the above copyright
2161// notice, this list of conditions and the following disclaimer.
2162// * Redistributions in binary form must reproduce the above
2163// copyright notice, this list of conditions and the following disclaimer
2164// in the documentation and/or other materials provided with the
2165// distribution.
2166// * Neither the name of Google Inc. nor the names of its
2167// contributors may be used to endorse or promote products derived from
2168// this software without specific prior written permission.
2169//
2170// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2171// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2172// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2173// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2174// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2175// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2176// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2177// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2178// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2179// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2180// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2181
2182
2183// Google Mock - a framework for writing C++ mock classes.
2184//
2185// This file implements the ON_CALL() and EXPECT_CALL() macros.
2186//
2187// A user can use the ON_CALL() macro to specify the default action of
2188// a mock method. The syntax is:
2189//
2190// ON_CALL(mock_object, Method(argument-matchers))
2191// .With(multi-argument-matcher)
2192// .WillByDefault(action);
2193//
2194// where the .With() clause is optional.
2195//
2196// A user can use the EXPECT_CALL() macro to specify an expectation on
2197// a mock method. The syntax is:
2198//
2199// EXPECT_CALL(mock_object, Method(argument-matchers))
2200// .With(multi-argument-matchers)
2201// .Times(cardinality)
2202// .InSequence(sequences)
2203// .After(expectations)
2204// .WillOnce(action)
2205// .WillRepeatedly(action)
2206// .RetiresOnSaturation();
2207//
2208// where all clauses are optional, and .InSequence()/.After()/
2209// .WillOnce() can appear any number of times.
2210
2211// GOOGLETEST_CM0002 DO NOT DELETE
2212
2213#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_
2214#define GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_
2215
2216#include <map>
2217#include <memory>
2218#include <set>
2219#include <sstream>
2220#include <string>
2221#include <utility>
2222#include <vector>
2223// Copyright 2007, Google Inc.
2224// All rights reserved.
2225//
2226// Redistribution and use in source and binary forms, with or without
2227// modification, are permitted provided that the following conditions are
2228// met:
2229//
2230// * Redistributions of source code must retain the above copyright
2231// notice, this list of conditions and the following disclaimer.
2232// * Redistributions in binary form must reproduce the above
2233// copyright notice, this list of conditions and the following disclaimer
2234// in the documentation and/or other materials provided with the
2235// distribution.
2236// * Neither the name of Google Inc. nor the names of its
2237// contributors may be used to endorse or promote products derived from
2238// this software without specific prior written permission.
2239//
2240// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2241// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2242// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2243// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2244// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2245// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2246// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2247// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2248// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2249// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2250// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2251
2252
2253// Google Mock - a framework for writing C++ mock classes.
2254//
2255// This file implements some commonly used argument matchers. More
2256// matchers can be defined by the user implementing the
2257// MatcherInterface<T> interface if necessary.
2258//
2259// See googletest/include/gtest/gtest-matchers.h for the definition of class
2260// Matcher, class MatcherInterface, and others.
2261
2262// GOOGLETEST_CM0002 DO NOT DELETE
2263
2264#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
2265#define GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
2266
2267#include <math.h>
2268#include <algorithm>
2269#include <initializer_list>
2270#include <iterator>
2271#include <limits>
2272#include <memory>
2273#include <ostream> // NOLINT
2274#include <sstream>
2275#include <string>
2276#include <type_traits>
2277#include <utility>
2278#include <vector>
2279
2280GTEST_DISABLE_MSC_WARNINGS_PUSH_(
2281 4251 5046 /* class A needs to have dll-interface to be used by clients of
2282 class B */
2283 /* Symbol involving type with internal linkage not defined */)
2284
2285namespace testing {
2286
2287// To implement a matcher Foo for type T, define:
2288// 1. a class FooMatcherImpl that implements the
2289// MatcherInterface<T> interface, and
2290// 2. a factory function that creates a Matcher<T> object from a
2291// FooMatcherImpl*.
2292//
2293// The two-level delegation design makes it possible to allow a user
2294// to write "v" instead of "Eq(v)" where a Matcher is expected, which
2295// is impossible if we pass matchers by pointers. It also eases
2296// ownership management as Matcher objects can now be copied like
2297// plain values.
2298
2299// A match result listener that stores the explanation in a string.
2300class StringMatchResultListener : public MatchResultListener {
2301 public:
2302 StringMatchResultListener() : MatchResultListener(&ss_) {}
2303
2304 // Returns the explanation accumulated so far.
2305 std::string str() const { return ss_.str(); }
2306
2307 // Clears the explanation accumulated so far.
2308 void Clear() { ss_.str(""); }
2309
2310 private:
2311 ::std::stringstream ss_;
2312
2313 GTEST_DISALLOW_COPY_AND_ASSIGN_(StringMatchResultListener);
2314};
2315
2316// Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION
2317// and MUST NOT BE USED IN USER CODE!!!
2318namespace internal {
2319
2320// The MatcherCastImpl class template is a helper for implementing
2321// MatcherCast(). We need this helper in order to partially
2322// specialize the implementation of MatcherCast() (C++ allows
2323// class/struct templates to be partially specialized, but not
2324// function templates.).
2325
2326// This general version is used when MatcherCast()'s argument is a
2327// polymorphic matcher (i.e. something that can be converted to a
2328// Matcher but is not one yet; for example, Eq(value)) or a value (for
2329// example, "hello").
2330template <typename T, typename M>
2331class MatcherCastImpl {
2332 public:
2333 static Matcher<T> Cast(const M& polymorphic_matcher_or_value) {
2334 // M can be a polymorphic matcher, in which case we want to use
2335 // its conversion operator to create Matcher<T>. Or it can be a value
2336 // that should be passed to the Matcher<T>'s constructor.
2337 //
2338 // We can't call Matcher<T>(polymorphic_matcher_or_value) when M is a
2339 // polymorphic matcher because it'll be ambiguous if T has an implicit
2340 // constructor from M (this usually happens when T has an implicit
2341 // constructor from any type).
2342 //
2343 // It won't work to unconditionally implict_cast
2344 // polymorphic_matcher_or_value to Matcher<T> because it won't trigger
2345 // a user-defined conversion from M to T if one exists (assuming M is
2346 // a value).
2347 return CastImpl(
2348 polymorphic_matcher_or_value,
2349 BooleanConstant<
2350 std::is_convertible<M, Matcher<T> >::value>(),
2351 BooleanConstant<
2352 std::is_convertible<M, T>::value>());
2353 }
2354
2355 private:
2356 template <bool Ignore>
2357 static Matcher<T> CastImpl(const M& polymorphic_matcher_or_value,
2358 BooleanConstant<true> /* convertible_to_matcher */,
2359 BooleanConstant<Ignore>) {
2360 // M is implicitly convertible to Matcher<T>, which means that either
2361 // M is a polymorphic matcher or Matcher<T> has an implicit constructor
2362 // from M. In both cases using the implicit conversion will produce a
2363 // matcher.
2364 //
2365 // Even if T has an implicit constructor from M, it won't be called because
2366 // creating Matcher<T> would require a chain of two user-defined conversions
2367 // (first to create T from M and then to create Matcher<T> from T).
2368 return polymorphic_matcher_or_value;
2369 }
2370
2371 // M can't be implicitly converted to Matcher<T>, so M isn't a polymorphic
2372 // matcher. It's a value of a type implicitly convertible to T. Use direct
2373 // initialization to create a matcher.
2374 static Matcher<T> CastImpl(
2375 const M& value, BooleanConstant<false> /* convertible_to_matcher */,
2376 BooleanConstant<true> /* convertible_to_T */) {
2377 return Matcher<T>(ImplicitCast_<T>(value));
2378 }
2379
2380 // M can't be implicitly converted to either Matcher<T> or T. Attempt to use
2381 // polymorphic matcher Eq(value) in this case.
2382 //
2383 // Note that we first attempt to perform an implicit cast on the value and
2384 // only fall back to the polymorphic Eq() matcher afterwards because the
2385 // latter calls bool operator==(const Lhs& lhs, const Rhs& rhs) in the end
2386 // which might be undefined even when Rhs is implicitly convertible to Lhs
2387 // (e.g. std::pair<const int, int> vs. std::pair<int, int>).
2388 //
2389 // We don't define this method inline as we need the declaration of Eq().
2390 static Matcher<T> CastImpl(
2391 const M& value, BooleanConstant<false> /* convertible_to_matcher */,
2392 BooleanConstant<false> /* convertible_to_T */);
2393};
2394
2395// This more specialized version is used when MatcherCast()'s argument
2396// is already a Matcher. This only compiles when type T can be
2397// statically converted to type U.
2398template <typename T, typename U>
2399class MatcherCastImpl<T, Matcher<U> > {
2400 public:
2401 static Matcher<T> Cast(const Matcher<U>& source_matcher) {
2402 return Matcher<T>(new Impl(source_matcher));
2403 }
2404
2405 private:
2406 class Impl : public MatcherInterface<T> {
2407 public:
2408 explicit Impl(const Matcher<U>& source_matcher)
2409 : source_matcher_(source_matcher) {}
2410
2411 // We delegate the matching logic to the source matcher.
2412 bool MatchAndExplain(T x, MatchResultListener* listener) const override {
2413 using FromType = typename std::remove_cv<typename std::remove_pointer<
2414 typename std::remove_reference<T>::type>::type>::type;
2415 using ToType = typename std::remove_cv<typename std::remove_pointer<
2416 typename std::remove_reference<U>::type>::type>::type;
2417 // Do not allow implicitly converting base*/& to derived*/&.
2418 static_assert(
2419 // Do not trigger if only one of them is a pointer. That implies a
2420 // regular conversion and not a down_cast.
2421 (std::is_pointer<typename std::remove_reference<T>::type>::value !=
2422 std::is_pointer<typename std::remove_reference<U>::type>::value) ||
2423 std::is_same<FromType, ToType>::value ||
2424 !std::is_base_of<FromType, ToType>::value,
2425 "Can't implicitly convert from <base> to <derived>");
2426
2427 return source_matcher_.MatchAndExplain(static_cast<U>(x), listener);
2428 }
2429
2430 void DescribeTo(::std::ostream* os) const override {
2431 source_matcher_.DescribeTo(os);
2432 }
2433
2434 void DescribeNegationTo(::std::ostream* os) const override {
2435 source_matcher_.DescribeNegationTo(os);
2436 }
2437
2438 private:
2439 const Matcher<U> source_matcher_;
2440
2441 GTEST_DISALLOW_ASSIGN_(Impl);
2442 };
2443};
2444
2445// This even more specialized version is used for efficiently casting
2446// a matcher to its own type.
2447template <typename T>
2448class MatcherCastImpl<T, Matcher<T> > {
2449 public:
2450 static Matcher<T> Cast(const Matcher<T>& matcher) { return matcher; }
2451};
2452
2453} // namespace internal
2454
2455// In order to be safe and clear, casting between different matcher
2456// types is done explicitly via MatcherCast<T>(m), which takes a
2457// matcher m and returns a Matcher<T>. It compiles only when T can be
2458// statically converted to the argument type of m.
2459template <typename T, typename M>
2460inline Matcher<T> MatcherCast(const M& matcher) {
2461 return internal::MatcherCastImpl<T, M>::Cast(matcher);
2462}
2463
2464// Implements SafeMatcherCast().
2465//
2466// FIXME: The intermediate SafeMatcherCastImpl class was introduced as a
2467// workaround for a compiler bug, and can now be removed.
2468template <typename T>
2469class SafeMatcherCastImpl {
2470 public:
2471 // This overload handles polymorphic matchers and values only since
2472 // monomorphic matchers are handled by the next one.
2473 template <typename M>
2474 static inline Matcher<T> Cast(const M& polymorphic_matcher_or_value) {
2475 return internal::MatcherCastImpl<T, M>::Cast(polymorphic_matcher_or_value);
2476 }
2477
2478 // This overload handles monomorphic matchers.
2479 //
2480 // In general, if type T can be implicitly converted to type U, we can
2481 // safely convert a Matcher<U> to a Matcher<T> (i.e. Matcher is
2482 // contravariant): just keep a copy of the original Matcher<U>, convert the
2483 // argument from type T to U, and then pass it to the underlying Matcher<U>.
2484 // The only exception is when U is a reference and T is not, as the
2485 // underlying Matcher<U> may be interested in the argument's address, which
2486 // is not preserved in the conversion from T to U.
2487 template <typename U>
2488 static inline Matcher<T> Cast(const Matcher<U>& matcher) {
2489 // Enforce that T can be implicitly converted to U.
2490 GTEST_COMPILE_ASSERT_((std::is_convertible<T, U>::value),
2491 "T must be implicitly convertible to U");
2492 // Enforce that we are not converting a non-reference type T to a reference
2493 // type U.
2494 GTEST_COMPILE_ASSERT_(
2495 internal::is_reference<T>::value || !internal::is_reference<U>::value,
2496 cannot_convert_non_reference_arg_to_reference);
2497 // In case both T and U are arithmetic types, enforce that the
2498 // conversion is not lossy.
2499 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(T) RawT;
2500 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(U) RawU;
2501 const bool kTIsOther = GMOCK_KIND_OF_(RawT) == internal::kOther;
2502 const bool kUIsOther = GMOCK_KIND_OF_(RawU) == internal::kOther;
2503 GTEST_COMPILE_ASSERT_(
2504 kTIsOther || kUIsOther ||
2505 (internal::LosslessArithmeticConvertible<RawT, RawU>::value),
2506 conversion_of_arithmetic_types_must_be_lossless);
2507 return MatcherCast<T>(matcher);
2508 }
2509};
2510
2511template <typename T, typename M>
2512inline Matcher<T> SafeMatcherCast(const M& polymorphic_matcher) {
2513 return SafeMatcherCastImpl<T>::Cast(polymorphic_matcher);
2514}
2515
2516// A<T>() returns a matcher that matches any value of type T.
2517template <typename T>
2518Matcher<T> A();
2519
2520// Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION
2521// and MUST NOT BE USED IN USER CODE!!!
2522namespace internal {
2523
2524// If the explanation is not empty, prints it to the ostream.
2525inline void PrintIfNotEmpty(const std::string& explanation,
2526 ::std::ostream* os) {
2527 if (explanation != "" && os != nullptr) {
2528 *os << ", " << explanation;
2529 }
2530}
2531
2532// Returns true if the given type name is easy to read by a human.
2533// This is used to decide whether printing the type of a value might
2534// be helpful.
2535inline bool IsReadableTypeName(const std::string& type_name) {
2536 // We consider a type name readable if it's short or doesn't contain
2537 // a template or function type.
2538 return (type_name.length() <= 20 ||
2539 type_name.find_first_of("<(") == std::string::npos);
2540}
2541
2542// Matches the value against the given matcher, prints the value and explains
2543// the match result to the listener. Returns the match result.
2544// 'listener' must not be NULL.
2545// Value cannot be passed by const reference, because some matchers take a
2546// non-const argument.
2547template <typename Value, typename T>
2548bool MatchPrintAndExplain(Value& value, const Matcher<T>& matcher,
2549 MatchResultListener* listener) {
2550 if (!listener->IsInterested()) {
2551 // If the listener is not interested, we do not need to construct the
2552 // inner explanation.
2553 return matcher.Matches(value);
2554 }
2555
2556 StringMatchResultListener inner_listener;
2557 const bool match = matcher.MatchAndExplain(value, &inner_listener);
2558
2559 UniversalPrint(value, listener->stream());
2560#if GTEST_HAS_RTTI
2561 const std::string& type_name = GetTypeName<Value>();
2562 if (IsReadableTypeName(type_name))
2563 *listener->stream() << " (of type " << type_name << ")";
2564#endif
2565 PrintIfNotEmpty(inner_listener.str(), listener->stream());
2566
2567 return match;
2568}
2569
2570// An internal helper class for doing compile-time loop on a tuple's
2571// fields.
2572template <size_t N>
2573class TuplePrefix {
2574 public:
2575 // TuplePrefix<N>::Matches(matcher_tuple, value_tuple) returns true
2576 // iff the first N fields of matcher_tuple matches the first N
2577 // fields of value_tuple, respectively.
2578 template <typename MatcherTuple, typename ValueTuple>
2579 static bool Matches(const MatcherTuple& matcher_tuple,
2580 const ValueTuple& value_tuple) {
2581 return TuplePrefix<N - 1>::Matches(matcher_tuple, value_tuple) &&
2582 std::get<N - 1>(matcher_tuple).Matches(std::get<N - 1>(value_tuple));
2583 }
2584
2585 // TuplePrefix<N>::ExplainMatchFailuresTo(matchers, values, os)
2586 // describes failures in matching the first N fields of matchers
2587 // against the first N fields of values. If there is no failure,
2588 // nothing will be streamed to os.
2589 template <typename MatcherTuple, typename ValueTuple>
2590 static void ExplainMatchFailuresTo(const MatcherTuple& matchers,
2591 const ValueTuple& values,
2592 ::std::ostream* os) {
2593 // First, describes failures in the first N - 1 fields.
2594 TuplePrefix<N - 1>::ExplainMatchFailuresTo(matchers, values, os);
2595
2596 // Then describes the failure (if any) in the (N - 1)-th (0-based)
2597 // field.
2598 typename std::tuple_element<N - 1, MatcherTuple>::type matcher =
2599 std::get<N - 1>(matchers);
2600 typedef typename std::tuple_element<N - 1, ValueTuple>::type Value;
2601 const Value& value = std::get<N - 1>(values);
2602 StringMatchResultListener listener;
2603 if (!matcher.MatchAndExplain(value, &listener)) {
2604 *os << " Expected arg #" << N - 1 << ": ";
2605 std::get<N - 1>(matchers).DescribeTo(os);
2606 *os << "\n Actual: ";
2607 // We remove the reference in type Value to prevent the
2608 // universal printer from printing the address of value, which
2609 // isn't interesting to the user most of the time. The
2610 // matcher's MatchAndExplain() method handles the case when
2611 // the address is interesting.
2612 internal::UniversalPrint(value, os);
2613 PrintIfNotEmpty(listener.str(), os);
2614 *os << "\n";
2615 }
2616 }
2617};
2618
2619// The base case.
2620template <>
2621class TuplePrefix<0> {
2622 public:
2623 template <typename MatcherTuple, typename ValueTuple>
2624 static bool Matches(const MatcherTuple& /* matcher_tuple */,
2625 const ValueTuple& /* value_tuple */) {
2626 return true;
2627 }
2628
2629 template <typename MatcherTuple, typename ValueTuple>
2630 static void ExplainMatchFailuresTo(const MatcherTuple& /* matchers */,
2631 const ValueTuple& /* values */,
2632 ::std::ostream* /* os */) {}
2633};
2634
2635// TupleMatches(matcher_tuple, value_tuple) returns true iff all
2636// matchers in matcher_tuple match the corresponding fields in
2637// value_tuple. It is a compiler error if matcher_tuple and
2638// value_tuple have different number of fields or incompatible field
2639// types.
2640template <typename MatcherTuple, typename ValueTuple>
2641bool TupleMatches(const MatcherTuple& matcher_tuple,
2642 const ValueTuple& value_tuple) {
2643 // Makes sure that matcher_tuple and value_tuple have the same
2644 // number of fields.
2645 GTEST_COMPILE_ASSERT_(std::tuple_size<MatcherTuple>::value ==
2646 std::tuple_size<ValueTuple>::value,
2647 matcher_and_value_have_different_numbers_of_fields);
2648 return TuplePrefix<std::tuple_size<ValueTuple>::value>::Matches(matcher_tuple,
2649 value_tuple);
2650}
2651
2652// Describes failures in matching matchers against values. If there
2653// is no failure, nothing will be streamed to os.
2654template <typename MatcherTuple, typename ValueTuple>
2655void ExplainMatchFailureTupleTo(const MatcherTuple& matchers,
2656 const ValueTuple& values,
2657 ::std::ostream* os) {
2658 TuplePrefix<std::tuple_size<MatcherTuple>::value>::ExplainMatchFailuresTo(
2659 matchers, values, os);
2660}
2661
2662// TransformTupleValues and its helper.
2663//
2664// TransformTupleValuesHelper hides the internal machinery that
2665// TransformTupleValues uses to implement a tuple traversal.
2666template <typename Tuple, typename Func, typename OutIter>
2667class TransformTupleValuesHelper {
2668 private:
2669 typedef ::std::tuple_size<Tuple> TupleSize;
2670
2671 public:
2672 // For each member of tuple 't', taken in order, evaluates '*out++ = f(t)'.
2673 // Returns the final value of 'out' in case the caller needs it.
2674 static OutIter Run(Func f, const Tuple& t, OutIter out) {
2675 return IterateOverTuple<Tuple, TupleSize::value>()(f, t, out);
2676 }
2677
2678 private:
2679 template <typename Tup, size_t kRemainingSize>
2680 struct IterateOverTuple {
2681 OutIter operator() (Func f, const Tup& t, OutIter out) const {
2682 *out++ = f(::std::get<TupleSize::value - kRemainingSize>(t));
2683 return IterateOverTuple<Tup, kRemainingSize - 1>()(f, t, out);
2684 }
2685 };
2686 template <typename Tup>
2687 struct IterateOverTuple<Tup, 0> {
2688 OutIter operator() (Func /* f */, const Tup& /* t */, OutIter out) const {
2689 return out;
2690 }
2691 };
2692};
2693
2694// Successively invokes 'f(element)' on each element of the tuple 't',
2695// appending each result to the 'out' iterator. Returns the final value
2696// of 'out'.
2697template <typename Tuple, typename Func, typename OutIter>
2698OutIter TransformTupleValues(Func f, const Tuple& t, OutIter out) {
2699 return TransformTupleValuesHelper<Tuple, Func, OutIter>::Run(f, t, out);
2700}
2701
2702// Implements A<T>().
2703template <typename T>
2704class AnyMatcherImpl : public MatcherInterface<const T&> {
2705 public:
2706 bool MatchAndExplain(const T& /* x */,
2707 MatchResultListener* /* listener */) const override {
2708 return true;
2709 }
2710 void DescribeTo(::std::ostream* os) const override { *os << "is anything"; }
2711 void DescribeNegationTo(::std::ostream* os) const override {
2712 // This is mostly for completeness' safe, as it's not very useful
2713 // to write Not(A<bool>()). However we cannot completely rule out
2714 // such a possibility, and it doesn't hurt to be prepared.
2715 *os << "never matches";
2716 }
2717};
2718
2719// Implements _, a matcher that matches any value of any
2720// type. This is a polymorphic matcher, so we need a template type
2721// conversion operator to make it appearing as a Matcher<T> for any
2722// type T.
2723class AnythingMatcher {
2724 public:
2725 template <typename T>
2726 operator Matcher<T>() const { return A<T>(); }
2727};
2728
2729// Implements the polymorphic IsNull() matcher, which matches any raw or smart
2730// pointer that is NULL.
2731class IsNullMatcher {
2732 public:
2733 template <typename Pointer>
2734 bool MatchAndExplain(const Pointer& p,
2735 MatchResultListener* /* listener */) const {
2736 return p == nullptr;
2737 }
2738
2739 void DescribeTo(::std::ostream* os) const { *os << "is NULL"; }
2740 void DescribeNegationTo(::std::ostream* os) const {
2741 *os << "isn't NULL";
2742 }
2743};
2744
2745// Implements the polymorphic NotNull() matcher, which matches any raw or smart
2746// pointer that is not NULL.
2747class NotNullMatcher {
2748 public:
2749 template <typename Pointer>
2750 bool MatchAndExplain(const Pointer& p,
2751 MatchResultListener* /* listener */) const {
2752 return p != nullptr;
2753 }
2754
2755 void DescribeTo(::std::ostream* os) const { *os << "isn't NULL"; }
2756 void DescribeNegationTo(::std::ostream* os) const {
2757 *os << "is NULL";
2758 }
2759};
2760
2761// Ref(variable) matches any argument that is a reference to
2762// 'variable'. This matcher is polymorphic as it can match any
2763// super type of the type of 'variable'.
2764//
2765// The RefMatcher template class implements Ref(variable). It can
2766// only be instantiated with a reference type. This prevents a user
2767// from mistakenly using Ref(x) to match a non-reference function
2768// argument. For example, the following will righteously cause a
2769// compiler error:
2770//
2771// int n;
2772// Matcher<int> m1 = Ref(n); // This won't compile.
2773// Matcher<int&> m2 = Ref(n); // This will compile.
2774template <typename T>
2775class RefMatcher;
2776
2777template <typename T>
2778class RefMatcher<T&> {
2779 // Google Mock is a generic framework and thus needs to support
2780 // mocking any function types, including those that take non-const
2781 // reference arguments. Therefore the template parameter T (and
2782 // Super below) can be instantiated to either a const type or a
2783 // non-const type.
2784 public:
2785 // RefMatcher() takes a T& instead of const T&, as we want the
2786 // compiler to catch using Ref(const_value) as a matcher for a
2787 // non-const reference.
2788 explicit RefMatcher(T& x) : object_(x) {} // NOLINT
2789
2790 template <typename Super>
2791 operator Matcher<Super&>() const {
2792 // By passing object_ (type T&) to Impl(), which expects a Super&,
2793 // we make sure that Super is a super type of T. In particular,
2794 // this catches using Ref(const_value) as a matcher for a
2795 // non-const reference, as you cannot implicitly convert a const
2796 // reference to a non-const reference.
2797 return MakeMatcher(new Impl<Super>(object_));
2798 }
2799
2800 private:
2801 template <typename Super>
2802 class Impl : public MatcherInterface<Super&> {
2803 public:
2804 explicit Impl(Super& x) : object_(x) {} // NOLINT
2805
2806 // MatchAndExplain() takes a Super& (as opposed to const Super&)
2807 // in order to match the interface MatcherInterface<Super&>.
2808 bool MatchAndExplain(Super& x,
2809 MatchResultListener* listener) const override {
2810 *listener << "which is located @" << static_cast<const void*>(&x);
2811 return &x == &object_;
2812 }
2813
2814 void DescribeTo(::std::ostream* os) const override {
2815 *os << "references the variable ";
2816 UniversalPrinter<Super&>::Print(object_, os);
2817 }
2818
2819 void DescribeNegationTo(::std::ostream* os) const override {
2820 *os << "does not reference the variable ";
2821 UniversalPrinter<Super&>::Print(object_, os);
2822 }
2823
2824 private:
2825 const Super& object_;
2826
2827 GTEST_DISALLOW_ASSIGN_(Impl);
2828 };
2829
2830 T& object_;
2831
2832 GTEST_DISALLOW_ASSIGN_(RefMatcher);
2833};
2834
2835// Polymorphic helper functions for narrow and wide string matchers.
2836inline bool CaseInsensitiveCStringEquals(const char* lhs, const char* rhs) {
2837 return String::CaseInsensitiveCStringEquals(lhs, rhs);
2838}
2839
2840inline bool CaseInsensitiveCStringEquals(const wchar_t* lhs,
2841 const wchar_t* rhs) {
2842 return String::CaseInsensitiveWideCStringEquals(lhs, rhs);
2843}
2844
2845// String comparison for narrow or wide strings that can have embedded NUL
2846// characters.
2847template <typename StringType>
2848bool CaseInsensitiveStringEquals(const StringType& s1,
2849 const StringType& s2) {
2850 // Are the heads equal?
2851 if (!CaseInsensitiveCStringEquals(s1.c_str(), s2.c_str())) {
2852 return false;
2853 }
2854
2855 // Skip the equal heads.
2856 const typename StringType::value_type nul = 0;
2857 const size_t i1 = s1.find(nul), i2 = s2.find(nul);
2858
2859 // Are we at the end of either s1 or s2?
2860 if (i1 == StringType::npos || i2 == StringType::npos) {
2861 return i1 == i2;
2862 }
2863
2864 // Are the tails equal?
2865 return CaseInsensitiveStringEquals(s1.substr(i1 + 1), s2.substr(i2 + 1));
2866}
2867
2868// String matchers.
2869
2870// Implements equality-based string matchers like StrEq, StrCaseNe, and etc.
2871template <typename StringType>
2872class StrEqualityMatcher {
2873 public:
2874 StrEqualityMatcher(const StringType& str, bool expect_eq,
2875 bool case_sensitive)
2876 : string_(str), expect_eq_(expect_eq), case_sensitive_(case_sensitive) {}
2877
2878#if GTEST_HAS_ABSL
2879 bool MatchAndExplain(const absl::string_view& s,
2880 MatchResultListener* listener) const {
2881 // This should fail to compile if absl::string_view is used with wide
2882 // strings.
2883 const StringType& str = string(s);
2884 return MatchAndExplain(str, listener);
2885 }
2886#endif // GTEST_HAS_ABSL
2887
2888 // Accepts pointer types, particularly:
2889 // const char*
2890 // char*
2891 // const wchar_t*
2892 // wchar_t*
2893 template <typename CharType>
2894 bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
2895 if (s == nullptr) {
2896 return !expect_eq_;
2897 }
2898 return MatchAndExplain(StringType(s), listener);
2899 }
2900
2901 // Matches anything that can convert to StringType.
2902 //
2903 // This is a template, not just a plain function with const StringType&,
2904 // because absl::string_view has some interfering non-explicit constructors.
2905 template <typename MatcheeStringType>
2906 bool MatchAndExplain(const MatcheeStringType& s,
2907 MatchResultListener* /* listener */) const {
2908 const StringType& s2(s);
2909 const bool eq = case_sensitive_ ? s2 == string_ :
2910 CaseInsensitiveStringEquals(s2, string_);
2911 return expect_eq_ == eq;
2912 }
2913
2914 void DescribeTo(::std::ostream* os) const {
2915 DescribeToHelper(expect_eq_, os);
2916 }
2917
2918 void DescribeNegationTo(::std::ostream* os) const {
2919 DescribeToHelper(!expect_eq_, os);
2920 }
2921
2922 private:
2923 void DescribeToHelper(bool expect_eq, ::std::ostream* os) const {
2924 *os << (expect_eq ? "is " : "isn't ");
2925 *os << "equal to ";
2926 if (!case_sensitive_) {
2927 *os << "(ignoring case) ";
2928 }
2929 UniversalPrint(string_, os);
2930 }
2931
2932 const StringType string_;
2933 const bool expect_eq_;
2934 const bool case_sensitive_;
2935
2936 GTEST_DISALLOW_ASSIGN_(StrEqualityMatcher);
2937};
2938
2939// Implements the polymorphic HasSubstr(substring) matcher, which
2940// can be used as a Matcher<T> as long as T can be converted to a
2941// string.
2942template <typename StringType>
2943class HasSubstrMatcher {
2944 public:
2945 explicit HasSubstrMatcher(const StringType& substring)
2946 : substring_(substring) {}
2947
2948#if GTEST_HAS_ABSL
2949 bool MatchAndExplain(const absl::string_view& s,
2950 MatchResultListener* listener) const {
2951 // This should fail to compile if absl::string_view is used with wide
2952 // strings.
2953 const StringType& str = string(s);
2954 return MatchAndExplain(str, listener);
2955 }
2956#endif // GTEST_HAS_ABSL
2957
2958 // Accepts pointer types, particularly:
2959 // const char*
2960 // char*
2961 // const wchar_t*
2962 // wchar_t*
2963 template <typename CharType>
2964 bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
2965 return s != nullptr && MatchAndExplain(StringType(s), listener);
2966 }
2967
2968 // Matches anything that can convert to StringType.
2969 //
2970 // This is a template, not just a plain function with const StringType&,
2971 // because absl::string_view has some interfering non-explicit constructors.
2972 template <typename MatcheeStringType>
2973 bool MatchAndExplain(const MatcheeStringType& s,
2974 MatchResultListener* /* listener */) const {
2975 const StringType& s2(s);
2976 return s2.find(substring_) != StringType::npos;
2977 }
2978
2979 // Describes what this matcher matches.
2980 void DescribeTo(::std::ostream* os) const {
2981 *os << "has substring ";
2982 UniversalPrint(substring_, os);
2983 }
2984
2985 void DescribeNegationTo(::std::ostream* os) const {
2986 *os << "has no substring ";
2987 UniversalPrint(substring_, os);
2988 }
2989
2990 private:
2991 const StringType substring_;
2992
2993 GTEST_DISALLOW_ASSIGN_(HasSubstrMatcher);
2994};
2995
2996// Implements the polymorphic StartsWith(substring) matcher, which
2997// can be used as a Matcher<T> as long as T can be converted to a
2998// string.
2999template <typename StringType>
3000class StartsWithMatcher {
3001 public:
3002 explicit StartsWithMatcher(const StringType& prefix) : prefix_(prefix) {
3003 }
3004
3005#if GTEST_HAS_ABSL
3006 bool MatchAndExplain(const absl::string_view& s,
3007 MatchResultListener* listener) const {
3008 // This should fail to compile if absl::string_view is used with wide
3009 // strings.
3010 const StringType& str = string(s);
3011 return MatchAndExplain(str, listener);
3012 }
3013#endif // GTEST_HAS_ABSL
3014
3015 // Accepts pointer types, particularly:
3016 // const char*
3017 // char*
3018 // const wchar_t*
3019 // wchar_t*
3020 template <typename CharType>
3021 bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
3022 return s != nullptr && MatchAndExplain(StringType(s), listener);
3023 }
3024
3025 // Matches anything that can convert to StringType.
3026 //
3027 // This is a template, not just a plain function with const StringType&,
3028 // because absl::string_view has some interfering non-explicit constructors.
3029 template <typename MatcheeStringType>
3030 bool MatchAndExplain(const MatcheeStringType& s,
3031 MatchResultListener* /* listener */) const {
3032 const StringType& s2(s);
3033 return s2.length() >= prefix_.length() &&
3034 s2.substr(0, prefix_.length()) == prefix_;
3035 }
3036
3037 void DescribeTo(::std::ostream* os) const {
3038 *os << "starts with ";
3039 UniversalPrint(prefix_, os);
3040 }
3041
3042 void DescribeNegationTo(::std::ostream* os) const {
3043 *os << "doesn't start with ";
3044 UniversalPrint(prefix_, os);
3045 }
3046
3047 private:
3048 const StringType prefix_;
3049
3050 GTEST_DISALLOW_ASSIGN_(StartsWithMatcher);
3051};
3052
3053// Implements the polymorphic EndsWith(substring) matcher, which
3054// can be used as a Matcher<T> as long as T can be converted to a
3055// string.
3056template <typename StringType>
3057class EndsWithMatcher {
3058 public:
3059 explicit EndsWithMatcher(const StringType& suffix) : suffix_(suffix) {}
3060
3061#if GTEST_HAS_ABSL
3062 bool MatchAndExplain(const absl::string_view& s,
3063 MatchResultListener* listener) const {
3064 // This should fail to compile if absl::string_view is used with wide
3065 // strings.
3066 const StringType& str = string(s);
3067 return MatchAndExplain(str, listener);
3068 }
3069#endif // GTEST_HAS_ABSL
3070
3071 // Accepts pointer types, particularly:
3072 // const char*
3073 // char*
3074 // const wchar_t*
3075 // wchar_t*
3076 template <typename CharType>
3077 bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
3078 return s != nullptr && MatchAndExplain(StringType(s), listener);
3079 }
3080
3081 // Matches anything that can convert to StringType.
3082 //
3083 // This is a template, not just a plain function with const StringType&,
3084 // because absl::string_view has some interfering non-explicit constructors.
3085 template <typename MatcheeStringType>
3086 bool MatchAndExplain(const MatcheeStringType& s,
3087 MatchResultListener* /* listener */) const {
3088 const StringType& s2(s);
3089 return s2.length() >= suffix_.length() &&
3090 s2.substr(s2.length() - suffix_.length()) == suffix_;
3091 }
3092
3093 void DescribeTo(::std::ostream* os) const {
3094 *os << "ends with ";
3095 UniversalPrint(suffix_, os);
3096 }
3097
3098 void DescribeNegationTo(::std::ostream* os) const {
3099 *os << "doesn't end with ";
3100 UniversalPrint(suffix_, os);
3101 }
3102
3103 private:
3104 const StringType suffix_;
3105
3106 GTEST_DISALLOW_ASSIGN_(EndsWithMatcher);
3107};
3108
3109// Implements a matcher that compares the two fields of a 2-tuple
3110// using one of the ==, <=, <, etc, operators. The two fields being
3111// compared don't have to have the same type.
3112//
3113// The matcher defined here is polymorphic (for example, Eq() can be
3114// used to match a std::tuple<int, short>, a std::tuple<const long&, double>,
3115// etc). Therefore we use a template type conversion operator in the
3116// implementation.
3117template <typename D, typename Op>
3118class PairMatchBase {
3119 public:
3120 template <typename T1, typename T2>
3121 operator Matcher<::std::tuple<T1, T2>>() const {
3122 return Matcher<::std::tuple<T1, T2>>(new Impl<const ::std::tuple<T1, T2>&>);
3123 }
3124 template <typename T1, typename T2>
3125 operator Matcher<const ::std::tuple<T1, T2>&>() const {
3126 return MakeMatcher(new Impl<const ::std::tuple<T1, T2>&>);
3127 }
3128
3129 private:
3130 static ::std::ostream& GetDesc(::std::ostream& os) { // NOLINT
3131 return os << D::Desc();
3132 }
3133
3134 template <typename Tuple>
3135 class Impl : public MatcherInterface<Tuple> {
3136 public:
3137 bool MatchAndExplain(Tuple args,
3138 MatchResultListener* /* listener */) const override {
3139 return Op()(::std::get<0>(args), ::std::get<1>(args));
3140 }
3141 void DescribeTo(::std::ostream* os) const override {
3142 *os << "are " << GetDesc;
3143 }
3144 void DescribeNegationTo(::std::ostream* os) const override {
3145 *os << "aren't " << GetDesc;
3146 }
3147 };
3148};
3149
3150class Eq2Matcher : public PairMatchBase<Eq2Matcher, AnyEq> {
3151 public:
3152 static const char* Desc() { return "an equal pair"; }
3153};
3154class Ne2Matcher : public PairMatchBase<Ne2Matcher, AnyNe> {
3155 public:
3156 static const char* Desc() { return "an unequal pair"; }
3157};
3158class Lt2Matcher : public PairMatchBase<Lt2Matcher, AnyLt> {
3159 public:
3160 static const char* Desc() { return "a pair where the first < the second"; }
3161};
3162class Gt2Matcher : public PairMatchBase<Gt2Matcher, AnyGt> {
3163 public:
3164 static const char* Desc() { return "a pair where the first > the second"; }
3165};
3166class Le2Matcher : public PairMatchBase<Le2Matcher, AnyLe> {
3167 public:
3168 static const char* Desc() { return "a pair where the first <= the second"; }
3169};
3170class Ge2Matcher : public PairMatchBase<Ge2Matcher, AnyGe> {
3171 public:
3172 static const char* Desc() { return "a pair where the first >= the second"; }
3173};
3174
3175// Implements the Not(...) matcher for a particular argument type T.
3176// We do not nest it inside the NotMatcher class template, as that
3177// will prevent different instantiations of NotMatcher from sharing
3178// the same NotMatcherImpl<T> class.
3179template <typename T>
3180class NotMatcherImpl : public MatcherInterface<const T&> {
3181 public:
3182 explicit NotMatcherImpl(const Matcher<T>& matcher)
3183 : matcher_(matcher) {}
3184
3185 bool MatchAndExplain(const T& x,
3186 MatchResultListener* listener) const override {
3187 return !matcher_.MatchAndExplain(x, listener);
3188 }
3189
3190 void DescribeTo(::std::ostream* os) const override {
3191 matcher_.DescribeNegationTo(os);
3192 }
3193
3194 void DescribeNegationTo(::std::ostream* os) const override {
3195 matcher_.DescribeTo(os);
3196 }
3197
3198 private:
3199 const Matcher<T> matcher_;
3200
3201 GTEST_DISALLOW_ASSIGN_(NotMatcherImpl);
3202};
3203
3204// Implements the Not(m) matcher, which matches a value that doesn't
3205// match matcher m.
3206template <typename InnerMatcher>
3207class NotMatcher {
3208 public:
3209 explicit NotMatcher(InnerMatcher matcher) : matcher_(matcher) {}
3210
3211 // This template type conversion operator allows Not(m) to be used
3212 // to match any type m can match.
3213 template <typename T>
3214 operator Matcher<T>() const {
3215 return Matcher<T>(new NotMatcherImpl<T>(SafeMatcherCast<T>(matcher_)));
3216 }
3217
3218 private:
3219 InnerMatcher matcher_;
3220
3221 GTEST_DISALLOW_ASSIGN_(NotMatcher);
3222};
3223
3224// Implements the AllOf(m1, m2) matcher for a particular argument type
3225// T. We do not nest it inside the BothOfMatcher class template, as
3226// that will prevent different instantiations of BothOfMatcher from
3227// sharing the same BothOfMatcherImpl<T> class.
3228template <typename T>
3229class AllOfMatcherImpl : public MatcherInterface<const T&> {
3230 public:
3231 explicit AllOfMatcherImpl(std::vector<Matcher<T> > matchers)
3232 : matchers_(std::move(matchers)) {}
3233
3234 void DescribeTo(::std::ostream* os) const override {
3235 *os << "(";
3236 for (size_t i = 0; i < matchers_.size(); ++i) {
3237 if (i != 0) *os << ") and (";
3238 matchers_[i].DescribeTo(os);
3239 }
3240 *os << ")";
3241 }
3242
3243 void DescribeNegationTo(::std::ostream* os) const override {
3244 *os << "(";
3245 for (size_t i = 0; i < matchers_.size(); ++i) {
3246 if (i != 0) *os << ") or (";
3247 matchers_[i].DescribeNegationTo(os);
3248 }
3249 *os << ")";
3250 }
3251
3252 bool MatchAndExplain(const T& x,
3253 MatchResultListener* listener) const override {
3254 // If either matcher1_ or matcher2_ doesn't match x, we only need
3255 // to explain why one of them fails.
3256 std::string all_match_result;
3257
3258 for (size_t i = 0; i < matchers_.size(); ++i) {
3259 StringMatchResultListener slistener;
3260 if (matchers_[i].MatchAndExplain(x, &slistener)) {
3261 if (all_match_result.empty()) {
3262 all_match_result = slistener.str();
3263 } else {
3264 std::string result = slistener.str();
3265 if (!result.empty()) {
3266 all_match_result += ", and ";
3267 all_match_result += result;
3268 }
3269 }
3270 } else {
3271 *listener << slistener.str();
3272 return false;
3273 }
3274 }
3275
3276 // Otherwise we need to explain why *both* of them match.
3277 *listener << all_match_result;
3278 return true;
3279 }
3280
3281 private:
3282 const std::vector<Matcher<T> > matchers_;
3283
3284 GTEST_DISALLOW_ASSIGN_(AllOfMatcherImpl);
3285};
3286
3287// VariadicMatcher is used for the variadic implementation of
3288// AllOf(m_1, m_2, ...) and AnyOf(m_1, m_2, ...).
3289// CombiningMatcher<T> is used to recursively combine the provided matchers
3290// (of type Args...).
3291template <template <typename T> class CombiningMatcher, typename... Args>
3292class VariadicMatcher {
3293 public:
3294 VariadicMatcher(const Args&... matchers) // NOLINT
3295 : matchers_(matchers...) {
3296 static_assert(sizeof...(Args) > 0, "Must have at least one matcher.");
3297 }
3298
3299 // This template type conversion operator allows an
3300 // VariadicMatcher<Matcher1, Matcher2...> object to match any type that
3301 // all of the provided matchers (Matcher1, Matcher2, ...) can match.
3302 template <typename T>
3303 operator Matcher<T>() const {
3304 std::vector<Matcher<T> > values;
3305 CreateVariadicMatcher<T>(&values, std::integral_constant<size_t, 0>());
3306 return Matcher<T>(new CombiningMatcher<T>(std::move(values)));
3307 }
3308
3309 private:
3310 template <typename T, size_t I>
3311 void CreateVariadicMatcher(std::vector<Matcher<T> >* values,
3312 std::integral_constant<size_t, I>) const {
3313 values->push_back(SafeMatcherCast<T>(std::get<I>(matchers_)));
3314 CreateVariadicMatcher<T>(values, std::integral_constant<size_t, I + 1>());
3315 }
3316
3317 template <typename T>
3318 void CreateVariadicMatcher(
3319 std::vector<Matcher<T> >*,
3320 std::integral_constant<size_t, sizeof...(Args)>) const {}
3321
3322 std::tuple<Args...> matchers_;
3323
3324 GTEST_DISALLOW_ASSIGN_(VariadicMatcher);
3325};
3326
3327template <typename... Args>
3328using AllOfMatcher = VariadicMatcher<AllOfMatcherImpl, Args...>;
3329
3330// Implements the AnyOf(m1, m2) matcher for a particular argument type
3331// T. We do not nest it inside the AnyOfMatcher class template, as
3332// that will prevent different instantiations of AnyOfMatcher from
3333// sharing the same EitherOfMatcherImpl<T> class.
3334template <typename T>
3335class AnyOfMatcherImpl : public MatcherInterface<const T&> {
3336 public:
3337 explicit AnyOfMatcherImpl(std::vector<Matcher<T> > matchers)
3338 : matchers_(std::move(matchers)) {}
3339
3340 void DescribeTo(::std::ostream* os) const override {
3341 *os << "(";
3342 for (size_t i = 0; i < matchers_.size(); ++i) {
3343 if (i != 0) *os << ") or (";
3344 matchers_[i].DescribeTo(os);
3345 }
3346 *os << ")";
3347 }
3348
3349 void DescribeNegationTo(::std::ostream* os) const override {
3350 *os << "(";
3351 for (size_t i = 0; i < matchers_.size(); ++i) {
3352 if (i != 0) *os << ") and (";
3353 matchers_[i].DescribeNegationTo(os);
3354 }
3355 *os << ")";
3356 }
3357
3358 bool MatchAndExplain(const T& x,
3359 MatchResultListener* listener) const override {
3360 std::string no_match_result;
3361
3362 // If either matcher1_ or matcher2_ matches x, we just need to
3363 // explain why *one* of them matches.
3364 for (size_t i = 0; i < matchers_.size(); ++i) {
3365 StringMatchResultListener slistener;
3366 if (matchers_[i].MatchAndExplain(x, &slistener)) {
3367 *listener << slistener.str();
3368 return true;
3369 } else {
3370 if (no_match_result.empty()) {
3371 no_match_result = slistener.str();
3372 } else {
3373 std::string result = slistener.str();
3374 if (!result.empty()) {
3375 no_match_result += ", and ";
3376 no_match_result += result;
3377 }
3378 }
3379 }
3380 }
3381
3382 // Otherwise we need to explain why *both* of them fail.
3383 *listener << no_match_result;
3384 return false;
3385 }
3386
3387 private:
3388 const std::vector<Matcher<T> > matchers_;
3389
3390 GTEST_DISALLOW_ASSIGN_(AnyOfMatcherImpl);
3391};
3392
3393// AnyOfMatcher is used for the variadic implementation of AnyOf(m_1, m_2, ...).
3394template <typename... Args>
3395using AnyOfMatcher = VariadicMatcher<AnyOfMatcherImpl, Args...>;
3396
3397// Wrapper for implementation of Any/AllOfArray().
3398template <template <class> class MatcherImpl, typename T>
3399class SomeOfArrayMatcher {
3400 public:
3401 // Constructs the matcher from a sequence of element values or
3402 // element matchers.
3403 template <typename Iter>
3404 SomeOfArrayMatcher(Iter first, Iter last) : matchers_(first, last) {}
3405
3406 template <typename U>
3407 operator Matcher<U>() const { // NOLINT
3408 using RawU = typename std::decay<U>::type;
3409 std::vector<Matcher<RawU>> matchers;
3410 for (const auto& matcher : matchers_) {
3411 matchers.push_back(MatcherCast<RawU>(matcher));
3412 }
3413 return Matcher<U>(new MatcherImpl<RawU>(std::move(matchers)));
3414 }
3415
3416 private:
3417 const ::std::vector<T> matchers_;
3418
3419 GTEST_DISALLOW_ASSIGN_(SomeOfArrayMatcher);
3420};
3421
3422template <typename T>
3423using AllOfArrayMatcher = SomeOfArrayMatcher<AllOfMatcherImpl, T>;
3424
3425template <typename T>
3426using AnyOfArrayMatcher = SomeOfArrayMatcher<AnyOfMatcherImpl, T>;
3427
3428// Used for implementing Truly(pred), which turns a predicate into a
3429// matcher.
3430template <typename Predicate>
3431class TrulyMatcher {
3432 public:
3433 explicit TrulyMatcher(Predicate pred) : predicate_(pred) {}
3434
3435 // This method template allows Truly(pred) to be used as a matcher
3436 // for type T where T is the argument type of predicate 'pred'. The
3437 // argument is passed by reference as the predicate may be
3438 // interested in the address of the argument.
3439 template <typename T>
3440 bool MatchAndExplain(T& x, // NOLINT
3441 MatchResultListener* /* listener */) const {
3442 // Without the if-statement, MSVC sometimes warns about converting
3443 // a value to bool (warning 4800).
3444 //
3445 // We cannot write 'return !!predicate_(x);' as that doesn't work
3446 // when predicate_(x) returns a class convertible to bool but
3447 // having no operator!().
3448 if (predicate_(x))
3449 return true;
3450 return false;
3451 }
3452
3453 void DescribeTo(::std::ostream* os) const {
3454 *os << "satisfies the given predicate";
3455 }
3456
3457 void DescribeNegationTo(::std::ostream* os) const {
3458 *os << "doesn't satisfy the given predicate";
3459 }
3460
3461 private:
3462 Predicate predicate_;
3463
3464 GTEST_DISALLOW_ASSIGN_(TrulyMatcher);
3465};
3466
3467// Used for implementing Matches(matcher), which turns a matcher into
3468// a predicate.
3469template <typename M>
3470class MatcherAsPredicate {
3471 public:
3472 explicit MatcherAsPredicate(M matcher) : matcher_(matcher) {}
3473
3474 // This template operator() allows Matches(m) to be used as a
3475 // predicate on type T where m is a matcher on type T.
3476 //
3477 // The argument x is passed by reference instead of by value, as
3478 // some matcher may be interested in its address (e.g. as in
3479 // Matches(Ref(n))(x)).
3480 template <typename T>
3481 bool operator()(const T& x) const {
3482 // We let matcher_ commit to a particular type here instead of
3483 // when the MatcherAsPredicate object was constructed. This
3484 // allows us to write Matches(m) where m is a polymorphic matcher
3485 // (e.g. Eq(5)).
3486 //
3487 // If we write Matcher<T>(matcher_).Matches(x) here, it won't
3488 // compile when matcher_ has type Matcher<const T&>; if we write
3489 // Matcher<const T&>(matcher_).Matches(x) here, it won't compile
3490 // when matcher_ has type Matcher<T>; if we just write
3491 // matcher_.Matches(x), it won't compile when matcher_ is
3492 // polymorphic, e.g. Eq(5).
3493 //
3494 // MatcherCast<const T&>() is necessary for making the code work
3495 // in all of the above situations.
3496 return MatcherCast<const T&>(matcher_).Matches(x);
3497 }
3498
3499 private:
3500 M matcher_;
3501
3502 GTEST_DISALLOW_ASSIGN_(MatcherAsPredicate);
3503};
3504
3505// For implementing ASSERT_THAT() and EXPECT_THAT(). The template
3506// argument M must be a type that can be converted to a matcher.
3507template <typename M>
3508class PredicateFormatterFromMatcher {
3509 public:
3510 explicit PredicateFormatterFromMatcher(M m) : matcher_(std::move(m)) {}
3511
3512 // This template () operator allows a PredicateFormatterFromMatcher
3513 // object to act as a predicate-formatter suitable for using with
3514 // Google Test's EXPECT_PRED_FORMAT1() macro.
3515 template <typename T>
3516 AssertionResult operator()(const char* value_text, const T& x) const {
3517 // We convert matcher_ to a Matcher<const T&> *now* instead of
3518 // when the PredicateFormatterFromMatcher object was constructed,
3519 // as matcher_ may be polymorphic (e.g. NotNull()) and we won't
3520 // know which type to instantiate it to until we actually see the
3521 // type of x here.
3522 //
3523 // We write SafeMatcherCast<const T&>(matcher_) instead of
3524 // Matcher<const T&>(matcher_), as the latter won't compile when
3525 // matcher_ has type Matcher<T> (e.g. An<int>()).
3526 // We don't write MatcherCast<const T&> either, as that allows
3527 // potentially unsafe downcasting of the matcher argument.
3528 const Matcher<const T&> matcher = SafeMatcherCast<const T&>(matcher_);
3529
3530 // The expected path here is that the matcher should match (i.e. that most
3531 // tests pass) so optimize for this case.
3532 if (matcher.Matches(x)) {
3533 return AssertionSuccess();
3534 }
3535
3536 ::std::stringstream ss;
3537 ss << "Value of: " << value_text << "\n"
3538 << "Expected: ";
3539 matcher.DescribeTo(&ss);
3540
3541 // Rerun the matcher to "PrintAndExain" the failure.
3542 StringMatchResultListener listener;
3543 if (MatchPrintAndExplain(x, matcher, &listener)) {
3544 ss << "\n The matcher failed on the initial attempt; but passed when "
3545 "rerun to generate the explanation.";
3546 }
3547 ss << "\n Actual: " << listener.str();
3548 return AssertionFailure() << ss.str();
3549 }
3550
3551 private:
3552 const M matcher_;
3553
3554 GTEST_DISALLOW_ASSIGN_(PredicateFormatterFromMatcher);
3555};
3556
3557// A helper function for converting a matcher to a predicate-formatter
3558// without the user needing to explicitly write the type. This is
3559// used for implementing ASSERT_THAT() and EXPECT_THAT().
3560// Implementation detail: 'matcher' is received by-value to force decaying.
3561template <typename M>
3562inline PredicateFormatterFromMatcher<M>
3563MakePredicateFormatterFromMatcher(M matcher) {
3564 return PredicateFormatterFromMatcher<M>(std::move(matcher));
3565}
3566
3567// Implements the polymorphic floating point equality matcher, which matches
3568// two float values using ULP-based approximation or, optionally, a
3569// user-specified epsilon. The template is meant to be instantiated with
3570// FloatType being either float or double.
3571template <typename FloatType>
3572class FloatingEqMatcher {
3573 public:
3574 // Constructor for FloatingEqMatcher.
3575 // The matcher's input will be compared with expected. The matcher treats two
3576 // NANs as equal if nan_eq_nan is true. Otherwise, under IEEE standards,
3577 // equality comparisons between NANs will always return false. We specify a
3578 // negative max_abs_error_ term to indicate that ULP-based approximation will
3579 // be used for comparison.
3580 FloatingEqMatcher(FloatType expected, bool nan_eq_nan) :
3581 expected_(expected), nan_eq_nan_(nan_eq_nan), max_abs_error_(-1) {
3582 }
3583
3584 // Constructor that supports a user-specified max_abs_error that will be used
3585 // for comparison instead of ULP-based approximation. The max absolute
3586 // should be non-negative.
3587 FloatingEqMatcher(FloatType expected, bool nan_eq_nan,
3588 FloatType max_abs_error)
3589 : expected_(expected),
3590 nan_eq_nan_(nan_eq_nan),
3591 max_abs_error_(max_abs_error) {
3592 GTEST_CHECK_(max_abs_error >= 0)
3593 << ", where max_abs_error is" << max_abs_error;
3594 }
3595
3596 // Implements floating point equality matcher as a Matcher<T>.
3597 template <typename T>
3598 class Impl : public MatcherInterface<T> {
3599 public:
3600 Impl(FloatType expected, bool nan_eq_nan, FloatType max_abs_error)
3601 : expected_(expected),
3602 nan_eq_nan_(nan_eq_nan),
3603 max_abs_error_(max_abs_error) {}
3604
3605 bool MatchAndExplain(T value,
3606 MatchResultListener* listener) const override {
3607 const FloatingPoint<FloatType> actual(value), expected(expected_);
3608
3609 // Compares NaNs first, if nan_eq_nan_ is true.
3610 if (actual.is_nan() || expected.is_nan()) {
3611 if (actual.is_nan() && expected.is_nan()) {
3612 return nan_eq_nan_;
3613 }
3614 // One is nan; the other is not nan.
3615 return false;
3616 }
3617 if (HasMaxAbsError()) {
3618 // We perform an equality check so that inf will match inf, regardless
3619 // of error bounds. If the result of value - expected_ would result in
3620 // overflow or if either value is inf, the default result is infinity,
3621 // which should only match if max_abs_error_ is also infinity.
3622 if (value == expected_) {
3623 return true;
3624 }
3625
3626 const FloatType diff = value - expected_;
3627 if (fabs(diff) <= max_abs_error_) {
3628 return true;
3629 }
3630
3631 if (listener->IsInterested()) {
3632 *listener << "which is " << diff << " from " << expected_;
3633 }
3634 return false;
3635 } else {
3636 return actual.AlmostEquals(expected);
3637 }
3638 }
3639
3640 void DescribeTo(::std::ostream* os) const override {
3641 // os->precision() returns the previously set precision, which we
3642 // store to restore the ostream to its original configuration
3643 // after outputting.
3644 const ::std::streamsize old_precision = os->precision(
3645 ::std::numeric_limits<FloatType>::digits10 + 2);
3646 if (FloatingPoint<FloatType>(expected_).is_nan()) {
3647 if (nan_eq_nan_) {
3648 *os << "is NaN";
3649 } else {
3650 *os << "never matches";
3651 }
3652 } else {
3653 *os << "is approximately " << expected_;
3654 if (HasMaxAbsError()) {
3655 *os << " (absolute error <= " << max_abs_error_ << ")";
3656 }
3657 }
3658 os->precision(old_precision);
3659 }
3660
3661 void DescribeNegationTo(::std::ostream* os) const override {
3662 // As before, get original precision.
3663 const ::std::streamsize old_precision = os->precision(
3664 ::std::numeric_limits<FloatType>::digits10 + 2);
3665 if (FloatingPoint<FloatType>(expected_).is_nan()) {
3666 if (nan_eq_nan_) {
3667 *os << "isn't NaN";
3668 } else {
3669 *os << "is anything";
3670 }
3671 } else {
3672 *os << "isn't approximately " << expected_;
3673 if (HasMaxAbsError()) {
3674 *os << " (absolute error > " << max_abs_error_ << ")";
3675 }
3676 }
3677 // Restore original precision.
3678 os->precision(old_precision);
3679 }
3680
3681 private:
3682 bool HasMaxAbsError() const {
3683 return max_abs_error_ >= 0;
3684 }
3685
3686 const FloatType expected_;
3687 const bool nan_eq_nan_;
3688 // max_abs_error will be used for value comparison when >= 0.
3689 const FloatType max_abs_error_;
3690
3691 GTEST_DISALLOW_ASSIGN_(Impl);
3692 };
3693
3694 // The following 3 type conversion operators allow FloatEq(expected) and
3695 // NanSensitiveFloatEq(expected) to be used as a Matcher<float>, a
3696 // Matcher<const float&>, or a Matcher<float&>, but nothing else.
3697 // (While Google's C++ coding style doesn't allow arguments passed
3698 // by non-const reference, we may see them in code not conforming to
3699 // the style. Therefore Google Mock needs to support them.)
3700 operator Matcher<FloatType>() const {
3701 return MakeMatcher(
3702 new Impl<FloatType>(expected_, nan_eq_nan_, max_abs_error_));
3703 }
3704
3705 operator Matcher<const FloatType&>() const {
3706 return MakeMatcher(
3707 new Impl<const FloatType&>(expected_, nan_eq_nan_, max_abs_error_));
3708 }
3709
3710 operator Matcher<FloatType&>() const {
3711 return MakeMatcher(
3712 new Impl<FloatType&>(expected_, nan_eq_nan_, max_abs_error_));
3713 }
3714
3715 private:
3716 const FloatType expected_;
3717 const bool nan_eq_nan_;
3718 // max_abs_error will be used for value comparison when >= 0.
3719 const FloatType max_abs_error_;
3720
3721 GTEST_DISALLOW_ASSIGN_(FloatingEqMatcher);
3722};
3723
3724// A 2-tuple ("binary") wrapper around FloatingEqMatcher:
3725// FloatingEq2Matcher() matches (x, y) by matching FloatingEqMatcher(x, false)
3726// against y, and FloatingEq2Matcher(e) matches FloatingEqMatcher(x, false, e)
3727// against y. The former implements "Eq", the latter "Near". At present, there
3728// is no version that compares NaNs as equal.
3729template <typename FloatType>
3730class FloatingEq2Matcher {
3731 public:
3732 FloatingEq2Matcher() { Init(-1, false); }
3733
3734 explicit FloatingEq2Matcher(bool nan_eq_nan) { Init(-1, nan_eq_nan); }
3735
3736 explicit FloatingEq2Matcher(FloatType max_abs_error) {
3737 Init(max_abs_error, false);
3738 }
3739
3740 FloatingEq2Matcher(FloatType max_abs_error, bool nan_eq_nan) {
3741 Init(max_abs_error, nan_eq_nan);
3742 }
3743
3744 template <typename T1, typename T2>
3745 operator Matcher<::std::tuple<T1, T2>>() const {
3746 return MakeMatcher(
3747 new Impl<::std::tuple<T1, T2>>(max_abs_error_, nan_eq_nan_));
3748 }
3749 template <typename T1, typename T2>
3750 operator Matcher<const ::std::tuple<T1, T2>&>() const {
3751 return MakeMatcher(
3752 new Impl<const ::std::tuple<T1, T2>&>(max_abs_error_, nan_eq_nan_));
3753 }
3754
3755 private:
3756 static ::std::ostream& GetDesc(::std::ostream& os) { // NOLINT
3757 return os << "an almost-equal pair";
3758 }
3759
3760 template <typename Tuple>
3761 class Impl : public MatcherInterface<Tuple> {
3762 public:
3763 Impl(FloatType max_abs_error, bool nan_eq_nan) :
3764 max_abs_error_(max_abs_error),
3765 nan_eq_nan_(nan_eq_nan) {}
3766
3767 bool MatchAndExplain(Tuple args,
3768 MatchResultListener* listener) const override {
3769 if (max_abs_error_ == -1) {
3770 FloatingEqMatcher<FloatType> fm(::std::get<0>(args), nan_eq_nan_);
3771 return static_cast<Matcher<FloatType>>(fm).MatchAndExplain(
3772 ::std::get<1>(args), listener);
3773 } else {
3774 FloatingEqMatcher<FloatType> fm(::std::get<0>(args), nan_eq_nan_,
3775 max_abs_error_);
3776 return static_cast<Matcher<FloatType>>(fm).MatchAndExplain(
3777 ::std::get<1>(args), listener);
3778 }
3779 }
3780 void DescribeTo(::std::ostream* os) const override {
3781 *os << "are " << GetDesc;
3782 }
3783 void DescribeNegationTo(::std::ostream* os) const override {
3784 *os << "aren't " << GetDesc;
3785 }
3786
3787 private:
3788 FloatType max_abs_error_;
3789 const bool nan_eq_nan_;
3790 };
3791
3792 void Init(FloatType max_abs_error_val, bool nan_eq_nan_val) {
3793 max_abs_error_ = max_abs_error_val;
3794 nan_eq_nan_ = nan_eq_nan_val;
3795 }
3796 FloatType max_abs_error_;
3797 bool nan_eq_nan_;
3798};
3799
3800// Implements the Pointee(m) matcher for matching a pointer whose
3801// pointee matches matcher m. The pointer can be either raw or smart.
3802template <typename InnerMatcher>
3803class PointeeMatcher {
3804 public:
3805 explicit PointeeMatcher(const InnerMatcher& matcher) : matcher_(matcher) {}
3806
3807 // This type conversion operator template allows Pointee(m) to be
3808 // used as a matcher for any pointer type whose pointee type is
3809 // compatible with the inner matcher, where type Pointer can be
3810 // either a raw pointer or a smart pointer.
3811 //
3812 // The reason we do this instead of relying on
3813 // MakePolymorphicMatcher() is that the latter is not flexible
3814 // enough for implementing the DescribeTo() method of Pointee().
3815 template <typename Pointer>
3816 operator Matcher<Pointer>() const {
3817 return Matcher<Pointer>(new Impl<const Pointer&>(matcher_));
3818 }
3819
3820 private:
3821 // The monomorphic implementation that works for a particular pointer type.
3822 template <typename Pointer>
3823 class Impl : public MatcherInterface<Pointer> {
3824 public:
3825 typedef typename PointeeOf<GTEST_REMOVE_CONST_( // NOLINT
3826 GTEST_REMOVE_REFERENCE_(Pointer))>::type Pointee;
3827
3828 explicit Impl(const InnerMatcher& matcher)
3829 : matcher_(MatcherCast<const Pointee&>(matcher)) {}
3830
3831 void DescribeTo(::std::ostream* os) const override {
3832 *os << "points to a value that ";
3833 matcher_.DescribeTo(os);
3834 }
3835
3836 void DescribeNegationTo(::std::ostream* os) const override {
3837 *os << "does not point to a value that ";
3838 matcher_.DescribeTo(os);
3839 }
3840
3841 bool MatchAndExplain(Pointer pointer,
3842 MatchResultListener* listener) const override {
3843 if (GetRawPointer(pointer) == nullptr) return false;
3844
3845 *listener << "which points to ";
3846 return MatchPrintAndExplain(*pointer, matcher_, listener);
3847 }
3848
3849 private:
3850 const Matcher<const Pointee&> matcher_;
3851
3852 GTEST_DISALLOW_ASSIGN_(Impl);
3853 };
3854
3855 const InnerMatcher matcher_;
3856
3857 GTEST_DISALLOW_ASSIGN_(PointeeMatcher);
3858};
3859
3860#if GTEST_HAS_RTTI
3861// Implements the WhenDynamicCastTo<T>(m) matcher that matches a pointer or
3862// reference that matches inner_matcher when dynamic_cast<T> is applied.
3863// The result of dynamic_cast<To> is forwarded to the inner matcher.
3864// If To is a pointer and the cast fails, the inner matcher will receive NULL.
3865// If To is a reference and the cast fails, this matcher returns false
3866// immediately.
3867template <typename To>
3868class WhenDynamicCastToMatcherBase {
3869 public:
3870 explicit WhenDynamicCastToMatcherBase(const Matcher<To>& matcher)
3871 : matcher_(matcher) {}
3872
3873 void DescribeTo(::std::ostream* os) const {
3874 GetCastTypeDescription(os);
3875 matcher_.DescribeTo(os);
3876 }
3877
3878 void DescribeNegationTo(::std::ostream* os) const {
3879 GetCastTypeDescription(os);
3880 matcher_.DescribeNegationTo(os);
3881 }
3882
3883 protected:
3884 const Matcher<To> matcher_;
3885
3886 static std::string GetToName() {
3887 return GetTypeName<To>();
3888 }
3889
3890 private:
3891 static void GetCastTypeDescription(::std::ostream* os) {
3892 *os << "when dynamic_cast to " << GetToName() << ", ";
3893 }
3894
3895 GTEST_DISALLOW_ASSIGN_(WhenDynamicCastToMatcherBase);
3896};
3897
3898// Primary template.
3899// To is a pointer. Cast and forward the result.
3900template <typename To>
3901class WhenDynamicCastToMatcher : public WhenDynamicCastToMatcherBase<To> {
3902 public:
3903 explicit WhenDynamicCastToMatcher(const Matcher<To>& matcher)
3904 : WhenDynamicCastToMatcherBase<To>(matcher) {}
3905
3906 template <typename From>
3907 bool MatchAndExplain(From from, MatchResultListener* listener) const {
3908 To to = dynamic_cast<To>(from);
3909 return MatchPrintAndExplain(to, this->matcher_, listener);
3910 }
3911};
3912
3913// Specialize for references.
3914// In this case we return false if the dynamic_cast fails.
3915template <typename To>
3916class WhenDynamicCastToMatcher<To&> : public WhenDynamicCastToMatcherBase<To&> {
3917 public:
3918 explicit WhenDynamicCastToMatcher(const Matcher<To&>& matcher)
3919 : WhenDynamicCastToMatcherBase<To&>(matcher) {}
3920
3921 template <typename From>
3922 bool MatchAndExplain(From& from, MatchResultListener* listener) const {
3923 // We don't want an std::bad_cast here, so do the cast with pointers.
3924 To* to = dynamic_cast<To*>(&from);
3925 if (to == nullptr) {
3926 *listener << "which cannot be dynamic_cast to " << this->GetToName();
3927 return false;
3928 }
3929 return MatchPrintAndExplain(*to, this->matcher_, listener);
3930 }
3931};
3932#endif // GTEST_HAS_RTTI
3933
3934// Implements the Field() matcher for matching a field (i.e. member
3935// variable) of an object.
3936template <typename Class, typename FieldType>
3937class FieldMatcher {
3938 public:
3939 FieldMatcher(FieldType Class::*field,
3940 const Matcher<const FieldType&>& matcher)
3941 : field_(field), matcher_(matcher), whose_field_("whose given field ") {}
3942
3943 FieldMatcher(const std::string& field_name, FieldType Class::*field,
3944 const Matcher<const FieldType&>& matcher)
3945 : field_(field),
3946 matcher_(matcher),
3947 whose_field_("whose field `" + field_name + "` ") {}
3948
3949 void DescribeTo(::std::ostream* os) const {
3950 *os << "is an object " << whose_field_;
3951 matcher_.DescribeTo(os);
3952 }
3953
3954 void DescribeNegationTo(::std::ostream* os) const {
3955 *os << "is an object " << whose_field_;
3956 matcher_.DescribeNegationTo(os);
3957 }
3958
3959 template <typename T>
3960 bool MatchAndExplain(const T& value, MatchResultListener* listener) const {
3961 // FIXME: The dispatch on std::is_pointer was introduced as a workaround for
3962 // a compiler bug, and can now be removed.
3963 return MatchAndExplainImpl(
3964 typename std::is_pointer<GTEST_REMOVE_CONST_(T)>::type(), value,
3965 listener);
3966 }
3967
3968 private:
3969 bool MatchAndExplainImpl(std::false_type /* is_not_pointer */,
3970 const Class& obj,
3971 MatchResultListener* listener) const {
3972 *listener << whose_field_ << "is ";
3973 return MatchPrintAndExplain(obj.*field_, matcher_, listener);
3974 }
3975
3976 bool MatchAndExplainImpl(std::true_type /* is_pointer */, const Class* p,
3977 MatchResultListener* listener) const {
3978 if (p == nullptr) return false;
3979
3980 *listener << "which points to an object ";
3981 // Since *p has a field, it must be a class/struct/union type and
3982 // thus cannot be a pointer. Therefore we pass false_type() as
3983 // the first argument.
3984 return MatchAndExplainImpl(std::false_type(), *p, listener);
3985 }
3986
3987 const FieldType Class::*field_;
3988 const Matcher<const FieldType&> matcher_;
3989
3990 // Contains either "whose given field " if the name of the field is unknown
3991 // or "whose field `name_of_field` " if the name is known.
3992 const std::string whose_field_;
3993
3994 GTEST_DISALLOW_ASSIGN_(FieldMatcher);
3995};
3996
3997// Implements the Property() matcher for matching a property
3998// (i.e. return value of a getter method) of an object.
3999//
4000// Property is a const-qualified member function of Class returning
4001// PropertyType.
4002template <typename Class, typename PropertyType, typename Property>
4003class PropertyMatcher {
4004 public:
4005 typedef const PropertyType& RefToConstProperty;
4006
4007 PropertyMatcher(Property property, const Matcher<RefToConstProperty>& matcher)
4008 : property_(property),
4009 matcher_(matcher),
4010 whose_property_("whose given property ") {}
4011
4012 PropertyMatcher(const std::string& property_name, Property property,
4013 const Matcher<RefToConstProperty>& matcher)
4014 : property_(property),
4015 matcher_(matcher),
4016 whose_property_("whose property `" + property_name + "` ") {}
4017
4018 void DescribeTo(::std::ostream* os) const {
4019 *os << "is an object " << whose_property_;
4020 matcher_.DescribeTo(os);
4021 }
4022
4023 void DescribeNegationTo(::std::ostream* os) const {
4024 *os << "is an object " << whose_property_;
4025 matcher_.DescribeNegationTo(os);
4026 }
4027
4028 template <typename T>
4029 bool MatchAndExplain(const T&value, MatchResultListener* listener) const {
4030 return MatchAndExplainImpl(
4031 typename std::is_pointer<GTEST_REMOVE_CONST_(T)>::type(), value,
4032 listener);
4033 }
4034
4035 private:
4036 bool MatchAndExplainImpl(std::false_type /* is_not_pointer */,
4037 const Class& obj,
4038 MatchResultListener* listener) const {
4039 *listener << whose_property_ << "is ";
4040 // Cannot pass the return value (for example, int) to MatchPrintAndExplain,
4041 // which takes a non-const reference as argument.
4042 RefToConstProperty result = (obj.*property_)();
4043 return MatchPrintAndExplain(result, matcher_, listener);
4044 }
4045
4046 bool MatchAndExplainImpl(std::true_type /* is_pointer */, const Class* p,
4047 MatchResultListener* listener) const {
4048 if (p == nullptr) return false;
4049
4050 *listener << "which points to an object ";
4051 // Since *p has a property method, it must be a class/struct/union
4052 // type and thus cannot be a pointer. Therefore we pass
4053 // false_type() as the first argument.
4054 return MatchAndExplainImpl(std::false_type(), *p, listener);
4055 }
4056
4057 Property property_;
4058 const Matcher<RefToConstProperty> matcher_;
4059
4060 // Contains either "whose given property " if the name of the property is
4061 // unknown or "whose property `name_of_property` " if the name is known.
4062 const std::string whose_property_;
4063
4064 GTEST_DISALLOW_ASSIGN_(PropertyMatcher);
4065};
4066
4067// Type traits specifying various features of different functors for ResultOf.
4068// The default template specifies features for functor objects.
4069template <typename Functor>
4070struct CallableTraits {
4071 typedef Functor StorageType;
4072
4073 static void CheckIsValid(Functor /* functor */) {}
4074
4075 template <typename T>
4076 static auto Invoke(Functor f, T arg) -> decltype(f(arg)) { return f(arg); }
4077};
4078
4079// Specialization for function pointers.
4080template <typename ArgType, typename ResType>
4081struct CallableTraits<ResType(*)(ArgType)> {
4082 typedef ResType ResultType;
4083 typedef ResType(*StorageType)(ArgType);
4084
4085 static void CheckIsValid(ResType(*f)(ArgType)) {
4086 GTEST_CHECK_(f != nullptr)
4087 << "NULL function pointer is passed into ResultOf().";
4088 }
4089 template <typename T>
4090 static ResType Invoke(ResType(*f)(ArgType), T arg) {
4091 return (*f)(arg);
4092 }
4093};
4094
4095// Implements the ResultOf() matcher for matching a return value of a
4096// unary function of an object.
4097template <typename Callable, typename InnerMatcher>
4098class ResultOfMatcher {
4099 public:
4100 ResultOfMatcher(Callable callable, InnerMatcher matcher)
4101 : callable_(std::move(callable)), matcher_(std::move(matcher)) {
4102 CallableTraits<Callable>::CheckIsValid(callable_);
4103 }
4104
4105 template <typename T>
4106 operator Matcher<T>() const {
4107 return Matcher<T>(new Impl<T>(callable_, matcher_));
4108 }
4109
4110 private:
4111 typedef typename CallableTraits<Callable>::StorageType CallableStorageType;
4112
4113 template <typename T>
4114 class Impl : public MatcherInterface<T> {
4115 using ResultType = decltype(CallableTraits<Callable>::template Invoke<T>(
4116 std::declval<CallableStorageType>(), std::declval<T>()));
4117
4118 public:
4119 template <typename M>
4120 Impl(const CallableStorageType& callable, const M& matcher)
4121 : callable_(callable), matcher_(MatcherCast<ResultType>(matcher)) {}
4122
4123 void DescribeTo(::std::ostream* os) const override {
4124 *os << "is mapped by the given callable to a value that ";
4125 matcher_.DescribeTo(os);
4126 }
4127
4128 void DescribeNegationTo(::std::ostream* os) const override {
4129 *os << "is mapped by the given callable to a value that ";
4130 matcher_.DescribeNegationTo(os);
4131 }
4132
4133 bool MatchAndExplain(T obj, MatchResultListener* listener) const override {
4134 *listener << "which is mapped by the given callable to ";
4135 // Cannot pass the return value directly to MatchPrintAndExplain, which
4136 // takes a non-const reference as argument.
4137 // Also, specifying template argument explicitly is needed because T could
4138 // be a non-const reference (e.g. Matcher<Uncopyable&>).
4139 ResultType result =
4140 CallableTraits<Callable>::template Invoke<T>(callable_, obj);
4141 return MatchPrintAndExplain(result, matcher_, listener);
4142 }
4143
4144 private:
4145 // Functors often define operator() as non-const method even though
4146 // they are actually stateless. But we need to use them even when
4147 // 'this' is a const pointer. It's the user's responsibility not to
4148 // use stateful callables with ResultOf(), which doesn't guarantee
4149 // how many times the callable will be invoked.
4150 mutable CallableStorageType callable_;
4151 const Matcher<ResultType> matcher_;
4152
4153 GTEST_DISALLOW_ASSIGN_(Impl);
4154 }; // class Impl
4155
4156 const CallableStorageType callable_;
4157 const InnerMatcher matcher_;
4158
4159 GTEST_DISALLOW_ASSIGN_(ResultOfMatcher);
4160};
4161
4162// Implements a matcher that checks the size of an STL-style container.
4163template <typename SizeMatcher>
4164class SizeIsMatcher {
4165 public:
4166 explicit SizeIsMatcher(const SizeMatcher& size_matcher)
4167 : size_matcher_(size_matcher) {
4168 }
4169
4170 template <typename Container>
4171 operator Matcher<Container>() const {
4172 return Matcher<Container>(new Impl<const Container&>(size_matcher_));
4173 }
4174
4175 template <typename Container>
4176 class Impl : public MatcherInterface<Container> {
4177 public:
4178 using SizeType = decltype(std::declval<Container>().size());
4179 explicit Impl(const SizeMatcher& size_matcher)
4180 : size_matcher_(MatcherCast<SizeType>(size_matcher)) {}
4181
4182 void DescribeTo(::std::ostream* os) const override {
4183 *os << "size ";
4184 size_matcher_.DescribeTo(os);
4185 }
4186 void DescribeNegationTo(::std::ostream* os) const override {
4187 *os << "size ";
4188 size_matcher_.DescribeNegationTo(os);
4189 }
4190
4191 bool MatchAndExplain(Container container,
4192 MatchResultListener* listener) const override {
4193 SizeType size = container.size();
4194 StringMatchResultListener size_listener;
4195 const bool result = size_matcher_.MatchAndExplain(size, &size_listener);
4196 *listener
4197 << "whose size " << size << (result ? " matches" : " doesn't match");
4198 PrintIfNotEmpty(size_listener.str(), listener->stream());
4199 return result;
4200 }
4201
4202 private:
4203 const Matcher<SizeType> size_matcher_;
4204 GTEST_DISALLOW_ASSIGN_(Impl);
4205 };
4206
4207 private:
4208 const SizeMatcher size_matcher_;
4209 GTEST_DISALLOW_ASSIGN_(SizeIsMatcher);
4210};
4211
4212// Implements a matcher that checks the begin()..end() distance of an STL-style
4213// container.
4214template <typename DistanceMatcher>
4215class BeginEndDistanceIsMatcher {
4216 public:
4217 explicit BeginEndDistanceIsMatcher(const DistanceMatcher& distance_matcher)
4218 : distance_matcher_(distance_matcher) {}
4219
4220 template <typename Container>
4221 operator Matcher<Container>() const {
4222 return Matcher<Container>(new Impl<const Container&>(distance_matcher_));
4223 }
4224
4225 template <typename Container>
4226 class Impl : public MatcherInterface<Container> {
4227 public:
4228 typedef internal::StlContainerView<
4229 GTEST_REMOVE_REFERENCE_AND_CONST_(Container)> ContainerView;
4230 typedef typename std::iterator_traits<
4231 typename ContainerView::type::const_iterator>::difference_type
4232 DistanceType;
4233 explicit Impl(const DistanceMatcher& distance_matcher)
4234 : distance_matcher_(MatcherCast<DistanceType>(distance_matcher)) {}
4235
4236 void DescribeTo(::std::ostream* os) const override {
4237 *os << "distance between begin() and end() ";
4238 distance_matcher_.DescribeTo(os);
4239 }
4240 void DescribeNegationTo(::std::ostream* os) const override {
4241 *os << "distance between begin() and end() ";
4242 distance_matcher_.DescribeNegationTo(os);
4243 }
4244
4245 bool MatchAndExplain(Container container,
4246 MatchResultListener* listener) const override {
4247 using std::begin;
4248 using std::end;
4249 DistanceType distance = std::distance(begin(container), end(container));
4250 StringMatchResultListener distance_listener;
4251 const bool result =
4252 distance_matcher_.MatchAndExplain(distance, &distance_listener);
4253 *listener << "whose distance between begin() and end() " << distance
4254 << (result ? " matches" : " doesn't match");
4255 PrintIfNotEmpty(distance_listener.str(), listener->stream());
4256 return result;
4257 }
4258
4259 private:
4260 const Matcher<DistanceType> distance_matcher_;
4261 GTEST_DISALLOW_ASSIGN_(Impl);
4262 };
4263
4264 private:
4265 const DistanceMatcher distance_matcher_;
4266 GTEST_DISALLOW_ASSIGN_(BeginEndDistanceIsMatcher);
4267};
4268
4269// Implements an equality matcher for any STL-style container whose elements
4270// support ==. This matcher is like Eq(), but its failure explanations provide
4271// more detailed information that is useful when the container is used as a set.
4272// The failure message reports elements that are in one of the operands but not
4273// the other. The failure messages do not report duplicate or out-of-order
4274// elements in the containers (which don't properly matter to sets, but can
4275// occur if the containers are vectors or lists, for example).
4276//
4277// Uses the container's const_iterator, value_type, operator ==,
4278// begin(), and end().
4279template <typename Container>
4280class ContainerEqMatcher {
4281 public:
4282 typedef internal::StlContainerView<Container> View;
4283 typedef typename View::type StlContainer;
4284 typedef typename View::const_reference StlContainerReference;
4285
4286 // We make a copy of expected in case the elements in it are modified
4287 // after this matcher is created.
4288 explicit ContainerEqMatcher(const Container& expected)
4289 : expected_(View::Copy(expected)) {
4290 // Makes sure the user doesn't instantiate this class template
4291 // with a const or reference type.
4292 (void)testing::StaticAssertTypeEq<Container,
4293 GTEST_REMOVE_REFERENCE_AND_CONST_(Container)>();
4294 }
4295
4296 void DescribeTo(::std::ostream* os) const {
4297 *os << "equals ";
4298 UniversalPrint(expected_, os);
4299 }
4300 void DescribeNegationTo(::std::ostream* os) const {
4301 *os << "does not equal ";
4302 UniversalPrint(expected_, os);
4303 }
4304
4305 template <typename LhsContainer>
4306 bool MatchAndExplain(const LhsContainer& lhs,
4307 MatchResultListener* listener) const {
4308 // GTEST_REMOVE_CONST_() is needed to work around an MSVC 8.0 bug
4309 // that causes LhsContainer to be a const type sometimes.
4310 typedef internal::StlContainerView<GTEST_REMOVE_CONST_(LhsContainer)>
4311 LhsView;
4312 typedef typename LhsView::type LhsStlContainer;
4313 StlContainerReference lhs_stl_container = LhsView::ConstReference(lhs);
4314 if (lhs_stl_container == expected_)
4315 return true;
4316
4317 ::std::ostream* const os = listener->stream();
4318 if (os != nullptr) {
4319 // Something is different. Check for extra values first.
4320 bool printed_header = false;
4321 for (typename LhsStlContainer::const_iterator it =
4322 lhs_stl_container.begin();
4323 it != lhs_stl_container.end(); ++it) {
4324 if (internal::ArrayAwareFind(expected_.begin(), expected_.end(), *it) ==
4325 expected_.end()) {
4326 if (printed_header) {
4327 *os << ", ";
4328 } else {
4329 *os << "which has these unexpected elements: ";
4330 printed_header = true;
4331 }
4332 UniversalPrint(*it, os);
4333 }
4334 }
4335
4336 // Now check for missing values.
4337 bool printed_header2 = false;
4338 for (typename StlContainer::const_iterator it = expected_.begin();
4339 it != expected_.end(); ++it) {
4340 if (internal::ArrayAwareFind(
4341 lhs_stl_container.begin(), lhs_stl_container.end(), *it) ==
4342 lhs_stl_container.end()) {
4343 if (printed_header2) {
4344 *os << ", ";
4345 } else {
4346 *os << (printed_header ? ",\nand" : "which")
4347 << " doesn't have these expected elements: ";
4348 printed_header2 = true;
4349 }
4350 UniversalPrint(*it, os);
4351 }
4352 }
4353 }
4354
4355 return false;
4356 }
4357
4358 private:
4359 const StlContainer expected_;
4360
4361 GTEST_DISALLOW_ASSIGN_(ContainerEqMatcher);
4362};
4363
4364// A comparator functor that uses the < operator to compare two values.
4365struct LessComparator {
4366 template <typename T, typename U>
4367 bool operator()(const T& lhs, const U& rhs) const { return lhs < rhs; }
4368};
4369
4370// Implements WhenSortedBy(comparator, container_matcher).
4371template <typename Comparator, typename ContainerMatcher>
4372class WhenSortedByMatcher {
4373 public:
4374 WhenSortedByMatcher(const Comparator& comparator,
4375 const ContainerMatcher& matcher)
4376 : comparator_(comparator), matcher_(matcher) {}
4377
4378 template <typename LhsContainer>
4379 operator Matcher<LhsContainer>() const {
4380 return MakeMatcher(new Impl<LhsContainer>(comparator_, matcher_));
4381 }
4382
4383 template <typename LhsContainer>
4384 class Impl : public MatcherInterface<LhsContainer> {
4385 public:
4386 typedef internal::StlContainerView<
4387 GTEST_REMOVE_REFERENCE_AND_CONST_(LhsContainer)> LhsView;
4388 typedef typename LhsView::type LhsStlContainer;
4389 typedef typename LhsView::const_reference LhsStlContainerReference;
4390 // Transforms std::pair<const Key, Value> into std::pair<Key, Value>
4391 // so that we can match associative containers.
4392 typedef typename RemoveConstFromKey<
4393 typename LhsStlContainer::value_type>::type LhsValue;
4394
4395 Impl(const Comparator& comparator, const ContainerMatcher& matcher)
4396 : comparator_(comparator), matcher_(matcher) {}
4397
4398 void DescribeTo(::std::ostream* os) const override {
4399 *os << "(when sorted) ";
4400 matcher_.DescribeTo(os);
4401 }
4402
4403 void DescribeNegationTo(::std::ostream* os) const override {
4404 *os << "(when sorted) ";
4405 matcher_.DescribeNegationTo(os);
4406 }
4407
4408 bool MatchAndExplain(LhsContainer lhs,
4409 MatchResultListener* listener) const override {
4410 LhsStlContainerReference lhs_stl_container = LhsView::ConstReference(lhs);
4411 ::std::vector<LhsValue> sorted_container(lhs_stl_container.begin(),
4412 lhs_stl_container.end());
4413 ::std::sort(
4414 sorted_container.begin(), sorted_container.end(), comparator_);
4415
4416 if (!listener->IsInterested()) {
4417 // If the listener is not interested, we do not need to
4418 // construct the inner explanation.
4419 return matcher_.Matches(sorted_container);
4420 }
4421
4422 *listener << "which is ";
4423 UniversalPrint(sorted_container, listener->stream());
4424 *listener << " when sorted";
4425
4426 StringMatchResultListener inner_listener;
4427 const bool match = matcher_.MatchAndExplain(sorted_container,
4428 &inner_listener);
4429 PrintIfNotEmpty(inner_listener.str(), listener->stream());
4430 return match;
4431 }
4432
4433 private:
4434 const Comparator comparator_;
4435 const Matcher<const ::std::vector<LhsValue>&> matcher_;
4436
4437 GTEST_DISALLOW_COPY_AND_ASSIGN_(Impl);
4438 };
4439
4440 private:
4441 const Comparator comparator_;
4442 const ContainerMatcher matcher_;
4443
4444 GTEST_DISALLOW_ASSIGN_(WhenSortedByMatcher);
4445};
4446
4447// Implements Pointwise(tuple_matcher, rhs_container). tuple_matcher
4448// must be able to be safely cast to Matcher<std::tuple<const T1&, const
4449// T2&> >, where T1 and T2 are the types of elements in the LHS
4450// container and the RHS container respectively.
4451template <typename TupleMatcher, typename RhsContainer>
4452class PointwiseMatcher {
4453 GTEST_COMPILE_ASSERT_(
4454 !IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(RhsContainer)>::value,
4455 use_UnorderedPointwise_with_hash_tables);
4456
4457 public:
4458 typedef internal::StlContainerView<RhsContainer> RhsView;
4459 typedef typename RhsView::type RhsStlContainer;
4460 typedef typename RhsStlContainer::value_type RhsValue;
4461
4462 // Like ContainerEq, we make a copy of rhs in case the elements in
4463 // it are modified after this matcher is created.
4464 PointwiseMatcher(const TupleMatcher& tuple_matcher, const RhsContainer& rhs)
4465 : tuple_matcher_(tuple_matcher), rhs_(RhsView::Copy(rhs)) {
4466 // Makes sure the user doesn't instantiate this class template
4467 // with a const or reference type.
4468 (void)testing::StaticAssertTypeEq<RhsContainer,
4469 GTEST_REMOVE_REFERENCE_AND_CONST_(RhsContainer)>();
4470 }
4471
4472 template <typename LhsContainer>
4473 operator Matcher<LhsContainer>() const {
4474 GTEST_COMPILE_ASSERT_(
4475 !IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(LhsContainer)>::value,
4476 use_UnorderedPointwise_with_hash_tables);
4477
4478 return Matcher<LhsContainer>(
4479 new Impl<const LhsContainer&>(tuple_matcher_, rhs_));
4480 }
4481
4482 template <typename LhsContainer>
4483 class Impl : public MatcherInterface<LhsContainer> {
4484 public:
4485 typedef internal::StlContainerView<
4486 GTEST_REMOVE_REFERENCE_AND_CONST_(LhsContainer)> LhsView;
4487 typedef typename LhsView::type LhsStlContainer;
4488 typedef typename LhsView::const_reference LhsStlContainerReference;
4489 typedef typename LhsStlContainer::value_type LhsValue;
4490 // We pass the LHS value and the RHS value to the inner matcher by
4491 // reference, as they may be expensive to copy. We must use tuple
4492 // instead of pair here, as a pair cannot hold references (C++ 98,
4493 // 20.2.2 [lib.pairs]).
4494 typedef ::std::tuple<const LhsValue&, const RhsValue&> InnerMatcherArg;
4495
4496 Impl(const TupleMatcher& tuple_matcher, const RhsStlContainer& rhs)
4497 // mono_tuple_matcher_ holds a monomorphic version of the tuple matcher.
4498 : mono_tuple_matcher_(SafeMatcherCast<InnerMatcherArg>(tuple_matcher)),
4499 rhs_(rhs) {}
4500
4501 void DescribeTo(::std::ostream* os) const override {
4502 *os << "contains " << rhs_.size()
4503 << " values, where each value and its corresponding value in ";
4504 UniversalPrinter<RhsStlContainer>::Print(rhs_, os);
4505 *os << " ";
4506 mono_tuple_matcher_.DescribeTo(os);
4507 }
4508 void DescribeNegationTo(::std::ostream* os) const override {
4509 *os << "doesn't contain exactly " << rhs_.size()
4510 << " values, or contains a value x at some index i"
4511 << " where x and the i-th value of ";
4512 UniversalPrint(rhs_, os);
4513 *os << " ";
4514 mono_tuple_matcher_.DescribeNegationTo(os);
4515 }
4516
4517 bool MatchAndExplain(LhsContainer lhs,
4518 MatchResultListener* listener) const override {
4519 LhsStlContainerReference lhs_stl_container = LhsView::ConstReference(lhs);
4520 const size_t actual_size = lhs_stl_container.size();
4521 if (actual_size != rhs_.size()) {
4522 *listener << "which contains " << actual_size << " values";
4523 return false;
4524 }
4525
4526 typename LhsStlContainer::const_iterator left = lhs_stl_container.begin();
4527 typename RhsStlContainer::const_iterator right = rhs_.begin();
4528 for (size_t i = 0; i != actual_size; ++i, ++left, ++right) {
4529 if (listener->IsInterested()) {
4530 StringMatchResultListener inner_listener;
4531 // Create InnerMatcherArg as a temporarily object to avoid it outlives
4532 // *left and *right. Dereference or the conversion to `const T&` may
4533 // return temp objects, e.g for vector<bool>.
4534 if (!mono_tuple_matcher_.MatchAndExplain(
4535 InnerMatcherArg(ImplicitCast_<const LhsValue&>(*left),
4536 ImplicitCast_<const RhsValue&>(*right)),
4537 &inner_listener)) {
4538 *listener << "where the value pair (";
4539 UniversalPrint(*left, listener->stream());
4540 *listener << ", ";
4541 UniversalPrint(*right, listener->stream());
4542 *listener << ") at index #" << i << " don't match";
4543 PrintIfNotEmpty(inner_listener.str(), listener->stream());
4544 return false;
4545 }
4546 } else {
4547 if (!mono_tuple_matcher_.Matches(
4548 InnerMatcherArg(ImplicitCast_<const LhsValue&>(*left),
4549 ImplicitCast_<const RhsValue&>(*right))))
4550 return false;
4551 }
4552 }
4553
4554 return true;
4555 }
4556
4557 private:
4558 const Matcher<InnerMatcherArg> mono_tuple_matcher_;
4559 const RhsStlContainer rhs_;
4560
4561 GTEST_DISALLOW_ASSIGN_(Impl);
4562 };
4563
4564 private:
4565 const TupleMatcher tuple_matcher_;
4566 const RhsStlContainer rhs_;
4567
4568 GTEST_DISALLOW_ASSIGN_(PointwiseMatcher);
4569};
4570
4571// Holds the logic common to ContainsMatcherImpl and EachMatcherImpl.
4572template <typename Container>
4573class QuantifierMatcherImpl : public MatcherInterface<Container> {
4574 public:
4575 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
4576 typedef StlContainerView<RawContainer> View;
4577 typedef typename View::type StlContainer;
4578 typedef typename View::const_reference StlContainerReference;
4579 typedef typename StlContainer::value_type Element;
4580
4581 template <typename InnerMatcher>
4582 explicit QuantifierMatcherImpl(InnerMatcher inner_matcher)
4583 : inner_matcher_(
4584 testing::SafeMatcherCast<const Element&>(inner_matcher)) {}
4585
4586 // Checks whether:
4587 // * All elements in the container match, if all_elements_should_match.
4588 // * Any element in the container matches, if !all_elements_should_match.
4589 bool MatchAndExplainImpl(bool all_elements_should_match,
4590 Container container,
4591 MatchResultListener* listener) const {
4592 StlContainerReference stl_container = View::ConstReference(container);
4593 size_t i = 0;
4594 for (typename StlContainer::const_iterator it = stl_container.begin();
4595 it != stl_container.end(); ++it, ++i) {
4596 StringMatchResultListener inner_listener;
4597 const bool matches = inner_matcher_.MatchAndExplain(*it, &inner_listener);
4598
4599 if (matches != all_elements_should_match) {
4600 *listener << "whose element #" << i
4601 << (matches ? " matches" : " doesn't match");
4602 PrintIfNotEmpty(inner_listener.str(), listener->stream());
4603 return !all_elements_should_match;
4604 }
4605 }
4606 return all_elements_should_match;
4607 }
4608
4609 protected:
4610 const Matcher<const Element&> inner_matcher_;
4611
4612 GTEST_DISALLOW_ASSIGN_(QuantifierMatcherImpl);
4613};
4614
4615// Implements Contains(element_matcher) for the given argument type Container.
4616// Symmetric to EachMatcherImpl.
4617template <typename Container>
4618class ContainsMatcherImpl : public QuantifierMatcherImpl<Container> {
4619 public:
4620 template <typename InnerMatcher>
4621 explicit ContainsMatcherImpl(InnerMatcher inner_matcher)
4622 : QuantifierMatcherImpl<Container>(inner_matcher) {}
4623
4624 // Describes what this matcher does.
4625 void DescribeTo(::std::ostream* os) const override {
4626 *os << "contains at least one element that ";
4627 this->inner_matcher_.DescribeTo(os);
4628 }
4629
4630 void DescribeNegationTo(::std::ostream* os) const override {
4631 *os << "doesn't contain any element that ";
4632 this->inner_matcher_.DescribeTo(os);
4633 }
4634
4635 bool MatchAndExplain(Container container,
4636 MatchResultListener* listener) const override {
4637 return this->MatchAndExplainImpl(false, container, listener);
4638 }
4639
4640 private:
4641 GTEST_DISALLOW_ASSIGN_(ContainsMatcherImpl);
4642};
4643
4644// Implements Each(element_matcher) for the given argument type Container.
4645// Symmetric to ContainsMatcherImpl.
4646template <typename Container>
4647class EachMatcherImpl : public QuantifierMatcherImpl<Container> {
4648 public:
4649 template <typename InnerMatcher>
4650 explicit EachMatcherImpl(InnerMatcher inner_matcher)
4651 : QuantifierMatcherImpl<Container>(inner_matcher) {}
4652
4653 // Describes what this matcher does.
4654 void DescribeTo(::std::ostream* os) const override {
4655 *os << "only contains elements that ";
4656 this->inner_matcher_.DescribeTo(os);
4657 }
4658
4659 void DescribeNegationTo(::std::ostream* os) const override {
4660 *os << "contains some element that ";
4661 this->inner_matcher_.DescribeNegationTo(os);
4662 }
4663
4664 bool MatchAndExplain(Container container,
4665 MatchResultListener* listener) const override {
4666 return this->MatchAndExplainImpl(true, container, listener);
4667 }
4668
4669 private:
4670 GTEST_DISALLOW_ASSIGN_(EachMatcherImpl);
4671};
4672
4673// Implements polymorphic Contains(element_matcher).
4674template <typename M>
4675class ContainsMatcher {
4676 public:
4677 explicit ContainsMatcher(M m) : inner_matcher_(m) {}
4678
4679 template <typename Container>
4680 operator Matcher<Container>() const {
4681 return Matcher<Container>(
4682 new ContainsMatcherImpl<const Container&>(inner_matcher_));
4683 }
4684
4685 private:
4686 const M inner_matcher_;
4687
4688 GTEST_DISALLOW_ASSIGN_(ContainsMatcher);
4689};
4690
4691// Implements polymorphic Each(element_matcher).
4692template <typename M>
4693class EachMatcher {
4694 public:
4695 explicit EachMatcher(M m) : inner_matcher_(m) {}
4696
4697 template <typename Container>
4698 operator Matcher<Container>() const {
4699 return Matcher<Container>(
4700 new EachMatcherImpl<const Container&>(inner_matcher_));
4701 }
4702
4703 private:
4704 const M inner_matcher_;
4705
4706 GTEST_DISALLOW_ASSIGN_(EachMatcher);
4707};
4708
4709struct Rank1 {};
4710struct Rank0 : Rank1 {};
4711
4712namespace pair_getters {
4713using std::get;
4714template <typename T>
4715auto First(T& x, Rank1) -> decltype(get<0>(x)) { // NOLINT
4716 return get<0>(x);
4717}
4718template <typename T>
4719auto First(T& x, Rank0) -> decltype((x.first)) { // NOLINT
4720 return x.first;
4721}
4722
4723template <typename T>
4724auto Second(T& x, Rank1) -> decltype(get<1>(x)) { // NOLINT
4725 return get<1>(x);
4726}
4727template <typename T>
4728auto Second(T& x, Rank0) -> decltype((x.second)) { // NOLINT
4729 return x.second;
4730}
4731} // namespace pair_getters
4732
4733// Implements Key(inner_matcher) for the given argument pair type.
4734// Key(inner_matcher) matches an std::pair whose 'first' field matches
4735// inner_matcher. For example, Contains(Key(Ge(5))) can be used to match an
4736// std::map that contains at least one element whose key is >= 5.
4737template <typename PairType>
4738class KeyMatcherImpl : public MatcherInterface<PairType> {
4739 public:
4740 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(PairType) RawPairType;
4741 typedef typename RawPairType::first_type KeyType;
4742
4743 template <typename InnerMatcher>
4744 explicit KeyMatcherImpl(InnerMatcher inner_matcher)
4745 : inner_matcher_(
4746 testing::SafeMatcherCast<const KeyType&>(inner_matcher)) {
4747 }
4748
4749 // Returns true iff 'key_value.first' (the key) matches the inner matcher.
4750 bool MatchAndExplain(PairType key_value,
4751 MatchResultListener* listener) const override {
4752 StringMatchResultListener inner_listener;
4753 const bool match = inner_matcher_.MatchAndExplain(
4754 pair_getters::First(key_value, Rank0()), &inner_listener);
4755 const std::string explanation = inner_listener.str();
4756 if (explanation != "") {
4757 *listener << "whose first field is a value " << explanation;
4758 }
4759 return match;
4760 }
4761
4762 // Describes what this matcher does.
4763 void DescribeTo(::std::ostream* os) const override {
4764 *os << "has a key that ";
4765 inner_matcher_.DescribeTo(os);
4766 }
4767
4768 // Describes what the negation of this matcher does.
4769 void DescribeNegationTo(::std::ostream* os) const override {
4770 *os << "doesn't have a key that ";
4771 inner_matcher_.DescribeTo(os);
4772 }
4773
4774 private:
4775 const Matcher<const KeyType&> inner_matcher_;
4776
4777 GTEST_DISALLOW_ASSIGN_(KeyMatcherImpl);
4778};
4779
4780// Implements polymorphic Key(matcher_for_key).
4781template <typename M>
4782class KeyMatcher {
4783 public:
4784 explicit KeyMatcher(M m) : matcher_for_key_(m) {}
4785
4786 template <typename PairType>
4787 operator Matcher<PairType>() const {
4788 return Matcher<PairType>(
4789 new KeyMatcherImpl<const PairType&>(matcher_for_key_));
4790 }
4791
4792 private:
4793 const M matcher_for_key_;
4794
4795 GTEST_DISALLOW_ASSIGN_(KeyMatcher);
4796};
4797
4798// Implements Pair(first_matcher, second_matcher) for the given argument pair
4799// type with its two matchers. See Pair() function below.
4800template <typename PairType>
4801class PairMatcherImpl : public MatcherInterface<PairType> {
4802 public:
4803 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(PairType) RawPairType;
4804 typedef typename RawPairType::first_type FirstType;
4805 typedef typename RawPairType::second_type SecondType;
4806
4807 template <typename FirstMatcher, typename SecondMatcher>
4808 PairMatcherImpl(FirstMatcher first_matcher, SecondMatcher second_matcher)
4809 : first_matcher_(
4810 testing::SafeMatcherCast<const FirstType&>(first_matcher)),
4811 second_matcher_(
4812 testing::SafeMatcherCast<const SecondType&>(second_matcher)) {
4813 }
4814
4815 // Describes what this matcher does.
4816 void DescribeTo(::std::ostream* os) const override {
4817 *os << "has a first field that ";
4818 first_matcher_.DescribeTo(os);
4819 *os << ", and has a second field that ";
4820 second_matcher_.DescribeTo(os);
4821 }
4822
4823 // Describes what the negation of this matcher does.
4824 void DescribeNegationTo(::std::ostream* os) const override {
4825 *os << "has a first field that ";
4826 first_matcher_.DescribeNegationTo(os);
4827 *os << ", or has a second field that ";
4828 second_matcher_.DescribeNegationTo(os);
4829 }
4830
4831 // Returns true iff 'a_pair.first' matches first_matcher and 'a_pair.second'
4832 // matches second_matcher.
4833 bool MatchAndExplain(PairType a_pair,
4834 MatchResultListener* listener) const override {
4835 if (!listener->IsInterested()) {
4836 // If the listener is not interested, we don't need to construct the
4837 // explanation.
4838 return first_matcher_.Matches(pair_getters::First(a_pair, Rank0())) &&
4839 second_matcher_.Matches(pair_getters::Second(a_pair, Rank0()));
4840 }
4841 StringMatchResultListener first_inner_listener;
4842 if (!first_matcher_.MatchAndExplain(pair_getters::First(a_pair, Rank0()),
4843 &first_inner_listener)) {
4844 *listener << "whose first field does not match";
4845 PrintIfNotEmpty(first_inner_listener.str(), listener->stream());
4846 return false;
4847 }
4848 StringMatchResultListener second_inner_listener;
4849 if (!second_matcher_.MatchAndExplain(pair_getters::Second(a_pair, Rank0()),
4850 &second_inner_listener)) {
4851 *listener << "whose second field does not match";
4852 PrintIfNotEmpty(second_inner_listener.str(), listener->stream());
4853 return false;
4854 }
4855 ExplainSuccess(first_inner_listener.str(), second_inner_listener.str(),
4856 listener);
4857 return true;
4858 }
4859
4860 private:
4861 void ExplainSuccess(const std::string& first_explanation,
4862 const std::string& second_explanation,
4863 MatchResultListener* listener) const {
4864 *listener << "whose both fields match";
4865 if (first_explanation != "") {
4866 *listener << ", where the first field is a value " << first_explanation;
4867 }
4868 if (second_explanation != "") {
4869 *listener << ", ";
4870 if (first_explanation != "") {
4871 *listener << "and ";
4872 } else {
4873 *listener << "where ";
4874 }
4875 *listener << "the second field is a value " << second_explanation;
4876 }
4877 }
4878
4879 const Matcher<const FirstType&> first_matcher_;
4880 const Matcher<const SecondType&> second_matcher_;
4881
4882 GTEST_DISALLOW_ASSIGN_(PairMatcherImpl);
4883};
4884
4885// Implements polymorphic Pair(first_matcher, second_matcher).
4886template <typename FirstMatcher, typename SecondMatcher>
4887class PairMatcher {
4888 public:
4889 PairMatcher(FirstMatcher first_matcher, SecondMatcher second_matcher)
4890 : first_matcher_(first_matcher), second_matcher_(second_matcher) {}
4891
4892 template <typename PairType>
4893 operator Matcher<PairType> () const {
4894 return Matcher<PairType>(
4895 new PairMatcherImpl<const PairType&>(first_matcher_, second_matcher_));
4896 }
4897
4898 private:
4899 const FirstMatcher first_matcher_;
4900 const SecondMatcher second_matcher_;
4901
4902 GTEST_DISALLOW_ASSIGN_(PairMatcher);
4903};
4904
4905// Implements ElementsAre() and ElementsAreArray().
4906template <typename Container>
4907class ElementsAreMatcherImpl : public MatcherInterface<Container> {
4908 public:
4909 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
4910 typedef internal::StlContainerView<RawContainer> View;
4911 typedef typename View::type StlContainer;
4912 typedef typename View::const_reference StlContainerReference;
4913 typedef typename StlContainer::value_type Element;
4914
4915 // Constructs the matcher from a sequence of element values or
4916 // element matchers.
4917 template <typename InputIter>
4918 ElementsAreMatcherImpl(InputIter first, InputIter last) {
4919 while (first != last) {
4920 matchers_.push_back(MatcherCast<const Element&>(*first++));
4921 }
4922 }
4923
4924 // Describes what this matcher does.
4925 void DescribeTo(::std::ostream* os) const override {
4926 if (count() == 0) {
4927 *os << "is empty";
4928 } else if (count() == 1) {
4929 *os << "has 1 element that ";
4930 matchers_[0].DescribeTo(os);
4931 } else {
4932 *os << "has " << Elements(count()) << " where\n";
4933 for (size_t i = 0; i != count(); ++i) {
4934 *os << "element #" << i << " ";
4935 matchers_[i].DescribeTo(os);
4936 if (i + 1 < count()) {
4937 *os << ",\n";
4938 }
4939 }
4940 }
4941 }
4942
4943 // Describes what the negation of this matcher does.
4944 void DescribeNegationTo(::std::ostream* os) const override {
4945 if (count() == 0) {
4946 *os << "isn't empty";
4947 return;
4948 }
4949
4950 *os << "doesn't have " << Elements(count()) << ", or\n";
4951 for (size_t i = 0; i != count(); ++i) {
4952 *os << "element #" << i << " ";
4953 matchers_[i].DescribeNegationTo(os);
4954 if (i + 1 < count()) {
4955 *os << ", or\n";
4956 }
4957 }
4958 }
4959
4960 bool MatchAndExplain(Container container,
4961 MatchResultListener* listener) const override {
4962 // To work with stream-like "containers", we must only walk
4963 // through the elements in one pass.
4964
4965 const bool listener_interested = listener->IsInterested();
4966
4967 // explanations[i] is the explanation of the element at index i.
4968 ::std::vector<std::string> explanations(count());
4969 StlContainerReference stl_container = View::ConstReference(container);
4970 typename StlContainer::const_iterator it = stl_container.begin();
4971 size_t exam_pos = 0;
4972 bool mismatch_found = false; // Have we found a mismatched element yet?
4973
4974 // Go through the elements and matchers in pairs, until we reach
4975 // the end of either the elements or the matchers, or until we find a
4976 // mismatch.
4977 for (; it != stl_container.end() && exam_pos != count(); ++it, ++exam_pos) {
4978 bool match; // Does the current element match the current matcher?
4979 if (listener_interested) {
4980 StringMatchResultListener s;
4981 match = matchers_[exam_pos].MatchAndExplain(*it, &s);
4982 explanations[exam_pos] = s.str();
4983 } else {
4984 match = matchers_[exam_pos].Matches(*it);
4985 }
4986
4987 if (!match) {
4988 mismatch_found = true;
4989 break;
4990 }
4991 }
4992 // If mismatch_found is true, 'exam_pos' is the index of the mismatch.
4993
4994 // Find how many elements the actual container has. We avoid
4995 // calling size() s.t. this code works for stream-like "containers"
4996 // that don't define size().
4997 size_t actual_count = exam_pos;
4998 for (; it != stl_container.end(); ++it) {
4999 ++actual_count;
5000 }
5001
5002 if (actual_count != count()) {
5003 // The element count doesn't match. If the container is empty,
5004 // there's no need to explain anything as Google Mock already
5005 // prints the empty container. Otherwise we just need to show
5006 // how many elements there actually are.
5007 if (listener_interested && (actual_count != 0)) {
5008 *listener << "which has " << Elements(actual_count);
5009 }
5010 return false;
5011 }
5012
5013 if (mismatch_found) {
5014 // The element count matches, but the exam_pos-th element doesn't match.
5015 if (listener_interested) {
5016 *listener << "whose element #" << exam_pos << " doesn't match";
5017 PrintIfNotEmpty(explanations[exam_pos], listener->stream());
5018 }
5019 return false;
5020 }
5021
5022 // Every element matches its expectation. We need to explain why
5023 // (the obvious ones can be skipped).
5024 if (listener_interested) {
5025 bool reason_printed = false;
5026 for (size_t i = 0; i != count(); ++i) {
5027 const std::string& s = explanations[i];
5028 if (!s.empty()) {
5029 if (reason_printed) {
5030 *listener << ",\nand ";
5031 }
5032 *listener << "whose element #" << i << " matches, " << s;
5033 reason_printed = true;
5034 }
5035 }
5036 }
5037 return true;
5038 }
5039
5040 private:
5041 static Message Elements(size_t count) {
5042 return Message() << count << (count == 1 ? " element" : " elements");
5043 }
5044
5045 size_t count() const { return matchers_.size(); }
5046
5047 ::std::vector<Matcher<const Element&> > matchers_;
5048
5049 GTEST_DISALLOW_ASSIGN_(ElementsAreMatcherImpl);
5050};
5051
5052// Connectivity matrix of (elements X matchers), in element-major order.
5053// Initially, there are no edges.
5054// Use NextGraph() to iterate over all possible edge configurations.
5055// Use Randomize() to generate a random edge configuration.
5056class GTEST_API_ MatchMatrix {
5057 public:
5058 MatchMatrix(size_t num_elements, size_t num_matchers)
5059 : num_elements_(num_elements),
5060 num_matchers_(num_matchers),
5061 matched_(num_elements_* num_matchers_, 0) {
5062 }
5063
5064 size_t LhsSize() const { return num_elements_; }
5065 size_t RhsSize() const { return num_matchers_; }
5066 bool HasEdge(size_t ilhs, size_t irhs) const {
5067 return matched_[SpaceIndex(ilhs, irhs)] == 1;
5068 }
5069 void SetEdge(size_t ilhs, size_t irhs, bool b) {
5070 matched_[SpaceIndex(ilhs, irhs)] = b ? 1 : 0;
5071 }
5072
5073 // Treating the connectivity matrix as a (LhsSize()*RhsSize())-bit number,
5074 // adds 1 to that number; returns false if incrementing the graph left it
5075 // empty.
5076 bool NextGraph();
5077
5078 void Randomize();
5079
5080 std::string DebugString() const;
5081
5082 private:
5083 size_t SpaceIndex(size_t ilhs, size_t irhs) const {
5084 return ilhs * num_matchers_ + irhs;
5085 }
5086
5087 size_t num_elements_;
5088 size_t num_matchers_;
5089
5090 // Each element is a char interpreted as bool. They are stored as a
5091 // flattened array in lhs-major order, use 'SpaceIndex()' to translate
5092 // a (ilhs, irhs) matrix coordinate into an offset.
5093 ::std::vector<char> matched_;
5094};
5095
5096typedef ::std::pair<size_t, size_t> ElementMatcherPair;
5097typedef ::std::vector<ElementMatcherPair> ElementMatcherPairs;
5098
5099// Returns a maximum bipartite matching for the specified graph 'g'.
5100// The matching is represented as a vector of {element, matcher} pairs.
5101GTEST_API_ ElementMatcherPairs
5102FindMaxBipartiteMatching(const MatchMatrix& g);
5103
5104struct UnorderedMatcherRequire {
5105 enum Flags {
5106 Superset = 1 << 0,
5107 Subset = 1 << 1,
5108 ExactMatch = Superset | Subset,
5109 };
5110};
5111
5112// Untyped base class for implementing UnorderedElementsAre. By
5113// putting logic that's not specific to the element type here, we
5114// reduce binary bloat and increase compilation speed.
5115class GTEST_API_ UnorderedElementsAreMatcherImplBase {
5116 protected:
5117 explicit UnorderedElementsAreMatcherImplBase(
5118 UnorderedMatcherRequire::Flags matcher_flags)
5119 : match_flags_(matcher_flags) {}
5120
5121 // A vector of matcher describers, one for each element matcher.
5122 // Does not own the describers (and thus can be used only when the
5123 // element matchers are alive).
5124 typedef ::std::vector<const MatcherDescriberInterface*> MatcherDescriberVec;
5125
5126 // Describes this UnorderedElementsAre matcher.
5127 void DescribeToImpl(::std::ostream* os) const;
5128
5129 // Describes the negation of this UnorderedElementsAre matcher.
5130 void DescribeNegationToImpl(::std::ostream* os) const;
5131
5132 bool VerifyMatchMatrix(const ::std::vector<std::string>& element_printouts,
5133 const MatchMatrix& matrix,
5134 MatchResultListener* listener) const;
5135
5136 bool FindPairing(const MatchMatrix& matrix,
5137 MatchResultListener* listener) const;
5138
5139 MatcherDescriberVec& matcher_describers() {
5140 return matcher_describers_;
5141 }
5142
5143 static Message Elements(size_t n) {
5144 return Message() << n << " element" << (n == 1 ? "" : "s");
5145 }
5146
5147 UnorderedMatcherRequire::Flags match_flags() const { return match_flags_; }
5148
5149 private:
5150 UnorderedMatcherRequire::Flags match_flags_;
5151 MatcherDescriberVec matcher_describers_;
5152
5153 GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreMatcherImplBase);
5154};
5155
5156// Implements UnorderedElementsAre, UnorderedElementsAreArray, IsSubsetOf, and
5157// IsSupersetOf.
5158template <typename Container>
5159class UnorderedElementsAreMatcherImpl
5160 : public MatcherInterface<Container>,
5161 public UnorderedElementsAreMatcherImplBase {
5162 public:
5163 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
5164 typedef internal::StlContainerView<RawContainer> View;
5165 typedef typename View::type StlContainer;
5166 typedef typename View::const_reference StlContainerReference;
5167 typedef typename StlContainer::const_iterator StlContainerConstIterator;
5168 typedef typename StlContainer::value_type Element;
5169
5170 template <typename InputIter>
5171 UnorderedElementsAreMatcherImpl(UnorderedMatcherRequire::Flags matcher_flags,
5172 InputIter first, InputIter last)
5173 : UnorderedElementsAreMatcherImplBase(matcher_flags) {
5174 for (; first != last; ++first) {
5175 matchers_.push_back(MatcherCast<const Element&>(*first));
5176 matcher_describers().push_back(matchers_.back().GetDescriber());
5177 }
5178 }
5179
5180 // Describes what this matcher does.
5181 void DescribeTo(::std::ostream* os) const override {
5182 return UnorderedElementsAreMatcherImplBase::DescribeToImpl(os);
5183 }
5184
5185 // Describes what the negation of this matcher does.
5186 void DescribeNegationTo(::std::ostream* os) const override {
5187 return UnorderedElementsAreMatcherImplBase::DescribeNegationToImpl(os);
5188 }
5189
5190 bool MatchAndExplain(Container container,
5191 MatchResultListener* listener) const override {
5192 StlContainerReference stl_container = View::ConstReference(container);
5193 ::std::vector<std::string> element_printouts;
5194 MatchMatrix matrix =
5195 AnalyzeElements(stl_container.begin(), stl_container.end(),
5196 &element_printouts, listener);
5197
5198 if (matrix.LhsSize() == 0 && matrix.RhsSize() == 0) {
5199 return true;
5200 }
5201
5202 if (match_flags() == UnorderedMatcherRequire::ExactMatch) {
5203 if (matrix.LhsSize() != matrix.RhsSize()) {
5204 // The element count doesn't match. If the container is empty,
5205 // there's no need to explain anything as Google Mock already
5206 // prints the empty container. Otherwise we just need to show
5207 // how many elements there actually are.
5208 if (matrix.LhsSize() != 0 && listener->IsInterested()) {
5209 *listener << "which has " << Elements(matrix.LhsSize());
5210 }
5211 return false;
5212 }
5213 }
5214
5215 return VerifyMatchMatrix(element_printouts, matrix, listener) &&
5216 FindPairing(matrix, listener);
5217 }
5218
5219 private:
5220 template <typename ElementIter>
5221 MatchMatrix AnalyzeElements(ElementIter elem_first, ElementIter elem_last,
5222 ::std::vector<std::string>* element_printouts,
5223 MatchResultListener* listener) const {
5224 element_printouts->clear();
5225 ::std::vector<char> did_match;
5226 size_t num_elements = 0;
5227 for (; elem_first != elem_last; ++num_elements, ++elem_first) {
5228 if (listener->IsInterested()) {
5229 element_printouts->push_back(PrintToString(*elem_first));
5230 }
5231 for (size_t irhs = 0; irhs != matchers_.size(); ++irhs) {
5232 did_match.push_back(Matches(matchers_[irhs])(*elem_first));
5233 }
5234 }
5235
5236 MatchMatrix matrix(num_elements, matchers_.size());
5237 ::std::vector<char>::const_iterator did_match_iter = did_match.begin();
5238 for (size_t ilhs = 0; ilhs != num_elements; ++ilhs) {
5239 for (size_t irhs = 0; irhs != matchers_.size(); ++irhs) {
5240 matrix.SetEdge(ilhs, irhs, *did_match_iter++ != 0);
5241 }
5242 }
5243 return matrix;
5244 }
5245
5246 ::std::vector<Matcher<const Element&> > matchers_;
5247
5248 GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreMatcherImpl);
5249};
5250
5251// Functor for use in TransformTuple.
5252// Performs MatcherCast<Target> on an input argument of any type.
5253template <typename Target>
5254struct CastAndAppendTransform {
5255 template <typename Arg>
5256 Matcher<Target> operator()(const Arg& a) const {
5257 return MatcherCast<Target>(a);
5258 }
5259};
5260
5261// Implements UnorderedElementsAre.
5262template <typename MatcherTuple>
5263class UnorderedElementsAreMatcher {
5264 public:
5265 explicit UnorderedElementsAreMatcher(const MatcherTuple& args)
5266 : matchers_(args) {}
5267
5268 template <typename Container>
5269 operator Matcher<Container>() const {
5270 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
5271 typedef typename internal::StlContainerView<RawContainer>::type View;
5272 typedef typename View::value_type Element;
5273 typedef ::std::vector<Matcher<const Element&> > MatcherVec;
5274 MatcherVec matchers;
5275 matchers.reserve(::std::tuple_size<MatcherTuple>::value);
5276 TransformTupleValues(CastAndAppendTransform<const Element&>(), matchers_,
5277 ::std::back_inserter(matchers));
5278 return Matcher<Container>(
5279 new UnorderedElementsAreMatcherImpl<const Container&>(
5280 UnorderedMatcherRequire::ExactMatch, matchers.begin(),
5281 matchers.end()));
5282 }
5283
5284 private:
5285 const MatcherTuple matchers_;
5286 GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreMatcher);
5287};
5288
5289// Implements ElementsAre.
5290template <typename MatcherTuple>
5291class ElementsAreMatcher {
5292 public:
5293 explicit ElementsAreMatcher(const MatcherTuple& args) : matchers_(args) {}
5294
5295 template <typename Container>
5296 operator Matcher<Container>() const {
5297 GTEST_COMPILE_ASSERT_(
5298 !IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(Container)>::value ||
5299 ::std::tuple_size<MatcherTuple>::value < 2,
5300 use_UnorderedElementsAre_with_hash_tables);
5301
5302 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
5303 typedef typename internal::StlContainerView<RawContainer>::type View;
5304 typedef typename View::value_type Element;
5305 typedef ::std::vector<Matcher<const Element&> > MatcherVec;
5306 MatcherVec matchers;
5307 matchers.reserve(::std::tuple_size<MatcherTuple>::value);
5308 TransformTupleValues(CastAndAppendTransform<const Element&>(), matchers_,
5309 ::std::back_inserter(matchers));
5310 return Matcher<Container>(new ElementsAreMatcherImpl<const Container&>(
5311 matchers.begin(), matchers.end()));
5312 }
5313
5314 private:
5315 const MatcherTuple matchers_;
5316 GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher);
5317};
5318
5319// Implements UnorderedElementsAreArray(), IsSubsetOf(), and IsSupersetOf().
5320template <typename T>
5321class UnorderedElementsAreArrayMatcher {
5322 public:
5323 template <typename Iter>
5324 UnorderedElementsAreArrayMatcher(UnorderedMatcherRequire::Flags match_flags,
5325 Iter first, Iter last)
5326 : match_flags_(match_flags), matchers_(first, last) {}
5327
5328 template <typename Container>
5329 operator Matcher<Container>() const {
5330 return Matcher<Container>(
5331 new UnorderedElementsAreMatcherImpl<const Container&>(
5332 match_flags_, matchers_.begin(), matchers_.end()));
5333 }
5334
5335 private:
5336 UnorderedMatcherRequire::Flags match_flags_;
5337 ::std::vector<T> matchers_;
5338
5339 GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreArrayMatcher);
5340};
5341
5342// Implements ElementsAreArray().
5343template <typename T>
5344class ElementsAreArrayMatcher {
5345 public:
5346 template <typename Iter>
5347 ElementsAreArrayMatcher(Iter first, Iter last) : matchers_(first, last) {}
5348
5349 template <typename Container>
5350 operator Matcher<Container>() const {
5351 GTEST_COMPILE_ASSERT_(
5352 !IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(Container)>::value,
5353 use_UnorderedElementsAreArray_with_hash_tables);
5354
5355 return Matcher<Container>(new ElementsAreMatcherImpl<const Container&>(
5356 matchers_.begin(), matchers_.end()));
5357 }
5358
5359 private:
5360 const ::std::vector<T> matchers_;
5361
5362 GTEST_DISALLOW_ASSIGN_(ElementsAreArrayMatcher);
5363};
5364
5365// Given a 2-tuple matcher tm of type Tuple2Matcher and a value second
5366// of type Second, BoundSecondMatcher<Tuple2Matcher, Second>(tm,
5367// second) is a polymorphic matcher that matches a value x iff tm
5368// matches tuple (x, second). Useful for implementing
5369// UnorderedPointwise() in terms of UnorderedElementsAreArray().
5370//
5371// BoundSecondMatcher is copyable and assignable, as we need to put
5372// instances of this class in a vector when implementing
5373// UnorderedPointwise().
5374template <typename Tuple2Matcher, typename Second>
5375class BoundSecondMatcher {
5376 public:
5377 BoundSecondMatcher(const Tuple2Matcher& tm, const Second& second)
5378 : tuple2_matcher_(tm), second_value_(second) {}
5379
5380 template <typename T>
5381 operator Matcher<T>() const {
5382 return MakeMatcher(new Impl<T>(tuple2_matcher_, second_value_));
5383 }
5384
5385 // We have to define this for UnorderedPointwise() to compile in
5386 // C++98 mode, as it puts BoundSecondMatcher instances in a vector,
5387 // which requires the elements to be assignable in C++98. The
5388 // compiler cannot generate the operator= for us, as Tuple2Matcher
5389 // and Second may not be assignable.
5390 //
5391 // However, this should never be called, so the implementation just
5392 // need to assert.
5393 void operator=(const BoundSecondMatcher& /*rhs*/) {
5394 GTEST_LOG_(FATAL) << "BoundSecondMatcher should never be assigned.";
5395 }
5396
5397 private:
5398 template <typename T>
5399 class Impl : public MatcherInterface<T> {
5400 public:
5401 typedef ::std::tuple<T, Second> ArgTuple;
5402
5403 Impl(const Tuple2Matcher& tm, const Second& second)
5404 : mono_tuple2_matcher_(SafeMatcherCast<const ArgTuple&>(tm)),
5405 second_value_(second) {}
5406
5407 void DescribeTo(::std::ostream* os) const override {
5408 *os << "and ";
5409 UniversalPrint(second_value_, os);
5410 *os << " ";
5411 mono_tuple2_matcher_.DescribeTo(os);
5412 }
5413
5414 bool MatchAndExplain(T x, MatchResultListener* listener) const override {
5415 return mono_tuple2_matcher_.MatchAndExplain(ArgTuple(x, second_value_),
5416 listener);
5417 }
5418
5419 private:
5420 const Matcher<const ArgTuple&> mono_tuple2_matcher_;
5421 const Second second_value_;
5422
5423 GTEST_DISALLOW_ASSIGN_(Impl);
5424 };
5425
5426 const Tuple2Matcher tuple2_matcher_;
5427 const Second second_value_;
5428};
5429
5430// Given a 2-tuple matcher tm and a value second,
5431// MatcherBindSecond(tm, second) returns a matcher that matches a
5432// value x iff tm matches tuple (x, second). Useful for implementing
5433// UnorderedPointwise() in terms of UnorderedElementsAreArray().
5434template <typename Tuple2Matcher, typename Second>
5435BoundSecondMatcher<Tuple2Matcher, Second> MatcherBindSecond(
5436 const Tuple2Matcher& tm, const Second& second) {
5437 return BoundSecondMatcher<Tuple2Matcher, Second>(tm, second);
5438}
5439
5440// Returns the description for a matcher defined using the MATCHER*()
5441// macro where the user-supplied description string is "", if
5442// 'negation' is false; otherwise returns the description of the
5443// negation of the matcher. 'param_values' contains a list of strings
5444// that are the print-out of the matcher's parameters.
5445GTEST_API_ std::string FormatMatcherDescription(bool negation,
5446 const char* matcher_name,
5447 const Strings& param_values);
5448
5449// Implements a matcher that checks the value of a optional<> type variable.
5450template <typename ValueMatcher>
5451class OptionalMatcher {
5452 public:
5453 explicit OptionalMatcher(const ValueMatcher& value_matcher)
5454 : value_matcher_(value_matcher) {}
5455
5456 template <typename Optional>
5457 operator Matcher<Optional>() const {
5458 return Matcher<Optional>(new Impl<const Optional&>(value_matcher_));
5459 }
5460
5461 template <typename Optional>
5462 class Impl : public MatcherInterface<Optional> {
5463 public:
5464 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Optional) OptionalView;
5465 typedef typename OptionalView::value_type ValueType;
5466 explicit Impl(const ValueMatcher& value_matcher)
5467 : value_matcher_(MatcherCast<ValueType>(value_matcher)) {}
5468
5469 void DescribeTo(::std::ostream* os) const override {
5470 *os << "value ";
5471 value_matcher_.DescribeTo(os);
5472 }
5473
5474 void DescribeNegationTo(::std::ostream* os) const override {
5475 *os << "value ";
5476 value_matcher_.DescribeNegationTo(os);
5477 }
5478
5479 bool MatchAndExplain(Optional optional,
5480 MatchResultListener* listener) const override {
5481 if (!optional) {
5482 *listener << "which is not engaged";
5483 return false;
5484 }
5485 const ValueType& value = *optional;
5486 StringMatchResultListener value_listener;
5487 const bool match = value_matcher_.MatchAndExplain(value, &value_listener);
5488 *listener << "whose value " << PrintToString(value)
5489 << (match ? " matches" : " doesn't match");
5490 PrintIfNotEmpty(value_listener.str(), listener->stream());
5491 return match;
5492 }
5493
5494 private:
5495 const Matcher<ValueType> value_matcher_;
5496 GTEST_DISALLOW_ASSIGN_(Impl);
5497 };
5498
5499 private:
5500 const ValueMatcher value_matcher_;
5501 GTEST_DISALLOW_ASSIGN_(OptionalMatcher);
5502};
5503
5504namespace variant_matcher {
5505// Overloads to allow VariantMatcher to do proper ADL lookup.
5506template <typename T>
5507void holds_alternative() {}
5508template <typename T>
5509void get() {}
5510
5511// Implements a matcher that checks the value of a variant<> type variable.
5512template <typename T>
5513class VariantMatcher {
5514 public:
5515 explicit VariantMatcher(::testing::Matcher<const T&> matcher)
5516 : matcher_(std::move(matcher)) {}
5517
5518 template <typename Variant>
5519 bool MatchAndExplain(const Variant& value,
5520 ::testing::MatchResultListener* listener) const {
5521 using std::get;
5522 if (!listener->IsInterested()) {
5523 return holds_alternative<T>(value) && matcher_.Matches(get<T>(value));
5524 }
5525
5526 if (!holds_alternative<T>(value)) {
5527 *listener << "whose value is not of type '" << GetTypeName() << "'";
5528 return false;
5529 }
5530
5531 const T& elem = get<T>(value);
5532 StringMatchResultListener elem_listener;
5533 const bool match = matcher_.MatchAndExplain(elem, &elem_listener);
5534 *listener << "whose value " << PrintToString(elem)
5535 << (match ? " matches" : " doesn't match");
5536 PrintIfNotEmpty(elem_listener.str(), listener->stream());
5537 return match;
5538 }
5539
5540 void DescribeTo(std::ostream* os) const {
5541 *os << "is a variant<> with value of type '" << GetTypeName()
5542 << "' and the value ";
5543 matcher_.DescribeTo(os);
5544 }
5545
5546 void DescribeNegationTo(std::ostream* os) const {
5547 *os << "is a variant<> with value of type other than '" << GetTypeName()
5548 << "' or the value ";
5549 matcher_.DescribeNegationTo(os);
5550 }
5551
5552 private:
5553 static std::string GetTypeName() {
5554#if GTEST_HAS_RTTI
5555 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(
5556 return internal::GetTypeName<T>());
5557#endif
5558 return "the element type";
5559 }
5560
5561 const ::testing::Matcher<const T&> matcher_;
5562};
5563
5564} // namespace variant_matcher
5565
5566namespace any_cast_matcher {
5567
5568// Overloads to allow AnyCastMatcher to do proper ADL lookup.
5569template <typename T>
5570void any_cast() {}
5571
5572// Implements a matcher that any_casts the value.
5573template <typename T>
5574class AnyCastMatcher {
5575 public:
5576 explicit AnyCastMatcher(const ::testing::Matcher<const T&>& matcher)
5577 : matcher_(matcher) {}
5578
5579 template <typename AnyType>
5580 bool MatchAndExplain(const AnyType& value,
5581 ::testing::MatchResultListener* listener) const {
5582 if (!listener->IsInterested()) {
5583 const T* ptr = any_cast<T>(&value);
5584 return ptr != nullptr && matcher_.Matches(*ptr);
5585 }
5586
5587 const T* elem = any_cast<T>(&value);
5588 if (elem == nullptr) {
5589 *listener << "whose value is not of type '" << GetTypeName() << "'";
5590 return false;
5591 }
5592
5593 StringMatchResultListener elem_listener;
5594 const bool match = matcher_.MatchAndExplain(*elem, &elem_listener);
5595 *listener << "whose value " << PrintToString(*elem)
5596 << (match ? " matches" : " doesn't match");
5597 PrintIfNotEmpty(elem_listener.str(), listener->stream());
5598 return match;
5599 }
5600
5601 void DescribeTo(std::ostream* os) const {
5602 *os << "is an 'any' type with value of type '" << GetTypeName()
5603 << "' and the value ";
5604 matcher_.DescribeTo(os);
5605 }
5606
5607 void DescribeNegationTo(std::ostream* os) const {
5608 *os << "is an 'any' type with value of type other than '" << GetTypeName()
5609 << "' or the value ";
5610 matcher_.DescribeNegationTo(os);
5611 }
5612
5613 private:
5614 static std::string GetTypeName() {
5615#if GTEST_HAS_RTTI
5616 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(
5617 return internal::GetTypeName<T>());
5618#endif
5619 return "the element type";
5620 }
5621
5622 const ::testing::Matcher<const T&> matcher_;
5623};
5624
5625} // namespace any_cast_matcher
5626
5627// Implements the Args() matcher.
5628template <class ArgsTuple, size_t... k>
5629class ArgsMatcherImpl : public MatcherInterface<ArgsTuple> {
5630 public:
5631 using RawArgsTuple = typename std::decay<ArgsTuple>::type;
5632 using SelectedArgs =
5633 std::tuple<typename std::tuple_element<k, RawArgsTuple>::type...>;
5634 using MonomorphicInnerMatcher = Matcher<const SelectedArgs&>;
5635
5636 template <typename InnerMatcher>
5637 explicit ArgsMatcherImpl(const InnerMatcher& inner_matcher)
5638 : inner_matcher_(SafeMatcherCast<const SelectedArgs&>(inner_matcher)) {}
5639
5640 bool MatchAndExplain(ArgsTuple args,
5641 MatchResultListener* listener) const override {
5642 // Workaround spurious C4100 on MSVC<=15.7 when k is empty.
5643 (void)args;
5644 const SelectedArgs& selected_args =
5645 std::forward_as_tuple(std::get<k>(args)...);
5646 if (!listener->IsInterested()) return inner_matcher_.Matches(selected_args);
5647
5648 PrintIndices(listener->stream());
5649 *listener << "are " << PrintToString(selected_args);
5650
5651 StringMatchResultListener inner_listener;
5652 const bool match =
5653 inner_matcher_.MatchAndExplain(selected_args, &inner_listener);
5654 PrintIfNotEmpty(inner_listener.str(), listener->stream());
5655 return match;
5656 }
5657
5658 void DescribeTo(::std::ostream* os) const override {
5659 *os << "are a tuple ";
5660 PrintIndices(os);
5661 inner_matcher_.DescribeTo(os);
5662 }
5663
5664 void DescribeNegationTo(::std::ostream* os) const override {
5665 *os << "are a tuple ";
5666 PrintIndices(os);
5667 inner_matcher_.DescribeNegationTo(os);
5668 }
5669
5670 private:
5671 // Prints the indices of the selected fields.
5672 static void PrintIndices(::std::ostream* os) {
5673 *os << "whose fields (";
5674 const char* sep = "";
5675 // Workaround spurious C4189 on MSVC<=15.7 when k is empty.
5676 (void)sep;
5677 const char* dummy[] = {"", (*os << sep << "#" << k, sep = ", ")...};
5678 (void)dummy;
5679 *os << ") ";
5680 }
5681
5682 MonomorphicInnerMatcher inner_matcher_;
5683};
5684
5685template <class InnerMatcher, size_t... k>
5686class ArgsMatcher {
5687 public:
5688 explicit ArgsMatcher(InnerMatcher inner_matcher)
5689 : inner_matcher_(std::move(inner_matcher)) {}
5690
5691 template <typename ArgsTuple>
5692 operator Matcher<ArgsTuple>() const { // NOLINT
5693 return MakeMatcher(new ArgsMatcherImpl<ArgsTuple, k...>(inner_matcher_));
5694 }
5695
5696 private:
5697 InnerMatcher inner_matcher_;
5698};
5699
5700} // namespace internal
5701
5702// ElementsAreArray(iterator_first, iterator_last)
5703// ElementsAreArray(pointer, count)
5704// ElementsAreArray(array)
5705// ElementsAreArray(container)
5706// ElementsAreArray({ e1, e2, ..., en })
5707//
5708// The ElementsAreArray() functions are like ElementsAre(...), except
5709// that they are given a homogeneous sequence rather than taking each
5710// element as a function argument. The sequence can be specified as an
5711// array, a pointer and count, a vector, an initializer list, or an
5712// STL iterator range. In each of these cases, the underlying sequence
5713// can be either a sequence of values or a sequence of matchers.
5714//
5715// All forms of ElementsAreArray() make a copy of the input matcher sequence.
5716
5717template <typename Iter>
5718inline internal::ElementsAreArrayMatcher<
5719 typename ::std::iterator_traits<Iter>::value_type>
5720ElementsAreArray(Iter first, Iter last) {
5721 typedef typename ::std::iterator_traits<Iter>::value_type T;
5722 return internal::ElementsAreArrayMatcher<T>(first, last);
5723}
5724
5725template <typename T>
5726inline internal::ElementsAreArrayMatcher<T> ElementsAreArray(
5727 const T* pointer, size_t count) {
5728 return ElementsAreArray(pointer, pointer + count);
5729}
5730
5731template <typename T, size_t N>
5732inline internal::ElementsAreArrayMatcher<T> ElementsAreArray(
5733 const T (&array)[N]) {
5734 return ElementsAreArray(array, N);
5735}
5736
5737template <typename Container>
5738inline internal::ElementsAreArrayMatcher<typename Container::value_type>
5739ElementsAreArray(const Container& container) {
5740 return ElementsAreArray(container.begin(), container.end());
5741}
5742
5743template <typename T>
5744inline internal::ElementsAreArrayMatcher<T>
5745ElementsAreArray(::std::initializer_list<T> xs) {
5746 return ElementsAreArray(xs.begin(), xs.end());
5747}
5748
5749// UnorderedElementsAreArray(iterator_first, iterator_last)
5750// UnorderedElementsAreArray(pointer, count)
5751// UnorderedElementsAreArray(array)
5752// UnorderedElementsAreArray(container)
5753// UnorderedElementsAreArray({ e1, e2, ..., en })
5754//
5755// UnorderedElementsAreArray() verifies that a bijective mapping onto a
5756// collection of matchers exists.
5757//
5758// The matchers can be specified as an array, a pointer and count, a container,
5759// an initializer list, or an STL iterator range. In each of these cases, the
5760// underlying matchers can be either values or matchers.
5761
5762template <typename Iter>
5763inline internal::UnorderedElementsAreArrayMatcher<
5764 typename ::std::iterator_traits<Iter>::value_type>
5765UnorderedElementsAreArray(Iter first, Iter last) {
5766 typedef typename ::std::iterator_traits<Iter>::value_type T;
5767 return internal::UnorderedElementsAreArrayMatcher<T>(
5768 internal::UnorderedMatcherRequire::ExactMatch, first, last);
5769}
5770
5771template <typename T>
5772inline internal::UnorderedElementsAreArrayMatcher<T>
5773UnorderedElementsAreArray(const T* pointer, size_t count) {
5774 return UnorderedElementsAreArray(pointer, pointer + count);
5775}
5776
5777template <typename T, size_t N>
5778inline internal::UnorderedElementsAreArrayMatcher<T>
5779UnorderedElementsAreArray(const T (&array)[N]) {
5780 return UnorderedElementsAreArray(array, N);
5781}
5782
5783template <typename Container>
5784inline internal::UnorderedElementsAreArrayMatcher<
5785 typename Container::value_type>
5786UnorderedElementsAreArray(const Container& container) {
5787 return UnorderedElementsAreArray(container.begin(), container.end());
5788}
5789
5790template <typename T>
5791inline internal::UnorderedElementsAreArrayMatcher<T>
5792UnorderedElementsAreArray(::std::initializer_list<T> xs) {
5793 return UnorderedElementsAreArray(xs.begin(), xs.end());
5794}
5795
5796// _ is a matcher that matches anything of any type.
5797//
5798// This definition is fine as:
5799//
5800// 1. The C++ standard permits using the name _ in a namespace that
5801// is not the global namespace or ::std.
5802// 2. The AnythingMatcher class has no data member or constructor,
5803// so it's OK to create global variables of this type.
5804// 3. c-style has approved of using _ in this case.
5805const internal::AnythingMatcher _ = {};
5806// Creates a matcher that matches any value of the given type T.
5807template <typename T>
5808inline Matcher<T> A() {
5809 return Matcher<T>(new internal::AnyMatcherImpl<T>());
5810}
5811
5812// Creates a matcher that matches any value of the given type T.
5813template <typename T>
5814inline Matcher<T> An() { return A<T>(); }
5815
5816template <typename T, typename M>
5817Matcher<T> internal::MatcherCastImpl<T, M>::CastImpl(
5818 const M& value,
5819 internal::BooleanConstant<false> /* convertible_to_matcher */,
5820 internal::BooleanConstant<false> /* convertible_to_T */) {
5821 return Eq(value);
5822}
5823
5824// Creates a polymorphic matcher that matches any NULL pointer.
5825inline PolymorphicMatcher<internal::IsNullMatcher > IsNull() {
5826 return MakePolymorphicMatcher(internal::IsNullMatcher());
5827}
5828
5829// Creates a polymorphic matcher that matches any non-NULL pointer.
5830// This is convenient as Not(NULL) doesn't compile (the compiler
5831// thinks that that expression is comparing a pointer with an integer).
5832inline PolymorphicMatcher<internal::NotNullMatcher > NotNull() {
5833 return MakePolymorphicMatcher(internal::NotNullMatcher());
5834}
5835
5836// Creates a polymorphic matcher that matches any argument that
5837// references variable x.
5838template <typename T>
5839inline internal::RefMatcher<T&> Ref(T& x) { // NOLINT
5840 return internal::RefMatcher<T&>(x);
5841}
5842
5843// Creates a matcher that matches any double argument approximately
5844// equal to rhs, where two NANs are considered unequal.
5845inline internal::FloatingEqMatcher<double> DoubleEq(double rhs) {
5846 return internal::FloatingEqMatcher<double>(rhs, false);
5847}
5848
5849// Creates a matcher that matches any double argument approximately
5850// equal to rhs, including NaN values when rhs is NaN.
5851inline internal::FloatingEqMatcher<double> NanSensitiveDoubleEq(double rhs) {
5852 return internal::FloatingEqMatcher<double>(rhs, true);
5853}
5854
5855// Creates a matcher that matches any double argument approximately equal to
5856// rhs, up to the specified max absolute error bound, where two NANs are
5857// considered unequal. The max absolute error bound must be non-negative.
5858inline internal::FloatingEqMatcher<double> DoubleNear(
5859 double rhs, double max_abs_error) {
5860 return internal::FloatingEqMatcher<double>(rhs, false, max_abs_error);
5861}
5862
5863// Creates a matcher that matches any double argument approximately equal to
5864// rhs, up to the specified max absolute error bound, including NaN values when
5865// rhs is NaN. The max absolute error bound must be non-negative.
5866inline internal::FloatingEqMatcher<double> NanSensitiveDoubleNear(
5867 double rhs, double max_abs_error) {
5868 return internal::FloatingEqMatcher<double>(rhs, true, max_abs_error);
5869}
5870
5871// Creates a matcher that matches any float argument approximately
5872// equal to rhs, where two NANs are considered unequal.
5873inline internal::FloatingEqMatcher<float> FloatEq(float rhs) {
5874 return internal::FloatingEqMatcher<float>(rhs, false);
5875}
5876
5877// Creates a matcher that matches any float argument approximately
5878// equal to rhs, including NaN values when rhs is NaN.
5879inline internal::FloatingEqMatcher<float> NanSensitiveFloatEq(float rhs) {
5880 return internal::FloatingEqMatcher<float>(rhs, true);
5881}
5882
5883// Creates a matcher that matches any float argument approximately equal to
5884// rhs, up to the specified max absolute error bound, where two NANs are
5885// considered unequal. The max absolute error bound must be non-negative.
5886inline internal::FloatingEqMatcher<float> FloatNear(
5887 float rhs, float max_abs_error) {
5888 return internal::FloatingEqMatcher<float>(rhs, false, max_abs_error);
5889}
5890
5891// Creates a matcher that matches any float argument approximately equal to
5892// rhs, up to the specified max absolute error bound, including NaN values when
5893// rhs is NaN. The max absolute error bound must be non-negative.
5894inline internal::FloatingEqMatcher<float> NanSensitiveFloatNear(
5895 float rhs, float max_abs_error) {
5896 return internal::FloatingEqMatcher<float>(rhs, true, max_abs_error);
5897}
5898
5899// Creates a matcher that matches a pointer (raw or smart) that points
5900// to a value that matches inner_matcher.
5901template <typename InnerMatcher>
5902inline internal::PointeeMatcher<InnerMatcher> Pointee(
5903 const InnerMatcher& inner_matcher) {
5904 return internal::PointeeMatcher<InnerMatcher>(inner_matcher);
5905}
5906
5907#if GTEST_HAS_RTTI
5908// Creates a matcher that matches a pointer or reference that matches
5909// inner_matcher when dynamic_cast<To> is applied.
5910// The result of dynamic_cast<To> is forwarded to the inner matcher.
5911// If To is a pointer and the cast fails, the inner matcher will receive NULL.
5912// If To is a reference and the cast fails, this matcher returns false
5913// immediately.
5914template <typename To>
5915inline PolymorphicMatcher<internal::WhenDynamicCastToMatcher<To> >
5916WhenDynamicCastTo(const Matcher<To>& inner_matcher) {
5917 return MakePolymorphicMatcher(
5918 internal::WhenDynamicCastToMatcher<To>(inner_matcher));
5919}
5920#endif // GTEST_HAS_RTTI
5921
5922// Creates a matcher that matches an object whose given field matches
5923// 'matcher'. For example,
5924// Field(&Foo::number, Ge(5))
5925// matches a Foo object x iff x.number >= 5.
5926template <typename Class, typename FieldType, typename FieldMatcher>
5927inline PolymorphicMatcher<
5928 internal::FieldMatcher<Class, FieldType> > Field(
5929 FieldType Class::*field, const FieldMatcher& matcher) {
5930 return MakePolymorphicMatcher(
5931 internal::FieldMatcher<Class, FieldType>(
5932 field, MatcherCast<const FieldType&>(matcher)));
5933 // The call to MatcherCast() is required for supporting inner
5934 // matchers of compatible types. For example, it allows
5935 // Field(&Foo::bar, m)
5936 // to compile where bar is an int32 and m is a matcher for int64.
5937}
5938
5939// Same as Field() but also takes the name of the field to provide better error
5940// messages.
5941template <typename Class, typename FieldType, typename FieldMatcher>
5942inline PolymorphicMatcher<internal::FieldMatcher<Class, FieldType> > Field(
5943 const std::string& field_name, FieldType Class::*field,
5944 const FieldMatcher& matcher) {
5945 return MakePolymorphicMatcher(internal::FieldMatcher<Class, FieldType>(
5946 field_name, field, MatcherCast<const FieldType&>(matcher)));
5947}
5948
5949// Creates a matcher that matches an object whose given property
5950// matches 'matcher'. For example,
5951// Property(&Foo::str, StartsWith("hi"))
5952// matches a Foo object x iff x.str() starts with "hi".
5953template <typename Class, typename PropertyType, typename PropertyMatcher>
5954inline PolymorphicMatcher<internal::PropertyMatcher<
5955 Class, PropertyType, PropertyType (Class::*)() const> >
5956Property(PropertyType (Class::*property)() const,
5957 const PropertyMatcher& matcher) {
5958 return MakePolymorphicMatcher(
5959 internal::PropertyMatcher<Class, PropertyType,
5960 PropertyType (Class::*)() const>(
5961 property, MatcherCast<const PropertyType&>(matcher)));
5962 // The call to MatcherCast() is required for supporting inner
5963 // matchers of compatible types. For example, it allows
5964 // Property(&Foo::bar, m)
5965 // to compile where bar() returns an int32 and m is a matcher for int64.
5966}
5967
5968// Same as Property() above, but also takes the name of the property to provide
5969// better error messages.
5970template <typename Class, typename PropertyType, typename PropertyMatcher>
5971inline PolymorphicMatcher<internal::PropertyMatcher<
5972 Class, PropertyType, PropertyType (Class::*)() const> >
5973Property(const std::string& property_name,
5974 PropertyType (Class::*property)() const,
5975 const PropertyMatcher& matcher) {
5976 return MakePolymorphicMatcher(
5977 internal::PropertyMatcher<Class, PropertyType,
5978 PropertyType (Class::*)() const>(
5979 property_name, property, MatcherCast<const PropertyType&>(matcher)));
5980}
5981
5982// The same as above but for reference-qualified member functions.
5983template <typename Class, typename PropertyType, typename PropertyMatcher>
5984inline PolymorphicMatcher<internal::PropertyMatcher<
5985 Class, PropertyType, PropertyType (Class::*)() const &> >
5986Property(PropertyType (Class::*property)() const &,
5987 const PropertyMatcher& matcher) {
5988 return MakePolymorphicMatcher(
5989 internal::PropertyMatcher<Class, PropertyType,
5990 PropertyType (Class::*)() const&>(
5991 property, MatcherCast<const PropertyType&>(matcher)));
5992}
5993
5994// Three-argument form for reference-qualified member functions.
5995template <typename Class, typename PropertyType, typename PropertyMatcher>
5996inline PolymorphicMatcher<internal::PropertyMatcher<
5997 Class, PropertyType, PropertyType (Class::*)() const &> >
5998Property(const std::string& property_name,
5999 PropertyType (Class::*property)() const &,
6000 const PropertyMatcher& matcher) {
6001 return MakePolymorphicMatcher(
6002 internal::PropertyMatcher<Class, PropertyType,
6003 PropertyType (Class::*)() const&>(
6004 property_name, property, MatcherCast<const PropertyType&>(matcher)));
6005}
6006
6007// Creates a matcher that matches an object iff the result of applying
6008// a callable to x matches 'matcher'.
6009// For example,
6010// ResultOf(f, StartsWith("hi"))
6011// matches a Foo object x iff f(x) starts with "hi".
6012// `callable` parameter can be a function, function pointer, or a functor. It is
6013// required to keep no state affecting the results of the calls on it and make
6014// no assumptions about how many calls will be made. Any state it keeps must be
6015// protected from the concurrent access.
6016template <typename Callable, typename InnerMatcher>
6017internal::ResultOfMatcher<Callable, InnerMatcher> ResultOf(
6018 Callable callable, InnerMatcher matcher) {
6019 return internal::ResultOfMatcher<Callable, InnerMatcher>(
6020 std::move(callable), std::move(matcher));
6021}
6022
6023// String matchers.
6024
6025// Matches a string equal to str.
6026inline PolymorphicMatcher<internal::StrEqualityMatcher<std::string> > StrEq(
6027 const std::string& str) {
6028 return MakePolymorphicMatcher(
6029 internal::StrEqualityMatcher<std::string>(str, true, true));
6030}
6031
6032// Matches a string not equal to str.
6033inline PolymorphicMatcher<internal::StrEqualityMatcher<std::string> > StrNe(
6034 const std::string& str) {
6035 return MakePolymorphicMatcher(
6036 internal::StrEqualityMatcher<std::string>(str, false, true));
6037}
6038
6039// Matches a string equal to str, ignoring case.
6040inline PolymorphicMatcher<internal::StrEqualityMatcher<std::string> > StrCaseEq(
6041 const std::string& str) {
6042 return MakePolymorphicMatcher(
6043 internal::StrEqualityMatcher<std::string>(str, true, false));
6044}
6045
6046// Matches a string not equal to str, ignoring case.
6047inline PolymorphicMatcher<internal::StrEqualityMatcher<std::string> > StrCaseNe(
6048 const std::string& str) {
6049 return MakePolymorphicMatcher(
6050 internal::StrEqualityMatcher<std::string>(str, false, false));
6051}
6052
6053// Creates a matcher that matches any string, std::string, or C string
6054// that contains the given substring.
6055inline PolymorphicMatcher<internal::HasSubstrMatcher<std::string> > HasSubstr(
6056 const std::string& substring) {
6057 return MakePolymorphicMatcher(
6058 internal::HasSubstrMatcher<std::string>(substring));
6059}
6060
6061// Matches a string that starts with 'prefix' (case-sensitive).
6062inline PolymorphicMatcher<internal::StartsWithMatcher<std::string> > StartsWith(
6063 const std::string& prefix) {
6064 return MakePolymorphicMatcher(
6065 internal::StartsWithMatcher<std::string>(prefix));
6066}
6067
6068// Matches a string that ends with 'suffix' (case-sensitive).
6069inline PolymorphicMatcher<internal::EndsWithMatcher<std::string> > EndsWith(
6070 const std::string& suffix) {
6071 return MakePolymorphicMatcher(internal::EndsWithMatcher<std::string>(suffix));
6072}
6073
6074#if GTEST_HAS_GLOBAL_WSTRING || GTEST_HAS_STD_WSTRING
6075// Wide string matchers.
6076
6077// Matches a string equal to str.
6078inline PolymorphicMatcher<internal::StrEqualityMatcher<std::wstring> > StrEq(
6079 const std::wstring& str) {
6080 return MakePolymorphicMatcher(
6081 internal::StrEqualityMatcher<std::wstring>(str, true, true));
6082}
6083
6084// Matches a string not equal to str.
6085inline PolymorphicMatcher<internal::StrEqualityMatcher<std::wstring> > StrNe(
6086 const std::wstring& str) {
6087 return MakePolymorphicMatcher(
6088 internal::StrEqualityMatcher<std::wstring>(str, false, true));
6089}
6090
6091// Matches a string equal to str, ignoring case.
6092inline PolymorphicMatcher<internal::StrEqualityMatcher<std::wstring> >
6093StrCaseEq(const std::wstring& str) {
6094 return MakePolymorphicMatcher(
6095 internal::StrEqualityMatcher<std::wstring>(str, true, false));
6096}
6097
6098// Matches a string not equal to str, ignoring case.
6099inline PolymorphicMatcher<internal::StrEqualityMatcher<std::wstring> >
6100StrCaseNe(const std::wstring& str) {
6101 return MakePolymorphicMatcher(
6102 internal::StrEqualityMatcher<std::wstring>(str, false, false));
6103}
6104
6105// Creates a matcher that matches any ::wstring, std::wstring, or C wide string
6106// that contains the given substring.
6107inline PolymorphicMatcher<internal::HasSubstrMatcher<std::wstring> > HasSubstr(
6108 const std::wstring& substring) {
6109 return MakePolymorphicMatcher(
6110 internal::HasSubstrMatcher<std::wstring>(substring));
6111}
6112
6113// Matches a string that starts with 'prefix' (case-sensitive).
6114inline PolymorphicMatcher<internal::StartsWithMatcher<std::wstring> >
6115StartsWith(const std::wstring& prefix) {
6116 return MakePolymorphicMatcher(
6117 internal::StartsWithMatcher<std::wstring>(prefix));
6118}
6119
6120// Matches a string that ends with 'suffix' (case-sensitive).
6121inline PolymorphicMatcher<internal::EndsWithMatcher<std::wstring> > EndsWith(
6122 const std::wstring& suffix) {
6123 return MakePolymorphicMatcher(
6124 internal::EndsWithMatcher<std::wstring>(suffix));
6125}
6126
6127#endif // GTEST_HAS_GLOBAL_WSTRING || GTEST_HAS_STD_WSTRING
6128
6129// Creates a polymorphic matcher that matches a 2-tuple where the
6130// first field == the second field.
6131inline internal::Eq2Matcher Eq() { return internal::Eq2Matcher(); }
6132
6133// Creates a polymorphic matcher that matches a 2-tuple where the
6134// first field >= the second field.
6135inline internal::Ge2Matcher Ge() { return internal::Ge2Matcher(); }
6136
6137// Creates a polymorphic matcher that matches a 2-tuple where the
6138// first field > the second field.
6139inline internal::Gt2Matcher Gt() { return internal::Gt2Matcher(); }
6140
6141// Creates a polymorphic matcher that matches a 2-tuple where the
6142// first field <= the second field.
6143inline internal::Le2Matcher Le() { return internal::Le2Matcher(); }
6144
6145// Creates a polymorphic matcher that matches a 2-tuple where the
6146// first field < the second field.
6147inline internal::Lt2Matcher Lt() { return internal::Lt2Matcher(); }
6148
6149// Creates a polymorphic matcher that matches a 2-tuple where the
6150// first field != the second field.
6151inline internal::Ne2Matcher Ne() { return internal::Ne2Matcher(); }
6152
6153// Creates a polymorphic matcher that matches a 2-tuple where
6154// FloatEq(first field) matches the second field.
6155inline internal::FloatingEq2Matcher<float> FloatEq() {
6156 return internal::FloatingEq2Matcher<float>();
6157}
6158
6159// Creates a polymorphic matcher that matches a 2-tuple where
6160// DoubleEq(first field) matches the second field.
6161inline internal::FloatingEq2Matcher<double> DoubleEq() {
6162 return internal::FloatingEq2Matcher<double>();
6163}
6164
6165// Creates a polymorphic matcher that matches a 2-tuple where
6166// FloatEq(first field) matches the second field with NaN equality.
6167inline internal::FloatingEq2Matcher<float> NanSensitiveFloatEq() {
6168 return internal::FloatingEq2Matcher<float>(true);
6169}
6170
6171// Creates a polymorphic matcher that matches a 2-tuple where
6172// DoubleEq(first field) matches the second field with NaN equality.
6173inline internal::FloatingEq2Matcher<double> NanSensitiveDoubleEq() {
6174 return internal::FloatingEq2Matcher<double>(true);
6175}
6176
6177// Creates a polymorphic matcher that matches a 2-tuple where
6178// FloatNear(first field, max_abs_error) matches the second field.
6179inline internal::FloatingEq2Matcher<float> FloatNear(float max_abs_error) {
6180 return internal::FloatingEq2Matcher<float>(max_abs_error);
6181}
6182
6183// Creates a polymorphic matcher that matches a 2-tuple where
6184// DoubleNear(first field, max_abs_error) matches the second field.
6185inline internal::FloatingEq2Matcher<double> DoubleNear(double max_abs_error) {
6186 return internal::FloatingEq2Matcher<double>(max_abs_error);
6187}
6188
6189// Creates a polymorphic matcher that matches a 2-tuple where
6190// FloatNear(first field, max_abs_error) matches the second field with NaN
6191// equality.
6192inline internal::FloatingEq2Matcher<float> NanSensitiveFloatNear(
6193 float max_abs_error) {
6194 return internal::FloatingEq2Matcher<float>(max_abs_error, true);
6195}
6196
6197// Creates a polymorphic matcher that matches a 2-tuple where
6198// DoubleNear(first field, max_abs_error) matches the second field with NaN
6199// equality.
6200inline internal::FloatingEq2Matcher<double> NanSensitiveDoubleNear(
6201 double max_abs_error) {
6202 return internal::FloatingEq2Matcher<double>(max_abs_error, true);
6203}
6204
6205// Creates a matcher that matches any value of type T that m doesn't
6206// match.
6207template <typename InnerMatcher>
6208inline internal::NotMatcher<InnerMatcher> Not(InnerMatcher m) {
6209 return internal::NotMatcher<InnerMatcher>(m);
6210}
6211
6212// Returns a matcher that matches anything that satisfies the given
6213// predicate. The predicate can be any unary function or functor
6214// whose return type can be implicitly converted to bool.
6215template <typename Predicate>
6216inline PolymorphicMatcher<internal::TrulyMatcher<Predicate> >
6217Truly(Predicate pred) {
6218 return MakePolymorphicMatcher(internal::TrulyMatcher<Predicate>(pred));
6219}
6220
6221// Returns a matcher that matches the container size. The container must
6222// support both size() and size_type which all STL-like containers provide.
6223// Note that the parameter 'size' can be a value of type size_type as well as
6224// matcher. For instance:
6225// EXPECT_THAT(container, SizeIs(2)); // Checks container has 2 elements.
6226// EXPECT_THAT(container, SizeIs(Le(2)); // Checks container has at most 2.
6227template <typename SizeMatcher>
6228inline internal::SizeIsMatcher<SizeMatcher>
6229SizeIs(const SizeMatcher& size_matcher) {
6230 return internal::SizeIsMatcher<SizeMatcher>(size_matcher);
6231}
6232
6233// Returns a matcher that matches the distance between the container's begin()
6234// iterator and its end() iterator, i.e. the size of the container. This matcher
6235// can be used instead of SizeIs with containers such as std::forward_list which
6236// do not implement size(). The container must provide const_iterator (with
6237// valid iterator_traits), begin() and end().
6238template <typename DistanceMatcher>
6239inline internal::BeginEndDistanceIsMatcher<DistanceMatcher>
6240BeginEndDistanceIs(const DistanceMatcher& distance_matcher) {
6241 return internal::BeginEndDistanceIsMatcher<DistanceMatcher>(distance_matcher);
6242}
6243
6244// Returns a matcher that matches an equal container.
6245// This matcher behaves like Eq(), but in the event of mismatch lists the
6246// values that are included in one container but not the other. (Duplicate
6247// values and order differences are not explained.)
6248template <typename Container>
6249inline PolymorphicMatcher<internal::ContainerEqMatcher< // NOLINT
6250 GTEST_REMOVE_CONST_(Container)> >
6251 ContainerEq(const Container& rhs) {
6252 // This following line is for working around a bug in MSVC 8.0,
6253 // which causes Container to be a const type sometimes.
6254 typedef GTEST_REMOVE_CONST_(Container) RawContainer;
6255 return MakePolymorphicMatcher(
6256 internal::ContainerEqMatcher<RawContainer>(rhs));
6257}
6258
6259// Returns a matcher that matches a container that, when sorted using
6260// the given comparator, matches container_matcher.
6261template <typename Comparator, typename ContainerMatcher>
6262inline internal::WhenSortedByMatcher<Comparator, ContainerMatcher>
6263WhenSortedBy(const Comparator& comparator,
6264 const ContainerMatcher& container_matcher) {
6265 return internal::WhenSortedByMatcher<Comparator, ContainerMatcher>(
6266 comparator, container_matcher);
6267}
6268
6269// Returns a matcher that matches a container that, when sorted using
6270// the < operator, matches container_matcher.
6271template <typename ContainerMatcher>
6272inline internal::WhenSortedByMatcher<internal::LessComparator, ContainerMatcher>
6273WhenSorted(const ContainerMatcher& container_matcher) {
6274 return
6275 internal::WhenSortedByMatcher<internal::LessComparator, ContainerMatcher>(
6276 internal::LessComparator(), container_matcher);
6277}
6278
6279// Matches an STL-style container or a native array that contains the
6280// same number of elements as in rhs, where its i-th element and rhs's
6281// i-th element (as a pair) satisfy the given pair matcher, for all i.
6282// TupleMatcher must be able to be safely cast to Matcher<std::tuple<const
6283// T1&, const T2&> >, where T1 and T2 are the types of elements in the
6284// LHS container and the RHS container respectively.
6285template <typename TupleMatcher, typename Container>
6286inline internal::PointwiseMatcher<TupleMatcher,
6287 GTEST_REMOVE_CONST_(Container)>
6288Pointwise(const TupleMatcher& tuple_matcher, const Container& rhs) {
6289 // This following line is for working around a bug in MSVC 8.0,
6290 // which causes Container to be a const type sometimes (e.g. when
6291 // rhs is a const int[])..
6292 typedef GTEST_REMOVE_CONST_(Container) RawContainer;
6293 return internal::PointwiseMatcher<TupleMatcher, RawContainer>(
6294 tuple_matcher, rhs);
6295}
6296
6297
6298// Supports the Pointwise(m, {a, b, c}) syntax.
6299template <typename TupleMatcher, typename T>
6300inline internal::PointwiseMatcher<TupleMatcher, std::vector<T> > Pointwise(
6301 const TupleMatcher& tuple_matcher, std::initializer_list<T> rhs) {
6302 return Pointwise(tuple_matcher, std::vector<T>(rhs));
6303}
6304
6305
6306// UnorderedPointwise(pair_matcher, rhs) matches an STL-style
6307// container or a native array that contains the same number of
6308// elements as in rhs, where in some permutation of the container, its
6309// i-th element and rhs's i-th element (as a pair) satisfy the given
6310// pair matcher, for all i. Tuple2Matcher must be able to be safely
6311// cast to Matcher<std::tuple<const T1&, const T2&> >, where T1 and T2 are
6312// the types of elements in the LHS container and the RHS container
6313// respectively.
6314//
6315// This is like Pointwise(pair_matcher, rhs), except that the element
6316// order doesn't matter.
6317template <typename Tuple2Matcher, typename RhsContainer>
6318inline internal::UnorderedElementsAreArrayMatcher<
6319 typename internal::BoundSecondMatcher<
6320 Tuple2Matcher, typename internal::StlContainerView<GTEST_REMOVE_CONST_(
6321 RhsContainer)>::type::value_type> >
6322UnorderedPointwise(const Tuple2Matcher& tuple2_matcher,
6323 const RhsContainer& rhs_container) {
6324 // This following line is for working around a bug in MSVC 8.0,
6325 // which causes RhsContainer to be a const type sometimes (e.g. when
6326 // rhs_container is a const int[]).
6327 typedef GTEST_REMOVE_CONST_(RhsContainer) RawRhsContainer;
6328
6329 // RhsView allows the same code to handle RhsContainer being a
6330 // STL-style container and it being a native C-style array.
6331 typedef typename internal::StlContainerView<RawRhsContainer> RhsView;
6332 typedef typename RhsView::type RhsStlContainer;
6333 typedef typename RhsStlContainer::value_type Second;
6334 const RhsStlContainer& rhs_stl_container =
6335 RhsView::ConstReference(rhs_container);
6336
6337 // Create a matcher for each element in rhs_container.
6338 ::std::vector<internal::BoundSecondMatcher<Tuple2Matcher, Second> > matchers;
6339 for (typename RhsStlContainer::const_iterator it = rhs_stl_container.begin();
6340 it != rhs_stl_container.end(); ++it) {
6341 matchers.push_back(
6342 internal::MatcherBindSecond(tuple2_matcher, *it));
6343 }
6344
6345 // Delegate the work to UnorderedElementsAreArray().
6346 return UnorderedElementsAreArray(matchers);
6347}
6348
6349
6350// Supports the UnorderedPointwise(m, {a, b, c}) syntax.
6351template <typename Tuple2Matcher, typename T>
6352inline internal::UnorderedElementsAreArrayMatcher<
6353 typename internal::BoundSecondMatcher<Tuple2Matcher, T> >
6354UnorderedPointwise(const Tuple2Matcher& tuple2_matcher,
6355 std::initializer_list<T> rhs) {
6356 return UnorderedPointwise(tuple2_matcher, std::vector<T>(rhs));
6357}
6358
6359
6360// Matches an STL-style container or a native array that contains at
6361// least one element matching the given value or matcher.
6362//
6363// Examples:
6364// ::std::set<int> page_ids;
6365// page_ids.insert(3);
6366// page_ids.insert(1);
6367// EXPECT_THAT(page_ids, Contains(1));
6368// EXPECT_THAT(page_ids, Contains(Gt(2)));
6369// EXPECT_THAT(page_ids, Not(Contains(4)));
6370//
6371// ::std::map<int, size_t> page_lengths;
6372// page_lengths[1] = 100;
6373// EXPECT_THAT(page_lengths,
6374// Contains(::std::pair<const int, size_t>(1, 100)));
6375//
6376// const char* user_ids[] = { "joe", "mike", "tom" };
6377// EXPECT_THAT(user_ids, Contains(Eq(::std::string("tom"))));
6378template <typename M>
6379inline internal::ContainsMatcher<M> Contains(M matcher) {
6380 return internal::ContainsMatcher<M>(matcher);
6381}
6382
6383// IsSupersetOf(iterator_first, iterator_last)
6384// IsSupersetOf(pointer, count)
6385// IsSupersetOf(array)
6386// IsSupersetOf(container)
6387// IsSupersetOf({e1, e2, ..., en})
6388//
6389// IsSupersetOf() verifies that a surjective partial mapping onto a collection
6390// of matchers exists. In other words, a container matches
6391// IsSupersetOf({e1, ..., en}) if and only if there is a permutation
6392// {y1, ..., yn} of some of the container's elements where y1 matches e1,
6393// ..., and yn matches en. Obviously, the size of the container must be >= n
6394// in order to have a match. Examples:
6395//
6396// - {1, 2, 3} matches IsSupersetOf({Ge(3), Ne(0)}), as 3 matches Ge(3) and
6397// 1 matches Ne(0).
6398// - {1, 2} doesn't match IsSupersetOf({Eq(1), Lt(2)}), even though 1 matches
6399// both Eq(1) and Lt(2). The reason is that different matchers must be used
6400// for elements in different slots of the container.
6401// - {1, 1, 2} matches IsSupersetOf({Eq(1), Lt(2)}), as (the first) 1 matches
6402// Eq(1) and (the second) 1 matches Lt(2).
6403// - {1, 2, 3} matches IsSupersetOf(Gt(1), Gt(1)), as 2 matches (the first)
6404// Gt(1) and 3 matches (the second) Gt(1).
6405//
6406// The matchers can be specified as an array, a pointer and count, a container,
6407// an initializer list, or an STL iterator range. In each of these cases, the
6408// underlying matchers can be either values or matchers.
6409
6410template <typename Iter>
6411inline internal::UnorderedElementsAreArrayMatcher<
6412 typename ::std::iterator_traits<Iter>::value_type>
6413IsSupersetOf(Iter first, Iter last) {
6414 typedef typename ::std::iterator_traits<Iter>::value_type T;
6415 return internal::UnorderedElementsAreArrayMatcher<T>(
6416 internal::UnorderedMatcherRequire::Superset, first, last);
6417}
6418
6419template <typename T>
6420inline internal::UnorderedElementsAreArrayMatcher<T> IsSupersetOf(
6421 const T* pointer, size_t count) {
6422 return IsSupersetOf(pointer, pointer + count);
6423}
6424
6425template <typename T, size_t N>
6426inline internal::UnorderedElementsAreArrayMatcher<T> IsSupersetOf(
6427 const T (&array)[N]) {
6428 return IsSupersetOf(array, N);
6429}
6430
6431template <typename Container>
6432inline internal::UnorderedElementsAreArrayMatcher<
6433 typename Container::value_type>
6434IsSupersetOf(const Container& container) {
6435 return IsSupersetOf(container.begin(), container.end());
6436}
6437
6438template <typename T>
6439inline internal::UnorderedElementsAreArrayMatcher<T> IsSupersetOf(
6440 ::std::initializer_list<T> xs) {
6441 return IsSupersetOf(xs.begin(), xs.end());
6442}
6443
6444// IsSubsetOf(iterator_first, iterator_last)
6445// IsSubsetOf(pointer, count)
6446// IsSubsetOf(array)
6447// IsSubsetOf(container)
6448// IsSubsetOf({e1, e2, ..., en})
6449//
6450// IsSubsetOf() verifies that an injective mapping onto a collection of matchers
6451// exists. In other words, a container matches IsSubsetOf({e1, ..., en}) if and
6452// only if there is a subset of matchers {m1, ..., mk} which would match the
6453// container using UnorderedElementsAre. Obviously, the size of the container
6454// must be <= n in order to have a match. Examples:
6455//
6456// - {1} matches IsSubsetOf({Gt(0), Lt(0)}), as 1 matches Gt(0).
6457// - {1, -1} matches IsSubsetOf({Lt(0), Gt(0)}), as 1 matches Gt(0) and -1
6458// matches Lt(0).
6459// - {1, 2} doesn't matches IsSubsetOf({Gt(0), Lt(0)}), even though 1 and 2 both
6460// match Gt(0). The reason is that different matchers must be used for
6461// elements in different slots of the container.
6462//
6463// The matchers can be specified as an array, a pointer and count, a container,
6464// an initializer list, or an STL iterator range. In each of these cases, the
6465// underlying matchers can be either values or matchers.
6466
6467template <typename Iter>
6468inline internal::UnorderedElementsAreArrayMatcher<
6469 typename ::std::iterator_traits<Iter>::value_type>
6470IsSubsetOf(Iter first, Iter last) {
6471 typedef typename ::std::iterator_traits<Iter>::value_type T;
6472 return internal::UnorderedElementsAreArrayMatcher<T>(
6473 internal::UnorderedMatcherRequire::Subset, first, last);
6474}
6475
6476template <typename T>
6477inline internal::UnorderedElementsAreArrayMatcher<T> IsSubsetOf(
6478 const T* pointer, size_t count) {
6479 return IsSubsetOf(pointer, pointer + count);
6480}
6481
6482template <typename T, size_t N>
6483inline internal::UnorderedElementsAreArrayMatcher<T> IsSubsetOf(
6484 const T (&array)[N]) {
6485 return IsSubsetOf(array, N);
6486}
6487
6488template <typename Container>
6489inline internal::UnorderedElementsAreArrayMatcher<
6490 typename Container::value_type>
6491IsSubsetOf(const Container& container) {
6492 return IsSubsetOf(container.begin(), container.end());
6493}
6494
6495template <typename T>
6496inline internal::UnorderedElementsAreArrayMatcher<T> IsSubsetOf(
6497 ::std::initializer_list<T> xs) {
6498 return IsSubsetOf(xs.begin(), xs.end());
6499}
6500
6501// Matches an STL-style container or a native array that contains only
6502// elements matching the given value or matcher.
6503//
6504// Each(m) is semantically equivalent to Not(Contains(Not(m))). Only
6505// the messages are different.
6506//
6507// Examples:
6508// ::std::set<int> page_ids;
6509// // Each(m) matches an empty container, regardless of what m is.
6510// EXPECT_THAT(page_ids, Each(Eq(1)));
6511// EXPECT_THAT(page_ids, Each(Eq(77)));
6512//
6513// page_ids.insert(3);
6514// EXPECT_THAT(page_ids, Each(Gt(0)));
6515// EXPECT_THAT(page_ids, Not(Each(Gt(4))));
6516// page_ids.insert(1);
6517// EXPECT_THAT(page_ids, Not(Each(Lt(2))));
6518//
6519// ::std::map<int, size_t> page_lengths;
6520// page_lengths[1] = 100;
6521// page_lengths[2] = 200;
6522// page_lengths[3] = 300;
6523// EXPECT_THAT(page_lengths, Not(Each(Pair(1, 100))));
6524// EXPECT_THAT(page_lengths, Each(Key(Le(3))));
6525//
6526// const char* user_ids[] = { "joe", "mike", "tom" };
6527// EXPECT_THAT(user_ids, Not(Each(Eq(::std::string("tom")))));
6528template <typename M>
6529inline internal::EachMatcher<M> Each(M matcher) {
6530 return internal::EachMatcher<M>(matcher);
6531}
6532
6533// Key(inner_matcher) matches an std::pair whose 'first' field matches
6534// inner_matcher. For example, Contains(Key(Ge(5))) can be used to match an
6535// std::map that contains at least one element whose key is >= 5.
6536template <typename M>
6537inline internal::KeyMatcher<M> Key(M inner_matcher) {
6538 return internal::KeyMatcher<M>(inner_matcher);
6539}
6540
6541// Pair(first_matcher, second_matcher) matches a std::pair whose 'first' field
6542// matches first_matcher and whose 'second' field matches second_matcher. For
6543// example, EXPECT_THAT(map_type, ElementsAre(Pair(Ge(5), "foo"))) can be used
6544// to match a std::map<int, string> that contains exactly one element whose key
6545// is >= 5 and whose value equals "foo".
6546template <typename FirstMatcher, typename SecondMatcher>
6547inline internal::PairMatcher<FirstMatcher, SecondMatcher>
6548Pair(FirstMatcher first_matcher, SecondMatcher second_matcher) {
6549 return internal::PairMatcher<FirstMatcher, SecondMatcher>(
6550 first_matcher, second_matcher);
6551}
6552
6553// Returns a predicate that is satisfied by anything that matches the
6554// given matcher.
6555template <typename M>
6556inline internal::MatcherAsPredicate<M> Matches(M matcher) {
6557 return internal::MatcherAsPredicate<M>(matcher);
6558}
6559
6560// Returns true iff the value matches the matcher.
6561template <typename T, typename M>
6562inline bool Value(const T& value, M matcher) {
6563 return testing::Matches(matcher)(value);
6564}
6565
6566// Matches the value against the given matcher and explains the match
6567// result to listener.
6568template <typename T, typename M>
6569inline bool ExplainMatchResult(
6570 M matcher, const T& value, MatchResultListener* listener) {
6571 return SafeMatcherCast<const T&>(matcher).MatchAndExplain(value, listener);
6572}
6573
6574// Returns a string representation of the given matcher. Useful for description
6575// strings of matchers defined using MATCHER_P* macros that accept matchers as
6576// their arguments. For example:
6577//
6578// MATCHER_P(XAndYThat, matcher,
6579// "X that " + DescribeMatcher<int>(matcher, negation) +
6580// " and Y that " + DescribeMatcher<double>(matcher, negation)) {
6581// return ExplainMatchResult(matcher, arg.x(), result_listener) &&
6582// ExplainMatchResult(matcher, arg.y(), result_listener);
6583// }
6584template <typename T, typename M>
6585std::string DescribeMatcher(const M& matcher, bool negation = false) {
6586 ::std::stringstream ss;
6587 Matcher<T> monomorphic_matcher = SafeMatcherCast<T>(matcher);
6588 if (negation) {
6589 monomorphic_matcher.DescribeNegationTo(&ss);
6590 } else {
6591 monomorphic_matcher.DescribeTo(&ss);
6592 }
6593 return ss.str();
6594}
6595
6596template <typename... Args>
6597internal::ElementsAreMatcher<
6598 std::tuple<typename std::decay<const Args&>::type...>>
6599ElementsAre(const Args&... matchers) {
6600 return internal::ElementsAreMatcher<
6601 std::tuple<typename std::decay<const Args&>::type...>>(
6602 std::make_tuple(matchers...));
6603}
6604
6605template <typename... Args>
6606internal::UnorderedElementsAreMatcher<
6607 std::tuple<typename std::decay<const Args&>::type...>>
6608UnorderedElementsAre(const Args&... matchers) {
6609 return internal::UnorderedElementsAreMatcher<
6610 std::tuple<typename std::decay<const Args&>::type...>>(
6611 std::make_tuple(matchers...));
6612}
6613
6614// Define variadic matcher versions.
6615template <typename... Args>
6616internal::AllOfMatcher<typename std::decay<const Args&>::type...> AllOf(
6617 const Args&... matchers) {
6618 return internal::AllOfMatcher<typename std::decay<const Args&>::type...>(
6619 matchers...);
6620}
6621
6622template <typename... Args>
6623internal::AnyOfMatcher<typename std::decay<const Args&>::type...> AnyOf(
6624 const Args&... matchers) {
6625 return internal::AnyOfMatcher<typename std::decay<const Args&>::type...>(
6626 matchers...);
6627}
6628
6629// AnyOfArray(array)
6630// AnyOfArray(pointer, count)
6631// AnyOfArray(container)
6632// AnyOfArray({ e1, e2, ..., en })
6633// AnyOfArray(iterator_first, iterator_last)
6634//
6635// AnyOfArray() verifies whether a given value matches any member of a
6636// collection of matchers.
6637//
6638// AllOfArray(array)
6639// AllOfArray(pointer, count)
6640// AllOfArray(container)
6641// AllOfArray({ e1, e2, ..., en })
6642// AllOfArray(iterator_first, iterator_last)
6643//
6644// AllOfArray() verifies whether a given value matches all members of a
6645// collection of matchers.
6646//
6647// The matchers can be specified as an array, a pointer and count, a container,
6648// an initializer list, or an STL iterator range. In each of these cases, the
6649// underlying matchers can be either values or matchers.
6650
6651template <typename Iter>
6652inline internal::AnyOfArrayMatcher<
6653 typename ::std::iterator_traits<Iter>::value_type>
6654AnyOfArray(Iter first, Iter last) {
6655 return internal::AnyOfArrayMatcher<
6656 typename ::std::iterator_traits<Iter>::value_type>(first, last);
6657}
6658
6659template <typename Iter>
6660inline internal::AllOfArrayMatcher<
6661 typename ::std::iterator_traits<Iter>::value_type>
6662AllOfArray(Iter first, Iter last) {
6663 return internal::AllOfArrayMatcher<
6664 typename ::std::iterator_traits<Iter>::value_type>(first, last);
6665}
6666
6667template <typename T>
6668inline internal::AnyOfArrayMatcher<T> AnyOfArray(const T* ptr, size_t count) {
6669 return AnyOfArray(ptr, ptr + count);
6670}
6671
6672template <typename T>
6673inline internal::AllOfArrayMatcher<T> AllOfArray(const T* ptr, size_t count) {
6674 return AllOfArray(ptr, ptr + count);
6675}
6676
6677template <typename T, size_t N>
6678inline internal::AnyOfArrayMatcher<T> AnyOfArray(const T (&array)[N]) {
6679 return AnyOfArray(array, N);
6680}
6681
6682template <typename T, size_t N>
6683inline internal::AllOfArrayMatcher<T> AllOfArray(const T (&array)[N]) {
6684 return AllOfArray(array, N);
6685}
6686
6687template <typename Container>
6688inline internal::AnyOfArrayMatcher<typename Container::value_type> AnyOfArray(
6689 const Container& container) {
6690 return AnyOfArray(container.begin(), container.end());
6691}
6692
6693template <typename Container>
6694inline internal::AllOfArrayMatcher<typename Container::value_type> AllOfArray(
6695 const Container& container) {
6696 return AllOfArray(container.begin(), container.end());
6697}
6698
6699template <typename T>
6700inline internal::AnyOfArrayMatcher<T> AnyOfArray(
6701 ::std::initializer_list<T> xs) {
6702 return AnyOfArray(xs.begin(), xs.end());
6703}
6704
6705template <typename T>
6706inline internal::AllOfArrayMatcher<T> AllOfArray(
6707 ::std::initializer_list<T> xs) {
6708 return AllOfArray(xs.begin(), xs.end());
6709}
6710
6711// Args<N1, N2, ..., Nk>(a_matcher) matches a tuple if the selected
6712// fields of it matches a_matcher. C++ doesn't support default
6713// arguments for function templates, so we have to overload it.
6714template <size_t... k, typename InnerMatcher>
6715internal::ArgsMatcher<typename std::decay<InnerMatcher>::type, k...> Args(
6716 InnerMatcher&& matcher) {
6717 return internal::ArgsMatcher<typename std::decay<InnerMatcher>::type, k...>(
6718 std::forward<InnerMatcher>(matcher));
6719}
6720
6721// AllArgs(m) is a synonym of m. This is useful in
6722//
6723// EXPECT_CALL(foo, Bar(_, _)).With(AllArgs(Eq()));
6724//
6725// which is easier to read than
6726//
6727// EXPECT_CALL(foo, Bar(_, _)).With(Eq());
6728template <typename InnerMatcher>
6729inline InnerMatcher AllArgs(const InnerMatcher& matcher) { return matcher; }
6730
6731// Returns a matcher that matches the value of an optional<> type variable.
6732// The matcher implementation only uses '!arg' and requires that the optional<>
6733// type has a 'value_type' member type and that '*arg' is of type 'value_type'
6734// and is printable using 'PrintToString'. It is compatible with
6735// std::optional/std::experimental::optional.
6736// Note that to compare an optional type variable against nullopt you should
6737// use Eq(nullopt) and not Optional(Eq(nullopt)). The latter implies that the
6738// optional value contains an optional itself.
6739template <typename ValueMatcher>
6740inline internal::OptionalMatcher<ValueMatcher> Optional(
6741 const ValueMatcher& value_matcher) {
6742 return internal::OptionalMatcher<ValueMatcher>(value_matcher);
6743}
6744
6745// Returns a matcher that matches the value of a absl::any type variable.
6746template <typename T>
6747PolymorphicMatcher<internal::any_cast_matcher::AnyCastMatcher<T> > AnyWith(
6748 const Matcher<const T&>& matcher) {
6749 return MakePolymorphicMatcher(
6750 internal::any_cast_matcher::AnyCastMatcher<T>(matcher));
6751}
6752
6753// Returns a matcher that matches the value of a variant<> type variable.
6754// The matcher implementation uses ADL to find the holds_alternative and get
6755// functions.
6756// It is compatible with std::variant.
6757template <typename T>
6758PolymorphicMatcher<internal::variant_matcher::VariantMatcher<T> > VariantWith(
6759 const Matcher<const T&>& matcher) {
6760 return MakePolymorphicMatcher(
6761 internal::variant_matcher::VariantMatcher<T>(matcher));
6762}
6763
6764// These macros allow using matchers to check values in Google Test
6765// tests. ASSERT_THAT(value, matcher) and EXPECT_THAT(value, matcher)
6766// succeed iff the value matches the matcher. If the assertion fails,
6767// the value and the description of the matcher will be printed.
6768#define ASSERT_THAT(value, matcher) ASSERT_PRED_FORMAT1(\
6769 ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value)
6770#define EXPECT_THAT(value, matcher) EXPECT_PRED_FORMAT1(\
6771 ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value)
6772
6773} // namespace testing
6774
6775GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 5046
6776
6777// Include any custom callback matchers added by the local installation.
6778// We must include this header at the end to make sure it can use the
6779// declarations from this file.
6780// Copyright 2015, Google Inc.
6781// All rights reserved.
6782//
6783// Redistribution and use in source and binary forms, with or without
6784// modification, are permitted provided that the following conditions are
6785// met:
6786//
6787// * Redistributions of source code must retain the above copyright
6788// notice, this list of conditions and the following disclaimer.
6789// * Redistributions in binary form must reproduce the above
6790// copyright notice, this list of conditions and the following disclaimer
6791// in the documentation and/or other materials provided with the
6792// distribution.
6793// * Neither the name of Google Inc. nor the names of its
6794// contributors may be used to endorse or promote products derived from
6795// this software without specific prior written permission.
6796//
6797// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6798// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
6799// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6800// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
6801// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
6802// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
6803// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
6804// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
6805// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
6806// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
6807// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6808//
6809// Injection point for custom user configurations. See README for details
6810//
6811// GOOGLETEST_CM0002 DO NOT DELETE
6812
6813#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_MATCHERS_H_
6814#define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_MATCHERS_H_
6815#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_MATCHERS_H_
6816
6817#endif // GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
6818
6819#if GTEST_HAS_EXCEPTIONS
6820# include <stdexcept> // NOLINT
6821#endif
6822
6823GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
6824/* class A needs to have dll-interface to be used by clients of class B */)
6825
6826namespace testing {
6827
6828// An abstract handle of an expectation.
6829class Expectation;
6830
6831// A set of expectation handles.
6832class ExpectationSet;
6833
6834// Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION
6835// and MUST NOT BE USED IN USER CODE!!!
6836namespace internal {
6837
6838// Implements a mock function.
6839template <typename F> class FunctionMocker;
6840
6841// Base class for expectations.
6842class ExpectationBase;
6843
6844// Implements an expectation.
6845template <typename F> class TypedExpectation;
6846
6847// Helper class for testing the Expectation class template.
6848class ExpectationTester;
6849
6850// Protects the mock object registry (in class Mock), all function
6851// mockers, and all expectations.
6852//
6853// The reason we don't use more fine-grained protection is: when a
6854// mock function Foo() is called, it needs to consult its expectations
6855// to see which one should be picked. If another thread is allowed to
6856// call a mock function (either Foo() or a different one) at the same
6857// time, it could affect the "retired" attributes of Foo()'s
6858// expectations when InSequence() is used, and thus affect which
6859// expectation gets picked. Therefore, we sequence all mock function
6860// calls to ensure the integrity of the mock objects' states.
6861GTEST_API_ GTEST_DECLARE_STATIC_MUTEX_(g_gmock_mutex);
6862
6863// Untyped base class for ActionResultHolder<R>.
6864class UntypedActionResultHolderBase;
6865
6866// Abstract base class of FunctionMocker. This is the
6867// type-agnostic part of the function mocker interface. Its pure
6868// virtual methods are implemented by FunctionMocker.
6869class GTEST_API_ UntypedFunctionMockerBase {
6870 public:
6871 UntypedFunctionMockerBase();
6872 virtual ~UntypedFunctionMockerBase();
6873
6874 // Verifies that all expectations on this mock function have been
6875 // satisfied. Reports one or more Google Test non-fatal failures
6876 // and returns false if not.
6877 bool VerifyAndClearExpectationsLocked()
6878 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
6879
6880 // Clears the ON_CALL()s set on this mock function.
6881 virtual void ClearDefaultActionsLocked()
6882 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) = 0;
6883
6884 // In all of the following Untyped* functions, it's the caller's
6885 // responsibility to guarantee the correctness of the arguments'
6886 // types.
6887
6888 // Performs the default action with the given arguments and returns
6889 // the action's result. The call description string will be used in
6890 // the error message to describe the call in the case the default
6891 // action fails.
6892 // L = *
6893 virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction(
6894 void* untyped_args, const std::string& call_description) const = 0;
6895
6896 // Performs the given action with the given arguments and returns
6897 // the action's result.
6898 // L = *
6899 virtual UntypedActionResultHolderBase* UntypedPerformAction(
6900 const void* untyped_action, void* untyped_args) const = 0;
6901
6902 // Writes a message that the call is uninteresting (i.e. neither
6903 // explicitly expected nor explicitly unexpected) to the given
6904 // ostream.
6905 virtual void UntypedDescribeUninterestingCall(
6906 const void* untyped_args,
6907 ::std::ostream* os) const
6908 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) = 0;
6909
6910 // Returns the expectation that matches the given function arguments
6911 // (or NULL is there's no match); when a match is found,
6912 // untyped_action is set to point to the action that should be
6913 // performed (or NULL if the action is "do default"), and
6914 // is_excessive is modified to indicate whether the call exceeds the
6915 // expected number.
6916 virtual const ExpectationBase* UntypedFindMatchingExpectation(
6917 const void* untyped_args,
6918 const void** untyped_action, bool* is_excessive,
6919 ::std::ostream* what, ::std::ostream* why)
6920 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) = 0;
6921
6922 // Prints the given function arguments to the ostream.
6923 virtual void UntypedPrintArgs(const void* untyped_args,
6924 ::std::ostream* os) const = 0;
6925
6926 // Sets the mock object this mock method belongs to, and registers
6927 // this information in the global mock registry. Will be called
6928 // whenever an EXPECT_CALL() or ON_CALL() is executed on this mock
6929 // method.
6930 void RegisterOwner(const void* mock_obj)
6931 GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
6932
6933 // Sets the mock object this mock method belongs to, and sets the
6934 // name of the mock function. Will be called upon each invocation
6935 // of this mock function.
6936 void SetOwnerAndName(const void* mock_obj, const char* name)
6937 GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
6938
6939 // Returns the mock object this mock method belongs to. Must be
6940 // called after RegisterOwner() or SetOwnerAndName() has been
6941 // called.
6942 const void* MockObject() const
6943 GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
6944
6945 // Returns the name of this mock method. Must be called after
6946 // SetOwnerAndName() has been called.
6947 const char* Name() const
6948 GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
6949
6950 // Returns the result of invoking this mock function with the given
6951 // arguments. This function can be safely called from multiple
6952 // threads concurrently. The caller is responsible for deleting the
6953 // result.
6954 UntypedActionResultHolderBase* UntypedInvokeWith(void* untyped_args)
6955 GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
6956
6957 protected:
6958 typedef std::vector<const void*> UntypedOnCallSpecs;
6959
6960 using UntypedExpectations = std::vector<std::shared_ptr<ExpectationBase>>;
6961
6962 // Returns an Expectation object that references and co-owns exp,
6963 // which must be an expectation on this mock function.
6964 Expectation GetHandleOf(ExpectationBase* exp);
6965
6966 // Address of the mock object this mock method belongs to. Only
6967 // valid after this mock method has been called or
6968 // ON_CALL/EXPECT_CALL has been invoked on it.
6969 const void* mock_obj_; // Protected by g_gmock_mutex.
6970
6971 // Name of the function being mocked. Only valid after this mock
6972 // method has been called.
6973 const char* name_; // Protected by g_gmock_mutex.
6974
6975 // All default action specs for this function mocker.
6976 UntypedOnCallSpecs untyped_on_call_specs_;
6977
6978 // All expectations for this function mocker.
6979 //
6980 // It's undefined behavior to interleave expectations (EXPECT_CALLs
6981 // or ON_CALLs) and mock function calls. Also, the order of
6982 // expectations is important. Therefore it's a logic race condition
6983 // to read/write untyped_expectations_ concurrently. In order for
6984 // tools like tsan to catch concurrent read/write accesses to
6985 // untyped_expectations, we deliberately leave accesses to it
6986 // unprotected.
6987 UntypedExpectations untyped_expectations_;
6988}; // class UntypedFunctionMockerBase
6989
6990// Untyped base class for OnCallSpec<F>.
6991class UntypedOnCallSpecBase {
6992 public:
6993 // The arguments are the location of the ON_CALL() statement.
6994 UntypedOnCallSpecBase(const char* a_file, int a_line)
6995 : file_(a_file), line_(a_line), last_clause_(kNone) {}
6996
6997 // Where in the source file was the default action spec defined?
6998 const char* file() const { return file_; }
6999 int line() const { return line_; }
7000
7001 protected:
7002 // Gives each clause in the ON_CALL() statement a name.
7003 enum Clause {
7004 // Do not change the order of the enum members! The run-time
7005 // syntax checking relies on it.
7006 kNone,
7007 kWith,
7008 kWillByDefault
7009 };
7010
7011 // Asserts that the ON_CALL() statement has a certain property.
7012 void AssertSpecProperty(bool property,
7013 const std::string& failure_message) const {
7014 Assert(property, file_, line_, failure_message);
7015 }
7016
7017 // Expects that the ON_CALL() statement has a certain property.
7018 void ExpectSpecProperty(bool property,
7019 const std::string& failure_message) const {
7020 Expect(property, file_, line_, failure_message);
7021 }
7022
7023 const char* file_;
7024 int line_;
7025
7026 // The last clause in the ON_CALL() statement as seen so far.
7027 // Initially kNone and changes as the statement is parsed.
7028 Clause last_clause_;
7029}; // class UntypedOnCallSpecBase
7030
7031// This template class implements an ON_CALL spec.
7032template <typename F>
7033class OnCallSpec : public UntypedOnCallSpecBase {
7034 public:
7035 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
7036 typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple;
7037
7038 // Constructs an OnCallSpec object from the information inside
7039 // the parenthesis of an ON_CALL() statement.
7040 OnCallSpec(const char* a_file, int a_line,
7041 const ArgumentMatcherTuple& matchers)
7042 : UntypedOnCallSpecBase(a_file, a_line),
7043 matchers_(matchers),
7044 // By default, extra_matcher_ should match anything. However,
7045 // we cannot initialize it with _ as that causes ambiguity between
7046 // Matcher's copy and move constructor for some argument types.
7047 extra_matcher_(A<const ArgumentTuple&>()) {}
7048
7049 // Implements the .With() clause.
7050 OnCallSpec& With(const Matcher<const ArgumentTuple&>& m) {
7051 // Makes sure this is called at most once.
7052 ExpectSpecProperty(last_clause_ < kWith,
7053 ".With() cannot appear "
7054 "more than once in an ON_CALL().");
7055 last_clause_ = kWith;
7056
7057 extra_matcher_ = m;
7058 return *this;
7059 }
7060
7061 // Implements the .WillByDefault() clause.
7062 OnCallSpec& WillByDefault(const Action<F>& action) {
7063 ExpectSpecProperty(last_clause_ < kWillByDefault,
7064 ".WillByDefault() must appear "
7065 "exactly once in an ON_CALL().");
7066 last_clause_ = kWillByDefault;
7067
7068 ExpectSpecProperty(!action.IsDoDefault(),
7069 "DoDefault() cannot be used in ON_CALL().");
7070 action_ = action;
7071 return *this;
7072 }
7073
7074 // Returns true iff the given arguments match the matchers.
7075 bool Matches(const ArgumentTuple& args) const {
7076 return TupleMatches(matchers_, args) && extra_matcher_.Matches(args);
7077 }
7078
7079 // Returns the action specified by the user.
7080 const Action<F>& GetAction() const {
7081 AssertSpecProperty(last_clause_ == kWillByDefault,
7082 ".WillByDefault() must appear exactly "
7083 "once in an ON_CALL().");
7084 return action_;
7085 }
7086
7087 private:
7088 // The information in statement
7089 //
7090 // ON_CALL(mock_object, Method(matchers))
7091 // .With(multi-argument-matcher)
7092 // .WillByDefault(action);
7093 //
7094 // is recorded in the data members like this:
7095 //
7096 // source file that contains the statement => file_
7097 // line number of the statement => line_
7098 // matchers => matchers_
7099 // multi-argument-matcher => extra_matcher_
7100 // action => action_
7101 ArgumentMatcherTuple matchers_;
7102 Matcher<const ArgumentTuple&> extra_matcher_;
7103 Action<F> action_;
7104}; // class OnCallSpec
7105
7106// Possible reactions on uninteresting calls.
7107enum CallReaction {
7108 kAllow,
7109 kWarn,
7110 kFail,
7111};
7112
7113} // namespace internal
7114
7115// Utilities for manipulating mock objects.
7116class GTEST_API_ Mock {
7117 public:
7118 // The following public methods can be called concurrently.
7119
7120 // Tells Google Mock to ignore mock_obj when checking for leaked
7121 // mock objects.
7122 static void AllowLeak(const void* mock_obj)
7123 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
7124
7125 // Verifies and clears all expectations on the given mock object.
7126 // If the expectations aren't satisfied, generates one or more
7127 // Google Test non-fatal failures and returns false.
7128 static bool VerifyAndClearExpectations(void* mock_obj)
7129 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
7130
7131 // Verifies all expectations on the given mock object and clears its
7132 // default actions and expectations. Returns true iff the
7133 // verification was successful.
7134 static bool VerifyAndClear(void* mock_obj)
7135 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
7136
7137 // Returns whether the mock was created as a naggy mock (default)
7138 static bool IsNaggy(void* mock_obj)
7139 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
7140 // Returns whether the mock was created as a nice mock
7141 static bool IsNice(void* mock_obj)
7142 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
7143 // Returns whether the mock was created as a strict mock
7144 static bool IsStrict(void* mock_obj)
7145 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
7146
7147 private:
7148 friend class internal::UntypedFunctionMockerBase;
7149
7150 // Needed for a function mocker to register itself (so that we know
7151 // how to clear a mock object).
7152 template <typename F>
7153 friend class internal::FunctionMocker;
7154
7155 template <typename M>
7156 friend class NiceMock;
7157
7158 template <typename M>
7159 friend class NaggyMock;
7160
7161 template <typename M>
7162 friend class StrictMock;
7163
7164 // Tells Google Mock to allow uninteresting calls on the given mock
7165 // object.
7166 static void AllowUninterestingCalls(const void* mock_obj)
7167 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
7168
7169 // Tells Google Mock to warn the user about uninteresting calls on
7170 // the given mock object.
7171 static void WarnUninterestingCalls(const void* mock_obj)
7172 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
7173
7174 // Tells Google Mock to fail uninteresting calls on the given mock
7175 // object.
7176 static void FailUninterestingCalls(const void* mock_obj)
7177 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
7178
7179 // Tells Google Mock the given mock object is being destroyed and
7180 // its entry in the call-reaction table should be removed.
7181 static void UnregisterCallReaction(const void* mock_obj)
7182 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
7183
7184 // Returns the reaction Google Mock will have on uninteresting calls
7185 // made on the given mock object.
7186 static internal::CallReaction GetReactionOnUninterestingCalls(
7187 const void* mock_obj)
7188 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
7189
7190 // Verifies that all expectations on the given mock object have been
7191 // satisfied. Reports one or more Google Test non-fatal failures
7192 // and returns false if not.
7193 static bool VerifyAndClearExpectationsLocked(void* mock_obj)
7194 GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex);
7195
7196 // Clears all ON_CALL()s set on the given mock object.
7197 static void ClearDefaultActionsLocked(void* mock_obj)
7198 GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex);
7199
7200 // Registers a mock object and a mock method it owns.
7201 static void Register(
7202 const void* mock_obj,
7203 internal::UntypedFunctionMockerBase* mocker)
7204 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
7205
7206 // Tells Google Mock where in the source code mock_obj is used in an
7207 // ON_CALL or EXPECT_CALL. In case mock_obj is leaked, this
7208 // information helps the user identify which object it is.
7209 static void RegisterUseByOnCallOrExpectCall(
7210 const void* mock_obj, const char* file, int line)
7211 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
7212
7213 // Unregisters a mock method; removes the owning mock object from
7214 // the registry when the last mock method associated with it has
7215 // been unregistered. This is called only in the destructor of
7216 // FunctionMocker.
7217 static void UnregisterLocked(internal::UntypedFunctionMockerBase* mocker)
7218 GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex);
7219}; // class Mock
7220
7221// An abstract handle of an expectation. Useful in the .After()
7222// clause of EXPECT_CALL() for setting the (partial) order of
7223// expectations. The syntax:
7224//
7225// Expectation e1 = EXPECT_CALL(...)...;
7226// EXPECT_CALL(...).After(e1)...;
7227//
7228// sets two expectations where the latter can only be matched after
7229// the former has been satisfied.
7230//
7231// Notes:
7232// - This class is copyable and has value semantics.
7233// - Constness is shallow: a const Expectation object itself cannot
7234// be modified, but the mutable methods of the ExpectationBase
7235// object it references can be called via expectation_base().
7236
7237class GTEST_API_ Expectation {
7238 public:
7239 // Constructs a null object that doesn't reference any expectation.
7240 Expectation();
7241
7242 ~Expectation();
7243
7244 // This single-argument ctor must not be explicit, in order to support the
7245 // Expectation e = EXPECT_CALL(...);
7246 // syntax.
7247 //
7248 // A TypedExpectation object stores its pre-requisites as
7249 // Expectation objects, and needs to call the non-const Retire()
7250 // method on the ExpectationBase objects they reference. Therefore
7251 // Expectation must receive a *non-const* reference to the
7252 // ExpectationBase object.
7253 Expectation(internal::ExpectationBase& exp); // NOLINT
7254
7255 // The compiler-generated copy ctor and operator= work exactly as
7256 // intended, so we don't need to define our own.
7257
7258 // Returns true iff rhs references the same expectation as this object does.
7259 bool operator==(const Expectation& rhs) const {
7260 return expectation_base_ == rhs.expectation_base_;
7261 }
7262
7263 bool operator!=(const Expectation& rhs) const { return !(*this == rhs); }
7264
7265 private:
7266 friend class ExpectationSet;
7267 friend class Sequence;
7268 friend class ::testing::internal::ExpectationBase;
7269 friend class ::testing::internal::UntypedFunctionMockerBase;
7270
7271 template <typename F>
7272 friend class ::testing::internal::FunctionMocker;
7273
7274 template <typename F>
7275 friend class ::testing::internal::TypedExpectation;
7276
7277 // This comparator is needed for putting Expectation objects into a set.
7278 class Less {
7279 public:
7280 bool operator()(const Expectation& lhs, const Expectation& rhs) const {
7281 return lhs.expectation_base_.get() < rhs.expectation_base_.get();
7282 }
7283 };
7284
7285 typedef ::std::set<Expectation, Less> Set;
7286
7287 Expectation(
7288 const std::shared_ptr<internal::ExpectationBase>& expectation_base);
7289
7290 // Returns the expectation this object references.
7291 const std::shared_ptr<internal::ExpectationBase>& expectation_base() const {
7292 return expectation_base_;
7293 }
7294
7295 // A shared_ptr that co-owns the expectation this handle references.
7296 std::shared_ptr<internal::ExpectationBase> expectation_base_;
7297};
7298
7299// A set of expectation handles. Useful in the .After() clause of
7300// EXPECT_CALL() for setting the (partial) order of expectations. The
7301// syntax:
7302//
7303// ExpectationSet es;
7304// es += EXPECT_CALL(...)...;
7305// es += EXPECT_CALL(...)...;
7306// EXPECT_CALL(...).After(es)...;
7307//
7308// sets three expectations where the last one can only be matched
7309// after the first two have both been satisfied.
7310//
7311// This class is copyable and has value semantics.
7312class ExpectationSet {
7313 public:
7314 // A bidirectional iterator that can read a const element in the set.
7315 typedef Expectation::Set::const_iterator const_iterator;
7316
7317 // An object stored in the set. This is an alias of Expectation.
7318 typedef Expectation::Set::value_type value_type;
7319
7320 // Constructs an empty set.
7321 ExpectationSet() {}
7322
7323 // This single-argument ctor must not be explicit, in order to support the
7324 // ExpectationSet es = EXPECT_CALL(...);
7325 // syntax.
7326 ExpectationSet(internal::ExpectationBase& exp) { // NOLINT
7327 *this += Expectation(exp);
7328 }
7329
7330 // This single-argument ctor implements implicit conversion from
7331 // Expectation and thus must not be explicit. This allows either an
7332 // Expectation or an ExpectationSet to be used in .After().
7333 ExpectationSet(const Expectation& e) { // NOLINT
7334 *this += e;
7335 }
7336
7337 // The compiler-generator ctor and operator= works exactly as
7338 // intended, so we don't need to define our own.
7339
7340 // Returns true iff rhs contains the same set of Expectation objects
7341 // as this does.
7342 bool operator==(const ExpectationSet& rhs) const {
7343 return expectations_ == rhs.expectations_;
7344 }
7345
7346 bool operator!=(const ExpectationSet& rhs) const { return !(*this == rhs); }
7347
7348 // Implements the syntax
7349 // expectation_set += EXPECT_CALL(...);
7350 ExpectationSet& operator+=(const Expectation& e) {
7351 expectations_.insert(e);
7352 return *this;
7353 }
7354
7355 int size() const { return static_cast<int>(expectations_.size()); }
7356
7357 const_iterator begin() const { return expectations_.begin(); }
7358 const_iterator end() const { return expectations_.end(); }
7359
7360 private:
7361 Expectation::Set expectations_;
7362};
7363
7364
7365// Sequence objects are used by a user to specify the relative order
7366// in which the expectations should match. They are copyable (we rely
7367// on the compiler-defined copy constructor and assignment operator).
7368class GTEST_API_ Sequence {
7369 public:
7370 // Constructs an empty sequence.
7371 Sequence() : last_expectation_(new Expectation) {}
7372
7373 // Adds an expectation to this sequence. The caller must ensure
7374 // that no other thread is accessing this Sequence object.
7375 void AddExpectation(const Expectation& expectation) const;
7376
7377 private:
7378 // The last expectation in this sequence.
7379 std::shared_ptr<Expectation> last_expectation_;
7380}; // class Sequence
7381
7382// An object of this type causes all EXPECT_CALL() statements
7383// encountered in its scope to be put in an anonymous sequence. The
7384// work is done in the constructor and destructor. You should only
7385// create an InSequence object on the stack.
7386//
7387// The sole purpose for this class is to support easy definition of
7388// sequential expectations, e.g.
7389//
7390// {
7391// InSequence dummy; // The name of the object doesn't matter.
7392//
7393// // The following expectations must match in the order they appear.
7394// EXPECT_CALL(a, Bar())...;
7395// EXPECT_CALL(a, Baz())...;
7396// ...
7397// EXPECT_CALL(b, Xyz())...;
7398// }
7399//
7400// You can create InSequence objects in multiple threads, as long as
7401// they are used to affect different mock objects. The idea is that
7402// each thread can create and set up its own mocks as if it's the only
7403// thread. However, for clarity of your tests we recommend you to set
7404// up mocks in the main thread unless you have a good reason not to do
7405// so.
7406class GTEST_API_ InSequence {
7407 public:
7408 InSequence();
7409 ~InSequence();
7410 private:
7411 bool sequence_created_;
7412
7413 GTEST_DISALLOW_COPY_AND_ASSIGN_(InSequence); // NOLINT
7414} GTEST_ATTRIBUTE_UNUSED_;
7415
7416namespace internal {
7417
7418// Points to the implicit sequence introduced by a living InSequence
7419// object (if any) in the current thread or NULL.
7420GTEST_API_ extern ThreadLocal<Sequence*> g_gmock_implicit_sequence;
7421
7422// Base class for implementing expectations.
7423//
7424// There are two reasons for having a type-agnostic base class for
7425// Expectation:
7426//
7427// 1. We need to store collections of expectations of different
7428// types (e.g. all pre-requisites of a particular expectation, all
7429// expectations in a sequence). Therefore these expectation objects
7430// must share a common base class.
7431//
7432// 2. We can avoid binary code bloat by moving methods not depending
7433// on the template argument of Expectation to the base class.
7434//
7435// This class is internal and mustn't be used by user code directly.
7436class GTEST_API_ ExpectationBase {
7437 public:
7438 // source_text is the EXPECT_CALL(...) source that created this Expectation.
7439 ExpectationBase(const char* file, int line, const std::string& source_text);
7440
7441 virtual ~ExpectationBase();
7442
7443 // Where in the source file was the expectation spec defined?
7444 const char* file() const { return file_; }
7445 int line() const { return line_; }
7446 const char* source_text() const { return source_text_.c_str(); }
7447 // Returns the cardinality specified in the expectation spec.
7448 const Cardinality& cardinality() const { return cardinality_; }
7449
7450 // Describes the source file location of this expectation.
7451 void DescribeLocationTo(::std::ostream* os) const {
7452 *os << FormatFileLocation(file(), line()) << " ";
7453 }
7454
7455 // Describes how many times a function call matching this
7456 // expectation has occurred.
7457 void DescribeCallCountTo(::std::ostream* os) const
7458 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
7459
7460 // If this mock method has an extra matcher (i.e. .With(matcher)),
7461 // describes it to the ostream.
7462 virtual void MaybeDescribeExtraMatcherTo(::std::ostream* os) = 0;
7463
7464 protected:
7465 friend class ::testing::Expectation;
7466 friend class UntypedFunctionMockerBase;
7467
7468 enum Clause {
7469 // Don't change the order of the enum members!
7470 kNone,
7471 kWith,
7472 kTimes,
7473 kInSequence,
7474 kAfter,
7475 kWillOnce,
7476 kWillRepeatedly,
7477 kRetiresOnSaturation
7478 };
7479
7480 typedef std::vector<const void*> UntypedActions;
7481
7482 // Returns an Expectation object that references and co-owns this
7483 // expectation.
7484 virtual Expectation GetHandle() = 0;
7485
7486 // Asserts that the EXPECT_CALL() statement has the given property.
7487 void AssertSpecProperty(bool property,
7488 const std::string& failure_message) const {
7489 Assert(property, file_, line_, failure_message);
7490 }
7491
7492 // Expects that the EXPECT_CALL() statement has the given property.
7493 void ExpectSpecProperty(bool property,
7494 const std::string& failure_message) const {
7495 Expect(property, file_, line_, failure_message);
7496 }
7497
7498 // Explicitly specifies the cardinality of this expectation. Used
7499 // by the subclasses to implement the .Times() clause.
7500 void SpecifyCardinality(const Cardinality& cardinality);
7501
7502 // Returns true iff the user specified the cardinality explicitly
7503 // using a .Times().
7504 bool cardinality_specified() const { return cardinality_specified_; }
7505
7506 // Sets the cardinality of this expectation spec.
7507 void set_cardinality(const Cardinality& a_cardinality) {
7508 cardinality_ = a_cardinality;
7509 }
7510
7511 // The following group of methods should only be called after the
7512 // EXPECT_CALL() statement, and only when g_gmock_mutex is held by
7513 // the current thread.
7514
7515 // Retires all pre-requisites of this expectation.
7516 void RetireAllPreRequisites()
7517 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
7518
7519 // Returns true iff this expectation is retired.
7520 bool is_retired() const
7521 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
7522 g_gmock_mutex.AssertHeld();
7523 return retired_;
7524 }
7525
7526 // Retires this expectation.
7527 void Retire()
7528 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
7529 g_gmock_mutex.AssertHeld();
7530 retired_ = true;
7531 }
7532
7533 // Returns true iff this expectation is satisfied.
7534 bool IsSatisfied() const
7535 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
7536 g_gmock_mutex.AssertHeld();
7537 return cardinality().IsSatisfiedByCallCount(call_count_);
7538 }
7539
7540 // Returns true iff this expectation is saturated.
7541 bool IsSaturated() const
7542 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
7543 g_gmock_mutex.AssertHeld();
7544 return cardinality().IsSaturatedByCallCount(call_count_);
7545 }
7546
7547 // Returns true iff this expectation is over-saturated.
7548 bool IsOverSaturated() const
7549 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
7550 g_gmock_mutex.AssertHeld();
7551 return cardinality().IsOverSaturatedByCallCount(call_count_);
7552 }
7553
7554 // Returns true iff all pre-requisites of this expectation are satisfied.
7555 bool AllPrerequisitesAreSatisfied() const
7556 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
7557
7558 // Adds unsatisfied pre-requisites of this expectation to 'result'.
7559 void FindUnsatisfiedPrerequisites(ExpectationSet* result) const
7560 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
7561
7562 // Returns the number this expectation has been invoked.
7563 int call_count() const
7564 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
7565 g_gmock_mutex.AssertHeld();
7566 return call_count_;
7567 }
7568
7569 // Increments the number this expectation has been invoked.
7570 void IncrementCallCount()
7571 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
7572 g_gmock_mutex.AssertHeld();
7573 call_count_++;
7574 }
7575
7576 // Checks the action count (i.e. the number of WillOnce() and
7577 // WillRepeatedly() clauses) against the cardinality if this hasn't
7578 // been done before. Prints a warning if there are too many or too
7579 // few actions.
7580 void CheckActionCountIfNotDone() const
7581 GTEST_LOCK_EXCLUDED_(mutex_);
7582
7583 friend class ::testing::Sequence;
7584 friend class ::testing::internal::ExpectationTester;
7585
7586 template <typename Function>
7587 friend class TypedExpectation;
7588
7589 // Implements the .Times() clause.
7590 void UntypedTimes(const Cardinality& a_cardinality);
7591
7592 // This group of fields are part of the spec and won't change after
7593 // an EXPECT_CALL() statement finishes.
7594 const char* file_; // The file that contains the expectation.
7595 int line_; // The line number of the expectation.
7596 const std::string source_text_; // The EXPECT_CALL(...) source text.
7597 // True iff the cardinality is specified explicitly.
7598 bool cardinality_specified_;
7599 Cardinality cardinality_; // The cardinality of the expectation.
7600 // The immediate pre-requisites (i.e. expectations that must be
7601 // satisfied before this expectation can be matched) of this
7602 // expectation. We use std::shared_ptr in the set because we want an
7603 // Expectation object to be co-owned by its FunctionMocker and its
7604 // successors. This allows multiple mock objects to be deleted at
7605 // different times.
7606 ExpectationSet immediate_prerequisites_;
7607
7608 // This group of fields are the current state of the expectation,
7609 // and can change as the mock function is called.
7610 int call_count_; // How many times this expectation has been invoked.
7611 bool retired_; // True iff this expectation has retired.
7612 UntypedActions untyped_actions_;
7613 bool extra_matcher_specified_;
7614 bool repeated_action_specified_; // True if a WillRepeatedly() was specified.
7615 bool retires_on_saturation_;
7616 Clause last_clause_;
7617 mutable bool action_count_checked_; // Under mutex_.
7618 mutable Mutex mutex_; // Protects action_count_checked_.
7619
7620 GTEST_DISALLOW_ASSIGN_(ExpectationBase);
7621}; // class ExpectationBase
7622
7623// Impements an expectation for the given function type.
7624template <typename F>
7625class TypedExpectation : public ExpectationBase {
7626 public:
7627 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
7628 typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple;
7629 typedef typename Function<F>::Result Result;
7630
7631 TypedExpectation(FunctionMocker<F>* owner, const char* a_file, int a_line,
7632 const std::string& a_source_text,
7633 const ArgumentMatcherTuple& m)
7634 : ExpectationBase(a_file, a_line, a_source_text),
7635 owner_(owner),
7636 matchers_(m),
7637 // By default, extra_matcher_ should match anything. However,
7638 // we cannot initialize it with _ as that causes ambiguity between
7639 // Matcher's copy and move constructor for some argument types.
7640 extra_matcher_(A<const ArgumentTuple&>()),
7641 repeated_action_(DoDefault()) {}
7642
7643 ~TypedExpectation() override {
7644 // Check the validity of the action count if it hasn't been done
7645 // yet (for example, if the expectation was never used).
7646 CheckActionCountIfNotDone();
7647 for (UntypedActions::const_iterator it = untyped_actions_.begin();
7648 it != untyped_actions_.end(); ++it) {
7649 delete static_cast<const Action<F>*>(*it);
7650 }
7651 }
7652
7653 // Implements the .With() clause.
7654 TypedExpectation& With(const Matcher<const ArgumentTuple&>& m) {
7655 if (last_clause_ == kWith) {
7656 ExpectSpecProperty(false,
7657 ".With() cannot appear "
7658 "more than once in an EXPECT_CALL().");
7659 } else {
7660 ExpectSpecProperty(last_clause_ < kWith,
7661 ".With() must be the first "
7662 "clause in an EXPECT_CALL().");
7663 }
7664 last_clause_ = kWith;
7665
7666 extra_matcher_ = m;
7667 extra_matcher_specified_ = true;
7668 return *this;
7669 }
7670
7671 // Implements the .Times() clause.
7672 TypedExpectation& Times(const Cardinality& a_cardinality) {
7673 ExpectationBase::UntypedTimes(a_cardinality);
7674 return *this;
7675 }
7676
7677 // Implements the .Times() clause.
7678 TypedExpectation& Times(int n) {
7679 return Times(Exactly(n));
7680 }
7681
7682 // Implements the .InSequence() clause.
7683 TypedExpectation& InSequence(const Sequence& s) {
7684 ExpectSpecProperty(last_clause_ <= kInSequence,
7685 ".InSequence() cannot appear after .After(),"
7686 " .WillOnce(), .WillRepeatedly(), or "
7687 ".RetiresOnSaturation().");
7688 last_clause_ = kInSequence;
7689
7690 s.AddExpectation(GetHandle());
7691 return *this;
7692 }
7693 TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2) {
7694 return InSequence(s1).InSequence(s2);
7695 }
7696 TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2,
7697 const Sequence& s3) {
7698 return InSequence(s1, s2).InSequence(s3);
7699 }
7700 TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2,
7701 const Sequence& s3, const Sequence& s4) {
7702 return InSequence(s1, s2, s3).InSequence(s4);
7703 }
7704 TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2,
7705 const Sequence& s3, const Sequence& s4,
7706 const Sequence& s5) {
7707 return InSequence(s1, s2, s3, s4).InSequence(s5);
7708 }
7709
7710 // Implements that .After() clause.
7711 TypedExpectation& After(const ExpectationSet& s) {
7712 ExpectSpecProperty(last_clause_ <= kAfter,
7713 ".After() cannot appear after .WillOnce(),"
7714 " .WillRepeatedly(), or "
7715 ".RetiresOnSaturation().");
7716 last_clause_ = kAfter;
7717
7718 for (ExpectationSet::const_iterator it = s.begin(); it != s.end(); ++it) {
7719 immediate_prerequisites_ += *it;
7720 }
7721 return *this;
7722 }
7723 TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2) {
7724 return After(s1).After(s2);
7725 }
7726 TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2,
7727 const ExpectationSet& s3) {
7728 return After(s1, s2).After(s3);
7729 }
7730 TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2,
7731 const ExpectationSet& s3, const ExpectationSet& s4) {
7732 return After(s1, s2, s3).After(s4);
7733 }
7734 TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2,
7735 const ExpectationSet& s3, const ExpectationSet& s4,
7736 const ExpectationSet& s5) {
7737 return After(s1, s2, s3, s4).After(s5);
7738 }
7739
7740 // Implements the .WillOnce() clause.
7741 TypedExpectation& WillOnce(const Action<F>& action) {
7742 ExpectSpecProperty(last_clause_ <= kWillOnce,
7743 ".WillOnce() cannot appear after "
7744 ".WillRepeatedly() or .RetiresOnSaturation().");
7745 last_clause_ = kWillOnce;
7746
7747 untyped_actions_.push_back(new Action<F>(action));
7748 if (!cardinality_specified()) {
7749 set_cardinality(Exactly(static_cast<int>(untyped_actions_.size())));
7750 }
7751 return *this;
7752 }
7753
7754 // Implements the .WillRepeatedly() clause.
7755 TypedExpectation& WillRepeatedly(const Action<F>& action) {
7756 if (last_clause_ == kWillRepeatedly) {
7757 ExpectSpecProperty(false,
7758 ".WillRepeatedly() cannot appear "
7759 "more than once in an EXPECT_CALL().");
7760 } else {
7761 ExpectSpecProperty(last_clause_ < kWillRepeatedly,
7762 ".WillRepeatedly() cannot appear "
7763 "after .RetiresOnSaturation().");
7764 }
7765 last_clause_ = kWillRepeatedly;
7766 repeated_action_specified_ = true;
7767
7768 repeated_action_ = action;
7769 if (!cardinality_specified()) {
7770 set_cardinality(AtLeast(static_cast<int>(untyped_actions_.size())));
7771 }
7772
7773 // Now that no more action clauses can be specified, we check
7774 // whether their count makes sense.
7775 CheckActionCountIfNotDone();
7776 return *this;
7777 }
7778
7779 // Implements the .RetiresOnSaturation() clause.
7780 TypedExpectation& RetiresOnSaturation() {
7781 ExpectSpecProperty(last_clause_ < kRetiresOnSaturation,
7782 ".RetiresOnSaturation() cannot appear "
7783 "more than once.");
7784 last_clause_ = kRetiresOnSaturation;
7785 retires_on_saturation_ = true;
7786
7787 // Now that no more action clauses can be specified, we check
7788 // whether their count makes sense.
7789 CheckActionCountIfNotDone();
7790 return *this;
7791 }
7792
7793 // Returns the matchers for the arguments as specified inside the
7794 // EXPECT_CALL() macro.
7795 const ArgumentMatcherTuple& matchers() const {
7796 return matchers_;
7797 }
7798
7799 // Returns the matcher specified by the .With() clause.
7800 const Matcher<const ArgumentTuple&>& extra_matcher() const {
7801 return extra_matcher_;
7802 }
7803
7804 // Returns the action specified by the .WillRepeatedly() clause.
7805 const Action<F>& repeated_action() const { return repeated_action_; }
7806
7807 // If this mock method has an extra matcher (i.e. .With(matcher)),
7808 // describes it to the ostream.
7809 void MaybeDescribeExtraMatcherTo(::std::ostream* os) override {
7810 if (extra_matcher_specified_) {
7811 *os << " Expected args: ";
7812 extra_matcher_.DescribeTo(os);
7813 *os << "\n";
7814 }
7815 }
7816
7817 private:
7818 template <typename Function>
7819 friend class FunctionMocker;
7820
7821 // Returns an Expectation object that references and co-owns this
7822 // expectation.
7823 Expectation GetHandle() override { return owner_->GetHandleOf(this); }
7824
7825 // The following methods will be called only after the EXPECT_CALL()
7826 // statement finishes and when the current thread holds
7827 // g_gmock_mutex.
7828
7829 // Returns true iff this expectation matches the given arguments.
7830 bool Matches(const ArgumentTuple& args) const
7831 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
7832 g_gmock_mutex.AssertHeld();
7833 return TupleMatches(matchers_, args) && extra_matcher_.Matches(args);
7834 }
7835
7836 // Returns true iff this expectation should handle the given arguments.
7837 bool ShouldHandleArguments(const ArgumentTuple& args) const
7838 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
7839 g_gmock_mutex.AssertHeld();
7840
7841 // In case the action count wasn't checked when the expectation
7842 // was defined (e.g. if this expectation has no WillRepeatedly()
7843 // or RetiresOnSaturation() clause), we check it when the
7844 // expectation is used for the first time.
7845 CheckActionCountIfNotDone();
7846 return !is_retired() && AllPrerequisitesAreSatisfied() && Matches(args);
7847 }
7848
7849 // Describes the result of matching the arguments against this
7850 // expectation to the given ostream.
7851 void ExplainMatchResultTo(
7852 const ArgumentTuple& args,
7853 ::std::ostream* os) const
7854 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
7855 g_gmock_mutex.AssertHeld();
7856
7857 if (is_retired()) {
7858 *os << " Expected: the expectation is active\n"
7859 << " Actual: it is retired\n";
7860 } else if (!Matches(args)) {
7861 if (!TupleMatches(matchers_, args)) {
7862 ExplainMatchFailureTupleTo(matchers_, args, os);
7863 }
7864 StringMatchResultListener listener;
7865 if (!extra_matcher_.MatchAndExplain(args, &listener)) {
7866 *os << " Expected args: ";
7867 extra_matcher_.DescribeTo(os);
7868 *os << "\n Actual: don't match";
7869
7870 internal::PrintIfNotEmpty(listener.str(), os);
7871 *os << "\n";
7872 }
7873 } else if (!AllPrerequisitesAreSatisfied()) {
7874 *os << " Expected: all pre-requisites are satisfied\n"
7875 << " Actual: the following immediate pre-requisites "
7876 << "are not satisfied:\n";
7877 ExpectationSet unsatisfied_prereqs;
7878 FindUnsatisfiedPrerequisites(&unsatisfied_prereqs);
7879 int i = 0;
7880 for (ExpectationSet::const_iterator it = unsatisfied_prereqs.begin();
7881 it != unsatisfied_prereqs.end(); ++it) {
7882 it->expectation_base()->DescribeLocationTo(os);
7883 *os << "pre-requisite #" << i++ << "\n";
7884 }
7885 *os << " (end of pre-requisites)\n";
7886 } else {
7887 // This line is here just for completeness' sake. It will never
7888 // be executed as currently the ExplainMatchResultTo() function
7889 // is called only when the mock function call does NOT match the
7890 // expectation.
7891 *os << "The call matches the expectation.\n";
7892 }
7893 }
7894
7895 // Returns the action that should be taken for the current invocation.
7896 const Action<F>& GetCurrentAction(const FunctionMocker<F>* mocker,
7897 const ArgumentTuple& args) const
7898 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
7899 g_gmock_mutex.AssertHeld();
7900 const int count = call_count();
7901 Assert(count >= 1, __FILE__, __LINE__,
7902 "call_count() is <= 0 when GetCurrentAction() is "
7903 "called - this should never happen.");
7904
7905 const int action_count = static_cast<int>(untyped_actions_.size());
7906 if (action_count > 0 && !repeated_action_specified_ &&
7907 count > action_count) {
7908 // If there is at least one WillOnce() and no WillRepeatedly(),
7909 // we warn the user when the WillOnce() clauses ran out.
7910 ::std::stringstream ss;
7911 DescribeLocationTo(&ss);
7912 ss << "Actions ran out in " << source_text() << "...\n"
7913 << "Called " << count << " times, but only "
7914 << action_count << " WillOnce()"
7915 << (action_count == 1 ? " is" : "s are") << " specified - ";
7916 mocker->DescribeDefaultActionTo(args, &ss);
7917 Log(kWarning, ss.str(), 1);
7918 }
7919
7920 return count <= action_count
7921 ? *static_cast<const Action<F>*>(
7922 untyped_actions_[static_cast<size_t>(count - 1)])
7923 : repeated_action();
7924 }
7925
7926 // Given the arguments of a mock function call, if the call will
7927 // over-saturate this expectation, returns the default action;
7928 // otherwise, returns the next action in this expectation. Also
7929 // describes *what* happened to 'what', and explains *why* Google
7930 // Mock does it to 'why'. This method is not const as it calls
7931 // IncrementCallCount(). A return value of NULL means the default
7932 // action.
7933 const Action<F>* GetActionForArguments(const FunctionMocker<F>* mocker,
7934 const ArgumentTuple& args,
7935 ::std::ostream* what,
7936 ::std::ostream* why)
7937 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
7938 g_gmock_mutex.AssertHeld();
7939 if (IsSaturated()) {
7940 // We have an excessive call.
7941 IncrementCallCount();
7942 *what << "Mock function called more times than expected - ";
7943 mocker->DescribeDefaultActionTo(args, what);
7944 DescribeCallCountTo(why);
7945
7946 return nullptr;
7947 }
7948
7949 IncrementCallCount();
7950 RetireAllPreRequisites();
7951
7952 if (retires_on_saturation_ && IsSaturated()) {
7953 Retire();
7954 }
7955
7956 // Must be done after IncrementCount()!
7957 *what << "Mock function call matches " << source_text() <<"...\n";
7958 return &(GetCurrentAction(mocker, args));
7959 }
7960
7961 // All the fields below won't change once the EXPECT_CALL()
7962 // statement finishes.
7963 FunctionMocker<F>* const owner_;
7964 ArgumentMatcherTuple matchers_;
7965 Matcher<const ArgumentTuple&> extra_matcher_;
7966 Action<F> repeated_action_;
7967
7968 GTEST_DISALLOW_COPY_AND_ASSIGN_(TypedExpectation);
7969}; // class TypedExpectation
7970
7971// A MockSpec object is used by ON_CALL() or EXPECT_CALL() for
7972// specifying the default behavior of, or expectation on, a mock
7973// function.
7974
7975// Note: class MockSpec really belongs to the ::testing namespace.
7976// However if we define it in ::testing, MSVC will complain when
7977// classes in ::testing::internal declare it as a friend class
7978// template. To workaround this compiler bug, we define MockSpec in
7979// ::testing::internal and import it into ::testing.
7980
7981// Logs a message including file and line number information.
7982GTEST_API_ void LogWithLocation(testing::internal::LogSeverity severity,
7983 const char* file, int line,
7984 const std::string& message);
7985
7986template <typename F>
7987class MockSpec {
7988 public:
7989 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
7990 typedef typename internal::Function<F>::ArgumentMatcherTuple
7991 ArgumentMatcherTuple;
7992
7993 // Constructs a MockSpec object, given the function mocker object
7994 // that the spec is associated with.
7995 MockSpec(internal::FunctionMocker<F>* function_mocker,
7996 const ArgumentMatcherTuple& matchers)
7997 : function_mocker_(function_mocker), matchers_(matchers) {}
7998
7999 // Adds a new default action spec to the function mocker and returns
8000 // the newly created spec.
8001 internal::OnCallSpec<F>& InternalDefaultActionSetAt(
8002 const char* file, int line, const char* obj, const char* call) {
8003 LogWithLocation(internal::kInfo, file, line,
8004 std::string("ON_CALL(") + obj + ", " + call + ") invoked");
8005 return function_mocker_->AddNewOnCallSpec(file, line, matchers_);
8006 }
8007
8008 // Adds a new expectation spec to the function mocker and returns
8009 // the newly created spec.
8010 internal::TypedExpectation<F>& InternalExpectedAt(
8011 const char* file, int line, const char* obj, const char* call) {
8012 const std::string source_text(std::string("EXPECT_CALL(") + obj + ", " +
8013 call + ")");
8014 LogWithLocation(internal::kInfo, file, line, source_text + " invoked");
8015 return function_mocker_->AddNewExpectation(
8016 file, line, source_text, matchers_);
8017 }
8018
8019 // This operator overload is used to swallow the superfluous parameter list
8020 // introduced by the ON/EXPECT_CALL macros. See the macro comments for more
8021 // explanation.
8022 MockSpec<F>& operator()(const internal::WithoutMatchers&, void* const) {
8023 return *this;
8024 }
8025
8026 private:
8027 template <typename Function>
8028 friend class internal::FunctionMocker;
8029
8030 // The function mocker that owns this spec.
8031 internal::FunctionMocker<F>* const function_mocker_;
8032 // The argument matchers specified in the spec.
8033 ArgumentMatcherTuple matchers_;
8034
8035 GTEST_DISALLOW_ASSIGN_(MockSpec);
8036}; // class MockSpec
8037
8038// Wrapper type for generically holding an ordinary value or lvalue reference.
8039// If T is not a reference type, it must be copyable or movable.
8040// ReferenceOrValueWrapper<T> is movable, and will also be copyable unless
8041// T is a move-only value type (which means that it will always be copyable
8042// if the current platform does not support move semantics).
8043//
8044// The primary template defines handling for values, but function header
8045// comments describe the contract for the whole template (including
8046// specializations).
8047template <typename T>
8048class ReferenceOrValueWrapper {
8049 public:
8050 // Constructs a wrapper from the given value/reference.
8051 explicit ReferenceOrValueWrapper(T value)
8052 : value_(std::move(value)) {
8053 }
8054
8055 // Unwraps and returns the underlying value/reference, exactly as
8056 // originally passed. The behavior of calling this more than once on
8057 // the same object is unspecified.
8058 T Unwrap() { return std::move(value_); }
8059
8060 // Provides nondestructive access to the underlying value/reference.
8061 // Always returns a const reference (more precisely,
8062 // const RemoveReference<T>&). The behavior of calling this after
8063 // calling Unwrap on the same object is unspecified.
8064 const T& Peek() const {
8065 return value_;
8066 }
8067
8068 private:
8069 T value_;
8070};
8071
8072// Specialization for lvalue reference types. See primary template
8073// for documentation.
8074template <typename T>
8075class ReferenceOrValueWrapper<T&> {
8076 public:
8077 // Workaround for debatable pass-by-reference lint warning (c-library-team
8078 // policy precludes NOLINT in this context)
8079 typedef T& reference;
8080 explicit ReferenceOrValueWrapper(reference ref)
8081 : value_ptr_(&ref) {}
8082 T& Unwrap() { return *value_ptr_; }
8083 const T& Peek() const { return *value_ptr_; }
8084
8085 private:
8086 T* value_ptr_;
8087};
8088
8089// MSVC warns about using 'this' in base member initializer list, so
8090// we need to temporarily disable the warning. We have to do it for
8091// the entire class to suppress the warning, even though it's about
8092// the constructor only.
8093GTEST_DISABLE_MSC_WARNINGS_PUSH_(4355)
8094
8095// C++ treats the void type specially. For example, you cannot define
8096// a void-typed variable or pass a void value to a function.
8097// ActionResultHolder<T> holds a value of type T, where T must be a
8098// copyable type or void (T doesn't need to be default-constructable).
8099// It hides the syntactic difference between void and other types, and
8100// is used to unify the code for invoking both void-returning and
8101// non-void-returning mock functions.
8102
8103// Untyped base class for ActionResultHolder<T>.
8104class UntypedActionResultHolderBase {
8105 public:
8106 virtual ~UntypedActionResultHolderBase() {}
8107
8108 // Prints the held value as an action's result to os.
8109 virtual void PrintAsActionResult(::std::ostream* os) const = 0;
8110};
8111
8112// This generic definition is used when T is not void.
8113template <typename T>
8114class ActionResultHolder : public UntypedActionResultHolderBase {
8115 public:
8116 // Returns the held value. Must not be called more than once.
8117 T Unwrap() {
8118 return result_.Unwrap();
8119 }
8120
8121 // Prints the held value as an action's result to os.
8122 void PrintAsActionResult(::std::ostream* os) const override {
8123 *os << "\n Returns: ";
8124 // T may be a reference type, so we don't use UniversalPrint().
8125 UniversalPrinter<T>::Print(result_.Peek(), os);
8126 }
8127
8128 // Performs the given mock function's default action and returns the
8129 // result in a new-ed ActionResultHolder.
8130 template <typename F>
8131 static ActionResultHolder* PerformDefaultAction(
8132 const FunctionMocker<F>* func_mocker,
8133 typename Function<F>::ArgumentTuple&& args,
8134 const std::string& call_description) {
8135 return new ActionResultHolder(Wrapper(func_mocker->PerformDefaultAction(
8136 std::move(args), call_description)));
8137 }
8138
8139 // Performs the given action and returns the result in a new-ed
8140 // ActionResultHolder.
8141 template <typename F>
8142 static ActionResultHolder* PerformAction(
8143 const Action<F>& action, typename Function<F>::ArgumentTuple&& args) {
8144 return new ActionResultHolder(
8145 Wrapper(action.Perform(std::move(args))));
8146 }
8147
8148 private:
8149 typedef ReferenceOrValueWrapper<T> Wrapper;
8150
8151 explicit ActionResultHolder(Wrapper result)
8152 : result_(std::move(result)) {
8153 }
8154
8155 Wrapper result_;
8156
8157 GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionResultHolder);
8158};
8159
8160// Specialization for T = void.
8161template <>
8162class ActionResultHolder<void> : public UntypedActionResultHolderBase {
8163 public:
8164 void Unwrap() { }
8165
8166 void PrintAsActionResult(::std::ostream* /* os */) const override {}
8167
8168 // Performs the given mock function's default action and returns ownership
8169 // of an empty ActionResultHolder*.
8170 template <typename F>
8171 static ActionResultHolder* PerformDefaultAction(
8172 const FunctionMocker<F>* func_mocker,
8173 typename Function<F>::ArgumentTuple&& args,
8174 const std::string& call_description) {
8175 func_mocker->PerformDefaultAction(std::move(args), call_description);
8176 return new ActionResultHolder;
8177 }
8178
8179 // Performs the given action and returns ownership of an empty
8180 // ActionResultHolder*.
8181 template <typename F>
8182 static ActionResultHolder* PerformAction(
8183 const Action<F>& action, typename Function<F>::ArgumentTuple&& args) {
8184 action.Perform(std::move(args));
8185 return new ActionResultHolder;
8186 }
8187
8188 private:
8189 ActionResultHolder() {}
8190 GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionResultHolder);
8191};
8192
8193template <typename F>
8194class FunctionMocker;
8195
8196template <typename R, typename... Args>
8197class FunctionMocker<R(Args...)> final : public UntypedFunctionMockerBase {
8198 using F = R(Args...);
8199
8200 public:
8201 using Result = R;
8202 using ArgumentTuple = std::tuple<Args...>;
8203 using ArgumentMatcherTuple = std::tuple<Matcher<Args>...>;
8204
8205 FunctionMocker() {}
8206
8207 // There is no generally useful and implementable semantics of
8208 // copying a mock object, so copying a mock is usually a user error.
8209 // Thus we disallow copying function mockers. If the user really
8210 // wants to copy a mock object, they should implement their own copy
8211 // operation, for example:
8212 //
8213 // class MockFoo : public Foo {
8214 // public:
8215 // // Defines a copy constructor explicitly.
8216 // MockFoo(const MockFoo& src) {}
8217 // ...
8218 // };
8219 FunctionMocker(const FunctionMocker&) = delete;
8220 FunctionMocker& operator=(const FunctionMocker&) = delete;
8221
8222 // The destructor verifies that all expectations on this mock
8223 // function have been satisfied. If not, it will report Google Test
8224 // non-fatal failures for the violations.
8225 ~FunctionMocker() override GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
8226 MutexLock l(&g_gmock_mutex);
8227 VerifyAndClearExpectationsLocked();
8228 Mock::UnregisterLocked(this);
8229 ClearDefaultActionsLocked();
8230 }
8231
8232 // Returns the ON_CALL spec that matches this mock function with the
8233 // given arguments; returns NULL if no matching ON_CALL is found.
8234 // L = *
8235 const OnCallSpec<F>* FindOnCallSpec(
8236 const ArgumentTuple& args) const {
8237 for (UntypedOnCallSpecs::const_reverse_iterator it
8238 = untyped_on_call_specs_.rbegin();
8239 it != untyped_on_call_specs_.rend(); ++it) {
8240 const OnCallSpec<F>* spec = static_cast<const OnCallSpec<F>*>(*it);
8241 if (spec->Matches(args))
8242 return spec;
8243 }
8244
8245 return nullptr;
8246 }
8247
8248 // Performs the default action of this mock function on the given
8249 // arguments and returns the result. Asserts (or throws if
8250 // exceptions are enabled) with a helpful call descrption if there
8251 // is no valid return value. This method doesn't depend on the
8252 // mutable state of this object, and thus can be called concurrently
8253 // without locking.
8254 // L = *
8255 Result PerformDefaultAction(ArgumentTuple&& args,
8256 const std::string& call_description) const {
8257 const OnCallSpec<F>* const spec =
8258 this->FindOnCallSpec(args);
8259 if (spec != nullptr) {
8260 return spec->GetAction().Perform(std::move(args));
8261 }
8262 const std::string message =
8263 call_description +
8264 "\n The mock function has no default action "
8265 "set, and its return type has no default value set.";
8266#if GTEST_HAS_EXCEPTIONS
8267 if (!DefaultValue<Result>::Exists()) {
8268 throw std::runtime_error(message);
8269 }
8270#else
8271 Assert(DefaultValue<Result>::Exists(), "", -1, message);
8272#endif
8273 return DefaultValue<Result>::Get();
8274 }
8275
8276 // Performs the default action with the given arguments and returns
8277 // the action's result. The call description string will be used in
8278 // the error message to describe the call in the case the default
8279 // action fails. The caller is responsible for deleting the result.
8280 // L = *
8281 UntypedActionResultHolderBase* UntypedPerformDefaultAction(
8282 void* untyped_args, // must point to an ArgumentTuple
8283 const std::string& call_description) const override {
8284 ArgumentTuple* args = static_cast<ArgumentTuple*>(untyped_args);
8285 return ResultHolder::PerformDefaultAction(this, std::move(*args),
8286 call_description);
8287 }
8288
8289 // Performs the given action with the given arguments and returns
8290 // the action's result. The caller is responsible for deleting the
8291 // result.
8292 // L = *
8293 UntypedActionResultHolderBase* UntypedPerformAction(
8294 const void* untyped_action, void* untyped_args) const override {
8295 // Make a copy of the action before performing it, in case the
8296 // action deletes the mock object (and thus deletes itself).
8297 const Action<F> action = *static_cast<const Action<F>*>(untyped_action);
8298 ArgumentTuple* args = static_cast<ArgumentTuple*>(untyped_args);
8299 return ResultHolder::PerformAction(action, std::move(*args));
8300 }
8301
8302 // Implements UntypedFunctionMockerBase::ClearDefaultActionsLocked():
8303 // clears the ON_CALL()s set on this mock function.
8304 void ClearDefaultActionsLocked() override
8305 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
8306 g_gmock_mutex.AssertHeld();
8307
8308 // Deleting our default actions may trigger other mock objects to be
8309 // deleted, for example if an action contains a reference counted smart
8310 // pointer to that mock object, and that is the last reference. So if we
8311 // delete our actions within the context of the global mutex we may deadlock
8312 // when this method is called again. Instead, make a copy of the set of
8313 // actions to delete, clear our set within the mutex, and then delete the
8314 // actions outside of the mutex.
8315 UntypedOnCallSpecs specs_to_delete;
8316 untyped_on_call_specs_.swap(specs_to_delete);
8317
8318 g_gmock_mutex.Unlock();
8319 for (UntypedOnCallSpecs::const_iterator it =
8320 specs_to_delete.begin();
8321 it != specs_to_delete.end(); ++it) {
8322 delete static_cast<const OnCallSpec<F>*>(*it);
8323 }
8324
8325 // Lock the mutex again, since the caller expects it to be locked when we
8326 // return.
8327 g_gmock_mutex.Lock();
8328 }
8329
8330 // Returns the result of invoking this mock function with the given
8331 // arguments. This function can be safely called from multiple
8332 // threads concurrently.
8333 Result Invoke(Args... args) GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
8334 ArgumentTuple tuple(std::forward<Args>(args)...);
8335 std::unique_ptr<ResultHolder> holder(DownCast_<ResultHolder*>(
8336 this->UntypedInvokeWith(static_cast<void*>(&tuple))));
8337 return holder->Unwrap();
8338 }
8339
8340 MockSpec<F> With(Matcher<Args>... m) {
8341 return MockSpec<F>(this, ::std::make_tuple(std::move(m)...));
8342 }
8343
8344 protected:
8345 template <typename Function>
8346 friend class MockSpec;
8347
8348 typedef ActionResultHolder<Result> ResultHolder;
8349
8350 // Adds and returns a default action spec for this mock function.
8351 OnCallSpec<F>& AddNewOnCallSpec(
8352 const char* file, int line,
8353 const ArgumentMatcherTuple& m)
8354 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
8355 Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line);
8356 OnCallSpec<F>* const on_call_spec = new OnCallSpec<F>(file, line, m);
8357 untyped_on_call_specs_.push_back(on_call_spec);
8358 return *on_call_spec;
8359 }
8360
8361 // Adds and returns an expectation spec for this mock function.
8362 TypedExpectation<F>& AddNewExpectation(const char* file, int line,
8363 const std::string& source_text,
8364 const ArgumentMatcherTuple& m)
8365 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
8366 Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line);
8367 TypedExpectation<F>* const expectation =
8368 new TypedExpectation<F>(this, file, line, source_text, m);
8369 const std::shared_ptr<ExpectationBase> untyped_expectation(expectation);
8370 // See the definition of untyped_expectations_ for why access to
8371 // it is unprotected here.
8372 untyped_expectations_.push_back(untyped_expectation);
8373
8374 // Adds this expectation into the implicit sequence if there is one.
8375 Sequence* const implicit_sequence = g_gmock_implicit_sequence.get();
8376 if (implicit_sequence != nullptr) {
8377 implicit_sequence->AddExpectation(Expectation(untyped_expectation));
8378 }
8379
8380 return *expectation;
8381 }
8382
8383 private:
8384 template <typename Func> friend class TypedExpectation;
8385
8386 // Some utilities needed for implementing UntypedInvokeWith().
8387
8388 // Describes what default action will be performed for the given
8389 // arguments.
8390 // L = *
8391 void DescribeDefaultActionTo(const ArgumentTuple& args,
8392 ::std::ostream* os) const {
8393 const OnCallSpec<F>* const spec = FindOnCallSpec(args);
8394
8395 if (spec == nullptr) {
8396 *os << (internal::type_equals<Result, void>::value ?
8397 "returning directly.\n" :
8398 "returning default value.\n");
8399 } else {
8400 *os << "taking default action specified at:\n"
8401 << FormatFileLocation(spec->file(), spec->line()) << "\n";
8402 }
8403 }
8404
8405 // Writes a message that the call is uninteresting (i.e. neither
8406 // explicitly expected nor explicitly unexpected) to the given
8407 // ostream.
8408 void UntypedDescribeUninterestingCall(const void* untyped_args,
8409 ::std::ostream* os) const override
8410 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
8411 const ArgumentTuple& args =
8412 *static_cast<const ArgumentTuple*>(untyped_args);
8413 *os << "Uninteresting mock function call - ";
8414 DescribeDefaultActionTo(args, os);
8415 *os << " Function call: " << Name();
8416 UniversalPrint(args, os);
8417 }
8418
8419 // Returns the expectation that matches the given function arguments
8420 // (or NULL is there's no match); when a match is found,
8421 // untyped_action is set to point to the action that should be
8422 // performed (or NULL if the action is "do default"), and
8423 // is_excessive is modified to indicate whether the call exceeds the
8424 // expected number.
8425 //
8426 // Critical section: We must find the matching expectation and the
8427 // corresponding action that needs to be taken in an ATOMIC
8428 // transaction. Otherwise another thread may call this mock
8429 // method in the middle and mess up the state.
8430 //
8431 // However, performing the action has to be left out of the critical
8432 // section. The reason is that we have no control on what the
8433 // action does (it can invoke an arbitrary user function or even a
8434 // mock function) and excessive locking could cause a dead lock.
8435 const ExpectationBase* UntypedFindMatchingExpectation(
8436 const void* untyped_args, const void** untyped_action, bool* is_excessive,
8437 ::std::ostream* what, ::std::ostream* why) override
8438 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
8439 const ArgumentTuple& args =
8440 *static_cast<const ArgumentTuple*>(untyped_args);
8441 MutexLock l(&g_gmock_mutex);
8442 TypedExpectation<F>* exp = this->FindMatchingExpectationLocked(args);
8443 if (exp == nullptr) { // A match wasn't found.
8444 this->FormatUnexpectedCallMessageLocked(args, what, why);
8445 return nullptr;
8446 }
8447
8448 // This line must be done before calling GetActionForArguments(),
8449 // which will increment the call count for *exp and thus affect
8450 // its saturation status.
8451 *is_excessive = exp->IsSaturated();
8452 const Action<F>* action = exp->GetActionForArguments(this, args, what, why);
8453 if (action != nullptr && action->IsDoDefault())
8454 action = nullptr; // Normalize "do default" to NULL.
8455 *untyped_action = action;
8456 return exp;
8457 }
8458
8459 // Prints the given function arguments to the ostream.
8460 void UntypedPrintArgs(const void* untyped_args,
8461 ::std::ostream* os) const override {
8462 const ArgumentTuple& args =
8463 *static_cast<const ArgumentTuple*>(untyped_args);
8464 UniversalPrint(args, os);
8465 }
8466
8467 // Returns the expectation that matches the arguments, or NULL if no
8468 // expectation matches them.
8469 TypedExpectation<F>* FindMatchingExpectationLocked(
8470 const ArgumentTuple& args) const
8471 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
8472 g_gmock_mutex.AssertHeld();
8473 // See the definition of untyped_expectations_ for why access to
8474 // it is unprotected here.
8475 for (typename UntypedExpectations::const_reverse_iterator it =
8476 untyped_expectations_.rbegin();
8477 it != untyped_expectations_.rend(); ++it) {
8478 TypedExpectation<F>* const exp =
8479 static_cast<TypedExpectation<F>*>(it->get());
8480 if (exp->ShouldHandleArguments(args)) {
8481 return exp;
8482 }
8483 }
8484 return nullptr;
8485 }
8486
8487 // Returns a message that the arguments don't match any expectation.
8488 void FormatUnexpectedCallMessageLocked(
8489 const ArgumentTuple& args,
8490 ::std::ostream* os,
8491 ::std::ostream* why) const
8492 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
8493 g_gmock_mutex.AssertHeld();
8494 *os << "\nUnexpected mock function call - ";
8495 DescribeDefaultActionTo(args, os);
8496 PrintTriedExpectationsLocked(args, why);
8497 }
8498
8499 // Prints a list of expectations that have been tried against the
8500 // current mock function call.
8501 void PrintTriedExpectationsLocked(
8502 const ArgumentTuple& args,
8503 ::std::ostream* why) const
8504 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
8505 g_gmock_mutex.AssertHeld();
8506 const size_t count = untyped_expectations_.size();
8507 *why << "Google Mock tried the following " << count << " "
8508 << (count == 1 ? "expectation, but it didn't match" :
8509 "expectations, but none matched")
8510 << ":\n";
8511 for (size_t i = 0; i < count; i++) {
8512 TypedExpectation<F>* const expectation =
8513 static_cast<TypedExpectation<F>*>(untyped_expectations_[i].get());
8514 *why << "\n";
8515 expectation->DescribeLocationTo(why);
8516 if (count > 1) {
8517 *why << "tried expectation #" << i << ": ";
8518 }
8519 *why << expectation->source_text() << "...\n";
8520 expectation->ExplainMatchResultTo(args, why);
8521 expectation->DescribeCallCountTo(why);
8522 }
8523 }
8524}; // class FunctionMocker
8525
8526GTEST_DISABLE_MSC_WARNINGS_POP_() // 4355
8527
8528// Reports an uninteresting call (whose description is in msg) in the
8529// manner specified by 'reaction'.
8530void ReportUninterestingCall(CallReaction reaction, const std::string& msg);
8531
8532} // namespace internal
8533
8534// A MockFunction<F> class has one mock method whose type is F. It is
8535// useful when you just want your test code to emit some messages and
8536// have Google Mock verify the right messages are sent (and perhaps at
8537// the right times). For example, if you are exercising code:
8538//
8539// Foo(1);
8540// Foo(2);
8541// Foo(3);
8542//
8543// and want to verify that Foo(1) and Foo(3) both invoke
8544// mock.Bar("a"), but Foo(2) doesn't invoke anything, you can write:
8545//
8546// TEST(FooTest, InvokesBarCorrectly) {
8547// MyMock mock;
8548// MockFunction<void(string check_point_name)> check;
8549// {
8550// InSequence s;
8551//
8552// EXPECT_CALL(mock, Bar("a"));
8553// EXPECT_CALL(check, Call("1"));
8554// EXPECT_CALL(check, Call("2"));
8555// EXPECT_CALL(mock, Bar("a"));
8556// }
8557// Foo(1);
8558// check.Call("1");
8559// Foo(2);
8560// check.Call("2");
8561// Foo(3);
8562// }
8563//
8564// The expectation spec says that the first Bar("a") must happen
8565// before check point "1", the second Bar("a") must happen after check
8566// point "2", and nothing should happen between the two check
8567// points. The explicit check points make it easy to tell which
8568// Bar("a") is called by which call to Foo().
8569//
8570// MockFunction<F> can also be used to exercise code that accepts
8571// std::function<F> callbacks. To do so, use AsStdFunction() method
8572// to create std::function proxy forwarding to original object's Call.
8573// Example:
8574//
8575// TEST(FooTest, RunsCallbackWithBarArgument) {
8576// MockFunction<int(string)> callback;
8577// EXPECT_CALL(callback, Call("bar")).WillOnce(Return(1));
8578// Foo(callback.AsStdFunction());
8579// }
8580template <typename F>
8581class MockFunction;
8582
8583template <typename R, typename... Args>
8584class MockFunction<R(Args...)> {
8585 public:
8586 MockFunction() {}
8587 MockFunction(const MockFunction&) = delete;
8588 MockFunction& operator=(const MockFunction&) = delete;
8589
8590 std::function<R(Args...)> AsStdFunction() {
8591 return [this](Args... args) -> R {
8592 return this->Call(std::forward<Args>(args)...);
8593 };
8594 }
8595
8596 // Implementation detail: the expansion of the MOCK_METHOD macro.
8597 R Call(Args... args) {
8598 mock_.SetOwnerAndName(this, "Call");
8599 return mock_.Invoke(std::forward<Args>(args)...);
8600 }
8601
8602 internal::MockSpec<R(Args...)> gmock_Call(Matcher<Args>... m) {
8603 mock_.RegisterOwner(this);
8604 return mock_.With(std::move(m)...);
8605 }
8606
8607 internal::MockSpec<R(Args...)> gmock_Call(const internal::WithoutMatchers&,
8608 R (*)(Args...)) {
8609 return this->gmock_Call(::testing::A<Args>()...);
8610 }
8611
8612 private:
8613 mutable internal::FunctionMocker<R(Args...)> mock_;
8614};
8615
8616// The style guide prohibits "using" statements in a namespace scope
8617// inside a header file. However, the MockSpec class template is
8618// meant to be defined in the ::testing namespace. The following line
8619// is just a trick for working around a bug in MSVC 8.0, which cannot
8620// handle it if we define MockSpec in ::testing.
8621using internal::MockSpec;
8622
8623// Const(x) is a convenient function for obtaining a const reference
8624// to x. This is useful for setting expectations on an overloaded
8625// const mock method, e.g.
8626//
8627// class MockFoo : public FooInterface {
8628// public:
8629// MOCK_METHOD0(Bar, int());
8630// MOCK_CONST_METHOD0(Bar, int&());
8631// };
8632//
8633// MockFoo foo;
8634// // Expects a call to non-const MockFoo::Bar().
8635// EXPECT_CALL(foo, Bar());
8636// // Expects a call to const MockFoo::Bar().
8637// EXPECT_CALL(Const(foo), Bar());
8638template <typename T>
8639inline const T& Const(const T& x) { return x; }
8640
8641// Constructs an Expectation object that references and co-owns exp.
8642inline Expectation::Expectation(internal::ExpectationBase& exp) // NOLINT
8643 : expectation_base_(exp.GetHandle().expectation_base()) {}
8644
8645} // namespace testing
8646
8647GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
8648
8649// Implementation for ON_CALL and EXPECT_CALL macros. A separate macro is
8650// required to avoid compile errors when the name of the method used in call is
8651// a result of macro expansion. See CompilesWithMethodNameExpandedFromMacro
8652// tests in internal/gmock-spec-builders_test.cc for more details.
8653//
8654// This macro supports statements both with and without parameter matchers. If
8655// the parameter list is omitted, gMock will accept any parameters, which allows
8656// tests to be written that don't need to encode the number of method
8657// parameter. This technique may only be used for non-overloaded methods.
8658//
8659// // These are the same:
8660// ON_CALL(mock, NoArgsMethod()).WillByDefault(...);
8661// ON_CALL(mock, NoArgsMethod).WillByDefault(...);
8662//
8663// // As are these:
8664// ON_CALL(mock, TwoArgsMethod(_, _)).WillByDefault(...);
8665// ON_CALL(mock, TwoArgsMethod).WillByDefault(...);
8666//
8667// // Can also specify args if you want, of course:
8668// ON_CALL(mock, TwoArgsMethod(_, 45)).WillByDefault(...);
8669//
8670// // Overloads work as long as you specify parameters:
8671// ON_CALL(mock, OverloadedMethod(_)).WillByDefault(...);
8672// ON_CALL(mock, OverloadedMethod(_, _)).WillByDefault(...);
8673//
8674// // Oops! Which overload did you want?
8675// ON_CALL(mock, OverloadedMethod).WillByDefault(...);
8676// => ERROR: call to member function 'gmock_OverloadedMethod' is ambiguous
8677//
8678// How this works: The mock class uses two overloads of the gmock_Method
8679// expectation setter method plus an operator() overload on the MockSpec object.
8680// In the matcher list form, the macro expands to:
8681//
8682// // This statement:
8683// ON_CALL(mock, TwoArgsMethod(_, 45))...
8684//
8685// // ...expands to:
8686// mock.gmock_TwoArgsMethod(_, 45)(WithoutMatchers(), nullptr)...
8687// |-------------v---------------||------------v-------------|
8688// invokes first overload swallowed by operator()
8689//
8690// // ...which is essentially:
8691// mock.gmock_TwoArgsMethod(_, 45)...
8692//
8693// Whereas the form without a matcher list:
8694//
8695// // This statement:
8696// ON_CALL(mock, TwoArgsMethod)...
8697//
8698// // ...expands to:
8699// mock.gmock_TwoArgsMethod(WithoutMatchers(), nullptr)...
8700// |-----------------------v--------------------------|
8701// invokes second overload
8702//
8703// // ...which is essentially:
8704// mock.gmock_TwoArgsMethod(_, _)...
8705//
8706// The WithoutMatchers() argument is used to disambiguate overloads and to
8707// block the caller from accidentally invoking the second overload directly. The
8708// second argument is an internal type derived from the method signature. The
8709// failure to disambiguate two overloads of this method in the ON_CALL statement
8710// is how we block callers from setting expectations on overloaded methods.
8711#define GMOCK_ON_CALL_IMPL_(mock_expr, Setter, call) \
8712 ((mock_expr).gmock_##call)(::testing::internal::GetWithoutMatchers(), \
8713 nullptr) \
8714 .Setter(__FILE__, __LINE__, #mock_expr, #call)
8715
8716#define ON_CALL(obj, call) \
8717 GMOCK_ON_CALL_IMPL_(obj, InternalDefaultActionSetAt, call)
8718
8719#define EXPECT_CALL(obj, call) \
8720 GMOCK_ON_CALL_IMPL_(obj, InternalExpectedAt, call)
8721
8722#endif // GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_
8723
8724namespace testing {
8725namespace internal {
8726// Removes the given pointer; this is a helper for the expectation setter method
8727// for parameterless matchers.
8728//
8729// We want to make sure that the user cannot set a parameterless expectation on
8730// overloaded methods, including methods which are overloaded on const. Example:
8731//
8732// class MockClass {
8733// MOCK_METHOD0(GetName, string&());
8734// MOCK_CONST_METHOD0(GetName, const string&());
8735// };
8736//
8737// TEST() {
8738// // This should be an error, as it's not clear which overload is expected.
8739// EXPECT_CALL(mock, GetName).WillOnce(ReturnRef(value));
8740// }
8741//
8742// Here are the generated expectation-setter methods:
8743//
8744// class MockClass {
8745// // Overload 1
8746// MockSpec<string&()> gmock_GetName() { ... }
8747// // Overload 2. Declared const so that the compiler will generate an
8748// // error when trying to resolve between this and overload 4 in
8749// // 'gmock_GetName(WithoutMatchers(), nullptr)'.
8750// MockSpec<string&()> gmock_GetName(
8751// const WithoutMatchers&, const Function<string&()>*) const {
8752// // Removes const from this, calls overload 1
8753// return AdjustConstness_(this)->gmock_GetName();
8754// }
8755//
8756// // Overload 3
8757// const string& gmock_GetName() const { ... }
8758// // Overload 4
8759// MockSpec<const string&()> gmock_GetName(
8760// const WithoutMatchers&, const Function<const string&()>*) const {
8761// // Does not remove const, calls overload 3
8762// return AdjustConstness_const(this)->gmock_GetName();
8763// }
8764// }
8765//
8766template <typename MockType>
8767const MockType* AdjustConstness_const(const MockType* mock) {
8768 return mock;
8769}
8770
8771// Removes const from and returns the given pointer; this is a helper for the
8772// expectation setter method for parameterless matchers.
8773template <typename MockType>
8774MockType* AdjustConstness_(const MockType* mock) {
8775 return const_cast<MockType*>(mock);
8776}
8777
8778} // namespace internal
8779
8780// The style guide prohibits "using" statements in a namespace scope
8781// inside a header file. However, the FunctionMocker class template
8782// is meant to be defined in the ::testing namespace. The following
8783// line is just a trick for working around a bug in MSVC 8.0, which
8784// cannot handle it if we define FunctionMocker in ::testing.
8785using internal::FunctionMocker;
8786
8787// GMOCK_RESULT_(tn, F) expands to the result type of function type F.
8788// We define this as a variadic macro in case F contains unprotected
8789// commas (the same reason that we use variadic macros in other places
8790// in this file).
8791// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
8792#define GMOCK_RESULT_(tn, ...) \
8793 tn ::testing::internal::Function<__VA_ARGS__>::Result
8794
8795// The type of argument N of the given function type.
8796// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
8797#define GMOCK_ARG_(tn, N, ...) \
8798 tn ::testing::internal::Function<__VA_ARGS__>::template Arg<N-1>::type
8799
8800// The matcher type for argument N of the given function type.
8801// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
8802#define GMOCK_MATCHER_(tn, N, ...) \
8803 const ::testing::Matcher<GMOCK_ARG_(tn, N, __VA_ARGS__)>&
8804
8805// The variable for mocking the given method.
8806// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
8807#define GMOCK_MOCKER_(arity, constness, Method) \
8808 GTEST_CONCAT_TOKEN_(gmock##constness##arity##_##Method##_, __LINE__)
8809
8810// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
8811#define GMOCK_METHOD0_(tn, constness, ct, Method, ...) \
8812 static_assert(0 == \
8813 ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, \
8814 "MOCK_METHOD<N> must match argument count.");\
8815 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
8816 ) constness { \
8817 GMOCK_MOCKER_(0, constness, Method).SetOwnerAndName(this, #Method); \
8818 return GMOCK_MOCKER_(0, constness, Method).Invoke(); \
8819 } \
8820 ::testing::MockSpec<__VA_ARGS__> \
8821 gmock_##Method() constness { \
8822 GMOCK_MOCKER_(0, constness, Method).RegisterOwner(this); \
8823 return GMOCK_MOCKER_(0, constness, Method).With(); \
8824 } \
8825 ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
8826 const ::testing::internal::WithoutMatchers&, \
8827 constness ::testing::internal::Function<__VA_ARGS__>* ) const { \
8828 return ::testing::internal::AdjustConstness_##constness(this)-> \
8829 gmock_##Method(); \
8830 } \
8831 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(0, constness, \
8832 Method)
8833
8834// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
8835#define GMOCK_METHOD1_(tn, constness, ct, Method, ...) \
8836 static_assert(1 == \
8837 ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, \
8838 "MOCK_METHOD<N> must match argument count.");\
8839 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
8840 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1) constness { \
8841 GMOCK_MOCKER_(1, constness, Method).SetOwnerAndName(this, #Method); \
8842 return GMOCK_MOCKER_(1, constness, \
8843 Method).Invoke(::std::forward<GMOCK_ARG_(tn, 1, \
8844 __VA_ARGS__)>(gmock_a1)); \
8845 } \
8846 ::testing::MockSpec<__VA_ARGS__> \
8847 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1) constness { \
8848 GMOCK_MOCKER_(1, constness, Method).RegisterOwner(this); \
8849 return GMOCK_MOCKER_(1, constness, Method).With(gmock_a1); \
8850 } \
8851 ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
8852 const ::testing::internal::WithoutMatchers&, \
8853 constness ::testing::internal::Function<__VA_ARGS__>* ) const { \
8854 return ::testing::internal::AdjustConstness_##constness(this)-> \
8855 gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>()); \
8856 } \
8857 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(1, constness, \
8858 Method)
8859
8860// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
8861#define GMOCK_METHOD2_(tn, constness, ct, Method, ...) \
8862 static_assert(2 == \
8863 ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, \
8864 "MOCK_METHOD<N> must match argument count.");\
8865 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
8866 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \
8867 __VA_ARGS__) gmock_a2) constness { \
8868 GMOCK_MOCKER_(2, constness, Method).SetOwnerAndName(this, #Method); \
8869 return GMOCK_MOCKER_(2, constness, \
8870 Method).Invoke(::std::forward<GMOCK_ARG_(tn, 1, \
8871 __VA_ARGS__)>(gmock_a1), \
8872 ::std::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(gmock_a2)); \
8873 } \
8874 ::testing::MockSpec<__VA_ARGS__> \
8875 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
8876 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2) constness { \
8877 GMOCK_MOCKER_(2, constness, Method).RegisterOwner(this); \
8878 return GMOCK_MOCKER_(2, constness, Method).With(gmock_a1, gmock_a2); \
8879 } \
8880 ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
8881 const ::testing::internal::WithoutMatchers&, \
8882 constness ::testing::internal::Function<__VA_ARGS__>* ) const { \
8883 return ::testing::internal::AdjustConstness_##constness(this)-> \
8884 gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \
8885 ::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>()); \
8886 } \
8887 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(2, constness, \
8888 Method)
8889
8890// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
8891#define GMOCK_METHOD3_(tn, constness, ct, Method, ...) \
8892 static_assert(3 == \
8893 ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, \
8894 "MOCK_METHOD<N> must match argument count.");\
8895 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
8896 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \
8897 __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, \
8898 __VA_ARGS__) gmock_a3) constness { \
8899 GMOCK_MOCKER_(3, constness, Method).SetOwnerAndName(this, #Method); \
8900 return GMOCK_MOCKER_(3, constness, \
8901 Method).Invoke(::std::forward<GMOCK_ARG_(tn, 1, \
8902 __VA_ARGS__)>(gmock_a1), \
8903 ::std::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(gmock_a2), \
8904 ::std::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(gmock_a3)); \
8905 } \
8906 ::testing::MockSpec<__VA_ARGS__> \
8907 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
8908 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
8909 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3) constness { \
8910 GMOCK_MOCKER_(3, constness, Method).RegisterOwner(this); \
8911 return GMOCK_MOCKER_(3, constness, Method).With(gmock_a1, gmock_a2, \
8912 gmock_a3); \
8913 } \
8914 ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
8915 const ::testing::internal::WithoutMatchers&, \
8916 constness ::testing::internal::Function<__VA_ARGS__>* ) const { \
8917 return ::testing::internal::AdjustConstness_##constness(this)-> \
8918 gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \
8919 ::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \
8920 ::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>()); \
8921 } \
8922 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(3, constness, \
8923 Method)
8924
8925// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
8926#define GMOCK_METHOD4_(tn, constness, ct, Method, ...) \
8927 static_assert(4 == \
8928 ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, \
8929 "MOCK_METHOD<N> must match argument count.");\
8930 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
8931 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \
8932 __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
8933 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4) constness { \
8934 GMOCK_MOCKER_(4, constness, Method).SetOwnerAndName(this, #Method); \
8935 return GMOCK_MOCKER_(4, constness, \
8936 Method).Invoke(::std::forward<GMOCK_ARG_(tn, 1, \
8937 __VA_ARGS__)>(gmock_a1), \
8938 ::std::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(gmock_a2), \
8939 ::std::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(gmock_a3), \
8940 ::std::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(gmock_a4)); \
8941 } \
8942 ::testing::MockSpec<__VA_ARGS__> \
8943 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
8944 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
8945 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
8946 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4) constness { \
8947 GMOCK_MOCKER_(4, constness, Method).RegisterOwner(this); \
8948 return GMOCK_MOCKER_(4, constness, Method).With(gmock_a1, gmock_a2, \
8949 gmock_a3, gmock_a4); \
8950 } \
8951 ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
8952 const ::testing::internal::WithoutMatchers&, \
8953 constness ::testing::internal::Function<__VA_ARGS__>* ) const { \
8954 return ::testing::internal::AdjustConstness_##constness(this)-> \
8955 gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \
8956 ::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \
8957 ::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(), \
8958 ::testing::A<GMOCK_ARG_(tn, 4, __VA_ARGS__)>()); \
8959 } \
8960 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(4, constness, \
8961 Method)
8962
8963// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
8964#define GMOCK_METHOD5_(tn, constness, ct, Method, ...) \
8965 static_assert(5 == \
8966 ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, \
8967 "MOCK_METHOD<N> must match argument count.");\
8968 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
8969 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \
8970 __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
8971 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, GMOCK_ARG_(tn, 5, \
8972 __VA_ARGS__) gmock_a5) constness { \
8973 GMOCK_MOCKER_(5, constness, Method).SetOwnerAndName(this, #Method); \
8974 return GMOCK_MOCKER_(5, constness, \
8975 Method).Invoke(::std::forward<GMOCK_ARG_(tn, 1, \
8976 __VA_ARGS__)>(gmock_a1), \
8977 ::std::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(gmock_a2), \
8978 ::std::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(gmock_a3), \
8979 ::std::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(gmock_a4), \
8980 ::std::forward<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(gmock_a5)); \
8981 } \
8982 ::testing::MockSpec<__VA_ARGS__> \
8983 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
8984 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
8985 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
8986 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
8987 GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5) constness { \
8988 GMOCK_MOCKER_(5, constness, Method).RegisterOwner(this); \
8989 return GMOCK_MOCKER_(5, constness, Method).With(gmock_a1, gmock_a2, \
8990 gmock_a3, gmock_a4, gmock_a5); \
8991 } \
8992 ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
8993 const ::testing::internal::WithoutMatchers&, \
8994 constness ::testing::internal::Function<__VA_ARGS__>* ) const { \
8995 return ::testing::internal::AdjustConstness_##constness(this)-> \
8996 gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \
8997 ::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \
8998 ::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(), \
8999 ::testing::A<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(), \
9000 ::testing::A<GMOCK_ARG_(tn, 5, __VA_ARGS__)>()); \
9001 } \
9002 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(5, constness, \
9003 Method)
9004
9005// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
9006#define GMOCK_METHOD6_(tn, constness, ct, Method, ...) \
9007 static_assert(6 == \
9008 ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, \
9009 "MOCK_METHOD<N> must match argument count.");\
9010 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
9011 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \
9012 __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
9013 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, GMOCK_ARG_(tn, 5, \
9014 __VA_ARGS__) gmock_a5, GMOCK_ARG_(tn, 6, \
9015 __VA_ARGS__) gmock_a6) constness { \
9016 GMOCK_MOCKER_(6, constness, Method).SetOwnerAndName(this, #Method); \
9017 return GMOCK_MOCKER_(6, constness, \
9018 Method).Invoke(::std::forward<GMOCK_ARG_(tn, 1, \
9019 __VA_ARGS__)>(gmock_a1), \
9020 ::std::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(gmock_a2), \
9021 ::std::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(gmock_a3), \
9022 ::std::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(gmock_a4), \
9023 ::std::forward<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(gmock_a5), \
9024 ::std::forward<GMOCK_ARG_(tn, 6, __VA_ARGS__)>(gmock_a6)); \
9025 } \
9026 ::testing::MockSpec<__VA_ARGS__> \
9027 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
9028 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
9029 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
9030 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
9031 GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \
9032 GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6) constness { \
9033 GMOCK_MOCKER_(6, constness, Method).RegisterOwner(this); \
9034 return GMOCK_MOCKER_(6, constness, Method).With(gmock_a1, gmock_a2, \
9035 gmock_a3, gmock_a4, gmock_a5, gmock_a6); \
9036 } \
9037 ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
9038 const ::testing::internal::WithoutMatchers&, \
9039 constness ::testing::internal::Function<__VA_ARGS__>* ) const { \
9040 return ::testing::internal::AdjustConstness_##constness(this)-> \
9041 gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \
9042 ::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \
9043 ::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(), \
9044 ::testing::A<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(), \
9045 ::testing::A<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(), \
9046 ::testing::A<GMOCK_ARG_(tn, 6, __VA_ARGS__)>()); \
9047 } \
9048 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(6, constness, \
9049 Method)
9050
9051// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
9052#define GMOCK_METHOD7_(tn, constness, ct, Method, ...) \
9053 static_assert(7 == \
9054 ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, \
9055 "MOCK_METHOD<N> must match argument count.");\
9056 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
9057 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \
9058 __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
9059 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, GMOCK_ARG_(tn, 5, \
9060 __VA_ARGS__) gmock_a5, GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
9061 GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7) constness { \
9062 GMOCK_MOCKER_(7, constness, Method).SetOwnerAndName(this, #Method); \
9063 return GMOCK_MOCKER_(7, constness, \
9064 Method).Invoke(::std::forward<GMOCK_ARG_(tn, 1, \
9065 __VA_ARGS__)>(gmock_a1), \
9066 ::std::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(gmock_a2), \
9067 ::std::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(gmock_a3), \
9068 ::std::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(gmock_a4), \
9069 ::std::forward<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(gmock_a5), \
9070 ::std::forward<GMOCK_ARG_(tn, 6, __VA_ARGS__)>(gmock_a6), \
9071 ::std::forward<GMOCK_ARG_(tn, 7, __VA_ARGS__)>(gmock_a7)); \
9072 } \
9073 ::testing::MockSpec<__VA_ARGS__> \
9074 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
9075 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
9076 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
9077 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
9078 GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \
9079 GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \
9080 GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7) constness { \
9081 GMOCK_MOCKER_(7, constness, Method).RegisterOwner(this); \
9082 return GMOCK_MOCKER_(7, constness, Method).With(gmock_a1, gmock_a2, \
9083 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7); \
9084 } \
9085 ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
9086 const ::testing::internal::WithoutMatchers&, \
9087 constness ::testing::internal::Function<__VA_ARGS__>* ) const { \
9088 return ::testing::internal::AdjustConstness_##constness(this)-> \
9089 gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \
9090 ::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \
9091 ::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(), \
9092 ::testing::A<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(), \
9093 ::testing::A<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(), \
9094 ::testing::A<GMOCK_ARG_(tn, 6, __VA_ARGS__)>(), \
9095 ::testing::A<GMOCK_ARG_(tn, 7, __VA_ARGS__)>()); \
9096 } \
9097 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(7, constness, \
9098 Method)
9099
9100// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
9101#define GMOCK_METHOD8_(tn, constness, ct, Method, ...) \
9102 static_assert(8 == \
9103 ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, \
9104 "MOCK_METHOD<N> must match argument count.");\
9105 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
9106 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \
9107 __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
9108 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, GMOCK_ARG_(tn, 5, \
9109 __VA_ARGS__) gmock_a5, GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
9110 GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, GMOCK_ARG_(tn, 8, \
9111 __VA_ARGS__) gmock_a8) constness { \
9112 GMOCK_MOCKER_(8, constness, Method).SetOwnerAndName(this, #Method); \
9113 return GMOCK_MOCKER_(8, constness, \
9114 Method).Invoke(::std::forward<GMOCK_ARG_(tn, 1, \
9115 __VA_ARGS__)>(gmock_a1), \
9116 ::std::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(gmock_a2), \
9117 ::std::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(gmock_a3), \
9118 ::std::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(gmock_a4), \
9119 ::std::forward<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(gmock_a5), \
9120 ::std::forward<GMOCK_ARG_(tn, 6, __VA_ARGS__)>(gmock_a6), \
9121 ::std::forward<GMOCK_ARG_(tn, 7, __VA_ARGS__)>(gmock_a7), \
9122 ::std::forward<GMOCK_ARG_(tn, 8, __VA_ARGS__)>(gmock_a8)); \
9123 } \
9124 ::testing::MockSpec<__VA_ARGS__> \
9125 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
9126 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
9127 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
9128 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
9129 GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \
9130 GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \
9131 GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \
9132 GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8) constness { \
9133 GMOCK_MOCKER_(8, constness, Method).RegisterOwner(this); \
9134 return GMOCK_MOCKER_(8, constness, Method).With(gmock_a1, gmock_a2, \
9135 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8); \
9136 } \
9137 ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
9138 const ::testing::internal::WithoutMatchers&, \
9139 constness ::testing::internal::Function<__VA_ARGS__>* ) const { \
9140 return ::testing::internal::AdjustConstness_##constness(this)-> \
9141 gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \
9142 ::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \
9143 ::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(), \
9144 ::testing::A<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(), \
9145 ::testing::A<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(), \
9146 ::testing::A<GMOCK_ARG_(tn, 6, __VA_ARGS__)>(), \
9147 ::testing::A<GMOCK_ARG_(tn, 7, __VA_ARGS__)>(), \
9148 ::testing::A<GMOCK_ARG_(tn, 8, __VA_ARGS__)>()); \
9149 } \
9150 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(8, constness, \
9151 Method)
9152
9153// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
9154#define GMOCK_METHOD9_(tn, constness, ct, Method, ...) \
9155 static_assert(9 == \
9156 ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, \
9157 "MOCK_METHOD<N> must match argument count.");\
9158 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
9159 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \
9160 __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
9161 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, GMOCK_ARG_(tn, 5, \
9162 __VA_ARGS__) gmock_a5, GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
9163 GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, GMOCK_ARG_(tn, 8, \
9164 __VA_ARGS__) gmock_a8, GMOCK_ARG_(tn, 9, \
9165 __VA_ARGS__) gmock_a9) constness { \
9166 GMOCK_MOCKER_(9, constness, Method).SetOwnerAndName(this, #Method); \
9167 return GMOCK_MOCKER_(9, constness, \
9168 Method).Invoke(::std::forward<GMOCK_ARG_(tn, 1, \
9169 __VA_ARGS__)>(gmock_a1), \
9170 ::std::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(gmock_a2), \
9171 ::std::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(gmock_a3), \
9172 ::std::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(gmock_a4), \
9173 ::std::forward<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(gmock_a5), \
9174 ::std::forward<GMOCK_ARG_(tn, 6, __VA_ARGS__)>(gmock_a6), \
9175 ::std::forward<GMOCK_ARG_(tn, 7, __VA_ARGS__)>(gmock_a7), \
9176 ::std::forward<GMOCK_ARG_(tn, 8, __VA_ARGS__)>(gmock_a8), \
9177 ::std::forward<GMOCK_ARG_(tn, 9, __VA_ARGS__)>(gmock_a9)); \
9178 } \
9179 ::testing::MockSpec<__VA_ARGS__> \
9180 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
9181 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
9182 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
9183 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
9184 GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \
9185 GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \
9186 GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \
9187 GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8, \
9188 GMOCK_MATCHER_(tn, 9, __VA_ARGS__) gmock_a9) constness { \
9189 GMOCK_MOCKER_(9, constness, Method).RegisterOwner(this); \
9190 return GMOCK_MOCKER_(9, constness, Method).With(gmock_a1, gmock_a2, \
9191 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, \
9192 gmock_a9); \
9193 } \
9194 ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
9195 const ::testing::internal::WithoutMatchers&, \
9196 constness ::testing::internal::Function<__VA_ARGS__>* ) const { \
9197 return ::testing::internal::AdjustConstness_##constness(this)-> \
9198 gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \
9199 ::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \
9200 ::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(), \
9201 ::testing::A<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(), \
9202 ::testing::A<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(), \
9203 ::testing::A<GMOCK_ARG_(tn, 6, __VA_ARGS__)>(), \
9204 ::testing::A<GMOCK_ARG_(tn, 7, __VA_ARGS__)>(), \
9205 ::testing::A<GMOCK_ARG_(tn, 8, __VA_ARGS__)>(), \
9206 ::testing::A<GMOCK_ARG_(tn, 9, __VA_ARGS__)>()); \
9207 } \
9208 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(9, constness, \
9209 Method)
9210
9211// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
9212#define GMOCK_METHOD10_(tn, constness, ct, Method, ...) \
9213 static_assert(10 == \
9214 ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, \
9215 "MOCK_METHOD<N> must match argument count.");\
9216 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
9217 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \
9218 __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
9219 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, GMOCK_ARG_(tn, 5, \
9220 __VA_ARGS__) gmock_a5, GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
9221 GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, GMOCK_ARG_(tn, 8, \
9222 __VA_ARGS__) gmock_a8, GMOCK_ARG_(tn, 9, __VA_ARGS__) gmock_a9, \
9223 GMOCK_ARG_(tn, 10, __VA_ARGS__) gmock_a10) constness { \
9224 GMOCK_MOCKER_(10, constness, Method).SetOwnerAndName(this, #Method); \
9225 return GMOCK_MOCKER_(10, constness, \
9226 Method).Invoke(::std::forward<GMOCK_ARG_(tn, 1, \
9227 __VA_ARGS__)>(gmock_a1), \
9228 ::std::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(gmock_a2), \
9229 ::std::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(gmock_a3), \
9230 ::std::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(gmock_a4), \
9231 ::std::forward<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(gmock_a5), \
9232 ::std::forward<GMOCK_ARG_(tn, 6, __VA_ARGS__)>(gmock_a6), \
9233 ::std::forward<GMOCK_ARG_(tn, 7, __VA_ARGS__)>(gmock_a7), \
9234 ::std::forward<GMOCK_ARG_(tn, 8, __VA_ARGS__)>(gmock_a8), \
9235 ::std::forward<GMOCK_ARG_(tn, 9, __VA_ARGS__)>(gmock_a9), \
9236 ::std::forward<GMOCK_ARG_(tn, 10, __VA_ARGS__)>(gmock_a10)); \
9237 } \
9238 ::testing::MockSpec<__VA_ARGS__> \
9239 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
9240 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
9241 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
9242 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
9243 GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \
9244 GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \
9245 GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \
9246 GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8, \
9247 GMOCK_MATCHER_(tn, 9, __VA_ARGS__) gmock_a9, \
9248 GMOCK_MATCHER_(tn, 10, \
9249 __VA_ARGS__) gmock_a10) constness { \
9250 GMOCK_MOCKER_(10, constness, Method).RegisterOwner(this); \
9251 return GMOCK_MOCKER_(10, constness, Method).With(gmock_a1, gmock_a2, \
9252 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, gmock_a9, \
9253 gmock_a10); \
9254 } \
9255 ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
9256 const ::testing::internal::WithoutMatchers&, \
9257 constness ::testing::internal::Function<__VA_ARGS__>* ) const { \
9258 return ::testing::internal::AdjustConstness_##constness(this)-> \
9259 gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \
9260 ::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \
9261 ::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(), \
9262 ::testing::A<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(), \
9263 ::testing::A<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(), \
9264 ::testing::A<GMOCK_ARG_(tn, 6, __VA_ARGS__)>(), \
9265 ::testing::A<GMOCK_ARG_(tn, 7, __VA_ARGS__)>(), \
9266 ::testing::A<GMOCK_ARG_(tn, 8, __VA_ARGS__)>(), \
9267 ::testing::A<GMOCK_ARG_(tn, 9, __VA_ARGS__)>(), \
9268 ::testing::A<GMOCK_ARG_(tn, 10, __VA_ARGS__)>()); \
9269 } \
9270 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(10, constness, \
9271 Method)
9272
9273#define MOCK_METHOD0(m, ...) GMOCK_METHOD0_(, , , m, __VA_ARGS__)
9274#define MOCK_METHOD1(m, ...) GMOCK_METHOD1_(, , , m, __VA_ARGS__)
9275#define MOCK_METHOD2(m, ...) GMOCK_METHOD2_(, , , m, __VA_ARGS__)
9276#define MOCK_METHOD3(m, ...) GMOCK_METHOD3_(, , , m, __VA_ARGS__)
9277#define MOCK_METHOD4(m, ...) GMOCK_METHOD4_(, , , m, __VA_ARGS__)
9278#define MOCK_METHOD5(m, ...) GMOCK_METHOD5_(, , , m, __VA_ARGS__)
9279#define MOCK_METHOD6(m, ...) GMOCK_METHOD6_(, , , m, __VA_ARGS__)
9280#define MOCK_METHOD7(m, ...) GMOCK_METHOD7_(, , , m, __VA_ARGS__)
9281#define MOCK_METHOD8(m, ...) GMOCK_METHOD8_(, , , m, __VA_ARGS__)
9282#define MOCK_METHOD9(m, ...) GMOCK_METHOD9_(, , , m, __VA_ARGS__)
9283#define MOCK_METHOD10(m, ...) GMOCK_METHOD10_(, , , m, __VA_ARGS__)
9284
9285#define MOCK_CONST_METHOD0(m, ...) GMOCK_METHOD0_(, const, , m, __VA_ARGS__)
9286#define MOCK_CONST_METHOD1(m, ...) GMOCK_METHOD1_(, const, , m, __VA_ARGS__)
9287#define MOCK_CONST_METHOD2(m, ...) GMOCK_METHOD2_(, const, , m, __VA_ARGS__)
9288#define MOCK_CONST_METHOD3(m, ...) GMOCK_METHOD3_(, const, , m, __VA_ARGS__)
9289#define MOCK_CONST_METHOD4(m, ...) GMOCK_METHOD4_(, const, , m, __VA_ARGS__)
9290#define MOCK_CONST_METHOD5(m, ...) GMOCK_METHOD5_(, const, , m, __VA_ARGS__)
9291#define MOCK_CONST_METHOD6(m, ...) GMOCK_METHOD6_(, const, , m, __VA_ARGS__)
9292#define MOCK_CONST_METHOD7(m, ...) GMOCK_METHOD7_(, const, , m, __VA_ARGS__)
9293#define MOCK_CONST_METHOD8(m, ...) GMOCK_METHOD8_(, const, , m, __VA_ARGS__)
9294#define MOCK_CONST_METHOD9(m, ...) GMOCK_METHOD9_(, const, , m, __VA_ARGS__)
9295#define MOCK_CONST_METHOD10(m, ...) GMOCK_METHOD10_(, const, , m, __VA_ARGS__)
9296
9297#define MOCK_METHOD0_T(m, ...) GMOCK_METHOD0_(typename, , , m, __VA_ARGS__)
9298#define MOCK_METHOD1_T(m, ...) GMOCK_METHOD1_(typename, , , m, __VA_ARGS__)
9299#define MOCK_METHOD2_T(m, ...) GMOCK_METHOD2_(typename, , , m, __VA_ARGS__)
9300#define MOCK_METHOD3_T(m, ...) GMOCK_METHOD3_(typename, , , m, __VA_ARGS__)
9301#define MOCK_METHOD4_T(m, ...) GMOCK_METHOD4_(typename, , , m, __VA_ARGS__)
9302#define MOCK_METHOD5_T(m, ...) GMOCK_METHOD5_(typename, , , m, __VA_ARGS__)
9303#define MOCK_METHOD6_T(m, ...) GMOCK_METHOD6_(typename, , , m, __VA_ARGS__)
9304#define MOCK_METHOD7_T(m, ...) GMOCK_METHOD7_(typename, , , m, __VA_ARGS__)
9305#define MOCK_METHOD8_T(m, ...) GMOCK_METHOD8_(typename, , , m, __VA_ARGS__)
9306#define MOCK_METHOD9_T(m, ...) GMOCK_METHOD9_(typename, , , m, __VA_ARGS__)
9307#define MOCK_METHOD10_T(m, ...) GMOCK_METHOD10_(typename, , , m, __VA_ARGS__)
9308
9309#define MOCK_CONST_METHOD0_T(m, ...) \
9310 GMOCK_METHOD0_(typename, const, , m, __VA_ARGS__)
9311#define MOCK_CONST_METHOD1_T(m, ...) \
9312 GMOCK_METHOD1_(typename, const, , m, __VA_ARGS__)
9313#define MOCK_CONST_METHOD2_T(m, ...) \
9314 GMOCK_METHOD2_(typename, const, , m, __VA_ARGS__)
9315#define MOCK_CONST_METHOD3_T(m, ...) \
9316 GMOCK_METHOD3_(typename, const, , m, __VA_ARGS__)
9317#define MOCK_CONST_METHOD4_T(m, ...) \
9318 GMOCK_METHOD4_(typename, const, , m, __VA_ARGS__)
9319#define MOCK_CONST_METHOD5_T(m, ...) \
9320 GMOCK_METHOD5_(typename, const, , m, __VA_ARGS__)
9321#define MOCK_CONST_METHOD6_T(m, ...) \
9322 GMOCK_METHOD6_(typename, const, , m, __VA_ARGS__)
9323#define MOCK_CONST_METHOD7_T(m, ...) \
9324 GMOCK_METHOD7_(typename, const, , m, __VA_ARGS__)
9325#define MOCK_CONST_METHOD8_T(m, ...) \
9326 GMOCK_METHOD8_(typename, const, , m, __VA_ARGS__)
9327#define MOCK_CONST_METHOD9_T(m, ...) \
9328 GMOCK_METHOD9_(typename, const, , m, __VA_ARGS__)
9329#define MOCK_CONST_METHOD10_T(m, ...) \
9330 GMOCK_METHOD10_(typename, const, , m, __VA_ARGS__)
9331
9332#define MOCK_METHOD0_WITH_CALLTYPE(ct, m, ...) \
9333 GMOCK_METHOD0_(, , ct, m, __VA_ARGS__)
9334#define MOCK_METHOD1_WITH_CALLTYPE(ct, m, ...) \
9335 GMOCK_METHOD1_(, , ct, m, __VA_ARGS__)
9336#define MOCK_METHOD2_WITH_CALLTYPE(ct, m, ...) \
9337 GMOCK_METHOD2_(, , ct, m, __VA_ARGS__)
9338#define MOCK_METHOD3_WITH_CALLTYPE(ct, m, ...) \
9339 GMOCK_METHOD3_(, , ct, m, __VA_ARGS__)
9340#define MOCK_METHOD4_WITH_CALLTYPE(ct, m, ...) \
9341 GMOCK_METHOD4_(, , ct, m, __VA_ARGS__)
9342#define MOCK_METHOD5_WITH_CALLTYPE(ct, m, ...) \
9343 GMOCK_METHOD5_(, , ct, m, __VA_ARGS__)
9344#define MOCK_METHOD6_WITH_CALLTYPE(ct, m, ...) \
9345 GMOCK_METHOD6_(, , ct, m, __VA_ARGS__)
9346#define MOCK_METHOD7_WITH_CALLTYPE(ct, m, ...) \
9347 GMOCK_METHOD7_(, , ct, m, __VA_ARGS__)
9348#define MOCK_METHOD8_WITH_CALLTYPE(ct, m, ...) \
9349 GMOCK_METHOD8_(, , ct, m, __VA_ARGS__)
9350#define MOCK_METHOD9_WITH_CALLTYPE(ct, m, ...) \
9351 GMOCK_METHOD9_(, , ct, m, __VA_ARGS__)
9352#define MOCK_METHOD10_WITH_CALLTYPE(ct, m, ...) \
9353 GMOCK_METHOD10_(, , ct, m, __VA_ARGS__)
9354
9355#define MOCK_CONST_METHOD0_WITH_CALLTYPE(ct, m, ...) \
9356 GMOCK_METHOD0_(, const, ct, m, __VA_ARGS__)
9357#define MOCK_CONST_METHOD1_WITH_CALLTYPE(ct, m, ...) \
9358 GMOCK_METHOD1_(, const, ct, m, __VA_ARGS__)
9359#define MOCK_CONST_METHOD2_WITH_CALLTYPE(ct, m, ...) \
9360 GMOCK_METHOD2_(, const, ct, m, __VA_ARGS__)
9361#define MOCK_CONST_METHOD3_WITH_CALLTYPE(ct, m, ...) \
9362 GMOCK_METHOD3_(, const, ct, m, __VA_ARGS__)
9363#define MOCK_CONST_METHOD4_WITH_CALLTYPE(ct, m, ...) \
9364 GMOCK_METHOD4_(, const, ct, m, __VA_ARGS__)
9365#define MOCK_CONST_METHOD5_WITH_CALLTYPE(ct, m, ...) \
9366 GMOCK_METHOD5_(, const, ct, m, __VA_ARGS__)
9367#define MOCK_CONST_METHOD6_WITH_CALLTYPE(ct, m, ...) \
9368 GMOCK_METHOD6_(, const, ct, m, __VA_ARGS__)
9369#define MOCK_CONST_METHOD7_WITH_CALLTYPE(ct, m, ...) \
9370 GMOCK_METHOD7_(, const, ct, m, __VA_ARGS__)
9371#define MOCK_CONST_METHOD8_WITH_CALLTYPE(ct, m, ...) \
9372 GMOCK_METHOD8_(, const, ct, m, __VA_ARGS__)
9373#define MOCK_CONST_METHOD9_WITH_CALLTYPE(ct, m, ...) \
9374 GMOCK_METHOD9_(, const, ct, m, __VA_ARGS__)
9375#define MOCK_CONST_METHOD10_WITH_CALLTYPE(ct, m, ...) \
9376 GMOCK_METHOD10_(, const, ct, m, __VA_ARGS__)
9377
9378#define MOCK_METHOD0_T_WITH_CALLTYPE(ct, m, ...) \
9379 GMOCK_METHOD0_(typename, , ct, m, __VA_ARGS__)
9380#define MOCK_METHOD1_T_WITH_CALLTYPE(ct, m, ...) \
9381 GMOCK_METHOD1_(typename, , ct, m, __VA_ARGS__)
9382#define MOCK_METHOD2_T_WITH_CALLTYPE(ct, m, ...) \
9383 GMOCK_METHOD2_(typename, , ct, m, __VA_ARGS__)
9384#define MOCK_METHOD3_T_WITH_CALLTYPE(ct, m, ...) \
9385 GMOCK_METHOD3_(typename, , ct, m, __VA_ARGS__)
9386#define MOCK_METHOD4_T_WITH_CALLTYPE(ct, m, ...) \
9387 GMOCK_METHOD4_(typename, , ct, m, __VA_ARGS__)
9388#define MOCK_METHOD5_T_WITH_CALLTYPE(ct, m, ...) \
9389 GMOCK_METHOD5_(typename, , ct, m, __VA_ARGS__)
9390#define MOCK_METHOD6_T_WITH_CALLTYPE(ct, m, ...) \
9391 GMOCK_METHOD6_(typename, , ct, m, __VA_ARGS__)
9392#define MOCK_METHOD7_T_WITH_CALLTYPE(ct, m, ...) \
9393 GMOCK_METHOD7_(typename, , ct, m, __VA_ARGS__)
9394#define MOCK_METHOD8_T_WITH_CALLTYPE(ct, m, ...) \
9395 GMOCK_METHOD8_(typename, , ct, m, __VA_ARGS__)
9396#define MOCK_METHOD9_T_WITH_CALLTYPE(ct, m, ...) \
9397 GMOCK_METHOD9_(typename, , ct, m, __VA_ARGS__)
9398#define MOCK_METHOD10_T_WITH_CALLTYPE(ct, m, ...) \
9399 GMOCK_METHOD10_(typename, , ct, m, __VA_ARGS__)
9400
9401#define MOCK_CONST_METHOD0_T_WITH_CALLTYPE(ct, m, ...) \
9402 GMOCK_METHOD0_(typename, const, ct, m, __VA_ARGS__)
9403#define MOCK_CONST_METHOD1_T_WITH_CALLTYPE(ct, m, ...) \
9404 GMOCK_METHOD1_(typename, const, ct, m, __VA_ARGS__)
9405#define MOCK_CONST_METHOD2_T_WITH_CALLTYPE(ct, m, ...) \
9406 GMOCK_METHOD2_(typename, const, ct, m, __VA_ARGS__)
9407#define MOCK_CONST_METHOD3_T_WITH_CALLTYPE(ct, m, ...) \
9408 GMOCK_METHOD3_(typename, const, ct, m, __VA_ARGS__)
9409#define MOCK_CONST_METHOD4_T_WITH_CALLTYPE(ct, m, ...) \
9410 GMOCK_METHOD4_(typename, const, ct, m, __VA_ARGS__)
9411#define MOCK_CONST_METHOD5_T_WITH_CALLTYPE(ct, m, ...) \
9412 GMOCK_METHOD5_(typename, const, ct, m, __VA_ARGS__)
9413#define MOCK_CONST_METHOD6_T_WITH_CALLTYPE(ct, m, ...) \
9414 GMOCK_METHOD6_(typename, const, ct, m, __VA_ARGS__)
9415#define MOCK_CONST_METHOD7_T_WITH_CALLTYPE(ct, m, ...) \
9416 GMOCK_METHOD7_(typename, const, ct, m, __VA_ARGS__)
9417#define MOCK_CONST_METHOD8_T_WITH_CALLTYPE(ct, m, ...) \
9418 GMOCK_METHOD8_(typename, const, ct, m, __VA_ARGS__)
9419#define MOCK_CONST_METHOD9_T_WITH_CALLTYPE(ct, m, ...) \
9420 GMOCK_METHOD9_(typename, const, ct, m, __VA_ARGS__)
9421#define MOCK_CONST_METHOD10_T_WITH_CALLTYPE(ct, m, ...) \
9422 GMOCK_METHOD10_(typename, const, ct, m, __VA_ARGS__)
9423
9424} // namespace testing
9425
9426#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
9427#ifndef THIRD_PARTY_GOOGLETEST_GOOGLEMOCK_INCLUDE_GMOCK_PP_H_
9428#define THIRD_PARTY_GOOGLETEST_GOOGLEMOCK_INCLUDE_GMOCK_PP_H_
9429
9430#undef GMOCK_PP_INTERNAL_USE_MSVC
9431#if defined(__clang__)
9432#define GMOCK_PP_INTERNAL_USE_MSVC 0
9433#elif defined(_MSC_VER)
9434// TODO(iserna): Also verify tradional versus comformant preprocessor.
9435static_assert(
9436 _MSC_VER >= 1900,
9437 "MSVC version not supported. There is support for MSVC 14.0 and above.");
9438#define GMOCK_PP_INTERNAL_USE_MSVC 1
9439#else
9440#define GMOCK_PP_INTERNAL_USE_MSVC 0
9441#endif
9442
9443// Expands and concatenates the arguments. Constructed macros reevaluate.
9444#define GMOCK_PP_CAT(_1, _2) GMOCK_PP_INTERNAL_CAT(_1, _2)
9445
9446// Expands and stringifies the only argument.
9447#define GMOCK_PP_STRINGIZE(...) GMOCK_PP_INTERNAL_STRINGIZE(__VA_ARGS__)
9448
9449// Returns empty. Given a variadic number of arguments.
9450#define GMOCK_PP_EMPTY(...)
9451
9452// Returns a comma. Given a variadic number of arguments.
9453#define GMOCK_PP_COMMA(...) ,
9454
9455// Returns the only argument.
9456#define GMOCK_PP_IDENTITY(_1) _1
9457
9458// MSVC preprocessor collapses __VA_ARGS__ in a single argument, we use a
9459// CAT-like directive to force correct evaluation. Each macro has its own.
9460#if GMOCK_PP_INTERNAL_USE_MSVC
9461
9462// Evaluates to the number of arguments after expansion.
9463//
9464// #define PAIR x, y
9465//
9466// GMOCK_PP_NARG() => 1
9467// GMOCK_PP_NARG(x) => 1
9468// GMOCK_PP_NARG(x, y) => 2
9469// GMOCK_PP_NARG(PAIR) => 2
9470//
9471// Requires: the number of arguments after expansion is at most 15.
9472#define GMOCK_PP_NARG(...) \
9473 GMOCK_PP_INTERNAL_NARG_CAT( \
9474 GMOCK_PP_INTERNAL_INTERNAL_16TH(__VA_ARGS__, 15, 14, 13, 12, 11, 10, 9, \
9475 8, 7, 6, 5, 4, 3, 2, 1), )
9476
9477// Returns 1 if the expansion of arguments has an unprotected comma. Otherwise
9478// returns 0. Requires no more than 15 unprotected commas.
9479#define GMOCK_PP_HAS_COMMA(...) \
9480 GMOCK_PP_INTERNAL_HAS_COMMA_CAT( \
9481 GMOCK_PP_INTERNAL_INTERNAL_16TH(__VA_ARGS__, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
9482 1, 1, 1, 1, 1, 0), )
9483// Returns the first argument.
9484#define GMOCK_PP_HEAD(...) \
9485 GMOCK_PP_INTERNAL_HEAD_CAT(GMOCK_PP_INTERNAL_HEAD(__VA_ARGS__), )
9486
9487// Returns the tail. A variadic list of all arguments minus the first. Requires
9488// at least one argument.
9489#define GMOCK_PP_TAIL(...) \
9490 GMOCK_PP_INTERNAL_TAIL_CAT(GMOCK_PP_INTERNAL_TAIL(__VA_ARGS__), )
9491
9492// Calls CAT(_Macro, NARG(__VA_ARGS__))(__VA_ARGS__)
9493#define GMOCK_PP_VARIADIC_CALL(_Macro, ...) \
9494 GMOCK_PP_INTERNAL_VARIADIC_CALL_CAT( \
9495 GMOCK_PP_CAT(_Macro, GMOCK_PP_NARG(__VA_ARGS__))(__VA_ARGS__), )
9496
9497#else // GMOCK_PP_INTERNAL_USE_MSVC
9498
9499#define GMOCK_PP_NARG(...) \
9500 GMOCK_PP_INTERNAL_INTERNAL_16TH(__VA_ARGS__, 15, 14, 13, 12, 11, 10, 9, 8, \
9501 7, 6, 5, 4, 3, 2, 1)
9502#define GMOCK_PP_HAS_COMMA(...) \
9503 GMOCK_PP_INTERNAL_INTERNAL_16TH(__VA_ARGS__, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
9504 1, 1, 1, 1, 0)
9505#define GMOCK_PP_HEAD(...) GMOCK_PP_INTERNAL_HEAD(__VA_ARGS__)
9506#define GMOCK_PP_TAIL(...) GMOCK_PP_INTERNAL_TAIL(__VA_ARGS__)
9507#define GMOCK_PP_VARIADIC_CALL(_Macro, ...) \
9508 GMOCK_PP_CAT(_Macro, GMOCK_PP_NARG(__VA_ARGS__))(__VA_ARGS__)
9509
9510#endif // GMOCK_PP_INTERNAL_USE_MSVC
9511
9512// If the arguments after expansion have no tokens, evaluates to `1`. Otherwise
9513// evaluates to `0`.
9514//
9515// Requires: * the number of arguments after expansion is at most 15.
9516// * If the argument is a macro, it must be able to be called with one
9517// argument.
9518//
9519// Implementation details:
9520//
9521// There is one case when it generates a compile error: if the argument is macro
9522// that cannot be called with one argument.
9523//
9524// #define M(a, b) // it doesn't matter what it expands to
9525//
9526// // Expected: expands to `0`.
9527// // Actual: compile error.
9528// GMOCK_PP_IS_EMPTY(M)
9529//
9530// There are 4 cases tested:
9531//
9532// * __VA_ARGS__ possible expansion has no unparen'd commas. Expected 0.
9533// * __VA_ARGS__ possible expansion is not enclosed in parenthesis. Expected 0.
9534// * __VA_ARGS__ possible expansion is not a macro that ()-evaluates to a comma.
9535// Expected 0
9536// * __VA_ARGS__ is empty, or has unparen'd commas, or is enclosed in
9537// parenthesis, or is a macro that ()-evaluates to comma. Expected 1.
9538//
9539// We trigger detection on '0001', i.e. on empty.
9540#define GMOCK_PP_IS_EMPTY(...) \
9541 GMOCK_PP_INTERNAL_IS_EMPTY(GMOCK_PP_HAS_COMMA(__VA_ARGS__), \
9542 GMOCK_PP_HAS_COMMA(GMOCK_PP_COMMA __VA_ARGS__), \
9543 GMOCK_PP_HAS_COMMA(__VA_ARGS__()), \
9544 GMOCK_PP_HAS_COMMA(GMOCK_PP_COMMA __VA_ARGS__()))
9545
9546// Evaluates to _Then if _Cond is 1 and _Else if _Cond is 0.
9547#define GMOCK_PP_IF(_Cond, _Then, _Else) \
9548 GMOCK_PP_CAT(GMOCK_PP_INTERNAL_IF_, _Cond)(_Then, _Else)
9549
9550// Evaluates to the number of arguments after expansion. Identifies 'empty' as
9551// 0.
9552//
9553// #define PAIR x, y
9554//
9555// GMOCK_PP_NARG0() => 0
9556// GMOCK_PP_NARG0(x) => 1
9557// GMOCK_PP_NARG0(x, y) => 2
9558// GMOCK_PP_NARG0(PAIR) => 2
9559//
9560// Requires: * the number of arguments after expansion is at most 15.
9561// * If the argument is a macro, it must be able to be called with one
9562// argument.
9563#define GMOCK_PP_NARG0(...) \
9564 GMOCK_PP_IF(GMOCK_PP_IS_EMPTY(__VA_ARGS__), 0, GMOCK_PP_NARG(__VA_ARGS__))
9565
9566// Expands to 1 if the first argument starts with something in parentheses,
9567// otherwise to 0.
9568#define GMOCK_PP_IS_BEGIN_PARENS(...) \
9569 GMOCK_PP_INTERNAL_ALTERNATE_HEAD( \
9570 GMOCK_PP_CAT(GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_R_, \
9571 GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_C __VA_ARGS__))
9572
9573// Expands to 1 is there is only one argument and it is enclosed in parentheses.
9574#define GMOCK_PP_IS_ENCLOSED_PARENS(...) \
9575 GMOCK_PP_IF(GMOCK_PP_IS_BEGIN_PARENS(__VA_ARGS__), \
9576 GMOCK_PP_IS_EMPTY(GMOCK_PP_EMPTY __VA_ARGS__), 0)
9577
9578// Remove the parens, requires GMOCK_PP_IS_ENCLOSED_PARENS(args) => 1.
9579#define GMOCK_PP_REMOVE_PARENS(...) GMOCK_PP_INTERNAL_REMOVE_PARENS __VA_ARGS__
9580
9581// Expands to _Macro(0, _Data, e1) _Macro(1, _Data, e2) ... _Macro(K -1, _Data,
9582// eK) as many of GMOCK_INTERNAL_NARG0 _Tuple.
9583// Requires: * |_Macro| can be called with 3 arguments.
9584// * |_Tuple| expansion has no more than 15 elements.
9585#define GMOCK_PP_FOR_EACH(_Macro, _Data, _Tuple) \
9586 GMOCK_PP_CAT(GMOCK_PP_INTERNAL_FOR_EACH_IMPL_, GMOCK_PP_NARG0 _Tuple) \
9587 (0, _Macro, _Data, _Tuple)
9588
9589// Expands to _Macro(0, _Data, ) _Macro(1, _Data, ) ... _Macro(K - 1, _Data, )
9590// Empty if _K = 0.
9591// Requires: * |_Macro| can be called with 3 arguments.
9592// * |_K| literal between 0 and 15
9593#define GMOCK_PP_REPEAT(_Macro, _Data, _N) \
9594 GMOCK_PP_CAT(GMOCK_PP_INTERNAL_FOR_EACH_IMPL_, _N) \
9595 (0, _Macro, _Data, GMOCK_PP_INTENRAL_EMPTY_TUPLE)
9596
9597// Increments the argument, requires the argument to be between 0 and 15.
9598#define GMOCK_PP_INC(_i) GMOCK_PP_CAT(GMOCK_PP_INTERNAL_INC_, _i)
9599
9600// Returns comma if _i != 0. Requires _i to be between 0 and 15.
9601#define GMOCK_PP_COMMA_IF(_i) GMOCK_PP_CAT(GMOCK_PP_INTERNAL_COMMA_IF_, _i)
9602
9603// Internal details follow. Do not use any of these symbols outside of this
9604// file or we will break your code.
9605#define GMOCK_PP_INTENRAL_EMPTY_TUPLE (, , , , , , , , , , , , , , , )
9606#define GMOCK_PP_INTERNAL_CAT(_1, _2) _1##_2
9607#define GMOCK_PP_INTERNAL_STRINGIZE(...) #__VA_ARGS__
9608#define GMOCK_PP_INTERNAL_INTERNAL_16TH(_1, _2, _3, _4, _5, _6, _7, _8, _9, \
9609 _10, _11, _12, _13, _14, _15, _16, \
9610 ...) \
9611 _16
9612#define GMOCK_PP_INTERNAL_CAT_5(_1, _2, _3, _4, _5) _1##_2##_3##_4##_5
9613#define GMOCK_PP_INTERNAL_IS_EMPTY(_1, _2, _3, _4) \
9614 GMOCK_PP_HAS_COMMA(GMOCK_PP_INTERNAL_CAT_5(GMOCK_PP_INTERNAL_IS_EMPTY_CASE_, \
9615 _1, _2, _3, _4))
9616#define GMOCK_PP_INTERNAL_IS_EMPTY_CASE_0001 ,
9617#define GMOCK_PP_INTERNAL_IF_1(_Then, _Else) _Then
9618#define GMOCK_PP_INTERNAL_IF_0(_Then, _Else) _Else
9619#define GMOCK_PP_INTERNAL_HEAD(_1, ...) _1
9620#define GMOCK_PP_INTERNAL_TAIL(_1, ...) __VA_ARGS__
9621
9622#if GMOCK_PP_INTERNAL_USE_MSVC
9623#define GMOCK_PP_INTERNAL_NARG_CAT(_1, _2) GMOCK_PP_INTERNAL_NARG_CAT_I(_1, _2)
9624#define GMOCK_PP_INTERNAL_HEAD_CAT(_1, _2) GMOCK_PP_INTERNAL_HEAD_CAT_I(_1, _2)
9625#define GMOCK_PP_INTERNAL_HAS_COMMA_CAT(_1, _2) \
9626 GMOCK_PP_INTERNAL_HAS_COMMA_CAT_I(_1, _2)
9627#define GMOCK_PP_INTERNAL_TAIL_CAT(_1, _2) GMOCK_PP_INTERNAL_TAIL_CAT_I(_1, _2)
9628#define GMOCK_PP_INTERNAL_VARIADIC_CALL_CAT(_1, _2) \
9629 GMOCK_PP_INTERNAL_VARIADIC_CALL_CAT_I(_1, _2)
9630#define GMOCK_PP_INTERNAL_NARG_CAT_I(_1, _2) _1##_2
9631#define GMOCK_PP_INTERNAL_HEAD_CAT_I(_1, _2) _1##_2
9632#define GMOCK_PP_INTERNAL_HAS_COMMA_CAT_I(_1, _2) _1##_2
9633#define GMOCK_PP_INTERNAL_TAIL_CAT_I(_1, _2) _1##_2
9634#define GMOCK_PP_INTERNAL_VARIADIC_CALL_CAT_I(_1, _2) _1##_2
9635#define GMOCK_PP_INTERNAL_ALTERNATE_HEAD(...) \
9636 GMOCK_PP_INTERNAL_ALTERNATE_HEAD_CAT(GMOCK_PP_HEAD(__VA_ARGS__), )
9637#define GMOCK_PP_INTERNAL_ALTERNATE_HEAD_CAT(_1, _2) \
9638 GMOCK_PP_INTERNAL_ALTERNATE_HEAD_CAT_I(_1, _2)
9639#define GMOCK_PP_INTERNAL_ALTERNATE_HEAD_CAT_I(_1, _2) _1##_2
9640#else // GMOCK_PP_INTERNAL_USE_MSVC
9641#define GMOCK_PP_INTERNAL_ALTERNATE_HEAD(...) GMOCK_PP_HEAD(__VA_ARGS__)
9642#endif // GMOCK_PP_INTERNAL_USE_MSVC
9643
9644#define GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_C(...) 1 _
9645#define GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_R_1 1,
9646#define GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_R_GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_C \
9647 0,
9648#define GMOCK_PP_INTERNAL_REMOVE_PARENS(...) __VA_ARGS__
9649#define GMOCK_PP_INTERNAL_INC_0 1
9650#define GMOCK_PP_INTERNAL_INC_1 2
9651#define GMOCK_PP_INTERNAL_INC_2 3
9652#define GMOCK_PP_INTERNAL_INC_3 4
9653#define GMOCK_PP_INTERNAL_INC_4 5
9654#define GMOCK_PP_INTERNAL_INC_5 6
9655#define GMOCK_PP_INTERNAL_INC_6 7
9656#define GMOCK_PP_INTERNAL_INC_7 8
9657#define GMOCK_PP_INTERNAL_INC_8 9
9658#define GMOCK_PP_INTERNAL_INC_9 10
9659#define GMOCK_PP_INTERNAL_INC_10 11
9660#define GMOCK_PP_INTERNAL_INC_11 12
9661#define GMOCK_PP_INTERNAL_INC_12 13
9662#define GMOCK_PP_INTERNAL_INC_13 14
9663#define GMOCK_PP_INTERNAL_INC_14 15
9664#define GMOCK_PP_INTERNAL_INC_15 16
9665#define GMOCK_PP_INTERNAL_COMMA_IF_0
9666#define GMOCK_PP_INTERNAL_COMMA_IF_1 ,
9667#define GMOCK_PP_INTERNAL_COMMA_IF_2 ,
9668#define GMOCK_PP_INTERNAL_COMMA_IF_3 ,
9669#define GMOCK_PP_INTERNAL_COMMA_IF_4 ,
9670#define GMOCK_PP_INTERNAL_COMMA_IF_5 ,
9671#define GMOCK_PP_INTERNAL_COMMA_IF_6 ,
9672#define GMOCK_PP_INTERNAL_COMMA_IF_7 ,
9673#define GMOCK_PP_INTERNAL_COMMA_IF_8 ,
9674#define GMOCK_PP_INTERNAL_COMMA_IF_9 ,
9675#define GMOCK_PP_INTERNAL_COMMA_IF_10 ,
9676#define GMOCK_PP_INTERNAL_COMMA_IF_11 ,
9677#define GMOCK_PP_INTERNAL_COMMA_IF_12 ,
9678#define GMOCK_PP_INTERNAL_COMMA_IF_13 ,
9679#define GMOCK_PP_INTERNAL_COMMA_IF_14 ,
9680#define GMOCK_PP_INTERNAL_COMMA_IF_15 ,
9681#define GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, _element) \
9682 _Macro(_i, _Data, _element)
9683#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_0(_i, _Macro, _Data, _Tuple)
9684#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_1(_i, _Macro, _Data, _Tuple) \
9685 GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple)
9686#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_2(_i, _Macro, _Data, _Tuple) \
9687 GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
9688 GMOCK_PP_INTERNAL_FOR_EACH_IMPL_1(GMOCK_PP_INC(_i), _Macro, _Data, \
9689 (GMOCK_PP_TAIL _Tuple))
9690#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_3(_i, _Macro, _Data, _Tuple) \
9691 GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
9692 GMOCK_PP_INTERNAL_FOR_EACH_IMPL_2(GMOCK_PP_INC(_i), _Macro, _Data, \
9693 (GMOCK_PP_TAIL _Tuple))
9694#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_4(_i, _Macro, _Data, _Tuple) \
9695 GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
9696 GMOCK_PP_INTERNAL_FOR_EACH_IMPL_3(GMOCK_PP_INC(_i), _Macro, _Data, \
9697 (GMOCK_PP_TAIL _Tuple))
9698#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_5(_i, _Macro, _Data, _Tuple) \
9699 GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
9700 GMOCK_PP_INTERNAL_FOR_EACH_IMPL_4(GMOCK_PP_INC(_i), _Macro, _Data, \
9701 (GMOCK_PP_TAIL _Tuple))
9702#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_6(_i, _Macro, _Data, _Tuple) \
9703 GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
9704 GMOCK_PP_INTERNAL_FOR_EACH_IMPL_5(GMOCK_PP_INC(_i), _Macro, _Data, \
9705 (GMOCK_PP_TAIL _Tuple))
9706#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_7(_i, _Macro, _Data, _Tuple) \
9707 GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
9708 GMOCK_PP_INTERNAL_FOR_EACH_IMPL_6(GMOCK_PP_INC(_i), _Macro, _Data, \
9709 (GMOCK_PP_TAIL _Tuple))
9710#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_8(_i, _Macro, _Data, _Tuple) \
9711 GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
9712 GMOCK_PP_INTERNAL_FOR_EACH_IMPL_7(GMOCK_PP_INC(_i), _Macro, _Data, \
9713 (GMOCK_PP_TAIL _Tuple))
9714#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_9(_i, _Macro, _Data, _Tuple) \
9715 GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
9716 GMOCK_PP_INTERNAL_FOR_EACH_IMPL_8(GMOCK_PP_INC(_i), _Macro, _Data, \
9717 (GMOCK_PP_TAIL _Tuple))
9718#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_10(_i, _Macro, _Data, _Tuple) \
9719 GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
9720 GMOCK_PP_INTERNAL_FOR_EACH_IMPL_9(GMOCK_PP_INC(_i), _Macro, _Data, \
9721 (GMOCK_PP_TAIL _Tuple))
9722#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_11(_i, _Macro, _Data, _Tuple) \
9723 GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
9724 GMOCK_PP_INTERNAL_FOR_EACH_IMPL_10(GMOCK_PP_INC(_i), _Macro, _Data, \
9725 (GMOCK_PP_TAIL _Tuple))
9726#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_12(_i, _Macro, _Data, _Tuple) \
9727 GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
9728 GMOCK_PP_INTERNAL_FOR_EACH_IMPL_11(GMOCK_PP_INC(_i), _Macro, _Data, \
9729 (GMOCK_PP_TAIL _Tuple))
9730#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_13(_i, _Macro, _Data, _Tuple) \
9731 GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
9732 GMOCK_PP_INTERNAL_FOR_EACH_IMPL_12(GMOCK_PP_INC(_i), _Macro, _Data, \
9733 (GMOCK_PP_TAIL _Tuple))
9734#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_14(_i, _Macro, _Data, _Tuple) \
9735 GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
9736 GMOCK_PP_INTERNAL_FOR_EACH_IMPL_13(GMOCK_PP_INC(_i), _Macro, _Data, \
9737 (GMOCK_PP_TAIL _Tuple))
9738#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_15(_i, _Macro, _Data, _Tuple) \
9739 GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
9740 GMOCK_PP_INTERNAL_FOR_EACH_IMPL_14(GMOCK_PP_INC(_i), _Macro, _Data, \
9741 (GMOCK_PP_TAIL _Tuple))
9742
9743#endif // THIRD_PARTY_GOOGLETEST_GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PP_H_
9744
9745#define MOCK_METHOD(...) \
9746 GMOCK_PP_VARIADIC_CALL(GMOCK_INTERNAL_MOCK_METHOD_ARG_, __VA_ARGS__)
9747
9748#define GMOCK_INTERNAL_MOCK_METHOD_ARG_1(...) \
9749 GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__)
9750
9751#define GMOCK_INTERNAL_MOCK_METHOD_ARG_2(...) \
9752 GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__)
9753
9754#define GMOCK_INTERNAL_MOCK_METHOD_ARG_3(_Ret, _MethodName, _Args) \
9755 GMOCK_INTERNAL_MOCK_METHOD_ARG_4(_Ret, _MethodName, _Args, ())
9756
9757#define GMOCK_INTERNAL_MOCK_METHOD_ARG_4(_Ret, _MethodName, _Args, _Spec) \
9758 GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Args); \
9759 GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Spec); \
9760 GMOCK_INTERNAL_ASSERT_VALID_SIGNATURE( \
9761 GMOCK_PP_NARG0 _Args, GMOCK_INTERNAL_SIGNATURE(_Ret, _Args)); \
9762 GMOCK_INTERNAL_ASSERT_VALID_SPEC(_Spec) \
9763 GMOCK_INTERNAL_MOCK_METHOD_IMPL( \
9764 GMOCK_PP_NARG0 _Args, _MethodName, GMOCK_INTERNAL_HAS_CONST(_Spec), \
9765 GMOCK_INTERNAL_HAS_OVERRIDE(_Spec), GMOCK_INTERNAL_HAS_FINAL(_Spec), \
9766 GMOCK_INTERNAL_HAS_NOEXCEPT(_Spec), GMOCK_INTERNAL_GET_CALLTYPE(_Spec), \
9767 (GMOCK_INTERNAL_SIGNATURE(_Ret, _Args)))
9768
9769#define GMOCK_INTERNAL_MOCK_METHOD_ARG_5(...) \
9770 GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__)
9771
9772#define GMOCK_INTERNAL_MOCK_METHOD_ARG_6(...) \
9773 GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__)
9774
9775#define GMOCK_INTERNAL_MOCK_METHOD_ARG_7(...) \
9776 GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__)
9777
9778#define GMOCK_INTERNAL_WRONG_ARITY(...) \
9779 static_assert( \
9780 false, \
9781 "MOCK_METHOD must be called with 3 or 4 arguments. _Ret, " \
9782 "_MethodName, _Args and optionally _Spec. _Args and _Spec must be " \
9783 "enclosed in parentheses. If _Ret is a type with unprotected commas, " \
9784 "it must also be enclosed in parentheses.")
9785
9786#define GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Tuple) \
9787 static_assert( \
9788 GMOCK_PP_IS_ENCLOSED_PARENS(_Tuple), \
9789 GMOCK_PP_STRINGIZE(_Tuple) " should be enclosed in parentheses.")
9790
9791#define GMOCK_INTERNAL_ASSERT_VALID_SIGNATURE(_N, ...) \
9792 static_assert( \
9793 std::is_function<__VA_ARGS__>::value, \
9794 "Signature must be a function type, maybe return type contains " \
9795 "unprotected comma."); \
9796 static_assert( \
9797 ::testing::tuple_size<typename ::testing::internal::Function< \
9798 __VA_ARGS__>::ArgumentTuple>::value == _N, \
9799 "This method does not take " GMOCK_PP_STRINGIZE( \
9800 _N) " arguments. Parenthesize all types with unproctected commas.")
9801
9802#define GMOCK_INTERNAL_ASSERT_VALID_SPEC(_Spec) \
9803 GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_ASSERT_VALID_SPEC_ELEMENT, ~, _Spec)
9804
9805#define GMOCK_INTERNAL_MOCK_METHOD_IMPL(_N, _MethodName, _Constness, \
9806 _Override, _Final, _Noexcept, \
9807 _CallType, _Signature) \
9808 typename ::testing::internal::Function<GMOCK_PP_REMOVE_PARENS( \
9809 _Signature)>::Result \
9810 GMOCK_INTERNAL_EXPAND(_CallType) \
9811 _MethodName(GMOCK_PP_REPEAT(GMOCK_INTERNAL_PARAMETER, _Signature, _N)) \
9812 GMOCK_PP_IF(_Constness, const, ) GMOCK_PP_IF(_Noexcept, noexcept, ) \
9813 GMOCK_PP_IF(_Override, override, ) \
9814 GMOCK_PP_IF(_Final, final, ) { \
9815 GMOCK_MOCKER_(_N, _Constness, _MethodName) \
9816 .SetOwnerAndName(this, #_MethodName); \
9817 return GMOCK_MOCKER_(_N, _Constness, _MethodName) \
9818 .Invoke(GMOCK_PP_REPEAT(GMOCK_INTERNAL_FORWARD_ARG, _Signature, _N)); \
9819 } \
9820 ::testing::MockSpec<GMOCK_PP_REMOVE_PARENS(_Signature)> gmock_##_MethodName( \
9821 GMOCK_PP_REPEAT(GMOCK_INTERNAL_MATCHER_PARAMETER, _Signature, _N)) \
9822 GMOCK_PP_IF(_Constness, const, ) { \
9823 GMOCK_MOCKER_(_N, _Constness, _MethodName).RegisterOwner(this); \
9824 return GMOCK_MOCKER_(_N, _Constness, _MethodName) \
9825 .With(GMOCK_PP_REPEAT(GMOCK_INTERNAL_MATCHER_ARGUMENT, , _N)); \
9826 } \
9827 ::testing::MockSpec<GMOCK_PP_REMOVE_PARENS(_Signature)> gmock_##_MethodName( \
9828 const ::testing::internal::WithoutMatchers&, \
9829 GMOCK_PP_IF(_Constness, const, )::testing::internal::Function< \
9830 GMOCK_PP_REMOVE_PARENS(_Signature)>*) \
9831 const GMOCK_PP_IF(_Noexcept, noexcept, ) { \
9832 return GMOCK_PP_CAT(::testing::internal::AdjustConstness_, \
9833 GMOCK_PP_IF(_Constness, const, ))(this) \
9834 ->gmock_##_MethodName(GMOCK_PP_REPEAT( \
9835 GMOCK_INTERNAL_A_MATCHER_ARGUMENT, _Signature, _N)); \
9836 } \
9837 mutable ::testing::FunctionMocker<GMOCK_PP_REMOVE_PARENS(_Signature)> \
9838 GMOCK_MOCKER_(_N, _Constness, _MethodName)
9839
9840#define GMOCK_INTERNAL_EXPAND(...) __VA_ARGS__
9841
9842// Five Valid modifiers.
9843#define GMOCK_INTERNAL_HAS_CONST(_Tuple) \
9844 GMOCK_PP_HAS_COMMA(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_DETECT_CONST, ~, _Tuple))
9845
9846#define GMOCK_INTERNAL_HAS_OVERRIDE(_Tuple) \
9847 GMOCK_PP_HAS_COMMA( \
9848 GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_DETECT_OVERRIDE, ~, _Tuple))
9849
9850#define GMOCK_INTERNAL_HAS_FINAL(_Tuple) \
9851 GMOCK_PP_HAS_COMMA(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_DETECT_FINAL, ~, _Tuple))
9852
9853#define GMOCK_INTERNAL_HAS_NOEXCEPT(_Tuple) \
9854 GMOCK_PP_HAS_COMMA( \
9855 GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_DETECT_NOEXCEPT, ~, _Tuple))
9856
9857#define GMOCK_INTERNAL_GET_CALLTYPE(_Tuple) \
9858 GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_GET_CALLTYPE_IMPL, ~, _Tuple)
9859
9860#define GMOCK_INTERNAL_ASSERT_VALID_SPEC_ELEMENT(_i, _, _elem) \
9861 static_assert( \
9862 (GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_CONST(_i, _, _elem)) + \
9863 GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_OVERRIDE(_i, _, _elem)) + \
9864 GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_FINAL(_i, _, _elem)) + \
9865 GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_NOEXCEPT(_i, _, _elem)) + \
9866 GMOCK_INTERNAL_IS_CALLTYPE(_elem)) == 1, \
9867 GMOCK_PP_STRINGIZE( \
9868 _elem) " cannot be recognized as a valid specification modifier.");
9869
9870// Modifiers implementation.
9871#define GMOCK_INTERNAL_DETECT_CONST(_i, _, _elem) \
9872 GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_CONST_I_, _elem)
9873
9874#define GMOCK_INTERNAL_DETECT_CONST_I_const ,
9875
9876#define GMOCK_INTERNAL_DETECT_OVERRIDE(_i, _, _elem) \
9877 GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_OVERRIDE_I_, _elem)
9878
9879#define GMOCK_INTERNAL_DETECT_OVERRIDE_I_override ,
9880
9881#define GMOCK_INTERNAL_DETECT_FINAL(_i, _, _elem) \
9882 GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_FINAL_I_, _elem)
9883
9884#define GMOCK_INTERNAL_DETECT_FINAL_I_final ,
9885
9886// TODO(iserna): Maybe noexcept should accept an argument here as well.
9887#define GMOCK_INTERNAL_DETECT_NOEXCEPT(_i, _, _elem) \
9888 GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_NOEXCEPT_I_, _elem)
9889
9890#define GMOCK_INTERNAL_DETECT_NOEXCEPT_I_noexcept ,
9891
9892#define GMOCK_INTERNAL_GET_CALLTYPE_IMPL(_i, _, _elem) \
9893 GMOCK_PP_IF(GMOCK_INTERNAL_IS_CALLTYPE(_elem), \
9894 GMOCK_INTERNAL_GET_VALUE_CALLTYPE, GMOCK_PP_EMPTY) \
9895 (_elem)
9896
9897// TODO(iserna): GMOCK_INTERNAL_IS_CALLTYPE and
9898// GMOCK_INTERNAL_GET_VALUE_CALLTYPE needed more expansions to work on windows
9899// maybe they can be simplified somehow.
9900#define GMOCK_INTERNAL_IS_CALLTYPE(_arg) \
9901 GMOCK_INTERNAL_IS_CALLTYPE_I( \
9902 GMOCK_PP_CAT(GMOCK_INTERNAL_IS_CALLTYPE_HELPER_, _arg))
9903#define GMOCK_INTERNAL_IS_CALLTYPE_I(_arg) GMOCK_PP_IS_ENCLOSED_PARENS(_arg)
9904
9905#define GMOCK_INTERNAL_GET_VALUE_CALLTYPE(_arg) \
9906 GMOCK_INTERNAL_GET_VALUE_CALLTYPE_I( \
9907 GMOCK_PP_CAT(GMOCK_INTERNAL_IS_CALLTYPE_HELPER_, _arg))
9908#define GMOCK_INTERNAL_GET_VALUE_CALLTYPE_I(_arg) \
9909 GMOCK_PP_CAT(GMOCK_PP_IDENTITY, _arg)
9910
9911#define GMOCK_INTERNAL_IS_CALLTYPE_HELPER_Calltype
9912
9913#define GMOCK_INTERNAL_SIGNATURE(_Ret, _Args) \
9914 GMOCK_PP_IF(GMOCK_PP_IS_BEGIN_PARENS(_Ret), GMOCK_PP_REMOVE_PARENS, \
9915 GMOCK_PP_IDENTITY) \
9916 (_Ret)(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_GET_TYPE, _, _Args))
9917
9918#define GMOCK_INTERNAL_GET_TYPE(_i, _, _elem) \
9919 GMOCK_PP_COMMA_IF(_i) \
9920 GMOCK_PP_IF(GMOCK_PP_IS_BEGIN_PARENS(_elem), GMOCK_PP_REMOVE_PARENS, \
9921 GMOCK_PP_IDENTITY) \
9922 (_elem)
9923
9924#define GMOCK_INTERNAL_PARAMETER(_i, _Signature, _) \
9925 GMOCK_PP_COMMA_IF(_i) \
9926 GMOCK_INTERNAL_ARG_O(typename, GMOCK_PP_INC(_i), \
9927 GMOCK_PP_REMOVE_PARENS(_Signature)) \
9928 gmock_a##_i
9929
9930#define GMOCK_INTERNAL_FORWARD_ARG(_i, _Signature, _) \
9931 GMOCK_PP_COMMA_IF(_i) \
9932 ::std::forward<GMOCK_INTERNAL_ARG_O(typename, GMOCK_PP_INC(_i), \
9933 GMOCK_PP_REMOVE_PARENS(_Signature))>( \
9934 gmock_a##_i)
9935
9936#define GMOCK_INTERNAL_MATCHER_PARAMETER(_i, _Signature, _) \
9937 GMOCK_PP_COMMA_IF(_i) \
9938 GMOCK_INTERNAL_MATCHER_O(typename, GMOCK_PP_INC(_i), \
9939 GMOCK_PP_REMOVE_PARENS(_Signature)) \
9940 gmock_a##_i
9941
9942#define GMOCK_INTERNAL_MATCHER_ARGUMENT(_i, _1, _2) \
9943 GMOCK_PP_COMMA_IF(_i) \
9944 gmock_a##_i
9945
9946#define GMOCK_INTERNAL_A_MATCHER_ARGUMENT(_i, _Signature, _) \
9947 GMOCK_PP_COMMA_IF(_i) \
9948 ::testing::A<GMOCK_INTERNAL_ARG_O(typename, GMOCK_PP_INC(_i), \
9949 GMOCK_PP_REMOVE_PARENS(_Signature))>()
9950
9951#define GMOCK_INTERNAL_ARG_O(_tn, _i, ...) GMOCK_ARG_(_tn, _i, __VA_ARGS__)
9952
9953#define GMOCK_INTERNAL_MATCHER_O(_tn, _i, ...) \
9954 GMOCK_MATCHER_(_tn, _i, __VA_ARGS__)
9955
9956#endif // THIRD_PARTY_GOOGLETEST_GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_FUNCTION_MOCKER_H_
9957// This file was GENERATED by command:
9958// pump.py gmock-generated-actions.h.pump
9959// DO NOT EDIT BY HAND!!!
9960
9961// Copyright 2007, Google Inc.
9962// All rights reserved.
9963//
9964// Redistribution and use in source and binary forms, with or without
9965// modification, are permitted provided that the following conditions are
9966// met:
9967//
9968// * Redistributions of source code must retain the above copyright
9969// notice, this list of conditions and the following disclaimer.
9970// * Redistributions in binary form must reproduce the above
9971// copyright notice, this list of conditions and the following disclaimer
9972// in the documentation and/or other materials provided with the
9973// distribution.
9974// * Neither the name of Google Inc. nor the names of its
9975// contributors may be used to endorse or promote products derived from
9976// this software without specific prior written permission.
9977//
9978// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
9979// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
9980// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
9981// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9982// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9983// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9984// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
9985// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
9986// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
9987// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
9988// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9989
Austin Schuh70cc9552019-01-21 19:46:48 -08009990
9991// Google Mock - a framework for writing C++ mock classes.
9992//
9993// This file implements some commonly used variadic actions.
9994
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08009995// GOOGLETEST_CM0002 DO NOT DELETE
9996
Austin Schuh70cc9552019-01-21 19:46:48 -08009997#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
9998#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
9999
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010000#include <memory>
10001#include <utility>
10002
Austin Schuh70cc9552019-01-21 19:46:48 -080010003
10004namespace testing {
10005namespace internal {
10006
Austin Schuh70cc9552019-01-21 19:46:48 -080010007// A macro from the ACTION* family (defined later in this file)
10008// defines an action that can be used in a mock function. Typically,
10009// these actions only care about a subset of the arguments of the mock
10010// function. For example, if such an action only uses the second
10011// argument, it can be used in any mock function that takes >= 2
10012// arguments where the type of the second argument is compatible.
10013//
10014// Therefore, the action implementation must be prepared to take more
10015// arguments than it needs. The ExcessiveArg type is used to
10016// represent those excessive arguments. In order to keep the compiler
10017// error messages tractable, we define it in the testing namespace
10018// instead of testing::internal. However, this is an INTERNAL TYPE
10019// and subject to change without notice, so a user MUST NOT USE THIS
10020// TYPE DIRECTLY.
10021struct ExcessiveArg {};
10022
10023// A helper class needed for implementing the ACTION* macros.
10024template <typename Result, class Impl>
10025class ActionHelper {
10026 public:
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010027 static Result Perform(Impl* impl, const ::std::tuple<>& args) {
Austin Schuh70cc9552019-01-21 19:46:48 -080010028 return impl->template gmock_PerformImpl<>(args, ExcessiveArg(),
10029 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
10030 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
10031 ExcessiveArg());
10032 }
10033
10034 template <typename A0>
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010035 static Result Perform(Impl* impl, const ::std::tuple<A0>& args) {
10036 return impl->template gmock_PerformImpl<A0>(args, std::get<0>(args),
Austin Schuh70cc9552019-01-21 19:46:48 -080010037 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
10038 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
10039 ExcessiveArg());
10040 }
10041
10042 template <typename A0, typename A1>
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010043 static Result Perform(Impl* impl, const ::std::tuple<A0, A1>& args) {
10044 return impl->template gmock_PerformImpl<A0, A1>(args, std::get<0>(args),
10045 std::get<1>(args), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
Austin Schuh70cc9552019-01-21 19:46:48 -080010046 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
10047 ExcessiveArg());
10048 }
10049
10050 template <typename A0, typename A1, typename A2>
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010051 static Result Perform(Impl* impl, const ::std::tuple<A0, A1, A2>& args) {
10052 return impl->template gmock_PerformImpl<A0, A1, A2>(args,
10053 std::get<0>(args), std::get<1>(args), std::get<2>(args),
Austin Schuh70cc9552019-01-21 19:46:48 -080010054 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010055 ExcessiveArg(), ExcessiveArg(), ExcessiveArg());
Austin Schuh70cc9552019-01-21 19:46:48 -080010056 }
10057
10058 template <typename A0, typename A1, typename A2, typename A3>
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010059 static Result Perform(Impl* impl, const ::std::tuple<A0, A1, A2, A3>& args) {
10060 return impl->template gmock_PerformImpl<A0, A1, A2, A3>(args,
10061 std::get<0>(args), std::get<1>(args), std::get<2>(args),
10062 std::get<3>(args), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
10063 ExcessiveArg(), ExcessiveArg(), ExcessiveArg());
Austin Schuh70cc9552019-01-21 19:46:48 -080010064 }
10065
10066 template <typename A0, typename A1, typename A2, typename A3, typename A4>
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010067 static Result Perform(Impl* impl, const ::std::tuple<A0, A1, A2, A3,
Austin Schuh70cc9552019-01-21 19:46:48 -080010068 A4>& args) {
10069 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4>(args,
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010070 std::get<0>(args), std::get<1>(args), std::get<2>(args),
10071 std::get<3>(args), std::get<4>(args), ExcessiveArg(), ExcessiveArg(),
10072 ExcessiveArg(), ExcessiveArg(), ExcessiveArg());
Austin Schuh70cc9552019-01-21 19:46:48 -080010073 }
10074
10075 template <typename A0, typename A1, typename A2, typename A3, typename A4,
10076 typename A5>
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010077 static Result Perform(Impl* impl, const ::std::tuple<A0, A1, A2, A3, A4,
Austin Schuh70cc9552019-01-21 19:46:48 -080010078 A5>& args) {
10079 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5>(args,
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010080 std::get<0>(args), std::get<1>(args), std::get<2>(args),
10081 std::get<3>(args), std::get<4>(args), std::get<5>(args),
10082 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg());
Austin Schuh70cc9552019-01-21 19:46:48 -080010083 }
10084
10085 template <typename A0, typename A1, typename A2, typename A3, typename A4,
10086 typename A5, typename A6>
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010087 static Result Perform(Impl* impl, const ::std::tuple<A0, A1, A2, A3, A4, A5,
10088 A6>& args) {
Austin Schuh70cc9552019-01-21 19:46:48 -080010089 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6>(args,
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010090 std::get<0>(args), std::get<1>(args), std::get<2>(args),
10091 std::get<3>(args), std::get<4>(args), std::get<5>(args),
10092 std::get<6>(args), ExcessiveArg(), ExcessiveArg(), ExcessiveArg());
Austin Schuh70cc9552019-01-21 19:46:48 -080010093 }
10094
10095 template <typename A0, typename A1, typename A2, typename A3, typename A4,
10096 typename A5, typename A6, typename A7>
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010097 static Result Perform(Impl* impl, const ::std::tuple<A0, A1, A2, A3, A4, A5,
10098 A6, A7>& args) {
Austin Schuh70cc9552019-01-21 19:46:48 -080010099 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6,
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010100 A7>(args, std::get<0>(args), std::get<1>(args), std::get<2>(args),
10101 std::get<3>(args), std::get<4>(args), std::get<5>(args),
10102 std::get<6>(args), std::get<7>(args), ExcessiveArg(), ExcessiveArg());
Austin Schuh70cc9552019-01-21 19:46:48 -080010103 }
10104
10105 template <typename A0, typename A1, typename A2, typename A3, typename A4,
10106 typename A5, typename A6, typename A7, typename A8>
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010107 static Result Perform(Impl* impl, const ::std::tuple<A0, A1, A2, A3, A4, A5,
10108 A6, A7, A8>& args) {
Austin Schuh70cc9552019-01-21 19:46:48 -080010109 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6, A7,
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010110 A8>(args, std::get<0>(args), std::get<1>(args), std::get<2>(args),
10111 std::get<3>(args), std::get<4>(args), std::get<5>(args),
10112 std::get<6>(args), std::get<7>(args), std::get<8>(args),
Austin Schuh70cc9552019-01-21 19:46:48 -080010113 ExcessiveArg());
10114 }
10115
10116 template <typename A0, typename A1, typename A2, typename A3, typename A4,
10117 typename A5, typename A6, typename A7, typename A8, typename A9>
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010118 static Result Perform(Impl* impl, const ::std::tuple<A0, A1, A2, A3, A4, A5,
10119 A6, A7, A8, A9>& args) {
Austin Schuh70cc9552019-01-21 19:46:48 -080010120 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6, A7, A8,
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010121 A9>(args, std::get<0>(args), std::get<1>(args), std::get<2>(args),
10122 std::get<3>(args), std::get<4>(args), std::get<5>(args),
10123 std::get<6>(args), std::get<7>(args), std::get<8>(args),
10124 std::get<9>(args));
Austin Schuh70cc9552019-01-21 19:46:48 -080010125 }
10126};
10127
10128} // namespace internal
Austin Schuh70cc9552019-01-21 19:46:48 -080010129} // namespace testing
10130
10131// The ACTION* family of macros can be used in a namespace scope to
10132// define custom actions easily. The syntax:
10133//
10134// ACTION(name) { statements; }
10135//
10136// will define an action with the given name that executes the
10137// statements. The value returned by the statements will be used as
10138// the return value of the action. Inside the statements, you can
10139// refer to the K-th (0-based) argument of the mock function by
10140// 'argK', and refer to its type by 'argK_type'. For example:
10141//
10142// ACTION(IncrementArg1) {
10143// arg1_type temp = arg1;
10144// return ++(*temp);
10145// }
10146//
10147// allows you to write
10148//
10149// ...WillOnce(IncrementArg1());
10150//
10151// You can also refer to the entire argument tuple and its type by
10152// 'args' and 'args_type', and refer to the mock function type and its
10153// return type by 'function_type' and 'return_type'.
10154//
10155// Note that you don't need to specify the types of the mock function
10156// arguments. However rest assured that your code is still type-safe:
10157// you'll get a compiler error if *arg1 doesn't support the ++
10158// operator, or if the type of ++(*arg1) isn't compatible with the
10159// mock function's return type, for example.
10160//
10161// Sometimes you'll want to parameterize the action. For that you can use
10162// another macro:
10163//
10164// ACTION_P(name, param_name) { statements; }
10165//
10166// For example:
10167//
10168// ACTION_P(Add, n) { return arg0 + n; }
10169//
10170// will allow you to write:
10171//
10172// ...WillOnce(Add(5));
10173//
10174// Note that you don't need to provide the type of the parameter
10175// either. If you need to reference the type of a parameter named
10176// 'foo', you can write 'foo_type'. For example, in the body of
10177// ACTION_P(Add, n) above, you can write 'n_type' to refer to the type
10178// of 'n'.
10179//
10180// We also provide ACTION_P2, ACTION_P3, ..., up to ACTION_P10 to support
10181// multi-parameter actions.
10182//
10183// For the purpose of typing, you can view
10184//
10185// ACTION_Pk(Foo, p1, ..., pk) { ... }
10186//
10187// as shorthand for
10188//
10189// template <typename p1_type, ..., typename pk_type>
10190// FooActionPk<p1_type, ..., pk_type> Foo(p1_type p1, ..., pk_type pk) { ... }
10191//
10192// In particular, you can provide the template type arguments
10193// explicitly when invoking Foo(), as in Foo<long, bool>(5, false);
10194// although usually you can rely on the compiler to infer the types
10195// for you automatically. You can assign the result of expression
10196// Foo(p1, ..., pk) to a variable of type FooActionPk<p1_type, ...,
10197// pk_type>. This can be useful when composing actions.
10198//
10199// You can also overload actions with different numbers of parameters:
10200//
10201// ACTION_P(Plus, a) { ... }
10202// ACTION_P2(Plus, a, b) { ... }
10203//
10204// While it's tempting to always use the ACTION* macros when defining
10205// a new action, you should also consider implementing ActionInterface
10206// or using MakePolymorphicAction() instead, especially if you need to
10207// use the action a lot. While these approaches require more work,
10208// they give you more control on the types of the mock function
10209// arguments and the action parameters, which in general leads to
10210// better compiler error messages that pay off in the long run. They
10211// also allow overloading actions based on parameter types (as opposed
10212// to just based on the number of parameters).
10213//
10214// CAVEAT:
10215//
10216// ACTION*() can only be used in a namespace scope. The reason is
10217// that C++ doesn't yet allow function-local types to be used to
10218// instantiate templates. The up-coming C++0x standard will fix this.
10219// Once that's done, we'll consider supporting using ACTION*() inside
10220// a function.
10221//
10222// MORE INFORMATION:
10223//
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010224// To learn more about using these macros, please search for 'ACTION' on
10225// https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md
Austin Schuh70cc9552019-01-21 19:46:48 -080010226
10227// An internal macro needed for implementing ACTION*().
10228#define GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_\
10229 const args_type& args GTEST_ATTRIBUTE_UNUSED_, \
10230 arg0_type arg0 GTEST_ATTRIBUTE_UNUSED_, \
10231 arg1_type arg1 GTEST_ATTRIBUTE_UNUSED_, \
10232 arg2_type arg2 GTEST_ATTRIBUTE_UNUSED_, \
10233 arg3_type arg3 GTEST_ATTRIBUTE_UNUSED_, \
10234 arg4_type arg4 GTEST_ATTRIBUTE_UNUSED_, \
10235 arg5_type arg5 GTEST_ATTRIBUTE_UNUSED_, \
10236 arg6_type arg6 GTEST_ATTRIBUTE_UNUSED_, \
10237 arg7_type arg7 GTEST_ATTRIBUTE_UNUSED_, \
10238 arg8_type arg8 GTEST_ATTRIBUTE_UNUSED_, \
10239 arg9_type arg9 GTEST_ATTRIBUTE_UNUSED_
10240
10241// Sometimes you want to give an action explicit template parameters
10242// that cannot be inferred from its value parameters. ACTION() and
10243// ACTION_P*() don't support that. ACTION_TEMPLATE() remedies that
10244// and can be viewed as an extension to ACTION() and ACTION_P*().
10245//
10246// The syntax:
10247//
10248// ACTION_TEMPLATE(ActionName,
10249// HAS_m_TEMPLATE_PARAMS(kind1, name1, ..., kind_m, name_m),
10250// AND_n_VALUE_PARAMS(p1, ..., p_n)) { statements; }
10251//
10252// defines an action template that takes m explicit template
10253// parameters and n value parameters. name_i is the name of the i-th
10254// template parameter, and kind_i specifies whether it's a typename,
10255// an integral constant, or a template. p_i is the name of the i-th
10256// value parameter.
10257//
10258// Example:
10259//
10260// // DuplicateArg<k, T>(output) converts the k-th argument of the mock
10261// // function to type T and copies it to *output.
10262// ACTION_TEMPLATE(DuplicateArg,
10263// HAS_2_TEMPLATE_PARAMS(int, k, typename, T),
10264// AND_1_VALUE_PARAMS(output)) {
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010265// *output = T(::std::get<k>(args));
Austin Schuh70cc9552019-01-21 19:46:48 -080010266// }
10267// ...
10268// int n;
10269// EXPECT_CALL(mock, Foo(_, _))
10270// .WillOnce(DuplicateArg<1, unsigned char>(&n));
10271//
10272// To create an instance of an action template, write:
10273//
10274// ActionName<t1, ..., t_m>(v1, ..., v_n)
10275//
10276// where the ts are the template arguments and the vs are the value
10277// arguments. The value argument types are inferred by the compiler.
10278// If you want to explicitly specify the value argument types, you can
10279// provide additional template arguments:
10280//
10281// ActionName<t1, ..., t_m, u1, ..., u_k>(v1, ..., v_n)
10282//
10283// where u_i is the desired type of v_i.
10284//
10285// ACTION_TEMPLATE and ACTION/ACTION_P* can be overloaded on the
10286// number of value parameters, but not on the number of template
10287// parameters. Without the restriction, the meaning of the following
10288// is unclear:
10289//
10290// OverloadedAction<int, bool>(x);
10291//
10292// Are we using a single-template-parameter action where 'bool' refers
10293// to the type of x, or are we using a two-template-parameter action
10294// where the compiler is asked to infer the type of x?
10295//
10296// Implementation notes:
10297//
10298// GMOCK_INTERNAL_*_HAS_m_TEMPLATE_PARAMS and
10299// GMOCK_INTERNAL_*_AND_n_VALUE_PARAMS are internal macros for
10300// implementing ACTION_TEMPLATE. The main trick we use is to create
10301// new macro invocations when expanding a macro. For example, we have
10302//
10303// #define ACTION_TEMPLATE(name, template_params, value_params)
10304// ... GMOCK_INTERNAL_DECL_##template_params ...
10305//
10306// which causes ACTION_TEMPLATE(..., HAS_1_TEMPLATE_PARAMS(typename, T), ...)
10307// to expand to
10308//
10309// ... GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(typename, T) ...
10310//
10311// Since GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS is a macro, the
10312// preprocessor will continue to expand it to
10313//
10314// ... typename T ...
10315//
10316// This technique conforms to the C++ standard and is portable. It
10317// allows us to implement action templates using O(N) code, where N is
10318// the maximum number of template/value parameters supported. Without
10319// using it, we'd have to devote O(N^2) amount of code to implement all
10320// combinations of m and n.
10321
10322// Declares the template parameters.
10323#define GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(kind0, name0) kind0 name0
10324#define GMOCK_INTERNAL_DECL_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, \
10325 name1) kind0 name0, kind1 name1
10326#define GMOCK_INTERNAL_DECL_HAS_3_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
10327 kind2, name2) kind0 name0, kind1 name1, kind2 name2
10328#define GMOCK_INTERNAL_DECL_HAS_4_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
10329 kind2, name2, kind3, name3) kind0 name0, kind1 name1, kind2 name2, \
10330 kind3 name3
10331#define GMOCK_INTERNAL_DECL_HAS_5_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
10332 kind2, name2, kind3, name3, kind4, name4) kind0 name0, kind1 name1, \
10333 kind2 name2, kind3 name3, kind4 name4
10334#define GMOCK_INTERNAL_DECL_HAS_6_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
10335 kind2, name2, kind3, name3, kind4, name4, kind5, name5) kind0 name0, \
10336 kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5
10337#define GMOCK_INTERNAL_DECL_HAS_7_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
10338 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
10339 name6) kind0 name0, kind1 name1, kind2 name2, kind3 name3, kind4 name4, \
10340 kind5 name5, kind6 name6
10341#define GMOCK_INTERNAL_DECL_HAS_8_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
10342 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
10343 kind7, name7) kind0 name0, kind1 name1, kind2 name2, kind3 name3, \
10344 kind4 name4, kind5 name5, kind6 name6, kind7 name7
10345#define GMOCK_INTERNAL_DECL_HAS_9_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
10346 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
10347 kind7, name7, kind8, name8) kind0 name0, kind1 name1, kind2 name2, \
10348 kind3 name3, kind4 name4, kind5 name5, kind6 name6, kind7 name7, \
10349 kind8 name8
10350#define GMOCK_INTERNAL_DECL_HAS_10_TEMPLATE_PARAMS(kind0, name0, kind1, \
10351 name1, kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
10352 name6, kind7, name7, kind8, name8, kind9, name9) kind0 name0, \
10353 kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5, \
10354 kind6 name6, kind7 name7, kind8 name8, kind9 name9
10355
10356// Lists the template parameters.
10357#define GMOCK_INTERNAL_LIST_HAS_1_TEMPLATE_PARAMS(kind0, name0) name0
10358#define GMOCK_INTERNAL_LIST_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, \
10359 name1) name0, name1
10360#define GMOCK_INTERNAL_LIST_HAS_3_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
10361 kind2, name2) name0, name1, name2
10362#define GMOCK_INTERNAL_LIST_HAS_4_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
10363 kind2, name2, kind3, name3) name0, name1, name2, name3
10364#define GMOCK_INTERNAL_LIST_HAS_5_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
10365 kind2, name2, kind3, name3, kind4, name4) name0, name1, name2, name3, \
10366 name4
10367#define GMOCK_INTERNAL_LIST_HAS_6_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
10368 kind2, name2, kind3, name3, kind4, name4, kind5, name5) name0, name1, \
10369 name2, name3, name4, name5
10370#define GMOCK_INTERNAL_LIST_HAS_7_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
10371 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
10372 name6) name0, name1, name2, name3, name4, name5, name6
10373#define GMOCK_INTERNAL_LIST_HAS_8_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
10374 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
10375 kind7, name7) name0, name1, name2, name3, name4, name5, name6, name7
10376#define GMOCK_INTERNAL_LIST_HAS_9_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
10377 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
10378 kind7, name7, kind8, name8) name0, name1, name2, name3, name4, name5, \
10379 name6, name7, name8
10380#define GMOCK_INTERNAL_LIST_HAS_10_TEMPLATE_PARAMS(kind0, name0, kind1, \
10381 name1, kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
10382 name6, kind7, name7, kind8, name8, kind9, name9) name0, name1, name2, \
10383 name3, name4, name5, name6, name7, name8, name9
10384
10385// Declares the types of value parameters.
10386#define GMOCK_INTERNAL_DECL_TYPE_AND_0_VALUE_PARAMS()
10387#define GMOCK_INTERNAL_DECL_TYPE_AND_1_VALUE_PARAMS(p0) , typename p0##_type
10388#define GMOCK_INTERNAL_DECL_TYPE_AND_2_VALUE_PARAMS(p0, p1) , \
10389 typename p0##_type, typename p1##_type
10390#define GMOCK_INTERNAL_DECL_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) , \
10391 typename p0##_type, typename p1##_type, typename p2##_type
10392#define GMOCK_INTERNAL_DECL_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) , \
10393 typename p0##_type, typename p1##_type, typename p2##_type, \
10394 typename p3##_type
10395#define GMOCK_INTERNAL_DECL_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) , \
10396 typename p0##_type, typename p1##_type, typename p2##_type, \
10397 typename p3##_type, typename p4##_type
10398#define GMOCK_INTERNAL_DECL_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) , \
10399 typename p0##_type, typename p1##_type, typename p2##_type, \
10400 typename p3##_type, typename p4##_type, typename p5##_type
10401#define GMOCK_INTERNAL_DECL_TYPE_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
10402 p6) , typename p0##_type, typename p1##_type, typename p2##_type, \
10403 typename p3##_type, typename p4##_type, typename p5##_type, \
10404 typename p6##_type
10405#define GMOCK_INTERNAL_DECL_TYPE_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
10406 p6, p7) , typename p0##_type, typename p1##_type, typename p2##_type, \
10407 typename p3##_type, typename p4##_type, typename p5##_type, \
10408 typename p6##_type, typename p7##_type
10409#define GMOCK_INTERNAL_DECL_TYPE_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
10410 p6, p7, p8) , typename p0##_type, typename p1##_type, typename p2##_type, \
10411 typename p3##_type, typename p4##_type, typename p5##_type, \
10412 typename p6##_type, typename p7##_type, typename p8##_type
10413#define GMOCK_INTERNAL_DECL_TYPE_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
10414 p6, p7, p8, p9) , typename p0##_type, typename p1##_type, \
10415 typename p2##_type, typename p3##_type, typename p4##_type, \
10416 typename p5##_type, typename p6##_type, typename p7##_type, \
10417 typename p8##_type, typename p9##_type
10418
10419// Initializes the value parameters.
10420#define GMOCK_INTERNAL_INIT_AND_0_VALUE_PARAMS()\
10421 ()
10422#define GMOCK_INTERNAL_INIT_AND_1_VALUE_PARAMS(p0)\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010423 (p0##_type gmock_p0) : p0(::std::move(gmock_p0))
Austin Schuh70cc9552019-01-21 19:46:48 -080010424#define GMOCK_INTERNAL_INIT_AND_2_VALUE_PARAMS(p0, p1)\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010425 (p0##_type gmock_p0, p1##_type gmock_p1) : p0(::std::move(gmock_p0)), \
10426 p1(::std::move(gmock_p1))
Austin Schuh70cc9552019-01-21 19:46:48 -080010427#define GMOCK_INTERNAL_INIT_AND_3_VALUE_PARAMS(p0, p1, p2)\
10428 (p0##_type gmock_p0, p1##_type gmock_p1, \
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010429 p2##_type gmock_p2) : p0(::std::move(gmock_p0)), \
10430 p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2))
Austin Schuh70cc9552019-01-21 19:46:48 -080010431#define GMOCK_INTERNAL_INIT_AND_4_VALUE_PARAMS(p0, p1, p2, p3)\
10432 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010433 p3##_type gmock_p3) : p0(::std::move(gmock_p0)), \
10434 p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
10435 p3(::std::move(gmock_p3))
Austin Schuh70cc9552019-01-21 19:46:48 -080010436#define GMOCK_INTERNAL_INIT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)\
10437 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010438 p3##_type gmock_p3, p4##_type gmock_p4) : p0(::std::move(gmock_p0)), \
10439 p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
10440 p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4))
Austin Schuh70cc9552019-01-21 19:46:48 -080010441#define GMOCK_INTERNAL_INIT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)\
10442 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
10443 p3##_type gmock_p3, p4##_type gmock_p4, \
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010444 p5##_type gmock_p5) : p0(::std::move(gmock_p0)), \
10445 p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
10446 p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \
10447 p5(::std::move(gmock_p5))
Austin Schuh70cc9552019-01-21 19:46:48 -080010448#define GMOCK_INTERNAL_INIT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)\
10449 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
10450 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010451 p6##_type gmock_p6) : p0(::std::move(gmock_p0)), \
10452 p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
10453 p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \
10454 p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6))
Austin Schuh70cc9552019-01-21 19:46:48 -080010455#define GMOCK_INTERNAL_INIT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)\
10456 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
10457 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010458 p6##_type gmock_p6, p7##_type gmock_p7) : p0(::std::move(gmock_p0)), \
10459 p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
10460 p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \
10461 p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)), \
10462 p7(::std::move(gmock_p7))
Austin Schuh70cc9552019-01-21 19:46:48 -080010463#define GMOCK_INTERNAL_INIT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
10464 p7, p8)\
10465 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
10466 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
10467 p6##_type gmock_p6, p7##_type gmock_p7, \
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010468 p8##_type gmock_p8) : p0(::std::move(gmock_p0)), \
10469 p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
10470 p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \
10471 p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)), \
10472 p7(::std::move(gmock_p7)), p8(::std::move(gmock_p8))
Austin Schuh70cc9552019-01-21 19:46:48 -080010473#define GMOCK_INTERNAL_INIT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
10474 p7, p8, p9)\
10475 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
10476 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
10477 p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010478 p9##_type gmock_p9) : p0(::std::move(gmock_p0)), \
10479 p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
10480 p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \
10481 p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)), \
10482 p7(::std::move(gmock_p7)), p8(::std::move(gmock_p8)), \
10483 p9(::std::move(gmock_p9))
Austin Schuh70cc9552019-01-21 19:46:48 -080010484
10485// Declares the fields for storing the value parameters.
10486#define GMOCK_INTERNAL_DEFN_AND_0_VALUE_PARAMS()
10487#define GMOCK_INTERNAL_DEFN_AND_1_VALUE_PARAMS(p0) p0##_type p0;
10488#define GMOCK_INTERNAL_DEFN_AND_2_VALUE_PARAMS(p0, p1) p0##_type p0; \
10489 p1##_type p1;
10490#define GMOCK_INTERNAL_DEFN_AND_3_VALUE_PARAMS(p0, p1, p2) p0##_type p0; \
10491 p1##_type p1; p2##_type p2;
10492#define GMOCK_INTERNAL_DEFN_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0##_type p0; \
10493 p1##_type p1; p2##_type p2; p3##_type p3;
10494#define GMOCK_INTERNAL_DEFN_AND_5_VALUE_PARAMS(p0, p1, p2, p3, \
10495 p4) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4;
10496#define GMOCK_INTERNAL_DEFN_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, \
10497 p5) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \
10498 p5##_type p5;
10499#define GMOCK_INTERNAL_DEFN_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
10500 p6) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \
10501 p5##_type p5; p6##_type p6;
10502#define GMOCK_INTERNAL_DEFN_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
10503 p7) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \
10504 p5##_type p5; p6##_type p6; p7##_type p7;
10505#define GMOCK_INTERNAL_DEFN_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
10506 p7, p8) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; \
10507 p4##_type p4; p5##_type p5; p6##_type p6; p7##_type p7; p8##_type p8;
10508#define GMOCK_INTERNAL_DEFN_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
10509 p7, p8, p9) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; \
10510 p4##_type p4; p5##_type p5; p6##_type p6; p7##_type p7; p8##_type p8; \
10511 p9##_type p9;
10512
10513// Lists the value parameters.
10514#define GMOCK_INTERNAL_LIST_AND_0_VALUE_PARAMS()
10515#define GMOCK_INTERNAL_LIST_AND_1_VALUE_PARAMS(p0) p0
10516#define GMOCK_INTERNAL_LIST_AND_2_VALUE_PARAMS(p0, p1) p0, p1
10517#define GMOCK_INTERNAL_LIST_AND_3_VALUE_PARAMS(p0, p1, p2) p0, p1, p2
10518#define GMOCK_INTERNAL_LIST_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0, p1, p2, p3
10519#define GMOCK_INTERNAL_LIST_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) p0, p1, \
10520 p2, p3, p4
10521#define GMOCK_INTERNAL_LIST_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) p0, \
10522 p1, p2, p3, p4, p5
10523#define GMOCK_INTERNAL_LIST_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
10524 p6) p0, p1, p2, p3, p4, p5, p6
10525#define GMOCK_INTERNAL_LIST_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
10526 p7) p0, p1, p2, p3, p4, p5, p6, p7
10527#define GMOCK_INTERNAL_LIST_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
10528 p7, p8) p0, p1, p2, p3, p4, p5, p6, p7, p8
10529#define GMOCK_INTERNAL_LIST_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
10530 p7, p8, p9) p0, p1, p2, p3, p4, p5, p6, p7, p8, p9
10531
10532// Lists the value parameter types.
10533#define GMOCK_INTERNAL_LIST_TYPE_AND_0_VALUE_PARAMS()
10534#define GMOCK_INTERNAL_LIST_TYPE_AND_1_VALUE_PARAMS(p0) , p0##_type
10535#define GMOCK_INTERNAL_LIST_TYPE_AND_2_VALUE_PARAMS(p0, p1) , p0##_type, \
10536 p1##_type
10537#define GMOCK_INTERNAL_LIST_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) , p0##_type, \
10538 p1##_type, p2##_type
10539#define GMOCK_INTERNAL_LIST_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) , \
10540 p0##_type, p1##_type, p2##_type, p3##_type
10541#define GMOCK_INTERNAL_LIST_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) , \
10542 p0##_type, p1##_type, p2##_type, p3##_type, p4##_type
10543#define GMOCK_INTERNAL_LIST_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) , \
10544 p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type
10545#define GMOCK_INTERNAL_LIST_TYPE_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
10546 p6) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type, \
10547 p6##_type
10548#define GMOCK_INTERNAL_LIST_TYPE_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
10549 p6, p7) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
10550 p5##_type, p6##_type, p7##_type
10551#define GMOCK_INTERNAL_LIST_TYPE_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
10552 p6, p7, p8) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
10553 p5##_type, p6##_type, p7##_type, p8##_type
10554#define GMOCK_INTERNAL_LIST_TYPE_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
10555 p6, p7, p8, p9) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
10556 p5##_type, p6##_type, p7##_type, p8##_type, p9##_type
10557
10558// Declares the value parameters.
10559#define GMOCK_INTERNAL_DECL_AND_0_VALUE_PARAMS()
10560#define GMOCK_INTERNAL_DECL_AND_1_VALUE_PARAMS(p0) p0##_type p0
10561#define GMOCK_INTERNAL_DECL_AND_2_VALUE_PARAMS(p0, p1) p0##_type p0, \
10562 p1##_type p1
10563#define GMOCK_INTERNAL_DECL_AND_3_VALUE_PARAMS(p0, p1, p2) p0##_type p0, \
10564 p1##_type p1, p2##_type p2
10565#define GMOCK_INTERNAL_DECL_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0##_type p0, \
10566 p1##_type p1, p2##_type p2, p3##_type p3
10567#define GMOCK_INTERNAL_DECL_AND_5_VALUE_PARAMS(p0, p1, p2, p3, \
10568 p4) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4
10569#define GMOCK_INTERNAL_DECL_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, \
10570 p5) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \
10571 p5##_type p5
10572#define GMOCK_INTERNAL_DECL_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
10573 p6) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \
10574 p5##_type p5, p6##_type p6
10575#define GMOCK_INTERNAL_DECL_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
10576 p7) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \
10577 p5##_type p5, p6##_type p6, p7##_type p7
10578#define GMOCK_INTERNAL_DECL_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
10579 p7, p8) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
10580 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8
10581#define GMOCK_INTERNAL_DECL_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
10582 p7, p8, p9) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
10583 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \
10584 p9##_type p9
10585
10586// The suffix of the class template implementing the action template.
10587#define GMOCK_INTERNAL_COUNT_AND_0_VALUE_PARAMS()
10588#define GMOCK_INTERNAL_COUNT_AND_1_VALUE_PARAMS(p0) P
10589#define GMOCK_INTERNAL_COUNT_AND_2_VALUE_PARAMS(p0, p1) P2
10590#define GMOCK_INTERNAL_COUNT_AND_3_VALUE_PARAMS(p0, p1, p2) P3
10591#define GMOCK_INTERNAL_COUNT_AND_4_VALUE_PARAMS(p0, p1, p2, p3) P4
10592#define GMOCK_INTERNAL_COUNT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) P5
10593#define GMOCK_INTERNAL_COUNT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) P6
10594#define GMOCK_INTERNAL_COUNT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6) P7
10595#define GMOCK_INTERNAL_COUNT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
10596 p7) P8
10597#define GMOCK_INTERNAL_COUNT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
10598 p7, p8) P9
10599#define GMOCK_INTERNAL_COUNT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
10600 p7, p8, p9) P10
10601
10602// The name of the class template implementing the action template.
10603#define GMOCK_ACTION_CLASS_(name, value_params)\
10604 GTEST_CONCAT_TOKEN_(name##Action, GMOCK_INTERNAL_COUNT_##value_params)
10605
10606#define ACTION_TEMPLATE(name, template_params, value_params)\
10607 template <GMOCK_INTERNAL_DECL_##template_params\
10608 GMOCK_INTERNAL_DECL_TYPE_##value_params>\
10609 class GMOCK_ACTION_CLASS_(name, value_params) {\
10610 public:\
10611 explicit GMOCK_ACTION_CLASS_(name, value_params)\
10612 GMOCK_INTERNAL_INIT_##value_params {}\
10613 template <typename F>\
10614 class gmock_Impl : public ::testing::ActionInterface<F> {\
10615 public:\
10616 typedef F function_type;\
10617 typedef typename ::testing::internal::Function<F>::Result return_type;\
10618 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
10619 args_type;\
10620 explicit gmock_Impl GMOCK_INTERNAL_INIT_##value_params {}\
10621 virtual return_type Perform(const args_type& args) {\
10622 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
10623 Perform(this, args);\
10624 }\
10625 template <typename arg0_type, typename arg1_type, typename arg2_type, \
10626 typename arg3_type, typename arg4_type, typename arg5_type, \
10627 typename arg6_type, typename arg7_type, typename arg8_type, \
10628 typename arg9_type>\
10629 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
10630 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
10631 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
10632 arg9_type arg9) const;\
10633 GMOCK_INTERNAL_DEFN_##value_params\
10634 private:\
10635 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
10636 };\
10637 template <typename F> operator ::testing::Action<F>() const {\
10638 return ::testing::Action<F>(\
10639 new gmock_Impl<F>(GMOCK_INTERNAL_LIST_##value_params));\
10640 }\
10641 GMOCK_INTERNAL_DEFN_##value_params\
10642 private:\
10643 GTEST_DISALLOW_ASSIGN_(GMOCK_ACTION_CLASS_(name, value_params));\
10644 };\
10645 template <GMOCK_INTERNAL_DECL_##template_params\
10646 GMOCK_INTERNAL_DECL_TYPE_##value_params>\
10647 inline GMOCK_ACTION_CLASS_(name, value_params)<\
10648 GMOCK_INTERNAL_LIST_##template_params\
10649 GMOCK_INTERNAL_LIST_TYPE_##value_params> name(\
10650 GMOCK_INTERNAL_DECL_##value_params) {\
10651 return GMOCK_ACTION_CLASS_(name, value_params)<\
10652 GMOCK_INTERNAL_LIST_##template_params\
10653 GMOCK_INTERNAL_LIST_TYPE_##value_params>(\
10654 GMOCK_INTERNAL_LIST_##value_params);\
10655 }\
10656 template <GMOCK_INTERNAL_DECL_##template_params\
10657 GMOCK_INTERNAL_DECL_TYPE_##value_params>\
10658 template <typename F>\
10659 template <typename arg0_type, typename arg1_type, typename arg2_type, \
10660 typename arg3_type, typename arg4_type, typename arg5_type, \
10661 typename arg6_type, typename arg7_type, typename arg8_type, \
10662 typename arg9_type>\
10663 typename ::testing::internal::Function<F>::Result\
10664 GMOCK_ACTION_CLASS_(name, value_params)<\
10665 GMOCK_INTERNAL_LIST_##template_params\
10666 GMOCK_INTERNAL_LIST_TYPE_##value_params>::gmock_Impl<F>::\
10667 gmock_PerformImpl(\
10668 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
10669
10670#define ACTION(name)\
10671 class name##Action {\
10672 public:\
10673 name##Action() {}\
10674 template <typename F>\
10675 class gmock_Impl : public ::testing::ActionInterface<F> {\
10676 public:\
10677 typedef F function_type;\
10678 typedef typename ::testing::internal::Function<F>::Result return_type;\
10679 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
10680 args_type;\
10681 gmock_Impl() {}\
10682 virtual return_type Perform(const args_type& args) {\
10683 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
10684 Perform(this, args);\
10685 }\
10686 template <typename arg0_type, typename arg1_type, typename arg2_type, \
10687 typename arg3_type, typename arg4_type, typename arg5_type, \
10688 typename arg6_type, typename arg7_type, typename arg8_type, \
10689 typename arg9_type>\
10690 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
10691 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
10692 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
10693 arg9_type arg9) const;\
10694 private:\
10695 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
10696 };\
10697 template <typename F> operator ::testing::Action<F>() const {\
10698 return ::testing::Action<F>(new gmock_Impl<F>());\
10699 }\
10700 private:\
10701 GTEST_DISALLOW_ASSIGN_(name##Action);\
10702 };\
10703 inline name##Action name() {\
10704 return name##Action();\
10705 }\
10706 template <typename F>\
10707 template <typename arg0_type, typename arg1_type, typename arg2_type, \
10708 typename arg3_type, typename arg4_type, typename arg5_type, \
10709 typename arg6_type, typename arg7_type, typename arg8_type, \
10710 typename arg9_type>\
10711 typename ::testing::internal::Function<F>::Result\
10712 name##Action::gmock_Impl<F>::gmock_PerformImpl(\
10713 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
10714
10715#define ACTION_P(name, p0)\
10716 template <typename p0##_type>\
10717 class name##ActionP {\
10718 public:\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010719 explicit name##ActionP(p0##_type gmock_p0) : \
10720 p0(::std::forward<p0##_type>(gmock_p0)) {}\
Austin Schuh70cc9552019-01-21 19:46:48 -080010721 template <typename F>\
10722 class gmock_Impl : public ::testing::ActionInterface<F> {\
10723 public:\
10724 typedef F function_type;\
10725 typedef typename ::testing::internal::Function<F>::Result return_type;\
10726 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
10727 args_type;\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010728 explicit gmock_Impl(p0##_type gmock_p0) : \
10729 p0(::std::forward<p0##_type>(gmock_p0)) {}\
Austin Schuh70cc9552019-01-21 19:46:48 -080010730 virtual return_type Perform(const args_type& args) {\
10731 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
10732 Perform(this, args);\
10733 }\
10734 template <typename arg0_type, typename arg1_type, typename arg2_type, \
10735 typename arg3_type, typename arg4_type, typename arg5_type, \
10736 typename arg6_type, typename arg7_type, typename arg8_type, \
10737 typename arg9_type>\
10738 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
10739 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
10740 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
10741 arg9_type arg9) const;\
10742 p0##_type p0;\
10743 private:\
10744 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
10745 };\
10746 template <typename F> operator ::testing::Action<F>() const {\
10747 return ::testing::Action<F>(new gmock_Impl<F>(p0));\
10748 }\
10749 p0##_type p0;\
10750 private:\
10751 GTEST_DISALLOW_ASSIGN_(name##ActionP);\
10752 };\
10753 template <typename p0##_type>\
10754 inline name##ActionP<p0##_type> name(p0##_type p0) {\
10755 return name##ActionP<p0##_type>(p0);\
10756 }\
10757 template <typename p0##_type>\
10758 template <typename F>\
10759 template <typename arg0_type, typename arg1_type, typename arg2_type, \
10760 typename arg3_type, typename arg4_type, typename arg5_type, \
10761 typename arg6_type, typename arg7_type, typename arg8_type, \
10762 typename arg9_type>\
10763 typename ::testing::internal::Function<F>::Result\
10764 name##ActionP<p0##_type>::gmock_Impl<F>::gmock_PerformImpl(\
10765 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
10766
10767#define ACTION_P2(name, p0, p1)\
10768 template <typename p0##_type, typename p1##_type>\
10769 class name##ActionP2 {\
10770 public:\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010771 name##ActionP2(p0##_type gmock_p0, \
10772 p1##_type gmock_p1) : p0(::std::forward<p0##_type>(gmock_p0)), \
10773 p1(::std::forward<p1##_type>(gmock_p1)) {}\
Austin Schuh70cc9552019-01-21 19:46:48 -080010774 template <typename F>\
10775 class gmock_Impl : public ::testing::ActionInterface<F> {\
10776 public:\
10777 typedef F function_type;\
10778 typedef typename ::testing::internal::Function<F>::Result return_type;\
10779 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
10780 args_type;\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010781 gmock_Impl(p0##_type gmock_p0, \
10782 p1##_type gmock_p1) : p0(::std::forward<p0##_type>(gmock_p0)), \
10783 p1(::std::forward<p1##_type>(gmock_p1)) {}\
Austin Schuh70cc9552019-01-21 19:46:48 -080010784 virtual return_type Perform(const args_type& args) {\
10785 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
10786 Perform(this, args);\
10787 }\
10788 template <typename arg0_type, typename arg1_type, typename arg2_type, \
10789 typename arg3_type, typename arg4_type, typename arg5_type, \
10790 typename arg6_type, typename arg7_type, typename arg8_type, \
10791 typename arg9_type>\
10792 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
10793 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
10794 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
10795 arg9_type arg9) const;\
10796 p0##_type p0;\
10797 p1##_type p1;\
10798 private:\
10799 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
10800 };\
10801 template <typename F> operator ::testing::Action<F>() const {\
10802 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1));\
10803 }\
10804 p0##_type p0;\
10805 p1##_type p1;\
10806 private:\
10807 GTEST_DISALLOW_ASSIGN_(name##ActionP2);\
10808 };\
10809 template <typename p0##_type, typename p1##_type>\
10810 inline name##ActionP2<p0##_type, p1##_type> name(p0##_type p0, \
10811 p1##_type p1) {\
10812 return name##ActionP2<p0##_type, p1##_type>(p0, p1);\
10813 }\
10814 template <typename p0##_type, typename p1##_type>\
10815 template <typename F>\
10816 template <typename arg0_type, typename arg1_type, typename arg2_type, \
10817 typename arg3_type, typename arg4_type, typename arg5_type, \
10818 typename arg6_type, typename arg7_type, typename arg8_type, \
10819 typename arg9_type>\
10820 typename ::testing::internal::Function<F>::Result\
10821 name##ActionP2<p0##_type, p1##_type>::gmock_Impl<F>::gmock_PerformImpl(\
10822 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
10823
10824#define ACTION_P3(name, p0, p1, p2)\
10825 template <typename p0##_type, typename p1##_type, typename p2##_type>\
10826 class name##ActionP3 {\
10827 public:\
10828 name##ActionP3(p0##_type gmock_p0, p1##_type gmock_p1, \
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010829 p2##_type gmock_p2) : p0(::std::forward<p0##_type>(gmock_p0)), \
10830 p1(::std::forward<p1##_type>(gmock_p1)), \
10831 p2(::std::forward<p2##_type>(gmock_p2)) {}\
Austin Schuh70cc9552019-01-21 19:46:48 -080010832 template <typename F>\
10833 class gmock_Impl : public ::testing::ActionInterface<F> {\
10834 public:\
10835 typedef F function_type;\
10836 typedef typename ::testing::internal::Function<F>::Result return_type;\
10837 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
10838 args_type;\
10839 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, \
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010840 p2##_type gmock_p2) : p0(::std::forward<p0##_type>(gmock_p0)), \
10841 p1(::std::forward<p1##_type>(gmock_p1)), \
10842 p2(::std::forward<p2##_type>(gmock_p2)) {}\
Austin Schuh70cc9552019-01-21 19:46:48 -080010843 virtual return_type Perform(const args_type& args) {\
10844 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
10845 Perform(this, args);\
10846 }\
10847 template <typename arg0_type, typename arg1_type, typename arg2_type, \
10848 typename arg3_type, typename arg4_type, typename arg5_type, \
10849 typename arg6_type, typename arg7_type, typename arg8_type, \
10850 typename arg9_type>\
10851 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
10852 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
10853 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
10854 arg9_type arg9) const;\
10855 p0##_type p0;\
10856 p1##_type p1;\
10857 p2##_type p2;\
10858 private:\
10859 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
10860 };\
10861 template <typename F> operator ::testing::Action<F>() const {\
10862 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2));\
10863 }\
10864 p0##_type p0;\
10865 p1##_type p1;\
10866 p2##_type p2;\
10867 private:\
10868 GTEST_DISALLOW_ASSIGN_(name##ActionP3);\
10869 };\
10870 template <typename p0##_type, typename p1##_type, typename p2##_type>\
10871 inline name##ActionP3<p0##_type, p1##_type, p2##_type> name(p0##_type p0, \
10872 p1##_type p1, p2##_type p2) {\
10873 return name##ActionP3<p0##_type, p1##_type, p2##_type>(p0, p1, p2);\
10874 }\
10875 template <typename p0##_type, typename p1##_type, typename p2##_type>\
10876 template <typename F>\
10877 template <typename arg0_type, typename arg1_type, typename arg2_type, \
10878 typename arg3_type, typename arg4_type, typename arg5_type, \
10879 typename arg6_type, typename arg7_type, typename arg8_type, \
10880 typename arg9_type>\
10881 typename ::testing::internal::Function<F>::Result\
10882 name##ActionP3<p0##_type, p1##_type, \
10883 p2##_type>::gmock_Impl<F>::gmock_PerformImpl(\
10884 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
10885
10886#define ACTION_P4(name, p0, p1, p2, p3)\
10887 template <typename p0##_type, typename p1##_type, typename p2##_type, \
10888 typename p3##_type>\
10889 class name##ActionP4 {\
10890 public:\
10891 name##ActionP4(p0##_type gmock_p0, p1##_type gmock_p1, \
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010892 p2##_type gmock_p2, \
10893 p3##_type gmock_p3) : p0(::std::forward<p0##_type>(gmock_p0)), \
10894 p1(::std::forward<p1##_type>(gmock_p1)), \
10895 p2(::std::forward<p2##_type>(gmock_p2)), \
10896 p3(::std::forward<p3##_type>(gmock_p3)) {}\
Austin Schuh70cc9552019-01-21 19:46:48 -080010897 template <typename F>\
10898 class gmock_Impl : public ::testing::ActionInterface<F> {\
10899 public:\
10900 typedef F function_type;\
10901 typedef typename ::testing::internal::Function<F>::Result return_type;\
10902 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
10903 args_type;\
10904 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010905 p3##_type gmock_p3) : p0(::std::forward<p0##_type>(gmock_p0)), \
10906 p1(::std::forward<p1##_type>(gmock_p1)), \
10907 p2(::std::forward<p2##_type>(gmock_p2)), \
10908 p3(::std::forward<p3##_type>(gmock_p3)) {}\
Austin Schuh70cc9552019-01-21 19:46:48 -080010909 virtual return_type Perform(const args_type& args) {\
10910 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
10911 Perform(this, args);\
10912 }\
10913 template <typename arg0_type, typename arg1_type, typename arg2_type, \
10914 typename arg3_type, typename arg4_type, typename arg5_type, \
10915 typename arg6_type, typename arg7_type, typename arg8_type, \
10916 typename arg9_type>\
10917 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
10918 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
10919 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
10920 arg9_type arg9) const;\
10921 p0##_type p0;\
10922 p1##_type p1;\
10923 p2##_type p2;\
10924 p3##_type p3;\
10925 private:\
10926 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
10927 };\
10928 template <typename F> operator ::testing::Action<F>() const {\
10929 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3));\
10930 }\
10931 p0##_type p0;\
10932 p1##_type p1;\
10933 p2##_type p2;\
10934 p3##_type p3;\
10935 private:\
10936 GTEST_DISALLOW_ASSIGN_(name##ActionP4);\
10937 };\
10938 template <typename p0##_type, typename p1##_type, typename p2##_type, \
10939 typename p3##_type>\
10940 inline name##ActionP4<p0##_type, p1##_type, p2##_type, \
10941 p3##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
10942 p3##_type p3) {\
10943 return name##ActionP4<p0##_type, p1##_type, p2##_type, p3##_type>(p0, p1, \
10944 p2, p3);\
10945 }\
10946 template <typename p0##_type, typename p1##_type, typename p2##_type, \
10947 typename p3##_type>\
10948 template <typename F>\
10949 template <typename arg0_type, typename arg1_type, typename arg2_type, \
10950 typename arg3_type, typename arg4_type, typename arg5_type, \
10951 typename arg6_type, typename arg7_type, typename arg8_type, \
10952 typename arg9_type>\
10953 typename ::testing::internal::Function<F>::Result\
10954 name##ActionP4<p0##_type, p1##_type, p2##_type, \
10955 p3##_type>::gmock_Impl<F>::gmock_PerformImpl(\
10956 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
10957
10958#define ACTION_P5(name, p0, p1, p2, p3, p4)\
10959 template <typename p0##_type, typename p1##_type, typename p2##_type, \
10960 typename p3##_type, typename p4##_type>\
10961 class name##ActionP5 {\
10962 public:\
10963 name##ActionP5(p0##_type gmock_p0, p1##_type gmock_p1, \
10964 p2##_type gmock_p2, p3##_type gmock_p3, \
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010965 p4##_type gmock_p4) : p0(::std::forward<p0##_type>(gmock_p0)), \
10966 p1(::std::forward<p1##_type>(gmock_p1)), \
10967 p2(::std::forward<p2##_type>(gmock_p2)), \
10968 p3(::std::forward<p3##_type>(gmock_p3)), \
10969 p4(::std::forward<p4##_type>(gmock_p4)) {}\
Austin Schuh70cc9552019-01-21 19:46:48 -080010970 template <typename F>\
10971 class gmock_Impl : public ::testing::ActionInterface<F> {\
10972 public:\
10973 typedef F function_type;\
10974 typedef typename ::testing::internal::Function<F>::Result return_type;\
10975 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
10976 args_type;\
10977 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080010978 p3##_type gmock_p3, \
10979 p4##_type gmock_p4) : p0(::std::forward<p0##_type>(gmock_p0)), \
10980 p1(::std::forward<p1##_type>(gmock_p1)), \
10981 p2(::std::forward<p2##_type>(gmock_p2)), \
10982 p3(::std::forward<p3##_type>(gmock_p3)), \
10983 p4(::std::forward<p4##_type>(gmock_p4)) {}\
Austin Schuh70cc9552019-01-21 19:46:48 -080010984 virtual return_type Perform(const args_type& args) {\
10985 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
10986 Perform(this, args);\
10987 }\
10988 template <typename arg0_type, typename arg1_type, typename arg2_type, \
10989 typename arg3_type, typename arg4_type, typename arg5_type, \
10990 typename arg6_type, typename arg7_type, typename arg8_type, \
10991 typename arg9_type>\
10992 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
10993 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
10994 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
10995 arg9_type arg9) const;\
10996 p0##_type p0;\
10997 p1##_type p1;\
10998 p2##_type p2;\
10999 p3##_type p3;\
11000 p4##_type p4;\
11001 private:\
11002 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
11003 };\
11004 template <typename F> operator ::testing::Action<F>() const {\
11005 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4));\
11006 }\
11007 p0##_type p0;\
11008 p1##_type p1;\
11009 p2##_type p2;\
11010 p3##_type p3;\
11011 p4##_type p4;\
11012 private:\
11013 GTEST_DISALLOW_ASSIGN_(name##ActionP5);\
11014 };\
11015 template <typename p0##_type, typename p1##_type, typename p2##_type, \
11016 typename p3##_type, typename p4##_type>\
11017 inline name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \
11018 p4##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
11019 p4##_type p4) {\
11020 return name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \
11021 p4##_type>(p0, p1, p2, p3, p4);\
11022 }\
11023 template <typename p0##_type, typename p1##_type, typename p2##_type, \
11024 typename p3##_type, typename p4##_type>\
11025 template <typename F>\
11026 template <typename arg0_type, typename arg1_type, typename arg2_type, \
11027 typename arg3_type, typename arg4_type, typename arg5_type, \
11028 typename arg6_type, typename arg7_type, typename arg8_type, \
11029 typename arg9_type>\
11030 typename ::testing::internal::Function<F>::Result\
11031 name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \
11032 p4##_type>::gmock_Impl<F>::gmock_PerformImpl(\
11033 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
11034
11035#define ACTION_P6(name, p0, p1, p2, p3, p4, p5)\
11036 template <typename p0##_type, typename p1##_type, typename p2##_type, \
11037 typename p3##_type, typename p4##_type, typename p5##_type>\
11038 class name##ActionP6 {\
11039 public:\
11040 name##ActionP6(p0##_type gmock_p0, p1##_type gmock_p1, \
11041 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080011042 p5##_type gmock_p5) : p0(::std::forward<p0##_type>(gmock_p0)), \
11043 p1(::std::forward<p1##_type>(gmock_p1)), \
11044 p2(::std::forward<p2##_type>(gmock_p2)), \
11045 p3(::std::forward<p3##_type>(gmock_p3)), \
11046 p4(::std::forward<p4##_type>(gmock_p4)), \
11047 p5(::std::forward<p5##_type>(gmock_p5)) {}\
Austin Schuh70cc9552019-01-21 19:46:48 -080011048 template <typename F>\
11049 class gmock_Impl : public ::testing::ActionInterface<F> {\
11050 public:\
11051 typedef F function_type;\
11052 typedef typename ::testing::internal::Function<F>::Result return_type;\
11053 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
11054 args_type;\
11055 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
11056 p3##_type gmock_p3, p4##_type gmock_p4, \
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080011057 p5##_type gmock_p5) : p0(::std::forward<p0##_type>(gmock_p0)), \
11058 p1(::std::forward<p1##_type>(gmock_p1)), \
11059 p2(::std::forward<p2##_type>(gmock_p2)), \
11060 p3(::std::forward<p3##_type>(gmock_p3)), \
11061 p4(::std::forward<p4##_type>(gmock_p4)), \
11062 p5(::std::forward<p5##_type>(gmock_p5)) {}\
Austin Schuh70cc9552019-01-21 19:46:48 -080011063 virtual return_type Perform(const args_type& args) {\
11064 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
11065 Perform(this, args);\
11066 }\
11067 template <typename arg0_type, typename arg1_type, typename arg2_type, \
11068 typename arg3_type, typename arg4_type, typename arg5_type, \
11069 typename arg6_type, typename arg7_type, typename arg8_type, \
11070 typename arg9_type>\
11071 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
11072 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
11073 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
11074 arg9_type arg9) const;\
11075 p0##_type p0;\
11076 p1##_type p1;\
11077 p2##_type p2;\
11078 p3##_type p3;\
11079 p4##_type p4;\
11080 p5##_type p5;\
11081 private:\
11082 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
11083 };\
11084 template <typename F> operator ::testing::Action<F>() const {\
11085 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5));\
11086 }\
11087 p0##_type p0;\
11088 p1##_type p1;\
11089 p2##_type p2;\
11090 p3##_type p3;\
11091 p4##_type p4;\
11092 p5##_type p5;\
11093 private:\
11094 GTEST_DISALLOW_ASSIGN_(name##ActionP6);\
11095 };\
11096 template <typename p0##_type, typename p1##_type, typename p2##_type, \
11097 typename p3##_type, typename p4##_type, typename p5##_type>\
11098 inline name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, \
11099 p4##_type, p5##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
11100 p3##_type p3, p4##_type p4, p5##_type p5) {\
11101 return name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, \
11102 p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5);\
11103 }\
11104 template <typename p0##_type, typename p1##_type, typename p2##_type, \
11105 typename p3##_type, typename p4##_type, typename p5##_type>\
11106 template <typename F>\
11107 template <typename arg0_type, typename arg1_type, typename arg2_type, \
11108 typename arg3_type, typename arg4_type, typename arg5_type, \
11109 typename arg6_type, typename arg7_type, typename arg8_type, \
11110 typename arg9_type>\
11111 typename ::testing::internal::Function<F>::Result\
11112 name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
11113 p5##_type>::gmock_Impl<F>::gmock_PerformImpl(\
11114 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
11115
11116#define ACTION_P7(name, p0, p1, p2, p3, p4, p5, p6)\
11117 template <typename p0##_type, typename p1##_type, typename p2##_type, \
11118 typename p3##_type, typename p4##_type, typename p5##_type, \
11119 typename p6##_type>\
11120 class name##ActionP7 {\
11121 public:\
11122 name##ActionP7(p0##_type gmock_p0, p1##_type gmock_p1, \
11123 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080011124 p5##_type gmock_p5, \
11125 p6##_type gmock_p6) : p0(::std::forward<p0##_type>(gmock_p0)), \
11126 p1(::std::forward<p1##_type>(gmock_p1)), \
11127 p2(::std::forward<p2##_type>(gmock_p2)), \
11128 p3(::std::forward<p3##_type>(gmock_p3)), \
11129 p4(::std::forward<p4##_type>(gmock_p4)), \
11130 p5(::std::forward<p5##_type>(gmock_p5)), \
11131 p6(::std::forward<p6##_type>(gmock_p6)) {}\
Austin Schuh70cc9552019-01-21 19:46:48 -080011132 template <typename F>\
11133 class gmock_Impl : public ::testing::ActionInterface<F> {\
11134 public:\
11135 typedef F function_type;\
11136 typedef typename ::testing::internal::Function<F>::Result return_type;\
11137 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
11138 args_type;\
11139 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
11140 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080011141 p6##_type gmock_p6) : p0(::std::forward<p0##_type>(gmock_p0)), \
11142 p1(::std::forward<p1##_type>(gmock_p1)), \
11143 p2(::std::forward<p2##_type>(gmock_p2)), \
11144 p3(::std::forward<p3##_type>(gmock_p3)), \
11145 p4(::std::forward<p4##_type>(gmock_p4)), \
11146 p5(::std::forward<p5##_type>(gmock_p5)), \
11147 p6(::std::forward<p6##_type>(gmock_p6)) {}\
Austin Schuh70cc9552019-01-21 19:46:48 -080011148 virtual return_type Perform(const args_type& args) {\
11149 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
11150 Perform(this, args);\
11151 }\
11152 template <typename arg0_type, typename arg1_type, typename arg2_type, \
11153 typename arg3_type, typename arg4_type, typename arg5_type, \
11154 typename arg6_type, typename arg7_type, typename arg8_type, \
11155 typename arg9_type>\
11156 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
11157 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
11158 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
11159 arg9_type arg9) const;\
11160 p0##_type p0;\
11161 p1##_type p1;\
11162 p2##_type p2;\
11163 p3##_type p3;\
11164 p4##_type p4;\
11165 p5##_type p5;\
11166 p6##_type p6;\
11167 private:\
11168 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
11169 };\
11170 template <typename F> operator ::testing::Action<F>() const {\
11171 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
11172 p6));\
11173 }\
11174 p0##_type p0;\
11175 p1##_type p1;\
11176 p2##_type p2;\
11177 p3##_type p3;\
11178 p4##_type p4;\
11179 p5##_type p5;\
11180 p6##_type p6;\
11181 private:\
11182 GTEST_DISALLOW_ASSIGN_(name##ActionP7);\
11183 };\
11184 template <typename p0##_type, typename p1##_type, typename p2##_type, \
11185 typename p3##_type, typename p4##_type, typename p5##_type, \
11186 typename p6##_type>\
11187 inline name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, \
11188 p4##_type, p5##_type, p6##_type> name(p0##_type p0, p1##_type p1, \
11189 p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
11190 p6##_type p6) {\
11191 return name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, \
11192 p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, p6);\
11193 }\
11194 template <typename p0##_type, typename p1##_type, typename p2##_type, \
11195 typename p3##_type, typename p4##_type, typename p5##_type, \
11196 typename p6##_type>\
11197 template <typename F>\
11198 template <typename arg0_type, typename arg1_type, typename arg2_type, \
11199 typename arg3_type, typename arg4_type, typename arg5_type, \
11200 typename arg6_type, typename arg7_type, typename arg8_type, \
11201 typename arg9_type>\
11202 typename ::testing::internal::Function<F>::Result\
11203 name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
11204 p5##_type, p6##_type>::gmock_Impl<F>::gmock_PerformImpl(\
11205 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
11206
11207#define ACTION_P8(name, p0, p1, p2, p3, p4, p5, p6, p7)\
11208 template <typename p0##_type, typename p1##_type, typename p2##_type, \
11209 typename p3##_type, typename p4##_type, typename p5##_type, \
11210 typename p6##_type, typename p7##_type>\
11211 class name##ActionP8 {\
11212 public:\
11213 name##ActionP8(p0##_type gmock_p0, p1##_type gmock_p1, \
11214 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
11215 p5##_type gmock_p5, p6##_type gmock_p6, \
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080011216 p7##_type gmock_p7) : p0(::std::forward<p0##_type>(gmock_p0)), \
11217 p1(::std::forward<p1##_type>(gmock_p1)), \
11218 p2(::std::forward<p2##_type>(gmock_p2)), \
11219 p3(::std::forward<p3##_type>(gmock_p3)), \
11220 p4(::std::forward<p4##_type>(gmock_p4)), \
11221 p5(::std::forward<p5##_type>(gmock_p5)), \
11222 p6(::std::forward<p6##_type>(gmock_p6)), \
11223 p7(::std::forward<p7##_type>(gmock_p7)) {}\
Austin Schuh70cc9552019-01-21 19:46:48 -080011224 template <typename F>\
11225 class gmock_Impl : public ::testing::ActionInterface<F> {\
11226 public:\
11227 typedef F function_type;\
11228 typedef typename ::testing::internal::Function<F>::Result return_type;\
11229 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
11230 args_type;\
11231 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
11232 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080011233 p6##_type gmock_p6, \
11234 p7##_type gmock_p7) : p0(::std::forward<p0##_type>(gmock_p0)), \
11235 p1(::std::forward<p1##_type>(gmock_p1)), \
11236 p2(::std::forward<p2##_type>(gmock_p2)), \
11237 p3(::std::forward<p3##_type>(gmock_p3)), \
11238 p4(::std::forward<p4##_type>(gmock_p4)), \
11239 p5(::std::forward<p5##_type>(gmock_p5)), \
11240 p6(::std::forward<p6##_type>(gmock_p6)), \
11241 p7(::std::forward<p7##_type>(gmock_p7)) {}\
Austin Schuh70cc9552019-01-21 19:46:48 -080011242 virtual return_type Perform(const args_type& args) {\
11243 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
11244 Perform(this, args);\
11245 }\
11246 template <typename arg0_type, typename arg1_type, typename arg2_type, \
11247 typename arg3_type, typename arg4_type, typename arg5_type, \
11248 typename arg6_type, typename arg7_type, typename arg8_type, \
11249 typename arg9_type>\
11250 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
11251 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
11252 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
11253 arg9_type arg9) const;\
11254 p0##_type p0;\
11255 p1##_type p1;\
11256 p2##_type p2;\
11257 p3##_type p3;\
11258 p4##_type p4;\
11259 p5##_type p5;\
11260 p6##_type p6;\
11261 p7##_type p7;\
11262 private:\
11263 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
11264 };\
11265 template <typename F> operator ::testing::Action<F>() const {\
11266 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
11267 p6, p7));\
11268 }\
11269 p0##_type p0;\
11270 p1##_type p1;\
11271 p2##_type p2;\
11272 p3##_type p3;\
11273 p4##_type p4;\
11274 p5##_type p5;\
11275 p6##_type p6;\
11276 p7##_type p7;\
11277 private:\
11278 GTEST_DISALLOW_ASSIGN_(name##ActionP8);\
11279 };\
11280 template <typename p0##_type, typename p1##_type, typename p2##_type, \
11281 typename p3##_type, typename p4##_type, typename p5##_type, \
11282 typename p6##_type, typename p7##_type>\
11283 inline name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, \
11284 p4##_type, p5##_type, p6##_type, p7##_type> name(p0##_type p0, \
11285 p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
11286 p6##_type p6, p7##_type p7) {\
11287 return name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, \
11288 p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, p3, p4, p5, \
11289 p6, p7);\
11290 }\
11291 template <typename p0##_type, typename p1##_type, typename p2##_type, \
11292 typename p3##_type, typename p4##_type, typename p5##_type, \
11293 typename p6##_type, typename p7##_type>\
11294 template <typename F>\
11295 template <typename arg0_type, typename arg1_type, typename arg2_type, \
11296 typename arg3_type, typename arg4_type, typename arg5_type, \
11297 typename arg6_type, typename arg7_type, typename arg8_type, \
11298 typename arg9_type>\
11299 typename ::testing::internal::Function<F>::Result\
11300 name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
11301 p5##_type, p6##_type, \
11302 p7##_type>::gmock_Impl<F>::gmock_PerformImpl(\
11303 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
11304
11305#define ACTION_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8)\
11306 template <typename p0##_type, typename p1##_type, typename p2##_type, \
11307 typename p3##_type, typename p4##_type, typename p5##_type, \
11308 typename p6##_type, typename p7##_type, typename p8##_type>\
11309 class name##ActionP9 {\
11310 public:\
11311 name##ActionP9(p0##_type gmock_p0, p1##_type gmock_p1, \
11312 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
11313 p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080011314 p8##_type gmock_p8) : p0(::std::forward<p0##_type>(gmock_p0)), \
11315 p1(::std::forward<p1##_type>(gmock_p1)), \
11316 p2(::std::forward<p2##_type>(gmock_p2)), \
11317 p3(::std::forward<p3##_type>(gmock_p3)), \
11318 p4(::std::forward<p4##_type>(gmock_p4)), \
11319 p5(::std::forward<p5##_type>(gmock_p5)), \
11320 p6(::std::forward<p6##_type>(gmock_p6)), \
11321 p7(::std::forward<p7##_type>(gmock_p7)), \
11322 p8(::std::forward<p8##_type>(gmock_p8)) {}\
Austin Schuh70cc9552019-01-21 19:46:48 -080011323 template <typename F>\
11324 class gmock_Impl : public ::testing::ActionInterface<F> {\
11325 public:\
11326 typedef F function_type;\
11327 typedef typename ::testing::internal::Function<F>::Result return_type;\
11328 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
11329 args_type;\
11330 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
11331 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
11332 p6##_type gmock_p6, p7##_type gmock_p7, \
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080011333 p8##_type gmock_p8) : p0(::std::forward<p0##_type>(gmock_p0)), \
11334 p1(::std::forward<p1##_type>(gmock_p1)), \
11335 p2(::std::forward<p2##_type>(gmock_p2)), \
11336 p3(::std::forward<p3##_type>(gmock_p3)), \
11337 p4(::std::forward<p4##_type>(gmock_p4)), \
11338 p5(::std::forward<p5##_type>(gmock_p5)), \
11339 p6(::std::forward<p6##_type>(gmock_p6)), \
11340 p7(::std::forward<p7##_type>(gmock_p7)), \
11341 p8(::std::forward<p8##_type>(gmock_p8)) {}\
Austin Schuh70cc9552019-01-21 19:46:48 -080011342 virtual return_type Perform(const args_type& args) {\
11343 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
11344 Perform(this, args);\
11345 }\
11346 template <typename arg0_type, typename arg1_type, typename arg2_type, \
11347 typename arg3_type, typename arg4_type, typename arg5_type, \
11348 typename arg6_type, typename arg7_type, typename arg8_type, \
11349 typename arg9_type>\
11350 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
11351 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
11352 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
11353 arg9_type arg9) const;\
11354 p0##_type p0;\
11355 p1##_type p1;\
11356 p2##_type p2;\
11357 p3##_type p3;\
11358 p4##_type p4;\
11359 p5##_type p5;\
11360 p6##_type p6;\
11361 p7##_type p7;\
11362 p8##_type p8;\
11363 private:\
11364 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
11365 };\
11366 template <typename F> operator ::testing::Action<F>() const {\
11367 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
11368 p6, p7, p8));\
11369 }\
11370 p0##_type p0;\
11371 p1##_type p1;\
11372 p2##_type p2;\
11373 p3##_type p3;\
11374 p4##_type p4;\
11375 p5##_type p5;\
11376 p6##_type p6;\
11377 p7##_type p7;\
11378 p8##_type p8;\
11379 private:\
11380 GTEST_DISALLOW_ASSIGN_(name##ActionP9);\
11381 };\
11382 template <typename p0##_type, typename p1##_type, typename p2##_type, \
11383 typename p3##_type, typename p4##_type, typename p5##_type, \
11384 typename p6##_type, typename p7##_type, typename p8##_type>\
11385 inline name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, \
11386 p4##_type, p5##_type, p6##_type, p7##_type, \
11387 p8##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
11388 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, \
11389 p8##_type p8) {\
11390 return name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, \
11391 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type>(p0, p1, p2, \
11392 p3, p4, p5, p6, p7, p8);\
11393 }\
11394 template <typename p0##_type, typename p1##_type, typename p2##_type, \
11395 typename p3##_type, typename p4##_type, typename p5##_type, \
11396 typename p6##_type, typename p7##_type, typename p8##_type>\
11397 template <typename F>\
11398 template <typename arg0_type, typename arg1_type, typename arg2_type, \
11399 typename arg3_type, typename arg4_type, typename arg5_type, \
11400 typename arg6_type, typename arg7_type, typename arg8_type, \
11401 typename arg9_type>\
11402 typename ::testing::internal::Function<F>::Result\
11403 name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
11404 p5##_type, p6##_type, p7##_type, \
11405 p8##_type>::gmock_Impl<F>::gmock_PerformImpl(\
11406 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
11407
11408#define ACTION_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)\
11409 template <typename p0##_type, typename p1##_type, typename p2##_type, \
11410 typename p3##_type, typename p4##_type, typename p5##_type, \
11411 typename p6##_type, typename p7##_type, typename p8##_type, \
11412 typename p9##_type>\
11413 class name##ActionP10 {\
11414 public:\
11415 name##ActionP10(p0##_type gmock_p0, p1##_type gmock_p1, \
11416 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
11417 p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080011418 p8##_type gmock_p8, \
11419 p9##_type gmock_p9) : p0(::std::forward<p0##_type>(gmock_p0)), \
11420 p1(::std::forward<p1##_type>(gmock_p1)), \
11421 p2(::std::forward<p2##_type>(gmock_p2)), \
11422 p3(::std::forward<p3##_type>(gmock_p3)), \
11423 p4(::std::forward<p4##_type>(gmock_p4)), \
11424 p5(::std::forward<p5##_type>(gmock_p5)), \
11425 p6(::std::forward<p6##_type>(gmock_p6)), \
11426 p7(::std::forward<p7##_type>(gmock_p7)), \
11427 p8(::std::forward<p8##_type>(gmock_p8)), \
11428 p9(::std::forward<p9##_type>(gmock_p9)) {}\
Austin Schuh70cc9552019-01-21 19:46:48 -080011429 template <typename F>\
11430 class gmock_Impl : public ::testing::ActionInterface<F> {\
11431 public:\
11432 typedef F function_type;\
11433 typedef typename ::testing::internal::Function<F>::Result return_type;\
11434 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
11435 args_type;\
11436 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
11437 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
11438 p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080011439 p9##_type gmock_p9) : p0(::std::forward<p0##_type>(gmock_p0)), \
11440 p1(::std::forward<p1##_type>(gmock_p1)), \
11441 p2(::std::forward<p2##_type>(gmock_p2)), \
11442 p3(::std::forward<p3##_type>(gmock_p3)), \
11443 p4(::std::forward<p4##_type>(gmock_p4)), \
11444 p5(::std::forward<p5##_type>(gmock_p5)), \
11445 p6(::std::forward<p6##_type>(gmock_p6)), \
11446 p7(::std::forward<p7##_type>(gmock_p7)), \
11447 p8(::std::forward<p8##_type>(gmock_p8)), \
11448 p9(::std::forward<p9##_type>(gmock_p9)) {}\
Austin Schuh70cc9552019-01-21 19:46:48 -080011449 virtual return_type Perform(const args_type& args) {\
11450 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
11451 Perform(this, args);\
11452 }\
11453 template <typename arg0_type, typename arg1_type, typename arg2_type, \
11454 typename arg3_type, typename arg4_type, typename arg5_type, \
11455 typename arg6_type, typename arg7_type, typename arg8_type, \
11456 typename arg9_type>\
11457 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
11458 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
11459 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
11460 arg9_type arg9) const;\
11461 p0##_type p0;\
11462 p1##_type p1;\
11463 p2##_type p2;\
11464 p3##_type p3;\
11465 p4##_type p4;\
11466 p5##_type p5;\
11467 p6##_type p6;\
11468 p7##_type p7;\
11469 p8##_type p8;\
11470 p9##_type p9;\
11471 private:\
11472 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
11473 };\
11474 template <typename F> operator ::testing::Action<F>() const {\
11475 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
11476 p6, p7, p8, p9));\
11477 }\
11478 p0##_type p0;\
11479 p1##_type p1;\
11480 p2##_type p2;\
11481 p3##_type p3;\
11482 p4##_type p4;\
11483 p5##_type p5;\
11484 p6##_type p6;\
11485 p7##_type p7;\
11486 p8##_type p8;\
11487 p9##_type p9;\
11488 private:\
11489 GTEST_DISALLOW_ASSIGN_(name##ActionP10);\
11490 };\
11491 template <typename p0##_type, typename p1##_type, typename p2##_type, \
11492 typename p3##_type, typename p4##_type, typename p5##_type, \
11493 typename p6##_type, typename p7##_type, typename p8##_type, \
11494 typename p9##_type>\
11495 inline name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, \
11496 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
11497 p9##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
11498 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \
11499 p9##_type p9) {\
11500 return name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, \
11501 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, p9##_type>(p0, \
11502 p1, p2, p3, p4, p5, p6, p7, p8, p9);\
11503 }\
11504 template <typename p0##_type, typename p1##_type, typename p2##_type, \
11505 typename p3##_type, typename p4##_type, typename p5##_type, \
11506 typename p6##_type, typename p7##_type, typename p8##_type, \
11507 typename p9##_type>\
11508 template <typename F>\
11509 template <typename arg0_type, typename arg1_type, typename arg2_type, \
11510 typename arg3_type, typename arg4_type, typename arg5_type, \
11511 typename arg6_type, typename arg7_type, typename arg8_type, \
11512 typename arg9_type>\
11513 typename ::testing::internal::Function<F>::Result\
11514 name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
11515 p5##_type, p6##_type, p7##_type, p8##_type, \
11516 p9##_type>::gmock_Impl<F>::gmock_PerformImpl(\
11517 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
11518
11519namespace testing {
11520
11521
11522// The ACTION*() macros trigger warning C4100 (unreferenced formal
11523// parameter) in MSVC with -W4. Unfortunately they cannot be fixed in
11524// the macro definition, as the warnings are generated when the macro
11525// is expanded and macro expansion cannot contain #pragma. Therefore
11526// we suppress them here.
11527#ifdef _MSC_VER
11528# pragma warning(push)
11529# pragma warning(disable:4100)
11530#endif
11531
11532// Various overloads for InvokeArgument<N>().
11533//
11534// The InvokeArgument<N>(a1, a2, ..., a_k) action invokes the N-th
11535// (0-based) argument, which must be a k-ary callable, of the mock
11536// function, with arguments a1, a2, ..., a_k.
11537//
11538// Notes:
11539//
11540// 1. The arguments are passed by value by default. If you need to
11541// pass an argument by reference, wrap it inside ByRef(). For
11542// example,
11543//
11544// InvokeArgument<1>(5, string("Hello"), ByRef(foo))
11545//
11546// passes 5 and string("Hello") by value, and passes foo by
11547// reference.
11548//
11549// 2. If the callable takes an argument by reference but ByRef() is
11550// not used, it will receive the reference to a copy of the value,
11551// instead of the original value. For example, when the 0-th
11552// argument of the mock function takes a const string&, the action
11553//
11554// InvokeArgument<0>(string("Hello"))
11555//
11556// makes a copy of the temporary string("Hello") object and passes a
11557// reference of the copy, instead of the original temporary object,
11558// to the callable. This makes it easy for a user to define an
11559// InvokeArgument action from temporary values and have it performed
11560// later.
11561
11562namespace internal {
11563namespace invoke_argument {
11564
11565// Appears in InvokeArgumentAdl's argument list to help avoid
11566// accidental calls to user functions of the same name.
11567struct AdlTag {};
11568
11569// InvokeArgumentAdl - a helper for InvokeArgument.
11570// The basic overloads are provided here for generic functors.
11571// Overloads for other custom-callables are provided in the
11572// internal/custom/callback-actions.h header.
11573
11574template <typename R, typename F>
11575R InvokeArgumentAdl(AdlTag, F f) {
11576 return f();
11577}
11578template <typename R, typename F, typename A1>
11579R InvokeArgumentAdl(AdlTag, F f, A1 a1) {
11580 return f(a1);
11581}
11582template <typename R, typename F, typename A1, typename A2>
11583R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2) {
11584 return f(a1, a2);
11585}
11586template <typename R, typename F, typename A1, typename A2, typename A3>
11587R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3) {
11588 return f(a1, a2, a3);
11589}
11590template <typename R, typename F, typename A1, typename A2, typename A3,
11591 typename A4>
11592R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4) {
11593 return f(a1, a2, a3, a4);
11594}
11595template <typename R, typename F, typename A1, typename A2, typename A3,
11596 typename A4, typename A5>
11597R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) {
11598 return f(a1, a2, a3, a4, a5);
11599}
11600template <typename R, typename F, typename A1, typename A2, typename A3,
11601 typename A4, typename A5, typename A6>
11602R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) {
11603 return f(a1, a2, a3, a4, a5, a6);
11604}
11605template <typename R, typename F, typename A1, typename A2, typename A3,
11606 typename A4, typename A5, typename A6, typename A7>
11607R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
11608 A7 a7) {
11609 return f(a1, a2, a3, a4, a5, a6, a7);
11610}
11611template <typename R, typename F, typename A1, typename A2, typename A3,
11612 typename A4, typename A5, typename A6, typename A7, typename A8>
11613R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
11614 A7 a7, A8 a8) {
11615 return f(a1, a2, a3, a4, a5, a6, a7, a8);
11616}
11617template <typename R, typename F, typename A1, typename A2, typename A3,
11618 typename A4, typename A5, typename A6, typename A7, typename A8,
11619 typename A9>
11620R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
11621 A7 a7, A8 a8, A9 a9) {
11622 return f(a1, a2, a3, a4, a5, a6, a7, a8, a9);
11623}
11624template <typename R, typename F, typename A1, typename A2, typename A3,
11625 typename A4, typename A5, typename A6, typename A7, typename A8,
11626 typename A9, typename A10>
11627R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
11628 A7 a7, A8 a8, A9 a9, A10 a10) {
11629 return f(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
11630}
11631} // namespace invoke_argument
11632} // namespace internal
11633
11634ACTION_TEMPLATE(InvokeArgument,
11635 HAS_1_TEMPLATE_PARAMS(int, k),
11636 AND_0_VALUE_PARAMS()) {
11637 using internal::invoke_argument::InvokeArgumentAdl;
11638 return InvokeArgumentAdl<return_type>(
11639 internal::invoke_argument::AdlTag(),
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080011640 ::std::get<k>(args));
Austin Schuh70cc9552019-01-21 19:46:48 -080011641}
11642
11643ACTION_TEMPLATE(InvokeArgument,
11644 HAS_1_TEMPLATE_PARAMS(int, k),
11645 AND_1_VALUE_PARAMS(p0)) {
11646 using internal::invoke_argument::InvokeArgumentAdl;
11647 return InvokeArgumentAdl<return_type>(
11648 internal::invoke_argument::AdlTag(),
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080011649 ::std::get<k>(args), p0);
Austin Schuh70cc9552019-01-21 19:46:48 -080011650}
11651
11652ACTION_TEMPLATE(InvokeArgument,
11653 HAS_1_TEMPLATE_PARAMS(int, k),
11654 AND_2_VALUE_PARAMS(p0, p1)) {
11655 using internal::invoke_argument::InvokeArgumentAdl;
11656 return InvokeArgumentAdl<return_type>(
11657 internal::invoke_argument::AdlTag(),
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080011658 ::std::get<k>(args), p0, p1);
Austin Schuh70cc9552019-01-21 19:46:48 -080011659}
11660
11661ACTION_TEMPLATE(InvokeArgument,
11662 HAS_1_TEMPLATE_PARAMS(int, k),
11663 AND_3_VALUE_PARAMS(p0, p1, p2)) {
11664 using internal::invoke_argument::InvokeArgumentAdl;
11665 return InvokeArgumentAdl<return_type>(
11666 internal::invoke_argument::AdlTag(),
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080011667 ::std::get<k>(args), p0, p1, p2);
Austin Schuh70cc9552019-01-21 19:46:48 -080011668}
11669
11670ACTION_TEMPLATE(InvokeArgument,
11671 HAS_1_TEMPLATE_PARAMS(int, k),
11672 AND_4_VALUE_PARAMS(p0, p1, p2, p3)) {
11673 using internal::invoke_argument::InvokeArgumentAdl;
11674 return InvokeArgumentAdl<return_type>(
11675 internal::invoke_argument::AdlTag(),
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080011676 ::std::get<k>(args), p0, p1, p2, p3);
Austin Schuh70cc9552019-01-21 19:46:48 -080011677}
11678
11679ACTION_TEMPLATE(InvokeArgument,
11680 HAS_1_TEMPLATE_PARAMS(int, k),
11681 AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)) {
11682 using internal::invoke_argument::InvokeArgumentAdl;
11683 return InvokeArgumentAdl<return_type>(
11684 internal::invoke_argument::AdlTag(),
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080011685 ::std::get<k>(args), p0, p1, p2, p3, p4);
Austin Schuh70cc9552019-01-21 19:46:48 -080011686}
11687
11688ACTION_TEMPLATE(InvokeArgument,
11689 HAS_1_TEMPLATE_PARAMS(int, k),
11690 AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)) {
11691 using internal::invoke_argument::InvokeArgumentAdl;
11692 return InvokeArgumentAdl<return_type>(
11693 internal::invoke_argument::AdlTag(),
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080011694 ::std::get<k>(args), p0, p1, p2, p3, p4, p5);
Austin Schuh70cc9552019-01-21 19:46:48 -080011695}
11696
11697ACTION_TEMPLATE(InvokeArgument,
11698 HAS_1_TEMPLATE_PARAMS(int, k),
11699 AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)) {
11700 using internal::invoke_argument::InvokeArgumentAdl;
11701 return InvokeArgumentAdl<return_type>(
11702 internal::invoke_argument::AdlTag(),
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080011703 ::std::get<k>(args), p0, p1, p2, p3, p4, p5, p6);
Austin Schuh70cc9552019-01-21 19:46:48 -080011704}
11705
11706ACTION_TEMPLATE(InvokeArgument,
11707 HAS_1_TEMPLATE_PARAMS(int, k),
11708 AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)) {
11709 using internal::invoke_argument::InvokeArgumentAdl;
11710 return InvokeArgumentAdl<return_type>(
11711 internal::invoke_argument::AdlTag(),
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080011712 ::std::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7);
Austin Schuh70cc9552019-01-21 19:46:48 -080011713}
11714
11715ACTION_TEMPLATE(InvokeArgument,
11716 HAS_1_TEMPLATE_PARAMS(int, k),
11717 AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8)) {
11718 using internal::invoke_argument::InvokeArgumentAdl;
11719 return InvokeArgumentAdl<return_type>(
11720 internal::invoke_argument::AdlTag(),
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080011721 ::std::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7, p8);
Austin Schuh70cc9552019-01-21 19:46:48 -080011722}
11723
11724ACTION_TEMPLATE(InvokeArgument,
11725 HAS_1_TEMPLATE_PARAMS(int, k),
11726 AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)) {
11727 using internal::invoke_argument::InvokeArgumentAdl;
11728 return InvokeArgumentAdl<return_type>(
11729 internal::invoke_argument::AdlTag(),
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080011730 ::std::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7, p8, p9);
Austin Schuh70cc9552019-01-21 19:46:48 -080011731}
11732
11733// Various overloads for ReturnNew<T>().
11734//
11735// The ReturnNew<T>(a1, a2, ..., a_k) action returns a pointer to a new
11736// instance of type T, constructed on the heap with constructor arguments
11737// a1, a2, ..., and a_k. The caller assumes ownership of the returned value.
11738ACTION_TEMPLATE(ReturnNew,
11739 HAS_1_TEMPLATE_PARAMS(typename, T),
11740 AND_0_VALUE_PARAMS()) {
11741 return new T();
11742}
11743
11744ACTION_TEMPLATE(ReturnNew,
11745 HAS_1_TEMPLATE_PARAMS(typename, T),
11746 AND_1_VALUE_PARAMS(p0)) {
11747 return new T(p0);
11748}
11749
11750ACTION_TEMPLATE(ReturnNew,
11751 HAS_1_TEMPLATE_PARAMS(typename, T),
11752 AND_2_VALUE_PARAMS(p0, p1)) {
11753 return new T(p0, p1);
11754}
11755
11756ACTION_TEMPLATE(ReturnNew,
11757 HAS_1_TEMPLATE_PARAMS(typename, T),
11758 AND_3_VALUE_PARAMS(p0, p1, p2)) {
11759 return new T(p0, p1, p2);
11760}
11761
11762ACTION_TEMPLATE(ReturnNew,
11763 HAS_1_TEMPLATE_PARAMS(typename, T),
11764 AND_4_VALUE_PARAMS(p0, p1, p2, p3)) {
11765 return new T(p0, p1, p2, p3);
11766}
11767
11768ACTION_TEMPLATE(ReturnNew,
11769 HAS_1_TEMPLATE_PARAMS(typename, T),
11770 AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)) {
11771 return new T(p0, p1, p2, p3, p4);
11772}
11773
11774ACTION_TEMPLATE(ReturnNew,
11775 HAS_1_TEMPLATE_PARAMS(typename, T),
11776 AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)) {
11777 return new T(p0, p1, p2, p3, p4, p5);
11778}
11779
11780ACTION_TEMPLATE(ReturnNew,
11781 HAS_1_TEMPLATE_PARAMS(typename, T),
11782 AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)) {
11783 return new T(p0, p1, p2, p3, p4, p5, p6);
11784}
11785
11786ACTION_TEMPLATE(ReturnNew,
11787 HAS_1_TEMPLATE_PARAMS(typename, T),
11788 AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)) {
11789 return new T(p0, p1, p2, p3, p4, p5, p6, p7);
11790}
11791
11792ACTION_TEMPLATE(ReturnNew,
11793 HAS_1_TEMPLATE_PARAMS(typename, T),
11794 AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8)) {
11795 return new T(p0, p1, p2, p3, p4, p5, p6, p7, p8);
11796}
11797
11798ACTION_TEMPLATE(ReturnNew,
11799 HAS_1_TEMPLATE_PARAMS(typename, T),
11800 AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)) {
11801 return new T(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9);
11802}
11803
11804#ifdef _MSC_VER
11805# pragma warning(pop)
11806#endif
11807
11808} // namespace testing
11809
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080011810// Include any custom callback actions added by the local installation.
Austin Schuh70cc9552019-01-21 19:46:48 -080011811// We must include this header at the end to make sure it can use the
11812// declarations from this file.
11813// This file was GENERATED by command:
11814// pump.py gmock-generated-actions.h.pump
11815// DO NOT EDIT BY HAND!!!
11816
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080011817// GOOGLETEST_CM0002 DO NOT DELETE
11818
Austin Schuh70cc9552019-01-21 19:46:48 -080011819#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
11820#define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
11821
11822#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
11823
11824#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
11825// This file was GENERATED by command:
Austin Schuh70cc9552019-01-21 19:46:48 -080011826// pump.py gmock-generated-matchers.h.pump
11827// DO NOT EDIT BY HAND!!!
11828
11829// Copyright 2008, Google Inc.
11830// All rights reserved.
11831//
11832// Redistribution and use in source and binary forms, with or without
11833// modification, are permitted provided that the following conditions are
11834// met:
11835//
11836// * Redistributions of source code must retain the above copyright
11837// notice, this list of conditions and the following disclaimer.
11838// * Redistributions in binary form must reproduce the above
11839// copyright notice, this list of conditions and the following disclaimer
11840// in the documentation and/or other materials provided with the
11841// distribution.
11842// * Neither the name of Google Inc. nor the names of its
11843// contributors may be used to endorse or promote products derived from
11844// this software without specific prior written permission.
11845//
11846// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
11847// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
11848// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
11849// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
11850// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
11851// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11852// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11853// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11854// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
11855// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
11856// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11857
11858// Google Mock - a framework for writing C++ mock classes.
11859//
11860// This file implements some commonly used variadic matchers.
11861
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080011862// GOOGLETEST_CM0002 DO NOT DELETE
11863
Austin Schuh70cc9552019-01-21 19:46:48 -080011864#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
11865#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
11866
11867#include <iterator>
11868#include <sstream>
11869#include <string>
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080011870#include <utility>
Austin Schuh70cc9552019-01-21 19:46:48 -080011871#include <vector>
11872
Austin Schuh70cc9552019-01-21 19:46:48 -080011873// The MATCHER* family of macros can be used in a namespace scope to
11874// define custom matchers easily.
11875//
11876// Basic Usage
11877// ===========
11878//
11879// The syntax
11880//
11881// MATCHER(name, description_string) { statements; }
11882//
11883// defines a matcher with the given name that executes the statements,
11884// which must return a bool to indicate if the match succeeds. Inside
11885// the statements, you can refer to the value being matched by 'arg',
11886// and refer to its type by 'arg_type'.
11887//
11888// The description string documents what the matcher does, and is used
11889// to generate the failure message when the match fails. Since a
11890// MATCHER() is usually defined in a header file shared by multiple
11891// C++ source files, we require the description to be a C-string
11892// literal to avoid possible side effects. It can be empty, in which
11893// case we'll use the sequence of words in the matcher name as the
11894// description.
11895//
11896// For example:
11897//
11898// MATCHER(IsEven, "") { return (arg % 2) == 0; }
11899//
11900// allows you to write
11901//
11902// // Expects mock_foo.Bar(n) to be called where n is even.
11903// EXPECT_CALL(mock_foo, Bar(IsEven()));
11904//
11905// or,
11906//
11907// // Verifies that the value of some_expression is even.
11908// EXPECT_THAT(some_expression, IsEven());
11909//
11910// If the above assertion fails, it will print something like:
11911//
11912// Value of: some_expression
11913// Expected: is even
11914// Actual: 7
11915//
11916// where the description "is even" is automatically calculated from the
11917// matcher name IsEven.
11918//
11919// Argument Type
11920// =============
11921//
11922// Note that the type of the value being matched (arg_type) is
11923// determined by the context in which you use the matcher and is
11924// supplied to you by the compiler, so you don't need to worry about
11925// declaring it (nor can you). This allows the matcher to be
11926// polymorphic. For example, IsEven() can be used to match any type
11927// where the value of "(arg % 2) == 0" can be implicitly converted to
11928// a bool. In the "Bar(IsEven())" example above, if method Bar()
11929// takes an int, 'arg_type' will be int; if it takes an unsigned long,
11930// 'arg_type' will be unsigned long; and so on.
11931//
11932// Parameterizing Matchers
11933// =======================
11934//
11935// Sometimes you'll want to parameterize the matcher. For that you
11936// can use another macro:
11937//
11938// MATCHER_P(name, param_name, description_string) { statements; }
11939//
11940// For example:
11941//
11942// MATCHER_P(HasAbsoluteValue, value, "") { return abs(arg) == value; }
11943//
11944// will allow you to write:
11945//
11946// EXPECT_THAT(Blah("a"), HasAbsoluteValue(n));
11947//
11948// which may lead to this message (assuming n is 10):
11949//
11950// Value of: Blah("a")
11951// Expected: has absolute value 10
11952// Actual: -9
11953//
11954// Note that both the matcher description and its parameter are
11955// printed, making the message human-friendly.
11956//
11957// In the matcher definition body, you can write 'foo_type' to
11958// reference the type of a parameter named 'foo'. For example, in the
11959// body of MATCHER_P(HasAbsoluteValue, value) above, you can write
11960// 'value_type' to refer to the type of 'value'.
11961//
11962// We also provide MATCHER_P2, MATCHER_P3, ..., up to MATCHER_P10 to
11963// support multi-parameter matchers.
11964//
11965// Describing Parameterized Matchers
11966// =================================
11967//
11968// The last argument to MATCHER*() is a string-typed expression. The
11969// expression can reference all of the matcher's parameters and a
11970// special bool-typed variable named 'negation'. When 'negation' is
11971// false, the expression should evaluate to the matcher's description;
11972// otherwise it should evaluate to the description of the negation of
11973// the matcher. For example,
11974//
11975// using testing::PrintToString;
11976//
11977// MATCHER_P2(InClosedRange, low, hi,
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080011978// std::string(negation ? "is not" : "is") + " in range [" +
Austin Schuh70cc9552019-01-21 19:46:48 -080011979// PrintToString(low) + ", " + PrintToString(hi) + "]") {
11980// return low <= arg && arg <= hi;
11981// }
11982// ...
11983// EXPECT_THAT(3, InClosedRange(4, 6));
11984// EXPECT_THAT(3, Not(InClosedRange(2, 4)));
11985//
11986// would generate two failures that contain the text:
11987//
11988// Expected: is in range [4, 6]
11989// ...
11990// Expected: is not in range [2, 4]
11991//
11992// If you specify "" as the description, the failure message will
11993// contain the sequence of words in the matcher name followed by the
11994// parameter values printed as a tuple. For example,
11995//
11996// MATCHER_P2(InClosedRange, low, hi, "") { ... }
11997// ...
11998// EXPECT_THAT(3, InClosedRange(4, 6));
11999// EXPECT_THAT(3, Not(InClosedRange(2, 4)));
12000//
12001// would generate two failures that contain the text:
12002//
12003// Expected: in closed range (4, 6)
12004// ...
12005// Expected: not (in closed range (2, 4))
12006//
12007// Types of Matcher Parameters
12008// ===========================
12009//
12010// For the purpose of typing, you can view
12011//
12012// MATCHER_Pk(Foo, p1, ..., pk, description_string) { ... }
12013//
12014// as shorthand for
12015//
12016// template <typename p1_type, ..., typename pk_type>
12017// FooMatcherPk<p1_type, ..., pk_type>
12018// Foo(p1_type p1, ..., pk_type pk) { ... }
12019//
12020// When you write Foo(v1, ..., vk), the compiler infers the types of
12021// the parameters v1, ..., and vk for you. If you are not happy with
12022// the result of the type inference, you can specify the types by
12023// explicitly instantiating the template, as in Foo<long, bool>(5,
12024// false). As said earlier, you don't get to (or need to) specify
12025// 'arg_type' as that's determined by the context in which the matcher
12026// is used. You can assign the result of expression Foo(p1, ..., pk)
12027// to a variable of type FooMatcherPk<p1_type, ..., pk_type>. This
12028// can be useful when composing matchers.
12029//
12030// While you can instantiate a matcher template with reference types,
12031// passing the parameters by pointer usually makes your code more
12032// readable. If, however, you still want to pass a parameter by
12033// reference, be aware that in the failure message generated by the
12034// matcher you will see the value of the referenced object but not its
12035// address.
12036//
12037// Explaining Match Results
12038// ========================
12039//
12040// Sometimes the matcher description alone isn't enough to explain why
12041// the match has failed or succeeded. For example, when expecting a
12042// long string, it can be very helpful to also print the diff between
12043// the expected string and the actual one. To achieve that, you can
12044// optionally stream additional information to a special variable
12045// named result_listener, whose type is a pointer to class
12046// MatchResultListener:
12047//
12048// MATCHER_P(EqualsLongString, str, "") {
12049// if (arg == str) return true;
12050//
12051// *result_listener << "the difference: "
12052/// << DiffStrings(str, arg);
12053// return false;
12054// }
12055//
12056// Overloading Matchers
12057// ====================
12058//
12059// You can overload matchers with different numbers of parameters:
12060//
12061// MATCHER_P(Blah, a, description_string1) { ... }
12062// MATCHER_P2(Blah, a, b, description_string2) { ... }
12063//
12064// Caveats
12065// =======
12066//
12067// When defining a new matcher, you should also consider implementing
12068// MatcherInterface or using MakePolymorphicMatcher(). These
12069// approaches require more work than the MATCHER* macros, but also
12070// give you more control on the types of the value being matched and
12071// the matcher parameters, which may leads to better compiler error
12072// messages when the matcher is used wrong. They also allow
12073// overloading matchers based on parameter types (as opposed to just
12074// based on the number of parameters).
12075//
12076// MATCHER*() can only be used in a namespace scope. The reason is
12077// that C++ doesn't yet allow function-local types to be used to
12078// instantiate templates. The up-coming C++0x standard will fix this.
12079// Once that's done, we'll consider supporting using MATCHER*() inside
12080// a function.
12081//
12082// More Information
12083// ================
12084//
12085// To learn more about using these macros, please search for 'MATCHER'
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012086// on
12087// https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md
Austin Schuh70cc9552019-01-21 19:46:48 -080012088
12089#define MATCHER(name, description)\
12090 class name##Matcher {\
12091 public:\
12092 template <typename arg_type>\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012093 class gmock_Impl : public ::testing::MatcherInterface<\
12094 GTEST_REFERENCE_TO_CONST_(arg_type)> {\
Austin Schuh70cc9552019-01-21 19:46:48 -080012095 public:\
12096 gmock_Impl()\
12097 {}\
12098 virtual bool MatchAndExplain(\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012099 GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
12100 ::testing::MatchResultListener* result_listener) const;\
Austin Schuh70cc9552019-01-21 19:46:48 -080012101 virtual void DescribeTo(::std::ostream* gmock_os) const {\
12102 *gmock_os << FormatDescription(false);\
12103 }\
12104 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
12105 *gmock_os << FormatDescription(true);\
12106 }\
12107 private:\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012108 ::std::string FormatDescription(bool negation) const {\
12109 ::std::string gmock_description = (description);\
12110 if (!gmock_description.empty()) {\
Austin Schuh70cc9552019-01-21 19:46:48 -080012111 return gmock_description;\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012112 }\
Austin Schuh70cc9552019-01-21 19:46:48 -080012113 return ::testing::internal::FormatMatcherDescription(\
12114 negation, #name, \
12115 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012116 ::std::tuple<>()));\
Austin Schuh70cc9552019-01-21 19:46:48 -080012117 }\
Austin Schuh70cc9552019-01-21 19:46:48 -080012118 };\
12119 template <typename arg_type>\
12120 operator ::testing::Matcher<arg_type>() const {\
12121 return ::testing::Matcher<arg_type>(\
12122 new gmock_Impl<arg_type>());\
12123 }\
12124 name##Matcher() {\
12125 }\
12126 private:\
Austin Schuh70cc9552019-01-21 19:46:48 -080012127 };\
12128 inline name##Matcher name() {\
12129 return name##Matcher();\
12130 }\
12131 template <typename arg_type>\
12132 bool name##Matcher::gmock_Impl<arg_type>::MatchAndExplain(\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012133 GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
Austin Schuh70cc9552019-01-21 19:46:48 -080012134 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
12135 const
12136
12137#define MATCHER_P(name, p0, description)\
12138 template <typename p0##_type>\
12139 class name##MatcherP {\
12140 public:\
12141 template <typename arg_type>\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012142 class gmock_Impl : public ::testing::MatcherInterface<\
12143 GTEST_REFERENCE_TO_CONST_(arg_type)> {\
Austin Schuh70cc9552019-01-21 19:46:48 -080012144 public:\
12145 explicit gmock_Impl(p0##_type gmock_p0)\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012146 : p0(::std::move(gmock_p0)) {}\
Austin Schuh70cc9552019-01-21 19:46:48 -080012147 virtual bool MatchAndExplain(\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012148 GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
12149 ::testing::MatchResultListener* result_listener) const;\
Austin Schuh70cc9552019-01-21 19:46:48 -080012150 virtual void DescribeTo(::std::ostream* gmock_os) const {\
12151 *gmock_os << FormatDescription(false);\
12152 }\
12153 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
12154 *gmock_os << FormatDescription(true);\
12155 }\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012156 p0##_type const p0;\
Austin Schuh70cc9552019-01-21 19:46:48 -080012157 private:\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012158 ::std::string FormatDescription(bool negation) const {\
12159 ::std::string gmock_description = (description);\
12160 if (!gmock_description.empty()) {\
Austin Schuh70cc9552019-01-21 19:46:48 -080012161 return gmock_description;\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012162 }\
Austin Schuh70cc9552019-01-21 19:46:48 -080012163 return ::testing::internal::FormatMatcherDescription(\
12164 negation, #name, \
12165 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012166 ::std::tuple<p0##_type>(p0)));\
Austin Schuh70cc9552019-01-21 19:46:48 -080012167 }\
Austin Schuh70cc9552019-01-21 19:46:48 -080012168 };\
12169 template <typename arg_type>\
12170 operator ::testing::Matcher<arg_type>() const {\
12171 return ::testing::Matcher<arg_type>(\
12172 new gmock_Impl<arg_type>(p0));\
12173 }\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012174 explicit name##MatcherP(p0##_type gmock_p0) : p0(::std::move(gmock_p0)) {\
Austin Schuh70cc9552019-01-21 19:46:48 -080012175 }\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012176 p0##_type const p0;\
Austin Schuh70cc9552019-01-21 19:46:48 -080012177 private:\
Austin Schuh70cc9552019-01-21 19:46:48 -080012178 };\
12179 template <typename p0##_type>\
12180 inline name##MatcherP<p0##_type> name(p0##_type p0) {\
12181 return name##MatcherP<p0##_type>(p0);\
12182 }\
12183 template <typename p0##_type>\
12184 template <typename arg_type>\
12185 bool name##MatcherP<p0##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012186 GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
Austin Schuh70cc9552019-01-21 19:46:48 -080012187 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
12188 const
12189
12190#define MATCHER_P2(name, p0, p1, description)\
12191 template <typename p0##_type, typename p1##_type>\
12192 class name##MatcherP2 {\
12193 public:\
12194 template <typename arg_type>\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012195 class gmock_Impl : public ::testing::MatcherInterface<\
12196 GTEST_REFERENCE_TO_CONST_(arg_type)> {\
Austin Schuh70cc9552019-01-21 19:46:48 -080012197 public:\
12198 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1)\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012199 : p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)) {}\
Austin Schuh70cc9552019-01-21 19:46:48 -080012200 virtual bool MatchAndExplain(\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012201 GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
12202 ::testing::MatchResultListener* result_listener) const;\
Austin Schuh70cc9552019-01-21 19:46:48 -080012203 virtual void DescribeTo(::std::ostream* gmock_os) const {\
12204 *gmock_os << FormatDescription(false);\
12205 }\
12206 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
12207 *gmock_os << FormatDescription(true);\
12208 }\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012209 p0##_type const p0;\
12210 p1##_type const p1;\
Austin Schuh70cc9552019-01-21 19:46:48 -080012211 private:\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012212 ::std::string FormatDescription(bool negation) const {\
12213 ::std::string gmock_description = (description);\
12214 if (!gmock_description.empty()) {\
Austin Schuh70cc9552019-01-21 19:46:48 -080012215 return gmock_description;\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012216 }\
Austin Schuh70cc9552019-01-21 19:46:48 -080012217 return ::testing::internal::FormatMatcherDescription(\
12218 negation, #name, \
12219 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012220 ::std::tuple<p0##_type, p1##_type>(p0, p1)));\
Austin Schuh70cc9552019-01-21 19:46:48 -080012221 }\
Austin Schuh70cc9552019-01-21 19:46:48 -080012222 };\
12223 template <typename arg_type>\
12224 operator ::testing::Matcher<arg_type>() const {\
12225 return ::testing::Matcher<arg_type>(\
12226 new gmock_Impl<arg_type>(p0, p1));\
12227 }\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012228 name##MatcherP2(p0##_type gmock_p0, \
12229 p1##_type gmock_p1) : p0(::std::move(gmock_p0)), \
12230 p1(::std::move(gmock_p1)) {\
Austin Schuh70cc9552019-01-21 19:46:48 -080012231 }\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012232 p0##_type const p0;\
12233 p1##_type const p1;\
Austin Schuh70cc9552019-01-21 19:46:48 -080012234 private:\
Austin Schuh70cc9552019-01-21 19:46:48 -080012235 };\
12236 template <typename p0##_type, typename p1##_type>\
12237 inline name##MatcherP2<p0##_type, p1##_type> name(p0##_type p0, \
12238 p1##_type p1) {\
12239 return name##MatcherP2<p0##_type, p1##_type>(p0, p1);\
12240 }\
12241 template <typename p0##_type, typename p1##_type>\
12242 template <typename arg_type>\
12243 bool name##MatcherP2<p0##_type, \
12244 p1##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012245 GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
Austin Schuh70cc9552019-01-21 19:46:48 -080012246 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
12247 const
12248
12249#define MATCHER_P3(name, p0, p1, p2, description)\
12250 template <typename p0##_type, typename p1##_type, typename p2##_type>\
12251 class name##MatcherP3 {\
12252 public:\
12253 template <typename arg_type>\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012254 class gmock_Impl : public ::testing::MatcherInterface<\
12255 GTEST_REFERENCE_TO_CONST_(arg_type)> {\
Austin Schuh70cc9552019-01-21 19:46:48 -080012256 public:\
12257 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2)\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012258 : p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)), \
12259 p2(::std::move(gmock_p2)) {}\
Austin Schuh70cc9552019-01-21 19:46:48 -080012260 virtual bool MatchAndExplain(\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012261 GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
12262 ::testing::MatchResultListener* result_listener) const;\
Austin Schuh70cc9552019-01-21 19:46:48 -080012263 virtual void DescribeTo(::std::ostream* gmock_os) const {\
12264 *gmock_os << FormatDescription(false);\
12265 }\
12266 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
12267 *gmock_os << FormatDescription(true);\
12268 }\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012269 p0##_type const p0;\
12270 p1##_type const p1;\
12271 p2##_type const p2;\
Austin Schuh70cc9552019-01-21 19:46:48 -080012272 private:\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012273 ::std::string FormatDescription(bool negation) const {\
12274 ::std::string gmock_description = (description);\
12275 if (!gmock_description.empty()) {\
Austin Schuh70cc9552019-01-21 19:46:48 -080012276 return gmock_description;\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012277 }\
Austin Schuh70cc9552019-01-21 19:46:48 -080012278 return ::testing::internal::FormatMatcherDescription(\
12279 negation, #name, \
12280 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012281 ::std::tuple<p0##_type, p1##_type, p2##_type>(p0, p1, p2)));\
Austin Schuh70cc9552019-01-21 19:46:48 -080012282 }\
Austin Schuh70cc9552019-01-21 19:46:48 -080012283 };\
12284 template <typename arg_type>\
12285 operator ::testing::Matcher<arg_type>() const {\
12286 return ::testing::Matcher<arg_type>(\
12287 new gmock_Impl<arg_type>(p0, p1, p2));\
12288 }\
12289 name##MatcherP3(p0##_type gmock_p0, p1##_type gmock_p1, \
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012290 p2##_type gmock_p2) : p0(::std::move(gmock_p0)), \
12291 p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)) {\
Austin Schuh70cc9552019-01-21 19:46:48 -080012292 }\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012293 p0##_type const p0;\
12294 p1##_type const p1;\
12295 p2##_type const p2;\
Austin Schuh70cc9552019-01-21 19:46:48 -080012296 private:\
Austin Schuh70cc9552019-01-21 19:46:48 -080012297 };\
12298 template <typename p0##_type, typename p1##_type, typename p2##_type>\
12299 inline name##MatcherP3<p0##_type, p1##_type, p2##_type> name(p0##_type p0, \
12300 p1##_type p1, p2##_type p2) {\
12301 return name##MatcherP3<p0##_type, p1##_type, p2##_type>(p0, p1, p2);\
12302 }\
12303 template <typename p0##_type, typename p1##_type, typename p2##_type>\
12304 template <typename arg_type>\
12305 bool name##MatcherP3<p0##_type, p1##_type, \
12306 p2##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012307 GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
Austin Schuh70cc9552019-01-21 19:46:48 -080012308 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
12309 const
12310
12311#define MATCHER_P4(name, p0, p1, p2, p3, description)\
12312 template <typename p0##_type, typename p1##_type, typename p2##_type, \
12313 typename p3##_type>\
12314 class name##MatcherP4 {\
12315 public:\
12316 template <typename arg_type>\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012317 class gmock_Impl : public ::testing::MatcherInterface<\
12318 GTEST_REFERENCE_TO_CONST_(arg_type)> {\
Austin Schuh70cc9552019-01-21 19:46:48 -080012319 public:\
12320 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
12321 p3##_type gmock_p3)\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012322 : p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)), \
12323 p2(::std::move(gmock_p2)), p3(::std::move(gmock_p3)) {}\
Austin Schuh70cc9552019-01-21 19:46:48 -080012324 virtual bool MatchAndExplain(\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012325 GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
12326 ::testing::MatchResultListener* result_listener) const;\
Austin Schuh70cc9552019-01-21 19:46:48 -080012327 virtual void DescribeTo(::std::ostream* gmock_os) const {\
12328 *gmock_os << FormatDescription(false);\
12329 }\
12330 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
12331 *gmock_os << FormatDescription(true);\
12332 }\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012333 p0##_type const p0;\
12334 p1##_type const p1;\
12335 p2##_type const p2;\
12336 p3##_type const p3;\
Austin Schuh70cc9552019-01-21 19:46:48 -080012337 private:\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012338 ::std::string FormatDescription(bool negation) const {\
12339 ::std::string gmock_description = (description);\
12340 if (!gmock_description.empty()) {\
Austin Schuh70cc9552019-01-21 19:46:48 -080012341 return gmock_description;\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012342 }\
Austin Schuh70cc9552019-01-21 19:46:48 -080012343 return ::testing::internal::FormatMatcherDescription(\
12344 negation, #name, \
12345 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012346 ::std::tuple<p0##_type, p1##_type, p2##_type, p3##_type>(p0, \
12347 p1, p2, p3)));\
Austin Schuh70cc9552019-01-21 19:46:48 -080012348 }\
Austin Schuh70cc9552019-01-21 19:46:48 -080012349 };\
12350 template <typename arg_type>\
12351 operator ::testing::Matcher<arg_type>() const {\
12352 return ::testing::Matcher<arg_type>(\
12353 new gmock_Impl<arg_type>(p0, p1, p2, p3));\
12354 }\
12355 name##MatcherP4(p0##_type gmock_p0, p1##_type gmock_p1, \
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012356 p2##_type gmock_p2, p3##_type gmock_p3) : p0(::std::move(gmock_p0)), \
12357 p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
12358 p3(::std::move(gmock_p3)) {\
Austin Schuh70cc9552019-01-21 19:46:48 -080012359 }\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012360 p0##_type const p0;\
12361 p1##_type const p1;\
12362 p2##_type const p2;\
12363 p3##_type const p3;\
Austin Schuh70cc9552019-01-21 19:46:48 -080012364 private:\
Austin Schuh70cc9552019-01-21 19:46:48 -080012365 };\
12366 template <typename p0##_type, typename p1##_type, typename p2##_type, \
12367 typename p3##_type>\
12368 inline name##MatcherP4<p0##_type, p1##_type, p2##_type, \
12369 p3##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
12370 p3##_type p3) {\
12371 return name##MatcherP4<p0##_type, p1##_type, p2##_type, p3##_type>(p0, \
12372 p1, p2, p3);\
12373 }\
12374 template <typename p0##_type, typename p1##_type, typename p2##_type, \
12375 typename p3##_type>\
12376 template <typename arg_type>\
12377 bool name##MatcherP4<p0##_type, p1##_type, p2##_type, \
12378 p3##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012379 GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
Austin Schuh70cc9552019-01-21 19:46:48 -080012380 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
12381 const
12382
12383#define MATCHER_P5(name, p0, p1, p2, p3, p4, description)\
12384 template <typename p0##_type, typename p1##_type, typename p2##_type, \
12385 typename p3##_type, typename p4##_type>\
12386 class name##MatcherP5 {\
12387 public:\
12388 template <typename arg_type>\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012389 class gmock_Impl : public ::testing::MatcherInterface<\
12390 GTEST_REFERENCE_TO_CONST_(arg_type)> {\
Austin Schuh70cc9552019-01-21 19:46:48 -080012391 public:\
12392 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
12393 p3##_type gmock_p3, p4##_type gmock_p4)\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012394 : p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)), \
12395 p2(::std::move(gmock_p2)), p3(::std::move(gmock_p3)), \
12396 p4(::std::move(gmock_p4)) {}\
Austin Schuh70cc9552019-01-21 19:46:48 -080012397 virtual bool MatchAndExplain(\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012398 GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
12399 ::testing::MatchResultListener* result_listener) const;\
Austin Schuh70cc9552019-01-21 19:46:48 -080012400 virtual void DescribeTo(::std::ostream* gmock_os) const {\
12401 *gmock_os << FormatDescription(false);\
12402 }\
12403 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
12404 *gmock_os << FormatDescription(true);\
12405 }\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012406 p0##_type const p0;\
12407 p1##_type const p1;\
12408 p2##_type const p2;\
12409 p3##_type const p3;\
12410 p4##_type const p4;\
Austin Schuh70cc9552019-01-21 19:46:48 -080012411 private:\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012412 ::std::string FormatDescription(bool negation) const {\
12413 ::std::string gmock_description = (description);\
12414 if (!gmock_description.empty()) {\
Austin Schuh70cc9552019-01-21 19:46:48 -080012415 return gmock_description;\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012416 }\
Austin Schuh70cc9552019-01-21 19:46:48 -080012417 return ::testing::internal::FormatMatcherDescription(\
12418 negation, #name, \
12419 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012420 ::std::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
Austin Schuh70cc9552019-01-21 19:46:48 -080012421 p4##_type>(p0, p1, p2, p3, p4)));\
12422 }\
Austin Schuh70cc9552019-01-21 19:46:48 -080012423 };\
12424 template <typename arg_type>\
12425 operator ::testing::Matcher<arg_type>() const {\
12426 return ::testing::Matcher<arg_type>(\
12427 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4));\
12428 }\
12429 name##MatcherP5(p0##_type gmock_p0, p1##_type gmock_p1, \
12430 p2##_type gmock_p2, p3##_type gmock_p3, \
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012431 p4##_type gmock_p4) : p0(::std::move(gmock_p0)), \
12432 p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
12433 p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)) {\
Austin Schuh70cc9552019-01-21 19:46:48 -080012434 }\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012435 p0##_type const p0;\
12436 p1##_type const p1;\
12437 p2##_type const p2;\
12438 p3##_type const p3;\
12439 p4##_type const p4;\
Austin Schuh70cc9552019-01-21 19:46:48 -080012440 private:\
Austin Schuh70cc9552019-01-21 19:46:48 -080012441 };\
12442 template <typename p0##_type, typename p1##_type, typename p2##_type, \
12443 typename p3##_type, typename p4##_type>\
12444 inline name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \
12445 p4##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
12446 p4##_type p4) {\
12447 return name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \
12448 p4##_type>(p0, p1, p2, p3, p4);\
12449 }\
12450 template <typename p0##_type, typename p1##_type, typename p2##_type, \
12451 typename p3##_type, typename p4##_type>\
12452 template <typename arg_type>\
12453 bool name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \
12454 p4##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012455 GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
Austin Schuh70cc9552019-01-21 19:46:48 -080012456 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
12457 const
12458
12459#define MATCHER_P6(name, p0, p1, p2, p3, p4, p5, description)\
12460 template <typename p0##_type, typename p1##_type, typename p2##_type, \
12461 typename p3##_type, typename p4##_type, typename p5##_type>\
12462 class name##MatcherP6 {\
12463 public:\
12464 template <typename arg_type>\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012465 class gmock_Impl : public ::testing::MatcherInterface<\
12466 GTEST_REFERENCE_TO_CONST_(arg_type)> {\
Austin Schuh70cc9552019-01-21 19:46:48 -080012467 public:\
12468 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
12469 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5)\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012470 : p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)), \
12471 p2(::std::move(gmock_p2)), p3(::std::move(gmock_p3)), \
12472 p4(::std::move(gmock_p4)), p5(::std::move(gmock_p5)) {}\
Austin Schuh70cc9552019-01-21 19:46:48 -080012473 virtual bool MatchAndExplain(\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012474 GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
12475 ::testing::MatchResultListener* result_listener) const;\
Austin Schuh70cc9552019-01-21 19:46:48 -080012476 virtual void DescribeTo(::std::ostream* gmock_os) const {\
12477 *gmock_os << FormatDescription(false);\
12478 }\
12479 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
12480 *gmock_os << FormatDescription(true);\
12481 }\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012482 p0##_type const p0;\
12483 p1##_type const p1;\
12484 p2##_type const p2;\
12485 p3##_type const p3;\
12486 p4##_type const p4;\
12487 p5##_type const p5;\
Austin Schuh70cc9552019-01-21 19:46:48 -080012488 private:\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012489 ::std::string FormatDescription(bool negation) const {\
12490 ::std::string gmock_description = (description);\
12491 if (!gmock_description.empty()) {\
Austin Schuh70cc9552019-01-21 19:46:48 -080012492 return gmock_description;\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012493 }\
Austin Schuh70cc9552019-01-21 19:46:48 -080012494 return ::testing::internal::FormatMatcherDescription(\
12495 negation, #name, \
12496 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012497 ::std::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
Austin Schuh70cc9552019-01-21 19:46:48 -080012498 p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5)));\
12499 }\
Austin Schuh70cc9552019-01-21 19:46:48 -080012500 };\
12501 template <typename arg_type>\
12502 operator ::testing::Matcher<arg_type>() const {\
12503 return ::testing::Matcher<arg_type>(\
12504 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5));\
12505 }\
12506 name##MatcherP6(p0##_type gmock_p0, p1##_type gmock_p1, \
12507 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012508 p5##_type gmock_p5) : p0(::std::move(gmock_p0)), \
12509 p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
12510 p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \
12511 p5(::std::move(gmock_p5)) {\
Austin Schuh70cc9552019-01-21 19:46:48 -080012512 }\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012513 p0##_type const p0;\
12514 p1##_type const p1;\
12515 p2##_type const p2;\
12516 p3##_type const p3;\
12517 p4##_type const p4;\
12518 p5##_type const p5;\
Austin Schuh70cc9552019-01-21 19:46:48 -080012519 private:\
Austin Schuh70cc9552019-01-21 19:46:48 -080012520 };\
12521 template <typename p0##_type, typename p1##_type, typename p2##_type, \
12522 typename p3##_type, typename p4##_type, typename p5##_type>\
12523 inline name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, \
12524 p4##_type, p5##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
12525 p3##_type p3, p4##_type p4, p5##_type p5) {\
12526 return name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, \
12527 p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5);\
12528 }\
12529 template <typename p0##_type, typename p1##_type, typename p2##_type, \
12530 typename p3##_type, typename p4##_type, typename p5##_type>\
12531 template <typename arg_type>\
12532 bool name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
12533 p5##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012534 GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
Austin Schuh70cc9552019-01-21 19:46:48 -080012535 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
12536 const
12537
12538#define MATCHER_P7(name, p0, p1, p2, p3, p4, p5, p6, description)\
12539 template <typename p0##_type, typename p1##_type, typename p2##_type, \
12540 typename p3##_type, typename p4##_type, typename p5##_type, \
12541 typename p6##_type>\
12542 class name##MatcherP7 {\
12543 public:\
12544 template <typename arg_type>\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012545 class gmock_Impl : public ::testing::MatcherInterface<\
12546 GTEST_REFERENCE_TO_CONST_(arg_type)> {\
Austin Schuh70cc9552019-01-21 19:46:48 -080012547 public:\
12548 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
12549 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
12550 p6##_type gmock_p6)\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012551 : p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)), \
12552 p2(::std::move(gmock_p2)), p3(::std::move(gmock_p3)), \
12553 p4(::std::move(gmock_p4)), p5(::std::move(gmock_p5)), \
12554 p6(::std::move(gmock_p6)) {}\
Austin Schuh70cc9552019-01-21 19:46:48 -080012555 virtual bool MatchAndExplain(\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012556 GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
12557 ::testing::MatchResultListener* result_listener) const;\
Austin Schuh70cc9552019-01-21 19:46:48 -080012558 virtual void DescribeTo(::std::ostream* gmock_os) const {\
12559 *gmock_os << FormatDescription(false);\
12560 }\
12561 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
12562 *gmock_os << FormatDescription(true);\
12563 }\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012564 p0##_type const p0;\
12565 p1##_type const p1;\
12566 p2##_type const p2;\
12567 p3##_type const p3;\
12568 p4##_type const p4;\
12569 p5##_type const p5;\
12570 p6##_type const p6;\
Austin Schuh70cc9552019-01-21 19:46:48 -080012571 private:\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012572 ::std::string FormatDescription(bool negation) const {\
12573 ::std::string gmock_description = (description);\
12574 if (!gmock_description.empty()) {\
Austin Schuh70cc9552019-01-21 19:46:48 -080012575 return gmock_description;\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012576 }\
Austin Schuh70cc9552019-01-21 19:46:48 -080012577 return ::testing::internal::FormatMatcherDescription(\
12578 negation, #name, \
12579 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012580 ::std::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
Austin Schuh70cc9552019-01-21 19:46:48 -080012581 p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, \
12582 p6)));\
12583 }\
Austin Schuh70cc9552019-01-21 19:46:48 -080012584 };\
12585 template <typename arg_type>\
12586 operator ::testing::Matcher<arg_type>() const {\
12587 return ::testing::Matcher<arg_type>(\
12588 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6));\
12589 }\
12590 name##MatcherP7(p0##_type gmock_p0, p1##_type gmock_p1, \
12591 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012592 p5##_type gmock_p5, p6##_type gmock_p6) : p0(::std::move(gmock_p0)), \
12593 p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
12594 p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \
12595 p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)) {\
Austin Schuh70cc9552019-01-21 19:46:48 -080012596 }\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012597 p0##_type const p0;\
12598 p1##_type const p1;\
12599 p2##_type const p2;\
12600 p3##_type const p3;\
12601 p4##_type const p4;\
12602 p5##_type const p5;\
12603 p6##_type const p6;\
Austin Schuh70cc9552019-01-21 19:46:48 -080012604 private:\
Austin Schuh70cc9552019-01-21 19:46:48 -080012605 };\
12606 template <typename p0##_type, typename p1##_type, typename p2##_type, \
12607 typename p3##_type, typename p4##_type, typename p5##_type, \
12608 typename p6##_type>\
12609 inline name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, \
12610 p4##_type, p5##_type, p6##_type> name(p0##_type p0, p1##_type p1, \
12611 p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
12612 p6##_type p6) {\
12613 return name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, \
12614 p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, p6);\
12615 }\
12616 template <typename p0##_type, typename p1##_type, typename p2##_type, \
12617 typename p3##_type, typename p4##_type, typename p5##_type, \
12618 typename p6##_type>\
12619 template <typename arg_type>\
12620 bool name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
12621 p5##_type, p6##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012622 GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
Austin Schuh70cc9552019-01-21 19:46:48 -080012623 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
12624 const
12625
12626#define MATCHER_P8(name, p0, p1, p2, p3, p4, p5, p6, p7, description)\
12627 template <typename p0##_type, typename p1##_type, typename p2##_type, \
12628 typename p3##_type, typename p4##_type, typename p5##_type, \
12629 typename p6##_type, typename p7##_type>\
12630 class name##MatcherP8 {\
12631 public:\
12632 template <typename arg_type>\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012633 class gmock_Impl : public ::testing::MatcherInterface<\
12634 GTEST_REFERENCE_TO_CONST_(arg_type)> {\
Austin Schuh70cc9552019-01-21 19:46:48 -080012635 public:\
12636 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
12637 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
12638 p6##_type gmock_p6, p7##_type gmock_p7)\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012639 : p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)), \
12640 p2(::std::move(gmock_p2)), p3(::std::move(gmock_p3)), \
12641 p4(::std::move(gmock_p4)), p5(::std::move(gmock_p5)), \
12642 p6(::std::move(gmock_p6)), p7(::std::move(gmock_p7)) {}\
Austin Schuh70cc9552019-01-21 19:46:48 -080012643 virtual bool MatchAndExplain(\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012644 GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
12645 ::testing::MatchResultListener* result_listener) const;\
Austin Schuh70cc9552019-01-21 19:46:48 -080012646 virtual void DescribeTo(::std::ostream* gmock_os) const {\
12647 *gmock_os << FormatDescription(false);\
12648 }\
12649 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
12650 *gmock_os << FormatDescription(true);\
12651 }\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012652 p0##_type const p0;\
12653 p1##_type const p1;\
12654 p2##_type const p2;\
12655 p3##_type const p3;\
12656 p4##_type const p4;\
12657 p5##_type const p5;\
12658 p6##_type const p6;\
12659 p7##_type const p7;\
Austin Schuh70cc9552019-01-21 19:46:48 -080012660 private:\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012661 ::std::string FormatDescription(bool negation) const {\
12662 ::std::string gmock_description = (description);\
12663 if (!gmock_description.empty()) {\
Austin Schuh70cc9552019-01-21 19:46:48 -080012664 return gmock_description;\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012665 }\
Austin Schuh70cc9552019-01-21 19:46:48 -080012666 return ::testing::internal::FormatMatcherDescription(\
12667 negation, #name, \
12668 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012669 ::std::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
Austin Schuh70cc9552019-01-21 19:46:48 -080012670 p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, \
12671 p3, p4, p5, p6, p7)));\
12672 }\
Austin Schuh70cc9552019-01-21 19:46:48 -080012673 };\
12674 template <typename arg_type>\
12675 operator ::testing::Matcher<arg_type>() const {\
12676 return ::testing::Matcher<arg_type>(\
12677 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7));\
12678 }\
12679 name##MatcherP8(p0##_type gmock_p0, p1##_type gmock_p1, \
12680 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
12681 p5##_type gmock_p5, p6##_type gmock_p6, \
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012682 p7##_type gmock_p7) : p0(::std::move(gmock_p0)), \
12683 p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
12684 p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \
12685 p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)), \
12686 p7(::std::move(gmock_p7)) {\
Austin Schuh70cc9552019-01-21 19:46:48 -080012687 }\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012688 p0##_type const p0;\
12689 p1##_type const p1;\
12690 p2##_type const p2;\
12691 p3##_type const p3;\
12692 p4##_type const p4;\
12693 p5##_type const p5;\
12694 p6##_type const p6;\
12695 p7##_type const p7;\
Austin Schuh70cc9552019-01-21 19:46:48 -080012696 private:\
Austin Schuh70cc9552019-01-21 19:46:48 -080012697 };\
12698 template <typename p0##_type, typename p1##_type, typename p2##_type, \
12699 typename p3##_type, typename p4##_type, typename p5##_type, \
12700 typename p6##_type, typename p7##_type>\
12701 inline name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, \
12702 p4##_type, p5##_type, p6##_type, p7##_type> name(p0##_type p0, \
12703 p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
12704 p6##_type p6, p7##_type p7) {\
12705 return name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, \
12706 p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, p3, p4, p5, \
12707 p6, p7);\
12708 }\
12709 template <typename p0##_type, typename p1##_type, typename p2##_type, \
12710 typename p3##_type, typename p4##_type, typename p5##_type, \
12711 typename p6##_type, typename p7##_type>\
12712 template <typename arg_type>\
12713 bool name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
12714 p5##_type, p6##_type, \
12715 p7##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012716 GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
Austin Schuh70cc9552019-01-21 19:46:48 -080012717 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
12718 const
12719
12720#define MATCHER_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, description)\
12721 template <typename p0##_type, typename p1##_type, typename p2##_type, \
12722 typename p3##_type, typename p4##_type, typename p5##_type, \
12723 typename p6##_type, typename p7##_type, typename p8##_type>\
12724 class name##MatcherP9 {\
12725 public:\
12726 template <typename arg_type>\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012727 class gmock_Impl : public ::testing::MatcherInterface<\
12728 GTEST_REFERENCE_TO_CONST_(arg_type)> {\
Austin Schuh70cc9552019-01-21 19:46:48 -080012729 public:\
12730 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
12731 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
12732 p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8)\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012733 : p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)), \
12734 p2(::std::move(gmock_p2)), p3(::std::move(gmock_p3)), \
12735 p4(::std::move(gmock_p4)), p5(::std::move(gmock_p5)), \
12736 p6(::std::move(gmock_p6)), p7(::std::move(gmock_p7)), \
12737 p8(::std::move(gmock_p8)) {}\
Austin Schuh70cc9552019-01-21 19:46:48 -080012738 virtual bool MatchAndExplain(\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012739 GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
12740 ::testing::MatchResultListener* result_listener) const;\
Austin Schuh70cc9552019-01-21 19:46:48 -080012741 virtual void DescribeTo(::std::ostream* gmock_os) const {\
12742 *gmock_os << FormatDescription(false);\
12743 }\
12744 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
12745 *gmock_os << FormatDescription(true);\
12746 }\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012747 p0##_type const p0;\
12748 p1##_type const p1;\
12749 p2##_type const p2;\
12750 p3##_type const p3;\
12751 p4##_type const p4;\
12752 p5##_type const p5;\
12753 p6##_type const p6;\
12754 p7##_type const p7;\
12755 p8##_type const p8;\
Austin Schuh70cc9552019-01-21 19:46:48 -080012756 private:\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012757 ::std::string FormatDescription(bool negation) const {\
12758 ::std::string gmock_description = (description);\
12759 if (!gmock_description.empty()) {\
Austin Schuh70cc9552019-01-21 19:46:48 -080012760 return gmock_description;\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012761 }\
Austin Schuh70cc9552019-01-21 19:46:48 -080012762 return ::testing::internal::FormatMatcherDescription(\
12763 negation, #name, \
12764 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012765 ::std::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
Austin Schuh70cc9552019-01-21 19:46:48 -080012766 p4##_type, p5##_type, p6##_type, p7##_type, \
12767 p8##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8)));\
12768 }\
Austin Schuh70cc9552019-01-21 19:46:48 -080012769 };\
12770 template <typename arg_type>\
12771 operator ::testing::Matcher<arg_type>() const {\
12772 return ::testing::Matcher<arg_type>(\
12773 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8));\
12774 }\
12775 name##MatcherP9(p0##_type gmock_p0, p1##_type gmock_p1, \
12776 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
12777 p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012778 p8##_type gmock_p8) : p0(::std::move(gmock_p0)), \
12779 p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
12780 p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \
12781 p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)), \
12782 p7(::std::move(gmock_p7)), p8(::std::move(gmock_p8)) {\
Austin Schuh70cc9552019-01-21 19:46:48 -080012783 }\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012784 p0##_type const p0;\
12785 p1##_type const p1;\
12786 p2##_type const p2;\
12787 p3##_type const p3;\
12788 p4##_type const p4;\
12789 p5##_type const p5;\
12790 p6##_type const p6;\
12791 p7##_type const p7;\
12792 p8##_type const p8;\
Austin Schuh70cc9552019-01-21 19:46:48 -080012793 private:\
Austin Schuh70cc9552019-01-21 19:46:48 -080012794 };\
12795 template <typename p0##_type, typename p1##_type, typename p2##_type, \
12796 typename p3##_type, typename p4##_type, typename p5##_type, \
12797 typename p6##_type, typename p7##_type, typename p8##_type>\
12798 inline name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, \
12799 p4##_type, p5##_type, p6##_type, p7##_type, \
12800 p8##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
12801 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, \
12802 p8##_type p8) {\
12803 return name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, \
12804 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type>(p0, p1, p2, \
12805 p3, p4, p5, p6, p7, p8);\
12806 }\
12807 template <typename p0##_type, typename p1##_type, typename p2##_type, \
12808 typename p3##_type, typename p4##_type, typename p5##_type, \
12809 typename p6##_type, typename p7##_type, typename p8##_type>\
12810 template <typename arg_type>\
12811 bool name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
12812 p5##_type, p6##_type, p7##_type, \
12813 p8##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012814 GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
Austin Schuh70cc9552019-01-21 19:46:48 -080012815 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
12816 const
12817
12818#define MATCHER_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, description)\
12819 template <typename p0##_type, typename p1##_type, typename p2##_type, \
12820 typename p3##_type, typename p4##_type, typename p5##_type, \
12821 typename p6##_type, typename p7##_type, typename p8##_type, \
12822 typename p9##_type>\
12823 class name##MatcherP10 {\
12824 public:\
12825 template <typename arg_type>\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012826 class gmock_Impl : public ::testing::MatcherInterface<\
12827 GTEST_REFERENCE_TO_CONST_(arg_type)> {\
Austin Schuh70cc9552019-01-21 19:46:48 -080012828 public:\
12829 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
12830 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
12831 p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
12832 p9##_type gmock_p9)\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012833 : p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)), \
12834 p2(::std::move(gmock_p2)), p3(::std::move(gmock_p3)), \
12835 p4(::std::move(gmock_p4)), p5(::std::move(gmock_p5)), \
12836 p6(::std::move(gmock_p6)), p7(::std::move(gmock_p7)), \
12837 p8(::std::move(gmock_p8)), p9(::std::move(gmock_p9)) {}\
Austin Schuh70cc9552019-01-21 19:46:48 -080012838 virtual bool MatchAndExplain(\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012839 GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
12840 ::testing::MatchResultListener* result_listener) const;\
Austin Schuh70cc9552019-01-21 19:46:48 -080012841 virtual void DescribeTo(::std::ostream* gmock_os) const {\
12842 *gmock_os << FormatDescription(false);\
12843 }\
12844 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
12845 *gmock_os << FormatDescription(true);\
12846 }\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012847 p0##_type const p0;\
12848 p1##_type const p1;\
12849 p2##_type const p2;\
12850 p3##_type const p3;\
12851 p4##_type const p4;\
12852 p5##_type const p5;\
12853 p6##_type const p6;\
12854 p7##_type const p7;\
12855 p8##_type const p8;\
12856 p9##_type const p9;\
Austin Schuh70cc9552019-01-21 19:46:48 -080012857 private:\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012858 ::std::string FormatDescription(bool negation) const {\
12859 ::std::string gmock_description = (description);\
12860 if (!gmock_description.empty()) {\
Austin Schuh70cc9552019-01-21 19:46:48 -080012861 return gmock_description;\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012862 }\
Austin Schuh70cc9552019-01-21 19:46:48 -080012863 return ::testing::internal::FormatMatcherDescription(\
12864 negation, #name, \
12865 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012866 ::std::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
Austin Schuh70cc9552019-01-21 19:46:48 -080012867 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
12868 p9##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)));\
12869 }\
Austin Schuh70cc9552019-01-21 19:46:48 -080012870 };\
12871 template <typename arg_type>\
12872 operator ::testing::Matcher<arg_type>() const {\
12873 return ::testing::Matcher<arg_type>(\
12874 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9));\
12875 }\
12876 name##MatcherP10(p0##_type gmock_p0, p1##_type gmock_p1, \
12877 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
12878 p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012879 p8##_type gmock_p8, p9##_type gmock_p9) : p0(::std::move(gmock_p0)), \
12880 p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
12881 p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \
12882 p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)), \
12883 p7(::std::move(gmock_p7)), p8(::std::move(gmock_p8)), \
12884 p9(::std::move(gmock_p9)) {\
Austin Schuh70cc9552019-01-21 19:46:48 -080012885 }\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012886 p0##_type const p0;\
12887 p1##_type const p1;\
12888 p2##_type const p2;\
12889 p3##_type const p3;\
12890 p4##_type const p4;\
12891 p5##_type const p5;\
12892 p6##_type const p6;\
12893 p7##_type const p7;\
12894 p8##_type const p8;\
12895 p9##_type const p9;\
Austin Schuh70cc9552019-01-21 19:46:48 -080012896 private:\
Austin Schuh70cc9552019-01-21 19:46:48 -080012897 };\
12898 template <typename p0##_type, typename p1##_type, typename p2##_type, \
12899 typename p3##_type, typename p4##_type, typename p5##_type, \
12900 typename p6##_type, typename p7##_type, typename p8##_type, \
12901 typename p9##_type>\
12902 inline name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \
12903 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
12904 p9##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
12905 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \
12906 p9##_type p9) {\
12907 return name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \
12908 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, p9##_type>(p0, \
12909 p1, p2, p3, p4, p5, p6, p7, p8, p9);\
12910 }\
12911 template <typename p0##_type, typename p1##_type, typename p2##_type, \
12912 typename p3##_type, typename p4##_type, typename p5##_type, \
12913 typename p6##_type, typename p7##_type, typename p8##_type, \
12914 typename p9##_type>\
12915 template <typename arg_type>\
12916 bool name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \
12917 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
12918 p9##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012919 GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
Austin Schuh70cc9552019-01-21 19:46:48 -080012920 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
12921 const
12922
12923#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
12924// Copyright 2007, Google Inc.
12925// All rights reserved.
12926//
12927// Redistribution and use in source and binary forms, with or without
12928// modification, are permitted provided that the following conditions are
12929// met:
12930//
12931// * Redistributions of source code must retain the above copyright
12932// notice, this list of conditions and the following disclaimer.
12933// * Redistributions in binary form must reproduce the above
12934// copyright notice, this list of conditions and the following disclaimer
12935// in the documentation and/or other materials provided with the
12936// distribution.
12937// * Neither the name of Google Inc. nor the names of its
12938// contributors may be used to endorse or promote products derived from
12939// this software without specific prior written permission.
12940//
12941// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
12942// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
12943// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
12944// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
12945// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
12946// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
12947// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12948// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12949// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12950// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
12951// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012952
Austin Schuh70cc9552019-01-21 19:46:48 -080012953
12954// Google Mock - a framework for writing C++ mock classes.
12955//
12956// This file implements some actions that depend on gmock-generated-actions.h.
12957
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012958// GOOGLETEST_CM0002 DO NOT DELETE
12959
Austin Schuh70cc9552019-01-21 19:46:48 -080012960#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
12961#define GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
12962
12963#include <algorithm>
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080012964#include <type_traits>
Austin Schuh70cc9552019-01-21 19:46:48 -080012965
12966
12967namespace testing {
12968namespace internal {
12969
Austin Schuh70cc9552019-01-21 19:46:48 -080012970// An internal replacement for std::copy which mimics its behavior. This is
12971// necessary because Visual Studio deprecates ::std::copy, issuing warning 4996.
12972// However Visual Studio 2010 and later do not honor #pragmas which disable that
12973// warning.
12974template<typename InputIterator, typename OutputIterator>
12975inline OutputIterator CopyElements(InputIterator first,
12976 InputIterator last,
12977 OutputIterator output) {
12978 for (; first != last; ++first, ++output) {
12979 *output = *first;
12980 }
12981 return output;
12982}
12983
12984} // namespace internal
12985
12986// Various overloads for Invoke().
12987
Austin Schuh70cc9552019-01-21 19:46:48 -080012988// The ACTION*() macros trigger warning C4100 (unreferenced formal
12989// parameter) in MSVC with -W4. Unfortunately they cannot be fixed in
12990// the macro definition, as the warnings are generated when the macro
12991// is expanded and macro expansion cannot contain #pragma. Therefore
12992// we suppress them here.
12993#ifdef _MSC_VER
12994# pragma warning(push)
12995# pragma warning(disable:4100)
12996#endif
12997
12998// Action ReturnArg<k>() returns the k-th argument of the mock function.
12999ACTION_TEMPLATE(ReturnArg,
13000 HAS_1_TEMPLATE_PARAMS(int, k),
13001 AND_0_VALUE_PARAMS()) {
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080013002 return ::std::get<k>(args);
Austin Schuh70cc9552019-01-21 19:46:48 -080013003}
13004
13005// Action SaveArg<k>(pointer) saves the k-th (0-based) argument of the
13006// mock function to *pointer.
13007ACTION_TEMPLATE(SaveArg,
13008 HAS_1_TEMPLATE_PARAMS(int, k),
13009 AND_1_VALUE_PARAMS(pointer)) {
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080013010 *pointer = ::std::get<k>(args);
Austin Schuh70cc9552019-01-21 19:46:48 -080013011}
13012
13013// Action SaveArgPointee<k>(pointer) saves the value pointed to
13014// by the k-th (0-based) argument of the mock function to *pointer.
13015ACTION_TEMPLATE(SaveArgPointee,
13016 HAS_1_TEMPLATE_PARAMS(int, k),
13017 AND_1_VALUE_PARAMS(pointer)) {
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080013018 *pointer = *::std::get<k>(args);
Austin Schuh70cc9552019-01-21 19:46:48 -080013019}
13020
13021// Action SetArgReferee<k>(value) assigns 'value' to the variable
13022// referenced by the k-th (0-based) argument of the mock function.
13023ACTION_TEMPLATE(SetArgReferee,
13024 HAS_1_TEMPLATE_PARAMS(int, k),
13025 AND_1_VALUE_PARAMS(value)) {
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080013026 typedef typename ::std::tuple_element<k, args_type>::type argk_type;
Austin Schuh70cc9552019-01-21 19:46:48 -080013027 // Ensures that argument #k is a reference. If you get a compiler
13028 // error on the next line, you are using SetArgReferee<k>(value) in
13029 // a mock function whose k-th (0-based) argument is not a reference.
13030 GTEST_COMPILE_ASSERT_(internal::is_reference<argk_type>::value,
13031 SetArgReferee_must_be_used_with_a_reference_argument);
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080013032 ::std::get<k>(args) = value;
Austin Schuh70cc9552019-01-21 19:46:48 -080013033}
13034
13035// Action SetArrayArgument<k>(first, last) copies the elements in
13036// source range [first, last) to the array pointed to by the k-th
13037// (0-based) argument, which can be either a pointer or an
13038// iterator. The action does not take ownership of the elements in the
13039// source range.
13040ACTION_TEMPLATE(SetArrayArgument,
13041 HAS_1_TEMPLATE_PARAMS(int, k),
13042 AND_2_VALUE_PARAMS(first, last)) {
13043 // Visual Studio deprecates ::std::copy, so we use our own copy in that case.
13044#ifdef _MSC_VER
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080013045 internal::CopyElements(first, last, ::std::get<k>(args));
Austin Schuh70cc9552019-01-21 19:46:48 -080013046#else
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080013047 ::std::copy(first, last, ::std::get<k>(args));
Austin Schuh70cc9552019-01-21 19:46:48 -080013048#endif
13049}
13050
13051// Action DeleteArg<k>() deletes the k-th (0-based) argument of the mock
13052// function.
13053ACTION_TEMPLATE(DeleteArg,
13054 HAS_1_TEMPLATE_PARAMS(int, k),
13055 AND_0_VALUE_PARAMS()) {
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080013056 delete ::std::get<k>(args);
Austin Schuh70cc9552019-01-21 19:46:48 -080013057}
13058
13059// This action returns the value pointed to by 'pointer'.
13060ACTION_P(ReturnPointee, pointer) { return *pointer; }
13061
13062// Action Throw(exception) can be used in a mock function of any type
13063// to throw the given exception. Any copyable value can be thrown.
13064#if GTEST_HAS_EXCEPTIONS
13065
13066// Suppresses the 'unreachable code' warning that VC generates in opt modes.
13067# ifdef _MSC_VER
13068# pragma warning(push) // Saves the current warning state.
13069# pragma warning(disable:4702) // Temporarily disables warning 4702.
13070# endif
13071ACTION_P(Throw, exception) { throw exception; }
13072# ifdef _MSC_VER
13073# pragma warning(pop) // Restores the warning state.
13074# endif
13075
13076#endif // GTEST_HAS_EXCEPTIONS
13077
13078#ifdef _MSC_VER
13079# pragma warning(pop)
13080#endif
13081
13082} // namespace testing
13083
13084#endif // GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
13085// Copyright 2013, Google Inc.
13086// All rights reserved.
13087//
13088// Redistribution and use in source and binary forms, with or without
13089// modification, are permitted provided that the following conditions are
13090// met:
13091//
13092// * Redistributions of source code must retain the above copyright
13093// notice, this list of conditions and the following disclaimer.
13094// * Redistributions in binary form must reproduce the above
13095// copyright notice, this list of conditions and the following disclaimer
13096// in the documentation and/or other materials provided with the
13097// distribution.
13098// * Neither the name of Google Inc. nor the names of its
13099// contributors may be used to endorse or promote products derived from
13100// this software without specific prior written permission.
13101//
13102// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13103// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
13104// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
13105// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
13106// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
13107// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
13108// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
13109// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13110// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13111// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13112// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080013113
Austin Schuh70cc9552019-01-21 19:46:48 -080013114
13115// Google Mock - a framework for writing C++ mock classes.
13116//
13117// This file implements some matchers that depend on gmock-generated-matchers.h.
13118//
13119// Note that tests are implemented in gmock-matchers_test.cc rather than
13120// gmock-more-matchers-test.cc.
13121
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080013122// GOOGLETEST_CM0002 DO NOT DELETE
13123
13124#ifndef GMOCK_INCLUDE_GMOCK_MORE_MATCHERS_H_
13125#define GMOCK_INCLUDE_GMOCK_MORE_MATCHERS_H_
Austin Schuh70cc9552019-01-21 19:46:48 -080013126
13127
13128namespace testing {
13129
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080013130// Silence C4100 (unreferenced formal
13131// parameter) for MSVC
13132#ifdef _MSC_VER
13133# pragma warning(push)
13134# pragma warning(disable:4100)
13135#if (_MSC_VER == 1900)
13136// and silence C4800 (C4800: 'int *const ': forcing value
13137// to bool 'true' or 'false') for MSVC 14
13138# pragma warning(disable:4800)
13139 #endif
13140#endif
13141
Austin Schuh70cc9552019-01-21 19:46:48 -080013142// Defines a matcher that matches an empty container. The container must
13143// support both size() and empty(), which all STL-like containers provide.
13144MATCHER(IsEmpty, negation ? "isn't empty" : "is empty") {
13145 if (arg.empty()) {
13146 return true;
13147 }
13148 *result_listener << "whose size is " << arg.size();
13149 return false;
13150}
13151
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080013152// Define a matcher that matches a value that evaluates in boolean
13153// context to true. Useful for types that define "explicit operator
13154// bool" operators and so can't be compared for equality with true
13155// and false.
13156MATCHER(IsTrue, negation ? "is false" : "is true") {
13157 return static_cast<bool>(arg);
13158}
13159
13160// Define a matcher that matches a value that evaluates in boolean
13161// context to false. Useful for types that define "explicit operator
13162// bool" operators and so can't be compared for equality with true
13163// and false.
13164MATCHER(IsFalse, negation ? "is true" : "is false") {
13165 return !static_cast<bool>(arg);
13166}
13167
13168#ifdef _MSC_VER
13169# pragma warning(pop)
13170#endif
13171
13172
Austin Schuh70cc9552019-01-21 19:46:48 -080013173} // namespace testing
13174
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080013175#endif // GMOCK_INCLUDE_GMOCK_MORE_MATCHERS_H_
13176// Copyright 2008, Google Inc.
13177// All rights reserved.
13178//
13179// Redistribution and use in source and binary forms, with or without
13180// modification, are permitted provided that the following conditions are
13181// met:
13182//
13183// * Redistributions of source code must retain the above copyright
13184// notice, this list of conditions and the following disclaimer.
13185// * Redistributions in binary form must reproduce the above
13186// copyright notice, this list of conditions and the following disclaimer
13187// in the documentation and/or other materials provided with the
13188// distribution.
13189// * Neither the name of Google Inc. nor the names of its
13190// contributors may be used to endorse or promote products derived from
13191// this software without specific prior written permission.
13192//
13193// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13194// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
13195// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
13196// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
13197// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
13198// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
13199// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
13200// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13201// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13202// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13203// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13204
13205
13206// Implements class templates NiceMock, NaggyMock, and StrictMock.
13207//
13208// Given a mock class MockFoo that is created using Google Mock,
13209// NiceMock<MockFoo> is a subclass of MockFoo that allows
13210// uninteresting calls (i.e. calls to mock methods that have no
13211// EXPECT_CALL specs), NaggyMock<MockFoo> is a subclass of MockFoo
13212// that prints a warning when an uninteresting call occurs, and
13213// StrictMock<MockFoo> is a subclass of MockFoo that treats all
13214// uninteresting calls as errors.
13215//
13216// Currently a mock is naggy by default, so MockFoo and
13217// NaggyMock<MockFoo> behave like the same. However, we will soon
13218// switch the default behavior of mocks to be nice, as that in general
13219// leads to more maintainable tests. When that happens, MockFoo will
13220// stop behaving like NaggyMock<MockFoo> and start behaving like
13221// NiceMock<MockFoo>.
13222//
13223// NiceMock, NaggyMock, and StrictMock "inherit" the constructors of
13224// their respective base class. Therefore you can write
13225// NiceMock<MockFoo>(5, "a") to construct a nice mock where MockFoo
13226// has a constructor that accepts (int, const char*), for example.
13227//
13228// A known limitation is that NiceMock<MockFoo>, NaggyMock<MockFoo>,
13229// and StrictMock<MockFoo> only works for mock methods defined using
13230// the MOCK_METHOD* family of macros DIRECTLY in the MockFoo class.
13231// If a mock method is defined in a base class of MockFoo, the "nice"
13232// or "strict" modifier may not affect it, depending on the compiler.
13233// In particular, nesting NiceMock, NaggyMock, and StrictMock is NOT
13234// supported.
13235
13236// GOOGLETEST_CM0002 DO NOT DELETE
13237
13238#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_NICE_STRICT_H_
13239#define GMOCK_INCLUDE_GMOCK_GMOCK_NICE_STRICT_H_
13240
13241
13242namespace testing {
13243
13244template <class MockClass>
13245class NiceMock : public MockClass {
13246 public:
13247 NiceMock() : MockClass() {
13248 ::testing::Mock::AllowUninterestingCalls(
13249 internal::ImplicitCast_<MockClass*>(this));
13250 }
13251
13252 // Ideally, we would inherit base class's constructors through a using
13253 // declaration, which would preserve their visibility. However, many existing
13254 // tests rely on the fact that current implementation reexports protected
13255 // constructors as public. These tests would need to be cleaned up first.
13256
13257 // Single argument constructor is special-cased so that it can be
13258 // made explicit.
13259 template <typename A>
13260 explicit NiceMock(A&& arg) : MockClass(std::forward<A>(arg)) {
13261 ::testing::Mock::AllowUninterestingCalls(
13262 internal::ImplicitCast_<MockClass*>(this));
13263 }
13264
13265 template <typename A1, typename A2, typename... An>
13266 NiceMock(A1&& arg1, A2&& arg2, An&&... args)
13267 : MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2),
13268 std::forward<An>(args)...) {
13269 ::testing::Mock::AllowUninterestingCalls(
13270 internal::ImplicitCast_<MockClass*>(this));
13271 }
13272
13273 ~NiceMock() { // NOLINT
13274 ::testing::Mock::UnregisterCallReaction(
13275 internal::ImplicitCast_<MockClass*>(this));
13276 }
13277
13278 private:
13279 GTEST_DISALLOW_COPY_AND_ASSIGN_(NiceMock);
13280};
13281
13282template <class MockClass>
13283class NaggyMock : public MockClass {
13284 public:
13285 NaggyMock() : MockClass() {
13286 ::testing::Mock::WarnUninterestingCalls(
13287 internal::ImplicitCast_<MockClass*>(this));
13288 }
13289
13290 // Ideally, we would inherit base class's constructors through a using
13291 // declaration, which would preserve their visibility. However, many existing
13292 // tests rely on the fact that current implementation reexports protected
13293 // constructors as public. These tests would need to be cleaned up first.
13294
13295 // Single argument constructor is special-cased so that it can be
13296 // made explicit.
13297 template <typename A>
13298 explicit NaggyMock(A&& arg) : MockClass(std::forward<A>(arg)) {
13299 ::testing::Mock::WarnUninterestingCalls(
13300 internal::ImplicitCast_<MockClass*>(this));
13301 }
13302
13303 template <typename A1, typename A2, typename... An>
13304 NaggyMock(A1&& arg1, A2&& arg2, An&&... args)
13305 : MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2),
13306 std::forward<An>(args)...) {
13307 ::testing::Mock::WarnUninterestingCalls(
13308 internal::ImplicitCast_<MockClass*>(this));
13309 }
13310
13311 ~NaggyMock() { // NOLINT
13312 ::testing::Mock::UnregisterCallReaction(
13313 internal::ImplicitCast_<MockClass*>(this));
13314 }
13315
13316 private:
13317 GTEST_DISALLOW_COPY_AND_ASSIGN_(NaggyMock);
13318};
13319
13320template <class MockClass>
13321class StrictMock : public MockClass {
13322 public:
13323 StrictMock() : MockClass() {
13324 ::testing::Mock::FailUninterestingCalls(
13325 internal::ImplicitCast_<MockClass*>(this));
13326 }
13327
13328 // Ideally, we would inherit base class's constructors through a using
13329 // declaration, which would preserve their visibility. However, many existing
13330 // tests rely on the fact that current implementation reexports protected
13331 // constructors as public. These tests would need to be cleaned up first.
13332
13333 // Single argument constructor is special-cased so that it can be
13334 // made explicit.
13335 template <typename A>
13336 explicit StrictMock(A&& arg) : MockClass(std::forward<A>(arg)) {
13337 ::testing::Mock::FailUninterestingCalls(
13338 internal::ImplicitCast_<MockClass*>(this));
13339 }
13340
13341 template <typename A1, typename A2, typename... An>
13342 StrictMock(A1&& arg1, A2&& arg2, An&&... args)
13343 : MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2),
13344 std::forward<An>(args)...) {
13345 ::testing::Mock::FailUninterestingCalls(
13346 internal::ImplicitCast_<MockClass*>(this));
13347 }
13348
13349 ~StrictMock() { // NOLINT
13350 ::testing::Mock::UnregisterCallReaction(
13351 internal::ImplicitCast_<MockClass*>(this));
13352 }
13353
13354 private:
13355 GTEST_DISALLOW_COPY_AND_ASSIGN_(StrictMock);
13356};
13357
13358// The following specializations catch some (relatively more common)
13359// user errors of nesting nice and strict mocks. They do NOT catch
13360// all possible errors.
13361
13362// These specializations are declared but not defined, as NiceMock,
13363// NaggyMock, and StrictMock cannot be nested.
13364
13365template <typename MockClass>
13366class NiceMock<NiceMock<MockClass> >;
13367template <typename MockClass>
13368class NiceMock<NaggyMock<MockClass> >;
13369template <typename MockClass>
13370class NiceMock<StrictMock<MockClass> >;
13371
13372template <typename MockClass>
13373class NaggyMock<NiceMock<MockClass> >;
13374template <typename MockClass>
13375class NaggyMock<NaggyMock<MockClass> >;
13376template <typename MockClass>
13377class NaggyMock<StrictMock<MockClass> >;
13378
13379template <typename MockClass>
13380class StrictMock<NiceMock<MockClass> >;
13381template <typename MockClass>
13382class StrictMock<NaggyMock<MockClass> >;
13383template <typename MockClass>
13384class StrictMock<StrictMock<MockClass> >;
13385
13386} // namespace testing
13387
13388#endif // GMOCK_INCLUDE_GMOCK_GMOCK_NICE_STRICT_H_
Austin Schuh70cc9552019-01-21 19:46:48 -080013389
13390namespace testing {
13391
13392// Declares Google Mock flags that we want a user to use programmatically.
13393GMOCK_DECLARE_bool_(catch_leaked_mocks);
13394GMOCK_DECLARE_string_(verbose);
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080013395GMOCK_DECLARE_int32_(default_mock_behavior);
Austin Schuh70cc9552019-01-21 19:46:48 -080013396
13397// Initializes Google Mock. This must be called before running the
13398// tests. In particular, it parses the command line for the flags
13399// that Google Mock recognizes. Whenever a Google Mock flag is seen,
13400// it is removed from argv, and *argc is decremented.
13401//
13402// No value is returned. Instead, the Google Mock flag variables are
13403// updated.
13404//
13405// Since Google Test is needed for Google Mock to work, this function
13406// also initializes Google Test and parses its flags, if that hasn't
13407// been done.
13408GTEST_API_ void InitGoogleMock(int* argc, char** argv);
13409
13410// This overloaded version can be used in Windows programs compiled in
13411// UNICODE mode.
13412GTEST_API_ void InitGoogleMock(int* argc, wchar_t** argv);
13413
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080013414// This overloaded version can be used on Arduino/embedded platforms where
13415// there is no argc/argv.
13416GTEST_API_ void InitGoogleMock();
13417
Austin Schuh70cc9552019-01-21 19:46:48 -080013418} // namespace testing
13419
13420#endif // GMOCK_INCLUDE_GMOCK_GMOCK_H_