1 // Copyright 2007, Google Inc.
2 // All rights reserved.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
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
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.
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.
30 // Author: wan@google.com (Zhanyong Wan)
32 // Google Mock - a framework for writing C++ mock classes.
34 // This is the main header file a user should include.
36 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_H_
37 #define GMOCK_INCLUDE_GMOCK_GMOCK_H_
39 // This file implements the following syntax:
41 // ON_CALL(mock_object.Method(...))
43 // .WillByDefault(...);
45 // where With() is optional and WillByDefault() must appear exactly
48 // EXPECT_CALL(mock_object.Method(...))
53 // .WillRepeatedly(...) ?
54 // .RetiresOnSaturation() ? ;
56 // where all clauses are optional and WillOnce() can be repeated.
58 // Copyright 2007, Google Inc.
59 // All rights reserved.
61 // Redistribution and use in source and binary forms, with or without
62 // modification, are permitted provided that the following conditions are
65 // * Redistributions of source code must retain the above copyright
66 // notice, this list of conditions and the following disclaimer.
67 // * Redistributions in binary form must reproduce the above
68 // copyright notice, this list of conditions and the following disclaimer
69 // in the documentation and/or other materials provided with the
71 // * Neither the name of Google Inc. nor the names of its
72 // contributors may be used to endorse or promote products derived from
73 // this software without specific prior written permission.
75 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
76 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
77 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
78 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
79 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
80 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
81 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
82 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
83 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
84 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
85 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
87 // Author: wan@google.com (Zhanyong Wan)
89 // Google Mock - a framework for writing C++ mock classes.
91 // This file implements some commonly used actions.
93 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
94 #define GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
103 // Copyright 2007, Google Inc.
104 // All rights reserved.
106 // Redistribution and use in source and binary forms, with or without
107 // modification, are permitted provided that the following conditions are
110 // * Redistributions of source code must retain the above copyright
111 // notice, this list of conditions and the following disclaimer.
112 // * Redistributions in binary form must reproduce the above
113 // copyright notice, this list of conditions and the following disclaimer
114 // in the documentation and/or other materials provided with the
116 // * Neither the name of Google Inc. nor the names of its
117 // contributors may be used to endorse or promote products derived from
118 // this software without specific prior written permission.
120 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
121 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
122 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
123 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
124 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
125 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
126 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
127 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
128 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
129 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
130 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
132 // Author: wan@google.com (Zhanyong Wan)
134 // Google Mock - a framework for writing C++ mock classes.
136 // This file defines some utilities useful for implementing Google
137 // Mock. They are subject to change without notice, so please DO NOT
138 // USE THEM IN USER CODE.
140 #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
141 #define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
144 #include <ostream> // NOLINT
147 // This file was GENERATED by command:
148 // pump.py gmock-generated-internal-utils.h.pump
149 // DO NOT EDIT BY HAND!!!
151 // Copyright 2007, Google Inc.
152 // All rights reserved.
154 // Redistribution and use in source and binary forms, with or without
155 // modification, are permitted provided that the following conditions are
158 // * Redistributions of source code must retain the above copyright
159 // notice, this list of conditions and the following disclaimer.
160 // * Redistributions in binary form must reproduce the above
161 // copyright notice, this list of conditions and the following disclaimer
162 // in the documentation and/or other materials provided with the
164 // * Neither the name of Google Inc. nor the names of its
165 // contributors may be used to endorse or promote products derived from
166 // this software without specific prior written permission.
168 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
169 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
170 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
171 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
172 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
173 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
174 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
175 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
176 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
177 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
178 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
180 // Author: wan@google.com (Zhanyong Wan)
182 // Google Mock - a framework for writing C++ mock classes.
184 // This file contains template meta-programming utility classes needed
185 // for implementing Google Mock.
187 #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_
188 #define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_
190 // Copyright 2008, Google Inc.
191 // All rights reserved.
193 // Redistribution and use in source and binary forms, with or without
194 // modification, are permitted provided that the following conditions are
197 // * Redistributions of source code must retain the above copyright
198 // notice, this list of conditions and the following disclaimer.
199 // * Redistributions in binary form must reproduce the above
200 // copyright notice, this list of conditions and the following disclaimer
201 // in the documentation and/or other materials provided with the
203 // * Neither the name of Google Inc. nor the names of its
204 // contributors may be used to endorse or promote products derived from
205 // this software without specific prior written permission.
207 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
208 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
209 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
210 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
211 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
213 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
214 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
215 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
216 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
217 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
219 // Author: vadimb@google.com (Vadim Berman)
221 // Low-level types and utilities for porting Google Mock to various
222 // platforms. All macros ending with _ and symbols defined in an
223 // internal namespace are subject to change without notice. Code
224 // outside Google Mock MUST NOT USE THEM DIRECTLY. Macros that don't
225 // end with _ are part of Google Mock's public API and can be used by
226 // code outside Google Mock.
228 #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_
229 #define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_
235 // Most of the utilities needed for porting Google Mock are also
236 // required for Google Test and are defined in gtest-port.h.
238 // Note to maintainers: to reduce code duplication, prefer adding
239 // portability utilities to Google Test's gtest-port.h instead of
240 // here, as Google Mock depends on Google Test. Only add a utility
241 // here if it's truly specific to Google Mock.
242 #include "gtest/gtest.h"
243 // Copyright 2015, Google Inc.
244 // All rights reserved.
246 // Redistribution and use in source and binary forms, with or without
247 // modification, are permitted provided that the following conditions are
250 // * Redistributions of source code must retain the above copyright
251 // notice, this list of conditions and the following disclaimer.
252 // * Redistributions in binary form must reproduce the above
253 // copyright notice, this list of conditions and the following disclaimer
254 // in the documentation and/or other materials provided with the
256 // * Neither the name of Google Inc. nor the names of its
257 // contributors may be used to endorse or promote products derived from
258 // this software without specific prior written permission.
260 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
261 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
262 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
263 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
264 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
265 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
266 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
267 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
268 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
269 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
270 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272 // Injection point for custom user configurations.
273 // The following macros can be defined:
275 // Flag related macros:
276 // GMOCK_DECLARE_bool_(name)
277 // GMOCK_DECLARE_int32_(name)
278 // GMOCK_DECLARE_string_(name)
279 // GMOCK_DEFINE_bool_(name, default_val, doc)
280 // GMOCK_DEFINE_int32_(name, default_val, doc)
281 // GMOCK_DEFINE_string_(name, default_val, doc)
283 // ** Custom implementation starts here **
285 #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_
286 #define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_
288 #endif // GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_
290 // To avoid conditional compilation everywhere, we make it
291 // gmock-port.h's responsibility to #include the header implementing
292 // tr1/tuple. gmock-port.h does this via gtest-port.h, which is
293 // guaranteed to pull in the tuple header.
295 // For MS Visual C++, check the compiler version. At least VS 2003 is
296 // required to compile Google Mock.
297 #if defined(_MSC_VER) && _MSC_VER < 1310
298 # error "At least Visual C++ 2003 (7.1) is required to compile Google Mock."
301 // Macro for referencing flags. This is public as we want the user to
302 // use this syntax to reference Google Mock flags.
303 #define GMOCK_FLAG(name) FLAGS_gmock_##name
305 #if !defined(GMOCK_DECLARE_bool_)
307 // Macros for declaring flags.
308 #define GMOCK_DECLARE_bool_(name) extern GTEST_API_ bool GMOCK_FLAG(name)
309 #define GMOCK_DECLARE_int32_(name) \
310 extern GTEST_API_ ::testing::internal::Int32 GMOCK_FLAG(name)
311 #define GMOCK_DECLARE_string_(name) \
312 extern GTEST_API_ ::std::string GMOCK_FLAG(name)
314 // Macros for defining flags.
315 #define GMOCK_DEFINE_bool_(name, default_val, doc) \
316 GTEST_API_ bool GMOCK_FLAG(name) = (default_val)
317 #define GMOCK_DEFINE_int32_(name, default_val, doc) \
318 GTEST_API_ ::testing::internal::Int32 GMOCK_FLAG(name) = (default_val)
319 #define GMOCK_DEFINE_string_(name, default_val, doc) \
320 GTEST_API_ ::std::string GMOCK_FLAG(name) = (default_val)
322 #endif // !defined(GMOCK_DECLARE_bool_)
324 #endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_
328 template <typename T>
333 // An IgnoredValue object can be implicitly constructed from ANY value.
334 // This is used in implementing the IgnoreResult(a) action.
337 // This constructor template allows any value to be implicitly
338 // converted to IgnoredValue. The object has no data member and
339 // doesn't try to remember anything about the argument. We
340 // deliberately omit the 'explicit' keyword in order to allow the
341 // conversion to be implicit.
342 template <typename T>
343 IgnoredValue(const T& /* ignored */) {} // NOLINT(runtime/explicit)
346 // MatcherTuple<T>::type is a tuple type where each field is a Matcher
347 // for the corresponding field in tuple type T.
348 template <typename Tuple>
352 struct MatcherTuple< ::testing::tuple<> > {
353 typedef ::testing::tuple< > type;
356 template <typename A1>
357 struct MatcherTuple< ::testing::tuple<A1> > {
358 typedef ::testing::tuple<Matcher<A1> > type;
361 template <typename A1, typename A2>
362 struct MatcherTuple< ::testing::tuple<A1, A2> > {
363 typedef ::testing::tuple<Matcher<A1>, Matcher<A2> > type;
366 template <typename A1, typename A2, typename A3>
367 struct MatcherTuple< ::testing::tuple<A1, A2, A3> > {
368 typedef ::testing::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3> > type;
371 template <typename A1, typename A2, typename A3, typename A4>
372 struct MatcherTuple< ::testing::tuple<A1, A2, A3, A4> > {
373 typedef ::testing::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>,
377 template <typename A1, typename A2, typename A3, typename A4, typename A5>
378 struct MatcherTuple< ::testing::tuple<A1, A2, A3, A4, A5> > {
379 typedef ::testing::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
383 template <typename A1, typename A2, typename A3, typename A4, typename A5,
385 struct MatcherTuple< ::testing::tuple<A1, A2, A3, A4, A5, A6> > {
386 typedef ::testing::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
387 Matcher<A5>, Matcher<A6> > type;
390 template <typename A1, typename A2, typename A3, typename A4, typename A5,
391 typename A6, typename A7>
392 struct MatcherTuple< ::testing::tuple<A1, A2, A3, A4, A5, A6, A7> > {
393 typedef ::testing::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
394 Matcher<A5>, Matcher<A6>, Matcher<A7> > type;
397 template <typename A1, typename A2, typename A3, typename A4, typename A5,
398 typename A6, typename A7, typename A8>
399 struct MatcherTuple< ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8> > {
400 typedef ::testing::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
401 Matcher<A5>, Matcher<A6>, Matcher<A7>, Matcher<A8> > type;
404 template <typename A1, typename A2, typename A3, typename A4, typename A5,
405 typename A6, typename A7, typename A8, typename A9>
406 struct MatcherTuple< ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9> > {
407 typedef ::testing::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
408 Matcher<A5>, Matcher<A6>, Matcher<A7>, Matcher<A8>, Matcher<A9> > type;
411 template <typename A1, typename A2, typename A3, typename A4, typename A5,
412 typename A6, typename A7, typename A8, typename A9, typename A10>
413 struct MatcherTuple< ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9,
415 typedef ::testing::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
416 Matcher<A5>, Matcher<A6>, Matcher<A7>, Matcher<A8>, Matcher<A9>,
420 // Template struct Function<F>, where F must be a function type, contains
421 // the following typedefs:
423 // Result: the function's return type.
424 // ArgumentN: the type of the N-th argument, where N starts with 1.
425 // ArgumentTuple: the tuple type consisting of all parameters of F.
426 // ArgumentMatcherTuple: the tuple type consisting of Matchers for all
428 // MakeResultVoid: the function type obtained by substituting void
429 // for the return type of F.
430 // MakeResultIgnoredValue:
431 // the function type obtained by substituting Something
432 // for the return type of F.
433 template <typename F>
436 template <typename R>
437 struct Function<R()> {
439 typedef ::testing::tuple<> ArgumentTuple;
440 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
441 typedef void MakeResultVoid();
442 typedef IgnoredValue MakeResultIgnoredValue();
445 template <typename R, typename A1>
446 struct Function<R(A1)>
448 typedef A1 Argument1;
449 typedef ::testing::tuple<A1> ArgumentTuple;
450 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
451 typedef void MakeResultVoid(A1);
452 typedef IgnoredValue MakeResultIgnoredValue(A1);
455 template <typename R, typename A1, typename A2>
456 struct Function<R(A1, A2)>
458 typedef A2 Argument2;
459 typedef ::testing::tuple<A1, A2> ArgumentTuple;
460 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
461 typedef void MakeResultVoid(A1, A2);
462 typedef IgnoredValue MakeResultIgnoredValue(A1, A2);
465 template <typename R, typename A1, typename A2, typename A3>
466 struct Function<R(A1, A2, A3)>
467 : Function<R(A1, A2)> {
468 typedef A3 Argument3;
469 typedef ::testing::tuple<A1, A2, A3> ArgumentTuple;
470 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
471 typedef void MakeResultVoid(A1, A2, A3);
472 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3);
475 template <typename R, typename A1, typename A2, typename A3, typename A4>
476 struct Function<R(A1, A2, A3, A4)>
477 : Function<R(A1, A2, A3)> {
478 typedef A4 Argument4;
479 typedef ::testing::tuple<A1, A2, A3, A4> ArgumentTuple;
480 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
481 typedef void MakeResultVoid(A1, A2, A3, A4);
482 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4);
485 template <typename R, typename A1, typename A2, typename A3, typename A4,
487 struct Function<R(A1, A2, A3, A4, A5)>
488 : Function<R(A1, A2, A3, A4)> {
489 typedef A5 Argument5;
490 typedef ::testing::tuple<A1, A2, A3, A4, A5> ArgumentTuple;
491 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
492 typedef void MakeResultVoid(A1, A2, A3, A4, A5);
493 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5);
496 template <typename R, typename A1, typename A2, typename A3, typename A4,
497 typename A5, typename A6>
498 struct Function<R(A1, A2, A3, A4, A5, A6)>
499 : Function<R(A1, A2, A3, A4, A5)> {
500 typedef A6 Argument6;
501 typedef ::testing::tuple<A1, A2, A3, A4, A5, A6> ArgumentTuple;
502 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
503 typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6);
504 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6);
507 template <typename R, typename A1, typename A2, typename A3, typename A4,
508 typename A5, typename A6, typename A7>
509 struct Function<R(A1, A2, A3, A4, A5, A6, A7)>
510 : Function<R(A1, A2, A3, A4, A5, A6)> {
511 typedef A7 Argument7;
512 typedef ::testing::tuple<A1, A2, A3, A4, A5, A6, A7> ArgumentTuple;
513 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
514 typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7);
515 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7);
518 template <typename R, typename A1, typename A2, typename A3, typename A4,
519 typename A5, typename A6, typename A7, typename A8>
520 struct Function<R(A1, A2, A3, A4, A5, A6, A7, A8)>
521 : Function<R(A1, A2, A3, A4, A5, A6, A7)> {
522 typedef A8 Argument8;
523 typedef ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8> ArgumentTuple;
524 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
525 typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7, A8);
526 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7, A8);
529 template <typename R, typename A1, typename A2, typename A3, typename A4,
530 typename A5, typename A6, typename A7, typename A8, typename A9>
531 struct Function<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)>
532 : Function<R(A1, A2, A3, A4, A5, A6, A7, A8)> {
533 typedef A9 Argument9;
534 typedef ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9> ArgumentTuple;
535 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
536 typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7, A8, A9);
537 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7, A8,
541 template <typename R, typename A1, typename A2, typename A3, typename A4,
542 typename A5, typename A6, typename A7, typename A8, typename A9,
544 struct Function<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)>
545 : Function<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> {
546 typedef A10 Argument10;
547 typedef ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9,
549 typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
550 typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10);
551 typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7, A8,
555 } // namespace internal
557 } // namespace testing
559 #endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_
564 // Converts an identifier name to a space-separated list of lower-case
565 // words. Each maximum substring of the form [A-Za-z][a-z]*|\d+ is
566 // treated as one word. For example, both "FooBar123" and
567 // "foo_bar_123" are converted to "foo bar 123".
568 GTEST_API_ string ConvertIdentifierNameToWords(const char* id_name);
570 // PointeeOf<Pointer>::type is the type of a value pointed to by a
571 // Pointer, which can be either a smart pointer or a raw pointer. The
572 // following default implementation is for the case where Pointer is a
574 template <typename Pointer>
576 // Smart pointer classes define type element_type as the type of
578 typedef typename Pointer::element_type type;
580 // This specialization is for the raw pointer case.
581 template <typename T>
582 struct PointeeOf<T*> { typedef T type; }; // NOLINT
584 // GetRawPointer(p) returns the raw pointer underlying p when p is a
585 // smart pointer, or returns p itself when p is already a raw pointer.
586 // The following default implementation is for the smart pointer case.
587 template <typename Pointer>
588 inline const typename Pointer::element_type* GetRawPointer(const Pointer& p) {
591 // This overloaded version is for the raw pointer case.
592 template <typename Element>
593 inline Element* GetRawPointer(Element* p) { return p; }
595 // This comparator allows linked_ptr to be stored in sets.
596 template <typename T>
597 struct LinkedPtrLessThan {
598 bool operator()(const ::testing::internal::linked_ptr<T>& lhs,
599 const ::testing::internal::linked_ptr<T>& rhs) const {
600 return lhs.get() < rhs.get();
604 // Symbian compilation can be done with wchar_t being either a native
605 // type or a typedef. Using Google Mock with OpenC without wchar_t
606 // should require the definition of _STLP_NO_WCHAR_T.
608 // MSVC treats wchar_t as a native type usually, but treats it as the
609 // same as unsigned short when the compiler option /Zc:wchar_t- is
610 // specified. It defines _NATIVE_WCHAR_T_DEFINED symbol when wchar_t
612 #if (GTEST_OS_SYMBIAN && defined(_STLP_NO_WCHAR_T)) || \
613 (defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED))
614 // wchar_t is a typedef.
616 # define GMOCK_WCHAR_T_IS_NATIVE_ 1
619 // signed wchar_t and unsigned wchar_t are NOT in the C++ standard.
620 // Using them is a bad practice and not portable. So DON'T use them.
622 // Still, Google Mock is designed to work even if the user uses signed
623 // wchar_t or unsigned wchar_t (obviously, assuming the compiler
627 // wchar_t == signed wchar_t != unsigned wchar_t == unsigned int
629 // signed/unsigned wchar_t are valid types.
630 # define GMOCK_HAS_SIGNED_WCHAR_T_ 1
633 // In what follows, we use the term "kind" to indicate whether a type
634 // is bool, an integer type (excluding bool), a floating-point type,
635 // or none of them. This categorization is useful for determining
636 // when a matcher argument type can be safely converted to another
637 // type in the implementation of SafeMatcherCast.
639 kBool, kInteger, kFloatingPoint, kOther
642 // KindOf<T>::value is the kind of type T.
643 template <typename T> struct KindOf {
644 enum { value = kOther }; // The default kind.
647 // This macro declares that the kind of 'type' is 'kind'.
648 #define GMOCK_DECLARE_KIND_(type, kind) \
649 template <> struct KindOf<type> { enum { value = kind }; }
651 GMOCK_DECLARE_KIND_(bool, kBool);
653 // All standard integer types.
654 GMOCK_DECLARE_KIND_(char, kInteger);
655 GMOCK_DECLARE_KIND_(signed char, kInteger);
656 GMOCK_DECLARE_KIND_(unsigned char, kInteger);
657 GMOCK_DECLARE_KIND_(short, kInteger); // NOLINT
658 GMOCK_DECLARE_KIND_(unsigned short, kInteger); // NOLINT
659 GMOCK_DECLARE_KIND_(int, kInteger);
660 GMOCK_DECLARE_KIND_(unsigned int, kInteger);
661 GMOCK_DECLARE_KIND_(long, kInteger); // NOLINT
662 GMOCK_DECLARE_KIND_(unsigned long, kInteger); // NOLINT
664 #if GMOCK_WCHAR_T_IS_NATIVE_
665 GMOCK_DECLARE_KIND_(wchar_t, kInteger);
668 // Non-standard integer types.
669 GMOCK_DECLARE_KIND_(Int64, kInteger);
670 GMOCK_DECLARE_KIND_(UInt64, kInteger);
672 // All standard floating-point types.
673 GMOCK_DECLARE_KIND_(float, kFloatingPoint);
674 GMOCK_DECLARE_KIND_(double, kFloatingPoint);
675 GMOCK_DECLARE_KIND_(long double, kFloatingPoint);
677 #undef GMOCK_DECLARE_KIND_
679 // Evaluates to the kind of 'type'.
680 #define GMOCK_KIND_OF_(type) \
681 static_cast< ::testing::internal::TypeKind>( \
682 ::testing::internal::KindOf<type>::value)
684 // Evaluates to true iff integer type T is signed.
685 #define GMOCK_IS_SIGNED_(T) (static_cast<T>(-1) < 0)
687 // LosslessArithmeticConvertibleImpl<kFromKind, From, kToKind, To>::value
688 // is true iff arithmetic type From can be losslessly converted to
689 // arithmetic type To.
691 // It's the user's responsibility to ensure that both From and To are
692 // raw (i.e. has no CV modifier, is not a pointer, and is not a
693 // reference) built-in arithmetic types, kFromKind is the kind of
694 // From, and kToKind is the kind of To; the value is
695 // implementation-defined when the above pre-condition is violated.
696 template <TypeKind kFromKind, typename From, TypeKind kToKind, typename To>
697 struct LosslessArithmeticConvertibleImpl : public false_type {};
699 // Converting bool to bool is lossless.
701 struct LosslessArithmeticConvertibleImpl<kBool, bool, kBool, bool>
702 : public true_type {}; // NOLINT
704 // Converting bool to any integer type is lossless.
705 template <typename To>
706 struct LosslessArithmeticConvertibleImpl<kBool, bool, kInteger, To>
707 : public true_type {}; // NOLINT
709 // Converting bool to any floating-point type is lossless.
710 template <typename To>
711 struct LosslessArithmeticConvertibleImpl<kBool, bool, kFloatingPoint, To>
712 : public true_type {}; // NOLINT
714 // Converting an integer to bool is lossy.
715 template <typename From>
716 struct LosslessArithmeticConvertibleImpl<kInteger, From, kBool, bool>
717 : public false_type {}; // NOLINT
719 // Converting an integer to another non-bool integer is lossless iff
720 // the target type's range encloses the source type's range.
721 template <typename From, typename To>
722 struct LosslessArithmeticConvertibleImpl<kInteger, From, kInteger, To>
723 : public bool_constant<
724 // When converting from a smaller size to a larger size, we are
725 // fine as long as we are not converting from signed to unsigned.
726 ((sizeof(From) < sizeof(To)) &&
727 (!GMOCK_IS_SIGNED_(From) || GMOCK_IS_SIGNED_(To))) ||
728 // When converting between the same size, the signedness must match.
729 ((sizeof(From) == sizeof(To)) &&
730 (GMOCK_IS_SIGNED_(From) == GMOCK_IS_SIGNED_(To)))> {}; // NOLINT
732 #undef GMOCK_IS_SIGNED_
734 // Converting an integer to a floating-point type may be lossy, since
735 // the format of a floating-point number is implementation-defined.
736 template <typename From, typename To>
737 struct LosslessArithmeticConvertibleImpl<kInteger, From, kFloatingPoint, To>
738 : public false_type {}; // NOLINT
740 // Converting a floating-point to bool is lossy.
741 template <typename From>
742 struct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kBool, bool>
743 : public false_type {}; // NOLINT
745 // Converting a floating-point to an integer is lossy.
746 template <typename From, typename To>
747 struct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kInteger, To>
748 : public false_type {}; // NOLINT
750 // Converting a floating-point to another floating-point is lossless
751 // iff the target type is at least as big as the source type.
752 template <typename From, typename To>
753 struct LosslessArithmeticConvertibleImpl<
754 kFloatingPoint, From, kFloatingPoint, To>
755 : public bool_constant<sizeof(From) <= sizeof(To)> {}; // NOLINT
757 // LosslessArithmeticConvertible<From, To>::value is true iff arithmetic
758 // type From can be losslessly converted to arithmetic type To.
760 // It's the user's responsibility to ensure that both From and To are
761 // raw (i.e. has no CV modifier, is not a pointer, and is not a
762 // reference) built-in arithmetic types; the value is
763 // implementation-defined when the above pre-condition is violated.
764 template <typename From, typename To>
765 struct LosslessArithmeticConvertible
766 : public LosslessArithmeticConvertibleImpl<
767 GMOCK_KIND_OF_(From), From, GMOCK_KIND_OF_(To), To> {}; // NOLINT
769 // This interface knows how to report a Google Mock failure (either
770 // non-fatal or fatal).
771 class FailureReporterInterface {
773 // The type of a failure (either non-fatal or fatal).
778 virtual ~FailureReporterInterface() {}
780 // Reports a failure that occurred at the given source file location.
781 virtual void ReportFailure(FailureType type, const char* file, int line,
782 const string& message) = 0;
785 // Returns the failure reporter used by Google Mock.
786 GTEST_API_ FailureReporterInterface* GetFailureReporter();
788 // Asserts that condition is true; aborts the process with the given
789 // message if condition is false. We cannot use LOG(FATAL) or CHECK()
790 // as Google Mock might be used to mock the log sink itself. We
791 // inline this function to prevent it from showing up in the stack
793 inline void Assert(bool condition, const char* file, int line,
796 GetFailureReporter()->ReportFailure(FailureReporterInterface::kFatal,
800 inline void Assert(bool condition, const char* file, int line) {
801 Assert(condition, file, line, "Assertion failed.");
804 // Verifies that condition is true; generates a non-fatal failure if
805 // condition is false.
806 inline void Expect(bool condition, const char* file, int line,
809 GetFailureReporter()->ReportFailure(FailureReporterInterface::kNonfatal,
813 inline void Expect(bool condition, const char* file, int line) {
814 Expect(condition, file, line, "Expectation failed.");
817 // Severity level of a log.
823 // Valid values for the --gmock_verbose flag.
825 // All logs (informational and warnings) are printed.
826 const char kInfoVerbosity[] = "info";
827 // Only warnings are printed.
828 const char kWarningVerbosity[] = "warning";
829 // No logs are printed.
830 const char kErrorVerbosity[] = "error";
832 // Returns true iff a log with the given severity is visible according
833 // to the --gmock_verbose flag.
834 GTEST_API_ bool LogIsVisible(LogSeverity severity);
836 // Prints the given message to stdout iff 'severity' >= the level
837 // specified by the --gmock_verbose flag. If stack_frames_to_skip >=
838 // 0, also prints the stack trace excluding the top
839 // stack_frames_to_skip frames. In opt mode, any positive
840 // stack_frames_to_skip is treated as 0, since we don't know which
841 // function calls will be inlined by the compiler and need to be
843 GTEST_API_ void Log(LogSeverity severity,
844 const string& message,
845 int stack_frames_to_skip);
847 // TODO(wan@google.com): group all type utilities together.
851 // is_reference<T>::value is non-zero iff T is a reference type.
852 template <typename T> struct is_reference : public false_type {};
853 template <typename T> struct is_reference<T&> : public true_type {};
855 // type_equals<T1, T2>::value is non-zero iff T1 and T2 are the same type.
856 template <typename T1, typename T2> struct type_equals : public false_type {};
857 template <typename T> struct type_equals<T, T> : public true_type {};
859 // remove_reference<T>::type removes the reference from type T, if any.
860 template <typename T> struct remove_reference { typedef T type; }; // NOLINT
861 template <typename T> struct remove_reference<T&> { typedef T type; }; // NOLINT
863 // DecayArray<T>::type turns an array type U[N] to const U* and preserves
864 // other types. Useful for saving a copy of a function argument.
865 template <typename T> struct DecayArray { typedef T type; }; // NOLINT
866 template <typename T, size_t N> struct DecayArray<T[N]> {
867 typedef const T* type;
869 // Sometimes people use arrays whose size is not available at the use site
870 // (e.g. extern const char kNamePrefix[]). This specialization covers that
872 template <typename T> struct DecayArray<T[]> {
873 typedef const T* type;
876 // Disable MSVC warnings for infinite recursion, since in this case the
877 // the recursion is unreachable.
879 # pragma warning(push)
880 # pragma warning(disable:4717)
883 // Invalid<T>() is usable as an expression of type T, but will terminate
884 // the program with an assertion failure if actually run. This is useful
885 // when a value of type T is needed for compilation, but the statement
886 // will not really be executed (or we don't care if the statement
888 template <typename T>
890 Assert(false, "", -1, "Internal error: attempt to return invalid value");
891 // This statement is unreachable, and would never terminate even if it
892 // could be reached. It is provided only to placate compiler warnings
893 // about missing return statements.
898 # pragma warning(pop)
901 // Given a raw type (i.e. having no top-level reference or const
902 // modifier) RawContainer that's either an STL-style container or a
903 // native array, class StlContainerView<RawContainer> has the
904 // following members:
906 // - type is a type that provides an STL-style container view to
907 // (i.e. implements the STL container concept for) RawContainer;
908 // - const_reference is a type that provides a reference to a const
910 // - ConstReference(raw_container) returns a const reference to an STL-style
911 // container view to raw_container, which is a RawContainer.
912 // - Copy(raw_container) returns an STL-style container view of a
913 // copy of raw_container, which is a RawContainer.
915 // This generic version is used when RawContainer itself is already an
916 // STL-style container.
917 template <class RawContainer>
918 class StlContainerView {
920 typedef RawContainer type;
921 typedef const type& const_reference;
923 static const_reference ConstReference(const RawContainer& container) {
924 // Ensures that RawContainer is not a const type.
925 testing::StaticAssertTypeEq<RawContainer,
926 GTEST_REMOVE_CONST_(RawContainer)>();
929 static type Copy(const RawContainer& container) { return container; }
932 // This specialization is used when RawContainer is a native array type.
933 template <typename Element, size_t N>
934 class StlContainerView<Element[N]> {
936 typedef GTEST_REMOVE_CONST_(Element) RawElement;
937 typedef internal::NativeArray<RawElement> type;
938 // NativeArray<T> can represent a native array either by value or by
939 // reference (selected by a constructor argument), so 'const type'
940 // can be used to reference a const native array. We cannot
941 // 'typedef const type& const_reference' here, as that would mean
942 // ConstReference() has to return a reference to a local variable.
943 typedef const type const_reference;
945 static const_reference ConstReference(const Element (&array)[N]) {
946 // Ensures that Element is not a const type.
947 testing::StaticAssertTypeEq<Element, RawElement>();
949 // The Nokia Symbian compiler confuses itself in template instantiation
950 // for this call without the cast to Element*:
951 // function call '[testing::internal::NativeArray<char *>].NativeArray(
952 // {lval} const char *[4], long, testing::internal::RelationToSource)'
954 // 'testing::internal::NativeArray<char *>::NativeArray(
955 // char *const *, unsigned int, testing::internal::RelationToSource)'
956 // (instantiating: 'testing::internal::ContainsMatcherImpl
957 // <const char * (&)[4]>::Matches(const char * (&)[4]) const')
958 // (instantiating: 'testing::internal::StlContainerView<char *[4]>::
959 // ConstReference(const char * (&)[4])')
960 // (and though the N parameter type is mismatched in the above explicit
961 // conversion of it doesn't help - only the conversion of the array).
962 return type(const_cast<Element*>(&array[0]), N,
963 RelationToSourceReference());
965 return type(array, N, RelationToSourceReference());
966 #endif // GTEST_OS_SYMBIAN
968 static type Copy(const Element (&array)[N]) {
970 return type(const_cast<Element*>(&array[0]), N, RelationToSourceCopy());
972 return type(array, N, RelationToSourceCopy());
973 #endif // GTEST_OS_SYMBIAN
977 // This specialization is used when RawContainer is a native array
978 // represented as a (pointer, size) tuple.
979 template <typename ElementPointer, typename Size>
980 class StlContainerView< ::testing::tuple<ElementPointer, Size> > {
982 typedef GTEST_REMOVE_CONST_(
983 typename internal::PointeeOf<ElementPointer>::type) RawElement;
984 typedef internal::NativeArray<RawElement> type;
985 typedef const type const_reference;
987 static const_reference ConstReference(
988 const ::testing::tuple<ElementPointer, Size>& array) {
989 return type(get<0>(array), get<1>(array), RelationToSourceReference());
991 static type Copy(const ::testing::tuple<ElementPointer, Size>& array) {
992 return type(get<0>(array), get<1>(array), RelationToSourceCopy());
996 // The following specialization prevents the user from instantiating
997 // StlContainer with a reference type.
998 template <typename T> class StlContainerView<T&>;
1000 // A type transform to remove constness from the first part of a pair.
1001 // Pairs like that are used as the value_type of associative containers,
1002 // and this transform produces a similar but assignable pair.
1003 template <typename T>
1004 struct RemoveConstFromKey {
1008 // Partially specialized to remove constness from std::pair<const K, V>.
1009 template <typename K, typename V>
1010 struct RemoveConstFromKey<std::pair<const K, V> > {
1011 typedef std::pair<K, V> type;
1014 // Mapping from booleans to types. Similar to boost::bool_<kValue> and
1015 // std::integral_constant<bool, kValue>.
1016 template <bool kValue>
1017 struct BooleanConstant {};
1019 } // namespace internal
1020 } // namespace testing
1022 #endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
1025 #if GTEST_HAS_STD_TYPE_TRAITS_ // Defined by gtest-port.h via gmock-port.h.
1026 #include <type_traits>
1031 // To implement an action Foo, define:
1032 // 1. a class FooAction that implements the ActionInterface interface, and
1033 // 2. a factory function that creates an Action object from a
1034 // const FooAction*.
1036 // The two-level delegation design follows that of Matcher, providing
1037 // consistency for extension developers. It also eases ownership
1038 // management as Action objects can now be copied like plain values.
1040 namespace internal {
1042 template <typename F1, typename F2>
1043 class ActionAdaptor;
1045 // BuiltInDefaultValueGetter<T, true>::Get() returns a
1046 // default-constructed T value. BuiltInDefaultValueGetter<T,
1047 // false>::Get() crashes with an error.
1049 // This primary template is used when kDefaultConstructible is true.
1050 template <typename T, bool kDefaultConstructible>
1051 struct BuiltInDefaultValueGetter {
1052 static T Get() { return T(); }
1054 template <typename T>
1055 struct BuiltInDefaultValueGetter<T, false> {
1057 Assert(false, __FILE__, __LINE__,
1058 "Default action undefined for the function return type.");
1059 return internal::Invalid<T>();
1060 // The above statement will never be reached, but is required in
1061 // order for this function to compile.
1065 // BuiltInDefaultValue<T>::Get() returns the "built-in" default value
1066 // for type T, which is NULL when T is a raw pointer type, 0 when T is
1067 // a numeric type, false when T is bool, or "" when T is string or
1068 // std::string. In addition, in C++11 and above, it turns a
1069 // default-constructed T value if T is default constructible. For any
1070 // other type T, the built-in default T value is undefined, and the
1071 // function will abort the process.
1072 template <typename T>
1073 class BuiltInDefaultValue {
1075 #if GTEST_HAS_STD_TYPE_TRAITS_
1076 // This function returns true iff type T has a built-in default value.
1077 static bool Exists() {
1078 return ::std::is_default_constructible<T>::value;
1082 return BuiltInDefaultValueGetter<
1083 T, ::std::is_default_constructible<T>::value>::Get();
1086 #else // GTEST_HAS_STD_TYPE_TRAITS_
1087 // This function returns true iff type T has a built-in default value.
1088 static bool Exists() {
1093 return BuiltInDefaultValueGetter<T, false>::Get();
1096 #endif // GTEST_HAS_STD_TYPE_TRAITS_
1099 // This partial specialization says that we use the same built-in
1100 // default value for T and const T.
1101 template <typename T>
1102 class BuiltInDefaultValue<const T> {
1104 static bool Exists() { return BuiltInDefaultValue<T>::Exists(); }
1105 static T Get() { return BuiltInDefaultValue<T>::Get(); }
1108 // This partial specialization defines the default values for pointer
1110 template <typename T>
1111 class BuiltInDefaultValue<T*> {
1113 static bool Exists() { return true; }
1114 static T* Get() { return NULL; }
1117 // The following specializations define the default values for
1118 // specific types we care about.
1119 #define GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(type, value) \
1121 class BuiltInDefaultValue<type> { \
1123 static bool Exists() { return true; } \
1124 static type Get() { return value; } \
1127 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(void, ); // NOLINT
1128 #if GTEST_HAS_GLOBAL_STRING
1129 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(::string, "");
1130 #endif // GTEST_HAS_GLOBAL_STRING
1131 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(::std::string, "");
1132 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(bool, false);
1133 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned char, '\0');
1134 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed char, '\0');
1135 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(char, '\0');
1137 // There's no need for a default action for signed wchar_t, as that
1138 // type is the same as wchar_t for gcc, and invalid for MSVC.
1140 // There's also no need for a default action for unsigned wchar_t, as
1141 // that type is the same as unsigned int for gcc, and invalid for
1143 #if GMOCK_WCHAR_T_IS_NATIVE_
1144 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(wchar_t, 0U); // NOLINT
1147 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned short, 0U); // NOLINT
1148 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed short, 0); // NOLINT
1149 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned int, 0U);
1150 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed int, 0);
1151 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned long, 0UL); // NOLINT
1152 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed long, 0L); // NOLINT
1153 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(UInt64, 0);
1154 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(Int64, 0);
1155 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(float, 0);
1156 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(double, 0);
1158 #undef GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_
1160 } // namespace internal
1162 // When an unexpected function call is encountered, Google Mock will
1163 // let it return a default value if the user has specified one for its
1164 // return type, or if the return type has a built-in default value;
1165 // otherwise Google Mock won't know what value to return and will have
1166 // to abort the process.
1168 // The DefaultValue<T> class allows a user to specify the
1169 // default value for a type T that is both copyable and publicly
1170 // destructible (i.e. anything that can be used as a function return
1171 // type). The usage is:
1173 // // Sets the default value for type T to be foo.
1174 // DefaultValue<T>::Set(foo);
1175 template <typename T>
1176 class DefaultValue {
1178 // Sets the default value for type T; requires T to be
1179 // copy-constructable and have a public destructor.
1180 static void Set(T x) {
1182 producer_ = new FixedValueProducer(x);
1185 // Provides a factory function to be called to generate the default value.
1186 // This method can be used even if T is only move-constructible, but it is not
1187 // limited to that case.
1188 typedef T (*FactoryFunction)();
1189 static void SetFactory(FactoryFunction factory) {
1191 producer_ = new FactoryValueProducer(factory);
1194 // Unsets the default value for type T.
1195 static void Clear() {
1200 // Returns true iff the user has set the default value for type T.
1201 static bool IsSet() { return producer_ != NULL; }
1203 // Returns true if T has a default return value set by the user or there
1204 // exists a built-in default value.
1205 static bool Exists() {
1206 return IsSet() || internal::BuiltInDefaultValue<T>::Exists();
1209 // Returns the default value for type T if the user has set one;
1210 // otherwise returns the built-in default value. Requires that Exists()
1211 // is true, which ensures that the return value is well-defined.
1213 return producer_ == NULL ?
1214 internal::BuiltInDefaultValue<T>::Get() : producer_->Produce();
1218 class ValueProducer {
1220 virtual ~ValueProducer() {}
1221 virtual T Produce() = 0;
1224 class FixedValueProducer : public ValueProducer {
1226 explicit FixedValueProducer(T value) : value_(value) {}
1227 virtual T Produce() { return value_; }
1231 GTEST_DISALLOW_COPY_AND_ASSIGN_(FixedValueProducer);
1234 class FactoryValueProducer : public ValueProducer {
1236 explicit FactoryValueProducer(FactoryFunction factory)
1237 : factory_(factory) {}
1238 virtual T Produce() { return factory_(); }
1241 const FactoryFunction factory_;
1242 GTEST_DISALLOW_COPY_AND_ASSIGN_(FactoryValueProducer);
1245 static ValueProducer* producer_;
1248 // This partial specialization allows a user to set default values for
1250 template <typename T>
1251 class DefaultValue<T&> {
1253 // Sets the default value for type T&.
1254 static void Set(T& x) { // NOLINT
1258 // Unsets the default value for type T&.
1259 static void Clear() {
1263 // Returns true iff the user has set the default value for type T&.
1264 static bool IsSet() { return address_ != NULL; }
1266 // Returns true if T has a default return value set by the user or there
1267 // exists a built-in default value.
1268 static bool Exists() {
1269 return IsSet() || internal::BuiltInDefaultValue<T&>::Exists();
1272 // Returns the default value for type T& if the user has set one;
1273 // otherwise returns the built-in default value if there is one;
1274 // otherwise aborts the process.
1276 return address_ == NULL ?
1277 internal::BuiltInDefaultValue<T&>::Get() : *address_;
1284 // This specialization allows DefaultValue<void>::Get() to
1287 class DefaultValue<void> {
1289 static bool Exists() { return true; }
1290 static void Get() {}
1293 // Points to the user-set default value for type T.
1294 template <typename T>
1295 typename DefaultValue<T>::ValueProducer* DefaultValue<T>::producer_ = NULL;
1297 // Points to the user-set default value for type T&.
1298 template <typename T>
1299 T* DefaultValue<T&>::address_ = NULL;
1301 // Implement this interface to define an action for function type F.
1302 template <typename F>
1303 class ActionInterface {
1305 typedef typename internal::Function<F>::Result Result;
1306 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
1308 ActionInterface() {}
1309 virtual ~ActionInterface() {}
1311 // Performs the action. This method is not const, as in general an
1312 // action can have side effects and be stateful. For example, a
1313 // get-the-next-element-from-the-collection action will need to
1314 // remember the current element.
1315 virtual Result Perform(const ArgumentTuple& args) = 0;
1318 GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionInterface);
1321 // An Action<F> is a copyable and IMMUTABLE (except by assignment)
1322 // object that represents an action to be taken when a mock function
1323 // of type F is called. The implementation of Action<T> is just a
1324 // linked_ptr to const ActionInterface<T>, so copying is fairly cheap.
1325 // Don't inherit from Action!
1327 // You can view an object implementing ActionInterface<F> as a
1328 // concrete action (including its current state), and an Action<F>
1329 // object as a handle to it.
1330 template <typename F>
1333 typedef typename internal::Function<F>::Result Result;
1334 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
1336 // Constructs a null Action. Needed for storing Action objects in
1338 Action() : impl_(NULL) {}
1340 // Constructs an Action from its implementation. A NULL impl is
1341 // used to represent the "do-default" action.
1342 explicit Action(ActionInterface<F>* impl) : impl_(impl) {}
1344 // Copy constructor.
1345 Action(const Action& action) : impl_(action.impl_) {}
1347 // This constructor allows us to turn an Action<Func> object into an
1348 // Action<F>, as long as F's arguments can be implicitly converted
1349 // to Func's and Func's return type can be implicitly converted to
1351 template <typename Func>
1352 explicit Action(const Action<Func>& action);
1354 // Returns true iff this is the DoDefault() action.
1355 bool IsDoDefault() const { return impl_.get() == NULL; }
1357 // Performs the action. Note that this method is const even though
1358 // the corresponding method in ActionInterface is not. The reason
1359 // is that a const Action<F> means that it cannot be re-bound to
1360 // another concrete action, not that the concrete action it binds to
1361 // cannot change state. (Think of the difference between a const
1362 // pointer and a pointer to const.)
1363 Result Perform(const ArgumentTuple& args) const {
1365 !IsDoDefault(), __FILE__, __LINE__,
1366 "You are using DoDefault() inside a composite action like "
1367 "DoAll() or WithArgs(). This is not supported for technical "
1368 "reasons. Please instead spell out the default action, or "
1369 "assign the default action to an Action variable and use "
1370 "the variable in various places.");
1371 return impl_->Perform(args);
1375 template <typename F1, typename F2>
1376 friend class internal::ActionAdaptor;
1378 internal::linked_ptr<ActionInterface<F> > impl_;
1381 // The PolymorphicAction class template makes it easy to implement a
1382 // polymorphic action (i.e. an action that can be used in mock
1383 // functions of than one type, e.g. Return()).
1385 // To define a polymorphic action, a user first provides a COPYABLE
1386 // implementation class that has a Perform() method template:
1388 // class FooAction {
1390 // template <typename Result, typename ArgumentTuple>
1391 // Result Perform(const ArgumentTuple& args) const {
1392 // // Processes the arguments and returns a result, using
1393 // // tr1::get<N>(args) to get the N-th (0-based) argument in the tuple.
1398 // Then the user creates the polymorphic action using
1399 // MakePolymorphicAction(object) where object has type FooAction. See
1400 // the definition of Return(void) and SetArgumentPointee<N>(value) for
1401 // complete examples.
1402 template <typename Impl>
1403 class PolymorphicAction {
1405 explicit PolymorphicAction(const Impl& impl) : impl_(impl) {}
1407 template <typename F>
1408 operator Action<F>() const {
1409 return Action<F>(new MonomorphicImpl<F>(impl_));
1413 template <typename F>
1414 class MonomorphicImpl : public ActionInterface<F> {
1416 typedef typename internal::Function<F>::Result Result;
1417 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
1419 explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {}
1421 virtual Result Perform(const ArgumentTuple& args) {
1422 return impl_.template Perform<Result>(args);
1428 GTEST_DISALLOW_ASSIGN_(MonomorphicImpl);
1433 GTEST_DISALLOW_ASSIGN_(PolymorphicAction);
1436 // Creates an Action from its implementation and returns it. The
1437 // created Action object owns the implementation.
1438 template <typename F>
1439 Action<F> MakeAction(ActionInterface<F>* impl) {
1440 return Action<F>(impl);
1443 // Creates a polymorphic action from its implementation. This is
1444 // easier to use than the PolymorphicAction<Impl> constructor as it
1445 // doesn't require you to explicitly write the template argument, e.g.
1447 // MakePolymorphicAction(foo);
1449 // PolymorphicAction<TypeOfFoo>(foo);
1450 template <typename Impl>
1451 inline PolymorphicAction<Impl> MakePolymorphicAction(const Impl& impl) {
1452 return PolymorphicAction<Impl>(impl);
1455 namespace internal {
1457 // Allows an Action<F2> object to pose as an Action<F1>, as long as F2
1458 // and F1 are compatible.
1459 template <typename F1, typename F2>
1460 class ActionAdaptor : public ActionInterface<F1> {
1462 typedef typename internal::Function<F1>::Result Result;
1463 typedef typename internal::Function<F1>::ArgumentTuple ArgumentTuple;
1465 explicit ActionAdaptor(const Action<F2>& from) : impl_(from.impl_) {}
1467 virtual Result Perform(const ArgumentTuple& args) {
1468 return impl_->Perform(args);
1472 const internal::linked_ptr<ActionInterface<F2> > impl_;
1474 GTEST_DISALLOW_ASSIGN_(ActionAdaptor);
1477 // Helper struct to specialize ReturnAction to execute a move instead of a copy
1478 // on return. Useful for move-only types, but could be used on any type.
1479 template <typename T>
1480 struct ByMoveWrapper {
1481 explicit ByMoveWrapper(T value) : payload(internal::move(value)) {}
1485 // Implements the polymorphic Return(x) action, which can be used in
1486 // any function that returns the type of x, regardless of the argument
1489 // Note: The value passed into Return must be converted into
1490 // Function<F>::Result when this action is cast to Action<F> rather than
1491 // when that action is performed. This is important in scenarios like
1493 // MOCK_METHOD1(Method, T(U));
1498 // EXPECT_CALL(mock, Method(_)).WillOnce(Return(x));
1501 // In the example above the variable x holds reference to foo which leaves
1502 // scope and gets destroyed. If copying X just copies a reference to foo,
1503 // that copy will be left with a hanging reference. If conversion to T
1504 // makes a copy of foo, the above code is safe. To support that scenario, we
1505 // need to make sure that the type conversion happens inside the EXPECT_CALL
1506 // statement, and conversion of the result of Return to Action<T(U)> is a
1507 // good place for that.
1509 template <typename R>
1510 class ReturnAction {
1512 // Constructs a ReturnAction object from the value to be returned.
1513 // 'value' is passed by value instead of by const reference in order
1514 // to allow Return("string literal") to compile.
1515 explicit ReturnAction(R value) : value_(new R(internal::move(value))) {}
1517 // This template type conversion operator allows Return(x) to be
1518 // used in ANY function that returns x's type.
1519 template <typename F>
1520 operator Action<F>() const {
1521 // Assert statement belongs here because this is the best place to verify
1522 // conditions on F. It produces the clearest error messages
1523 // in most compilers.
1524 // Impl really belongs in this scope as a local class but can't
1525 // because MSVC produces duplicate symbols in different translation units
1526 // in this case. Until MS fixes that bug we put Impl into the class scope
1527 // and put the typedef both here (for use in assert statement) and
1528 // in the Impl class. But both definitions must be the same.
1529 typedef typename Function<F>::Result Result;
1530 GTEST_COMPILE_ASSERT_(
1531 !is_reference<Result>::value,
1532 use_ReturnRef_instead_of_Return_to_return_a_reference);
1533 return Action<F>(new Impl<R, F>(value_));
1537 // Implements the Return(x) action for a particular function type F.
1538 template <typename R_, typename F>
1539 class Impl : public ActionInterface<F> {
1541 typedef typename Function<F>::Result Result;
1542 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
1544 // The implicit cast is necessary when Result has more than one
1545 // single-argument constructor (e.g. Result is std::vector<int>) and R
1546 // has a type conversion operator template. In that case, value_(value)
1547 // won't compile as the compiler doesn't known which constructor of
1548 // Result to call. ImplicitCast_ forces the compiler to convert R to
1549 // Result without considering explicit constructors, thus resolving the
1550 // ambiguity. value_ is then initialized using its copy constructor.
1551 explicit Impl(const linked_ptr<R>& value)
1552 : value_before_cast_(*value),
1553 value_(ImplicitCast_<Result>(value_before_cast_)) {}
1555 virtual Result Perform(const ArgumentTuple&) { return value_; }
1558 GTEST_COMPILE_ASSERT_(!is_reference<Result>::value,
1559 Result_cannot_be_a_reference_type);
1560 // We save the value before casting just in case it is being cast to a
1562 R value_before_cast_;
1565 GTEST_DISALLOW_COPY_AND_ASSIGN_(Impl);
1568 // Partially specialize for ByMoveWrapper. This version of ReturnAction will
1569 // move its contents instead.
1570 template <typename R_, typename F>
1571 class Impl<ByMoveWrapper<R_>, F> : public ActionInterface<F> {
1573 typedef typename Function<F>::Result Result;
1574 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
1576 explicit Impl(const linked_ptr<R>& wrapper)
1577 : performed_(false), wrapper_(wrapper) {}
1579 virtual Result Perform(const ArgumentTuple&) {
1580 GTEST_CHECK_(!performed_)
1581 << "A ByMove() action should only be performed once.";
1583 return internal::move(wrapper_->payload);
1588 const linked_ptr<R> wrapper_;
1590 GTEST_DISALLOW_ASSIGN_(Impl);
1593 const linked_ptr<R> value_;
1595 GTEST_DISALLOW_ASSIGN_(ReturnAction);
1598 // Implements the ReturnNull() action.
1599 class ReturnNullAction {
1601 // Allows ReturnNull() to be used in any pointer-returning function. In C++11
1602 // this is enforced by returning nullptr, and in non-C++11 by asserting a
1603 // pointer type on compile time.
1604 template <typename Result, typename ArgumentTuple>
1605 static Result Perform(const ArgumentTuple&) {
1606 #if GTEST_LANG_CXX11
1609 GTEST_COMPILE_ASSERT_(internal::is_pointer<Result>::value,
1610 ReturnNull_can_be_used_to_return_a_pointer_only);
1612 #endif // GTEST_LANG_CXX11
1616 // Implements the Return() action.
1617 class ReturnVoidAction {
1619 // Allows Return() to be used in any void-returning function.
1620 template <typename Result, typename ArgumentTuple>
1621 static void Perform(const ArgumentTuple&) {
1622 CompileAssertTypesEqual<void, Result>();
1626 // Implements the polymorphic ReturnRef(x) action, which can be used
1627 // in any function that returns a reference to the type of x,
1628 // regardless of the argument types.
1629 template <typename T>
1630 class ReturnRefAction {
1632 // Constructs a ReturnRefAction object from the reference to be returned.
1633 explicit ReturnRefAction(T& ref) : ref_(ref) {} // NOLINT
1635 // This template type conversion operator allows ReturnRef(x) to be
1636 // used in ANY function that returns a reference to x's type.
1637 template <typename F>
1638 operator Action<F>() const {
1639 typedef typename Function<F>::Result Result;
1640 // Asserts that the function return type is a reference. This
1641 // catches the user error of using ReturnRef(x) when Return(x)
1642 // should be used, and generates some helpful error message.
1643 GTEST_COMPILE_ASSERT_(internal::is_reference<Result>::value,
1644 use_Return_instead_of_ReturnRef_to_return_a_value);
1645 return Action<F>(new Impl<F>(ref_));
1649 // Implements the ReturnRef(x) action for a particular function type F.
1650 template <typename F>
1651 class Impl : public ActionInterface<F> {
1653 typedef typename Function<F>::Result Result;
1654 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
1656 explicit Impl(T& ref) : ref_(ref) {} // NOLINT
1658 virtual Result Perform(const ArgumentTuple&) {
1665 GTEST_DISALLOW_ASSIGN_(Impl);
1670 GTEST_DISALLOW_ASSIGN_(ReturnRefAction);
1673 // Implements the polymorphic ReturnRefOfCopy(x) action, which can be
1674 // used in any function that returns a reference to the type of x,
1675 // regardless of the argument types.
1676 template <typename T>
1677 class ReturnRefOfCopyAction {
1679 // Constructs a ReturnRefOfCopyAction object from the reference to
1681 explicit ReturnRefOfCopyAction(const T& value) : value_(value) {} // NOLINT
1683 // This template type conversion operator allows ReturnRefOfCopy(x) to be
1684 // used in ANY function that returns a reference to x's type.
1685 template <typename F>
1686 operator Action<F>() const {
1687 typedef typename Function<F>::Result Result;
1688 // Asserts that the function return type is a reference. This
1689 // catches the user error of using ReturnRefOfCopy(x) when Return(x)
1690 // should be used, and generates some helpful error message.
1691 GTEST_COMPILE_ASSERT_(
1692 internal::is_reference<Result>::value,
1693 use_Return_instead_of_ReturnRefOfCopy_to_return_a_value);
1694 return Action<F>(new Impl<F>(value_));
1698 // Implements the ReturnRefOfCopy(x) action for a particular function type F.
1699 template <typename F>
1700 class Impl : public ActionInterface<F> {
1702 typedef typename Function<F>::Result Result;
1703 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
1705 explicit Impl(const T& value) : value_(value) {} // NOLINT
1707 virtual Result Perform(const ArgumentTuple&) {
1714 GTEST_DISALLOW_ASSIGN_(Impl);
1719 GTEST_DISALLOW_ASSIGN_(ReturnRefOfCopyAction);
1722 // Implements the polymorphic DoDefault() action.
1723 class DoDefaultAction {
1725 // This template type conversion operator allows DoDefault() to be
1726 // used in any function.
1727 template <typename F>
1728 operator Action<F>() const { return Action<F>(NULL); }
1731 // Implements the Assign action to set a given pointer referent to a
1732 // particular value.
1733 template <typename T1, typename T2>
1734 class AssignAction {
1736 AssignAction(T1* ptr, T2 value) : ptr_(ptr), value_(value) {}
1738 template <typename Result, typename ArgumentTuple>
1739 void Perform(const ArgumentTuple& /* args */) const {
1747 GTEST_DISALLOW_ASSIGN_(AssignAction);
1750 #if !GTEST_OS_WINDOWS_MOBILE
1752 // Implements the SetErrnoAndReturn action to simulate return from
1753 // various system calls and libc functions.
1754 template <typename T>
1755 class SetErrnoAndReturnAction {
1757 SetErrnoAndReturnAction(int errno_value, T result)
1758 : errno_(errno_value),
1760 template <typename Result, typename ArgumentTuple>
1761 Result Perform(const ArgumentTuple& /* args */) const {
1770 GTEST_DISALLOW_ASSIGN_(SetErrnoAndReturnAction);
1773 #endif // !GTEST_OS_WINDOWS_MOBILE
1775 // Implements the SetArgumentPointee<N>(x) action for any function
1776 // whose N-th argument (0-based) is a pointer to x's type. The
1777 // template parameter kIsProto is true iff type A is ProtocolMessage,
1778 // proto2::Message, or a sub-class of those.
1779 template <size_t N, typename A, bool kIsProto>
1780 class SetArgumentPointeeAction {
1782 // Constructs an action that sets the variable pointed to by the
1783 // N-th function argument to 'value'.
1784 explicit SetArgumentPointeeAction(const A& value) : value_(value) {}
1786 template <typename Result, typename ArgumentTuple>
1787 void Perform(const ArgumentTuple& args) const {
1788 CompileAssertTypesEqual<void, Result>();
1789 *::testing::get<N>(args) = value_;
1795 GTEST_DISALLOW_ASSIGN_(SetArgumentPointeeAction);
1798 template <size_t N, typename Proto>
1799 class SetArgumentPointeeAction<N, Proto, true> {
1801 // Constructs an action that sets the variable pointed to by the
1802 // N-th function argument to 'proto'. Both ProtocolMessage and
1803 // proto2::Message have the CopyFrom() method, so the same
1804 // implementation works for both.
1805 explicit SetArgumentPointeeAction(const Proto& proto) : proto_(new Proto) {
1806 proto_->CopyFrom(proto);
1809 template <typename Result, typename ArgumentTuple>
1810 void Perform(const ArgumentTuple& args) const {
1811 CompileAssertTypesEqual<void, Result>();
1812 ::testing::get<N>(args)->CopyFrom(*proto_);
1816 const internal::linked_ptr<Proto> proto_;
1818 GTEST_DISALLOW_ASSIGN_(SetArgumentPointeeAction);
1821 // Implements the InvokeWithoutArgs(f) action. The template argument
1822 // FunctionImpl is the implementation type of f, which can be either a
1823 // function pointer or a functor. InvokeWithoutArgs(f) can be used as an
1824 // Action<F> as long as f's type is compatible with F (i.e. f can be
1825 // assigned to a tr1::function<F>).
1826 template <typename FunctionImpl>
1827 class InvokeWithoutArgsAction {
1829 // The c'tor makes a copy of function_impl (either a function
1830 // pointer or a functor).
1831 explicit InvokeWithoutArgsAction(FunctionImpl function_impl)
1832 : function_impl_(function_impl) {}
1834 // Allows InvokeWithoutArgs(f) to be used as any action whose type is
1835 // compatible with f.
1836 template <typename Result, typename ArgumentTuple>
1837 Result Perform(const ArgumentTuple&) { return function_impl_(); }
1840 FunctionImpl function_impl_;
1842 GTEST_DISALLOW_ASSIGN_(InvokeWithoutArgsAction);
1845 // Implements the InvokeWithoutArgs(object_ptr, &Class::Method) action.
1846 template <class Class, typename MethodPtr>
1847 class InvokeMethodWithoutArgsAction {
1849 InvokeMethodWithoutArgsAction(Class* obj_ptr, MethodPtr method_ptr)
1850 : obj_ptr_(obj_ptr), method_ptr_(method_ptr) {}
1852 template <typename Result, typename ArgumentTuple>
1853 Result Perform(const ArgumentTuple&) const {
1854 return (obj_ptr_->*method_ptr_)();
1858 Class* const obj_ptr_;
1859 const MethodPtr method_ptr_;
1861 GTEST_DISALLOW_ASSIGN_(InvokeMethodWithoutArgsAction);
1864 // Implements the IgnoreResult(action) action.
1865 template <typename A>
1866 class IgnoreResultAction {
1868 explicit IgnoreResultAction(const A& action) : action_(action) {}
1870 template <typename F>
1871 operator Action<F>() const {
1872 // Assert statement belongs here because this is the best place to verify
1873 // conditions on F. It produces the clearest error messages
1874 // in most compilers.
1875 // Impl really belongs in this scope as a local class but can't
1876 // because MSVC produces duplicate symbols in different translation units
1877 // in this case. Until MS fixes that bug we put Impl into the class scope
1878 // and put the typedef both here (for use in assert statement) and
1879 // in the Impl class. But both definitions must be the same.
1880 typedef typename internal::Function<F>::Result Result;
1882 // Asserts at compile time that F returns void.
1883 CompileAssertTypesEqual<void, Result>();
1885 return Action<F>(new Impl<F>(action_));
1889 template <typename F>
1890 class Impl : public ActionInterface<F> {
1892 typedef typename internal::Function<F>::Result Result;
1893 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
1895 explicit Impl(const A& action) : action_(action) {}
1897 virtual void Perform(const ArgumentTuple& args) {
1898 // Performs the action and ignores its result.
1899 action_.Perform(args);
1903 // Type OriginalFunction is the same as F except that its return
1904 // type is IgnoredValue.
1905 typedef typename internal::Function<F>::MakeResultIgnoredValue
1908 const Action<OriginalFunction> action_;
1910 GTEST_DISALLOW_ASSIGN_(Impl);
1915 GTEST_DISALLOW_ASSIGN_(IgnoreResultAction);
1918 // A ReferenceWrapper<T> object represents a reference to type T,
1919 // which can be either const or not. It can be explicitly converted
1920 // from, and implicitly converted to, a T&. Unlike a reference,
1921 // ReferenceWrapper<T> can be copied and can survive template type
1922 // inference. This is used to support by-reference arguments in the
1923 // InvokeArgument<N>(...) action. The idea was from "reference
1924 // wrappers" in tr1, which we don't have in our source tree yet.
1925 template <typename T>
1926 class ReferenceWrapper {
1928 // Constructs a ReferenceWrapper<T> object from a T&.
1929 explicit ReferenceWrapper(T& l_value) : pointer_(&l_value) {} // NOLINT
1931 // Allows a ReferenceWrapper<T> object to be implicitly converted to
1933 operator T&() const { return *pointer_; }
1938 // Allows the expression ByRef(x) to be printed as a reference to x.
1939 template <typename T>
1940 void PrintTo(const ReferenceWrapper<T>& ref, ::std::ostream* os) {
1942 UniversalPrinter<T&>::Print(value, os);
1945 // Does two actions sequentially. Used for implementing the DoAll(a1,
1947 template <typename Action1, typename Action2>
1948 class DoBothAction {
1950 DoBothAction(Action1 action1, Action2 action2)
1951 : action1_(action1), action2_(action2) {}
1953 // This template type conversion operator allows DoAll(a1, ..., a_n)
1954 // to be used in ANY function of compatible type.
1955 template <typename F>
1956 operator Action<F>() const {
1957 return Action<F>(new Impl<F>(action1_, action2_));
1961 // Implements the DoAll(...) action for a particular function type F.
1962 template <typename F>
1963 class Impl : public ActionInterface<F> {
1965 typedef typename Function<F>::Result Result;
1966 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
1967 typedef typename Function<F>::MakeResultVoid VoidResult;
1969 Impl(const Action<VoidResult>& action1, const Action<F>& action2)
1970 : action1_(action1), action2_(action2) {}
1972 virtual Result Perform(const ArgumentTuple& args) {
1973 action1_.Perform(args);
1974 return action2_.Perform(args);
1978 const Action<VoidResult> action1_;
1979 const Action<F> action2_;
1981 GTEST_DISALLOW_ASSIGN_(Impl);
1987 GTEST_DISALLOW_ASSIGN_(DoBothAction);
1990 } // namespace internal
1992 // An Unused object can be implicitly constructed from ANY value.
1993 // This is handy when defining actions that ignore some or all of the
1994 // mock function arguments. For example, given
1996 // MOCK_METHOD3(Foo, double(const string& label, double x, double y));
1997 // MOCK_METHOD3(Bar, double(int index, double x, double y));
2001 // double DistanceToOriginWithLabel(const string& label, double x, double y) {
2002 // return sqrt(x*x + y*y);
2004 // double DistanceToOriginWithIndex(int index, double x, double y) {
2005 // return sqrt(x*x + y*y);
2008 // EXEPCT_CALL(mock, Foo("abc", _, _))
2009 // .WillOnce(Invoke(DistanceToOriginWithLabel));
2010 // EXEPCT_CALL(mock, Bar(5, _, _))
2011 // .WillOnce(Invoke(DistanceToOriginWithIndex));
2015 // // We can declare any uninteresting argument as Unused.
2016 // double DistanceToOrigin(Unused, double x, double y) {
2017 // return sqrt(x*x + y*y);
2020 // EXEPCT_CALL(mock, Foo("abc", _, _)).WillOnce(Invoke(DistanceToOrigin));
2021 // EXEPCT_CALL(mock, Bar(5, _, _)).WillOnce(Invoke(DistanceToOrigin));
2022 typedef internal::IgnoredValue Unused;
2024 // This constructor allows us to turn an Action<From> object into an
2025 // Action<To>, as long as To's arguments can be implicitly converted
2026 // to From's and From's return type cann be implicitly converted to
2028 template <typename To>
2029 template <typename From>
2030 Action<To>::Action(const Action<From>& from)
2031 : impl_(new internal::ActionAdaptor<To, From>(from)) {}
2033 // Creates an action that returns 'value'. 'value' is passed by value
2034 // instead of const reference - otherwise Return("string literal")
2035 // will trigger a compiler error about using array as initializer.
2036 template <typename R>
2037 internal::ReturnAction<R> Return(R value) {
2038 return internal::ReturnAction<R>(internal::move(value));
2041 // Creates an action that returns NULL.
2042 inline PolymorphicAction<internal::ReturnNullAction> ReturnNull() {
2043 return MakePolymorphicAction(internal::ReturnNullAction());
2046 // Creates an action that returns from a void function.
2047 inline PolymorphicAction<internal::ReturnVoidAction> Return() {
2048 return MakePolymorphicAction(internal::ReturnVoidAction());
2051 // Creates an action that returns the reference to a variable.
2052 template <typename R>
2053 inline internal::ReturnRefAction<R> ReturnRef(R& x) { // NOLINT
2054 return internal::ReturnRefAction<R>(x);
2057 // Creates an action that returns the reference to a copy of the
2058 // argument. The copy is created when the action is constructed and
2059 // lives as long as the action.
2060 template <typename R>
2061 inline internal::ReturnRefOfCopyAction<R> ReturnRefOfCopy(const R& x) {
2062 return internal::ReturnRefOfCopyAction<R>(x);
2065 // Modifies the parent action (a Return() action) to perform a move of the
2066 // argument instead of a copy.
2067 // Return(ByMove()) actions can only be executed once and will assert this
2069 template <typename R>
2070 internal::ByMoveWrapper<R> ByMove(R x) {
2071 return internal::ByMoveWrapper<R>(internal::move(x));
2074 // Creates an action that does the default action for the give mock function.
2075 inline internal::DoDefaultAction DoDefault() {
2076 return internal::DoDefaultAction();
2079 // Creates an action that sets the variable pointed by the N-th
2080 // (0-based) function argument to 'value'.
2081 template <size_t N, typename T>
2083 internal::SetArgumentPointeeAction<
2084 N, T, internal::IsAProtocolMessage<T>::value> >
2085 SetArgPointee(const T& x) {
2086 return MakePolymorphicAction(internal::SetArgumentPointeeAction<
2087 N, T, internal::IsAProtocolMessage<T>::value>(x));
2090 #if !((GTEST_GCC_VER_ && GTEST_GCC_VER_ < 40000) || GTEST_OS_SYMBIAN)
2091 // This overload allows SetArgPointee() to accept a string literal.
2092 // GCC prior to the version 4.0 and Symbian C++ compiler cannot distinguish
2093 // this overload from the templated version and emit a compile error.
2096 internal::SetArgumentPointeeAction<N, const char*, false> >
2097 SetArgPointee(const char* p) {
2098 return MakePolymorphicAction(internal::SetArgumentPointeeAction<
2099 N, const char*, false>(p));
2104 internal::SetArgumentPointeeAction<N, const wchar_t*, false> >
2105 SetArgPointee(const wchar_t* p) {
2106 return MakePolymorphicAction(internal::SetArgumentPointeeAction<
2107 N, const wchar_t*, false>(p));
2111 // The following version is DEPRECATED.
2112 template <size_t N, typename T>
2114 internal::SetArgumentPointeeAction<
2115 N, T, internal::IsAProtocolMessage<T>::value> >
2116 SetArgumentPointee(const T& x) {
2117 return MakePolymorphicAction(internal::SetArgumentPointeeAction<
2118 N, T, internal::IsAProtocolMessage<T>::value>(x));
2121 // Creates an action that sets a pointer referent to a given value.
2122 template <typename T1, typename T2>
2123 PolymorphicAction<internal::AssignAction<T1, T2> > Assign(T1* ptr, T2 val) {
2124 return MakePolymorphicAction(internal::AssignAction<T1, T2>(ptr, val));
2127 #if !GTEST_OS_WINDOWS_MOBILE
2129 // Creates an action that sets errno and returns the appropriate error.
2130 template <typename T>
2131 PolymorphicAction<internal::SetErrnoAndReturnAction<T> >
2132 SetErrnoAndReturn(int errval, T result) {
2133 return MakePolymorphicAction(
2134 internal::SetErrnoAndReturnAction<T>(errval, result));
2137 #endif // !GTEST_OS_WINDOWS_MOBILE
2139 // Various overloads for InvokeWithoutArgs().
2141 // Creates an action that invokes 'function_impl' with no argument.
2142 template <typename FunctionImpl>
2143 PolymorphicAction<internal::InvokeWithoutArgsAction<FunctionImpl> >
2144 InvokeWithoutArgs(FunctionImpl function_impl) {
2145 return MakePolymorphicAction(
2146 internal::InvokeWithoutArgsAction<FunctionImpl>(function_impl));
2149 // Creates an action that invokes the given method on the given object
2150 // with no argument.
2151 template <class Class, typename MethodPtr>
2152 PolymorphicAction<internal::InvokeMethodWithoutArgsAction<Class, MethodPtr> >
2153 InvokeWithoutArgs(Class* obj_ptr, MethodPtr method_ptr) {
2154 return MakePolymorphicAction(
2155 internal::InvokeMethodWithoutArgsAction<Class, MethodPtr>(
2156 obj_ptr, method_ptr));
2159 // Creates an action that performs an_action and throws away its
2160 // result. In other words, it changes the return type of an_action to
2161 // void. an_action MUST NOT return void, or the code won't compile.
2162 template <typename A>
2163 inline internal::IgnoreResultAction<A> IgnoreResult(const A& an_action) {
2164 return internal::IgnoreResultAction<A>(an_action);
2167 // Creates a reference wrapper for the given L-value. If necessary,
2168 // you can explicitly specify the type of the reference. For example,
2169 // suppose 'derived' is an object of type Derived, ByRef(derived)
2170 // would wrap a Derived&. If you want to wrap a const Base& instead,
2171 // where Base is a base class of Derived, just write:
2173 // ByRef<const Base>(derived)
2174 template <typename T>
2175 inline internal::ReferenceWrapper<T> ByRef(T& l_value) { // NOLINT
2176 return internal::ReferenceWrapper<T>(l_value);
2179 } // namespace testing
2181 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
2182 // Copyright 2007, Google Inc.
2183 // All rights reserved.
2185 // Redistribution and use in source and binary forms, with or without
2186 // modification, are permitted provided that the following conditions are
2189 // * Redistributions of source code must retain the above copyright
2190 // notice, this list of conditions and the following disclaimer.
2191 // * Redistributions in binary form must reproduce the above
2192 // copyright notice, this list of conditions and the following disclaimer
2193 // in the documentation and/or other materials provided with the
2195 // * Neither the name of Google Inc. nor the names of its
2196 // contributors may be used to endorse or promote products derived from
2197 // this software without specific prior written permission.
2199 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2200 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2201 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2202 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2203 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2204 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2205 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2206 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2207 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2208 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2209 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2211 // Author: wan@google.com (Zhanyong Wan)
2213 // Google Mock - a framework for writing C++ mock classes.
2215 // This file implements some commonly used cardinalities. More
2216 // cardinalities can be defined by the user implementing the
2217 // CardinalityInterface interface if necessary.
2219 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_
2220 #define GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_
2223 #include <ostream> // NOLINT
2227 // To implement a cardinality Foo, define:
2228 // 1. a class FooCardinality that implements the
2229 // CardinalityInterface interface, and
2230 // 2. a factory function that creates a Cardinality object from a
2231 // const FooCardinality*.
2233 // The two-level delegation design follows that of Matcher, providing
2234 // consistency for extension developers. It also eases ownership
2235 // management as Cardinality objects can now be copied like plain values.
2237 // The implementation of a cardinality.
2238 class CardinalityInterface {
2240 virtual ~CardinalityInterface() {}
2242 // Conservative estimate on the lower/upper bound of the number of
2244 virtual int ConservativeLowerBound() const { return 0; }
2245 virtual int ConservativeUpperBound() const { return INT_MAX; }
2247 // Returns true iff call_count calls will satisfy this cardinality.
2248 virtual bool IsSatisfiedByCallCount(int call_count) const = 0;
2250 // Returns true iff call_count calls will saturate this cardinality.
2251 virtual bool IsSaturatedByCallCount(int call_count) const = 0;
2253 // Describes self to an ostream.
2254 virtual void DescribeTo(::std::ostream* os) const = 0;
2257 // A Cardinality is a copyable and IMMUTABLE (except by assignment)
2258 // object that specifies how many times a mock function is expected to
2259 // be called. The implementation of Cardinality is just a linked_ptr
2260 // to const CardinalityInterface, so copying is fairly cheap.
2261 // Don't inherit from Cardinality!
2262 class GTEST_API_ Cardinality {
2264 // Constructs a null cardinality. Needed for storing Cardinality
2265 // objects in STL containers.
2268 // Constructs a Cardinality from its implementation.
2269 explicit Cardinality(const CardinalityInterface* impl) : impl_(impl) {}
2271 // Conservative estimate on the lower/upper bound of the number of
2273 int ConservativeLowerBound() const { return impl_->ConservativeLowerBound(); }
2274 int ConservativeUpperBound() const { return impl_->ConservativeUpperBound(); }
2276 // Returns true iff call_count calls will satisfy this cardinality.
2277 bool IsSatisfiedByCallCount(int call_count) const {
2278 return impl_->IsSatisfiedByCallCount(call_count);
2281 // Returns true iff call_count calls will saturate this cardinality.
2282 bool IsSaturatedByCallCount(int call_count) const {
2283 return impl_->IsSaturatedByCallCount(call_count);
2286 // Returns true iff call_count calls will over-saturate this
2287 // cardinality, i.e. exceed the maximum number of allowed calls.
2288 bool IsOverSaturatedByCallCount(int call_count) const {
2289 return impl_->IsSaturatedByCallCount(call_count) &&
2290 !impl_->IsSatisfiedByCallCount(call_count);
2293 // Describes self to an ostream
2294 void DescribeTo(::std::ostream* os) const { impl_->DescribeTo(os); }
2296 // Describes the given actual call count to an ostream.
2297 static void DescribeActualCallCountTo(int actual_call_count,
2298 ::std::ostream* os);
2301 internal::linked_ptr<const CardinalityInterface> impl_;
2304 // Creates a cardinality that allows at least n calls.
2305 GTEST_API_ Cardinality AtLeast(int n);
2307 // Creates a cardinality that allows at most n calls.
2308 GTEST_API_ Cardinality AtMost(int n);
2310 // Creates a cardinality that allows any number of calls.
2311 GTEST_API_ Cardinality AnyNumber();
2313 // Creates a cardinality that allows between min and max calls.
2314 GTEST_API_ Cardinality Between(int min, int max);
2316 // Creates a cardinality that allows exactly n calls.
2317 GTEST_API_ Cardinality Exactly(int n);
2319 // Creates a cardinality from its implementation.
2320 inline Cardinality MakeCardinality(const CardinalityInterface* c) {
2321 return Cardinality(c);
2324 } // namespace testing
2326 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_
2327 // This file was GENERATED by a script. DO NOT EDIT BY HAND!!!
2329 // Copyright 2007, Google Inc.
2330 // All rights reserved.
2332 // Redistribution and use in source and binary forms, with or without
2333 // modification, are permitted provided that the following conditions are
2336 // * Redistributions of source code must retain the above copyright
2337 // notice, this list of conditions and the following disclaimer.
2338 // * Redistributions in binary form must reproduce the above
2339 // copyright notice, this list of conditions and the following disclaimer
2340 // in the documentation and/or other materials provided with the
2342 // * Neither the name of Google Inc. nor the names of its
2343 // contributors may be used to endorse or promote products derived from
2344 // this software without specific prior written permission.
2346 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2347 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2348 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2349 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2350 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2351 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2352 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2353 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2354 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2355 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2356 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2358 // Author: wan@google.com (Zhanyong Wan)
2360 // Google Mock - a framework for writing C++ mock classes.
2362 // This file implements some commonly used variadic actions.
2364 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
2365 #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
2369 namespace internal {
2371 // InvokeHelper<F> knows how to unpack an N-tuple and invoke an N-ary
2372 // function or method with the unpacked values, where F is a function
2373 // type that takes N arguments.
2374 template <typename Result, typename ArgumentTuple>
2377 template <typename R>
2378 class InvokeHelper<R, ::testing::tuple<> > {
2380 template <typename Function>
2381 static R Invoke(Function function, const ::testing::tuple<>&) {
2385 template <class Class, typename MethodPtr>
2386 static R InvokeMethod(Class* obj_ptr,
2387 MethodPtr method_ptr,
2388 const ::testing::tuple<>&) {
2389 return (obj_ptr->*method_ptr)();
2393 template <typename R, typename A1>
2394 class InvokeHelper<R, ::testing::tuple<A1> > {
2396 template <typename Function>
2397 static R Invoke(Function function, const ::testing::tuple<A1>& args) {
2398 return function(get<0>(args));
2401 template <class Class, typename MethodPtr>
2402 static R InvokeMethod(Class* obj_ptr,
2403 MethodPtr method_ptr,
2404 const ::testing::tuple<A1>& args) {
2405 return (obj_ptr->*method_ptr)(get<0>(args));
2409 template <typename R, typename A1, typename A2>
2410 class InvokeHelper<R, ::testing::tuple<A1, A2> > {
2412 template <typename Function>
2413 static R Invoke(Function function, const ::testing::tuple<A1, A2>& args) {
2414 return function(get<0>(args), get<1>(args));
2417 template <class Class, typename MethodPtr>
2418 static R InvokeMethod(Class* obj_ptr,
2419 MethodPtr method_ptr,
2420 const ::testing::tuple<A1, A2>& args) {
2421 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args));
2425 template <typename R, typename A1, typename A2, typename A3>
2426 class InvokeHelper<R, ::testing::tuple<A1, A2, A3> > {
2428 template <typename Function>
2429 static R Invoke(Function function, const ::testing::tuple<A1, A2, A3>& args) {
2430 return function(get<0>(args), get<1>(args), get<2>(args));
2433 template <class Class, typename MethodPtr>
2434 static R InvokeMethod(Class* obj_ptr,
2435 MethodPtr method_ptr,
2436 const ::testing::tuple<A1, A2, A3>& args) {
2437 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args),
2442 template <typename R, typename A1, typename A2, typename A3, typename A4>
2443 class InvokeHelper<R, ::testing::tuple<A1, A2, A3, A4> > {
2445 template <typename Function>
2446 static R Invoke(Function function, const ::testing::tuple<A1, A2, A3,
2448 return function(get<0>(args), get<1>(args), get<2>(args),
2452 template <class Class, typename MethodPtr>
2453 static R InvokeMethod(Class* obj_ptr,
2454 MethodPtr method_ptr,
2455 const ::testing::tuple<A1, A2, A3, A4>& args) {
2456 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args),
2457 get<2>(args), get<3>(args));
2461 template <typename R, typename A1, typename A2, typename A3, typename A4,
2463 class InvokeHelper<R, ::testing::tuple<A1, A2, A3, A4, A5> > {
2465 template <typename Function>
2466 static R Invoke(Function function, const ::testing::tuple<A1, A2, A3, A4,
2468 return function(get<0>(args), get<1>(args), get<2>(args),
2469 get<3>(args), get<4>(args));
2472 template <class Class, typename MethodPtr>
2473 static R InvokeMethod(Class* obj_ptr,
2474 MethodPtr method_ptr,
2475 const ::testing::tuple<A1, A2, A3, A4, A5>& args) {
2476 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args),
2477 get<2>(args), get<3>(args), get<4>(args));
2481 template <typename R, typename A1, typename A2, typename A3, typename A4,
2482 typename A5, typename A6>
2483 class InvokeHelper<R, ::testing::tuple<A1, A2, A3, A4, A5, A6> > {
2485 template <typename Function>
2486 static R Invoke(Function function, const ::testing::tuple<A1, A2, A3, A4, A5,
2488 return function(get<0>(args), get<1>(args), get<2>(args),
2489 get<3>(args), get<4>(args), get<5>(args));
2492 template <class Class, typename MethodPtr>
2493 static R InvokeMethod(Class* obj_ptr,
2494 MethodPtr method_ptr,
2495 const ::testing::tuple<A1, A2, A3, A4, A5, A6>& args) {
2496 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args),
2497 get<2>(args), get<3>(args), get<4>(args), get<5>(args));
2501 template <typename R, typename A1, typename A2, typename A3, typename A4,
2502 typename A5, typename A6, typename A7>
2503 class InvokeHelper<R, ::testing::tuple<A1, A2, A3, A4, A5, A6, A7> > {
2505 template <typename Function>
2506 static R Invoke(Function function, const ::testing::tuple<A1, A2, A3, A4, A5,
2508 return function(get<0>(args), get<1>(args), get<2>(args),
2509 get<3>(args), get<4>(args), get<5>(args), get<6>(args));
2512 template <class Class, typename MethodPtr>
2513 static R InvokeMethod(Class* obj_ptr,
2514 MethodPtr method_ptr,
2515 const ::testing::tuple<A1, A2, A3, A4, A5, A6,
2517 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args),
2518 get<2>(args), get<3>(args), get<4>(args), get<5>(args),
2523 template <typename R, typename A1, typename A2, typename A3, typename A4,
2524 typename A5, typename A6, typename A7, typename A8>
2525 class InvokeHelper<R, ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8> > {
2527 template <typename Function>
2528 static R Invoke(Function function, const ::testing::tuple<A1, A2, A3, A4, A5,
2529 A6, A7, A8>& args) {
2530 return function(get<0>(args), get<1>(args), get<2>(args),
2531 get<3>(args), get<4>(args), get<5>(args), get<6>(args),
2535 template <class Class, typename MethodPtr>
2536 static R InvokeMethod(Class* obj_ptr,
2537 MethodPtr method_ptr,
2538 const ::testing::tuple<A1, A2, A3, A4, A5, A6, A7,
2540 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args),
2541 get<2>(args), get<3>(args), get<4>(args), get<5>(args),
2542 get<6>(args), get<7>(args));
2546 template <typename R, typename A1, typename A2, typename A3, typename A4,
2547 typename A5, typename A6, typename A7, typename A8, typename A9>
2548 class InvokeHelper<R, ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9> > {
2550 template <typename Function>
2551 static R Invoke(Function function, const ::testing::tuple<A1, A2, A3, A4, A5,
2552 A6, A7, A8, A9>& args) {
2553 return function(get<0>(args), get<1>(args), get<2>(args),
2554 get<3>(args), get<4>(args), get<5>(args), get<6>(args),
2555 get<7>(args), get<8>(args));
2558 template <class Class, typename MethodPtr>
2559 static R InvokeMethod(Class* obj_ptr,
2560 MethodPtr method_ptr,
2561 const ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8,
2563 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args),
2564 get<2>(args), get<3>(args), get<4>(args), get<5>(args),
2565 get<6>(args), get<7>(args), get<8>(args));
2569 template <typename R, typename A1, typename A2, typename A3, typename A4,
2570 typename A5, typename A6, typename A7, typename A8, typename A9,
2572 class InvokeHelper<R, ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9,
2575 template <typename Function>
2576 static R Invoke(Function function, const ::testing::tuple<A1, A2, A3, A4, A5,
2577 A6, A7, A8, A9, A10>& args) {
2578 return function(get<0>(args), get<1>(args), get<2>(args),
2579 get<3>(args), get<4>(args), get<5>(args), get<6>(args),
2580 get<7>(args), get<8>(args), get<9>(args));
2583 template <class Class, typename MethodPtr>
2584 static R InvokeMethod(Class* obj_ptr,
2585 MethodPtr method_ptr,
2586 const ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8,
2588 return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args),
2589 get<2>(args), get<3>(args), get<4>(args), get<5>(args),
2590 get<6>(args), get<7>(args), get<8>(args), get<9>(args));
2594 // An INTERNAL macro for extracting the type of a tuple field. It's
2595 // subject to change without notice - DO NOT USE IN USER CODE!
2596 #define GMOCK_FIELD_(Tuple, N) \
2597 typename ::testing::tuple_element<N, Tuple>::type
2599 // SelectArgs<Result, ArgumentTuple, k1, k2, ..., k_n>::type is the
2600 // type of an n-ary function whose i-th (1-based) argument type is the
2601 // k{i}-th (0-based) field of ArgumentTuple, which must be a tuple
2602 // type, and whose return type is Result. For example,
2603 // SelectArgs<int, ::testing::tuple<bool, char, double, long>, 0, 3>::type
2604 // is int(bool, long).
2606 // SelectArgs<Result, ArgumentTuple, k1, k2, ..., k_n>::Select(args)
2607 // returns the selected fields (k1, k2, ..., k_n) of args as a tuple.
2609 // SelectArgs<int, tuple<bool, char, double>, 2, 0>::Select(
2610 // ::testing::make_tuple(true, 'a', 2.5))
2611 // returns tuple (2.5, true).
2613 // The numbers in list k1, k2, ..., k_n must be >= 0, where n can be
2614 // in the range [0, 10]. Duplicates are allowed and they don't have
2615 // to be in an ascending or descending order.
2617 template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
2618 int k4, int k5, int k6, int k7, int k8, int k9, int k10>
2621 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
2622 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
2623 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5),
2624 GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7),
2625 GMOCK_FIELD_(ArgumentTuple, k8), GMOCK_FIELD_(ArgumentTuple, k9),
2626 GMOCK_FIELD_(ArgumentTuple, k10));
2627 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2628 static SelectedArgs Select(const ArgumentTuple& args) {
2629 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
2630 get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args),
2631 get<k8>(args), get<k9>(args), get<k10>(args));
2635 template <typename Result, typename ArgumentTuple>
2636 class SelectArgs<Result, ArgumentTuple,
2637 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1> {
2639 typedef Result type();
2640 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2641 static SelectedArgs Select(const ArgumentTuple& /* args */) {
2642 return SelectedArgs();
2646 template <typename Result, typename ArgumentTuple, int k1>
2647 class SelectArgs<Result, ArgumentTuple,
2648 k1, -1, -1, -1, -1, -1, -1, -1, -1, -1> {
2650 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1));
2651 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2652 static SelectedArgs Select(const ArgumentTuple& args) {
2653 return SelectedArgs(get<k1>(args));
2657 template <typename Result, typename ArgumentTuple, int k1, int k2>
2658 class SelectArgs<Result, ArgumentTuple,
2659 k1, k2, -1, -1, -1, -1, -1, -1, -1, -1> {
2661 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
2662 GMOCK_FIELD_(ArgumentTuple, k2));
2663 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2664 static SelectedArgs Select(const ArgumentTuple& args) {
2665 return SelectedArgs(get<k1>(args), get<k2>(args));
2669 template <typename Result, typename ArgumentTuple, int k1, int k2, int k3>
2670 class SelectArgs<Result, ArgumentTuple,
2671 k1, k2, k3, -1, -1, -1, -1, -1, -1, -1> {
2673 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
2674 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3));
2675 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2676 static SelectedArgs Select(const ArgumentTuple& args) {
2677 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args));
2681 template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
2683 class SelectArgs<Result, ArgumentTuple,
2684 k1, k2, k3, k4, -1, -1, -1, -1, -1, -1> {
2686 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
2687 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
2688 GMOCK_FIELD_(ArgumentTuple, k4));
2689 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2690 static SelectedArgs Select(const ArgumentTuple& args) {
2691 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
2696 template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
2698 class SelectArgs<Result, ArgumentTuple,
2699 k1, k2, k3, k4, k5, -1, -1, -1, -1, -1> {
2701 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
2702 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
2703 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5));
2704 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2705 static SelectedArgs Select(const ArgumentTuple& args) {
2706 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
2707 get<k4>(args), get<k5>(args));
2711 template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
2712 int k4, int k5, int k6>
2713 class SelectArgs<Result, ArgumentTuple,
2714 k1, k2, k3, k4, k5, k6, -1, -1, -1, -1> {
2716 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
2717 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
2718 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5),
2719 GMOCK_FIELD_(ArgumentTuple, k6));
2720 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2721 static SelectedArgs Select(const ArgumentTuple& args) {
2722 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
2723 get<k4>(args), get<k5>(args), get<k6>(args));
2727 template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
2728 int k4, int k5, int k6, int k7>
2729 class SelectArgs<Result, ArgumentTuple,
2730 k1, k2, k3, k4, k5, k6, k7, -1, -1, -1> {
2732 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
2733 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
2734 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5),
2735 GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7));
2736 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2737 static SelectedArgs Select(const ArgumentTuple& args) {
2738 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
2739 get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args));
2743 template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
2744 int k4, int k5, int k6, int k7, int k8>
2745 class SelectArgs<Result, ArgumentTuple,
2746 k1, k2, k3, k4, k5, k6, k7, k8, -1, -1> {
2748 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
2749 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
2750 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5),
2751 GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7),
2752 GMOCK_FIELD_(ArgumentTuple, k8));
2753 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2754 static SelectedArgs Select(const ArgumentTuple& args) {
2755 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
2756 get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args),
2761 template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
2762 int k4, int k5, int k6, int k7, int k8, int k9>
2763 class SelectArgs<Result, ArgumentTuple,
2764 k1, k2, k3, k4, k5, k6, k7, k8, k9, -1> {
2766 typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
2767 GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
2768 GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5),
2769 GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7),
2770 GMOCK_FIELD_(ArgumentTuple, k8), GMOCK_FIELD_(ArgumentTuple, k9));
2771 typedef typename Function<type>::ArgumentTuple SelectedArgs;
2772 static SelectedArgs Select(const ArgumentTuple& args) {
2773 return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
2774 get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args),
2775 get<k8>(args), get<k9>(args));
2781 // Implements the WithArgs action.
2782 template <typename InnerAction, int k1 = -1, int k2 = -1, int k3 = -1,
2783 int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1, int k8 = -1,
2784 int k9 = -1, int k10 = -1>
2785 class WithArgsAction {
2787 explicit WithArgsAction(const InnerAction& action) : action_(action) {}
2789 template <typename F>
2790 operator Action<F>() const { return MakeAction(new Impl<F>(action_)); }
2793 template <typename F>
2794 class Impl : public ActionInterface<F> {
2796 typedef typename Function<F>::Result Result;
2797 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
2799 explicit Impl(const InnerAction& action) : action_(action) {}
2801 virtual Result Perform(const ArgumentTuple& args) {
2802 return action_.Perform(SelectArgs<Result, ArgumentTuple, k1, k2, k3, k4,
2803 k5, k6, k7, k8, k9, k10>::Select(args));
2807 typedef typename SelectArgs<Result, ArgumentTuple,
2808 k1, k2, k3, k4, k5, k6, k7, k8, k9, k10>::type InnerFunctionType;
2810 Action<InnerFunctionType> action_;
2813 const InnerAction action_;
2815 GTEST_DISALLOW_ASSIGN_(WithArgsAction);
2818 // A macro from the ACTION* family (defined later in this file)
2819 // defines an action that can be used in a mock function. Typically,
2820 // these actions only care about a subset of the arguments of the mock
2821 // function. For example, if such an action only uses the second
2822 // argument, it can be used in any mock function that takes >= 2
2823 // arguments where the type of the second argument is compatible.
2825 // Therefore, the action implementation must be prepared to take more
2826 // arguments than it needs. The ExcessiveArg type is used to
2827 // represent those excessive arguments. In order to keep the compiler
2828 // error messages tractable, we define it in the testing namespace
2829 // instead of testing::internal. However, this is an INTERNAL TYPE
2830 // and subject to change without notice, so a user MUST NOT USE THIS
2832 struct ExcessiveArg {};
2834 // A helper class needed for implementing the ACTION* macros.
2835 template <typename Result, class Impl>
2836 class ActionHelper {
2838 static Result Perform(Impl* impl, const ::testing::tuple<>& args) {
2839 return impl->template gmock_PerformImpl<>(args, ExcessiveArg(),
2840 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2841 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2845 template <typename A0>
2846 static Result Perform(Impl* impl, const ::testing::tuple<A0>& args) {
2847 return impl->template gmock_PerformImpl<A0>(args, get<0>(args),
2848 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2849 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2853 template <typename A0, typename A1>
2854 static Result Perform(Impl* impl, const ::testing::tuple<A0, A1>& args) {
2855 return impl->template gmock_PerformImpl<A0, A1>(args, get<0>(args),
2856 get<1>(args), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2857 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2861 template <typename A0, typename A1, typename A2>
2862 static Result Perform(Impl* impl, const ::testing::tuple<A0, A1, A2>& args) {
2863 return impl->template gmock_PerformImpl<A0, A1, A2>(args, get<0>(args),
2864 get<1>(args), get<2>(args), ExcessiveArg(), ExcessiveArg(),
2865 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2869 template <typename A0, typename A1, typename A2, typename A3>
2870 static Result Perform(Impl* impl, const ::testing::tuple<A0, A1, A2,
2872 return impl->template gmock_PerformImpl<A0, A1, A2, A3>(args, get<0>(args),
2873 get<1>(args), get<2>(args), get<3>(args), ExcessiveArg(),
2874 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2878 template <typename A0, typename A1, typename A2, typename A3, typename A4>
2879 static Result Perform(Impl* impl, const ::testing::tuple<A0, A1, A2, A3,
2881 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4>(args,
2882 get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args),
2883 ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2887 template <typename A0, typename A1, typename A2, typename A3, typename A4,
2889 static Result Perform(Impl* impl, const ::testing::tuple<A0, A1, A2, A3, A4,
2891 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5>(args,
2892 get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args),
2893 get<5>(args), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
2897 template <typename A0, typename A1, typename A2, typename A3, typename A4,
2898 typename A5, typename A6>
2899 static Result Perform(Impl* impl, const ::testing::tuple<A0, A1, A2, A3, A4,
2901 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6>(args,
2902 get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args),
2903 get<5>(args), get<6>(args), ExcessiveArg(), ExcessiveArg(),
2907 template <typename A0, typename A1, typename A2, typename A3, typename A4,
2908 typename A5, typename A6, typename A7>
2909 static Result Perform(Impl* impl, const ::testing::tuple<A0, A1, A2, A3, A4,
2910 A5, A6, A7>& args) {
2911 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6,
2912 A7>(args, get<0>(args), get<1>(args), get<2>(args), get<3>(args),
2913 get<4>(args), get<5>(args), get<6>(args), get<7>(args), ExcessiveArg(),
2917 template <typename A0, typename A1, typename A2, typename A3, typename A4,
2918 typename A5, typename A6, typename A7, typename A8>
2919 static Result Perform(Impl* impl, const ::testing::tuple<A0, A1, A2, A3, A4,
2920 A5, A6, A7, A8>& args) {
2921 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6, A7,
2922 A8>(args, get<0>(args), get<1>(args), get<2>(args), get<3>(args),
2923 get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args),
2927 template <typename A0, typename A1, typename A2, typename A3, typename A4,
2928 typename A5, typename A6, typename A7, typename A8, typename A9>
2929 static Result Perform(Impl* impl, const ::testing::tuple<A0, A1, A2, A3, A4,
2930 A5, A6, A7, A8, A9>& args) {
2931 return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6, A7, A8,
2932 A9>(args, get<0>(args), get<1>(args), get<2>(args), get<3>(args),
2933 get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args),
2938 } // namespace internal
2940 // Various overloads for Invoke().
2942 // WithArgs<N1, N2, ..., Nk>(an_action) creates an action that passes
2943 // the selected arguments of the mock function to an_action and
2944 // performs it. It serves as an adaptor between actions with
2945 // different argument lists. C++ doesn't support default arguments for
2946 // function templates, so we have to overload it.
2947 template <int k1, typename InnerAction>
2948 inline internal::WithArgsAction<InnerAction, k1>
2949 WithArgs(const InnerAction& action) {
2950 return internal::WithArgsAction<InnerAction, k1>(action);
2953 template <int k1, int k2, typename InnerAction>
2954 inline internal::WithArgsAction<InnerAction, k1, k2>
2955 WithArgs(const InnerAction& action) {
2956 return internal::WithArgsAction<InnerAction, k1, k2>(action);
2959 template <int k1, int k2, int k3, typename InnerAction>
2960 inline internal::WithArgsAction<InnerAction, k1, k2, k3>
2961 WithArgs(const InnerAction& action) {
2962 return internal::WithArgsAction<InnerAction, k1, k2, k3>(action);
2965 template <int k1, int k2, int k3, int k4, typename InnerAction>
2966 inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4>
2967 WithArgs(const InnerAction& action) {
2968 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4>(action);
2971 template <int k1, int k2, int k3, int k4, int k5, typename InnerAction>
2972 inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5>
2973 WithArgs(const InnerAction& action) {
2974 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5>(action);
2977 template <int k1, int k2, int k3, int k4, int k5, int k6, typename InnerAction>
2978 inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6>
2979 WithArgs(const InnerAction& action) {
2980 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6>(action);
2983 template <int k1, int k2, int k3, int k4, int k5, int k6, int k7,
2984 typename InnerAction>
2985 inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7>
2986 WithArgs(const InnerAction& action) {
2987 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6,
2991 template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
2992 typename InnerAction>
2993 inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8>
2994 WithArgs(const InnerAction& action) {
2995 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7,
2999 template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
3000 int k9, typename InnerAction>
3001 inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8, k9>
3002 WithArgs(const InnerAction& action) {
3003 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8,
3007 template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
3008 int k9, int k10, typename InnerAction>
3009 inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8,
3011 WithArgs(const InnerAction& action) {
3012 return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8,
3016 // Creates an action that does actions a1, a2, ..., sequentially in
3018 template <typename Action1, typename Action2>
3019 inline internal::DoBothAction<Action1, Action2>
3020 DoAll(Action1 a1, Action2 a2) {
3021 return internal::DoBothAction<Action1, Action2>(a1, a2);
3024 template <typename Action1, typename Action2, typename Action3>
3025 inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
3027 DoAll(Action1 a1, Action2 a2, Action3 a3) {
3028 return DoAll(a1, DoAll(a2, a3));
3031 template <typename Action1, typename Action2, typename Action3,
3033 inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
3034 internal::DoBothAction<Action3, Action4> > >
3035 DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4) {
3036 return DoAll(a1, DoAll(a2, a3, a4));
3039 template <typename Action1, typename Action2, typename Action3,
3040 typename Action4, typename Action5>
3041 inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
3042 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
3044 DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5) {
3045 return DoAll(a1, DoAll(a2, a3, a4, a5));
3048 template <typename Action1, typename Action2, typename Action3,
3049 typename Action4, typename Action5, typename Action6>
3050 inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
3051 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
3052 internal::DoBothAction<Action5, Action6> > > > >
3053 DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6) {
3054 return DoAll(a1, DoAll(a2, a3, a4, a5, a6));
3057 template <typename Action1, typename Action2, typename Action3,
3058 typename Action4, typename Action5, typename Action6, typename Action7>
3059 inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
3060 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
3061 internal::DoBothAction<Action5, internal::DoBothAction<Action6,
3063 DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
3065 return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7));
3068 template <typename Action1, typename Action2, typename Action3,
3069 typename Action4, typename Action5, typename Action6, typename Action7,
3071 inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
3072 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
3073 internal::DoBothAction<Action5, internal::DoBothAction<Action6,
3074 internal::DoBothAction<Action7, Action8> > > > > > >
3075 DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
3076 Action7 a7, Action8 a8) {
3077 return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8));
3080 template <typename Action1, typename Action2, typename Action3,
3081 typename Action4, typename Action5, typename Action6, typename Action7,
3082 typename Action8, typename Action9>
3083 inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
3084 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
3085 internal::DoBothAction<Action5, internal::DoBothAction<Action6,
3086 internal::DoBothAction<Action7, internal::DoBothAction<Action8,
3087 Action9> > > > > > > >
3088 DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
3089 Action7 a7, Action8 a8, Action9 a9) {
3090 return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8, a9));
3093 template <typename Action1, typename Action2, typename Action3,
3094 typename Action4, typename Action5, typename Action6, typename Action7,
3095 typename Action8, typename Action9, typename Action10>
3096 inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
3097 internal::DoBothAction<Action3, internal::DoBothAction<Action4,
3098 internal::DoBothAction<Action5, internal::DoBothAction<Action6,
3099 internal::DoBothAction<Action7, internal::DoBothAction<Action8,
3100 internal::DoBothAction<Action9, Action10> > > > > > > > >
3101 DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
3102 Action7 a7, Action8 a8, Action9 a9, Action10 a10) {
3103 return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8, a9, a10));
3106 } // namespace testing
3108 // The ACTION* family of macros can be used in a namespace scope to
3109 // define custom actions easily. The syntax:
3111 // ACTION(name) { statements; }
3113 // will define an action with the given name that executes the
3114 // statements. The value returned by the statements will be used as
3115 // the return value of the action. Inside the statements, you can
3116 // refer to the K-th (0-based) argument of the mock function by
3117 // 'argK', and refer to its type by 'argK_type'. For example:
3119 // ACTION(IncrementArg1) {
3120 // arg1_type temp = arg1;
3121 // return ++(*temp);
3124 // allows you to write
3126 // ...WillOnce(IncrementArg1());
3128 // You can also refer to the entire argument tuple and its type by
3129 // 'args' and 'args_type', and refer to the mock function type and its
3130 // return type by 'function_type' and 'return_type'.
3132 // Note that you don't need to specify the types of the mock function
3133 // arguments. However rest assured that your code is still type-safe:
3134 // you'll get a compiler error if *arg1 doesn't support the ++
3135 // operator, or if the type of ++(*arg1) isn't compatible with the
3136 // mock function's return type, for example.
3138 // Sometimes you'll want to parameterize the action. For that you can use
3141 // ACTION_P(name, param_name) { statements; }
3145 // ACTION_P(Add, n) { return arg0 + n; }
3147 // will allow you to write:
3149 // ...WillOnce(Add(5));
3151 // Note that you don't need to provide the type of the parameter
3152 // either. If you need to reference the type of a parameter named
3153 // 'foo', you can write 'foo_type'. For example, in the body of
3154 // ACTION_P(Add, n) above, you can write 'n_type' to refer to the type
3157 // We also provide ACTION_P2, ACTION_P3, ..., up to ACTION_P10 to support
3158 // multi-parameter actions.
3160 // For the purpose of typing, you can view
3162 // ACTION_Pk(Foo, p1, ..., pk) { ... }
3166 // template <typename p1_type, ..., typename pk_type>
3167 // FooActionPk<p1_type, ..., pk_type> Foo(p1_type p1, ..., pk_type pk) { ... }
3169 // In particular, you can provide the template type arguments
3170 // explicitly when invoking Foo(), as in Foo<long, bool>(5, false);
3171 // although usually you can rely on the compiler to infer the types
3172 // for you automatically. You can assign the result of expression
3173 // Foo(p1, ..., pk) to a variable of type FooActionPk<p1_type, ...,
3174 // pk_type>. This can be useful when composing actions.
3176 // You can also overload actions with different numbers of parameters:
3178 // ACTION_P(Plus, a) { ... }
3179 // ACTION_P2(Plus, a, b) { ... }
3181 // While it's tempting to always use the ACTION* macros when defining
3182 // a new action, you should also consider implementing ActionInterface
3183 // or using MakePolymorphicAction() instead, especially if you need to
3184 // use the action a lot. While these approaches require more work,
3185 // they give you more control on the types of the mock function
3186 // arguments and the action parameters, which in general leads to
3187 // better compiler error messages that pay off in the long run. They
3188 // also allow overloading actions based on parameter types (as opposed
3189 // to just based on the number of parameters).
3193 // ACTION*() can only be used in a namespace scope. The reason is
3194 // that C++ doesn't yet allow function-local types to be used to
3195 // instantiate templates. The up-coming C++0x standard will fix this.
3196 // Once that's done, we'll consider supporting using ACTION*() inside
3199 // MORE INFORMATION:
3201 // To learn more about using these macros, please search for 'ACTION'
3202 // on http://code.google.com/p/googlemock/wiki/CookBook.
3204 // An internal macro needed for implementing ACTION*().
3205 #define GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_\
3206 const args_type& args GTEST_ATTRIBUTE_UNUSED_, \
3207 arg0_type arg0 GTEST_ATTRIBUTE_UNUSED_, \
3208 arg1_type arg1 GTEST_ATTRIBUTE_UNUSED_, \
3209 arg2_type arg2 GTEST_ATTRIBUTE_UNUSED_, \
3210 arg3_type arg3 GTEST_ATTRIBUTE_UNUSED_, \
3211 arg4_type arg4 GTEST_ATTRIBUTE_UNUSED_, \
3212 arg5_type arg5 GTEST_ATTRIBUTE_UNUSED_, \
3213 arg6_type arg6 GTEST_ATTRIBUTE_UNUSED_, \
3214 arg7_type arg7 GTEST_ATTRIBUTE_UNUSED_, \
3215 arg8_type arg8 GTEST_ATTRIBUTE_UNUSED_, \
3216 arg9_type arg9 GTEST_ATTRIBUTE_UNUSED_
3218 // Sometimes you want to give an action explicit template parameters
3219 // that cannot be inferred from its value parameters. ACTION() and
3220 // ACTION_P*() don't support that. ACTION_TEMPLATE() remedies that
3221 // and can be viewed as an extension to ACTION() and ACTION_P*().
3225 // ACTION_TEMPLATE(ActionName,
3226 // HAS_m_TEMPLATE_PARAMS(kind1, name1, ..., kind_m, name_m),
3227 // AND_n_VALUE_PARAMS(p1, ..., p_n)) { statements; }
3229 // defines an action template that takes m explicit template
3230 // parameters and n value parameters. name_i is the name of the i-th
3231 // template parameter, and kind_i specifies whether it's a typename,
3232 // an integral constant, or a template. p_i is the name of the i-th
3237 // // DuplicateArg<k, T>(output) converts the k-th argument of the mock
3238 // // function to type T and copies it to *output.
3239 // ACTION_TEMPLATE(DuplicateArg,
3240 // HAS_2_TEMPLATE_PARAMS(int, k, typename, T),
3241 // AND_1_VALUE_PARAMS(output)) {
3242 // *output = T(::testing::get<k>(args));
3246 // EXPECT_CALL(mock, Foo(_, _))
3247 // .WillOnce(DuplicateArg<1, unsigned char>(&n));
3249 // To create an instance of an action template, write:
3251 // ActionName<t1, ..., t_m>(v1, ..., v_n)
3253 // where the ts are the template arguments and the vs are the value
3254 // arguments. The value argument types are inferred by the compiler.
3255 // If you want to explicitly specify the value argument types, you can
3256 // provide additional template arguments:
3258 // ActionName<t1, ..., t_m, u1, ..., u_k>(v1, ..., v_n)
3260 // where u_i is the desired type of v_i.
3262 // ACTION_TEMPLATE and ACTION/ACTION_P* can be overloaded on the
3263 // number of value parameters, but not on the number of template
3264 // parameters. Without the restriction, the meaning of the following
3267 // OverloadedAction<int, bool>(x);
3269 // Are we using a single-template-parameter action where 'bool' refers
3270 // to the type of x, or are we using a two-template-parameter action
3271 // where the compiler is asked to infer the type of x?
3273 // Implementation notes:
3275 // GMOCK_INTERNAL_*_HAS_m_TEMPLATE_PARAMS and
3276 // GMOCK_INTERNAL_*_AND_n_VALUE_PARAMS are internal macros for
3277 // implementing ACTION_TEMPLATE. The main trick we use is to create
3278 // new macro invocations when expanding a macro. For example, we have
3280 // #define ACTION_TEMPLATE(name, template_params, value_params)
3281 // ... GMOCK_INTERNAL_DECL_##template_params ...
3283 // which causes ACTION_TEMPLATE(..., HAS_1_TEMPLATE_PARAMS(typename, T), ...)
3286 // ... GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(typename, T) ...
3288 // Since GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS is a macro, the
3289 // preprocessor will continue to expand it to
3291 // ... typename T ...
3293 // This technique conforms to the C++ standard and is portable. It
3294 // allows us to implement action templates using O(N) code, where N is
3295 // the maximum number of template/value parameters supported. Without
3296 // using it, we'd have to devote O(N^2) amount of code to implement all
3297 // combinations of m and n.
3299 // Declares the template parameters.
3300 #define GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(kind0, name0) kind0 name0
3301 #define GMOCK_INTERNAL_DECL_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, \
3302 name1) kind0 name0, kind1 name1
3303 #define GMOCK_INTERNAL_DECL_HAS_3_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3304 kind2, name2) kind0 name0, kind1 name1, kind2 name2
3305 #define GMOCK_INTERNAL_DECL_HAS_4_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3306 kind2, name2, kind3, name3) kind0 name0, kind1 name1, kind2 name2, \
3308 #define GMOCK_INTERNAL_DECL_HAS_5_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3309 kind2, name2, kind3, name3, kind4, name4) kind0 name0, kind1 name1, \
3310 kind2 name2, kind3 name3, kind4 name4
3311 #define GMOCK_INTERNAL_DECL_HAS_6_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3312 kind2, name2, kind3, name3, kind4, name4, kind5, name5) kind0 name0, \
3313 kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5
3314 #define GMOCK_INTERNAL_DECL_HAS_7_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3315 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
3316 name6) kind0 name0, kind1 name1, kind2 name2, kind3 name3, kind4 name4, \
3317 kind5 name5, kind6 name6
3318 #define GMOCK_INTERNAL_DECL_HAS_8_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3319 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
3320 kind7, name7) kind0 name0, kind1 name1, kind2 name2, kind3 name3, \
3321 kind4 name4, kind5 name5, kind6 name6, kind7 name7
3322 #define GMOCK_INTERNAL_DECL_HAS_9_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3323 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
3324 kind7, name7, kind8, name8) kind0 name0, kind1 name1, kind2 name2, \
3325 kind3 name3, kind4 name4, kind5 name5, kind6 name6, kind7 name7, \
3327 #define GMOCK_INTERNAL_DECL_HAS_10_TEMPLATE_PARAMS(kind0, name0, kind1, \
3328 name1, kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
3329 name6, kind7, name7, kind8, name8, kind9, name9) kind0 name0, \
3330 kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5, \
3331 kind6 name6, kind7 name7, kind8 name8, kind9 name9
3333 // Lists the template parameters.
3334 #define GMOCK_INTERNAL_LIST_HAS_1_TEMPLATE_PARAMS(kind0, name0) name0
3335 #define GMOCK_INTERNAL_LIST_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, \
3337 #define GMOCK_INTERNAL_LIST_HAS_3_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3338 kind2, name2) name0, name1, name2
3339 #define GMOCK_INTERNAL_LIST_HAS_4_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3340 kind2, name2, kind3, name3) name0, name1, name2, name3
3341 #define GMOCK_INTERNAL_LIST_HAS_5_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3342 kind2, name2, kind3, name3, kind4, name4) name0, name1, name2, name3, \
3344 #define GMOCK_INTERNAL_LIST_HAS_6_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3345 kind2, name2, kind3, name3, kind4, name4, kind5, name5) name0, name1, \
3346 name2, name3, name4, name5
3347 #define GMOCK_INTERNAL_LIST_HAS_7_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3348 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
3349 name6) name0, name1, name2, name3, name4, name5, name6
3350 #define GMOCK_INTERNAL_LIST_HAS_8_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3351 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
3352 kind7, name7) name0, name1, name2, name3, name4, name5, name6, name7
3353 #define GMOCK_INTERNAL_LIST_HAS_9_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
3354 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
3355 kind7, name7, kind8, name8) name0, name1, name2, name3, name4, name5, \
3357 #define GMOCK_INTERNAL_LIST_HAS_10_TEMPLATE_PARAMS(kind0, name0, kind1, \
3358 name1, kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
3359 name6, kind7, name7, kind8, name8, kind9, name9) name0, name1, name2, \
3360 name3, name4, name5, name6, name7, name8, name9
3362 // Declares the types of value parameters.
3363 #define GMOCK_INTERNAL_DECL_TYPE_AND_0_VALUE_PARAMS()
3364 #define GMOCK_INTERNAL_DECL_TYPE_AND_1_VALUE_PARAMS(p0) , typename p0##_type
3365 #define GMOCK_INTERNAL_DECL_TYPE_AND_2_VALUE_PARAMS(p0, p1) , \
3366 typename p0##_type, typename p1##_type
3367 #define GMOCK_INTERNAL_DECL_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) , \
3368 typename p0##_type, typename p1##_type, typename p2##_type
3369 #define GMOCK_INTERNAL_DECL_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) , \
3370 typename p0##_type, typename p1##_type, typename p2##_type, \
3372 #define GMOCK_INTERNAL_DECL_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) , \
3373 typename p0##_type, typename p1##_type, typename p2##_type, \
3374 typename p3##_type, typename p4##_type
3375 #define GMOCK_INTERNAL_DECL_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) , \
3376 typename p0##_type, typename p1##_type, typename p2##_type, \
3377 typename p3##_type, typename p4##_type, typename p5##_type
3378 #define GMOCK_INTERNAL_DECL_TYPE_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3379 p6) , typename p0##_type, typename p1##_type, typename p2##_type, \
3380 typename p3##_type, typename p4##_type, typename p5##_type, \
3382 #define GMOCK_INTERNAL_DECL_TYPE_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3383 p6, p7) , typename p0##_type, typename p1##_type, typename p2##_type, \
3384 typename p3##_type, typename p4##_type, typename p5##_type, \
3385 typename p6##_type, typename p7##_type
3386 #define GMOCK_INTERNAL_DECL_TYPE_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3387 p6, p7, p8) , typename p0##_type, typename p1##_type, typename p2##_type, \
3388 typename p3##_type, typename p4##_type, typename p5##_type, \
3389 typename p6##_type, typename p7##_type, typename p8##_type
3390 #define GMOCK_INTERNAL_DECL_TYPE_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3391 p6, p7, p8, p9) , typename p0##_type, typename p1##_type, \
3392 typename p2##_type, typename p3##_type, typename p4##_type, \
3393 typename p5##_type, typename p6##_type, typename p7##_type, \
3394 typename p8##_type, typename p9##_type
3396 // Initializes the value parameters.
3397 #define GMOCK_INTERNAL_INIT_AND_0_VALUE_PARAMS()\
3399 #define GMOCK_INTERNAL_INIT_AND_1_VALUE_PARAMS(p0)\
3400 (p0##_type gmock_p0) : p0(gmock_p0)
3401 #define GMOCK_INTERNAL_INIT_AND_2_VALUE_PARAMS(p0, p1)\
3402 (p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), p1(gmock_p1)
3403 #define GMOCK_INTERNAL_INIT_AND_3_VALUE_PARAMS(p0, p1, p2)\
3404 (p0##_type gmock_p0, p1##_type gmock_p1, \
3405 p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2)
3406 #define GMOCK_INTERNAL_INIT_AND_4_VALUE_PARAMS(p0, p1, p2, p3)\
3407 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3408 p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
3410 #define GMOCK_INTERNAL_INIT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)\
3411 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3412 p3##_type gmock_p3, p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), \
3413 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4)
3414 #define GMOCK_INTERNAL_INIT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)\
3415 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3416 p3##_type gmock_p3, p4##_type gmock_p4, \
3417 p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
3418 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5)
3419 #define GMOCK_INTERNAL_INIT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)\
3420 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3421 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
3422 p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
3423 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6)
3424 #define GMOCK_INTERNAL_INIT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)\
3425 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3426 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
3427 p6##_type gmock_p6, p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), \
3428 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
3430 #define GMOCK_INTERNAL_INIT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3432 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3433 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
3434 p6##_type gmock_p6, p7##_type gmock_p7, \
3435 p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
3436 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
3438 #define GMOCK_INTERNAL_INIT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3440 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3441 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
3442 p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
3443 p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
3444 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
3445 p8(gmock_p8), p9(gmock_p9)
3447 // Declares the fields for storing the value parameters.
3448 #define GMOCK_INTERNAL_DEFN_AND_0_VALUE_PARAMS()
3449 #define GMOCK_INTERNAL_DEFN_AND_1_VALUE_PARAMS(p0) p0##_type p0;
3450 #define GMOCK_INTERNAL_DEFN_AND_2_VALUE_PARAMS(p0, p1) p0##_type p0; \
3452 #define GMOCK_INTERNAL_DEFN_AND_3_VALUE_PARAMS(p0, p1, p2) p0##_type p0; \
3453 p1##_type p1; p2##_type p2;
3454 #define GMOCK_INTERNAL_DEFN_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0##_type p0; \
3455 p1##_type p1; p2##_type p2; p3##_type p3;
3456 #define GMOCK_INTERNAL_DEFN_AND_5_VALUE_PARAMS(p0, p1, p2, p3, \
3457 p4) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4;
3458 #define GMOCK_INTERNAL_DEFN_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, \
3459 p5) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \
3461 #define GMOCK_INTERNAL_DEFN_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3462 p6) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \
3463 p5##_type p5; p6##_type p6;
3464 #define GMOCK_INTERNAL_DEFN_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3465 p7) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \
3466 p5##_type p5; p6##_type p6; p7##_type p7;
3467 #define GMOCK_INTERNAL_DEFN_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3468 p7, p8) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; \
3469 p4##_type p4; p5##_type p5; p6##_type p6; p7##_type p7; p8##_type p8;
3470 #define GMOCK_INTERNAL_DEFN_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3471 p7, p8, p9) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; \
3472 p4##_type p4; p5##_type p5; p6##_type p6; p7##_type p7; p8##_type p8; \
3475 // Lists the value parameters.
3476 #define GMOCK_INTERNAL_LIST_AND_0_VALUE_PARAMS()
3477 #define GMOCK_INTERNAL_LIST_AND_1_VALUE_PARAMS(p0) p0
3478 #define GMOCK_INTERNAL_LIST_AND_2_VALUE_PARAMS(p0, p1) p0, p1
3479 #define GMOCK_INTERNAL_LIST_AND_3_VALUE_PARAMS(p0, p1, p2) p0, p1, p2
3480 #define GMOCK_INTERNAL_LIST_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0, p1, p2, p3
3481 #define GMOCK_INTERNAL_LIST_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) p0, p1, \
3483 #define GMOCK_INTERNAL_LIST_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) p0, \
3485 #define GMOCK_INTERNAL_LIST_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3486 p6) p0, p1, p2, p3, p4, p5, p6
3487 #define GMOCK_INTERNAL_LIST_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3488 p7) p0, p1, p2, p3, p4, p5, p6, p7
3489 #define GMOCK_INTERNAL_LIST_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3490 p7, p8) p0, p1, p2, p3, p4, p5, p6, p7, p8
3491 #define GMOCK_INTERNAL_LIST_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3492 p7, p8, p9) p0, p1, p2, p3, p4, p5, p6, p7, p8, p9
3494 // Lists the value parameter types.
3495 #define GMOCK_INTERNAL_LIST_TYPE_AND_0_VALUE_PARAMS()
3496 #define GMOCK_INTERNAL_LIST_TYPE_AND_1_VALUE_PARAMS(p0) , p0##_type
3497 #define GMOCK_INTERNAL_LIST_TYPE_AND_2_VALUE_PARAMS(p0, p1) , p0##_type, \
3499 #define GMOCK_INTERNAL_LIST_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) , p0##_type, \
3500 p1##_type, p2##_type
3501 #define GMOCK_INTERNAL_LIST_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) , \
3502 p0##_type, p1##_type, p2##_type, p3##_type
3503 #define GMOCK_INTERNAL_LIST_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) , \
3504 p0##_type, p1##_type, p2##_type, p3##_type, p4##_type
3505 #define GMOCK_INTERNAL_LIST_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) , \
3506 p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type
3507 #define GMOCK_INTERNAL_LIST_TYPE_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3508 p6) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type, \
3510 #define GMOCK_INTERNAL_LIST_TYPE_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3511 p6, p7) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
3512 p5##_type, p6##_type, p7##_type
3513 #define GMOCK_INTERNAL_LIST_TYPE_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3514 p6, p7, p8) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
3515 p5##_type, p6##_type, p7##_type, p8##_type
3516 #define GMOCK_INTERNAL_LIST_TYPE_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3517 p6, p7, p8, p9) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
3518 p5##_type, p6##_type, p7##_type, p8##_type, p9##_type
3520 // Declares the value parameters.
3521 #define GMOCK_INTERNAL_DECL_AND_0_VALUE_PARAMS()
3522 #define GMOCK_INTERNAL_DECL_AND_1_VALUE_PARAMS(p0) p0##_type p0
3523 #define GMOCK_INTERNAL_DECL_AND_2_VALUE_PARAMS(p0, p1) p0##_type p0, \
3525 #define GMOCK_INTERNAL_DECL_AND_3_VALUE_PARAMS(p0, p1, p2) p0##_type p0, \
3526 p1##_type p1, p2##_type p2
3527 #define GMOCK_INTERNAL_DECL_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0##_type p0, \
3528 p1##_type p1, p2##_type p2, p3##_type p3
3529 #define GMOCK_INTERNAL_DECL_AND_5_VALUE_PARAMS(p0, p1, p2, p3, \
3530 p4) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4
3531 #define GMOCK_INTERNAL_DECL_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, \
3532 p5) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \
3534 #define GMOCK_INTERNAL_DECL_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
3535 p6) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \
3536 p5##_type p5, p6##_type p6
3537 #define GMOCK_INTERNAL_DECL_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3538 p7) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \
3539 p5##_type p5, p6##_type p6, p7##_type p7
3540 #define GMOCK_INTERNAL_DECL_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3541 p7, p8) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
3542 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8
3543 #define GMOCK_INTERNAL_DECL_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3544 p7, p8, p9) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
3545 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \
3548 // The suffix of the class template implementing the action template.
3549 #define GMOCK_INTERNAL_COUNT_AND_0_VALUE_PARAMS()
3550 #define GMOCK_INTERNAL_COUNT_AND_1_VALUE_PARAMS(p0) P
3551 #define GMOCK_INTERNAL_COUNT_AND_2_VALUE_PARAMS(p0, p1) P2
3552 #define GMOCK_INTERNAL_COUNT_AND_3_VALUE_PARAMS(p0, p1, p2) P3
3553 #define GMOCK_INTERNAL_COUNT_AND_4_VALUE_PARAMS(p0, p1, p2, p3) P4
3554 #define GMOCK_INTERNAL_COUNT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) P5
3555 #define GMOCK_INTERNAL_COUNT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) P6
3556 #define GMOCK_INTERNAL_COUNT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6) P7
3557 #define GMOCK_INTERNAL_COUNT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3559 #define GMOCK_INTERNAL_COUNT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3561 #define GMOCK_INTERNAL_COUNT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
3564 // The name of the class template implementing the action template.
3565 #define GMOCK_ACTION_CLASS_(name, value_params)\
3566 GTEST_CONCAT_TOKEN_(name##Action, GMOCK_INTERNAL_COUNT_##value_params)
3568 #define ACTION_TEMPLATE(name, template_params, value_params)\
3569 template <GMOCK_INTERNAL_DECL_##template_params\
3570 GMOCK_INTERNAL_DECL_TYPE_##value_params>\
3571 class GMOCK_ACTION_CLASS_(name, value_params) {\
3573 explicit GMOCK_ACTION_CLASS_(name, value_params)\
3574 GMOCK_INTERNAL_INIT_##value_params {}\
3575 template <typename F>\
3576 class gmock_Impl : public ::testing::ActionInterface<F> {\
3578 typedef F function_type;\
3579 typedef typename ::testing::internal::Function<F>::Result return_type;\
3580 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
3582 explicit gmock_Impl GMOCK_INTERNAL_INIT_##value_params {}\
3583 virtual return_type Perform(const args_type& args) {\
3584 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
3585 Perform(this, args);\
3587 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3588 typename arg3_type, typename arg4_type, typename arg5_type, \
3589 typename arg6_type, typename arg7_type, typename arg8_type, \
3590 typename arg9_type>\
3591 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
3592 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
3593 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
3594 arg9_type arg9) const;\
3595 GMOCK_INTERNAL_DEFN_##value_params\
3597 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
3599 template <typename F> operator ::testing::Action<F>() const {\
3600 return ::testing::Action<F>(\
3601 new gmock_Impl<F>(GMOCK_INTERNAL_LIST_##value_params));\
3603 GMOCK_INTERNAL_DEFN_##value_params\
3605 GTEST_DISALLOW_ASSIGN_(GMOCK_ACTION_CLASS_(name, value_params));\
3607 template <GMOCK_INTERNAL_DECL_##template_params\
3608 GMOCK_INTERNAL_DECL_TYPE_##value_params>\
3609 inline GMOCK_ACTION_CLASS_(name, value_params)<\
3610 GMOCK_INTERNAL_LIST_##template_params\
3611 GMOCK_INTERNAL_LIST_TYPE_##value_params> name(\
3612 GMOCK_INTERNAL_DECL_##value_params) {\
3613 return GMOCK_ACTION_CLASS_(name, value_params)<\
3614 GMOCK_INTERNAL_LIST_##template_params\
3615 GMOCK_INTERNAL_LIST_TYPE_##value_params>(\
3616 GMOCK_INTERNAL_LIST_##value_params);\
3618 template <GMOCK_INTERNAL_DECL_##template_params\
3619 GMOCK_INTERNAL_DECL_TYPE_##value_params>\
3620 template <typename F>\
3621 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3622 typename arg3_type, typename arg4_type, typename arg5_type, \
3623 typename arg6_type, typename arg7_type, typename arg8_type, \
3624 typename arg9_type>\
3625 typename ::testing::internal::Function<F>::Result\
3626 GMOCK_ACTION_CLASS_(name, value_params)<\
3627 GMOCK_INTERNAL_LIST_##template_params\
3628 GMOCK_INTERNAL_LIST_TYPE_##value_params>::gmock_Impl<F>::\
3630 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
3632 #define ACTION(name)\
3633 class name##Action {\
3636 template <typename F>\
3637 class gmock_Impl : public ::testing::ActionInterface<F> {\
3639 typedef F function_type;\
3640 typedef typename ::testing::internal::Function<F>::Result return_type;\
3641 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
3644 virtual return_type Perform(const args_type& args) {\
3645 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
3646 Perform(this, args);\
3648 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3649 typename arg3_type, typename arg4_type, typename arg5_type, \
3650 typename arg6_type, typename arg7_type, typename arg8_type, \
3651 typename arg9_type>\
3652 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
3653 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
3654 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
3655 arg9_type arg9) const;\
3657 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
3659 template <typename F> operator ::testing::Action<F>() const {\
3660 return ::testing::Action<F>(new gmock_Impl<F>());\
3663 GTEST_DISALLOW_ASSIGN_(name##Action);\
3665 inline name##Action name() {\
3666 return name##Action();\
3668 template <typename F>\
3669 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3670 typename arg3_type, typename arg4_type, typename arg5_type, \
3671 typename arg6_type, typename arg7_type, typename arg8_type, \
3672 typename arg9_type>\
3673 typename ::testing::internal::Function<F>::Result\
3674 name##Action::gmock_Impl<F>::gmock_PerformImpl(\
3675 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
3677 #define ACTION_P(name, p0)\
3678 template <typename p0##_type>\
3679 class name##ActionP {\
3681 explicit name##ActionP(p0##_type gmock_p0) : p0(gmock_p0) {}\
3682 template <typename F>\
3683 class gmock_Impl : public ::testing::ActionInterface<F> {\
3685 typedef F function_type;\
3686 typedef typename ::testing::internal::Function<F>::Result return_type;\
3687 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
3689 explicit gmock_Impl(p0##_type gmock_p0) : p0(gmock_p0) {}\
3690 virtual return_type Perform(const args_type& args) {\
3691 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
3692 Perform(this, args);\
3694 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3695 typename arg3_type, typename arg4_type, typename arg5_type, \
3696 typename arg6_type, typename arg7_type, typename arg8_type, \
3697 typename arg9_type>\
3698 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
3699 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
3700 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
3701 arg9_type arg9) const;\
3704 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
3706 template <typename F> operator ::testing::Action<F>() const {\
3707 return ::testing::Action<F>(new gmock_Impl<F>(p0));\
3711 GTEST_DISALLOW_ASSIGN_(name##ActionP);\
3713 template <typename p0##_type>\
3714 inline name##ActionP<p0##_type> name(p0##_type p0) {\
3715 return name##ActionP<p0##_type>(p0);\
3717 template <typename p0##_type>\
3718 template <typename F>\
3719 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3720 typename arg3_type, typename arg4_type, typename arg5_type, \
3721 typename arg6_type, typename arg7_type, typename arg8_type, \
3722 typename arg9_type>\
3723 typename ::testing::internal::Function<F>::Result\
3724 name##ActionP<p0##_type>::gmock_Impl<F>::gmock_PerformImpl(\
3725 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
3727 #define ACTION_P2(name, p0, p1)\
3728 template <typename p0##_type, typename p1##_type>\
3729 class name##ActionP2 {\
3731 name##ActionP2(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \
3733 template <typename F>\
3734 class gmock_Impl : public ::testing::ActionInterface<F> {\
3736 typedef F function_type;\
3737 typedef typename ::testing::internal::Function<F>::Result return_type;\
3738 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
3740 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \
3742 virtual return_type Perform(const args_type& args) {\
3743 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
3744 Perform(this, args);\
3746 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3747 typename arg3_type, typename arg4_type, typename arg5_type, \
3748 typename arg6_type, typename arg7_type, typename arg8_type, \
3749 typename arg9_type>\
3750 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
3751 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
3752 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
3753 arg9_type arg9) const;\
3757 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
3759 template <typename F> operator ::testing::Action<F>() const {\
3760 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1));\
3765 GTEST_DISALLOW_ASSIGN_(name##ActionP2);\
3767 template <typename p0##_type, typename p1##_type>\
3768 inline name##ActionP2<p0##_type, p1##_type> name(p0##_type p0, \
3770 return name##ActionP2<p0##_type, p1##_type>(p0, p1);\
3772 template <typename p0##_type, typename p1##_type>\
3773 template <typename F>\
3774 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3775 typename arg3_type, typename arg4_type, typename arg5_type, \
3776 typename arg6_type, typename arg7_type, typename arg8_type, \
3777 typename arg9_type>\
3778 typename ::testing::internal::Function<F>::Result\
3779 name##ActionP2<p0##_type, p1##_type>::gmock_Impl<F>::gmock_PerformImpl(\
3780 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
3782 #define ACTION_P3(name, p0, p1, p2)\
3783 template <typename p0##_type, typename p1##_type, typename p2##_type>\
3784 class name##ActionP3 {\
3786 name##ActionP3(p0##_type gmock_p0, p1##_type gmock_p1, \
3787 p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\
3788 template <typename F>\
3789 class gmock_Impl : public ::testing::ActionInterface<F> {\
3791 typedef F function_type;\
3792 typedef typename ::testing::internal::Function<F>::Result return_type;\
3793 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
3795 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, \
3796 p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\
3797 virtual return_type Perform(const args_type& args) {\
3798 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
3799 Perform(this, args);\
3801 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3802 typename arg3_type, typename arg4_type, typename arg5_type, \
3803 typename arg6_type, typename arg7_type, typename arg8_type, \
3804 typename arg9_type>\
3805 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
3806 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
3807 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
3808 arg9_type arg9) const;\
3813 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
3815 template <typename F> operator ::testing::Action<F>() const {\
3816 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2));\
3822 GTEST_DISALLOW_ASSIGN_(name##ActionP3);\
3824 template <typename p0##_type, typename p1##_type, typename p2##_type>\
3825 inline name##ActionP3<p0##_type, p1##_type, p2##_type> name(p0##_type p0, \
3826 p1##_type p1, p2##_type p2) {\
3827 return name##ActionP3<p0##_type, p1##_type, p2##_type>(p0, p1, p2);\
3829 template <typename p0##_type, typename p1##_type, typename p2##_type>\
3830 template <typename F>\
3831 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3832 typename arg3_type, typename arg4_type, typename arg5_type, \
3833 typename arg6_type, typename arg7_type, typename arg8_type, \
3834 typename arg9_type>\
3835 typename ::testing::internal::Function<F>::Result\
3836 name##ActionP3<p0##_type, p1##_type, \
3837 p2##_type>::gmock_Impl<F>::gmock_PerformImpl(\
3838 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
3840 #define ACTION_P4(name, p0, p1, p2, p3)\
3841 template <typename p0##_type, typename p1##_type, typename p2##_type, \
3842 typename p3##_type>\
3843 class name##ActionP4 {\
3845 name##ActionP4(p0##_type gmock_p0, p1##_type gmock_p1, \
3846 p2##_type gmock_p2, p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), \
3847 p2(gmock_p2), p3(gmock_p3) {}\
3848 template <typename F>\
3849 class gmock_Impl : public ::testing::ActionInterface<F> {\
3851 typedef F function_type;\
3852 typedef typename ::testing::internal::Function<F>::Result return_type;\
3853 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
3855 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3856 p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
3858 virtual return_type Perform(const args_type& args) {\
3859 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
3860 Perform(this, args);\
3862 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3863 typename arg3_type, typename arg4_type, typename arg5_type, \
3864 typename arg6_type, typename arg7_type, typename arg8_type, \
3865 typename arg9_type>\
3866 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
3867 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
3868 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
3869 arg9_type arg9) const;\
3875 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
3877 template <typename F> operator ::testing::Action<F>() const {\
3878 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3));\
3885 GTEST_DISALLOW_ASSIGN_(name##ActionP4);\
3887 template <typename p0##_type, typename p1##_type, typename p2##_type, \
3888 typename p3##_type>\
3889 inline name##ActionP4<p0##_type, p1##_type, p2##_type, \
3890 p3##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
3892 return name##ActionP4<p0##_type, p1##_type, p2##_type, p3##_type>(p0, p1, \
3895 template <typename p0##_type, typename p1##_type, typename p2##_type, \
3896 typename p3##_type>\
3897 template <typename F>\
3898 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3899 typename arg3_type, typename arg4_type, typename arg5_type, \
3900 typename arg6_type, typename arg7_type, typename arg8_type, \
3901 typename arg9_type>\
3902 typename ::testing::internal::Function<F>::Result\
3903 name##ActionP4<p0##_type, p1##_type, p2##_type, \
3904 p3##_type>::gmock_Impl<F>::gmock_PerformImpl(\
3905 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
3907 #define ACTION_P5(name, p0, p1, p2, p3, p4)\
3908 template <typename p0##_type, typename p1##_type, typename p2##_type, \
3909 typename p3##_type, typename p4##_type>\
3910 class name##ActionP5 {\
3912 name##ActionP5(p0##_type gmock_p0, p1##_type gmock_p1, \
3913 p2##_type gmock_p2, p3##_type gmock_p3, \
3914 p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
3915 p3(gmock_p3), p4(gmock_p4) {}\
3916 template <typename F>\
3917 class gmock_Impl : public ::testing::ActionInterface<F> {\
3919 typedef F function_type;\
3920 typedef typename ::testing::internal::Function<F>::Result return_type;\
3921 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
3923 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3924 p3##_type gmock_p3, p4##_type gmock_p4) : p0(gmock_p0), \
3925 p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), p4(gmock_p4) {}\
3926 virtual return_type Perform(const args_type& args) {\
3927 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
3928 Perform(this, args);\
3930 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3931 typename arg3_type, typename arg4_type, typename arg5_type, \
3932 typename arg6_type, typename arg7_type, typename arg8_type, \
3933 typename arg9_type>\
3934 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
3935 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
3936 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
3937 arg9_type arg9) const;\
3944 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
3946 template <typename F> operator ::testing::Action<F>() const {\
3947 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4));\
3955 GTEST_DISALLOW_ASSIGN_(name##ActionP5);\
3957 template <typename p0##_type, typename p1##_type, typename p2##_type, \
3958 typename p3##_type, typename p4##_type>\
3959 inline name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \
3960 p4##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
3962 return name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \
3963 p4##_type>(p0, p1, p2, p3, p4);\
3965 template <typename p0##_type, typename p1##_type, typename p2##_type, \
3966 typename p3##_type, typename p4##_type>\
3967 template <typename F>\
3968 template <typename arg0_type, typename arg1_type, typename arg2_type, \
3969 typename arg3_type, typename arg4_type, typename arg5_type, \
3970 typename arg6_type, typename arg7_type, typename arg8_type, \
3971 typename arg9_type>\
3972 typename ::testing::internal::Function<F>::Result\
3973 name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \
3974 p4##_type>::gmock_Impl<F>::gmock_PerformImpl(\
3975 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
3977 #define ACTION_P6(name, p0, p1, p2, p3, p4, p5)\
3978 template <typename p0##_type, typename p1##_type, typename p2##_type, \
3979 typename p3##_type, typename p4##_type, typename p5##_type>\
3980 class name##ActionP6 {\
3982 name##ActionP6(p0##_type gmock_p0, p1##_type gmock_p1, \
3983 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
3984 p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
3985 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {}\
3986 template <typename F>\
3987 class gmock_Impl : public ::testing::ActionInterface<F> {\
3989 typedef F function_type;\
3990 typedef typename ::testing::internal::Function<F>::Result return_type;\
3991 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
3993 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
3994 p3##_type gmock_p3, p4##_type gmock_p4, \
3995 p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
3996 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {}\
3997 virtual return_type Perform(const args_type& args) {\
3998 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
3999 Perform(this, args);\
4001 template <typename arg0_type, typename arg1_type, typename arg2_type, \
4002 typename arg3_type, typename arg4_type, typename arg5_type, \
4003 typename arg6_type, typename arg7_type, typename arg8_type, \
4004 typename arg9_type>\
4005 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
4006 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
4007 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
4008 arg9_type arg9) const;\
4016 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
4018 template <typename F> operator ::testing::Action<F>() const {\
4019 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5));\
4028 GTEST_DISALLOW_ASSIGN_(name##ActionP6);\
4030 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4031 typename p3##_type, typename p4##_type, typename p5##_type>\
4032 inline name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, \
4033 p4##_type, p5##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
4034 p3##_type p3, p4##_type p4, p5##_type p5) {\
4035 return name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, \
4036 p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5);\
4038 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4039 typename p3##_type, typename p4##_type, typename p5##_type>\
4040 template <typename F>\
4041 template <typename arg0_type, typename arg1_type, typename arg2_type, \
4042 typename arg3_type, typename arg4_type, typename arg5_type, \
4043 typename arg6_type, typename arg7_type, typename arg8_type, \
4044 typename arg9_type>\
4045 typename ::testing::internal::Function<F>::Result\
4046 name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
4047 p5##_type>::gmock_Impl<F>::gmock_PerformImpl(\
4048 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
4050 #define ACTION_P7(name, p0, p1, p2, p3, p4, p5, p6)\
4051 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4052 typename p3##_type, typename p4##_type, typename p5##_type, \
4053 typename p6##_type>\
4054 class name##ActionP7 {\
4056 name##ActionP7(p0##_type gmock_p0, p1##_type gmock_p1, \
4057 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
4058 p5##_type gmock_p5, p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), \
4059 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), \
4061 template <typename F>\
4062 class gmock_Impl : public ::testing::ActionInterface<F> {\
4064 typedef F function_type;\
4065 typedef typename ::testing::internal::Function<F>::Result return_type;\
4066 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
4068 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
4069 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
4070 p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
4071 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6) {}\
4072 virtual return_type Perform(const args_type& args) {\
4073 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
4074 Perform(this, args);\
4076 template <typename arg0_type, typename arg1_type, typename arg2_type, \
4077 typename arg3_type, typename arg4_type, typename arg5_type, \
4078 typename arg6_type, typename arg7_type, typename arg8_type, \
4079 typename arg9_type>\
4080 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
4081 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
4082 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
4083 arg9_type arg9) const;\
4092 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
4094 template <typename F> operator ::testing::Action<F>() const {\
4095 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
4106 GTEST_DISALLOW_ASSIGN_(name##ActionP7);\
4108 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4109 typename p3##_type, typename p4##_type, typename p5##_type, \
4110 typename p6##_type>\
4111 inline name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, \
4112 p4##_type, p5##_type, p6##_type> name(p0##_type p0, p1##_type p1, \
4113 p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
4115 return name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, \
4116 p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, p6);\
4118 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4119 typename p3##_type, typename p4##_type, typename p5##_type, \
4120 typename p6##_type>\
4121 template <typename F>\
4122 template <typename arg0_type, typename arg1_type, typename arg2_type, \
4123 typename arg3_type, typename arg4_type, typename arg5_type, \
4124 typename arg6_type, typename arg7_type, typename arg8_type, \
4125 typename arg9_type>\
4126 typename ::testing::internal::Function<F>::Result\
4127 name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
4128 p5##_type, p6##_type>::gmock_Impl<F>::gmock_PerformImpl(\
4129 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
4131 #define ACTION_P8(name, p0, p1, p2, p3, p4, p5, p6, p7)\
4132 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4133 typename p3##_type, typename p4##_type, typename p5##_type, \
4134 typename p6##_type, typename p7##_type>\
4135 class name##ActionP8 {\
4137 name##ActionP8(p0##_type gmock_p0, p1##_type gmock_p1, \
4138 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
4139 p5##_type gmock_p5, p6##_type gmock_p6, \
4140 p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
4141 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
4143 template <typename F>\
4144 class gmock_Impl : public ::testing::ActionInterface<F> {\
4146 typedef F function_type;\
4147 typedef typename ::testing::internal::Function<F>::Result return_type;\
4148 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
4150 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
4151 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
4152 p6##_type gmock_p6, p7##_type gmock_p7) : p0(gmock_p0), \
4153 p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), \
4154 p5(gmock_p5), p6(gmock_p6), p7(gmock_p7) {}\
4155 virtual return_type Perform(const args_type& args) {\
4156 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
4157 Perform(this, args);\
4159 template <typename arg0_type, typename arg1_type, typename arg2_type, \
4160 typename arg3_type, typename arg4_type, typename arg5_type, \
4161 typename arg6_type, typename arg7_type, typename arg8_type, \
4162 typename arg9_type>\
4163 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
4164 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
4165 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
4166 arg9_type arg9) const;\
4176 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
4178 template <typename F> operator ::testing::Action<F>() const {\
4179 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
4191 GTEST_DISALLOW_ASSIGN_(name##ActionP8);\
4193 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4194 typename p3##_type, typename p4##_type, typename p5##_type, \
4195 typename p6##_type, typename p7##_type>\
4196 inline name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, \
4197 p4##_type, p5##_type, p6##_type, p7##_type> name(p0##_type p0, \
4198 p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
4199 p6##_type p6, p7##_type p7) {\
4200 return name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, \
4201 p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, p3, p4, p5, \
4204 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4205 typename p3##_type, typename p4##_type, typename p5##_type, \
4206 typename p6##_type, typename p7##_type>\
4207 template <typename F>\
4208 template <typename arg0_type, typename arg1_type, typename arg2_type, \
4209 typename arg3_type, typename arg4_type, typename arg5_type, \
4210 typename arg6_type, typename arg7_type, typename arg8_type, \
4211 typename arg9_type>\
4212 typename ::testing::internal::Function<F>::Result\
4213 name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
4214 p5##_type, p6##_type, \
4215 p7##_type>::gmock_Impl<F>::gmock_PerformImpl(\
4216 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
4218 #define ACTION_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8)\
4219 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4220 typename p3##_type, typename p4##_type, typename p5##_type, \
4221 typename p6##_type, typename p7##_type, typename p8##_type>\
4222 class name##ActionP9 {\
4224 name##ActionP9(p0##_type gmock_p0, p1##_type gmock_p1, \
4225 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
4226 p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
4227 p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
4228 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
4230 template <typename F>\
4231 class gmock_Impl : public ::testing::ActionInterface<F> {\
4233 typedef F function_type;\
4234 typedef typename ::testing::internal::Function<F>::Result return_type;\
4235 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
4237 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
4238 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
4239 p6##_type gmock_p6, p7##_type gmock_p7, \
4240 p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
4241 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
4242 p7(gmock_p7), p8(gmock_p8) {}\
4243 virtual return_type Perform(const args_type& args) {\
4244 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
4245 Perform(this, args);\
4247 template <typename arg0_type, typename arg1_type, typename arg2_type, \
4248 typename arg3_type, typename arg4_type, typename arg5_type, \
4249 typename arg6_type, typename arg7_type, typename arg8_type, \
4250 typename arg9_type>\
4251 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
4252 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
4253 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
4254 arg9_type arg9) const;\
4265 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
4267 template <typename F> operator ::testing::Action<F>() const {\
4268 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
4281 GTEST_DISALLOW_ASSIGN_(name##ActionP9);\
4283 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4284 typename p3##_type, typename p4##_type, typename p5##_type, \
4285 typename p6##_type, typename p7##_type, typename p8##_type>\
4286 inline name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, \
4287 p4##_type, p5##_type, p6##_type, p7##_type, \
4288 p8##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
4289 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, \
4291 return name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, \
4292 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type>(p0, p1, p2, \
4293 p3, p4, p5, p6, p7, p8);\
4295 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4296 typename p3##_type, typename p4##_type, typename p5##_type, \
4297 typename p6##_type, typename p7##_type, typename p8##_type>\
4298 template <typename F>\
4299 template <typename arg0_type, typename arg1_type, typename arg2_type, \
4300 typename arg3_type, typename arg4_type, typename arg5_type, \
4301 typename arg6_type, typename arg7_type, typename arg8_type, \
4302 typename arg9_type>\
4303 typename ::testing::internal::Function<F>::Result\
4304 name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
4305 p5##_type, p6##_type, p7##_type, \
4306 p8##_type>::gmock_Impl<F>::gmock_PerformImpl(\
4307 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
4309 #define ACTION_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)\
4310 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4311 typename p3##_type, typename p4##_type, typename p5##_type, \
4312 typename p6##_type, typename p7##_type, typename p8##_type, \
4313 typename p9##_type>\
4314 class name##ActionP10 {\
4316 name##ActionP10(p0##_type gmock_p0, p1##_type gmock_p1, \
4317 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
4318 p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
4319 p8##_type gmock_p8, p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), \
4320 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
4321 p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {}\
4322 template <typename F>\
4323 class gmock_Impl : public ::testing::ActionInterface<F> {\
4325 typedef F function_type;\
4326 typedef typename ::testing::internal::Function<F>::Result return_type;\
4327 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
4329 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
4330 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
4331 p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
4332 p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
4333 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
4334 p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {}\
4335 virtual return_type Perform(const args_type& args) {\
4336 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
4337 Perform(this, args);\
4339 template <typename arg0_type, typename arg1_type, typename arg2_type, \
4340 typename arg3_type, typename arg4_type, typename arg5_type, \
4341 typename arg6_type, typename arg7_type, typename arg8_type, \
4342 typename arg9_type>\
4343 return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
4344 arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
4345 arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
4346 arg9_type arg9) const;\
4358 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
4360 template <typename F> operator ::testing::Action<F>() const {\
4361 return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
4375 GTEST_DISALLOW_ASSIGN_(name##ActionP10);\
4377 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4378 typename p3##_type, typename p4##_type, typename p5##_type, \
4379 typename p6##_type, typename p7##_type, typename p8##_type, \
4380 typename p9##_type>\
4381 inline name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, \
4382 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
4383 p9##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
4384 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \
4386 return name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, \
4387 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, p9##_type>(p0, \
4388 p1, p2, p3, p4, p5, p6, p7, p8, p9);\
4390 template <typename p0##_type, typename p1##_type, typename p2##_type, \
4391 typename p3##_type, typename p4##_type, typename p5##_type, \
4392 typename p6##_type, typename p7##_type, typename p8##_type, \
4393 typename p9##_type>\
4394 template <typename F>\
4395 template <typename arg0_type, typename arg1_type, typename arg2_type, \
4396 typename arg3_type, typename arg4_type, typename arg5_type, \
4397 typename arg6_type, typename arg7_type, typename arg8_type, \
4398 typename arg9_type>\
4399 typename ::testing::internal::Function<F>::Result\
4400 name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
4401 p5##_type, p6##_type, p7##_type, p8##_type, \
4402 p9##_type>::gmock_Impl<F>::gmock_PerformImpl(\
4403 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
4408 // The ACTION*() macros trigger warning C4100 (unreferenced formal
4409 // parameter) in MSVC with -W4. Unfortunately they cannot be fixed in
4410 // the macro definition, as the warnings are generated when the macro
4411 // is expanded and macro expansion cannot contain #pragma. Therefore
4412 // we suppress them here.
4414 # pragma warning(push)
4415 # pragma warning(disable:4100)
4418 // Various overloads for InvokeArgument<N>().
4420 // The InvokeArgument<N>(a1, a2, ..., a_k) action invokes the N-th
4421 // (0-based) argument, which must be a k-ary callable, of the mock
4422 // function, with arguments a1, a2, ..., a_k.
4426 // 1. The arguments are passed by value by default. If you need to
4427 // pass an argument by reference, wrap it inside ByRef(). For
4430 // InvokeArgument<1>(5, string("Hello"), ByRef(foo))
4432 // passes 5 and string("Hello") by value, and passes foo by
4435 // 2. If the callable takes an argument by reference but ByRef() is
4436 // not used, it will receive the reference to a copy of the value,
4437 // instead of the original value. For example, when the 0-th
4438 // argument of the mock function takes a const string&, the action
4440 // InvokeArgument<0>(string("Hello"))
4442 // makes a copy of the temporary string("Hello") object and passes a
4443 // reference of the copy, instead of the original temporary object,
4444 // to the callable. This makes it easy for a user to define an
4445 // InvokeArgument action from temporary values and have it performed
4448 namespace internal {
4449 namespace invoke_argument {
4451 // Appears in InvokeArgumentAdl's argument list to help avoid
4452 // accidental calls to user functions of the same name.
4455 // InvokeArgumentAdl - a helper for InvokeArgument.
4456 // The basic overloads are provided here for generic functors.
4457 // Overloads for other custom-callables are provided in the
4458 // internal/custom/callback-actions.h header.
4460 template <typename R, typename F>
4461 R InvokeArgumentAdl(AdlTag, F f) {
4464 template <typename R, typename F, typename A1>
4465 R InvokeArgumentAdl(AdlTag, F f, A1 a1) {
4468 template <typename R, typename F, typename A1, typename A2>
4469 R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2) {
4472 template <typename R, typename F, typename A1, typename A2, typename A3>
4473 R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3) {
4474 return f(a1, a2, a3);
4476 template <typename R, typename F, typename A1, typename A2, typename A3,
4478 R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4) {
4479 return f(a1, a2, a3, a4);
4481 template <typename R, typename F, typename A1, typename A2, typename A3,
4482 typename A4, typename A5>
4483 R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) {
4484 return f(a1, a2, a3, a4, a5);
4486 template <typename R, typename F, typename A1, typename A2, typename A3,
4487 typename A4, typename A5, typename A6>
4488 R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) {
4489 return f(a1, a2, a3, a4, a5, a6);
4491 template <typename R, typename F, typename A1, typename A2, typename A3,
4492 typename A4, typename A5, typename A6, typename A7>
4493 R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
4495 return f(a1, a2, a3, a4, a5, a6, a7);
4497 template <typename R, typename F, typename A1, typename A2, typename A3,
4498 typename A4, typename A5, typename A6, typename A7, typename A8>
4499 R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
4501 return f(a1, a2, a3, a4, a5, a6, a7, a8);
4503 template <typename R, typename F, typename A1, typename A2, typename A3,
4504 typename A4, typename A5, typename A6, typename A7, typename A8,
4506 R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
4507 A7 a7, A8 a8, A9 a9) {
4508 return f(a1, a2, a3, a4, a5, a6, a7, a8, a9);
4510 template <typename R, typename F, typename A1, typename A2, typename A3,
4511 typename A4, typename A5, typename A6, typename A7, typename A8,
4512 typename A9, typename A10>
4513 R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
4514 A7 a7, A8 a8, A9 a9, A10 a10) {
4515 return f(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
4517 } // namespace invoke_argument
4518 } // namespace internal
4520 ACTION_TEMPLATE(InvokeArgument,
4521 HAS_1_TEMPLATE_PARAMS(int, k),
4522 AND_0_VALUE_PARAMS()) {
4523 using internal::invoke_argument::InvokeArgumentAdl;
4524 return InvokeArgumentAdl<return_type>(
4525 internal::invoke_argument::AdlTag(),
4526 ::testing::get<k>(args));
4529 ACTION_TEMPLATE(InvokeArgument,
4530 HAS_1_TEMPLATE_PARAMS(int, k),
4531 AND_1_VALUE_PARAMS(p0)) {
4532 using internal::invoke_argument::InvokeArgumentAdl;
4533 return InvokeArgumentAdl<return_type>(
4534 internal::invoke_argument::AdlTag(),
4535 ::testing::get<k>(args), p0);
4538 ACTION_TEMPLATE(InvokeArgument,
4539 HAS_1_TEMPLATE_PARAMS(int, k),
4540 AND_2_VALUE_PARAMS(p0, p1)) {
4541 using internal::invoke_argument::InvokeArgumentAdl;
4542 return InvokeArgumentAdl<return_type>(
4543 internal::invoke_argument::AdlTag(),
4544 ::testing::get<k>(args), p0, p1);
4547 ACTION_TEMPLATE(InvokeArgument,
4548 HAS_1_TEMPLATE_PARAMS(int, k),
4549 AND_3_VALUE_PARAMS(p0, p1, p2)) {
4550 using internal::invoke_argument::InvokeArgumentAdl;
4551 return InvokeArgumentAdl<return_type>(
4552 internal::invoke_argument::AdlTag(),
4553 ::testing::get<k>(args), p0, p1, p2);
4556 ACTION_TEMPLATE(InvokeArgument,
4557 HAS_1_TEMPLATE_PARAMS(int, k),
4558 AND_4_VALUE_PARAMS(p0, p1, p2, p3)) {
4559 using internal::invoke_argument::InvokeArgumentAdl;
4560 return InvokeArgumentAdl<return_type>(
4561 internal::invoke_argument::AdlTag(),
4562 ::testing::get<k>(args), p0, p1, p2, p3);
4565 ACTION_TEMPLATE(InvokeArgument,
4566 HAS_1_TEMPLATE_PARAMS(int, k),
4567 AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)) {
4568 using internal::invoke_argument::InvokeArgumentAdl;
4569 return InvokeArgumentAdl<return_type>(
4570 internal::invoke_argument::AdlTag(),
4571 ::testing::get<k>(args), p0, p1, p2, p3, p4);
4574 ACTION_TEMPLATE(InvokeArgument,
4575 HAS_1_TEMPLATE_PARAMS(int, k),
4576 AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)) {
4577 using internal::invoke_argument::InvokeArgumentAdl;
4578 return InvokeArgumentAdl<return_type>(
4579 internal::invoke_argument::AdlTag(),
4580 ::testing::get<k>(args), p0, p1, p2, p3, p4, p5);
4583 ACTION_TEMPLATE(InvokeArgument,
4584 HAS_1_TEMPLATE_PARAMS(int, k),
4585 AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)) {
4586 using internal::invoke_argument::InvokeArgumentAdl;
4587 return InvokeArgumentAdl<return_type>(
4588 internal::invoke_argument::AdlTag(),
4589 ::testing::get<k>(args), p0, p1, p2, p3, p4, p5, p6);
4592 ACTION_TEMPLATE(InvokeArgument,
4593 HAS_1_TEMPLATE_PARAMS(int, k),
4594 AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)) {
4595 using internal::invoke_argument::InvokeArgumentAdl;
4596 return InvokeArgumentAdl<return_type>(
4597 internal::invoke_argument::AdlTag(),
4598 ::testing::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7);
4601 ACTION_TEMPLATE(InvokeArgument,
4602 HAS_1_TEMPLATE_PARAMS(int, k),
4603 AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8)) {
4604 using internal::invoke_argument::InvokeArgumentAdl;
4605 return InvokeArgumentAdl<return_type>(
4606 internal::invoke_argument::AdlTag(),
4607 ::testing::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7, p8);
4610 ACTION_TEMPLATE(InvokeArgument,
4611 HAS_1_TEMPLATE_PARAMS(int, k),
4612 AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)) {
4613 using internal::invoke_argument::InvokeArgumentAdl;
4614 return InvokeArgumentAdl<return_type>(
4615 internal::invoke_argument::AdlTag(),
4616 ::testing::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7, p8, p9);
4619 // Various overloads for ReturnNew<T>().
4621 // The ReturnNew<T>(a1, a2, ..., a_k) action returns a pointer to a new
4622 // instance of type T, constructed on the heap with constructor arguments
4623 // a1, a2, ..., and a_k. The caller assumes ownership of the returned value.
4624 ACTION_TEMPLATE(ReturnNew,
4625 HAS_1_TEMPLATE_PARAMS(typename, T),
4626 AND_0_VALUE_PARAMS()) {
4630 ACTION_TEMPLATE(ReturnNew,
4631 HAS_1_TEMPLATE_PARAMS(typename, T),
4632 AND_1_VALUE_PARAMS(p0)) {
4636 ACTION_TEMPLATE(ReturnNew,
4637 HAS_1_TEMPLATE_PARAMS(typename, T),
4638 AND_2_VALUE_PARAMS(p0, p1)) {
4639 return new T(p0, p1);
4642 ACTION_TEMPLATE(ReturnNew,
4643 HAS_1_TEMPLATE_PARAMS(typename, T),
4644 AND_3_VALUE_PARAMS(p0, p1, p2)) {
4645 return new T(p0, p1, p2);
4648 ACTION_TEMPLATE(ReturnNew,
4649 HAS_1_TEMPLATE_PARAMS(typename, T),
4650 AND_4_VALUE_PARAMS(p0, p1, p2, p3)) {
4651 return new T(p0, p1, p2, p3);
4654 ACTION_TEMPLATE(ReturnNew,
4655 HAS_1_TEMPLATE_PARAMS(typename, T),
4656 AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)) {
4657 return new T(p0, p1, p2, p3, p4);
4660 ACTION_TEMPLATE(ReturnNew,
4661 HAS_1_TEMPLATE_PARAMS(typename, T),
4662 AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)) {
4663 return new T(p0, p1, p2, p3, p4, p5);
4666 ACTION_TEMPLATE(ReturnNew,
4667 HAS_1_TEMPLATE_PARAMS(typename, T),
4668 AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)) {
4669 return new T(p0, p1, p2, p3, p4, p5, p6);
4672 ACTION_TEMPLATE(ReturnNew,
4673 HAS_1_TEMPLATE_PARAMS(typename, T),
4674 AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)) {
4675 return new T(p0, p1, p2, p3, p4, p5, p6, p7);
4678 ACTION_TEMPLATE(ReturnNew,
4679 HAS_1_TEMPLATE_PARAMS(typename, T),
4680 AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8)) {
4681 return new T(p0, p1, p2, p3, p4, p5, p6, p7, p8);
4684 ACTION_TEMPLATE(ReturnNew,
4685 HAS_1_TEMPLATE_PARAMS(typename, T),
4686 AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)) {
4687 return new T(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9);
4691 # pragma warning(pop)
4694 } // namespace testing
4696 // Include any custom actions added by the local installation.
4697 // We must include this header at the end to make sure it can use the
4698 // declarations from this file.
4699 // This file was GENERATED by command:
4700 // pump.py gmock-generated-actions.h.pump
4701 // DO NOT EDIT BY HAND!!!
4703 #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
4704 #define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
4706 #endif // GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
4708 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
4709 // This file was GENERATED by command:
4710 // pump.py gmock-generated-function-mockers.h.pump
4711 // DO NOT EDIT BY HAND!!!
4713 // Copyright 2007, Google Inc.
4714 // All rights reserved.
4716 // Redistribution and use in source and binary forms, with or without
4717 // modification, are permitted provided that the following conditions are
4720 // * Redistributions of source code must retain the above copyright
4721 // notice, this list of conditions and the following disclaimer.
4722 // * Redistributions in binary form must reproduce the above
4723 // copyright notice, this list of conditions and the following disclaimer
4724 // in the documentation and/or other materials provided with the
4726 // * Neither the name of Google Inc. nor the names of its
4727 // contributors may be used to endorse or promote products derived from
4728 // this software without specific prior written permission.
4730 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4731 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
4732 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
4733 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
4734 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
4735 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
4736 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
4737 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
4738 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
4739 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
4740 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4742 // Author: wan@google.com (Zhanyong Wan)
4744 // Google Mock - a framework for writing C++ mock classes.
4746 // This file implements function mockers of various arities.
4748 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
4749 #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
4751 // Copyright 2007, Google Inc.
4752 // All rights reserved.
4754 // Redistribution and use in source and binary forms, with or without
4755 // modification, are permitted provided that the following conditions are
4758 // * Redistributions of source code must retain the above copyright
4759 // notice, this list of conditions and the following disclaimer.
4760 // * Redistributions in binary form must reproduce the above
4761 // copyright notice, this list of conditions and the following disclaimer
4762 // in the documentation and/or other materials provided with the
4764 // * Neither the name of Google Inc. nor the names of its
4765 // contributors may be used to endorse or promote products derived from
4766 // this software without specific prior written permission.
4768 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4769 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
4770 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
4771 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
4772 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
4773 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
4774 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
4775 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
4776 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
4777 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
4778 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4780 // Author: wan@google.com (Zhanyong Wan)
4782 // Google Mock - a framework for writing C++ mock classes.
4784 // This file implements the ON_CALL() and EXPECT_CALL() macros.
4786 // A user can use the ON_CALL() macro to specify the default action of
4787 // a mock method. The syntax is:
4789 // ON_CALL(mock_object, Method(argument-matchers))
4790 // .With(multi-argument-matcher)
4791 // .WillByDefault(action);
4793 // where the .With() clause is optional.
4795 // A user can use the EXPECT_CALL() macro to specify an expectation on
4796 // a mock method. The syntax is:
4798 // EXPECT_CALL(mock_object, Method(argument-matchers))
4799 // .With(multi-argument-matchers)
4800 // .Times(cardinality)
4801 // .InSequence(sequences)
4802 // .After(expectations)
4803 // .WillOnce(action)
4804 // .WillRepeatedly(action)
4805 // .RetiresOnSaturation();
4807 // where all clauses are optional, and .InSequence()/.After()/
4808 // .WillOnce() can appear any number of times.
4810 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_
4811 #define GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_
4819 #if GTEST_HAS_EXCEPTIONS
4820 # include <stdexcept> // NOLINT
4823 // Copyright 2007, Google Inc.
4824 // All rights reserved.
4826 // Redistribution and use in source and binary forms, with or without
4827 // modification, are permitted provided that the following conditions are
4830 // * Redistributions of source code must retain the above copyright
4831 // notice, this list of conditions and the following disclaimer.
4832 // * Redistributions in binary form must reproduce the above
4833 // copyright notice, this list of conditions and the following disclaimer
4834 // in the documentation and/or other materials provided with the
4836 // * Neither the name of Google Inc. nor the names of its
4837 // contributors may be used to endorse or promote products derived from
4838 // this software without specific prior written permission.
4840 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4841 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
4842 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
4843 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
4844 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
4845 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
4846 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
4847 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
4848 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
4849 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
4850 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4852 // Author: wan@google.com (Zhanyong Wan)
4854 // Google Mock - a framework for writing C++ mock classes.
4856 // This file implements some commonly used argument matchers. More
4857 // matchers can be defined by the user implementing the
4858 // MatcherInterface<T> interface if necessary.
4860 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
4861 #define GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
4864 #include <algorithm>
4867 #include <ostream> // NOLINT
4874 #if GTEST_HAS_STD_INITIALIZER_LIST_
4875 # include <initializer_list> // NOLINT -- must be after gtest.h
4880 // To implement a matcher Foo for type T, define:
4881 // 1. a class FooMatcherImpl that implements the
4882 // MatcherInterface<T> interface, and
4883 // 2. a factory function that creates a Matcher<T> object from a
4886 // The two-level delegation design makes it possible to allow a user
4887 // to write "v" instead of "Eq(v)" where a Matcher is expected, which
4888 // is impossible if we pass matchers by pointers. It also eases
4889 // ownership management as Matcher objects can now be copied like
4892 // MatchResultListener is an abstract class. Its << operator can be
4893 // used by a matcher to explain why a value matches or doesn't match.
4895 // TODO(wan@google.com): add method
4896 // bool InterestedInWhy(bool result) const;
4897 // to indicate whether the listener is interested in why the match
4898 // result is 'result'.
4899 class MatchResultListener {
4901 // Creates a listener object with the given underlying ostream. The
4902 // listener does not own the ostream, and does not dereference it
4903 // in the constructor or destructor.
4904 explicit MatchResultListener(::std::ostream* os) : stream_(os) {}
4905 virtual ~MatchResultListener() = 0; // Makes this class abstract.
4907 // Streams x to the underlying ostream; does nothing if the ostream
4909 template <typename T>
4910 MatchResultListener& operator<<(const T& x) {
4911 if (stream_ != NULL)
4916 // Returns the underlying ostream.
4917 ::std::ostream* stream() { return stream_; }
4919 // Returns true iff the listener is interested in an explanation of
4920 // the match result. A matcher's MatchAndExplain() method can use
4921 // this information to avoid generating the explanation when no one
4922 // intends to hear it.
4923 bool IsInterested() const { return stream_ != NULL; }
4926 ::std::ostream* const stream_;
4928 GTEST_DISALLOW_COPY_AND_ASSIGN_(MatchResultListener);
4931 inline MatchResultListener::~MatchResultListener() {
4934 // An instance of a subclass of this knows how to describe itself as a
4936 class MatcherDescriberInterface {
4938 virtual ~MatcherDescriberInterface() {}
4940 // Describes this matcher to an ostream. The function should print
4941 // a verb phrase that describes the property a value matching this
4942 // matcher should have. The subject of the verb phrase is the value
4943 // being matched. For example, the DescribeTo() method of the Gt(7)
4944 // matcher prints "is greater than 7".
4945 virtual void DescribeTo(::std::ostream* os) const = 0;
4947 // Describes the negation of this matcher to an ostream. For
4948 // example, if the description of this matcher is "is greater than
4949 // 7", the negated description could be "is not greater than 7".
4950 // You are not required to override this when implementing
4951 // MatcherInterface, but it is highly advised so that your matcher
4952 // can produce good error messages.
4953 virtual void DescribeNegationTo(::std::ostream* os) const {
4960 // The implementation of a matcher.
4961 template <typename T>
4962 class MatcherInterface : public MatcherDescriberInterface {
4964 // Returns true iff the matcher matches x; also explains the match
4965 // result to 'listener' if necessary (see the next paragraph), in
4966 // the form of a non-restrictive relative clause ("which ...",
4967 // "whose ...", etc) that describes x. For example, the
4968 // MatchAndExplain() method of the Pointee(...) matcher should
4969 // generate an explanation like "which points to ...".
4971 // Implementations of MatchAndExplain() should add an explanation of
4972 // the match result *if and only if* they can provide additional
4973 // information that's not already present (or not obvious) in the
4974 // print-out of x and the matcher's description. Whether the match
4975 // succeeds is not a factor in deciding whether an explanation is
4976 // needed, as sometimes the caller needs to print a failure message
4977 // when the match succeeds (e.g. when the matcher is used inside
4980 // For example, a "has at least 10 elements" matcher should explain
4981 // what the actual element count is, regardless of the match result,
4982 // as it is useful information to the reader; on the other hand, an
4983 // "is empty" matcher probably only needs to explain what the actual
4984 // size is when the match fails, as it's redundant to say that the
4985 // size is 0 when the value is already known to be empty.
4987 // You should override this method when defining a new matcher.
4989 // It's the responsibility of the caller (Google Mock) to guarantee
4990 // that 'listener' is not NULL. This helps to simplify a matcher's
4991 // implementation when it doesn't care about the performance, as it
4992 // can talk to 'listener' without checking its validity first.
4993 // However, in order to implement dummy listeners efficiently,
4994 // listener->stream() may be NULL.
4995 virtual bool MatchAndExplain(T x, MatchResultListener* listener) const = 0;
4997 // Inherits these methods from MatcherDescriberInterface:
4998 // virtual void DescribeTo(::std::ostream* os) const = 0;
4999 // virtual void DescribeNegationTo(::std::ostream* os) const;
5002 // A match result listener that stores the explanation in a string.
5003 class StringMatchResultListener : public MatchResultListener {
5005 StringMatchResultListener() : MatchResultListener(&ss_) {}
5007 // Returns the explanation accumulated so far.
5008 internal::string str() const { return ss_.str(); }
5010 // Clears the explanation accumulated so far.
5011 void Clear() { ss_.str(""); }
5014 ::std::stringstream ss_;
5016 GTEST_DISALLOW_COPY_AND_ASSIGN_(StringMatchResultListener);
5019 namespace internal {
5022 template <typename A, typename B>
5023 bool operator()(const A& a, const B& b) const { return a == b; }
5026 template <typename A, typename B>
5027 bool operator()(const A& a, const B& b) const { return a != b; }
5030 template <typename A, typename B>
5031 bool operator()(const A& a, const B& b) const { return a < b; }
5034 template <typename A, typename B>
5035 bool operator()(const A& a, const B& b) const { return a > b; }
5038 template <typename A, typename B>
5039 bool operator()(const A& a, const B& b) const { return a <= b; }
5042 template <typename A, typename B>
5043 bool operator()(const A& a, const B& b) const { return a >= b; }
5046 // A match result listener that ignores the explanation.
5047 class DummyMatchResultListener : public MatchResultListener {
5049 DummyMatchResultListener() : MatchResultListener(NULL) {}
5052 GTEST_DISALLOW_COPY_AND_ASSIGN_(DummyMatchResultListener);
5055 // A match result listener that forwards the explanation to a given
5056 // ostream. The difference between this and MatchResultListener is
5057 // that the former is concrete.
5058 class StreamMatchResultListener : public MatchResultListener {
5060 explicit StreamMatchResultListener(::std::ostream* os)
5061 : MatchResultListener(os) {}
5064 GTEST_DISALLOW_COPY_AND_ASSIGN_(StreamMatchResultListener);
5067 // An internal class for implementing Matcher<T>, which will derive
5068 // from it. We put functionalities common to all Matcher<T>
5069 // specializations here to avoid code duplication.
5070 template <typename T>
5073 // Returns true iff the matcher matches x; also explains the match
5074 // result to 'listener'.
5075 bool MatchAndExplain(T x, MatchResultListener* listener) const {
5076 return impl_->MatchAndExplain(x, listener);
5079 // Returns true iff this matcher matches x.
5080 bool Matches(T x) const {
5081 DummyMatchResultListener dummy;
5082 return MatchAndExplain(x, &dummy);
5085 // Describes this matcher to an ostream.
5086 void DescribeTo(::std::ostream* os) const { impl_->DescribeTo(os); }
5088 // Describes the negation of this matcher to an ostream.
5089 void DescribeNegationTo(::std::ostream* os) const {
5090 impl_->DescribeNegationTo(os);
5093 // Explains why x matches, or doesn't match, the matcher.
5094 void ExplainMatchResultTo(T x, ::std::ostream* os) const {
5095 StreamMatchResultListener listener(os);
5096 MatchAndExplain(x, &listener);
5099 // Returns the describer for this matcher object; retains ownership
5100 // of the describer, which is only guaranteed to be alive when
5101 // this matcher object is alive.
5102 const MatcherDescriberInterface* GetDescriber() const {
5109 // Constructs a matcher from its implementation.
5110 explicit MatcherBase(const MatcherInterface<T>* impl)
5113 virtual ~MatcherBase() {}
5116 // shared_ptr (util/gtl/shared_ptr.h) and linked_ptr have similar
5117 // interfaces. The former dynamically allocates a chunk of memory
5118 // to hold the reference count, while the latter tracks all
5119 // references using a circular linked list without allocating
5120 // memory. It has been observed that linked_ptr performs better in
5121 // typical scenarios. However, shared_ptr can out-perform
5122 // linked_ptr when there are many more uses of the copy constructor
5123 // than the default constructor.
5125 // If performance becomes a problem, we should see if using
5126 // shared_ptr helps.
5127 ::testing::internal::linked_ptr<const MatcherInterface<T> > impl_;
5130 } // namespace internal
5132 // A Matcher<T> is a copyable and IMMUTABLE (except by assignment)
5133 // object that can check whether a value of type T matches. The
5134 // implementation of Matcher<T> is just a linked_ptr to const
5135 // MatcherInterface<T>, so copying is fairly cheap. Don't inherit
5137 template <typename T>
5138 class Matcher : public internal::MatcherBase<T> {
5140 // Constructs a null matcher. Needed for storing Matcher objects in STL
5141 // containers. A default-constructed matcher is not yet initialized. You
5142 // cannot use it until a valid value has been assigned to it.
5143 explicit Matcher() {} // NOLINT
5145 // Constructs a matcher from its implementation.
5146 explicit Matcher(const MatcherInterface<T>* impl)
5147 : internal::MatcherBase<T>(impl) {}
5149 // Implicit constructor here allows people to write
5150 // EXPECT_CALL(foo, Bar(5)) instead of EXPECT_CALL(foo, Bar(Eq(5))) sometimes
5151 Matcher(T value); // NOLINT
5154 // The following two specializations allow the user to write str
5155 // instead of Eq(str) and "foo" instead of Eq("foo") when a string
5156 // matcher is expected.
5158 class GTEST_API_ Matcher<const internal::string&>
5159 : public internal::MatcherBase<const internal::string&> {
5163 explicit Matcher(const MatcherInterface<const internal::string&>* impl)
5164 : internal::MatcherBase<const internal::string&>(impl) {}
5166 // Allows the user to write str instead of Eq(str) sometimes, where
5167 // str is a string object.
5168 Matcher(const internal::string& s); // NOLINT
5170 // Allows the user to write "foo" instead of Eq("foo") sometimes.
5171 Matcher(const char* s); // NOLINT
5175 class GTEST_API_ Matcher<internal::string>
5176 : public internal::MatcherBase<internal::string> {
5180 explicit Matcher(const MatcherInterface<internal::string>* impl)
5181 : internal::MatcherBase<internal::string>(impl) {}
5183 // Allows the user to write str instead of Eq(str) sometimes, where
5184 // str is a string object.
5185 Matcher(const internal::string& s); // NOLINT
5187 // Allows the user to write "foo" instead of Eq("foo") sometimes.
5188 Matcher(const char* s); // NOLINT
5191 #if GTEST_HAS_STRING_PIECE_
5192 // The following two specializations allow the user to write str
5193 // instead of Eq(str) and "foo" instead of Eq("foo") when a StringPiece
5194 // matcher is expected.
5196 class GTEST_API_ Matcher<const StringPiece&>
5197 : public internal::MatcherBase<const StringPiece&> {
5201 explicit Matcher(const MatcherInterface<const StringPiece&>* impl)
5202 : internal::MatcherBase<const StringPiece&>(impl) {}
5204 // Allows the user to write str instead of Eq(str) sometimes, where
5205 // str is a string object.
5206 Matcher(const internal::string& s); // NOLINT
5208 // Allows the user to write "foo" instead of Eq("foo") sometimes.
5209 Matcher(const char* s); // NOLINT
5211 // Allows the user to pass StringPieces directly.
5212 Matcher(StringPiece s); // NOLINT
5216 class GTEST_API_ Matcher<StringPiece>
5217 : public internal::MatcherBase<StringPiece> {
5221 explicit Matcher(const MatcherInterface<StringPiece>* impl)
5222 : internal::MatcherBase<StringPiece>(impl) {}
5224 // Allows the user to write str instead of Eq(str) sometimes, where
5225 // str is a string object.
5226 Matcher(const internal::string& s); // NOLINT
5228 // Allows the user to write "foo" instead of Eq("foo") sometimes.
5229 Matcher(const char* s); // NOLINT
5231 // Allows the user to pass StringPieces directly.
5232 Matcher(StringPiece s); // NOLINT
5234 #endif // GTEST_HAS_STRING_PIECE_
5236 // The PolymorphicMatcher class template makes it easy to implement a
5237 // polymorphic matcher (i.e. a matcher that can match values of more
5238 // than one type, e.g. Eq(n) and NotNull()).
5240 // To define a polymorphic matcher, a user should provide an Impl
5241 // class that has a DescribeTo() method and a DescribeNegationTo()
5242 // method, and define a member function (or member function template)
5244 // bool MatchAndExplain(const Value& value,
5245 // MatchResultListener* listener) const;
5247 // See the definition of NotNull() for a complete example.
5248 template <class Impl>
5249 class PolymorphicMatcher {
5251 explicit PolymorphicMatcher(const Impl& an_impl) : impl_(an_impl) {}
5253 // Returns a mutable reference to the underlying matcher
5254 // implementation object.
5255 Impl& mutable_impl() { return impl_; }
5257 // Returns an immutable reference to the underlying matcher
5258 // implementation object.
5259 const Impl& impl() const { return impl_; }
5261 template <typename T>
5262 operator Matcher<T>() const {
5263 return Matcher<T>(new MonomorphicImpl<T>(impl_));
5267 template <typename T>
5268 class MonomorphicImpl : public MatcherInterface<T> {
5270 explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {}
5272 virtual void DescribeTo(::std::ostream* os) const {
5273 impl_.DescribeTo(os);
5276 virtual void DescribeNegationTo(::std::ostream* os) const {
5277 impl_.DescribeNegationTo(os);
5280 virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
5281 return impl_.MatchAndExplain(x, listener);
5287 GTEST_DISALLOW_ASSIGN_(MonomorphicImpl);
5292 GTEST_DISALLOW_ASSIGN_(PolymorphicMatcher);
5295 // Creates a matcher from its implementation. This is easier to use
5296 // than the Matcher<T> constructor as it doesn't require you to
5297 // explicitly write the template argument, e.g.
5299 // MakeMatcher(foo);
5301 // Matcher<const string&>(foo);
5302 template <typename T>
5303 inline Matcher<T> MakeMatcher(const MatcherInterface<T>* impl) {
5304 return Matcher<T>(impl);
5307 // Creates a polymorphic matcher from its implementation. This is
5308 // easier to use than the PolymorphicMatcher<Impl> constructor as it
5309 // doesn't require you to explicitly write the template argument, e.g.
5311 // MakePolymorphicMatcher(foo);
5313 // PolymorphicMatcher<TypeOfFoo>(foo);
5314 template <class Impl>
5315 inline PolymorphicMatcher<Impl> MakePolymorphicMatcher(const Impl& impl) {
5316 return PolymorphicMatcher<Impl>(impl);
5319 // Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION
5320 // and MUST NOT BE USED IN USER CODE!!!
5321 namespace internal {
5323 // The MatcherCastImpl class template is a helper for implementing
5324 // MatcherCast(). We need this helper in order to partially
5325 // specialize the implementation of MatcherCast() (C++ allows
5326 // class/struct templates to be partially specialized, but not
5327 // function templates.).
5329 // This general version is used when MatcherCast()'s argument is a
5330 // polymorphic matcher (i.e. something that can be converted to a
5331 // Matcher but is not one yet; for example, Eq(value)) or a value (for
5332 // example, "hello").
5333 template <typename T, typename M>
5334 class MatcherCastImpl {
5336 static Matcher<T> Cast(const M& polymorphic_matcher_or_value) {
5337 // M can be a polymorhic matcher, in which case we want to use
5338 // its conversion operator to create Matcher<T>. Or it can be a value
5339 // that should be passed to the Matcher<T>'s constructor.
5341 // We can't call Matcher<T>(polymorphic_matcher_or_value) when M is a
5342 // polymorphic matcher because it'll be ambiguous if T has an implicit
5343 // constructor from M (this usually happens when T has an implicit
5344 // constructor from any type).
5346 // It won't work to unconditionally implict_cast
5347 // polymorphic_matcher_or_value to Matcher<T> because it won't trigger
5348 // a user-defined conversion from M to T if one exists (assuming M is
5351 polymorphic_matcher_or_value,
5353 internal::ImplicitlyConvertible<M, Matcher<T> >::value>());
5357 static Matcher<T> CastImpl(const M& value, BooleanConstant<false>) {
5358 // M can't be implicitly converted to Matcher<T>, so M isn't a polymorphic
5359 // matcher. It must be a value then. Use direct initialization to create
5361 return Matcher<T>(ImplicitCast_<T>(value));
5364 static Matcher<T> CastImpl(const M& polymorphic_matcher_or_value,
5365 BooleanConstant<true>) {
5366 // M is implicitly convertible to Matcher<T>, which means that either
5367 // M is a polymorhpic matcher or Matcher<T> has an implicit constructor
5368 // from M. In both cases using the implicit conversion will produce a
5371 // Even if T has an implicit constructor from M, it won't be called because
5372 // creating Matcher<T> would require a chain of two user-defined conversions
5373 // (first to create T from M and then to create Matcher<T> from T).
5374 return polymorphic_matcher_or_value;
5378 // This more specialized version is used when MatcherCast()'s argument
5379 // is already a Matcher. This only compiles when type T can be
5380 // statically converted to type U.
5381 template <typename T, typename U>
5382 class MatcherCastImpl<T, Matcher<U> > {
5384 static Matcher<T> Cast(const Matcher<U>& source_matcher) {
5385 return Matcher<T>(new Impl(source_matcher));
5389 class Impl : public MatcherInterface<T> {
5391 explicit Impl(const Matcher<U>& source_matcher)
5392 : source_matcher_(source_matcher) {}
5394 // We delegate the matching logic to the source matcher.
5395 virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
5396 return source_matcher_.MatchAndExplain(static_cast<U>(x), listener);
5399 virtual void DescribeTo(::std::ostream* os) const {
5400 source_matcher_.DescribeTo(os);
5403 virtual void DescribeNegationTo(::std::ostream* os) const {
5404 source_matcher_.DescribeNegationTo(os);
5408 const Matcher<U> source_matcher_;
5410 GTEST_DISALLOW_ASSIGN_(Impl);
5414 // This even more specialized version is used for efficiently casting
5415 // a matcher to its own type.
5416 template <typename T>
5417 class MatcherCastImpl<T, Matcher<T> > {
5419 static Matcher<T> Cast(const Matcher<T>& matcher) { return matcher; }
5422 } // namespace internal
5424 // In order to be safe and clear, casting between different matcher
5425 // types is done explicitly via MatcherCast<T>(m), which takes a
5426 // matcher m and returns a Matcher<T>. It compiles only when T can be
5427 // statically converted to the argument type of m.
5428 template <typename T, typename M>
5429 inline Matcher<T> MatcherCast(const M& matcher) {
5430 return internal::MatcherCastImpl<T, M>::Cast(matcher);
5433 // Implements SafeMatcherCast().
5435 // We use an intermediate class to do the actual safe casting as Nokia's
5436 // Symbian compiler cannot decide between
5437 // template <T, M> ... (M) and
5438 // template <T, U> ... (const Matcher<U>&)
5439 // for function templates but can for member function templates.
5440 template <typename T>
5441 class SafeMatcherCastImpl {
5443 // This overload handles polymorphic matchers and values only since
5444 // monomorphic matchers are handled by the next one.
5445 template <typename M>
5446 static inline Matcher<T> Cast(const M& polymorphic_matcher_or_value) {
5447 return internal::MatcherCastImpl<T, M>::Cast(polymorphic_matcher_or_value);
5450 // This overload handles monomorphic matchers.
5452 // In general, if type T can be implicitly converted to type U, we can
5453 // safely convert a Matcher<U> to a Matcher<T> (i.e. Matcher is
5454 // contravariant): just keep a copy of the original Matcher<U>, convert the
5455 // argument from type T to U, and then pass it to the underlying Matcher<U>.
5456 // The only exception is when U is a reference and T is not, as the
5457 // underlying Matcher<U> may be interested in the argument's address, which
5458 // is not preserved in the conversion from T to U.
5459 template <typename U>
5460 static inline Matcher<T> Cast(const Matcher<U>& matcher) {
5461 // Enforce that T can be implicitly converted to U.
5462 GTEST_COMPILE_ASSERT_((internal::ImplicitlyConvertible<T, U>::value),
5463 T_must_be_implicitly_convertible_to_U);
5464 // Enforce that we are not converting a non-reference type T to a reference
5466 GTEST_COMPILE_ASSERT_(
5467 internal::is_reference<T>::value || !internal::is_reference<U>::value,
5468 cannot_convert_non_referentce_arg_to_reference);
5469 // In case both T and U are arithmetic types, enforce that the
5470 // conversion is not lossy.
5471 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(T) RawT;
5472 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(U) RawU;
5473 const bool kTIsOther = GMOCK_KIND_OF_(RawT) == internal::kOther;
5474 const bool kUIsOther = GMOCK_KIND_OF_(RawU) == internal::kOther;
5475 GTEST_COMPILE_ASSERT_(
5476 kTIsOther || kUIsOther ||
5477 (internal::LosslessArithmeticConvertible<RawT, RawU>::value),
5478 conversion_of_arithmetic_types_must_be_lossless);
5479 return MatcherCast<T>(matcher);
5483 template <typename T, typename M>
5484 inline Matcher<T> SafeMatcherCast(const M& polymorphic_matcher) {
5485 return SafeMatcherCastImpl<T>::Cast(polymorphic_matcher);
5488 // A<T>() returns a matcher that matches any value of type T.
5489 template <typename T>
5492 // Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION
5493 // and MUST NOT BE USED IN USER CODE!!!
5494 namespace internal {
5496 // If the explanation is not empty, prints it to the ostream.
5497 inline void PrintIfNotEmpty(const internal::string& explanation,
5498 ::std::ostream* os) {
5499 if (explanation != "" && os != NULL) {
5500 *os << ", " << explanation;
5504 // Returns true if the given type name is easy to read by a human.
5505 // This is used to decide whether printing the type of a value might
5507 inline bool IsReadableTypeName(const string& type_name) {
5508 // We consider a type name readable if it's short or doesn't contain
5509 // a template or function type.
5510 return (type_name.length() <= 20 ||
5511 type_name.find_first_of("<(") == string::npos);
5514 // Matches the value against the given matcher, prints the value and explains
5515 // the match result to the listener. Returns the match result.
5516 // 'listener' must not be NULL.
5517 // Value cannot be passed by const reference, because some matchers take a
5518 // non-const argument.
5519 template <typename Value, typename T>
5520 bool MatchPrintAndExplain(Value& value, const Matcher<T>& matcher,
5521 MatchResultListener* listener) {
5522 if (!listener->IsInterested()) {
5523 // If the listener is not interested, we do not need to construct the
5524 // inner explanation.
5525 return matcher.Matches(value);
5528 StringMatchResultListener inner_listener;
5529 const bool match = matcher.MatchAndExplain(value, &inner_listener);
5531 UniversalPrint(value, listener->stream());
5533 const string& type_name = GetTypeName<Value>();
5534 if (IsReadableTypeName(type_name))
5535 *listener->stream() << " (of type " << type_name << ")";
5537 PrintIfNotEmpty(inner_listener.str(), listener->stream());
5542 // An internal helper class for doing compile-time loop on a tuple's
5547 // TuplePrefix<N>::Matches(matcher_tuple, value_tuple) returns true
5548 // iff the first N fields of matcher_tuple matches the first N
5549 // fields of value_tuple, respectively.
5550 template <typename MatcherTuple, typename ValueTuple>
5551 static bool Matches(const MatcherTuple& matcher_tuple,
5552 const ValueTuple& value_tuple) {
5553 return TuplePrefix<N - 1>::Matches(matcher_tuple, value_tuple)
5554 && get<N - 1>(matcher_tuple).Matches(get<N - 1>(value_tuple));
5557 // TuplePrefix<N>::ExplainMatchFailuresTo(matchers, values, os)
5558 // describes failures in matching the first N fields of matchers
5559 // against the first N fields of values. If there is no failure,
5560 // nothing will be streamed to os.
5561 template <typename MatcherTuple, typename ValueTuple>
5562 static void ExplainMatchFailuresTo(const MatcherTuple& matchers,
5563 const ValueTuple& values,
5564 ::std::ostream* os) {
5565 // First, describes failures in the first N - 1 fields.
5566 TuplePrefix<N - 1>::ExplainMatchFailuresTo(matchers, values, os);
5568 // Then describes the failure (if any) in the (N - 1)-th (0-based)
5570 typename tuple_element<N - 1, MatcherTuple>::type matcher =
5571 get<N - 1>(matchers);
5572 typedef typename tuple_element<N - 1, ValueTuple>::type Value;
5573 Value value = get<N - 1>(values);
5574 StringMatchResultListener listener;
5575 if (!matcher.MatchAndExplain(value, &listener)) {
5576 // TODO(wan): include in the message the name of the parameter
5577 // as used in MOCK_METHOD*() when possible.
5578 *os << " Expected arg #" << N - 1 << ": ";
5579 get<N - 1>(matchers).DescribeTo(os);
5580 *os << "\n Actual: ";
5581 // We remove the reference in type Value to prevent the
5582 // universal printer from printing the address of value, which
5583 // isn't interesting to the user most of the time. The
5584 // matcher's MatchAndExplain() method handles the case when
5585 // the address is interesting.
5586 internal::UniversalPrint(value, os);
5587 PrintIfNotEmpty(listener.str(), os);
5595 class TuplePrefix<0> {
5597 template <typename MatcherTuple, typename ValueTuple>
5598 static bool Matches(const MatcherTuple& /* matcher_tuple */,
5599 const ValueTuple& /* value_tuple */) {
5603 template <typename MatcherTuple, typename ValueTuple>
5604 static void ExplainMatchFailuresTo(const MatcherTuple& /* matchers */,
5605 const ValueTuple& /* values */,
5606 ::std::ostream* /* os */) {}
5609 // TupleMatches(matcher_tuple, value_tuple) returns true iff all
5610 // matchers in matcher_tuple match the corresponding fields in
5611 // value_tuple. It is a compiler error if matcher_tuple and
5612 // value_tuple have different number of fields or incompatible field
5614 template <typename MatcherTuple, typename ValueTuple>
5615 bool TupleMatches(const MatcherTuple& matcher_tuple,
5616 const ValueTuple& value_tuple) {
5617 // Makes sure that matcher_tuple and value_tuple have the same
5618 // number of fields.
5619 GTEST_COMPILE_ASSERT_(tuple_size<MatcherTuple>::value ==
5620 tuple_size<ValueTuple>::value,
5621 matcher_and_value_have_different_numbers_of_fields);
5622 return TuplePrefix<tuple_size<ValueTuple>::value>::
5623 Matches(matcher_tuple, value_tuple);
5626 // Describes failures in matching matchers against values. If there
5627 // is no failure, nothing will be streamed to os.
5628 template <typename MatcherTuple, typename ValueTuple>
5629 void ExplainMatchFailureTupleTo(const MatcherTuple& matchers,
5630 const ValueTuple& values,
5631 ::std::ostream* os) {
5632 TuplePrefix<tuple_size<MatcherTuple>::value>::ExplainMatchFailuresTo(
5633 matchers, values, os);
5636 // TransformTupleValues and its helper.
5638 // TransformTupleValuesHelper hides the internal machinery that
5639 // TransformTupleValues uses to implement a tuple traversal.
5640 template <typename Tuple, typename Func, typename OutIter>
5641 class TransformTupleValuesHelper {
5643 typedef ::testing::tuple_size<Tuple> TupleSize;
5646 // For each member of tuple 't', taken in order, evaluates '*out++ = f(t)'.
5647 // Returns the final value of 'out' in case the caller needs it.
5648 static OutIter Run(Func f, const Tuple& t, OutIter out) {
5649 return IterateOverTuple<Tuple, TupleSize::value>()(f, t, out);
5653 template <typename Tup, size_t kRemainingSize>
5654 struct IterateOverTuple {
5655 OutIter operator() (Func f, const Tup& t, OutIter out) const {
5656 *out++ = f(::testing::get<TupleSize::value - kRemainingSize>(t));
5657 return IterateOverTuple<Tup, kRemainingSize - 1>()(f, t, out);
5660 template <typename Tup>
5661 struct IterateOverTuple<Tup, 0> {
5662 OutIter operator() (Func /* f */, const Tup& /* t */, OutIter out) const {
5668 // Successively invokes 'f(element)' on each element of the tuple 't',
5669 // appending each result to the 'out' iterator. Returns the final value
5671 template <typename Tuple, typename Func, typename OutIter>
5672 OutIter TransformTupleValues(Func f, const Tuple& t, OutIter out) {
5673 return TransformTupleValuesHelper<Tuple, Func, OutIter>::Run(f, t, out);
5676 // Implements A<T>().
5677 template <typename T>
5678 class AnyMatcherImpl : public MatcherInterface<T> {
5680 virtual bool MatchAndExplain(
5681 T /* x */, MatchResultListener* /* listener */) const { return true; }
5682 virtual void DescribeTo(::std::ostream* os) const { *os << "is anything"; }
5683 virtual void DescribeNegationTo(::std::ostream* os) const {
5684 // This is mostly for completeness' safe, as it's not very useful
5685 // to write Not(A<bool>()). However we cannot completely rule out
5686 // such a possibility, and it doesn't hurt to be prepared.
5687 *os << "never matches";
5691 // Implements _, a matcher that matches any value of any
5692 // type. This is a polymorphic matcher, so we need a template type
5693 // conversion operator to make it appearing as a Matcher<T> for any
5695 class AnythingMatcher {
5697 template <typename T>
5698 operator Matcher<T>() const { return A<T>(); }
5701 // Implements a matcher that compares a given value with a
5702 // pre-supplied value using one of the ==, <=, <, etc, operators. The
5703 // two values being compared don't have to have the same type.
5705 // The matcher defined here is polymorphic (for example, Eq(5) can be
5706 // used to match an int, a short, a double, etc). Therefore we use
5707 // a template type conversion operator in the implementation.
5709 // The following template definition assumes that the Rhs parameter is
5710 // a "bare" type (i.e. neither 'const T' nor 'T&').
5711 template <typename D, typename Rhs, typename Op>
5712 class ComparisonBase {
5714 explicit ComparisonBase(const Rhs& rhs) : rhs_(rhs) {}
5715 template <typename Lhs>
5716 operator Matcher<Lhs>() const {
5717 return MakeMatcher(new Impl<Lhs>(rhs_));
5721 template <typename Lhs>
5722 class Impl : public MatcherInterface<Lhs> {
5724 explicit Impl(const Rhs& rhs) : rhs_(rhs) {}
5725 virtual bool MatchAndExplain(
5726 Lhs lhs, MatchResultListener* /* listener */) const {
5727 return Op()(lhs, rhs_);
5729 virtual void DescribeTo(::std::ostream* os) const {
5730 *os << D::Desc() << " ";
5731 UniversalPrint(rhs_, os);
5733 virtual void DescribeNegationTo(::std::ostream* os) const {
5734 *os << D::NegatedDesc() << " ";
5735 UniversalPrint(rhs_, os);
5739 GTEST_DISALLOW_ASSIGN_(Impl);
5742 GTEST_DISALLOW_ASSIGN_(ComparisonBase);
5745 template <typename Rhs>
5746 class EqMatcher : public ComparisonBase<EqMatcher<Rhs>, Rhs, AnyEq> {
5748 explicit EqMatcher(const Rhs& rhs)
5749 : ComparisonBase<EqMatcher<Rhs>, Rhs, AnyEq>(rhs) { }
5750 static const char* Desc() { return "is equal to"; }
5751 static const char* NegatedDesc() { return "isn't equal to"; }
5753 template <typename Rhs>
5754 class NeMatcher : public ComparisonBase<NeMatcher<Rhs>, Rhs, AnyNe> {
5756 explicit NeMatcher(const Rhs& rhs)
5757 : ComparisonBase<NeMatcher<Rhs>, Rhs, AnyNe>(rhs) { }
5758 static const char* Desc() { return "isn't equal to"; }
5759 static const char* NegatedDesc() { return "is equal to"; }
5761 template <typename Rhs>
5762 class LtMatcher : public ComparisonBase<LtMatcher<Rhs>, Rhs, AnyLt> {
5764 explicit LtMatcher(const Rhs& rhs)
5765 : ComparisonBase<LtMatcher<Rhs>, Rhs, AnyLt>(rhs) { }
5766 static const char* Desc() { return "is <"; }
5767 static const char* NegatedDesc() { return "isn't <"; }
5769 template <typename Rhs>
5770 class GtMatcher : public ComparisonBase<GtMatcher<Rhs>, Rhs, AnyGt> {
5772 explicit GtMatcher(const Rhs& rhs)
5773 : ComparisonBase<GtMatcher<Rhs>, Rhs, AnyGt>(rhs) { }
5774 static const char* Desc() { return "is >"; }
5775 static const char* NegatedDesc() { return "isn't >"; }
5777 template <typename Rhs>
5778 class LeMatcher : public ComparisonBase<LeMatcher<Rhs>, Rhs, AnyLe> {
5780 explicit LeMatcher(const Rhs& rhs)
5781 : ComparisonBase<LeMatcher<Rhs>, Rhs, AnyLe>(rhs) { }
5782 static const char* Desc() { return "is <="; }
5783 static const char* NegatedDesc() { return "isn't <="; }
5785 template <typename Rhs>
5786 class GeMatcher : public ComparisonBase<GeMatcher<Rhs>, Rhs, AnyGe> {
5788 explicit GeMatcher(const Rhs& rhs)
5789 : ComparisonBase<GeMatcher<Rhs>, Rhs, AnyGe>(rhs) { }
5790 static const char* Desc() { return "is >="; }
5791 static const char* NegatedDesc() { return "isn't >="; }
5794 // Implements the polymorphic IsNull() matcher, which matches any raw or smart
5795 // pointer that is NULL.
5796 class IsNullMatcher {
5798 template <typename Pointer>
5799 bool MatchAndExplain(const Pointer& p,
5800 MatchResultListener* /* listener */) const {
5801 #if GTEST_LANG_CXX11
5802 return p == nullptr;
5803 #else // GTEST_LANG_CXX11
5804 return GetRawPointer(p) == NULL;
5805 #endif // GTEST_LANG_CXX11
5808 void DescribeTo(::std::ostream* os) const { *os << "is NULL"; }
5809 void DescribeNegationTo(::std::ostream* os) const {
5810 *os << "isn't NULL";
5814 // Implements the polymorphic NotNull() matcher, which matches any raw or smart
5815 // pointer that is not NULL.
5816 class NotNullMatcher {
5818 template <typename Pointer>
5819 bool MatchAndExplain(const Pointer& p,
5820 MatchResultListener* /* listener */) const {
5821 #if GTEST_LANG_CXX11
5822 return p != nullptr;
5823 #else // GTEST_LANG_CXX11
5824 return GetRawPointer(p) != NULL;
5825 #endif // GTEST_LANG_CXX11
5828 void DescribeTo(::std::ostream* os) const { *os << "isn't NULL"; }
5829 void DescribeNegationTo(::std::ostream* os) const {
5834 // Ref(variable) matches any argument that is a reference to
5835 // 'variable'. This matcher is polymorphic as it can match any
5836 // super type of the type of 'variable'.
5838 // The RefMatcher template class implements Ref(variable). It can
5839 // only be instantiated with a reference type. This prevents a user
5840 // from mistakenly using Ref(x) to match a non-reference function
5841 // argument. For example, the following will righteously cause a
5845 // Matcher<int> m1 = Ref(n); // This won't compile.
5846 // Matcher<int&> m2 = Ref(n); // This will compile.
5847 template <typename T>
5850 template <typename T>
5851 class RefMatcher<T&> {
5852 // Google Mock is a generic framework and thus needs to support
5853 // mocking any function types, including those that take non-const
5854 // reference arguments. Therefore the template parameter T (and
5855 // Super below) can be instantiated to either a const type or a
5858 // RefMatcher() takes a T& instead of const T&, as we want the
5859 // compiler to catch using Ref(const_value) as a matcher for a
5860 // non-const reference.
5861 explicit RefMatcher(T& x) : object_(x) {} // NOLINT
5863 template <typename Super>
5864 operator Matcher<Super&>() const {
5865 // By passing object_ (type T&) to Impl(), which expects a Super&,
5866 // we make sure that Super is a super type of T. In particular,
5867 // this catches using Ref(const_value) as a matcher for a
5868 // non-const reference, as you cannot implicitly convert a const
5869 // reference to a non-const reference.
5870 return MakeMatcher(new Impl<Super>(object_));
5874 template <typename Super>
5875 class Impl : public MatcherInterface<Super&> {
5877 explicit Impl(Super& x) : object_(x) {} // NOLINT
5879 // MatchAndExplain() takes a Super& (as opposed to const Super&)
5880 // in order to match the interface MatcherInterface<Super&>.
5881 virtual bool MatchAndExplain(
5882 Super& x, MatchResultListener* listener) const {
5883 *listener << "which is located @" << static_cast<const void*>(&x);
5884 return &x == &object_;
5887 virtual void DescribeTo(::std::ostream* os) const {
5888 *os << "references the variable ";
5889 UniversalPrinter<Super&>::Print(object_, os);
5892 virtual void DescribeNegationTo(::std::ostream* os) const {
5893 *os << "does not reference the variable ";
5894 UniversalPrinter<Super&>::Print(object_, os);
5898 const Super& object_;
5900 GTEST_DISALLOW_ASSIGN_(Impl);
5905 GTEST_DISALLOW_ASSIGN_(RefMatcher);
5908 // Polymorphic helper functions for narrow and wide string matchers.
5909 inline bool CaseInsensitiveCStringEquals(const char* lhs, const char* rhs) {
5910 return String::CaseInsensitiveCStringEquals(lhs, rhs);
5913 inline bool CaseInsensitiveCStringEquals(const wchar_t* lhs,
5914 const wchar_t* rhs) {
5915 return String::CaseInsensitiveWideCStringEquals(lhs, rhs);
5918 // String comparison for narrow or wide strings that can have embedded NUL
5920 template <typename StringType>
5921 bool CaseInsensitiveStringEquals(const StringType& s1,
5922 const StringType& s2) {
5923 // Are the heads equal?
5924 if (!CaseInsensitiveCStringEquals(s1.c_str(), s2.c_str())) {
5928 // Skip the equal heads.
5929 const typename StringType::value_type nul = 0;
5930 const size_t i1 = s1.find(nul), i2 = s2.find(nul);
5932 // Are we at the end of either s1 or s2?
5933 if (i1 == StringType::npos || i2 == StringType::npos) {
5937 // Are the tails equal?
5938 return CaseInsensitiveStringEquals(s1.substr(i1 + 1), s2.substr(i2 + 1));
5943 // Implements equality-based string matchers like StrEq, StrCaseNe, and etc.
5944 template <typename StringType>
5945 class StrEqualityMatcher {
5947 StrEqualityMatcher(const StringType& str, bool expect_eq,
5948 bool case_sensitive)
5949 : string_(str), expect_eq_(expect_eq), case_sensitive_(case_sensitive) {}
5951 // Accepts pointer types, particularly:
5956 template <typename CharType>
5957 bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
5961 return MatchAndExplain(StringType(s), listener);
5964 // Matches anything that can convert to StringType.
5966 // This is a template, not just a plain function with const StringType&,
5967 // because StringPiece has some interfering non-explicit constructors.
5968 template <typename MatcheeStringType>
5969 bool MatchAndExplain(const MatcheeStringType& s,
5970 MatchResultListener* /* listener */) const {
5971 const StringType& s2(s);
5972 const bool eq = case_sensitive_ ? s2 == string_ :
5973 CaseInsensitiveStringEquals(s2, string_);
5974 return expect_eq_ == eq;
5977 void DescribeTo(::std::ostream* os) const {
5978 DescribeToHelper(expect_eq_, os);
5981 void DescribeNegationTo(::std::ostream* os) const {
5982 DescribeToHelper(!expect_eq_, os);
5986 void DescribeToHelper(bool expect_eq, ::std::ostream* os) const {
5987 *os << (expect_eq ? "is " : "isn't ");
5989 if (!case_sensitive_) {
5990 *os << "(ignoring case) ";
5992 UniversalPrint(string_, os);
5995 const StringType string_;
5996 const bool expect_eq_;
5997 const bool case_sensitive_;
5999 GTEST_DISALLOW_ASSIGN_(StrEqualityMatcher);
6002 // Implements the polymorphic HasSubstr(substring) matcher, which
6003 // can be used as a Matcher<T> as long as T can be converted to a
6005 template <typename StringType>
6006 class HasSubstrMatcher {
6008 explicit HasSubstrMatcher(const StringType& substring)
6009 : substring_(substring) {}
6011 // Accepts pointer types, particularly:
6016 template <typename CharType>
6017 bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
6018 return s != NULL && MatchAndExplain(StringType(s), listener);
6021 // Matches anything that can convert to StringType.
6023 // This is a template, not just a plain function with const StringType&,
6024 // because StringPiece has some interfering non-explicit constructors.
6025 template <typename MatcheeStringType>
6026 bool MatchAndExplain(const MatcheeStringType& s,
6027 MatchResultListener* /* listener */) const {
6028 const StringType& s2(s);
6029 return s2.find(substring_) != StringType::npos;
6032 // Describes what this matcher matches.
6033 void DescribeTo(::std::ostream* os) const {
6034 *os << "has substring ";
6035 UniversalPrint(substring_, os);
6038 void DescribeNegationTo(::std::ostream* os) const {
6039 *os << "has no substring ";
6040 UniversalPrint(substring_, os);
6044 const StringType substring_;
6046 GTEST_DISALLOW_ASSIGN_(HasSubstrMatcher);
6049 // Implements the polymorphic StartsWith(substring) matcher, which
6050 // can be used as a Matcher<T> as long as T can be converted to a
6052 template <typename StringType>
6053 class StartsWithMatcher {
6055 explicit StartsWithMatcher(const StringType& prefix) : prefix_(prefix) {
6058 // Accepts pointer types, particularly:
6063 template <typename CharType>
6064 bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
6065 return s != NULL && MatchAndExplain(StringType(s), listener);
6068 // Matches anything that can convert to StringType.
6070 // This is a template, not just a plain function with const StringType&,
6071 // because StringPiece has some interfering non-explicit constructors.
6072 template <typename MatcheeStringType>
6073 bool MatchAndExplain(const MatcheeStringType& s,
6074 MatchResultListener* /* listener */) const {
6075 const StringType& s2(s);
6076 return s2.length() >= prefix_.length() &&
6077 s2.substr(0, prefix_.length()) == prefix_;
6080 void DescribeTo(::std::ostream* os) const {
6081 *os << "starts with ";
6082 UniversalPrint(prefix_, os);
6085 void DescribeNegationTo(::std::ostream* os) const {
6086 *os << "doesn't start with ";
6087 UniversalPrint(prefix_, os);
6091 const StringType prefix_;
6093 GTEST_DISALLOW_ASSIGN_(StartsWithMatcher);
6096 // Implements the polymorphic EndsWith(substring) matcher, which
6097 // can be used as a Matcher<T> as long as T can be converted to a
6099 template <typename StringType>
6100 class EndsWithMatcher {
6102 explicit EndsWithMatcher(const StringType& suffix) : suffix_(suffix) {}
6104 // Accepts pointer types, particularly:
6109 template <typename CharType>
6110 bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
6111 return s != NULL && MatchAndExplain(StringType(s), listener);
6114 // Matches anything that can convert to StringType.
6116 // This is a template, not just a plain function with const StringType&,
6117 // because StringPiece has some interfering non-explicit constructors.
6118 template <typename MatcheeStringType>
6119 bool MatchAndExplain(const MatcheeStringType& s,
6120 MatchResultListener* /* listener */) const {
6121 const StringType& s2(s);
6122 return s2.length() >= suffix_.length() &&
6123 s2.substr(s2.length() - suffix_.length()) == suffix_;
6126 void DescribeTo(::std::ostream* os) const {
6127 *os << "ends with ";
6128 UniversalPrint(suffix_, os);
6131 void DescribeNegationTo(::std::ostream* os) const {
6132 *os << "doesn't end with ";
6133 UniversalPrint(suffix_, os);
6137 const StringType suffix_;
6139 GTEST_DISALLOW_ASSIGN_(EndsWithMatcher);
6142 // Implements polymorphic matchers MatchesRegex(regex) and
6143 // ContainsRegex(regex), which can be used as a Matcher<T> as long as
6144 // T can be converted to a string.
6145 class MatchesRegexMatcher {
6147 MatchesRegexMatcher(const RE* regex, bool full_match)
6148 : regex_(regex), full_match_(full_match) {}
6150 // Accepts pointer types, particularly:
6155 template <typename CharType>
6156 bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
6157 return s != NULL && MatchAndExplain(internal::string(s), listener);
6160 // Matches anything that can convert to internal::string.
6162 // This is a template, not just a plain function with const internal::string&,
6163 // because StringPiece has some interfering non-explicit constructors.
6164 template <class MatcheeStringType>
6165 bool MatchAndExplain(const MatcheeStringType& s,
6166 MatchResultListener* /* listener */) const {
6167 const internal::string& s2(s);
6168 return full_match_ ? RE::FullMatch(s2, *regex_) :
6169 RE::PartialMatch(s2, *regex_);
6172 void DescribeTo(::std::ostream* os) const {
6173 *os << (full_match_ ? "matches" : "contains")
6174 << " regular expression ";
6175 UniversalPrinter<internal::string>::Print(regex_->pattern(), os);
6178 void DescribeNegationTo(::std::ostream* os) const {
6179 *os << "doesn't " << (full_match_ ? "match" : "contain")
6180 << " regular expression ";
6181 UniversalPrinter<internal::string>::Print(regex_->pattern(), os);
6185 const internal::linked_ptr<const RE> regex_;
6186 const bool full_match_;
6188 GTEST_DISALLOW_ASSIGN_(MatchesRegexMatcher);
6191 // Implements a matcher that compares the two fields of a 2-tuple
6192 // using one of the ==, <=, <, etc, operators. The two fields being
6193 // compared don't have to have the same type.
6195 // The matcher defined here is polymorphic (for example, Eq() can be
6196 // used to match a tuple<int, short>, a tuple<const long&, double>,
6197 // etc). Therefore we use a template type conversion operator in the
6199 template <typename D, typename Op>
6200 class PairMatchBase {
6202 template <typename T1, typename T2>
6203 operator Matcher< ::testing::tuple<T1, T2> >() const {
6204 return MakeMatcher(new Impl< ::testing::tuple<T1, T2> >);
6206 template <typename T1, typename T2>
6207 operator Matcher<const ::testing::tuple<T1, T2>&>() const {
6208 return MakeMatcher(new Impl<const ::testing::tuple<T1, T2>&>);
6212 static ::std::ostream& GetDesc(::std::ostream& os) { // NOLINT
6213 return os << D::Desc();
6216 template <typename Tuple>
6217 class Impl : public MatcherInterface<Tuple> {
6219 virtual bool MatchAndExplain(
6221 MatchResultListener* /* listener */) const {
6222 return Op()(::testing::get<0>(args), ::testing::get<1>(args));
6224 virtual void DescribeTo(::std::ostream* os) const {
6225 *os << "are " << GetDesc;
6227 virtual void DescribeNegationTo(::std::ostream* os) const {
6228 *os << "aren't " << GetDesc;
6233 class Eq2Matcher : public PairMatchBase<Eq2Matcher, AnyEq> {
6235 static const char* Desc() { return "an equal pair"; }
6237 class Ne2Matcher : public PairMatchBase<Ne2Matcher, AnyNe> {
6239 static const char* Desc() { return "an unequal pair"; }
6241 class Lt2Matcher : public PairMatchBase<Lt2Matcher, AnyLt> {
6243 static const char* Desc() { return "a pair where the first < the second"; }
6245 class Gt2Matcher : public PairMatchBase<Gt2Matcher, AnyGt> {
6247 static const char* Desc() { return "a pair where the first > the second"; }
6249 class Le2Matcher : public PairMatchBase<Le2Matcher, AnyLe> {
6251 static const char* Desc() { return "a pair where the first <= the second"; }
6253 class Ge2Matcher : public PairMatchBase<Ge2Matcher, AnyGe> {
6255 static const char* Desc() { return "a pair where the first >= the second"; }
6258 // Implements the Not(...) matcher for a particular argument type T.
6259 // We do not nest it inside the NotMatcher class template, as that
6260 // will prevent different instantiations of NotMatcher from sharing
6261 // the same NotMatcherImpl<T> class.
6262 template <typename T>
6263 class NotMatcherImpl : public MatcherInterface<T> {
6265 explicit NotMatcherImpl(const Matcher<T>& matcher)
6266 : matcher_(matcher) {}
6268 virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
6269 return !matcher_.MatchAndExplain(x, listener);
6272 virtual void DescribeTo(::std::ostream* os) const {
6273 matcher_.DescribeNegationTo(os);
6276 virtual void DescribeNegationTo(::std::ostream* os) const {
6277 matcher_.DescribeTo(os);
6281 const Matcher<T> matcher_;
6283 GTEST_DISALLOW_ASSIGN_(NotMatcherImpl);
6286 // Implements the Not(m) matcher, which matches a value that doesn't
6288 template <typename InnerMatcher>
6291 explicit NotMatcher(InnerMatcher matcher) : matcher_(matcher) {}
6293 // This template type conversion operator allows Not(m) to be used
6294 // to match any type m can match.
6295 template <typename T>
6296 operator Matcher<T>() const {
6297 return Matcher<T>(new NotMatcherImpl<T>(SafeMatcherCast<T>(matcher_)));
6301 InnerMatcher matcher_;
6303 GTEST_DISALLOW_ASSIGN_(NotMatcher);
6306 // Implements the AllOf(m1, m2) matcher for a particular argument type
6307 // T. We do not nest it inside the BothOfMatcher class template, as
6308 // that will prevent different instantiations of BothOfMatcher from
6309 // sharing the same BothOfMatcherImpl<T> class.
6310 template <typename T>
6311 class BothOfMatcherImpl : public MatcherInterface<T> {
6313 BothOfMatcherImpl(const Matcher<T>& matcher1, const Matcher<T>& matcher2)
6314 : matcher1_(matcher1), matcher2_(matcher2) {}
6316 virtual void DescribeTo(::std::ostream* os) const {
6318 matcher1_.DescribeTo(os);
6320 matcher2_.DescribeTo(os);
6324 virtual void DescribeNegationTo(::std::ostream* os) const {
6326 matcher1_.DescribeNegationTo(os);
6328 matcher2_.DescribeNegationTo(os);
6332 virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
6333 // If either matcher1_ or matcher2_ doesn't match x, we only need
6334 // to explain why one of them fails.
6335 StringMatchResultListener listener1;
6336 if (!matcher1_.MatchAndExplain(x, &listener1)) {
6337 *listener << listener1.str();
6341 StringMatchResultListener listener2;
6342 if (!matcher2_.MatchAndExplain(x, &listener2)) {
6343 *listener << listener2.str();
6347 // Otherwise we need to explain why *both* of them match.
6348 const internal::string s1 = listener1.str();
6349 const internal::string s2 = listener2.str();
6356 *listener << ", and " << s2;
6363 const Matcher<T> matcher1_;
6364 const Matcher<T> matcher2_;
6366 GTEST_DISALLOW_ASSIGN_(BothOfMatcherImpl);
6369 #if GTEST_LANG_CXX11
6370 // MatcherList provides mechanisms for storing a variable number of matchers in
6371 // a list structure (ListType) and creating a combining matcher from such a
6373 // The template is defined recursively using the following template paramters:
6374 // * kSize is the length of the MatcherList.
6375 // * Head is the type of the first matcher of the list.
6376 // * Tail denotes the types of the remaining matchers of the list.
6377 template <int kSize, typename Head, typename... Tail>
6378 struct MatcherList {
6379 typedef MatcherList<kSize - 1, Tail...> MatcherListTail;
6380 typedef ::std::pair<Head, typename MatcherListTail::ListType> ListType;
6382 // BuildList stores variadic type values in a nested pair structure.
6384 // MatcherList<3, int, string, float>::BuildList(5, "foo", 2.0) will return
6385 // the corresponding result of type pair<int, pair<string, float>>.
6386 static ListType BuildList(const Head& matcher, const Tail&... tail) {
6387 return ListType(matcher, MatcherListTail::BuildList(tail...));
6390 // CreateMatcher<T> creates a Matcher<T> from a given list of matchers (built
6391 // by BuildList()). CombiningMatcher<T> is used to combine the matchers of the
6392 // list. CombiningMatcher<T> must implement MatcherInterface<T> and have a
6393 // constructor taking two Matcher<T>s as input.
6394 template <typename T, template <typename /* T */> class CombiningMatcher>
6395 static Matcher<T> CreateMatcher(const ListType& matchers) {
6396 return Matcher<T>(new CombiningMatcher<T>(
6397 SafeMatcherCast<T>(matchers.first),
6398 MatcherListTail::template CreateMatcher<T, CombiningMatcher>(
6403 // The following defines the base case for the recursive definition of
6405 template <typename Matcher1, typename Matcher2>
6406 struct MatcherList<2, Matcher1, Matcher2> {
6407 typedef ::std::pair<Matcher1, Matcher2> ListType;
6409 static ListType BuildList(const Matcher1& matcher1,
6410 const Matcher2& matcher2) {
6411 return ::std::pair<Matcher1, Matcher2>(matcher1, matcher2);
6414 template <typename T, template <typename /* T */> class CombiningMatcher>
6415 static Matcher<T> CreateMatcher(const ListType& matchers) {
6416 return Matcher<T>(new CombiningMatcher<T>(
6417 SafeMatcherCast<T>(matchers.first),
6418 SafeMatcherCast<T>(matchers.second)));
6422 // VariadicMatcher is used for the variadic implementation of
6423 // AllOf(m_1, m_2, ...) and AnyOf(m_1, m_2, ...).
6424 // CombiningMatcher<T> is used to recursively combine the provided matchers
6425 // (of type Args...).
6426 template <template <typename T> class CombiningMatcher, typename... Args>
6427 class VariadicMatcher {
6429 VariadicMatcher(const Args&... matchers) // NOLINT
6430 : matchers_(MatcherListType::BuildList(matchers...)) {}
6432 // This template type conversion operator allows an
6433 // VariadicMatcher<Matcher1, Matcher2...> object to match any type that
6434 // all of the provided matchers (Matcher1, Matcher2, ...) can match.
6435 template <typename T>
6436 operator Matcher<T>() const {
6437 return MatcherListType::template CreateMatcher<T, CombiningMatcher>(
6442 typedef MatcherList<sizeof...(Args), Args...> MatcherListType;
6444 const typename MatcherListType::ListType matchers_;
6446 GTEST_DISALLOW_ASSIGN_(VariadicMatcher);
6449 template <typename... Args>
6450 using AllOfMatcher = VariadicMatcher<BothOfMatcherImpl, Args...>;
6452 #endif // GTEST_LANG_CXX11
6454 // Used for implementing the AllOf(m_1, ..., m_n) matcher, which
6455 // matches a value that matches all of the matchers m_1, ..., and m_n.
6456 template <typename Matcher1, typename Matcher2>
6457 class BothOfMatcher {
6459 BothOfMatcher(Matcher1 matcher1, Matcher2 matcher2)
6460 : matcher1_(matcher1), matcher2_(matcher2) {}
6462 // This template type conversion operator allows a
6463 // BothOfMatcher<Matcher1, Matcher2> object to match any type that
6464 // both Matcher1 and Matcher2 can match.
6465 template <typename T>
6466 operator Matcher<T>() const {
6467 return Matcher<T>(new BothOfMatcherImpl<T>(SafeMatcherCast<T>(matcher1_),
6468 SafeMatcherCast<T>(matcher2_)));
6475 GTEST_DISALLOW_ASSIGN_(BothOfMatcher);
6478 // Implements the AnyOf(m1, m2) matcher for a particular argument type
6479 // T. We do not nest it inside the AnyOfMatcher class template, as
6480 // that will prevent different instantiations of AnyOfMatcher from
6481 // sharing the same EitherOfMatcherImpl<T> class.
6482 template <typename T>
6483 class EitherOfMatcherImpl : public MatcherInterface<T> {
6485 EitherOfMatcherImpl(const Matcher<T>& matcher1, const Matcher<T>& matcher2)
6486 : matcher1_(matcher1), matcher2_(matcher2) {}
6488 virtual void DescribeTo(::std::ostream* os) const {
6490 matcher1_.DescribeTo(os);
6492 matcher2_.DescribeTo(os);
6496 virtual void DescribeNegationTo(::std::ostream* os) const {
6498 matcher1_.DescribeNegationTo(os);
6500 matcher2_.DescribeNegationTo(os);
6504 virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
6505 // If either matcher1_ or matcher2_ matches x, we just need to
6506 // explain why *one* of them matches.
6507 StringMatchResultListener listener1;
6508 if (matcher1_.MatchAndExplain(x, &listener1)) {
6509 *listener << listener1.str();
6513 StringMatchResultListener listener2;
6514 if (matcher2_.MatchAndExplain(x, &listener2)) {
6515 *listener << listener2.str();
6519 // Otherwise we need to explain why *both* of them fail.
6520 const internal::string s1 = listener1.str();
6521 const internal::string s2 = listener2.str();
6528 *listener << ", and " << s2;
6535 const Matcher<T> matcher1_;
6536 const Matcher<T> matcher2_;
6538 GTEST_DISALLOW_ASSIGN_(EitherOfMatcherImpl);
6541 #if GTEST_LANG_CXX11
6542 // AnyOfMatcher is used for the variadic implementation of AnyOf(m_1, m_2, ...).
6543 template <typename... Args>
6544 using AnyOfMatcher = VariadicMatcher<EitherOfMatcherImpl, Args...>;
6546 #endif // GTEST_LANG_CXX11
6548 // Used for implementing the AnyOf(m_1, ..., m_n) matcher, which
6549 // matches a value that matches at least one of the matchers m_1, ...,
6551 template <typename Matcher1, typename Matcher2>
6552 class EitherOfMatcher {
6554 EitherOfMatcher(Matcher1 matcher1, Matcher2 matcher2)
6555 : matcher1_(matcher1), matcher2_(matcher2) {}
6557 // This template type conversion operator allows a
6558 // EitherOfMatcher<Matcher1, Matcher2> object to match any type that
6559 // both Matcher1 and Matcher2 can match.
6560 template <typename T>
6561 operator Matcher<T>() const {
6562 return Matcher<T>(new EitherOfMatcherImpl<T>(
6563 SafeMatcherCast<T>(matcher1_), SafeMatcherCast<T>(matcher2_)));
6570 GTEST_DISALLOW_ASSIGN_(EitherOfMatcher);
6573 // Used for implementing Truly(pred), which turns a predicate into a
6575 template <typename Predicate>
6576 class TrulyMatcher {
6578 explicit TrulyMatcher(Predicate pred) : predicate_(pred) {}
6580 // This method template allows Truly(pred) to be used as a matcher
6581 // for type T where T is the argument type of predicate 'pred'. The
6582 // argument is passed by reference as the predicate may be
6583 // interested in the address of the argument.
6584 template <typename T>
6585 bool MatchAndExplain(T& x, // NOLINT
6586 MatchResultListener* /* listener */) const {
6587 // Without the if-statement, MSVC sometimes warns about converting
6588 // a value to bool (warning 4800).
6590 // We cannot write 'return !!predicate_(x);' as that doesn't work
6591 // when predicate_(x) returns a class convertible to bool but
6592 // having no operator!().
6598 void DescribeTo(::std::ostream* os) const {
6599 *os << "satisfies the given predicate";
6602 void DescribeNegationTo(::std::ostream* os) const {
6603 *os << "doesn't satisfy the given predicate";
6607 Predicate predicate_;
6609 GTEST_DISALLOW_ASSIGN_(TrulyMatcher);
6612 // Used for implementing Matches(matcher), which turns a matcher into
6614 template <typename M>
6615 class MatcherAsPredicate {
6617 explicit MatcherAsPredicate(M matcher) : matcher_(matcher) {}
6619 // This template operator() allows Matches(m) to be used as a
6620 // predicate on type T where m is a matcher on type T.
6622 // The argument x is passed by reference instead of by value, as
6623 // some matcher may be interested in its address (e.g. as in
6624 // Matches(Ref(n))(x)).
6625 template <typename T>
6626 bool operator()(const T& x) const {
6627 // We let matcher_ commit to a particular type here instead of
6628 // when the MatcherAsPredicate object was constructed. This
6629 // allows us to write Matches(m) where m is a polymorphic matcher
6632 // If we write Matcher<T>(matcher_).Matches(x) here, it won't
6633 // compile when matcher_ has type Matcher<const T&>; if we write
6634 // Matcher<const T&>(matcher_).Matches(x) here, it won't compile
6635 // when matcher_ has type Matcher<T>; if we just write
6636 // matcher_.Matches(x), it won't compile when matcher_ is
6637 // polymorphic, e.g. Eq(5).
6639 // MatcherCast<const T&>() is necessary for making the code work
6640 // in all of the above situations.
6641 return MatcherCast<const T&>(matcher_).Matches(x);
6647 GTEST_DISALLOW_ASSIGN_(MatcherAsPredicate);
6650 // For implementing ASSERT_THAT() and EXPECT_THAT(). The template
6651 // argument M must be a type that can be converted to a matcher.
6652 template <typename M>
6653 class PredicateFormatterFromMatcher {
6655 explicit PredicateFormatterFromMatcher(M m) : matcher_(internal::move(m)) {}
6657 // This template () operator allows a PredicateFormatterFromMatcher
6658 // object to act as a predicate-formatter suitable for using with
6659 // Google Test's EXPECT_PRED_FORMAT1() macro.
6660 template <typename T>
6661 AssertionResult operator()(const char* value_text, const T& x) const {
6662 // We convert matcher_ to a Matcher<const T&> *now* instead of
6663 // when the PredicateFormatterFromMatcher object was constructed,
6664 // as matcher_ may be polymorphic (e.g. NotNull()) and we won't
6665 // know which type to instantiate it to until we actually see the
6668 // We write SafeMatcherCast<const T&>(matcher_) instead of
6669 // Matcher<const T&>(matcher_), as the latter won't compile when
6670 // matcher_ has type Matcher<T> (e.g. An<int>()).
6671 // We don't write MatcherCast<const T&> either, as that allows
6672 // potentially unsafe downcasting of the matcher argument.
6673 const Matcher<const T&> matcher = SafeMatcherCast<const T&>(matcher_);
6674 StringMatchResultListener listener;
6675 if (MatchPrintAndExplain(x, matcher, &listener))
6676 return AssertionSuccess();
6678 ::std::stringstream ss;
6679 ss << "Value of: " << value_text << "\n"
6681 matcher.DescribeTo(&ss);
6682 ss << "\n Actual: " << listener.str();
6683 return AssertionFailure() << ss.str();
6689 GTEST_DISALLOW_ASSIGN_(PredicateFormatterFromMatcher);
6692 // A helper function for converting a matcher to a predicate-formatter
6693 // without the user needing to explicitly write the type. This is
6694 // used for implementing ASSERT_THAT() and EXPECT_THAT().
6695 // Implementation detail: 'matcher' is received by-value to force decaying.
6696 template <typename M>
6697 inline PredicateFormatterFromMatcher<M>
6698 MakePredicateFormatterFromMatcher(M matcher) {
6699 return PredicateFormatterFromMatcher<M>(internal::move(matcher));
6702 // Implements the polymorphic floating point equality matcher, which matches
6703 // two float values using ULP-based approximation or, optionally, a
6704 // user-specified epsilon. The template is meant to be instantiated with
6705 // FloatType being either float or double.
6706 template <typename FloatType>
6707 class FloatingEqMatcher {
6709 // Constructor for FloatingEqMatcher.
6710 // The matcher's input will be compared with expected. The matcher treats two
6711 // NANs as equal if nan_eq_nan is true. Otherwise, under IEEE standards,
6712 // equality comparisons between NANs will always return false. We specify a
6713 // negative max_abs_error_ term to indicate that ULP-based approximation will
6714 // be used for comparison.
6715 FloatingEqMatcher(FloatType expected, bool nan_eq_nan) :
6716 expected_(expected), nan_eq_nan_(nan_eq_nan), max_abs_error_(-1) {
6719 // Constructor that supports a user-specified max_abs_error that will be used
6720 // for comparison instead of ULP-based approximation. The max absolute
6721 // should be non-negative.
6722 FloatingEqMatcher(FloatType expected, bool nan_eq_nan,
6723 FloatType max_abs_error)
6724 : expected_(expected),
6725 nan_eq_nan_(nan_eq_nan),
6726 max_abs_error_(max_abs_error) {
6727 GTEST_CHECK_(max_abs_error >= 0)
6728 << ", where max_abs_error is" << max_abs_error;
6731 // Implements floating point equality matcher as a Matcher<T>.
6732 template <typename T>
6733 class Impl : public MatcherInterface<T> {
6735 Impl(FloatType expected, bool nan_eq_nan, FloatType max_abs_error)
6736 : expected_(expected),
6737 nan_eq_nan_(nan_eq_nan),
6738 max_abs_error_(max_abs_error) {}
6740 virtual bool MatchAndExplain(T value,
6741 MatchResultListener* listener) const {
6742 const FloatingPoint<FloatType> actual(value), expected(expected_);
6744 // Compares NaNs first, if nan_eq_nan_ is true.
6745 if (actual.is_nan() || expected.is_nan()) {
6746 if (actual.is_nan() && expected.is_nan()) {
6749 // One is nan; the other is not nan.
6752 if (HasMaxAbsError()) {
6753 // We perform an equality check so that inf will match inf, regardless
6754 // of error bounds. If the result of value - expected_ would result in
6755 // overflow or if either value is inf, the default result is infinity,
6756 // which should only match if max_abs_error_ is also infinity.
6757 if (value == expected_) {
6761 const FloatType diff = value - expected_;
6762 if (fabs(diff) <= max_abs_error_) {
6766 if (listener->IsInterested()) {
6767 *listener << "which is " << diff << " from " << expected_;
6771 return actual.AlmostEquals(expected);
6775 virtual void DescribeTo(::std::ostream* os) const {
6776 // os->precision() returns the previously set precision, which we
6777 // store to restore the ostream to its original configuration
6778 // after outputting.
6779 const ::std::streamsize old_precision = os->precision(
6780 ::std::numeric_limits<FloatType>::digits10 + 2);
6781 if (FloatingPoint<FloatType>(expected_).is_nan()) {
6785 *os << "never matches";
6788 *os << "is approximately " << expected_;
6789 if (HasMaxAbsError()) {
6790 *os << " (absolute error <= " << max_abs_error_ << ")";
6793 os->precision(old_precision);
6796 virtual void DescribeNegationTo(::std::ostream* os) const {
6797 // As before, get original precision.
6798 const ::std::streamsize old_precision = os->precision(
6799 ::std::numeric_limits<FloatType>::digits10 + 2);
6800 if (FloatingPoint<FloatType>(expected_).is_nan()) {
6804 *os << "is anything";
6807 *os << "isn't approximately " << expected_;
6808 if (HasMaxAbsError()) {
6809 *os << " (absolute error > " << max_abs_error_ << ")";
6812 // Restore original precision.
6813 os->precision(old_precision);
6817 bool HasMaxAbsError() const {
6818 return max_abs_error_ >= 0;
6821 const FloatType expected_;
6822 const bool nan_eq_nan_;
6823 // max_abs_error will be used for value comparison when >= 0.
6824 const FloatType max_abs_error_;
6826 GTEST_DISALLOW_ASSIGN_(Impl);
6829 // The following 3 type conversion operators allow FloatEq(expected) and
6830 // NanSensitiveFloatEq(expected) to be used as a Matcher<float>, a
6831 // Matcher<const float&>, or a Matcher<float&>, but nothing else.
6832 // (While Google's C++ coding style doesn't allow arguments passed
6833 // by non-const reference, we may see them in code not conforming to
6834 // the style. Therefore Google Mock needs to support them.)
6835 operator Matcher<FloatType>() const {
6837 new Impl<FloatType>(expected_, nan_eq_nan_, max_abs_error_));
6840 operator Matcher<const FloatType&>() const {
6842 new Impl<const FloatType&>(expected_, nan_eq_nan_, max_abs_error_));
6845 operator Matcher<FloatType&>() const {
6847 new Impl<FloatType&>(expected_, nan_eq_nan_, max_abs_error_));
6851 const FloatType expected_;
6852 const bool nan_eq_nan_;
6853 // max_abs_error will be used for value comparison when >= 0.
6854 const FloatType max_abs_error_;
6856 GTEST_DISALLOW_ASSIGN_(FloatingEqMatcher);
6859 // Implements the Pointee(m) matcher for matching a pointer whose
6860 // pointee matches matcher m. The pointer can be either raw or smart.
6861 template <typename InnerMatcher>
6862 class PointeeMatcher {
6864 explicit PointeeMatcher(const InnerMatcher& matcher) : matcher_(matcher) {}
6866 // This type conversion operator template allows Pointee(m) to be
6867 // used as a matcher for any pointer type whose pointee type is
6868 // compatible with the inner matcher, where type Pointer can be
6869 // either a raw pointer or a smart pointer.
6871 // The reason we do this instead of relying on
6872 // MakePolymorphicMatcher() is that the latter is not flexible
6873 // enough for implementing the DescribeTo() method of Pointee().
6874 template <typename Pointer>
6875 operator Matcher<Pointer>() const {
6876 return MakeMatcher(new Impl<Pointer>(matcher_));
6880 // The monomorphic implementation that works for a particular pointer type.
6881 template <typename Pointer>
6882 class Impl : public MatcherInterface<Pointer> {
6884 typedef typename PointeeOf<GTEST_REMOVE_CONST_( // NOLINT
6885 GTEST_REMOVE_REFERENCE_(Pointer))>::type Pointee;
6887 explicit Impl(const InnerMatcher& matcher)
6888 : matcher_(MatcherCast<const Pointee&>(matcher)) {}
6890 virtual void DescribeTo(::std::ostream* os) const {
6891 *os << "points to a value that ";
6892 matcher_.DescribeTo(os);
6895 virtual void DescribeNegationTo(::std::ostream* os) const {
6896 *os << "does not point to a value that ";
6897 matcher_.DescribeTo(os);
6900 virtual bool MatchAndExplain(Pointer pointer,
6901 MatchResultListener* listener) const {
6902 if (GetRawPointer(pointer) == NULL)
6905 *listener << "which points to ";
6906 return MatchPrintAndExplain(*pointer, matcher_, listener);
6910 const Matcher<const Pointee&> matcher_;
6912 GTEST_DISALLOW_ASSIGN_(Impl);
6915 const InnerMatcher matcher_;
6917 GTEST_DISALLOW_ASSIGN_(PointeeMatcher);
6920 // Implements the WhenDynamicCastTo<T>(m) matcher that matches a pointer or
6921 // reference that matches inner_matcher when dynamic_cast<T> is applied.
6922 // The result of dynamic_cast<To> is forwarded to the inner matcher.
6923 // If To is a pointer and the cast fails, the inner matcher will receive NULL.
6924 // If To is a reference and the cast fails, this matcher returns false
6926 template <typename To>
6927 class WhenDynamicCastToMatcherBase {
6929 explicit WhenDynamicCastToMatcherBase(const Matcher<To>& matcher)
6930 : matcher_(matcher) {}
6932 void DescribeTo(::std::ostream* os) const {
6933 GetCastTypeDescription(os);
6934 matcher_.DescribeTo(os);
6937 void DescribeNegationTo(::std::ostream* os) const {
6938 GetCastTypeDescription(os);
6939 matcher_.DescribeNegationTo(os);
6943 const Matcher<To> matcher_;
6945 static string GetToName() {
6947 return GetTypeName<To>();
6948 #else // GTEST_HAS_RTTI
6949 return "the target type";
6950 #endif // GTEST_HAS_RTTI
6954 static void GetCastTypeDescription(::std::ostream* os) {
6955 *os << "when dynamic_cast to " << GetToName() << ", ";
6958 GTEST_DISALLOW_ASSIGN_(WhenDynamicCastToMatcherBase);
6961 // Primary template.
6962 // To is a pointer. Cast and forward the result.
6963 template <typename To>
6964 class WhenDynamicCastToMatcher : public WhenDynamicCastToMatcherBase<To> {
6966 explicit WhenDynamicCastToMatcher(const Matcher<To>& matcher)
6967 : WhenDynamicCastToMatcherBase<To>(matcher) {}
6969 template <typename From>
6970 bool MatchAndExplain(From from, MatchResultListener* listener) const {
6971 // TODO(sbenza): Add more detail on failures. ie did the dyn_cast fail?
6972 To to = dynamic_cast<To>(from);
6973 return MatchPrintAndExplain(to, this->matcher_, listener);
6977 // Specialize for references.
6978 // In this case we return false if the dynamic_cast fails.
6979 template <typename To>
6980 class WhenDynamicCastToMatcher<To&> : public WhenDynamicCastToMatcherBase<To&> {
6982 explicit WhenDynamicCastToMatcher(const Matcher<To&>& matcher)
6983 : WhenDynamicCastToMatcherBase<To&>(matcher) {}
6985 template <typename From>
6986 bool MatchAndExplain(From& from, MatchResultListener* listener) const {
6987 // We don't want an std::bad_cast here, so do the cast with pointers.
6988 To* to = dynamic_cast<To*>(&from);
6990 *listener << "which cannot be dynamic_cast to " << this->GetToName();
6993 return MatchPrintAndExplain(*to, this->matcher_, listener);
6997 // Implements the Field() matcher for matching a field (i.e. member
6998 // variable) of an object.
6999 template <typename Class, typename FieldType>
7000 class FieldMatcher {
7002 FieldMatcher(FieldType Class::*field,
7003 const Matcher<const FieldType&>& matcher)
7004 : field_(field), matcher_(matcher) {}
7006 void DescribeTo(::std::ostream* os) const {
7007 *os << "is an object whose given field ";
7008 matcher_.DescribeTo(os);
7011 void DescribeNegationTo(::std::ostream* os) const {
7012 *os << "is an object whose given field ";
7013 matcher_.DescribeNegationTo(os);
7016 template <typename T>
7017 bool MatchAndExplain(const T& value, MatchResultListener* listener) const {
7018 return MatchAndExplainImpl(
7019 typename ::testing::internal::
7020 is_pointer<GTEST_REMOVE_CONST_(T)>::type(),
7025 // The first argument of MatchAndExplainImpl() is needed to help
7026 // Symbian's C++ compiler choose which overload to use. Its type is
7027 // true_type iff the Field() matcher is used to match a pointer.
7028 bool MatchAndExplainImpl(false_type /* is_not_pointer */, const Class& obj,
7029 MatchResultListener* listener) const {
7030 *listener << "whose given field is ";
7031 return MatchPrintAndExplain(obj.*field_, matcher_, listener);
7034 bool MatchAndExplainImpl(true_type /* is_pointer */, const Class* p,
7035 MatchResultListener* listener) const {
7039 *listener << "which points to an object ";
7040 // Since *p has a field, it must be a class/struct/union type and
7041 // thus cannot be a pointer. Therefore we pass false_type() as
7042 // the first argument.
7043 return MatchAndExplainImpl(false_type(), *p, listener);
7046 const FieldType Class::*field_;
7047 const Matcher<const FieldType&> matcher_;
7049 GTEST_DISALLOW_ASSIGN_(FieldMatcher);
7052 // Implements the Property() matcher for matching a property
7053 // (i.e. return value of a getter method) of an object.
7054 template <typename Class, typename PropertyType>
7055 class PropertyMatcher {
7057 // The property may have a reference type, so 'const PropertyType&'
7058 // may cause double references and fail to compile. That's why we
7059 // need GTEST_REFERENCE_TO_CONST, which works regardless of
7060 // PropertyType being a reference or not.
7061 typedef GTEST_REFERENCE_TO_CONST_(PropertyType) RefToConstProperty;
7063 PropertyMatcher(PropertyType (Class::*property)() const,
7064 const Matcher<RefToConstProperty>& matcher)
7065 : property_(property), matcher_(matcher) {}
7067 void DescribeTo(::std::ostream* os) const {
7068 *os << "is an object whose given property ";
7069 matcher_.DescribeTo(os);
7072 void DescribeNegationTo(::std::ostream* os) const {
7073 *os << "is an object whose given property ";
7074 matcher_.DescribeNegationTo(os);
7077 template <typename T>
7078 bool MatchAndExplain(const T&value, MatchResultListener* listener) const {
7079 return MatchAndExplainImpl(
7080 typename ::testing::internal::
7081 is_pointer<GTEST_REMOVE_CONST_(T)>::type(),
7086 // The first argument of MatchAndExplainImpl() is needed to help
7087 // Symbian's C++ compiler choose which overload to use. Its type is
7088 // true_type iff the Property() matcher is used to match a pointer.
7089 bool MatchAndExplainImpl(false_type /* is_not_pointer */, const Class& obj,
7090 MatchResultListener* listener) const {
7091 *listener << "whose given property is ";
7092 // Cannot pass the return value (for example, int) to MatchPrintAndExplain,
7093 // which takes a non-const reference as argument.
7094 #if defined(_PREFAST_ ) && _MSC_VER == 1800
7095 // Workaround bug in VC++ 2013's /analyze parser.
7096 // https://connect.microsoft.com/VisualStudio/feedback/details/1106363/internal-compiler-error-with-analyze-due-to-failure-to-infer-move
7097 posix::Abort(); // To make sure it is never run.
7100 RefToConstProperty result = (obj.*property_)();
7101 return MatchPrintAndExplain(result, matcher_, listener);
7105 bool MatchAndExplainImpl(true_type /* is_pointer */, const Class* p,
7106 MatchResultListener* listener) const {
7110 *listener << "which points to an object ";
7111 // Since *p has a property method, it must be a class/struct/union
7112 // type and thus cannot be a pointer. Therefore we pass
7113 // false_type() as the first argument.
7114 return MatchAndExplainImpl(false_type(), *p, listener);
7117 PropertyType (Class::*property_)() const;
7118 const Matcher<RefToConstProperty> matcher_;
7120 GTEST_DISALLOW_ASSIGN_(PropertyMatcher);
7123 // Type traits specifying various features of different functors for ResultOf.
7124 // The default template specifies features for functor objects.
7125 // Functor classes have to typedef argument_type and result_type
7126 // to be compatible with ResultOf.
7127 template <typename Functor>
7128 struct CallableTraits {
7129 typedef typename Functor::result_type ResultType;
7130 typedef Functor StorageType;
7132 static void CheckIsValid(Functor /* functor */) {}
7133 template <typename T>
7134 static ResultType Invoke(Functor f, T arg) { return f(arg); }
7137 // Specialization for function pointers.
7138 template <typename ArgType, typename ResType>
7139 struct CallableTraits<ResType(*)(ArgType)> {
7140 typedef ResType ResultType;
7141 typedef ResType(*StorageType)(ArgType);
7143 static void CheckIsValid(ResType(*f)(ArgType)) {
7144 GTEST_CHECK_(f != NULL)
7145 << "NULL function pointer is passed into ResultOf().";
7147 template <typename T>
7148 static ResType Invoke(ResType(*f)(ArgType), T arg) {
7153 // Implements the ResultOf() matcher for matching a return value of a
7154 // unary function of an object.
7155 template <typename Callable>
7156 class ResultOfMatcher {
7158 typedef typename CallableTraits<Callable>::ResultType ResultType;
7160 ResultOfMatcher(Callable callable, const Matcher<ResultType>& matcher)
7161 : callable_(callable), matcher_(matcher) {
7162 CallableTraits<Callable>::CheckIsValid(callable_);
7165 template <typename T>
7166 operator Matcher<T>() const {
7167 return Matcher<T>(new Impl<T>(callable_, matcher_));
7171 typedef typename CallableTraits<Callable>::StorageType CallableStorageType;
7173 template <typename T>
7174 class Impl : public MatcherInterface<T> {
7176 Impl(CallableStorageType callable, const Matcher<ResultType>& matcher)
7177 : callable_(callable), matcher_(matcher) {}
7179 virtual void DescribeTo(::std::ostream* os) const {
7180 *os << "is mapped by the given callable to a value that ";
7181 matcher_.DescribeTo(os);
7184 virtual void DescribeNegationTo(::std::ostream* os) const {
7185 *os << "is mapped by the given callable to a value that ";
7186 matcher_.DescribeNegationTo(os);
7189 virtual bool MatchAndExplain(T obj, MatchResultListener* listener) const {
7190 *listener << "which is mapped by the given callable to ";
7191 // Cannot pass the return value (for example, int) to
7192 // MatchPrintAndExplain, which takes a non-const reference as argument.
7194 CallableTraits<Callable>::template Invoke<T>(callable_, obj);
7195 return MatchPrintAndExplain(result, matcher_, listener);
7199 // Functors often define operator() as non-const method even though
7200 // they are actualy stateless. But we need to use them even when
7201 // 'this' is a const pointer. It's the user's responsibility not to
7202 // use stateful callables with ResultOf(), which does't guarantee
7203 // how many times the callable will be invoked.
7204 mutable CallableStorageType callable_;
7205 const Matcher<ResultType> matcher_;
7207 GTEST_DISALLOW_ASSIGN_(Impl);
7210 const CallableStorageType callable_;
7211 const Matcher<ResultType> matcher_;
7213 GTEST_DISALLOW_ASSIGN_(ResultOfMatcher);
7216 // Implements a matcher that checks the size of an STL-style container.
7217 template <typename SizeMatcher>
7218 class SizeIsMatcher {
7220 explicit SizeIsMatcher(const SizeMatcher& size_matcher)
7221 : size_matcher_(size_matcher) {
7224 template <typename Container>
7225 operator Matcher<Container>() const {
7226 return MakeMatcher(new Impl<Container>(size_matcher_));
7229 template <typename Container>
7230 class Impl : public MatcherInterface<Container> {
7232 typedef internal::StlContainerView<
7233 GTEST_REMOVE_REFERENCE_AND_CONST_(Container)> ContainerView;
7234 typedef typename ContainerView::type::size_type SizeType;
7235 explicit Impl(const SizeMatcher& size_matcher)
7236 : size_matcher_(MatcherCast<SizeType>(size_matcher)) {}
7238 virtual void DescribeTo(::std::ostream* os) const {
7240 size_matcher_.DescribeTo(os);
7242 virtual void DescribeNegationTo(::std::ostream* os) const {
7244 size_matcher_.DescribeNegationTo(os);
7247 virtual bool MatchAndExplain(Container container,
7248 MatchResultListener* listener) const {
7249 SizeType size = container.size();
7250 StringMatchResultListener size_listener;
7251 const bool result = size_matcher_.MatchAndExplain(size, &size_listener);
7253 << "whose size " << size << (result ? " matches" : " doesn't match");
7254 PrintIfNotEmpty(size_listener.str(), listener->stream());
7259 const Matcher<SizeType> size_matcher_;
7260 GTEST_DISALLOW_ASSIGN_(Impl);
7264 const SizeMatcher size_matcher_;
7265 GTEST_DISALLOW_ASSIGN_(SizeIsMatcher);
7268 // Implements a matcher that checks the begin()..end() distance of an STL-style
7270 template <typename DistanceMatcher>
7271 class BeginEndDistanceIsMatcher {
7273 explicit BeginEndDistanceIsMatcher(const DistanceMatcher& distance_matcher)
7274 : distance_matcher_(distance_matcher) {}
7276 template <typename Container>
7277 operator Matcher<Container>() const {
7278 return MakeMatcher(new Impl<Container>(distance_matcher_));
7281 template <typename Container>
7282 class Impl : public MatcherInterface<Container> {
7284 typedef internal::StlContainerView<
7285 GTEST_REMOVE_REFERENCE_AND_CONST_(Container)> ContainerView;
7286 typedef typename std::iterator_traits<
7287 typename ContainerView::type::const_iterator>::difference_type
7289 explicit Impl(const DistanceMatcher& distance_matcher)
7290 : distance_matcher_(MatcherCast<DistanceType>(distance_matcher)) {}
7292 virtual void DescribeTo(::std::ostream* os) const {
7293 *os << "distance between begin() and end() ";
7294 distance_matcher_.DescribeTo(os);
7296 virtual void DescribeNegationTo(::std::ostream* os) const {
7297 *os << "distance between begin() and end() ";
7298 distance_matcher_.DescribeNegationTo(os);
7301 virtual bool MatchAndExplain(Container container,
7302 MatchResultListener* listener) const {
7303 #if GTEST_HAS_STD_BEGIN_AND_END_
7306 DistanceType distance = std::distance(begin(container), end(container));
7308 DistanceType distance = std::distance(container.begin(), container.end());
7310 StringMatchResultListener distance_listener;
7312 distance_matcher_.MatchAndExplain(distance, &distance_listener);
7313 *listener << "whose distance between begin() and end() " << distance
7314 << (result ? " matches" : " doesn't match");
7315 PrintIfNotEmpty(distance_listener.str(), listener->stream());
7320 const Matcher<DistanceType> distance_matcher_;
7321 GTEST_DISALLOW_ASSIGN_(Impl);
7325 const DistanceMatcher distance_matcher_;
7326 GTEST_DISALLOW_ASSIGN_(BeginEndDistanceIsMatcher);
7329 // Implements an equality matcher for any STL-style container whose elements
7330 // support ==. This matcher is like Eq(), but its failure explanations provide
7331 // more detailed information that is useful when the container is used as a set.
7332 // The failure message reports elements that are in one of the operands but not
7333 // the other. The failure messages do not report duplicate or out-of-order
7334 // elements in the containers (which don't properly matter to sets, but can
7335 // occur if the containers are vectors or lists, for example).
7337 // Uses the container's const_iterator, value_type, operator ==,
7338 // begin(), and end().
7339 template <typename Container>
7340 class ContainerEqMatcher {
7342 typedef internal::StlContainerView<Container> View;
7343 typedef typename View::type StlContainer;
7344 typedef typename View::const_reference StlContainerReference;
7346 // We make a copy of expected in case the elements in it are modified
7347 // after this matcher is created.
7348 explicit ContainerEqMatcher(const Container& expected)
7349 : expected_(View::Copy(expected)) {
7350 // Makes sure the user doesn't instantiate this class template
7351 // with a const or reference type.
7352 (void)testing::StaticAssertTypeEq<Container,
7353 GTEST_REMOVE_REFERENCE_AND_CONST_(Container)>();
7356 void DescribeTo(::std::ostream* os) const {
7358 UniversalPrint(expected_, os);
7360 void DescribeNegationTo(::std::ostream* os) const {
7361 *os << "does not equal ";
7362 UniversalPrint(expected_, os);
7365 template <typename LhsContainer>
7366 bool MatchAndExplain(const LhsContainer& lhs,
7367 MatchResultListener* listener) const {
7368 // GTEST_REMOVE_CONST_() is needed to work around an MSVC 8.0 bug
7369 // that causes LhsContainer to be a const type sometimes.
7370 typedef internal::StlContainerView<GTEST_REMOVE_CONST_(LhsContainer)>
7372 typedef typename LhsView::type LhsStlContainer;
7373 StlContainerReference lhs_stl_container = LhsView::ConstReference(lhs);
7374 if (lhs_stl_container == expected_)
7377 ::std::ostream* const os = listener->stream();
7379 // Something is different. Check for extra values first.
7380 bool printed_header = false;
7381 for (typename LhsStlContainer::const_iterator it =
7382 lhs_stl_container.begin();
7383 it != lhs_stl_container.end(); ++it) {
7384 if (internal::ArrayAwareFind(expected_.begin(), expected_.end(), *it) ==
7386 if (printed_header) {
7389 *os << "which has these unexpected elements: ";
7390 printed_header = true;
7392 UniversalPrint(*it, os);
7396 // Now check for missing values.
7397 bool printed_header2 = false;
7398 for (typename StlContainer::const_iterator it = expected_.begin();
7399 it != expected_.end(); ++it) {
7400 if (internal::ArrayAwareFind(
7401 lhs_stl_container.begin(), lhs_stl_container.end(), *it) ==
7402 lhs_stl_container.end()) {
7403 if (printed_header2) {
7406 *os << (printed_header ? ",\nand" : "which")
7407 << " doesn't have these expected elements: ";
7408 printed_header2 = true;
7410 UniversalPrint(*it, os);
7419 const StlContainer expected_;
7421 GTEST_DISALLOW_ASSIGN_(ContainerEqMatcher);
7424 // A comparator functor that uses the < operator to compare two values.
7425 struct LessComparator {
7426 template <typename T, typename U>
7427 bool operator()(const T& lhs, const U& rhs) const { return lhs < rhs; }
7430 // Implements WhenSortedBy(comparator, container_matcher).
7431 template <typename Comparator, typename ContainerMatcher>
7432 class WhenSortedByMatcher {
7434 WhenSortedByMatcher(const Comparator& comparator,
7435 const ContainerMatcher& matcher)
7436 : comparator_(comparator), matcher_(matcher) {}
7438 template <typename LhsContainer>
7439 operator Matcher<LhsContainer>() const {
7440 return MakeMatcher(new Impl<LhsContainer>(comparator_, matcher_));
7443 template <typename LhsContainer>
7444 class Impl : public MatcherInterface<LhsContainer> {
7446 typedef internal::StlContainerView<
7447 GTEST_REMOVE_REFERENCE_AND_CONST_(LhsContainer)> LhsView;
7448 typedef typename LhsView::type LhsStlContainer;
7449 typedef typename LhsView::const_reference LhsStlContainerReference;
7450 // Transforms std::pair<const Key, Value> into std::pair<Key, Value>
7451 // so that we can match associative containers.
7452 typedef typename RemoveConstFromKey<
7453 typename LhsStlContainer::value_type>::type LhsValue;
7455 Impl(const Comparator& comparator, const ContainerMatcher& matcher)
7456 : comparator_(comparator), matcher_(matcher) {}
7458 virtual void DescribeTo(::std::ostream* os) const {
7459 *os << "(when sorted) ";
7460 matcher_.DescribeTo(os);
7463 virtual void DescribeNegationTo(::std::ostream* os) const {
7464 *os << "(when sorted) ";
7465 matcher_.DescribeNegationTo(os);
7468 virtual bool MatchAndExplain(LhsContainer lhs,
7469 MatchResultListener* listener) const {
7470 LhsStlContainerReference lhs_stl_container = LhsView::ConstReference(lhs);
7471 ::std::vector<LhsValue> sorted_container(lhs_stl_container.begin(),
7472 lhs_stl_container.end());
7474 sorted_container.begin(), sorted_container.end(), comparator_);
7476 if (!listener->IsInterested()) {
7477 // If the listener is not interested, we do not need to
7478 // construct the inner explanation.
7479 return matcher_.Matches(sorted_container);
7482 *listener << "which is ";
7483 UniversalPrint(sorted_container, listener->stream());
7484 *listener << " when sorted";
7486 StringMatchResultListener inner_listener;
7487 const bool match = matcher_.MatchAndExplain(sorted_container,
7489 PrintIfNotEmpty(inner_listener.str(), listener->stream());
7494 const Comparator comparator_;
7495 const Matcher<const ::std::vector<LhsValue>&> matcher_;
7497 GTEST_DISALLOW_COPY_AND_ASSIGN_(Impl);
7501 const Comparator comparator_;
7502 const ContainerMatcher matcher_;
7504 GTEST_DISALLOW_ASSIGN_(WhenSortedByMatcher);
7507 // Implements Pointwise(tuple_matcher, rhs_container). tuple_matcher
7508 // must be able to be safely cast to Matcher<tuple<const T1&, const
7509 // T2&> >, where T1 and T2 are the types of elements in the LHS
7510 // container and the RHS container respectively.
7511 template <typename TupleMatcher, typename RhsContainer>
7512 class PointwiseMatcher {
7514 typedef internal::StlContainerView<RhsContainer> RhsView;
7515 typedef typename RhsView::type RhsStlContainer;
7516 typedef typename RhsStlContainer::value_type RhsValue;
7518 // Like ContainerEq, we make a copy of rhs in case the elements in
7519 // it are modified after this matcher is created.
7520 PointwiseMatcher(const TupleMatcher& tuple_matcher, const RhsContainer& rhs)
7521 : tuple_matcher_(tuple_matcher), rhs_(RhsView::Copy(rhs)) {
7522 // Makes sure the user doesn't instantiate this class template
7523 // with a const or reference type.
7524 (void)testing::StaticAssertTypeEq<RhsContainer,
7525 GTEST_REMOVE_REFERENCE_AND_CONST_(RhsContainer)>();
7528 template <typename LhsContainer>
7529 operator Matcher<LhsContainer>() const {
7530 return MakeMatcher(new Impl<LhsContainer>(tuple_matcher_, rhs_));
7533 template <typename LhsContainer>
7534 class Impl : public MatcherInterface<LhsContainer> {
7536 typedef internal::StlContainerView<
7537 GTEST_REMOVE_REFERENCE_AND_CONST_(LhsContainer)> LhsView;
7538 typedef typename LhsView::type LhsStlContainer;
7539 typedef typename LhsView::const_reference LhsStlContainerReference;
7540 typedef typename LhsStlContainer::value_type LhsValue;
7541 // We pass the LHS value and the RHS value to the inner matcher by
7542 // reference, as they may be expensive to copy. We must use tuple
7543 // instead of pair here, as a pair cannot hold references (C++ 98,
7544 // 20.2.2 [lib.pairs]).
7545 typedef ::testing::tuple<const LhsValue&, const RhsValue&> InnerMatcherArg;
7547 Impl(const TupleMatcher& tuple_matcher, const RhsStlContainer& rhs)
7548 // mono_tuple_matcher_ holds a monomorphic version of the tuple matcher.
7549 : mono_tuple_matcher_(SafeMatcherCast<InnerMatcherArg>(tuple_matcher)),
7552 virtual void DescribeTo(::std::ostream* os) const {
7553 *os << "contains " << rhs_.size()
7554 << " values, where each value and its corresponding value in ";
7555 UniversalPrinter<RhsStlContainer>::Print(rhs_, os);
7557 mono_tuple_matcher_.DescribeTo(os);
7559 virtual void DescribeNegationTo(::std::ostream* os) const {
7560 *os << "doesn't contain exactly " << rhs_.size()
7561 << " values, or contains a value x at some index i"
7562 << " where x and the i-th value of ";
7563 UniversalPrint(rhs_, os);
7565 mono_tuple_matcher_.DescribeNegationTo(os);
7568 virtual bool MatchAndExplain(LhsContainer lhs,
7569 MatchResultListener* listener) const {
7570 LhsStlContainerReference lhs_stl_container = LhsView::ConstReference(lhs);
7571 const size_t actual_size = lhs_stl_container.size();
7572 if (actual_size != rhs_.size()) {
7573 *listener << "which contains " << actual_size << " values";
7577 typename LhsStlContainer::const_iterator left = lhs_stl_container.begin();
7578 typename RhsStlContainer::const_iterator right = rhs_.begin();
7579 for (size_t i = 0; i != actual_size; ++i, ++left, ++right) {
7580 const InnerMatcherArg value_pair(*left, *right);
7582 if (listener->IsInterested()) {
7583 StringMatchResultListener inner_listener;
7584 if (!mono_tuple_matcher_.MatchAndExplain(
7585 value_pair, &inner_listener)) {
7586 *listener << "where the value pair (";
7587 UniversalPrint(*left, listener->stream());
7589 UniversalPrint(*right, listener->stream());
7590 *listener << ") at index #" << i << " don't match";
7591 PrintIfNotEmpty(inner_listener.str(), listener->stream());
7595 if (!mono_tuple_matcher_.Matches(value_pair))
7604 const Matcher<InnerMatcherArg> mono_tuple_matcher_;
7605 const RhsStlContainer rhs_;
7607 GTEST_DISALLOW_ASSIGN_(Impl);
7611 const TupleMatcher tuple_matcher_;
7612 const RhsStlContainer rhs_;
7614 GTEST_DISALLOW_ASSIGN_(PointwiseMatcher);
7617 // Holds the logic common to ContainsMatcherImpl and EachMatcherImpl.
7618 template <typename Container>
7619 class QuantifierMatcherImpl : public MatcherInterface<Container> {
7621 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
7622 typedef StlContainerView<RawContainer> View;
7623 typedef typename View::type StlContainer;
7624 typedef typename View::const_reference StlContainerReference;
7625 typedef typename StlContainer::value_type Element;
7627 template <typename InnerMatcher>
7628 explicit QuantifierMatcherImpl(InnerMatcher inner_matcher)
7630 testing::SafeMatcherCast<const Element&>(inner_matcher)) {}
7633 // * All elements in the container match, if all_elements_should_match.
7634 // * Any element in the container matches, if !all_elements_should_match.
7635 bool MatchAndExplainImpl(bool all_elements_should_match,
7636 Container container,
7637 MatchResultListener* listener) const {
7638 StlContainerReference stl_container = View::ConstReference(container);
7640 for (typename StlContainer::const_iterator it = stl_container.begin();
7641 it != stl_container.end(); ++it, ++i) {
7642 StringMatchResultListener inner_listener;
7643 const bool matches = inner_matcher_.MatchAndExplain(*it, &inner_listener);
7645 if (matches != all_elements_should_match) {
7646 *listener << "whose element #" << i
7647 << (matches ? " matches" : " doesn't match");
7648 PrintIfNotEmpty(inner_listener.str(), listener->stream());
7649 return !all_elements_should_match;
7652 return all_elements_should_match;
7656 const Matcher<const Element&> inner_matcher_;
7658 GTEST_DISALLOW_ASSIGN_(QuantifierMatcherImpl);
7661 // Implements Contains(element_matcher) for the given argument type Container.
7662 // Symmetric to EachMatcherImpl.
7663 template <typename Container>
7664 class ContainsMatcherImpl : public QuantifierMatcherImpl<Container> {
7666 template <typename InnerMatcher>
7667 explicit ContainsMatcherImpl(InnerMatcher inner_matcher)
7668 : QuantifierMatcherImpl<Container>(inner_matcher) {}
7670 // Describes what this matcher does.
7671 virtual void DescribeTo(::std::ostream* os) const {
7672 *os << "contains at least one element that ";
7673 this->inner_matcher_.DescribeTo(os);
7676 virtual void DescribeNegationTo(::std::ostream* os) const {
7677 *os << "doesn't contain any element that ";
7678 this->inner_matcher_.DescribeTo(os);
7681 virtual bool MatchAndExplain(Container container,
7682 MatchResultListener* listener) const {
7683 return this->MatchAndExplainImpl(false, container, listener);
7687 GTEST_DISALLOW_ASSIGN_(ContainsMatcherImpl);
7690 // Implements Each(element_matcher) for the given argument type Container.
7691 // Symmetric to ContainsMatcherImpl.
7692 template <typename Container>
7693 class EachMatcherImpl : public QuantifierMatcherImpl<Container> {
7695 template <typename InnerMatcher>
7696 explicit EachMatcherImpl(InnerMatcher inner_matcher)
7697 : QuantifierMatcherImpl<Container>(inner_matcher) {}
7699 // Describes what this matcher does.
7700 virtual void DescribeTo(::std::ostream* os) const {
7701 *os << "only contains elements that ";
7702 this->inner_matcher_.DescribeTo(os);
7705 virtual void DescribeNegationTo(::std::ostream* os) const {
7706 *os << "contains some element that ";
7707 this->inner_matcher_.DescribeNegationTo(os);
7710 virtual bool MatchAndExplain(Container container,
7711 MatchResultListener* listener) const {
7712 return this->MatchAndExplainImpl(true, container, listener);
7716 GTEST_DISALLOW_ASSIGN_(EachMatcherImpl);
7719 // Implements polymorphic Contains(element_matcher).
7720 template <typename M>
7721 class ContainsMatcher {
7723 explicit ContainsMatcher(M m) : inner_matcher_(m) {}
7725 template <typename Container>
7726 operator Matcher<Container>() const {
7727 return MakeMatcher(new ContainsMatcherImpl<Container>(inner_matcher_));
7731 const M inner_matcher_;
7733 GTEST_DISALLOW_ASSIGN_(ContainsMatcher);
7736 // Implements polymorphic Each(element_matcher).
7737 template <typename M>
7740 explicit EachMatcher(M m) : inner_matcher_(m) {}
7742 template <typename Container>
7743 operator Matcher<Container>() const {
7744 return MakeMatcher(new EachMatcherImpl<Container>(inner_matcher_));
7748 const M inner_matcher_;
7750 GTEST_DISALLOW_ASSIGN_(EachMatcher);
7753 // Implements Key(inner_matcher) for the given argument pair type.
7754 // Key(inner_matcher) matches an std::pair whose 'first' field matches
7755 // inner_matcher. For example, Contains(Key(Ge(5))) can be used to match an
7756 // std::map that contains at least one element whose key is >= 5.
7757 template <typename PairType>
7758 class KeyMatcherImpl : public MatcherInterface<PairType> {
7760 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(PairType) RawPairType;
7761 typedef typename RawPairType::first_type KeyType;
7763 template <typename InnerMatcher>
7764 explicit KeyMatcherImpl(InnerMatcher inner_matcher)
7766 testing::SafeMatcherCast<const KeyType&>(inner_matcher)) {
7769 // Returns true iff 'key_value.first' (the key) matches the inner matcher.
7770 virtual bool MatchAndExplain(PairType key_value,
7771 MatchResultListener* listener) const {
7772 StringMatchResultListener inner_listener;
7773 const bool match = inner_matcher_.MatchAndExplain(key_value.first,
7775 const internal::string explanation = inner_listener.str();
7776 if (explanation != "") {
7777 *listener << "whose first field is a value " << explanation;
7782 // Describes what this matcher does.
7783 virtual void DescribeTo(::std::ostream* os) const {
7784 *os << "has a key that ";
7785 inner_matcher_.DescribeTo(os);
7788 // Describes what the negation of this matcher does.
7789 virtual void DescribeNegationTo(::std::ostream* os) const {
7790 *os << "doesn't have a key that ";
7791 inner_matcher_.DescribeTo(os);
7795 const Matcher<const KeyType&> inner_matcher_;
7797 GTEST_DISALLOW_ASSIGN_(KeyMatcherImpl);
7800 // Implements polymorphic Key(matcher_for_key).
7801 template <typename M>
7804 explicit KeyMatcher(M m) : matcher_for_key_(m) {}
7806 template <typename PairType>
7807 operator Matcher<PairType>() const {
7808 return MakeMatcher(new KeyMatcherImpl<PairType>(matcher_for_key_));
7812 const M matcher_for_key_;
7814 GTEST_DISALLOW_ASSIGN_(KeyMatcher);
7817 // Implements Pair(first_matcher, second_matcher) for the given argument pair
7818 // type with its two matchers. See Pair() function below.
7819 template <typename PairType>
7820 class PairMatcherImpl : public MatcherInterface<PairType> {
7822 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(PairType) RawPairType;
7823 typedef typename RawPairType::first_type FirstType;
7824 typedef typename RawPairType::second_type SecondType;
7826 template <typename FirstMatcher, typename SecondMatcher>
7827 PairMatcherImpl(FirstMatcher first_matcher, SecondMatcher second_matcher)
7829 testing::SafeMatcherCast<const FirstType&>(first_matcher)),
7831 testing::SafeMatcherCast<const SecondType&>(second_matcher)) {
7834 // Describes what this matcher does.
7835 virtual void DescribeTo(::std::ostream* os) const {
7836 *os << "has a first field that ";
7837 first_matcher_.DescribeTo(os);
7838 *os << ", and has a second field that ";
7839 second_matcher_.DescribeTo(os);
7842 // Describes what the negation of this matcher does.
7843 virtual void DescribeNegationTo(::std::ostream* os) const {
7844 *os << "has a first field that ";
7845 first_matcher_.DescribeNegationTo(os);
7846 *os << ", or has a second field that ";
7847 second_matcher_.DescribeNegationTo(os);
7850 // Returns true iff 'a_pair.first' matches first_matcher and 'a_pair.second'
7851 // matches second_matcher.
7852 virtual bool MatchAndExplain(PairType a_pair,
7853 MatchResultListener* listener) const {
7854 if (!listener->IsInterested()) {
7855 // If the listener is not interested, we don't need to construct the
7857 return first_matcher_.Matches(a_pair.first) &&
7858 second_matcher_.Matches(a_pair.second);
7860 StringMatchResultListener first_inner_listener;
7861 if (!first_matcher_.MatchAndExplain(a_pair.first,
7862 &first_inner_listener)) {
7863 *listener << "whose first field does not match";
7864 PrintIfNotEmpty(first_inner_listener.str(), listener->stream());
7867 StringMatchResultListener second_inner_listener;
7868 if (!second_matcher_.MatchAndExplain(a_pair.second,
7869 &second_inner_listener)) {
7870 *listener << "whose second field does not match";
7871 PrintIfNotEmpty(second_inner_listener.str(), listener->stream());
7874 ExplainSuccess(first_inner_listener.str(), second_inner_listener.str(),
7880 void ExplainSuccess(const internal::string& first_explanation,
7881 const internal::string& second_explanation,
7882 MatchResultListener* listener) const {
7883 *listener << "whose both fields match";
7884 if (first_explanation != "") {
7885 *listener << ", where the first field is a value " << first_explanation;
7887 if (second_explanation != "") {
7889 if (first_explanation != "") {
7890 *listener << "and ";
7892 *listener << "where ";
7894 *listener << "the second field is a value " << second_explanation;
7898 const Matcher<const FirstType&> first_matcher_;
7899 const Matcher<const SecondType&> second_matcher_;
7901 GTEST_DISALLOW_ASSIGN_(PairMatcherImpl);
7904 // Implements polymorphic Pair(first_matcher, second_matcher).
7905 template <typename FirstMatcher, typename SecondMatcher>
7908 PairMatcher(FirstMatcher first_matcher, SecondMatcher second_matcher)
7909 : first_matcher_(first_matcher), second_matcher_(second_matcher) {}
7911 template <typename PairType>
7912 operator Matcher<PairType> () const {
7914 new PairMatcherImpl<PairType>(
7915 first_matcher_, second_matcher_));
7919 const FirstMatcher first_matcher_;
7920 const SecondMatcher second_matcher_;
7922 GTEST_DISALLOW_ASSIGN_(PairMatcher);
7925 // Implements ElementsAre() and ElementsAreArray().
7926 template <typename Container>
7927 class ElementsAreMatcherImpl : public MatcherInterface<Container> {
7929 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
7930 typedef internal::StlContainerView<RawContainer> View;
7931 typedef typename View::type StlContainer;
7932 typedef typename View::const_reference StlContainerReference;
7933 typedef typename StlContainer::value_type Element;
7935 // Constructs the matcher from a sequence of element values or
7936 // element matchers.
7937 template <typename InputIter>
7938 ElementsAreMatcherImpl(InputIter first, InputIter last) {
7939 while (first != last) {
7940 matchers_.push_back(MatcherCast<const Element&>(*first++));
7944 // Describes what this matcher does.
7945 virtual void DescribeTo(::std::ostream* os) const {
7948 } else if (count() == 1) {
7949 *os << "has 1 element that ";
7950 matchers_[0].DescribeTo(os);
7952 *os << "has " << Elements(count()) << " where\n";
7953 for (size_t i = 0; i != count(); ++i) {
7954 *os << "element #" << i << " ";
7955 matchers_[i].DescribeTo(os);
7956 if (i + 1 < count()) {
7963 // Describes what the negation of this matcher does.
7964 virtual void DescribeNegationTo(::std::ostream* os) const {
7966 *os << "isn't empty";
7970 *os << "doesn't have " << Elements(count()) << ", or\n";
7971 for (size_t i = 0; i != count(); ++i) {
7972 *os << "element #" << i << " ";
7973 matchers_[i].DescribeNegationTo(os);
7974 if (i + 1 < count()) {
7980 virtual bool MatchAndExplain(Container container,
7981 MatchResultListener* listener) const {
7982 // To work with stream-like "containers", we must only walk
7983 // through the elements in one pass.
7985 const bool listener_interested = listener->IsInterested();
7987 // explanations[i] is the explanation of the element at index i.
7988 ::std::vector<internal::string> explanations(count());
7989 StlContainerReference stl_container = View::ConstReference(container);
7990 typename StlContainer::const_iterator it = stl_container.begin();
7991 size_t exam_pos = 0;
7992 bool mismatch_found = false; // Have we found a mismatched element yet?
7994 // Go through the elements and matchers in pairs, until we reach
7995 // the end of either the elements or the matchers, or until we find a
7997 for (; it != stl_container.end() && exam_pos != count(); ++it, ++exam_pos) {
7998 bool match; // Does the current element match the current matcher?
7999 if (listener_interested) {
8000 StringMatchResultListener s;
8001 match = matchers_[exam_pos].MatchAndExplain(*it, &s);
8002 explanations[exam_pos] = s.str();
8004 match = matchers_[exam_pos].Matches(*it);
8008 mismatch_found = true;
8012 // If mismatch_found is true, 'exam_pos' is the index of the mismatch.
8014 // Find how many elements the actual container has. We avoid
8015 // calling size() s.t. this code works for stream-like "containers"
8016 // that don't define size().
8017 size_t actual_count = exam_pos;
8018 for (; it != stl_container.end(); ++it) {
8022 if (actual_count != count()) {
8023 // The element count doesn't match. If the container is empty,
8024 // there's no need to explain anything as Google Mock already
8025 // prints the empty container. Otherwise we just need to show
8026 // how many elements there actually are.
8027 if (listener_interested && (actual_count != 0)) {
8028 *listener << "which has " << Elements(actual_count);
8033 if (mismatch_found) {
8034 // The element count matches, but the exam_pos-th element doesn't match.
8035 if (listener_interested) {
8036 *listener << "whose element #" << exam_pos << " doesn't match";
8037 PrintIfNotEmpty(explanations[exam_pos], listener->stream());
8042 // Every element matches its expectation. We need to explain why
8043 // (the obvious ones can be skipped).
8044 if (listener_interested) {
8045 bool reason_printed = false;
8046 for (size_t i = 0; i != count(); ++i) {
8047 const internal::string& s = explanations[i];
8049 if (reason_printed) {
8050 *listener << ",\nand ";
8052 *listener << "whose element #" << i << " matches, " << s;
8053 reason_printed = true;
8061 static Message Elements(size_t count) {
8062 return Message() << count << (count == 1 ? " element" : " elements");
8065 size_t count() const { return matchers_.size(); }
8067 ::std::vector<Matcher<const Element&> > matchers_;
8069 GTEST_DISALLOW_ASSIGN_(ElementsAreMatcherImpl);
8072 // Connectivity matrix of (elements X matchers), in element-major order.
8073 // Initially, there are no edges.
8074 // Use NextGraph() to iterate over all possible edge configurations.
8075 // Use Randomize() to generate a random edge configuration.
8076 class GTEST_API_ MatchMatrix {
8078 MatchMatrix(size_t num_elements, size_t num_matchers)
8079 : num_elements_(num_elements),
8080 num_matchers_(num_matchers),
8081 matched_(num_elements_* num_matchers_, 0) {
8084 size_t LhsSize() const { return num_elements_; }
8085 size_t RhsSize() const { return num_matchers_; }
8086 bool HasEdge(size_t ilhs, size_t irhs) const {
8087 return matched_[SpaceIndex(ilhs, irhs)] == 1;
8089 void SetEdge(size_t ilhs, size_t irhs, bool b) {
8090 matched_[SpaceIndex(ilhs, irhs)] = b ? 1 : 0;
8093 // Treating the connectivity matrix as a (LhsSize()*RhsSize())-bit number,
8094 // adds 1 to that number; returns false if incrementing the graph left it
8100 string DebugString() const;
8103 size_t SpaceIndex(size_t ilhs, size_t irhs) const {
8104 return ilhs * num_matchers_ + irhs;
8107 size_t num_elements_;
8108 size_t num_matchers_;
8110 // Each element is a char interpreted as bool. They are stored as a
8111 // flattened array in lhs-major order, use 'SpaceIndex()' to translate
8112 // a (ilhs, irhs) matrix coordinate into an offset.
8113 ::std::vector<char> matched_;
8116 typedef ::std::pair<size_t, size_t> ElementMatcherPair;
8117 typedef ::std::vector<ElementMatcherPair> ElementMatcherPairs;
8119 // Returns a maximum bipartite matching for the specified graph 'g'.
8120 // The matching is represented as a vector of {element, matcher} pairs.
8121 GTEST_API_ ElementMatcherPairs
8122 FindMaxBipartiteMatching(const MatchMatrix& g);
8124 GTEST_API_ bool FindPairing(const MatchMatrix& matrix,
8125 MatchResultListener* listener);
8127 // Untyped base class for implementing UnorderedElementsAre. By
8128 // putting logic that's not specific to the element type here, we
8129 // reduce binary bloat and increase compilation speed.
8130 class GTEST_API_ UnorderedElementsAreMatcherImplBase {
8132 // A vector of matcher describers, one for each element matcher.
8133 // Does not own the describers (and thus can be used only when the
8134 // element matchers are alive).
8135 typedef ::std::vector<const MatcherDescriberInterface*> MatcherDescriberVec;
8137 // Describes this UnorderedElementsAre matcher.
8138 void DescribeToImpl(::std::ostream* os) const;
8140 // Describes the negation of this UnorderedElementsAre matcher.
8141 void DescribeNegationToImpl(::std::ostream* os) const;
8143 bool VerifyAllElementsAndMatchersAreMatched(
8144 const ::std::vector<string>& element_printouts,
8145 const MatchMatrix& matrix,
8146 MatchResultListener* listener) const;
8148 MatcherDescriberVec& matcher_describers() {
8149 return matcher_describers_;
8152 static Message Elements(size_t n) {
8153 return Message() << n << " element" << (n == 1 ? "" : "s");
8157 MatcherDescriberVec matcher_describers_;
8159 GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreMatcherImplBase);
8162 // Implements unordered ElementsAre and unordered ElementsAreArray.
8163 template <typename Container>
8164 class UnorderedElementsAreMatcherImpl
8165 : public MatcherInterface<Container>,
8166 public UnorderedElementsAreMatcherImplBase {
8168 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
8169 typedef internal::StlContainerView<RawContainer> View;
8170 typedef typename View::type StlContainer;
8171 typedef typename View::const_reference StlContainerReference;
8172 typedef typename StlContainer::const_iterator StlContainerConstIterator;
8173 typedef typename StlContainer::value_type Element;
8175 // Constructs the matcher from a sequence of element values or
8176 // element matchers.
8177 template <typename InputIter>
8178 UnorderedElementsAreMatcherImpl(InputIter first, InputIter last) {
8179 for (; first != last; ++first) {
8180 matchers_.push_back(MatcherCast<const Element&>(*first));
8181 matcher_describers().push_back(matchers_.back().GetDescriber());
8185 // Describes what this matcher does.
8186 virtual void DescribeTo(::std::ostream* os) const {
8187 return UnorderedElementsAreMatcherImplBase::DescribeToImpl(os);
8190 // Describes what the negation of this matcher does.
8191 virtual void DescribeNegationTo(::std::ostream* os) const {
8192 return UnorderedElementsAreMatcherImplBase::DescribeNegationToImpl(os);
8195 virtual bool MatchAndExplain(Container container,
8196 MatchResultListener* listener) const {
8197 StlContainerReference stl_container = View::ConstReference(container);
8198 ::std::vector<string> element_printouts;
8199 MatchMatrix matrix = AnalyzeElements(stl_container.begin(),
8200 stl_container.end(),
8204 const size_t actual_count = matrix.LhsSize();
8205 if (actual_count == 0 && matchers_.empty()) {
8208 if (actual_count != matchers_.size()) {
8209 // The element count doesn't match. If the container is empty,
8210 // there's no need to explain anything as Google Mock already
8211 // prints the empty container. Otherwise we just need to show
8212 // how many elements there actually are.
8213 if (actual_count != 0 && listener->IsInterested()) {
8214 *listener << "which has " << Elements(actual_count);
8219 return VerifyAllElementsAndMatchersAreMatched(element_printouts,
8220 matrix, listener) &&
8221 FindPairing(matrix, listener);
8225 typedef ::std::vector<Matcher<const Element&> > MatcherVec;
8227 template <typename ElementIter>
8228 MatchMatrix AnalyzeElements(ElementIter elem_first, ElementIter elem_last,
8229 ::std::vector<string>* element_printouts,
8230 MatchResultListener* listener) const {
8231 element_printouts->clear();
8232 ::std::vector<char> did_match;
8233 size_t num_elements = 0;
8234 for (; elem_first != elem_last; ++num_elements, ++elem_first) {
8235 if (listener->IsInterested()) {
8236 element_printouts->push_back(PrintToString(*elem_first));
8238 for (size_t irhs = 0; irhs != matchers_.size(); ++irhs) {
8239 did_match.push_back(Matches(matchers_[irhs])(*elem_first));
8243 MatchMatrix matrix(num_elements, matchers_.size());
8244 ::std::vector<char>::const_iterator did_match_iter = did_match.begin();
8245 for (size_t ilhs = 0; ilhs != num_elements; ++ilhs) {
8246 for (size_t irhs = 0; irhs != matchers_.size(); ++irhs) {
8247 matrix.SetEdge(ilhs, irhs, *did_match_iter++ != 0);
8253 MatcherVec matchers_;
8255 GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreMatcherImpl);
8258 // Functor for use in TransformTuple.
8259 // Performs MatcherCast<Target> on an input argument of any type.
8260 template <typename Target>
8261 struct CastAndAppendTransform {
8262 template <typename Arg>
8263 Matcher<Target> operator()(const Arg& a) const {
8264 return MatcherCast<Target>(a);
8268 // Implements UnorderedElementsAre.
8269 template <typename MatcherTuple>
8270 class UnorderedElementsAreMatcher {
8272 explicit UnorderedElementsAreMatcher(const MatcherTuple& args)
8273 : matchers_(args) {}
8275 template <typename Container>
8276 operator Matcher<Container>() const {
8277 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
8278 typedef typename internal::StlContainerView<RawContainer>::type View;
8279 typedef typename View::value_type Element;
8280 typedef ::std::vector<Matcher<const Element&> > MatcherVec;
8281 MatcherVec matchers;
8282 matchers.reserve(::testing::tuple_size<MatcherTuple>::value);
8283 TransformTupleValues(CastAndAppendTransform<const Element&>(), matchers_,
8284 ::std::back_inserter(matchers));
8285 return MakeMatcher(new UnorderedElementsAreMatcherImpl<Container>(
8286 matchers.begin(), matchers.end()));
8290 const MatcherTuple matchers_;
8291 GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreMatcher);
8294 // Implements ElementsAre.
8295 template <typename MatcherTuple>
8296 class ElementsAreMatcher {
8298 explicit ElementsAreMatcher(const MatcherTuple& args) : matchers_(args) {}
8300 template <typename Container>
8301 operator Matcher<Container>() const {
8302 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
8303 typedef typename internal::StlContainerView<RawContainer>::type View;
8304 typedef typename View::value_type Element;
8305 typedef ::std::vector<Matcher<const Element&> > MatcherVec;
8306 MatcherVec matchers;
8307 matchers.reserve(::testing::tuple_size<MatcherTuple>::value);
8308 TransformTupleValues(CastAndAppendTransform<const Element&>(), matchers_,
8309 ::std::back_inserter(matchers));
8310 return MakeMatcher(new ElementsAreMatcherImpl<Container>(
8311 matchers.begin(), matchers.end()));
8315 const MatcherTuple matchers_;
8316 GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher);
8319 // Implements UnorderedElementsAreArray().
8320 template <typename T>
8321 class UnorderedElementsAreArrayMatcher {
8323 UnorderedElementsAreArrayMatcher() {}
8325 template <typename Iter>
8326 UnorderedElementsAreArrayMatcher(Iter first, Iter last)
8327 : matchers_(first, last) {}
8329 template <typename Container>
8330 operator Matcher<Container>() const {
8332 new UnorderedElementsAreMatcherImpl<Container>(matchers_.begin(),
8337 ::std::vector<T> matchers_;
8339 GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreArrayMatcher);
8342 // Implements ElementsAreArray().
8343 template <typename T>
8344 class ElementsAreArrayMatcher {
8346 template <typename Iter>
8347 ElementsAreArrayMatcher(Iter first, Iter last) : matchers_(first, last) {}
8349 template <typename Container>
8350 operator Matcher<Container>() const {
8351 return MakeMatcher(new ElementsAreMatcherImpl<Container>(
8352 matchers_.begin(), matchers_.end()));
8356 const ::std::vector<T> matchers_;
8358 GTEST_DISALLOW_ASSIGN_(ElementsAreArrayMatcher);
8361 // Given a 2-tuple matcher tm of type Tuple2Matcher and a value second
8362 // of type Second, BoundSecondMatcher<Tuple2Matcher, Second>(tm,
8363 // second) is a polymorphic matcher that matches a value x iff tm
8364 // matches tuple (x, second). Useful for implementing
8365 // UnorderedPointwise() in terms of UnorderedElementsAreArray().
8367 // BoundSecondMatcher is copyable and assignable, as we need to put
8368 // instances of this class in a vector when implementing
8369 // UnorderedPointwise().
8370 template <typename Tuple2Matcher, typename Second>
8371 class BoundSecondMatcher {
8373 BoundSecondMatcher(const Tuple2Matcher& tm, const Second& second)
8374 : tuple2_matcher_(tm), second_value_(second) {}
8376 template <typename T>
8377 operator Matcher<T>() const {
8378 return MakeMatcher(new Impl<T>(tuple2_matcher_, second_value_));
8381 // We have to define this for UnorderedPointwise() to compile in
8382 // C++98 mode, as it puts BoundSecondMatcher instances in a vector,
8383 // which requires the elements to be assignable in C++98. The
8384 // compiler cannot generate the operator= for us, as Tuple2Matcher
8385 // and Second may not be assignable.
8387 // However, this should never be called, so the implementation just
8389 void operator=(const BoundSecondMatcher& /*rhs*/) {
8390 GTEST_LOG_(FATAL) << "BoundSecondMatcher should never be assigned.";
8394 template <typename T>
8395 class Impl : public MatcherInterface<T> {
8397 typedef ::testing::tuple<T, Second> ArgTuple;
8399 Impl(const Tuple2Matcher& tm, const Second& second)
8400 : mono_tuple2_matcher_(SafeMatcherCast<const ArgTuple&>(tm)),
8401 second_value_(second) {}
8403 virtual void DescribeTo(::std::ostream* os) const {
8405 UniversalPrint(second_value_, os);
8407 mono_tuple2_matcher_.DescribeTo(os);
8410 virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
8411 return mono_tuple2_matcher_.MatchAndExplain(ArgTuple(x, second_value_),
8416 const Matcher<const ArgTuple&> mono_tuple2_matcher_;
8417 const Second second_value_;
8419 GTEST_DISALLOW_ASSIGN_(Impl);
8422 const Tuple2Matcher tuple2_matcher_;
8423 const Second second_value_;
8426 // Given a 2-tuple matcher tm and a value second,
8427 // MatcherBindSecond(tm, second) returns a matcher that matches a
8428 // value x iff tm matches tuple (x, second). Useful for implementing
8429 // UnorderedPointwise() in terms of UnorderedElementsAreArray().
8430 template <typename Tuple2Matcher, typename Second>
8431 BoundSecondMatcher<Tuple2Matcher, Second> MatcherBindSecond(
8432 const Tuple2Matcher& tm, const Second& second) {
8433 return BoundSecondMatcher<Tuple2Matcher, Second>(tm, second);
8436 // Returns the description for a matcher defined using the MATCHER*()
8437 // macro where the user-supplied description string is "", if
8438 // 'negation' is false; otherwise returns the description of the
8439 // negation of the matcher. 'param_values' contains a list of strings
8440 // that are the print-out of the matcher's parameters.
8441 GTEST_API_ string FormatMatcherDescription(bool negation,
8442 const char* matcher_name,
8443 const Strings& param_values);
8445 } // namespace internal
8447 // ElementsAreArray(first, last)
8448 // ElementsAreArray(pointer, count)
8449 // ElementsAreArray(array)
8450 // ElementsAreArray(container)
8451 // ElementsAreArray({ e1, e2, ..., en })
8453 // The ElementsAreArray() functions are like ElementsAre(...), except
8454 // that they are given a homogeneous sequence rather than taking each
8455 // element as a function argument. The sequence can be specified as an
8456 // array, a pointer and count, a vector, an initializer list, or an
8457 // STL iterator range. In each of these cases, the underlying sequence
8458 // can be either a sequence of values or a sequence of matchers.
8460 // All forms of ElementsAreArray() make a copy of the input matcher sequence.
8462 template <typename Iter>
8463 inline internal::ElementsAreArrayMatcher<
8464 typename ::std::iterator_traits<Iter>::value_type>
8465 ElementsAreArray(Iter first, Iter last) {
8466 typedef typename ::std::iterator_traits<Iter>::value_type T;
8467 return internal::ElementsAreArrayMatcher<T>(first, last);
8470 template <typename T>
8471 inline internal::ElementsAreArrayMatcher<T> ElementsAreArray(
8472 const T* pointer, size_t count) {
8473 return ElementsAreArray(pointer, pointer + count);
8476 template <typename T, size_t N>
8477 inline internal::ElementsAreArrayMatcher<T> ElementsAreArray(
8478 const T (&array)[N]) {
8479 return ElementsAreArray(array, N);
8482 template <typename Container>
8483 inline internal::ElementsAreArrayMatcher<typename Container::value_type>
8484 ElementsAreArray(const Container& container) {
8485 return ElementsAreArray(container.begin(), container.end());
8488 #if GTEST_HAS_STD_INITIALIZER_LIST_
8489 template <typename T>
8490 inline internal::ElementsAreArrayMatcher<T>
8491 ElementsAreArray(::std::initializer_list<T> xs) {
8492 return ElementsAreArray(xs.begin(), xs.end());
8496 // UnorderedElementsAreArray(first, last)
8497 // UnorderedElementsAreArray(pointer, count)
8498 // UnorderedElementsAreArray(array)
8499 // UnorderedElementsAreArray(container)
8500 // UnorderedElementsAreArray({ e1, e2, ..., en })
8502 // The UnorderedElementsAreArray() functions are like
8503 // ElementsAreArray(...), but allow matching the elements in any order.
8504 template <typename Iter>
8505 inline internal::UnorderedElementsAreArrayMatcher<
8506 typename ::std::iterator_traits<Iter>::value_type>
8507 UnorderedElementsAreArray(Iter first, Iter last) {
8508 typedef typename ::std::iterator_traits<Iter>::value_type T;
8509 return internal::UnorderedElementsAreArrayMatcher<T>(first, last);
8512 template <typename T>
8513 inline internal::UnorderedElementsAreArrayMatcher<T>
8514 UnorderedElementsAreArray(const T* pointer, size_t count) {
8515 return UnorderedElementsAreArray(pointer, pointer + count);
8518 template <typename T, size_t N>
8519 inline internal::UnorderedElementsAreArrayMatcher<T>
8520 UnorderedElementsAreArray(const T (&array)[N]) {
8521 return UnorderedElementsAreArray(array, N);
8524 template <typename Container>
8525 inline internal::UnorderedElementsAreArrayMatcher<
8526 typename Container::value_type>
8527 UnorderedElementsAreArray(const Container& container) {
8528 return UnorderedElementsAreArray(container.begin(), container.end());
8531 #if GTEST_HAS_STD_INITIALIZER_LIST_
8532 template <typename T>
8533 inline internal::UnorderedElementsAreArrayMatcher<T>
8534 UnorderedElementsAreArray(::std::initializer_list<T> xs) {
8535 return UnorderedElementsAreArray(xs.begin(), xs.end());
8539 // _ is a matcher that matches anything of any type.
8541 // This definition is fine as:
8543 // 1. The C++ standard permits using the name _ in a namespace that
8544 // is not the global namespace or ::std.
8545 // 2. The AnythingMatcher class has no data member or constructor,
8546 // so it's OK to create global variables of this type.
8547 // 3. c-style has approved of using _ in this case.
8548 const internal::AnythingMatcher _ = {};
8549 // Creates a matcher that matches any value of the given type T.
8550 template <typename T>
8551 inline Matcher<T> A() { return MakeMatcher(new internal::AnyMatcherImpl<T>()); }
8553 // Creates a matcher that matches any value of the given type T.
8554 template <typename T>
8555 inline Matcher<T> An() { return A<T>(); }
8557 // Creates a polymorphic matcher that matches anything equal to x.
8558 // Note: if the parameter of Eq() were declared as const T&, Eq("foo")
8559 // wouldn't compile.
8560 template <typename T>
8561 inline internal::EqMatcher<T> Eq(T x) { return internal::EqMatcher<T>(x); }
8563 // Constructs a Matcher<T> from a 'value' of type T. The constructed
8564 // matcher matches any value that's equal to 'value'.
8565 template <typename T>
8566 Matcher<T>::Matcher(T value) { *this = Eq(value); }
8568 // Creates a monomorphic matcher that matches anything with type Lhs
8569 // and equal to rhs. A user may need to use this instead of Eq(...)
8570 // in order to resolve an overloading ambiguity.
8572 // TypedEq<T>(x) is just a convenient short-hand for Matcher<T>(Eq(x))
8573 // or Matcher<T>(x), but more readable than the latter.
8575 // We could define similar monomorphic matchers for other comparison
8576 // operations (e.g. TypedLt, TypedGe, and etc), but decided not to do
8577 // it yet as those are used much less than Eq() in practice. A user
8578 // can always write Matcher<T>(Lt(5)) to be explicit about the type,
8580 template <typename Lhs, typename Rhs>
8581 inline Matcher<Lhs> TypedEq(const Rhs& rhs) { return Eq(rhs); }
8583 // Creates a polymorphic matcher that matches anything >= x.
8584 template <typename Rhs>
8585 inline internal::GeMatcher<Rhs> Ge(Rhs x) {
8586 return internal::GeMatcher<Rhs>(x);
8589 // Creates a polymorphic matcher that matches anything > x.
8590 template <typename Rhs>
8591 inline internal::GtMatcher<Rhs> Gt(Rhs x) {
8592 return internal::GtMatcher<Rhs>(x);
8595 // Creates a polymorphic matcher that matches anything <= x.
8596 template <typename Rhs>
8597 inline internal::LeMatcher<Rhs> Le(Rhs x) {
8598 return internal::LeMatcher<Rhs>(x);
8601 // Creates a polymorphic matcher that matches anything < x.
8602 template <typename Rhs>
8603 inline internal::LtMatcher<Rhs> Lt(Rhs x) {
8604 return internal::LtMatcher<Rhs>(x);
8607 // Creates a polymorphic matcher that matches anything != x.
8608 template <typename Rhs>
8609 inline internal::NeMatcher<Rhs> Ne(Rhs x) {
8610 return internal::NeMatcher<Rhs>(x);
8613 // Creates a polymorphic matcher that matches any NULL pointer.
8614 inline PolymorphicMatcher<internal::IsNullMatcher > IsNull() {
8615 return MakePolymorphicMatcher(internal::IsNullMatcher());
8618 // Creates a polymorphic matcher that matches any non-NULL pointer.
8619 // This is convenient as Not(NULL) doesn't compile (the compiler
8620 // thinks that that expression is comparing a pointer with an integer).
8621 inline PolymorphicMatcher<internal::NotNullMatcher > NotNull() {
8622 return MakePolymorphicMatcher(internal::NotNullMatcher());
8625 // Creates a polymorphic matcher that matches any argument that
8626 // references variable x.
8627 template <typename T>
8628 inline internal::RefMatcher<T&> Ref(T& x) { // NOLINT
8629 return internal::RefMatcher<T&>(x);
8632 // Creates a matcher that matches any double argument approximately
8633 // equal to rhs, where two NANs are considered unequal.
8634 inline internal::FloatingEqMatcher<double> DoubleEq(double rhs) {
8635 return internal::FloatingEqMatcher<double>(rhs, false);
8638 // Creates a matcher that matches any double argument approximately
8639 // equal to rhs, including NaN values when rhs is NaN.
8640 inline internal::FloatingEqMatcher<double> NanSensitiveDoubleEq(double rhs) {
8641 return internal::FloatingEqMatcher<double>(rhs, true);
8644 // Creates a matcher that matches any double argument approximately equal to
8645 // rhs, up to the specified max absolute error bound, where two NANs are
8646 // considered unequal. The max absolute error bound must be non-negative.
8647 inline internal::FloatingEqMatcher<double> DoubleNear(
8648 double rhs, double max_abs_error) {
8649 return internal::FloatingEqMatcher<double>(rhs, false, max_abs_error);
8652 // Creates a matcher that matches any double argument approximately equal to
8653 // rhs, up to the specified max absolute error bound, including NaN values when
8654 // rhs is NaN. The max absolute error bound must be non-negative.
8655 inline internal::FloatingEqMatcher<double> NanSensitiveDoubleNear(
8656 double rhs, double max_abs_error) {
8657 return internal::FloatingEqMatcher<double>(rhs, true, max_abs_error);
8660 // Creates a matcher that matches any float argument approximately
8661 // equal to rhs, where two NANs are considered unequal.
8662 inline internal::FloatingEqMatcher<float> FloatEq(float rhs) {
8663 return internal::FloatingEqMatcher<float>(rhs, false);
8666 // Creates a matcher that matches any float argument approximately
8667 // equal to rhs, including NaN values when rhs is NaN.
8668 inline internal::FloatingEqMatcher<float> NanSensitiveFloatEq(float rhs) {
8669 return internal::FloatingEqMatcher<float>(rhs, true);
8672 // Creates a matcher that matches any float argument approximately equal to
8673 // rhs, up to the specified max absolute error bound, where two NANs are
8674 // considered unequal. The max absolute error bound must be non-negative.
8675 inline internal::FloatingEqMatcher<float> FloatNear(
8676 float rhs, float max_abs_error) {
8677 return internal::FloatingEqMatcher<float>(rhs, false, max_abs_error);
8680 // Creates a matcher that matches any float argument approximately equal to
8681 // rhs, up to the specified max absolute error bound, including NaN values when
8682 // rhs is NaN. The max absolute error bound must be non-negative.
8683 inline internal::FloatingEqMatcher<float> NanSensitiveFloatNear(
8684 float rhs, float max_abs_error) {
8685 return internal::FloatingEqMatcher<float>(rhs, true, max_abs_error);
8688 // Creates a matcher that matches a pointer (raw or smart) that points
8689 // to a value that matches inner_matcher.
8690 template <typename InnerMatcher>
8691 inline internal::PointeeMatcher<InnerMatcher> Pointee(
8692 const InnerMatcher& inner_matcher) {
8693 return internal::PointeeMatcher<InnerMatcher>(inner_matcher);
8696 // Creates a matcher that matches a pointer or reference that matches
8697 // inner_matcher when dynamic_cast<To> is applied.
8698 // The result of dynamic_cast<To> is forwarded to the inner matcher.
8699 // If To is a pointer and the cast fails, the inner matcher will receive NULL.
8700 // If To is a reference and the cast fails, this matcher returns false
8702 template <typename To>
8703 inline PolymorphicMatcher<internal::WhenDynamicCastToMatcher<To> >
8704 WhenDynamicCastTo(const Matcher<To>& inner_matcher) {
8705 return MakePolymorphicMatcher(
8706 internal::WhenDynamicCastToMatcher<To>(inner_matcher));
8709 // Creates a matcher that matches an object whose given field matches
8710 // 'matcher'. For example,
8711 // Field(&Foo::number, Ge(5))
8712 // matches a Foo object x iff x.number >= 5.
8713 template <typename Class, typename FieldType, typename FieldMatcher>
8714 inline PolymorphicMatcher<
8715 internal::FieldMatcher<Class, FieldType> > Field(
8716 FieldType Class::*field, const FieldMatcher& matcher) {
8717 return MakePolymorphicMatcher(
8718 internal::FieldMatcher<Class, FieldType>(
8719 field, MatcherCast<const FieldType&>(matcher)));
8720 // The call to MatcherCast() is required for supporting inner
8721 // matchers of compatible types. For example, it allows
8722 // Field(&Foo::bar, m)
8723 // to compile where bar is an int32 and m is a matcher for int64.
8726 // Creates a matcher that matches an object whose given property
8727 // matches 'matcher'. For example,
8728 // Property(&Foo::str, StartsWith("hi"))
8729 // matches a Foo object x iff x.str() starts with "hi".
8730 template <typename Class, typename PropertyType, typename PropertyMatcher>
8731 inline PolymorphicMatcher<
8732 internal::PropertyMatcher<Class, PropertyType> > Property(
8733 PropertyType (Class::*property)() const, const PropertyMatcher& matcher) {
8734 return MakePolymorphicMatcher(
8735 internal::PropertyMatcher<Class, PropertyType>(
8737 MatcherCast<GTEST_REFERENCE_TO_CONST_(PropertyType)>(matcher)));
8738 // The call to MatcherCast() is required for supporting inner
8739 // matchers of compatible types. For example, it allows
8740 // Property(&Foo::bar, m)
8741 // to compile where bar() returns an int32 and m is a matcher for int64.
8744 // Creates a matcher that matches an object iff the result of applying
8745 // a callable to x matches 'matcher'.
8747 // ResultOf(f, StartsWith("hi"))
8748 // matches a Foo object x iff f(x) starts with "hi".
8749 // callable parameter can be a function, function pointer, or a functor.
8750 // Callable has to satisfy the following conditions:
8751 // * It is required to keep no state affecting the results of
8752 // the calls on it and make no assumptions about how many calls
8753 // will be made. Any state it keeps must be protected from the
8754 // concurrent access.
8755 // * If it is a function object, it has to define type result_type.
8756 // We recommend deriving your functor classes from std::unary_function.
8757 template <typename Callable, typename ResultOfMatcher>
8758 internal::ResultOfMatcher<Callable> ResultOf(
8759 Callable callable, const ResultOfMatcher& matcher) {
8760 return internal::ResultOfMatcher<Callable>(
8762 MatcherCast<typename internal::CallableTraits<Callable>::ResultType>(
8764 // The call to MatcherCast() is required for supporting inner
8765 // matchers of compatible types. For example, it allows
8766 // ResultOf(Function, m)
8767 // to compile where Function() returns an int32 and m is a matcher for int64.
8772 // Matches a string equal to str.
8773 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> >
8774 StrEq(const internal::string& str) {
8775 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>(
8779 // Matches a string not equal to str.
8780 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> >
8781 StrNe(const internal::string& str) {
8782 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>(
8786 // Matches a string equal to str, ignoring case.
8787 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> >
8788 StrCaseEq(const internal::string& str) {
8789 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>(
8793 // Matches a string not equal to str, ignoring case.
8794 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> >
8795 StrCaseNe(const internal::string& str) {
8796 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>(
8797 str, false, false));
8800 // Creates a matcher that matches any string, std::string, or C string
8801 // that contains the given substring.
8802 inline PolymorphicMatcher<internal::HasSubstrMatcher<internal::string> >
8803 HasSubstr(const internal::string& substring) {
8804 return MakePolymorphicMatcher(internal::HasSubstrMatcher<internal::string>(
8808 // Matches a string that starts with 'prefix' (case-sensitive).
8809 inline PolymorphicMatcher<internal::StartsWithMatcher<internal::string> >
8810 StartsWith(const internal::string& prefix) {
8811 return MakePolymorphicMatcher(internal::StartsWithMatcher<internal::string>(
8815 // Matches a string that ends with 'suffix' (case-sensitive).
8816 inline PolymorphicMatcher<internal::EndsWithMatcher<internal::string> >
8817 EndsWith(const internal::string& suffix) {
8818 return MakePolymorphicMatcher(internal::EndsWithMatcher<internal::string>(
8822 // Matches a string that fully matches regular expression 'regex'.
8823 // The matcher takes ownership of 'regex'.
8824 inline PolymorphicMatcher<internal::MatchesRegexMatcher> MatchesRegex(
8825 const internal::RE* regex) {
8826 return MakePolymorphicMatcher(internal::MatchesRegexMatcher(regex, true));
8828 inline PolymorphicMatcher<internal::MatchesRegexMatcher> MatchesRegex(
8829 const internal::string& regex) {
8830 return MatchesRegex(new internal::RE(regex));
8833 // Matches a string that contains regular expression 'regex'.
8834 // The matcher takes ownership of 'regex'.
8835 inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex(
8836 const internal::RE* regex) {
8837 return MakePolymorphicMatcher(internal::MatchesRegexMatcher(regex, false));
8839 inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex(
8840 const internal::string& regex) {
8841 return ContainsRegex(new internal::RE(regex));
8844 #if GTEST_HAS_GLOBAL_WSTRING || GTEST_HAS_STD_WSTRING
8845 // Wide string matchers.
8847 // Matches a string equal to str.
8848 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> >
8849 StrEq(const internal::wstring& str) {
8850 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstring>(
8854 // Matches a string not equal to str.
8855 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> >
8856 StrNe(const internal::wstring& str) {
8857 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstring>(
8861 // Matches a string equal to str, ignoring case.
8862 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> >
8863 StrCaseEq(const internal::wstring& str) {
8864 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstring>(
8868 // Matches a string not equal to str, ignoring case.
8869 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> >
8870 StrCaseNe(const internal::wstring& str) {
8871 return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstring>(
8872 str, false, false));
8875 // Creates a matcher that matches any wstring, std::wstring, or C wide string
8876 // that contains the given substring.
8877 inline PolymorphicMatcher<internal::HasSubstrMatcher<internal::wstring> >
8878 HasSubstr(const internal::wstring& substring) {
8879 return MakePolymorphicMatcher(internal::HasSubstrMatcher<internal::wstring>(
8883 // Matches a string that starts with 'prefix' (case-sensitive).
8884 inline PolymorphicMatcher<internal::StartsWithMatcher<internal::wstring> >
8885 StartsWith(const internal::wstring& prefix) {
8886 return MakePolymorphicMatcher(internal::StartsWithMatcher<internal::wstring>(
8890 // Matches a string that ends with 'suffix' (case-sensitive).
8891 inline PolymorphicMatcher<internal::EndsWithMatcher<internal::wstring> >
8892 EndsWith(const internal::wstring& suffix) {
8893 return MakePolymorphicMatcher(internal::EndsWithMatcher<internal::wstring>(
8897 #endif // GTEST_HAS_GLOBAL_WSTRING || GTEST_HAS_STD_WSTRING
8899 // Creates a polymorphic matcher that matches a 2-tuple where the
8900 // first field == the second field.
8901 inline internal::Eq2Matcher Eq() { return internal::Eq2Matcher(); }
8903 // Creates a polymorphic matcher that matches a 2-tuple where the
8904 // first field >= the second field.
8905 inline internal::Ge2Matcher Ge() { return internal::Ge2Matcher(); }
8907 // Creates a polymorphic matcher that matches a 2-tuple where the
8908 // first field > the second field.
8909 inline internal::Gt2Matcher Gt() { return internal::Gt2Matcher(); }
8911 // Creates a polymorphic matcher that matches a 2-tuple where the
8912 // first field <= the second field.
8913 inline internal::Le2Matcher Le() { return internal::Le2Matcher(); }
8915 // Creates a polymorphic matcher that matches a 2-tuple where the
8916 // first field < the second field.
8917 inline internal::Lt2Matcher Lt() { return internal::Lt2Matcher(); }
8919 // Creates a polymorphic matcher that matches a 2-tuple where the
8920 // first field != the second field.
8921 inline internal::Ne2Matcher Ne() { return internal::Ne2Matcher(); }
8923 // Creates a matcher that matches any value of type T that m doesn't
8925 template <typename InnerMatcher>
8926 inline internal::NotMatcher<InnerMatcher> Not(InnerMatcher m) {
8927 return internal::NotMatcher<InnerMatcher>(m);
8930 // Returns a matcher that matches anything that satisfies the given
8931 // predicate. The predicate can be any unary function or functor
8932 // whose return type can be implicitly converted to bool.
8933 template <typename Predicate>
8934 inline PolymorphicMatcher<internal::TrulyMatcher<Predicate> >
8935 Truly(Predicate pred) {
8936 return MakePolymorphicMatcher(internal::TrulyMatcher<Predicate>(pred));
8939 // Returns a matcher that matches the container size. The container must
8940 // support both size() and size_type which all STL-like containers provide.
8941 // Note that the parameter 'size' can be a value of type size_type as well as
8942 // matcher. For instance:
8943 // EXPECT_THAT(container, SizeIs(2)); // Checks container has 2 elements.
8944 // EXPECT_THAT(container, SizeIs(Le(2)); // Checks container has at most 2.
8945 template <typename SizeMatcher>
8946 inline internal::SizeIsMatcher<SizeMatcher>
8947 SizeIs(const SizeMatcher& size_matcher) {
8948 return internal::SizeIsMatcher<SizeMatcher>(size_matcher);
8951 // Returns a matcher that matches the distance between the container's begin()
8952 // iterator and its end() iterator, i.e. the size of the container. This matcher
8953 // can be used instead of SizeIs with containers such as std::forward_list which
8954 // do not implement size(). The container must provide const_iterator (with
8955 // valid iterator_traits), begin() and end().
8956 template <typename DistanceMatcher>
8957 inline internal::BeginEndDistanceIsMatcher<DistanceMatcher>
8958 BeginEndDistanceIs(const DistanceMatcher& distance_matcher) {
8959 return internal::BeginEndDistanceIsMatcher<DistanceMatcher>(distance_matcher);
8962 // Returns a matcher that matches an equal container.
8963 // This matcher behaves like Eq(), but in the event of mismatch lists the
8964 // values that are included in one container but not the other. (Duplicate
8965 // values and order differences are not explained.)
8966 template <typename Container>
8967 inline PolymorphicMatcher<internal::ContainerEqMatcher< // NOLINT
8968 GTEST_REMOVE_CONST_(Container)> >
8969 ContainerEq(const Container& rhs) {
8970 // This following line is for working around a bug in MSVC 8.0,
8971 // which causes Container to be a const type sometimes.
8972 typedef GTEST_REMOVE_CONST_(Container) RawContainer;
8973 return MakePolymorphicMatcher(
8974 internal::ContainerEqMatcher<RawContainer>(rhs));
8977 // Returns a matcher that matches a container that, when sorted using
8978 // the given comparator, matches container_matcher.
8979 template <typename Comparator, typename ContainerMatcher>
8980 inline internal::WhenSortedByMatcher<Comparator, ContainerMatcher>
8981 WhenSortedBy(const Comparator& comparator,
8982 const ContainerMatcher& container_matcher) {
8983 return internal::WhenSortedByMatcher<Comparator, ContainerMatcher>(
8984 comparator, container_matcher);
8987 // Returns a matcher that matches a container that, when sorted using
8988 // the < operator, matches container_matcher.
8989 template <typename ContainerMatcher>
8990 inline internal::WhenSortedByMatcher<internal::LessComparator, ContainerMatcher>
8991 WhenSorted(const ContainerMatcher& container_matcher) {
8993 internal::WhenSortedByMatcher<internal::LessComparator, ContainerMatcher>(
8994 internal::LessComparator(), container_matcher);
8997 // Matches an STL-style container or a native array that contains the
8998 // same number of elements as in rhs, where its i-th element and rhs's
8999 // i-th element (as a pair) satisfy the given pair matcher, for all i.
9000 // TupleMatcher must be able to be safely cast to Matcher<tuple<const
9001 // T1&, const T2&> >, where T1 and T2 are the types of elements in the
9002 // LHS container and the RHS container respectively.
9003 template <typename TupleMatcher, typename Container>
9004 inline internal::PointwiseMatcher<TupleMatcher,
9005 GTEST_REMOVE_CONST_(Container)>
9006 Pointwise(const TupleMatcher& tuple_matcher, const Container& rhs) {
9007 // This following line is for working around a bug in MSVC 8.0,
9008 // which causes Container to be a const type sometimes (e.g. when
9009 // rhs is a const int[])..
9010 typedef GTEST_REMOVE_CONST_(Container) RawContainer;
9011 return internal::PointwiseMatcher<TupleMatcher, RawContainer>(
9012 tuple_matcher, rhs);
9015 #if GTEST_HAS_STD_INITIALIZER_LIST_
9017 // Supports the Pointwise(m, {a, b, c}) syntax.
9018 template <typename TupleMatcher, typename T>
9019 inline internal::PointwiseMatcher<TupleMatcher, std::vector<T> > Pointwise(
9020 const TupleMatcher& tuple_matcher, std::initializer_list<T> rhs) {
9021 return Pointwise(tuple_matcher, std::vector<T>(rhs));
9024 #endif // GTEST_HAS_STD_INITIALIZER_LIST_
9026 // UnorderedPointwise(pair_matcher, rhs) matches an STL-style
9027 // container or a native array that contains the same number of
9028 // elements as in rhs, where in some permutation of the container, its
9029 // i-th element and rhs's i-th element (as a pair) satisfy the given
9030 // pair matcher, for all i. Tuple2Matcher must be able to be safely
9031 // cast to Matcher<tuple<const T1&, const T2&> >, where T1 and T2 are
9032 // the types of elements in the LHS container and the RHS container
9035 // This is like Pointwise(pair_matcher, rhs), except that the element
9036 // order doesn't matter.
9037 template <typename Tuple2Matcher, typename RhsContainer>
9038 inline internal::UnorderedElementsAreArrayMatcher<
9039 typename internal::BoundSecondMatcher<
9040 Tuple2Matcher, typename internal::StlContainerView<GTEST_REMOVE_CONST_(
9041 RhsContainer)>::type::value_type> >
9042 UnorderedPointwise(const Tuple2Matcher& tuple2_matcher,
9043 const RhsContainer& rhs_container) {
9044 // This following line is for working around a bug in MSVC 8.0,
9045 // which causes RhsContainer to be a const type sometimes (e.g. when
9046 // rhs_container is a const int[]).
9047 typedef GTEST_REMOVE_CONST_(RhsContainer) RawRhsContainer;
9049 // RhsView allows the same code to handle RhsContainer being a
9050 // STL-style container and it being a native C-style array.
9051 typedef typename internal::StlContainerView<RawRhsContainer> RhsView;
9052 typedef typename RhsView::type RhsStlContainer;
9053 typedef typename RhsStlContainer::value_type Second;
9054 const RhsStlContainer& rhs_stl_container =
9055 RhsView::ConstReference(rhs_container);
9057 // Create a matcher for each element in rhs_container.
9058 ::std::vector<internal::BoundSecondMatcher<Tuple2Matcher, Second> > matchers;
9059 for (typename RhsStlContainer::const_iterator it = rhs_stl_container.begin();
9060 it != rhs_stl_container.end(); ++it) {
9062 internal::MatcherBindSecond(tuple2_matcher, *it));
9065 // Delegate the work to UnorderedElementsAreArray().
9066 return UnorderedElementsAreArray(matchers);
9069 #if GTEST_HAS_STD_INITIALIZER_LIST_
9071 // Supports the UnorderedPointwise(m, {a, b, c}) syntax.
9072 template <typename Tuple2Matcher, typename T>
9073 inline internal::UnorderedElementsAreArrayMatcher<
9074 typename internal::BoundSecondMatcher<Tuple2Matcher, T> >
9075 UnorderedPointwise(const Tuple2Matcher& tuple2_matcher,
9076 std::initializer_list<T> rhs) {
9077 return UnorderedPointwise(tuple2_matcher, std::vector<T>(rhs));
9080 #endif // GTEST_HAS_STD_INITIALIZER_LIST_
9082 // Matches an STL-style container or a native array that contains at
9083 // least one element matching the given value or matcher.
9086 // ::std::set<int> page_ids;
9087 // page_ids.insert(3);
9088 // page_ids.insert(1);
9089 // EXPECT_THAT(page_ids, Contains(1));
9090 // EXPECT_THAT(page_ids, Contains(Gt(2)));
9091 // EXPECT_THAT(page_ids, Not(Contains(4)));
9093 // ::std::map<int, size_t> page_lengths;
9094 // page_lengths[1] = 100;
9095 // EXPECT_THAT(page_lengths,
9096 // Contains(::std::pair<const int, size_t>(1, 100)));
9098 // const char* user_ids[] = { "joe", "mike", "tom" };
9099 // EXPECT_THAT(user_ids, Contains(Eq(::std::string("tom"))));
9100 template <typename M>
9101 inline internal::ContainsMatcher<M> Contains(M matcher) {
9102 return internal::ContainsMatcher<M>(matcher);
9105 // Matches an STL-style container or a native array that contains only
9106 // elements matching the given value or matcher.
9108 // Each(m) is semantically equivalent to Not(Contains(Not(m))). Only
9109 // the messages are different.
9112 // ::std::set<int> page_ids;
9113 // // Each(m) matches an empty container, regardless of what m is.
9114 // EXPECT_THAT(page_ids, Each(Eq(1)));
9115 // EXPECT_THAT(page_ids, Each(Eq(77)));
9117 // page_ids.insert(3);
9118 // EXPECT_THAT(page_ids, Each(Gt(0)));
9119 // EXPECT_THAT(page_ids, Not(Each(Gt(4))));
9120 // page_ids.insert(1);
9121 // EXPECT_THAT(page_ids, Not(Each(Lt(2))));
9123 // ::std::map<int, size_t> page_lengths;
9124 // page_lengths[1] = 100;
9125 // page_lengths[2] = 200;
9126 // page_lengths[3] = 300;
9127 // EXPECT_THAT(page_lengths, Not(Each(Pair(1, 100))));
9128 // EXPECT_THAT(page_lengths, Each(Key(Le(3))));
9130 // const char* user_ids[] = { "joe", "mike", "tom" };
9131 // EXPECT_THAT(user_ids, Not(Each(Eq(::std::string("tom")))));
9132 template <typename M>
9133 inline internal::EachMatcher<M> Each(M matcher) {
9134 return internal::EachMatcher<M>(matcher);
9137 // Key(inner_matcher) matches an std::pair whose 'first' field matches
9138 // inner_matcher. For example, Contains(Key(Ge(5))) can be used to match an
9139 // std::map that contains at least one element whose key is >= 5.
9140 template <typename M>
9141 inline internal::KeyMatcher<M> Key(M inner_matcher) {
9142 return internal::KeyMatcher<M>(inner_matcher);
9145 // Pair(first_matcher, second_matcher) matches a std::pair whose 'first' field
9146 // matches first_matcher and whose 'second' field matches second_matcher. For
9147 // example, EXPECT_THAT(map_type, ElementsAre(Pair(Ge(5), "foo"))) can be used
9148 // to match a std::map<int, string> that contains exactly one element whose key
9149 // is >= 5 and whose value equals "foo".
9150 template <typename FirstMatcher, typename SecondMatcher>
9151 inline internal::PairMatcher<FirstMatcher, SecondMatcher>
9152 Pair(FirstMatcher first_matcher, SecondMatcher second_matcher) {
9153 return internal::PairMatcher<FirstMatcher, SecondMatcher>(
9154 first_matcher, second_matcher);
9157 // Returns a predicate that is satisfied by anything that matches the
9159 template <typename M>
9160 inline internal::MatcherAsPredicate<M> Matches(M matcher) {
9161 return internal::MatcherAsPredicate<M>(matcher);
9164 // Returns true iff the value matches the matcher.
9165 template <typename T, typename M>
9166 inline bool Value(const T& value, M matcher) {
9167 return testing::Matches(matcher)(value);
9170 // Matches the value against the given matcher and explains the match
9171 // result to listener.
9172 template <typename T, typename M>
9173 inline bool ExplainMatchResult(
9174 M matcher, const T& value, MatchResultListener* listener) {
9175 return SafeMatcherCast<const T&>(matcher).MatchAndExplain(value, listener);
9178 #if GTEST_LANG_CXX11
9179 // Define variadic matcher versions. They are overloaded in
9180 // gmock-generated-matchers.h for the cases supported by pre C++11 compilers.
9181 template <typename... Args>
9182 inline internal::AllOfMatcher<Args...> AllOf(const Args&... matchers) {
9183 return internal::AllOfMatcher<Args...>(matchers...);
9186 template <typename... Args>
9187 inline internal::AnyOfMatcher<Args...> AnyOf(const Args&... matchers) {
9188 return internal::AnyOfMatcher<Args...>(matchers...);
9191 #endif // GTEST_LANG_CXX11
9193 // AllArgs(m) is a synonym of m. This is useful in
9195 // EXPECT_CALL(foo, Bar(_, _)).With(AllArgs(Eq()));
9197 // which is easier to read than
9199 // EXPECT_CALL(foo, Bar(_, _)).With(Eq());
9200 template <typename InnerMatcher>
9201 inline InnerMatcher AllArgs(const InnerMatcher& matcher) { return matcher; }
9203 // These macros allow using matchers to check values in Google Test
9204 // tests. ASSERT_THAT(value, matcher) and EXPECT_THAT(value, matcher)
9205 // succeed iff the value matches the matcher. If the assertion fails,
9206 // the value and the description of the matcher will be printed.
9207 #define ASSERT_THAT(value, matcher) ASSERT_PRED_FORMAT1(\
9208 ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value)
9209 #define EXPECT_THAT(value, matcher) EXPECT_PRED_FORMAT1(\
9210 ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value)
9212 } // namespace testing
9214 // Include any custom callback matchers added by the local installation.
9215 // We must include this header at the end to make sure it can use the
9216 // declarations from this file.
9217 // Copyright 2015, Google Inc.
9218 // All rights reserved.
9220 // Redistribution and use in source and binary forms, with or without
9221 // modification, are permitted provided that the following conditions are
9224 // * Redistributions of source code must retain the above copyright
9225 // notice, this list of conditions and the following disclaimer.
9226 // * Redistributions in binary form must reproduce the above
9227 // copyright notice, this list of conditions and the following disclaimer
9228 // in the documentation and/or other materials provided with the
9230 // * Neither the name of Google Inc. nor the names of its
9231 // contributors may be used to endorse or promote products derived from
9232 // this software without specific prior written permission.
9234 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
9235 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
9236 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
9237 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9238 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9239 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9240 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
9241 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
9242 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
9243 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
9244 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9246 // ============================================================
9247 // An installation-specific extension point for gmock-matchers.h.
9248 // ============================================================
9250 // Adds google3 callback support to CallableTraits.
9252 #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_CALLBACK_MATCHERS_H_
9253 #define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_CALLBACK_MATCHERS_H_
9255 #endif // GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_CALLBACK_MATCHERS_H_
9256 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
9260 // An abstract handle of an expectation.
9263 // A set of expectation handles.
9264 class ExpectationSet;
9266 // Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION
9267 // and MUST NOT BE USED IN USER CODE!!!
9268 namespace internal {
9270 // Implements a mock function.
9271 template <typename F> class FunctionMocker;
9273 // Base class for expectations.
9274 class ExpectationBase;
9276 // Implements an expectation.
9277 template <typename F> class TypedExpectation;
9279 // Helper class for testing the Expectation class template.
9280 class ExpectationTester;
9282 // Base class for function mockers.
9283 template <typename F> class FunctionMockerBase;
9285 // Protects the mock object registry (in class Mock), all function
9286 // mockers, and all expectations.
9288 // The reason we don't use more fine-grained protection is: when a
9289 // mock function Foo() is called, it needs to consult its expectations
9290 // to see which one should be picked. If another thread is allowed to
9291 // call a mock function (either Foo() or a different one) at the same
9292 // time, it could affect the "retired" attributes of Foo()'s
9293 // expectations when InSequence() is used, and thus affect which
9294 // expectation gets picked. Therefore, we sequence all mock function
9295 // calls to ensure the integrity of the mock objects' states.
9296 GTEST_API_ GTEST_DECLARE_STATIC_MUTEX_(g_gmock_mutex);
9298 // Untyped base class for ActionResultHolder<R>.
9299 class UntypedActionResultHolderBase;
9301 // Abstract base class of FunctionMockerBase. This is the
9302 // type-agnostic part of the function mocker interface. Its pure
9303 // virtual methods are implemented by FunctionMockerBase.
9304 class GTEST_API_ UntypedFunctionMockerBase {
9306 UntypedFunctionMockerBase();
9307 virtual ~UntypedFunctionMockerBase();
9309 // Verifies that all expectations on this mock function have been
9310 // satisfied. Reports one or more Google Test non-fatal failures
9311 // and returns false if not.
9312 bool VerifyAndClearExpectationsLocked()
9313 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
9315 // Clears the ON_CALL()s set on this mock function.
9316 virtual void ClearDefaultActionsLocked()
9317 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) = 0;
9319 // In all of the following Untyped* functions, it's the caller's
9320 // responsibility to guarantee the correctness of the arguments'
9323 // Performs the default action with the given arguments and returns
9324 // the action's result. The call description string will be used in
9325 // the error message to describe the call in the case the default
9328 virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction(
9329 const void* untyped_args,
9330 const string& call_description) const = 0;
9332 // Performs the given action with the given arguments and returns
9333 // the action's result.
9335 virtual UntypedActionResultHolderBase* UntypedPerformAction(
9336 const void* untyped_action,
9337 const void* untyped_args) const = 0;
9339 // Writes a message that the call is uninteresting (i.e. neither
9340 // explicitly expected nor explicitly unexpected) to the given
9342 virtual void UntypedDescribeUninterestingCall(
9343 const void* untyped_args,
9344 ::std::ostream* os) const
9345 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) = 0;
9347 // Returns the expectation that matches the given function arguments
9348 // (or NULL is there's no match); when a match is found,
9349 // untyped_action is set to point to the action that should be
9350 // performed (or NULL if the action is "do default"), and
9351 // is_excessive is modified to indicate whether the call exceeds the
9353 virtual const ExpectationBase* UntypedFindMatchingExpectation(
9354 const void* untyped_args,
9355 const void** untyped_action, bool* is_excessive,
9356 ::std::ostream* what, ::std::ostream* why)
9357 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) = 0;
9359 // Prints the given function arguments to the ostream.
9360 virtual void UntypedPrintArgs(const void* untyped_args,
9361 ::std::ostream* os) const = 0;
9363 // Sets the mock object this mock method belongs to, and registers
9364 // this information in the global mock registry. Will be called
9365 // whenever an EXPECT_CALL() or ON_CALL() is executed on this mock
9367 // TODO(wan@google.com): rename to SetAndRegisterOwner().
9368 void RegisterOwner(const void* mock_obj)
9369 GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
9371 // Sets the mock object this mock method belongs to, and sets the
9372 // name of the mock function. Will be called upon each invocation
9373 // of this mock function.
9374 void SetOwnerAndName(const void* mock_obj, const char* name)
9375 GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
9377 // Returns the mock object this mock method belongs to. Must be
9378 // called after RegisterOwner() or SetOwnerAndName() has been
9380 const void* MockObject() const
9381 GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
9383 // Returns the name of this mock method. Must be called after
9384 // SetOwnerAndName() has been called.
9385 const char* Name() const
9386 GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
9388 // Returns the result of invoking this mock function with the given
9389 // arguments. This function can be safely called from multiple
9390 // threads concurrently. The caller is responsible for deleting the
9392 UntypedActionResultHolderBase* UntypedInvokeWith(
9393 const void* untyped_args)
9394 GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
9397 typedef std::vector<const void*> UntypedOnCallSpecs;
9399 typedef std::vector<internal::linked_ptr<ExpectationBase> >
9400 UntypedExpectations;
9402 // Returns an Expectation object that references and co-owns exp,
9403 // which must be an expectation on this mock function.
9404 Expectation GetHandleOf(ExpectationBase* exp);
9406 // Address of the mock object this mock method belongs to. Only
9407 // valid after this mock method has been called or
9408 // ON_CALL/EXPECT_CALL has been invoked on it.
9409 const void* mock_obj_; // Protected by g_gmock_mutex.
9411 // Name of the function being mocked. Only valid after this mock
9412 // method has been called.
9413 const char* name_; // Protected by g_gmock_mutex.
9415 // All default action specs for this function mocker.
9416 UntypedOnCallSpecs untyped_on_call_specs_;
9418 // All expectations for this function mocker.
9419 UntypedExpectations untyped_expectations_;
9420 }; // class UntypedFunctionMockerBase
9422 // Untyped base class for OnCallSpec<F>.
9423 class UntypedOnCallSpecBase {
9425 // The arguments are the location of the ON_CALL() statement.
9426 UntypedOnCallSpecBase(const char* a_file, int a_line)
9427 : file_(a_file), line_(a_line), last_clause_(kNone) {}
9429 // Where in the source file was the default action spec defined?
9430 const char* file() const { return file_; }
9431 int line() const { return line_; }
9434 // Gives each clause in the ON_CALL() statement a name.
9436 // Do not change the order of the enum members! The run-time
9437 // syntax checking relies on it.
9443 // Asserts that the ON_CALL() statement has a certain property.
9444 void AssertSpecProperty(bool property, const string& failure_message) const {
9445 Assert(property, file_, line_, failure_message);
9448 // Expects that the ON_CALL() statement has a certain property.
9449 void ExpectSpecProperty(bool property, const string& failure_message) const {
9450 Expect(property, file_, line_, failure_message);
9456 // The last clause in the ON_CALL() statement as seen so far.
9457 // Initially kNone and changes as the statement is parsed.
9458 Clause last_clause_;
9459 }; // class UntypedOnCallSpecBase
9461 // This template class implements an ON_CALL spec.
9462 template <typename F>
9463 class OnCallSpec : public UntypedOnCallSpecBase {
9465 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
9466 typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple;
9468 // Constructs an OnCallSpec object from the information inside
9469 // the parenthesis of an ON_CALL() statement.
9470 OnCallSpec(const char* a_file, int a_line,
9471 const ArgumentMatcherTuple& matchers)
9472 : UntypedOnCallSpecBase(a_file, a_line),
9473 matchers_(matchers),
9474 // By default, extra_matcher_ should match anything. However,
9475 // we cannot initialize it with _ as that triggers a compiler
9476 // bug in Symbian's C++ compiler (cannot decide between two
9477 // overloaded constructors of Matcher<const ArgumentTuple&>).
9478 extra_matcher_(A<const ArgumentTuple&>()) {
9481 // Implements the .With() clause.
9482 OnCallSpec& With(const Matcher<const ArgumentTuple&>& m) {
9483 // Makes sure this is called at most once.
9484 ExpectSpecProperty(last_clause_ < kWith,
9485 ".With() cannot appear "
9486 "more than once in an ON_CALL().");
9487 last_clause_ = kWith;
9493 // Implements the .WillByDefault() clause.
9494 OnCallSpec& WillByDefault(const Action<F>& action) {
9495 ExpectSpecProperty(last_clause_ < kWillByDefault,
9496 ".WillByDefault() must appear "
9497 "exactly once in an ON_CALL().");
9498 last_clause_ = kWillByDefault;
9500 ExpectSpecProperty(!action.IsDoDefault(),
9501 "DoDefault() cannot be used in ON_CALL().");
9506 // Returns true iff the given arguments match the matchers.
9507 bool Matches(const ArgumentTuple& args) const {
9508 return TupleMatches(matchers_, args) && extra_matcher_.Matches(args);
9511 // Returns the action specified by the user.
9512 const Action<F>& GetAction() const {
9513 AssertSpecProperty(last_clause_ == kWillByDefault,
9514 ".WillByDefault() must appear exactly "
9515 "once in an ON_CALL().");
9520 // The information in statement
9522 // ON_CALL(mock_object, Method(matchers))
9523 // .With(multi-argument-matcher)
9524 // .WillByDefault(action);
9526 // is recorded in the data members like this:
9528 // source file that contains the statement => file_
9529 // line number of the statement => line_
9530 // matchers => matchers_
9531 // multi-argument-matcher => extra_matcher_
9532 // action => action_
9533 ArgumentMatcherTuple matchers_;
9534 Matcher<const ArgumentTuple&> extra_matcher_;
9536 }; // class OnCallSpec
9538 // Possible reactions on uninteresting calls.
9543 kDefault = kWarn // By default, warn about uninteresting calls.
9546 } // namespace internal
9548 // Utilities for manipulating mock objects.
9549 class GTEST_API_ Mock {
9551 // The following public methods can be called concurrently.
9553 // Tells Google Mock to ignore mock_obj when checking for leaked
9555 static void AllowLeak(const void* mock_obj)
9556 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
9558 // Verifies and clears all expectations on the given mock object.
9559 // If the expectations aren't satisfied, generates one or more
9560 // Google Test non-fatal failures and returns false.
9561 static bool VerifyAndClearExpectations(void* mock_obj)
9562 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
9564 // Verifies all expectations on the given mock object and clears its
9565 // default actions and expectations. Returns true iff the
9566 // verification was successful.
9567 static bool VerifyAndClear(void* mock_obj)
9568 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
9571 friend class internal::UntypedFunctionMockerBase;
9573 // Needed for a function mocker to register itself (so that we know
9574 // how to clear a mock object).
9575 template <typename F>
9576 friend class internal::FunctionMockerBase;
9578 template <typename M>
9579 friend class NiceMock;
9581 template <typename M>
9582 friend class NaggyMock;
9584 template <typename M>
9585 friend class StrictMock;
9587 // Tells Google Mock to allow uninteresting calls on the given mock
9589 static void AllowUninterestingCalls(const void* mock_obj)
9590 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
9592 // Tells Google Mock to warn the user about uninteresting calls on
9593 // the given mock object.
9594 static void WarnUninterestingCalls(const void* mock_obj)
9595 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
9597 // Tells Google Mock to fail uninteresting calls on the given mock
9599 static void FailUninterestingCalls(const void* mock_obj)
9600 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
9602 // Tells Google Mock the given mock object is being destroyed and
9603 // its entry in the call-reaction table should be removed.
9604 static void UnregisterCallReaction(const void* mock_obj)
9605 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
9607 // Returns the reaction Google Mock will have on uninteresting calls
9608 // made on the given mock object.
9609 static internal::CallReaction GetReactionOnUninterestingCalls(
9610 const void* mock_obj)
9611 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
9613 // Verifies that all expectations on the given mock object have been
9614 // satisfied. Reports one or more Google Test non-fatal failures
9615 // and returns false if not.
9616 static bool VerifyAndClearExpectationsLocked(void* mock_obj)
9617 GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex);
9619 // Clears all ON_CALL()s set on the given mock object.
9620 static void ClearDefaultActionsLocked(void* mock_obj)
9621 GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex);
9623 // Registers a mock object and a mock method it owns.
9624 static void Register(
9625 const void* mock_obj,
9626 internal::UntypedFunctionMockerBase* mocker)
9627 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
9629 // Tells Google Mock where in the source code mock_obj is used in an
9630 // ON_CALL or EXPECT_CALL. In case mock_obj is leaked, this
9631 // information helps the user identify which object it is.
9632 static void RegisterUseByOnCallOrExpectCall(
9633 const void* mock_obj, const char* file, int line)
9634 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
9636 // Unregisters a mock method; removes the owning mock object from
9637 // the registry when the last mock method associated with it has
9638 // been unregistered. This is called only in the destructor of
9639 // FunctionMockerBase.
9640 static void UnregisterLocked(internal::UntypedFunctionMockerBase* mocker)
9641 GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex);
9644 // An abstract handle of an expectation. Useful in the .After()
9645 // clause of EXPECT_CALL() for setting the (partial) order of
9646 // expectations. The syntax:
9648 // Expectation e1 = EXPECT_CALL(...)...;
9649 // EXPECT_CALL(...).After(e1)...;
9651 // sets two expectations where the latter can only be matched after
9652 // the former has been satisfied.
9655 // - This class is copyable and has value semantics.
9656 // - Constness is shallow: a const Expectation object itself cannot
9657 // be modified, but the mutable methods of the ExpectationBase
9658 // object it references can be called via expectation_base().
9659 // - The constructors and destructor are defined out-of-line because
9660 // the Symbian WINSCW compiler wants to otherwise instantiate them
9661 // when it sees this class definition, at which point it doesn't have
9662 // ExpectationBase available yet, leading to incorrect destruction
9663 // in the linked_ptr (or compilation errors if using a checking
9665 class GTEST_API_ Expectation {
9667 // Constructs a null object that doesn't reference any expectation.
9672 // This single-argument ctor must not be explicit, in order to support the
9673 // Expectation e = EXPECT_CALL(...);
9676 // A TypedExpectation object stores its pre-requisites as
9677 // Expectation objects, and needs to call the non-const Retire()
9678 // method on the ExpectationBase objects they reference. Therefore
9679 // Expectation must receive a *non-const* reference to the
9680 // ExpectationBase object.
9681 Expectation(internal::ExpectationBase& exp); // NOLINT
9683 // The compiler-generated copy ctor and operator= work exactly as
9684 // intended, so we don't need to define our own.
9686 // Returns true iff rhs references the same expectation as this object does.
9687 bool operator==(const Expectation& rhs) const {
9688 return expectation_base_ == rhs.expectation_base_;
9691 bool operator!=(const Expectation& rhs) const { return !(*this == rhs); }
9694 friend class ExpectationSet;
9695 friend class Sequence;
9696 friend class ::testing::internal::ExpectationBase;
9697 friend class ::testing::internal::UntypedFunctionMockerBase;
9699 template <typename F>
9700 friend class ::testing::internal::FunctionMockerBase;
9702 template <typename F>
9703 friend class ::testing::internal::TypedExpectation;
9705 // This comparator is needed for putting Expectation objects into a set.
9708 bool operator()(const Expectation& lhs, const Expectation& rhs) const {
9709 return lhs.expectation_base_.get() < rhs.expectation_base_.get();
9713 typedef ::std::set<Expectation, Less> Set;
9716 const internal::linked_ptr<internal::ExpectationBase>& expectation_base);
9718 // Returns the expectation this object references.
9719 const internal::linked_ptr<internal::ExpectationBase>&
9720 expectation_base() const {
9721 return expectation_base_;
9724 // A linked_ptr that co-owns the expectation this handle references.
9725 internal::linked_ptr<internal::ExpectationBase> expectation_base_;
9728 // A set of expectation handles. Useful in the .After() clause of
9729 // EXPECT_CALL() for setting the (partial) order of expectations. The
9732 // ExpectationSet es;
9733 // es += EXPECT_CALL(...)...;
9734 // es += EXPECT_CALL(...)...;
9735 // EXPECT_CALL(...).After(es)...;
9737 // sets three expectations where the last one can only be matched
9738 // after the first two have both been satisfied.
9740 // This class is copyable and has value semantics.
9741 class ExpectationSet {
9743 // A bidirectional iterator that can read a const element in the set.
9744 typedef Expectation::Set::const_iterator const_iterator;
9746 // An object stored in the set. This is an alias of Expectation.
9747 typedef Expectation::Set::value_type value_type;
9749 // Constructs an empty set.
9752 // This single-argument ctor must not be explicit, in order to support the
9753 // ExpectationSet es = EXPECT_CALL(...);
9755 ExpectationSet(internal::ExpectationBase& exp) { // NOLINT
9756 *this += Expectation(exp);
9759 // This single-argument ctor implements implicit conversion from
9760 // Expectation and thus must not be explicit. This allows either an
9761 // Expectation or an ExpectationSet to be used in .After().
9762 ExpectationSet(const Expectation& e) { // NOLINT
9766 // The compiler-generator ctor and operator= works exactly as
9767 // intended, so we don't need to define our own.
9769 // Returns true iff rhs contains the same set of Expectation objects
9771 bool operator==(const ExpectationSet& rhs) const {
9772 return expectations_ == rhs.expectations_;
9775 bool operator!=(const ExpectationSet& rhs) const { return !(*this == rhs); }
9777 // Implements the syntax
9778 // expectation_set += EXPECT_CALL(...);
9779 ExpectationSet& operator+=(const Expectation& e) {
9780 expectations_.insert(e);
9784 int size() const { return static_cast<int>(expectations_.size()); }
9786 const_iterator begin() const { return expectations_.begin(); }
9787 const_iterator end() const { return expectations_.end(); }
9790 Expectation::Set expectations_;
9794 // Sequence objects are used by a user to specify the relative order
9795 // in which the expectations should match. They are copyable (we rely
9796 // on the compiler-defined copy constructor and assignment operator).
9797 class GTEST_API_ Sequence {
9799 // Constructs an empty sequence.
9800 Sequence() : last_expectation_(new Expectation) {}
9802 // Adds an expectation to this sequence. The caller must ensure
9803 // that no other thread is accessing this Sequence object.
9804 void AddExpectation(const Expectation& expectation) const;
9807 // The last expectation in this sequence. We use a linked_ptr here
9808 // because Sequence objects are copyable and we want the copies to
9809 // be aliases. The linked_ptr allows the copies to co-own and share
9810 // the same Expectation object.
9811 internal::linked_ptr<Expectation> last_expectation_;
9812 }; // class Sequence
9814 // An object of this type causes all EXPECT_CALL() statements
9815 // encountered in its scope to be put in an anonymous sequence. The
9816 // work is done in the constructor and destructor. You should only
9817 // create an InSequence object on the stack.
9819 // The sole purpose for this class is to support easy definition of
9820 // sequential expectations, e.g.
9823 // InSequence dummy; // The name of the object doesn't matter.
9825 // // The following expectations must match in the order they appear.
9826 // EXPECT_CALL(a, Bar())...;
9827 // EXPECT_CALL(a, Baz())...;
9829 // EXPECT_CALL(b, Xyz())...;
9832 // You can create InSequence objects in multiple threads, as long as
9833 // they are used to affect different mock objects. The idea is that
9834 // each thread can create and set up its own mocks as if it's the only
9835 // thread. However, for clarity of your tests we recommend you to set
9836 // up mocks in the main thread unless you have a good reason not to do
9838 class GTEST_API_ InSequence {
9843 bool sequence_created_;
9845 GTEST_DISALLOW_COPY_AND_ASSIGN_(InSequence); // NOLINT
9846 } GTEST_ATTRIBUTE_UNUSED_;
9848 namespace internal {
9850 // Points to the implicit sequence introduced by a living InSequence
9851 // object (if any) in the current thread or NULL.
9852 GTEST_API_ extern ThreadLocal<Sequence*> g_gmock_implicit_sequence;
9854 // Base class for implementing expectations.
9856 // There are two reasons for having a type-agnostic base class for
9859 // 1. We need to store collections of expectations of different
9860 // types (e.g. all pre-requisites of a particular expectation, all
9861 // expectations in a sequence). Therefore these expectation objects
9862 // must share a common base class.
9864 // 2. We can avoid binary code bloat by moving methods not depending
9865 // on the template argument of Expectation to the base class.
9867 // This class is internal and mustn't be used by user code directly.
9868 class GTEST_API_ ExpectationBase {
9870 // source_text is the EXPECT_CALL(...) source that created this Expectation.
9871 ExpectationBase(const char* file, int line, const string& source_text);
9873 virtual ~ExpectationBase();
9875 // Where in the source file was the expectation spec defined?
9876 const char* file() const { return file_; }
9877 int line() const { return line_; }
9878 const char* source_text() const { return source_text_.c_str(); }
9879 // Returns the cardinality specified in the expectation spec.
9880 const Cardinality& cardinality() const { return cardinality_; }
9882 // Describes the source file location of this expectation.
9883 void DescribeLocationTo(::std::ostream* os) const {
9884 *os << FormatFileLocation(file(), line()) << " ";
9887 // Describes how many times a function call matching this
9888 // expectation has occurred.
9889 void DescribeCallCountTo(::std::ostream* os) const
9890 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
9892 // If this mock method has an extra matcher (i.e. .With(matcher)),
9893 // describes it to the ostream.
9894 virtual void MaybeDescribeExtraMatcherTo(::std::ostream* os) = 0;
9897 friend class ::testing::Expectation;
9898 friend class UntypedFunctionMockerBase;
9901 // Don't change the order of the enum members!
9909 kRetiresOnSaturation
9912 typedef std::vector<const void*> UntypedActions;
9914 // Returns an Expectation object that references and co-owns this
9916 virtual Expectation GetHandle() = 0;
9918 // Asserts that the EXPECT_CALL() statement has the given property.
9919 void AssertSpecProperty(bool property, const string& failure_message) const {
9920 Assert(property, file_, line_, failure_message);
9923 // Expects that the EXPECT_CALL() statement has the given property.
9924 void ExpectSpecProperty(bool property, const string& failure_message) const {
9925 Expect(property, file_, line_, failure_message);
9928 // Explicitly specifies the cardinality of this expectation. Used
9929 // by the subclasses to implement the .Times() clause.
9930 void SpecifyCardinality(const Cardinality& cardinality);
9932 // Returns true iff the user specified the cardinality explicitly
9933 // using a .Times().
9934 bool cardinality_specified() const { return cardinality_specified_; }
9936 // Sets the cardinality of this expectation spec.
9937 void set_cardinality(const Cardinality& a_cardinality) {
9938 cardinality_ = a_cardinality;
9941 // The following group of methods should only be called after the
9942 // EXPECT_CALL() statement, and only when g_gmock_mutex is held by
9943 // the current thread.
9945 // Retires all pre-requisites of this expectation.
9946 void RetireAllPreRequisites()
9947 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
9949 // Returns true iff this expectation is retired.
9950 bool is_retired() const
9951 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9952 g_gmock_mutex.AssertHeld();
9956 // Retires this expectation.
9958 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9959 g_gmock_mutex.AssertHeld();
9963 // Returns true iff this expectation is satisfied.
9964 bool IsSatisfied() const
9965 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9966 g_gmock_mutex.AssertHeld();
9967 return cardinality().IsSatisfiedByCallCount(call_count_);
9970 // Returns true iff this expectation is saturated.
9971 bool IsSaturated() const
9972 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9973 g_gmock_mutex.AssertHeld();
9974 return cardinality().IsSaturatedByCallCount(call_count_);
9977 // Returns true iff this expectation is over-saturated.
9978 bool IsOverSaturated() const
9979 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9980 g_gmock_mutex.AssertHeld();
9981 return cardinality().IsOverSaturatedByCallCount(call_count_);
9984 // Returns true iff all pre-requisites of this expectation are satisfied.
9985 bool AllPrerequisitesAreSatisfied() const
9986 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
9988 // Adds unsatisfied pre-requisites of this expectation to 'result'.
9989 void FindUnsatisfiedPrerequisites(ExpectationSet* result) const
9990 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
9992 // Returns the number this expectation has been invoked.
9993 int call_count() const
9994 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9995 g_gmock_mutex.AssertHeld();
9999 // Increments the number this expectation has been invoked.
10000 void IncrementCallCount()
10001 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
10002 g_gmock_mutex.AssertHeld();
10006 // Checks the action count (i.e. the number of WillOnce() and
10007 // WillRepeatedly() clauses) against the cardinality if this hasn't
10008 // been done before. Prints a warning if there are too many or too
10010 void CheckActionCountIfNotDone() const
10011 GTEST_LOCK_EXCLUDED_(mutex_);
10013 friend class ::testing::Sequence;
10014 friend class ::testing::internal::ExpectationTester;
10016 template <typename Function>
10017 friend class TypedExpectation;
10019 // Implements the .Times() clause.
10020 void UntypedTimes(const Cardinality& a_cardinality);
10022 // This group of fields are part of the spec and won't change after
10023 // an EXPECT_CALL() statement finishes.
10024 const char* file_; // The file that contains the expectation.
10025 int line_; // The line number of the expectation.
10026 const string source_text_; // The EXPECT_CALL(...) source text.
10027 // True iff the cardinality is specified explicitly.
10028 bool cardinality_specified_;
10029 Cardinality cardinality_; // The cardinality of the expectation.
10030 // The immediate pre-requisites (i.e. expectations that must be
10031 // satisfied before this expectation can be matched) of this
10032 // expectation. We use linked_ptr in the set because we want an
10033 // Expectation object to be co-owned by its FunctionMocker and its
10034 // successors. This allows multiple mock objects to be deleted at
10035 // different times.
10036 ExpectationSet immediate_prerequisites_;
10038 // This group of fields are the current state of the expectation,
10039 // and can change as the mock function is called.
10040 int call_count_; // How many times this expectation has been invoked.
10041 bool retired_; // True iff this expectation has retired.
10042 UntypedActions untyped_actions_;
10043 bool extra_matcher_specified_;
10044 bool repeated_action_specified_; // True if a WillRepeatedly() was specified.
10045 bool retires_on_saturation_;
10046 Clause last_clause_;
10047 mutable bool action_count_checked_; // Under mutex_.
10048 mutable Mutex mutex_; // Protects action_count_checked_.
10050 GTEST_DISALLOW_ASSIGN_(ExpectationBase);
10051 }; // class ExpectationBase
10053 // Impements an expectation for the given function type.
10054 template <typename F>
10055 class TypedExpectation : public ExpectationBase {
10057 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
10058 typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple;
10059 typedef typename Function<F>::Result Result;
10061 TypedExpectation(FunctionMockerBase<F>* owner,
10062 const char* a_file, int a_line, const string& a_source_text,
10063 const ArgumentMatcherTuple& m)
10064 : ExpectationBase(a_file, a_line, a_source_text),
10067 // By default, extra_matcher_ should match anything. However,
10068 // we cannot initialize it with _ as that triggers a compiler
10069 // bug in Symbian's C++ compiler (cannot decide between two
10070 // overloaded constructors of Matcher<const ArgumentTuple&>).
10071 extra_matcher_(A<const ArgumentTuple&>()),
10072 repeated_action_(DoDefault()) {}
10074 virtual ~TypedExpectation() {
10075 // Check the validity of the action count if it hasn't been done
10076 // yet (for example, if the expectation was never used).
10077 CheckActionCountIfNotDone();
10078 for (UntypedActions::const_iterator it = untyped_actions_.begin();
10079 it != untyped_actions_.end(); ++it) {
10080 delete static_cast<const Action<F>*>(*it);
10084 // Implements the .With() clause.
10085 TypedExpectation& With(const Matcher<const ArgumentTuple&>& m) {
10086 if (last_clause_ == kWith) {
10087 ExpectSpecProperty(false,
10088 ".With() cannot appear "
10089 "more than once in an EXPECT_CALL().");
10091 ExpectSpecProperty(last_clause_ < kWith,
10092 ".With() must be the first "
10093 "clause in an EXPECT_CALL().");
10095 last_clause_ = kWith;
10097 extra_matcher_ = m;
10098 extra_matcher_specified_ = true;
10102 // Implements the .Times() clause.
10103 TypedExpectation& Times(const Cardinality& a_cardinality) {
10104 ExpectationBase::UntypedTimes(a_cardinality);
10108 // Implements the .Times() clause.
10109 TypedExpectation& Times(int n) {
10110 return Times(Exactly(n));
10113 // Implements the .InSequence() clause.
10114 TypedExpectation& InSequence(const Sequence& s) {
10115 ExpectSpecProperty(last_clause_ <= kInSequence,
10116 ".InSequence() cannot appear after .After(),"
10117 " .WillOnce(), .WillRepeatedly(), or "
10118 ".RetiresOnSaturation().");
10119 last_clause_ = kInSequence;
10121 s.AddExpectation(GetHandle());
10124 TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2) {
10125 return InSequence(s1).InSequence(s2);
10127 TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2,
10128 const Sequence& s3) {
10129 return InSequence(s1, s2).InSequence(s3);
10131 TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2,
10132 const Sequence& s3, const Sequence& s4) {
10133 return InSequence(s1, s2, s3).InSequence(s4);
10135 TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2,
10136 const Sequence& s3, const Sequence& s4,
10137 const Sequence& s5) {
10138 return InSequence(s1, s2, s3, s4).InSequence(s5);
10141 // Implements that .After() clause.
10142 TypedExpectation& After(const ExpectationSet& s) {
10143 ExpectSpecProperty(last_clause_ <= kAfter,
10144 ".After() cannot appear after .WillOnce(),"
10145 " .WillRepeatedly(), or "
10146 ".RetiresOnSaturation().");
10147 last_clause_ = kAfter;
10149 for (ExpectationSet::const_iterator it = s.begin(); it != s.end(); ++it) {
10150 immediate_prerequisites_ += *it;
10154 TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2) {
10155 return After(s1).After(s2);
10157 TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2,
10158 const ExpectationSet& s3) {
10159 return After(s1, s2).After(s3);
10161 TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2,
10162 const ExpectationSet& s3, const ExpectationSet& s4) {
10163 return After(s1, s2, s3).After(s4);
10165 TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2,
10166 const ExpectationSet& s3, const ExpectationSet& s4,
10167 const ExpectationSet& s5) {
10168 return After(s1, s2, s3, s4).After(s5);
10171 // Implements the .WillOnce() clause.
10172 TypedExpectation& WillOnce(const Action<F>& action) {
10173 ExpectSpecProperty(last_clause_ <= kWillOnce,
10174 ".WillOnce() cannot appear after "
10175 ".WillRepeatedly() or .RetiresOnSaturation().");
10176 last_clause_ = kWillOnce;
10178 untyped_actions_.push_back(new Action<F>(action));
10179 if (!cardinality_specified()) {
10180 set_cardinality(Exactly(static_cast<int>(untyped_actions_.size())));
10185 // Implements the .WillRepeatedly() clause.
10186 TypedExpectation& WillRepeatedly(const Action<F>& action) {
10187 if (last_clause_ == kWillRepeatedly) {
10188 ExpectSpecProperty(false,
10189 ".WillRepeatedly() cannot appear "
10190 "more than once in an EXPECT_CALL().");
10192 ExpectSpecProperty(last_clause_ < kWillRepeatedly,
10193 ".WillRepeatedly() cannot appear "
10194 "after .RetiresOnSaturation().");
10196 last_clause_ = kWillRepeatedly;
10197 repeated_action_specified_ = true;
10199 repeated_action_ = action;
10200 if (!cardinality_specified()) {
10201 set_cardinality(AtLeast(static_cast<int>(untyped_actions_.size())));
10204 // Now that no more action clauses can be specified, we check
10205 // whether their count makes sense.
10206 CheckActionCountIfNotDone();
10210 // Implements the .RetiresOnSaturation() clause.
10211 TypedExpectation& RetiresOnSaturation() {
10212 ExpectSpecProperty(last_clause_ < kRetiresOnSaturation,
10213 ".RetiresOnSaturation() cannot appear "
10214 "more than once.");
10215 last_clause_ = kRetiresOnSaturation;
10216 retires_on_saturation_ = true;
10218 // Now that no more action clauses can be specified, we check
10219 // whether their count makes sense.
10220 CheckActionCountIfNotDone();
10224 // Returns the matchers for the arguments as specified inside the
10225 // EXPECT_CALL() macro.
10226 const ArgumentMatcherTuple& matchers() const {
10230 // Returns the matcher specified by the .With() clause.
10231 const Matcher<const ArgumentTuple&>& extra_matcher() const {
10232 return extra_matcher_;
10235 // Returns the action specified by the .WillRepeatedly() clause.
10236 const Action<F>& repeated_action() const { return repeated_action_; }
10238 // If this mock method has an extra matcher (i.e. .With(matcher)),
10239 // describes it to the ostream.
10240 virtual void MaybeDescribeExtraMatcherTo(::std::ostream* os) {
10241 if (extra_matcher_specified_) {
10242 *os << " Expected args: ";
10243 extra_matcher_.DescribeTo(os);
10249 template <typename Function>
10250 friend class FunctionMockerBase;
10252 // Returns an Expectation object that references and co-owns this
10254 virtual Expectation GetHandle() {
10255 return owner_->GetHandleOf(this);
10258 // The following methods will be called only after the EXPECT_CALL()
10259 // statement finishes and when the current thread holds
10262 // Returns true iff this expectation matches the given arguments.
10263 bool Matches(const ArgumentTuple& args) const
10264 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
10265 g_gmock_mutex.AssertHeld();
10266 return TupleMatches(matchers_, args) && extra_matcher_.Matches(args);
10269 // Returns true iff this expectation should handle the given arguments.
10270 bool ShouldHandleArguments(const ArgumentTuple& args) const
10271 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
10272 g_gmock_mutex.AssertHeld();
10274 // In case the action count wasn't checked when the expectation
10275 // was defined (e.g. if this expectation has no WillRepeatedly()
10276 // or RetiresOnSaturation() clause), we check it when the
10277 // expectation is used for the first time.
10278 CheckActionCountIfNotDone();
10279 return !is_retired() && AllPrerequisitesAreSatisfied() && Matches(args);
10282 // Describes the result of matching the arguments against this
10283 // expectation to the given ostream.
10284 void ExplainMatchResultTo(
10285 const ArgumentTuple& args,
10286 ::std::ostream* os) const
10287 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
10288 g_gmock_mutex.AssertHeld();
10290 if (is_retired()) {
10291 *os << " Expected: the expectation is active\n"
10292 << " Actual: it is retired\n";
10293 } else if (!Matches(args)) {
10294 if (!TupleMatches(matchers_, args)) {
10295 ExplainMatchFailureTupleTo(matchers_, args, os);
10297 StringMatchResultListener listener;
10298 if (!extra_matcher_.MatchAndExplain(args, &listener)) {
10299 *os << " Expected args: ";
10300 extra_matcher_.DescribeTo(os);
10301 *os << "\n Actual: don't match";
10303 internal::PrintIfNotEmpty(listener.str(), os);
10306 } else if (!AllPrerequisitesAreSatisfied()) {
10307 *os << " Expected: all pre-requisites are satisfied\n"
10308 << " Actual: the following immediate pre-requisites "
10309 << "are not satisfied:\n";
10310 ExpectationSet unsatisfied_prereqs;
10311 FindUnsatisfiedPrerequisites(&unsatisfied_prereqs);
10313 for (ExpectationSet::const_iterator it = unsatisfied_prereqs.begin();
10314 it != unsatisfied_prereqs.end(); ++it) {
10315 it->expectation_base()->DescribeLocationTo(os);
10316 *os << "pre-requisite #" << i++ << "\n";
10318 *os << " (end of pre-requisites)\n";
10320 // This line is here just for completeness' sake. It will never
10321 // be executed as currently the ExplainMatchResultTo() function
10322 // is called only when the mock function call does NOT match the
10324 *os << "The call matches the expectation.\n";
10328 // Returns the action that should be taken for the current invocation.
10329 const Action<F>& GetCurrentAction(
10330 const FunctionMockerBase<F>* mocker,
10331 const ArgumentTuple& args) const
10332 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
10333 g_gmock_mutex.AssertHeld();
10334 const int count = call_count();
10335 Assert(count >= 1, __FILE__, __LINE__,
10336 "call_count() is <= 0 when GetCurrentAction() is "
10337 "called - this should never happen.");
10339 const int action_count = static_cast<int>(untyped_actions_.size());
10340 if (action_count > 0 && !repeated_action_specified_ &&
10341 count > action_count) {
10342 // If there is at least one WillOnce() and no WillRepeatedly(),
10343 // we warn the user when the WillOnce() clauses ran out.
10344 ::std::stringstream ss;
10345 DescribeLocationTo(&ss);
10346 ss << "Actions ran out in " << source_text() << "...\n"
10347 << "Called " << count << " times, but only "
10348 << action_count << " WillOnce()"
10349 << (action_count == 1 ? " is" : "s are") << " specified - ";
10350 mocker->DescribeDefaultActionTo(args, &ss);
10351 Log(kWarning, ss.str(), 1);
10354 return count <= action_count ?
10355 *static_cast<const Action<F>*>(untyped_actions_[count - 1]) :
10359 // Given the arguments of a mock function call, if the call will
10360 // over-saturate this expectation, returns the default action;
10361 // otherwise, returns the next action in this expectation. Also
10362 // describes *what* happened to 'what', and explains *why* Google
10363 // Mock does it to 'why'. This method is not const as it calls
10364 // IncrementCallCount(). A return value of NULL means the default
10366 const Action<F>* GetActionForArguments(
10367 const FunctionMockerBase<F>* mocker,
10368 const ArgumentTuple& args,
10369 ::std::ostream* what,
10370 ::std::ostream* why)
10371 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
10372 g_gmock_mutex.AssertHeld();
10373 if (IsSaturated()) {
10374 // We have an excessive call.
10375 IncrementCallCount();
10376 *what << "Mock function called more times than expected - ";
10377 mocker->DescribeDefaultActionTo(args, what);
10378 DescribeCallCountTo(why);
10380 // TODO(wan@google.com): allow the user to control whether
10381 // unexpected calls should fail immediately or continue using a
10382 // flag --gmock_unexpected_calls_are_fatal.
10386 IncrementCallCount();
10387 RetireAllPreRequisites();
10389 if (retires_on_saturation_ && IsSaturated()) {
10393 // Must be done after IncrementCount()!
10394 *what << "Mock function call matches " << source_text() <<"...\n";
10395 return &(GetCurrentAction(mocker, args));
10398 // All the fields below won't change once the EXPECT_CALL()
10399 // statement finishes.
10400 FunctionMockerBase<F>* const owner_;
10401 ArgumentMatcherTuple matchers_;
10402 Matcher<const ArgumentTuple&> extra_matcher_;
10403 Action<F> repeated_action_;
10405 GTEST_DISALLOW_COPY_AND_ASSIGN_(TypedExpectation);
10406 }; // class TypedExpectation
10408 // A MockSpec object is used by ON_CALL() or EXPECT_CALL() for
10409 // specifying the default behavior of, or expectation on, a mock
10412 // Note: class MockSpec really belongs to the ::testing namespace.
10413 // However if we define it in ::testing, MSVC will complain when
10414 // classes in ::testing::internal declare it as a friend class
10415 // template. To workaround this compiler bug, we define MockSpec in
10416 // ::testing::internal and import it into ::testing.
10418 // Logs a message including file and line number information.
10419 GTEST_API_ void LogWithLocation(testing::internal::LogSeverity severity,
10420 const char* file, int line,
10421 const string& message);
10423 template <typename F>
10426 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
10427 typedef typename internal::Function<F>::ArgumentMatcherTuple
10428 ArgumentMatcherTuple;
10430 // Constructs a MockSpec object, given the function mocker object
10431 // that the spec is associated with.
10432 explicit MockSpec(internal::FunctionMockerBase<F>* function_mocker)
10433 : function_mocker_(function_mocker) {}
10435 // Adds a new default action spec to the function mocker and returns
10436 // the newly created spec.
10437 internal::OnCallSpec<F>& InternalDefaultActionSetAt(
10438 const char* file, int line, const char* obj, const char* call) {
10439 LogWithLocation(internal::kInfo, file, line,
10440 string("ON_CALL(") + obj + ", " + call + ") invoked");
10441 return function_mocker_->AddNewOnCallSpec(file, line, matchers_);
10444 // Adds a new expectation spec to the function mocker and returns
10445 // the newly created spec.
10446 internal::TypedExpectation<F>& InternalExpectedAt(
10447 const char* file, int line, const char* obj, const char* call) {
10448 const string source_text(string("EXPECT_CALL(") + obj + ", " + call + ")");
10449 LogWithLocation(internal::kInfo, file, line, source_text + " invoked");
10450 return function_mocker_->AddNewExpectation(
10451 file, line, source_text, matchers_);
10455 template <typename Function>
10456 friend class internal::FunctionMocker;
10458 void SetMatchers(const ArgumentMatcherTuple& matchers) {
10459 matchers_ = matchers;
10462 // The function mocker that owns this spec.
10463 internal::FunctionMockerBase<F>* const function_mocker_;
10464 // The argument matchers specified in the spec.
10465 ArgumentMatcherTuple matchers_;
10467 GTEST_DISALLOW_ASSIGN_(MockSpec);
10468 }; // class MockSpec
10470 // Wrapper type for generically holding an ordinary value or lvalue reference.
10471 // If T is not a reference type, it must be copyable or movable.
10472 // ReferenceOrValueWrapper<T> is movable, and will also be copyable unless
10473 // T is a move-only value type (which means that it will always be copyable
10474 // if the current platform does not support move semantics).
10476 // The primary template defines handling for values, but function header
10477 // comments describe the contract for the whole template (including
10478 // specializations).
10479 template <typename T>
10480 class ReferenceOrValueWrapper {
10482 // Constructs a wrapper from the given value/reference.
10483 explicit ReferenceOrValueWrapper(T value)
10484 : value_(::testing::internal::move(value)) {
10487 // Unwraps and returns the underlying value/reference, exactly as
10488 // originally passed. The behavior of calling this more than once on
10489 // the same object is unspecified.
10490 T Unwrap() { return ::testing::internal::move(value_); }
10492 // Provides nondestructive access to the underlying value/reference.
10493 // Always returns a const reference (more precisely,
10494 // const RemoveReference<T>&). The behavior of calling this after
10495 // calling Unwrap on the same object is unspecified.
10496 const T& Peek() const {
10504 // Specialization for lvalue reference types. See primary template
10505 // for documentation.
10506 template <typename T>
10507 class ReferenceOrValueWrapper<T&> {
10509 // Workaround for debatable pass-by-reference lint warning (c-library-team
10510 // policy precludes NOLINT in this context)
10511 typedef T& reference;
10512 explicit ReferenceOrValueWrapper(reference ref)
10513 : value_ptr_(&ref) {}
10514 T& Unwrap() { return *value_ptr_; }
10515 const T& Peek() const { return *value_ptr_; }
10521 // MSVC warns about using 'this' in base member initializer list, so
10522 // we need to temporarily disable the warning. We have to do it for
10523 // the entire class to suppress the warning, even though it's about
10524 // the constructor only.
10527 # pragma warning(push) // Saves the current warning state.
10528 # pragma warning(disable:4355) // Temporarily disables warning 4355.
10531 // C++ treats the void type specially. For example, you cannot define
10532 // a void-typed variable or pass a void value to a function.
10533 // ActionResultHolder<T> holds a value of type T, where T must be a
10534 // copyable type or void (T doesn't need to be default-constructable).
10535 // It hides the syntactic difference between void and other types, and
10536 // is used to unify the code for invoking both void-returning and
10537 // non-void-returning mock functions.
10539 // Untyped base class for ActionResultHolder<T>.
10540 class UntypedActionResultHolderBase {
10542 virtual ~UntypedActionResultHolderBase() {}
10544 // Prints the held value as an action's result to os.
10545 virtual void PrintAsActionResult(::std::ostream* os) const = 0;
10548 // This generic definition is used when T is not void.
10549 template <typename T>
10550 class ActionResultHolder : public UntypedActionResultHolderBase {
10552 // Returns the held value. Must not be called more than once.
10554 return result_.Unwrap();
10557 // Prints the held value as an action's result to os.
10558 virtual void PrintAsActionResult(::std::ostream* os) const {
10559 *os << "\n Returns: ";
10560 // T may be a reference type, so we don't use UniversalPrint().
10561 UniversalPrinter<T>::Print(result_.Peek(), os);
10564 // Performs the given mock function's default action and returns the
10565 // result in a new-ed ActionResultHolder.
10566 template <typename F>
10567 static ActionResultHolder* PerformDefaultAction(
10568 const FunctionMockerBase<F>* func_mocker,
10569 const typename Function<F>::ArgumentTuple& args,
10570 const string& call_description) {
10571 return new ActionResultHolder(Wrapper(
10572 func_mocker->PerformDefaultAction(args, call_description)));
10575 // Performs the given action and returns the result in a new-ed
10576 // ActionResultHolder.
10577 template <typename F>
10578 static ActionResultHolder*
10579 PerformAction(const Action<F>& action,
10580 const typename Function<F>::ArgumentTuple& args) {
10581 return new ActionResultHolder(Wrapper(action.Perform(args)));
10585 typedef ReferenceOrValueWrapper<T> Wrapper;
10587 explicit ActionResultHolder(Wrapper result)
10588 : result_(::testing::internal::move(result)) {
10593 GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionResultHolder);
10596 // Specialization for T = void.
10598 class ActionResultHolder<void> : public UntypedActionResultHolderBase {
10602 virtual void PrintAsActionResult(::std::ostream* /* os */) const {}
10604 // Performs the given mock function's default action and returns ownership
10605 // of an empty ActionResultHolder*.
10606 template <typename F>
10607 static ActionResultHolder* PerformDefaultAction(
10608 const FunctionMockerBase<F>* func_mocker,
10609 const typename Function<F>::ArgumentTuple& args,
10610 const string& call_description) {
10611 func_mocker->PerformDefaultAction(args, call_description);
10612 return new ActionResultHolder;
10615 // Performs the given action and returns ownership of an empty
10616 // ActionResultHolder*.
10617 template <typename F>
10618 static ActionResultHolder* PerformAction(
10619 const Action<F>& action,
10620 const typename Function<F>::ArgumentTuple& args) {
10621 action.Perform(args);
10622 return new ActionResultHolder;
10626 ActionResultHolder() {}
10627 GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionResultHolder);
10630 // The base of the function mocker class for the given function type.
10631 // We put the methods in this class instead of its child to avoid code
10633 template <typename F>
10634 class FunctionMockerBase : public UntypedFunctionMockerBase {
10636 typedef typename Function<F>::Result Result;
10637 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
10638 typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple;
10640 FunctionMockerBase() : current_spec_(this) {}
10642 // The destructor verifies that all expectations on this mock
10643 // function have been satisfied. If not, it will report Google Test
10644 // non-fatal failures for the violations.
10645 virtual ~FunctionMockerBase()
10646 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
10647 MutexLock l(&g_gmock_mutex);
10648 VerifyAndClearExpectationsLocked();
10649 Mock::UnregisterLocked(this);
10650 ClearDefaultActionsLocked();
10653 // Returns the ON_CALL spec that matches this mock function with the
10654 // given arguments; returns NULL if no matching ON_CALL is found.
10656 const OnCallSpec<F>* FindOnCallSpec(
10657 const ArgumentTuple& args) const {
10658 for (UntypedOnCallSpecs::const_reverse_iterator it
10659 = untyped_on_call_specs_.rbegin();
10660 it != untyped_on_call_specs_.rend(); ++it) {
10661 const OnCallSpec<F>* spec = static_cast<const OnCallSpec<F>*>(*it);
10662 if (spec->Matches(args))
10669 // Performs the default action of this mock function on the given
10670 // arguments and returns the result. Asserts (or throws if
10671 // exceptions are enabled) with a helpful call descrption if there
10672 // is no valid return value. This method doesn't depend on the
10673 // mutable state of this object, and thus can be called concurrently
10674 // without locking.
10676 Result PerformDefaultAction(const ArgumentTuple& args,
10677 const string& call_description) const {
10678 const OnCallSpec<F>* const spec =
10679 this->FindOnCallSpec(args);
10680 if (spec != NULL) {
10681 return spec->GetAction().Perform(args);
10683 const string message = call_description +
10684 "\n The mock function has no default action "
10685 "set, and its return type has no default value set.";
10686 #if GTEST_HAS_EXCEPTIONS
10687 if (!DefaultValue<Result>::Exists()) {
10688 throw std::runtime_error(message);
10691 Assert(DefaultValue<Result>::Exists(), "", -1, message);
10693 return DefaultValue<Result>::Get();
10696 // Performs the default action with the given arguments and returns
10697 // the action's result. The call description string will be used in
10698 // the error message to describe the call in the case the default
10699 // action fails. The caller is responsible for deleting the result.
10701 virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction(
10702 const void* untyped_args, // must point to an ArgumentTuple
10703 const string& call_description) const {
10704 const ArgumentTuple& args =
10705 *static_cast<const ArgumentTuple*>(untyped_args);
10706 return ResultHolder::PerformDefaultAction(this, args, call_description);
10709 // Performs the given action with the given arguments and returns
10710 // the action's result. The caller is responsible for deleting the
10713 virtual UntypedActionResultHolderBase* UntypedPerformAction(
10714 const void* untyped_action, const void* untyped_args) const {
10715 // Make a copy of the action before performing it, in case the
10716 // action deletes the mock object (and thus deletes itself).
10717 const Action<F> action = *static_cast<const Action<F>*>(untyped_action);
10718 const ArgumentTuple& args =
10719 *static_cast<const ArgumentTuple*>(untyped_args);
10720 return ResultHolder::PerformAction(action, args);
10723 // Implements UntypedFunctionMockerBase::ClearDefaultActionsLocked():
10724 // clears the ON_CALL()s set on this mock function.
10725 virtual void ClearDefaultActionsLocked()
10726 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
10727 g_gmock_mutex.AssertHeld();
10729 // Deleting our default actions may trigger other mock objects to be
10730 // deleted, for example if an action contains a reference counted smart
10731 // pointer to that mock object, and that is the last reference. So if we
10732 // delete our actions within the context of the global mutex we may deadlock
10733 // when this method is called again. Instead, make a copy of the set of
10734 // actions to delete, clear our set within the mutex, and then delete the
10735 // actions outside of the mutex.
10736 UntypedOnCallSpecs specs_to_delete;
10737 untyped_on_call_specs_.swap(specs_to_delete);
10739 g_gmock_mutex.Unlock();
10740 for (UntypedOnCallSpecs::const_iterator it =
10741 specs_to_delete.begin();
10742 it != specs_to_delete.end(); ++it) {
10743 delete static_cast<const OnCallSpec<F>*>(*it);
10746 // Lock the mutex again, since the caller expects it to be locked when we
10748 g_gmock_mutex.Lock();
10752 template <typename Function>
10753 friend class MockSpec;
10755 typedef ActionResultHolder<Result> ResultHolder;
10757 // Returns the result of invoking this mock function with the given
10758 // arguments. This function can be safely called from multiple
10759 // threads concurrently.
10760 Result InvokeWith(const ArgumentTuple& args)
10761 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
10762 scoped_ptr<ResultHolder> holder(
10763 DownCast_<ResultHolder*>(this->UntypedInvokeWith(&args)));
10764 return holder->Unwrap();
10767 // Adds and returns a default action spec for this mock function.
10768 OnCallSpec<F>& AddNewOnCallSpec(
10769 const char* file, int line,
10770 const ArgumentMatcherTuple& m)
10771 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
10772 Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line);
10773 OnCallSpec<F>* const on_call_spec = new OnCallSpec<F>(file, line, m);
10774 untyped_on_call_specs_.push_back(on_call_spec);
10775 return *on_call_spec;
10778 // Adds and returns an expectation spec for this mock function.
10779 TypedExpectation<F>& AddNewExpectation(
10782 const string& source_text,
10783 const ArgumentMatcherTuple& m)
10784 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
10785 Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line);
10786 TypedExpectation<F>* const expectation =
10787 new TypedExpectation<F>(this, file, line, source_text, m);
10788 const linked_ptr<ExpectationBase> untyped_expectation(expectation);
10789 untyped_expectations_.push_back(untyped_expectation);
10791 // Adds this expectation into the implicit sequence if there is one.
10792 Sequence* const implicit_sequence = g_gmock_implicit_sequence.get();
10793 if (implicit_sequence != NULL) {
10794 implicit_sequence->AddExpectation(Expectation(untyped_expectation));
10797 return *expectation;
10800 // The current spec (either default action spec or expectation spec)
10801 // being described on this function mocker.
10802 MockSpec<F>& current_spec() { return current_spec_; }
10805 template <typename Func> friend class TypedExpectation;
10807 // Some utilities needed for implementing UntypedInvokeWith().
10809 // Describes what default action will be performed for the given
10812 void DescribeDefaultActionTo(const ArgumentTuple& args,
10813 ::std::ostream* os) const {
10814 const OnCallSpec<F>* const spec = FindOnCallSpec(args);
10816 if (spec == NULL) {
10817 *os << (internal::type_equals<Result, void>::value ?
10818 "returning directly.\n" :
10819 "returning default value.\n");
10821 *os << "taking default action specified at:\n"
10822 << FormatFileLocation(spec->file(), spec->line()) << "\n";
10826 // Writes a message that the call is uninteresting (i.e. neither
10827 // explicitly expected nor explicitly unexpected) to the given
10829 virtual void UntypedDescribeUninterestingCall(
10830 const void* untyped_args,
10831 ::std::ostream* os) const
10832 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
10833 const ArgumentTuple& args =
10834 *static_cast<const ArgumentTuple*>(untyped_args);
10835 *os << "Uninteresting mock function call - ";
10836 DescribeDefaultActionTo(args, os);
10837 *os << " Function call: " << Name();
10838 UniversalPrint(args, os);
10841 // Returns the expectation that matches the given function arguments
10842 // (or NULL is there's no match); when a match is found,
10843 // untyped_action is set to point to the action that should be
10844 // performed (or NULL if the action is "do default"), and
10845 // is_excessive is modified to indicate whether the call exceeds the
10846 // expected number.
10848 // Critical section: We must find the matching expectation and the
10849 // corresponding action that needs to be taken in an ATOMIC
10850 // transaction. Otherwise another thread may call this mock
10851 // method in the middle and mess up the state.
10853 // However, performing the action has to be left out of the critical
10854 // section. The reason is that we have no control on what the
10855 // action does (it can invoke an arbitrary user function or even a
10856 // mock function) and excessive locking could cause a dead lock.
10857 virtual const ExpectationBase* UntypedFindMatchingExpectation(
10858 const void* untyped_args,
10859 const void** untyped_action, bool* is_excessive,
10860 ::std::ostream* what, ::std::ostream* why)
10861 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
10862 const ArgumentTuple& args =
10863 *static_cast<const ArgumentTuple*>(untyped_args);
10864 MutexLock l(&g_gmock_mutex);
10865 TypedExpectation<F>* exp = this->FindMatchingExpectationLocked(args);
10866 if (exp == NULL) { // A match wasn't found.
10867 this->FormatUnexpectedCallMessageLocked(args, what, why);
10871 // This line must be done before calling GetActionForArguments(),
10872 // which will increment the call count for *exp and thus affect
10873 // its saturation status.
10874 *is_excessive = exp->IsSaturated();
10875 const Action<F>* action = exp->GetActionForArguments(this, args, what, why);
10876 if (action != NULL && action->IsDoDefault())
10877 action = NULL; // Normalize "do default" to NULL.
10878 *untyped_action = action;
10882 // Prints the given function arguments to the ostream.
10883 virtual void UntypedPrintArgs(const void* untyped_args,
10884 ::std::ostream* os) const {
10885 const ArgumentTuple& args =
10886 *static_cast<const ArgumentTuple*>(untyped_args);
10887 UniversalPrint(args, os);
10890 // Returns the expectation that matches the arguments, or NULL if no
10891 // expectation matches them.
10892 TypedExpectation<F>* FindMatchingExpectationLocked(
10893 const ArgumentTuple& args) const
10894 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
10895 g_gmock_mutex.AssertHeld();
10896 for (typename UntypedExpectations::const_reverse_iterator it =
10897 untyped_expectations_.rbegin();
10898 it != untyped_expectations_.rend(); ++it) {
10899 TypedExpectation<F>* const exp =
10900 static_cast<TypedExpectation<F>*>(it->get());
10901 if (exp->ShouldHandleArguments(args)) {
10908 // Returns a message that the arguments don't match any expectation.
10909 void FormatUnexpectedCallMessageLocked(
10910 const ArgumentTuple& args,
10911 ::std::ostream* os,
10912 ::std::ostream* why) const
10913 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
10914 g_gmock_mutex.AssertHeld();
10915 *os << "\nUnexpected mock function call - ";
10916 DescribeDefaultActionTo(args, os);
10917 PrintTriedExpectationsLocked(args, why);
10920 // Prints a list of expectations that have been tried against the
10921 // current mock function call.
10922 void PrintTriedExpectationsLocked(
10923 const ArgumentTuple& args,
10924 ::std::ostream* why) const
10925 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
10926 g_gmock_mutex.AssertHeld();
10927 const int count = static_cast<int>(untyped_expectations_.size());
10928 *why << "Google Mock tried the following " << count << " "
10929 << (count == 1 ? "expectation, but it didn't match" :
10930 "expectations, but none matched")
10932 for (int i = 0; i < count; i++) {
10933 TypedExpectation<F>* const expectation =
10934 static_cast<TypedExpectation<F>*>(untyped_expectations_[i].get());
10936 expectation->DescribeLocationTo(why);
10938 *why << "tried expectation #" << i << ": ";
10940 *why << expectation->source_text() << "...\n";
10941 expectation->ExplainMatchResultTo(args, why);
10942 expectation->DescribeCallCountTo(why);
10946 // The current spec (either default action spec or expectation spec)
10947 // being described on this function mocker.
10948 MockSpec<F> current_spec_;
10950 // There is no generally useful and implementable semantics of
10951 // copying a mock object, so copying a mock is usually a user error.
10952 // Thus we disallow copying function mockers. If the user really
10953 // wants to copy a mock object, he should implement his own copy
10954 // operation, for example:
10956 // class MockFoo : public Foo {
10958 // // Defines a copy constructor explicitly.
10959 // MockFoo(const MockFoo& src) {}
10962 GTEST_DISALLOW_COPY_AND_ASSIGN_(FunctionMockerBase);
10963 }; // class FunctionMockerBase
10966 # pragma warning(pop) // Restores the warning state.
10969 // Implements methods of FunctionMockerBase.
10971 // Verifies that all expectations on this mock function have been
10972 // satisfied. Reports one or more Google Test non-fatal failures and
10973 // returns false if not.
10975 // Reports an uninteresting call (whose description is in msg) in the
10976 // manner specified by 'reaction'.
10977 void ReportUninterestingCall(CallReaction reaction, const string& msg);
10979 } // namespace internal
10981 // The style guide prohibits "using" statements in a namespace scope
10982 // inside a header file. However, the MockSpec class template is
10983 // meant to be defined in the ::testing namespace. The following line
10984 // is just a trick for working around a bug in MSVC 8.0, which cannot
10985 // handle it if we define MockSpec in ::testing.
10986 using internal::MockSpec;
10988 // Const(x) is a convenient function for obtaining a const reference
10989 // to x. This is useful for setting expectations on an overloaded
10990 // const mock method, e.g.
10992 // class MockFoo : public FooInterface {
10994 // MOCK_METHOD0(Bar, int());
10995 // MOCK_CONST_METHOD0(Bar, int&());
10999 // // Expects a call to non-const MockFoo::Bar().
11000 // EXPECT_CALL(foo, Bar());
11001 // // Expects a call to const MockFoo::Bar().
11002 // EXPECT_CALL(Const(foo), Bar());
11003 template <typename T>
11004 inline const T& Const(const T& x) { return x; }
11006 // Constructs an Expectation object that references and co-owns exp.
11007 inline Expectation::Expectation(internal::ExpectationBase& exp) // NOLINT
11008 : expectation_base_(exp.GetHandle().expectation_base()) {}
11010 } // namespace testing
11012 // A separate macro is required to avoid compile errors when the name
11013 // of the method used in call is a result of macro expansion.
11014 // See CompilesWithMethodNameExpandedFromMacro tests in
11015 // internal/gmock-spec-builders_test.cc for more details.
11016 #define GMOCK_ON_CALL_IMPL_(obj, call) \
11017 ((obj).gmock_##call).InternalDefaultActionSetAt(__FILE__, __LINE__, \
11019 #define ON_CALL(obj, call) GMOCK_ON_CALL_IMPL_(obj, call)
11021 #define GMOCK_EXPECT_CALL_IMPL_(obj, call) \
11022 ((obj).gmock_##call).InternalExpectedAt(__FILE__, __LINE__, #obj, #call)
11023 #define EXPECT_CALL(obj, call) GMOCK_EXPECT_CALL_IMPL_(obj, call)
11025 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_
11027 #if GTEST_HAS_STD_FUNCTION_
11028 # include <functional>
11031 namespace testing {
11032 namespace internal {
11034 template <typename F>
11035 class FunctionMockerBase;
11037 // Note: class FunctionMocker really belongs to the ::testing
11038 // namespace. However if we define it in ::testing, MSVC will
11039 // complain when classes in ::testing::internal declare it as a
11040 // friend class template. To workaround this compiler bug, we define
11041 // FunctionMocker in ::testing::internal and import it into ::testing.
11042 template <typename F>
11043 class FunctionMocker;
11045 template <typename R>
11046 class FunctionMocker<R()> : public
11047 internal::FunctionMockerBase<R()> {
11050 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
11052 MockSpec<F>& With() {
11053 return this->current_spec();
11057 // Even though gcc and MSVC don't enforce it, 'this->' is required
11058 // by the C++ standard [14.6.4] here, as the base class type is
11059 // dependent on the template argument (and thus shouldn't be
11060 // looked into when resolving InvokeWith).
11061 return this->InvokeWith(ArgumentTuple());
11065 template <typename R, typename A1>
11066 class FunctionMocker<R(A1)> : public
11067 internal::FunctionMockerBase<R(A1)> {
11070 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
11072 MockSpec<F>& With(const Matcher<A1>& m1) {
11073 this->current_spec().SetMatchers(::testing::make_tuple(m1));
11074 return this->current_spec();
11078 // Even though gcc and MSVC don't enforce it, 'this->' is required
11079 // by the C++ standard [14.6.4] here, as the base class type is
11080 // dependent on the template argument (and thus shouldn't be
11081 // looked into when resolving InvokeWith).
11082 return this->InvokeWith(ArgumentTuple(a1));
11086 template <typename R, typename A1, typename A2>
11087 class FunctionMocker<R(A1, A2)> : public
11088 internal::FunctionMockerBase<R(A1, A2)> {
11090 typedef R F(A1, A2);
11091 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
11093 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2) {
11094 this->current_spec().SetMatchers(::testing::make_tuple(m1, m2));
11095 return this->current_spec();
11098 R Invoke(A1 a1, A2 a2) {
11099 // Even though gcc and MSVC don't enforce it, 'this->' is required
11100 // by the C++ standard [14.6.4] here, as the base class type is
11101 // dependent on the template argument (and thus shouldn't be
11102 // looked into when resolving InvokeWith).
11103 return this->InvokeWith(ArgumentTuple(a1, a2));
11107 template <typename R, typename A1, typename A2, typename A3>
11108 class FunctionMocker<R(A1, A2, A3)> : public
11109 internal::FunctionMockerBase<R(A1, A2, A3)> {
11111 typedef R F(A1, A2, A3);
11112 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
11114 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
11115 const Matcher<A3>& m3) {
11116 this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3));
11117 return this->current_spec();
11120 R Invoke(A1 a1, A2 a2, A3 a3) {
11121 // Even though gcc and MSVC don't enforce it, 'this->' is required
11122 // by the C++ standard [14.6.4] here, as the base class type is
11123 // dependent on the template argument (and thus shouldn't be
11124 // looked into when resolving InvokeWith).
11125 return this->InvokeWith(ArgumentTuple(a1, a2, a3));
11129 template <typename R, typename A1, typename A2, typename A3, typename A4>
11130 class FunctionMocker<R(A1, A2, A3, A4)> : public
11131 internal::FunctionMockerBase<R(A1, A2, A3, A4)> {
11133 typedef R F(A1, A2, A3, A4);
11134 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
11136 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
11137 const Matcher<A3>& m3, const Matcher<A4>& m4) {
11138 this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3, m4));
11139 return this->current_spec();
11142 R Invoke(A1 a1, A2 a2, A3 a3, A4 a4) {
11143 // Even though gcc and MSVC don't enforce it, 'this->' is required
11144 // by the C++ standard [14.6.4] here, as the base class type is
11145 // dependent on the template argument (and thus shouldn't be
11146 // looked into when resolving InvokeWith).
11147 return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4));
11151 template <typename R, typename A1, typename A2, typename A3, typename A4,
11153 class FunctionMocker<R(A1, A2, A3, A4, A5)> : public
11154 internal::FunctionMockerBase<R(A1, A2, A3, A4, A5)> {
11156 typedef R F(A1, A2, A3, A4, A5);
11157 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
11159 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
11160 const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5) {
11161 this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3, m4, m5));
11162 return this->current_spec();
11165 R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) {
11166 // Even though gcc and MSVC don't enforce it, 'this->' is required
11167 // by the C++ standard [14.6.4] here, as the base class type is
11168 // dependent on the template argument (and thus shouldn't be
11169 // looked into when resolving InvokeWith).
11170 return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5));
11174 template <typename R, typename A1, typename A2, typename A3, typename A4,
11175 typename A5, typename A6>
11176 class FunctionMocker<R(A1, A2, A3, A4, A5, A6)> : public
11177 internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6)> {
11179 typedef R F(A1, A2, A3, A4, A5, A6);
11180 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
11182 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
11183 const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5,
11184 const Matcher<A6>& m6) {
11185 this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3, m4, m5,
11187 return this->current_spec();
11190 R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) {
11191 // Even though gcc and MSVC don't enforce it, 'this->' is required
11192 // by the C++ standard [14.6.4] here, as the base class type is
11193 // dependent on the template argument (and thus shouldn't be
11194 // looked into when resolving InvokeWith).
11195 return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6));
11199 template <typename R, typename A1, typename A2, typename A3, typename A4,
11200 typename A5, typename A6, typename A7>
11201 class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7)> : public
11202 internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6, A7)> {
11204 typedef R F(A1, A2, A3, A4, A5, A6, A7);
11205 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
11207 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
11208 const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5,
11209 const Matcher<A6>& m6, const Matcher<A7>& m7) {
11210 this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3, m4, m5,
11212 return this->current_spec();
11215 R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) {
11216 // Even though gcc and MSVC don't enforce it, 'this->' is required
11217 // by the C++ standard [14.6.4] here, as the base class type is
11218 // dependent on the template argument (and thus shouldn't be
11219 // looked into when resolving InvokeWith).
11220 return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7));
11224 template <typename R, typename A1, typename A2, typename A3, typename A4,
11225 typename A5, typename A6, typename A7, typename A8>
11226 class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8)> : public
11227 internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6, A7, A8)> {
11229 typedef R F(A1, A2, A3, A4, A5, A6, A7, A8);
11230 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
11232 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
11233 const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5,
11234 const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8) {
11235 this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3, m4, m5,
11237 return this->current_spec();
11240 R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) {
11241 // Even though gcc and MSVC don't enforce it, 'this->' is required
11242 // by the C++ standard [14.6.4] here, as the base class type is
11243 // dependent on the template argument (and thus shouldn't be
11244 // looked into when resolving InvokeWith).
11245 return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8));
11249 template <typename R, typename A1, typename A2, typename A3, typename A4,
11250 typename A5, typename A6, typename A7, typename A8, typename A9>
11251 class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> : public
11252 internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> {
11254 typedef R F(A1, A2, A3, A4, A5, A6, A7, A8, A9);
11255 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
11257 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
11258 const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5,
11259 const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8,
11260 const Matcher<A9>& m9) {
11261 this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3, m4, m5,
11263 return this->current_spec();
11266 R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) {
11267 // Even though gcc and MSVC don't enforce it, 'this->' is required
11268 // by the C++ standard [14.6.4] here, as the base class type is
11269 // dependent on the template argument (and thus shouldn't be
11270 // looked into when resolving InvokeWith).
11271 return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8, a9));
11275 template <typename R, typename A1, typename A2, typename A3, typename A4,
11276 typename A5, typename A6, typename A7, typename A8, typename A9,
11278 class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> : public
11279 internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> {
11281 typedef R F(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10);
11282 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
11284 MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
11285 const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5,
11286 const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8,
11287 const Matcher<A9>& m9, const Matcher<A10>& m10) {
11288 this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3, m4, m5,
11289 m6, m7, m8, m9, m10));
11290 return this->current_spec();
11293 R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9,
11295 // Even though gcc and MSVC don't enforce it, 'this->' is required
11296 // by the C++ standard [14.6.4] here, as the base class type is
11297 // dependent on the template argument (and thus shouldn't be
11298 // looked into when resolving InvokeWith).
11299 return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8, a9,
11304 } // namespace internal
11306 // The style guide prohibits "using" statements in a namespace scope
11307 // inside a header file. However, the FunctionMocker class template
11308 // is meant to be defined in the ::testing namespace. The following
11309 // line is just a trick for working around a bug in MSVC 8.0, which
11310 // cannot handle it if we define FunctionMocker in ::testing.
11311 using internal::FunctionMocker;
11313 // GMOCK_RESULT_(tn, F) expands to the result type of function type F.
11314 // We define this as a variadic macro in case F contains unprotected
11315 // commas (the same reason that we use variadic macros in other places
11317 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
11318 #define GMOCK_RESULT_(tn, ...) \
11319 tn ::testing::internal::Function<__VA_ARGS__>::Result
11321 // The type of argument N of the given function type.
11322 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
11323 #define GMOCK_ARG_(tn, N, ...) \
11324 tn ::testing::internal::Function<__VA_ARGS__>::Argument##N
11326 // The matcher type for argument N of the given function type.
11327 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
11328 #define GMOCK_MATCHER_(tn, N, ...) \
11329 const ::testing::Matcher<GMOCK_ARG_(tn, N, __VA_ARGS__)>&
11331 // The variable for mocking the given method.
11332 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
11333 #define GMOCK_MOCKER_(arity, constness, Method) \
11334 GTEST_CONCAT_TOKEN_(gmock##constness##arity##_##Method##_, __LINE__)
11336 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
11337 #define GMOCK_METHOD0_(tn, constness, ct, Method, ...) \
11338 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
11340 GTEST_COMPILE_ASSERT_((::testing::tuple_size< \
11341 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
11343 this_method_does_not_take_0_arguments); \
11344 GMOCK_MOCKER_(0, constness, Method).SetOwnerAndName(this, #Method); \
11345 return GMOCK_MOCKER_(0, constness, Method).Invoke(); \
11347 ::testing::MockSpec<__VA_ARGS__>& \
11348 gmock_##Method() constness { \
11349 GMOCK_MOCKER_(0, constness, Method).RegisterOwner(this); \
11350 return GMOCK_MOCKER_(0, constness, Method).With(); \
11352 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(0, constness, \
11355 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
11356 #define GMOCK_METHOD1_(tn, constness, ct, Method, ...) \
11357 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
11358 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1) constness { \
11359 GTEST_COMPILE_ASSERT_((::testing::tuple_size< \
11360 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
11362 this_method_does_not_take_1_argument); \
11363 GMOCK_MOCKER_(1, constness, Method).SetOwnerAndName(this, #Method); \
11364 return GMOCK_MOCKER_(1, constness, Method).Invoke(gmock_a1); \
11366 ::testing::MockSpec<__VA_ARGS__>& \
11367 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1) constness { \
11368 GMOCK_MOCKER_(1, constness, Method).RegisterOwner(this); \
11369 return GMOCK_MOCKER_(1, constness, Method).With(gmock_a1); \
11371 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(1, constness, \
11374 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
11375 #define GMOCK_METHOD2_(tn, constness, ct, Method, ...) \
11376 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
11377 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
11378 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2) constness { \
11379 GTEST_COMPILE_ASSERT_((::testing::tuple_size< \
11380 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
11382 this_method_does_not_take_2_arguments); \
11383 GMOCK_MOCKER_(2, constness, Method).SetOwnerAndName(this, #Method); \
11384 return GMOCK_MOCKER_(2, constness, Method).Invoke(gmock_a1, gmock_a2); \
11386 ::testing::MockSpec<__VA_ARGS__>& \
11387 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
11388 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2) constness { \
11389 GMOCK_MOCKER_(2, constness, Method).RegisterOwner(this); \
11390 return GMOCK_MOCKER_(2, constness, Method).With(gmock_a1, gmock_a2); \
11392 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(2, constness, \
11395 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
11396 #define GMOCK_METHOD3_(tn, constness, ct, Method, ...) \
11397 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
11398 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
11399 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
11400 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3) constness { \
11401 GTEST_COMPILE_ASSERT_((::testing::tuple_size< \
11402 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
11404 this_method_does_not_take_3_arguments); \
11405 GMOCK_MOCKER_(3, constness, Method).SetOwnerAndName(this, #Method); \
11406 return GMOCK_MOCKER_(3, constness, Method).Invoke(gmock_a1, gmock_a2, \
11409 ::testing::MockSpec<__VA_ARGS__>& \
11410 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
11411 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
11412 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3) constness { \
11413 GMOCK_MOCKER_(3, constness, Method).RegisterOwner(this); \
11414 return GMOCK_MOCKER_(3, constness, Method).With(gmock_a1, gmock_a2, \
11417 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(3, constness, \
11420 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
11421 #define GMOCK_METHOD4_(tn, constness, ct, Method, ...) \
11422 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
11423 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
11424 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
11425 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
11426 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4) constness { \
11427 GTEST_COMPILE_ASSERT_((::testing::tuple_size< \
11428 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
11430 this_method_does_not_take_4_arguments); \
11431 GMOCK_MOCKER_(4, constness, Method).SetOwnerAndName(this, #Method); \
11432 return GMOCK_MOCKER_(4, constness, Method).Invoke(gmock_a1, gmock_a2, \
11433 gmock_a3, gmock_a4); \
11435 ::testing::MockSpec<__VA_ARGS__>& \
11436 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
11437 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
11438 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
11439 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4) constness { \
11440 GMOCK_MOCKER_(4, constness, Method).RegisterOwner(this); \
11441 return GMOCK_MOCKER_(4, constness, Method).With(gmock_a1, gmock_a2, \
11442 gmock_a3, gmock_a4); \
11444 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(4, constness, \
11447 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
11448 #define GMOCK_METHOD5_(tn, constness, ct, Method, ...) \
11449 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
11450 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
11451 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
11452 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
11453 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \
11454 GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5) constness { \
11455 GTEST_COMPILE_ASSERT_((::testing::tuple_size< \
11456 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
11458 this_method_does_not_take_5_arguments); \
11459 GMOCK_MOCKER_(5, constness, Method).SetOwnerAndName(this, #Method); \
11460 return GMOCK_MOCKER_(5, constness, Method).Invoke(gmock_a1, gmock_a2, \
11461 gmock_a3, gmock_a4, gmock_a5); \
11463 ::testing::MockSpec<__VA_ARGS__>& \
11464 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
11465 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
11466 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
11467 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
11468 GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5) constness { \
11469 GMOCK_MOCKER_(5, constness, Method).RegisterOwner(this); \
11470 return GMOCK_MOCKER_(5, constness, Method).With(gmock_a1, gmock_a2, \
11471 gmock_a3, gmock_a4, gmock_a5); \
11473 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(5, constness, \
11476 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
11477 #define GMOCK_METHOD6_(tn, constness, ct, Method, ...) \
11478 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
11479 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
11480 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
11481 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
11482 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \
11483 GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \
11484 GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6) constness { \
11485 GTEST_COMPILE_ASSERT_((::testing::tuple_size< \
11486 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
11488 this_method_does_not_take_6_arguments); \
11489 GMOCK_MOCKER_(6, constness, Method).SetOwnerAndName(this, #Method); \
11490 return GMOCK_MOCKER_(6, constness, Method).Invoke(gmock_a1, gmock_a2, \
11491 gmock_a3, gmock_a4, gmock_a5, gmock_a6); \
11493 ::testing::MockSpec<__VA_ARGS__>& \
11494 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
11495 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
11496 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
11497 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
11498 GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \
11499 GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6) constness { \
11500 GMOCK_MOCKER_(6, constness, Method).RegisterOwner(this); \
11501 return GMOCK_MOCKER_(6, constness, Method).With(gmock_a1, gmock_a2, \
11502 gmock_a3, gmock_a4, gmock_a5, gmock_a6); \
11504 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(6, constness, \
11507 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
11508 #define GMOCK_METHOD7_(tn, constness, ct, Method, ...) \
11509 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
11510 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
11511 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
11512 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
11513 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \
11514 GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \
11515 GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
11516 GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7) constness { \
11517 GTEST_COMPILE_ASSERT_((::testing::tuple_size< \
11518 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
11520 this_method_does_not_take_7_arguments); \
11521 GMOCK_MOCKER_(7, constness, Method).SetOwnerAndName(this, #Method); \
11522 return GMOCK_MOCKER_(7, constness, Method).Invoke(gmock_a1, gmock_a2, \
11523 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7); \
11525 ::testing::MockSpec<__VA_ARGS__>& \
11526 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
11527 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
11528 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
11529 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
11530 GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \
11531 GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \
11532 GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7) constness { \
11533 GMOCK_MOCKER_(7, constness, Method).RegisterOwner(this); \
11534 return GMOCK_MOCKER_(7, constness, Method).With(gmock_a1, gmock_a2, \
11535 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7); \
11537 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(7, constness, \
11540 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
11541 #define GMOCK_METHOD8_(tn, constness, ct, Method, ...) \
11542 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
11543 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
11544 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
11545 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
11546 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \
11547 GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \
11548 GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
11549 GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \
11550 GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8) constness { \
11551 GTEST_COMPILE_ASSERT_((::testing::tuple_size< \
11552 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
11554 this_method_does_not_take_8_arguments); \
11555 GMOCK_MOCKER_(8, constness, Method).SetOwnerAndName(this, #Method); \
11556 return GMOCK_MOCKER_(8, constness, Method).Invoke(gmock_a1, gmock_a2, \
11557 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8); \
11559 ::testing::MockSpec<__VA_ARGS__>& \
11560 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
11561 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
11562 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
11563 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
11564 GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \
11565 GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \
11566 GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \
11567 GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8) constness { \
11568 GMOCK_MOCKER_(8, constness, Method).RegisterOwner(this); \
11569 return GMOCK_MOCKER_(8, constness, Method).With(gmock_a1, gmock_a2, \
11570 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8); \
11572 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(8, constness, \
11575 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
11576 #define GMOCK_METHOD9_(tn, constness, ct, Method, ...) \
11577 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
11578 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
11579 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
11580 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
11581 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \
11582 GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \
11583 GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
11584 GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \
11585 GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8, \
11586 GMOCK_ARG_(tn, 9, __VA_ARGS__) gmock_a9) constness { \
11587 GTEST_COMPILE_ASSERT_((::testing::tuple_size< \
11588 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
11590 this_method_does_not_take_9_arguments); \
11591 GMOCK_MOCKER_(9, constness, Method).SetOwnerAndName(this, #Method); \
11592 return GMOCK_MOCKER_(9, constness, Method).Invoke(gmock_a1, gmock_a2, \
11593 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, \
11596 ::testing::MockSpec<__VA_ARGS__>& \
11597 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
11598 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
11599 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
11600 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
11601 GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \
11602 GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \
11603 GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \
11604 GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8, \
11605 GMOCK_MATCHER_(tn, 9, __VA_ARGS__) gmock_a9) constness { \
11606 GMOCK_MOCKER_(9, constness, Method).RegisterOwner(this); \
11607 return GMOCK_MOCKER_(9, constness, Method).With(gmock_a1, gmock_a2, \
11608 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, \
11611 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(9, constness, \
11614 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
11615 #define GMOCK_METHOD10_(tn, constness, ct, Method, ...) \
11616 GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
11617 GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
11618 GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
11619 GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
11620 GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \
11621 GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \
11622 GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
11623 GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \
11624 GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8, \
11625 GMOCK_ARG_(tn, 9, __VA_ARGS__) gmock_a9, \
11626 GMOCK_ARG_(tn, 10, __VA_ARGS__) gmock_a10) constness { \
11627 GTEST_COMPILE_ASSERT_((::testing::tuple_size< \
11628 tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
11630 this_method_does_not_take_10_arguments); \
11631 GMOCK_MOCKER_(10, constness, Method).SetOwnerAndName(this, #Method); \
11632 return GMOCK_MOCKER_(10, constness, Method).Invoke(gmock_a1, gmock_a2, \
11633 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, gmock_a9, \
11636 ::testing::MockSpec<__VA_ARGS__>& \
11637 gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
11638 GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
11639 GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
11640 GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
11641 GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \
11642 GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \
11643 GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \
11644 GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8, \
11645 GMOCK_MATCHER_(tn, 9, __VA_ARGS__) gmock_a9, \
11646 GMOCK_MATCHER_(tn, 10, \
11647 __VA_ARGS__) gmock_a10) constness { \
11648 GMOCK_MOCKER_(10, constness, Method).RegisterOwner(this); \
11649 return GMOCK_MOCKER_(10, constness, Method).With(gmock_a1, gmock_a2, \
11650 gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, gmock_a9, \
11653 mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(10, constness, \
11656 #define MOCK_METHOD0(m, ...) GMOCK_METHOD0_(, , , m, __VA_ARGS__)
11657 #define MOCK_METHOD1(m, ...) GMOCK_METHOD1_(, , , m, __VA_ARGS__)
11658 #define MOCK_METHOD2(m, ...) GMOCK_METHOD2_(, , , m, __VA_ARGS__)
11659 #define MOCK_METHOD3(m, ...) GMOCK_METHOD3_(, , , m, __VA_ARGS__)
11660 #define MOCK_METHOD4(m, ...) GMOCK_METHOD4_(, , , m, __VA_ARGS__)
11661 #define MOCK_METHOD5(m, ...) GMOCK_METHOD5_(, , , m, __VA_ARGS__)
11662 #define MOCK_METHOD6(m, ...) GMOCK_METHOD6_(, , , m, __VA_ARGS__)
11663 #define MOCK_METHOD7(m, ...) GMOCK_METHOD7_(, , , m, __VA_ARGS__)
11664 #define MOCK_METHOD8(m, ...) GMOCK_METHOD8_(, , , m, __VA_ARGS__)
11665 #define MOCK_METHOD9(m, ...) GMOCK_METHOD9_(, , , m, __VA_ARGS__)
11666 #define MOCK_METHOD10(m, ...) GMOCK_METHOD10_(, , , m, __VA_ARGS__)
11668 #define MOCK_CONST_METHOD0(m, ...) GMOCK_METHOD0_(, const, , m, __VA_ARGS__)
11669 #define MOCK_CONST_METHOD1(m, ...) GMOCK_METHOD1_(, const, , m, __VA_ARGS__)
11670 #define MOCK_CONST_METHOD2(m, ...) GMOCK_METHOD2_(, const, , m, __VA_ARGS__)
11671 #define MOCK_CONST_METHOD3(m, ...) GMOCK_METHOD3_(, const, , m, __VA_ARGS__)
11672 #define MOCK_CONST_METHOD4(m, ...) GMOCK_METHOD4_(, const, , m, __VA_ARGS__)
11673 #define MOCK_CONST_METHOD5(m, ...) GMOCK_METHOD5_(, const, , m, __VA_ARGS__)
11674 #define MOCK_CONST_METHOD6(m, ...) GMOCK_METHOD6_(, const, , m, __VA_ARGS__)
11675 #define MOCK_CONST_METHOD7(m, ...) GMOCK_METHOD7_(, const, , m, __VA_ARGS__)
11676 #define MOCK_CONST_METHOD8(m, ...) GMOCK_METHOD8_(, const, , m, __VA_ARGS__)
11677 #define MOCK_CONST_METHOD9(m, ...) GMOCK_METHOD9_(, const, , m, __VA_ARGS__)
11678 #define MOCK_CONST_METHOD10(m, ...) GMOCK_METHOD10_(, const, , m, __VA_ARGS__)
11680 #define MOCK_METHOD0_T(m, ...) GMOCK_METHOD0_(typename, , , m, __VA_ARGS__)
11681 #define MOCK_METHOD1_T(m, ...) GMOCK_METHOD1_(typename, , , m, __VA_ARGS__)
11682 #define MOCK_METHOD2_T(m, ...) GMOCK_METHOD2_(typename, , , m, __VA_ARGS__)
11683 #define MOCK_METHOD3_T(m, ...) GMOCK_METHOD3_(typename, , , m, __VA_ARGS__)
11684 #define MOCK_METHOD4_T(m, ...) GMOCK_METHOD4_(typename, , , m, __VA_ARGS__)
11685 #define MOCK_METHOD5_T(m, ...) GMOCK_METHOD5_(typename, , , m, __VA_ARGS__)
11686 #define MOCK_METHOD6_T(m, ...) GMOCK_METHOD6_(typename, , , m, __VA_ARGS__)
11687 #define MOCK_METHOD7_T(m, ...) GMOCK_METHOD7_(typename, , , m, __VA_ARGS__)
11688 #define MOCK_METHOD8_T(m, ...) GMOCK_METHOD8_(typename, , , m, __VA_ARGS__)
11689 #define MOCK_METHOD9_T(m, ...) GMOCK_METHOD9_(typename, , , m, __VA_ARGS__)
11690 #define MOCK_METHOD10_T(m, ...) GMOCK_METHOD10_(typename, , , m, __VA_ARGS__)
11692 #define MOCK_CONST_METHOD0_T(m, ...) \
11693 GMOCK_METHOD0_(typename, const, , m, __VA_ARGS__)
11694 #define MOCK_CONST_METHOD1_T(m, ...) \
11695 GMOCK_METHOD1_(typename, const, , m, __VA_ARGS__)
11696 #define MOCK_CONST_METHOD2_T(m, ...) \
11697 GMOCK_METHOD2_(typename, const, , m, __VA_ARGS__)
11698 #define MOCK_CONST_METHOD3_T(m, ...) \
11699 GMOCK_METHOD3_(typename, const, , m, __VA_ARGS__)
11700 #define MOCK_CONST_METHOD4_T(m, ...) \
11701 GMOCK_METHOD4_(typename, const, , m, __VA_ARGS__)
11702 #define MOCK_CONST_METHOD5_T(m, ...) \
11703 GMOCK_METHOD5_(typename, const, , m, __VA_ARGS__)
11704 #define MOCK_CONST_METHOD6_T(m, ...) \
11705 GMOCK_METHOD6_(typename, const, , m, __VA_ARGS__)
11706 #define MOCK_CONST_METHOD7_T(m, ...) \
11707 GMOCK_METHOD7_(typename, const, , m, __VA_ARGS__)
11708 #define MOCK_CONST_METHOD8_T(m, ...) \
11709 GMOCK_METHOD8_(typename, const, , m, __VA_ARGS__)
11710 #define MOCK_CONST_METHOD9_T(m, ...) \
11711 GMOCK_METHOD9_(typename, const, , m, __VA_ARGS__)
11712 #define MOCK_CONST_METHOD10_T(m, ...) \
11713 GMOCK_METHOD10_(typename, const, , m, __VA_ARGS__)
11715 #define MOCK_METHOD0_WITH_CALLTYPE(ct, m, ...) \
11716 GMOCK_METHOD0_(, , ct, m, __VA_ARGS__)
11717 #define MOCK_METHOD1_WITH_CALLTYPE(ct, m, ...) \
11718 GMOCK_METHOD1_(, , ct, m, __VA_ARGS__)
11719 #define MOCK_METHOD2_WITH_CALLTYPE(ct, m, ...) \
11720 GMOCK_METHOD2_(, , ct, m, __VA_ARGS__)
11721 #define MOCK_METHOD3_WITH_CALLTYPE(ct, m, ...) \
11722 GMOCK_METHOD3_(, , ct, m, __VA_ARGS__)
11723 #define MOCK_METHOD4_WITH_CALLTYPE(ct, m, ...) \
11724 GMOCK_METHOD4_(, , ct, m, __VA_ARGS__)
11725 #define MOCK_METHOD5_WITH_CALLTYPE(ct, m, ...) \
11726 GMOCK_METHOD5_(, , ct, m, __VA_ARGS__)
11727 #define MOCK_METHOD6_WITH_CALLTYPE(ct, m, ...) \
11728 GMOCK_METHOD6_(, , ct, m, __VA_ARGS__)
11729 #define MOCK_METHOD7_WITH_CALLTYPE(ct, m, ...) \
11730 GMOCK_METHOD7_(, , ct, m, __VA_ARGS__)
11731 #define MOCK_METHOD8_WITH_CALLTYPE(ct, m, ...) \
11732 GMOCK_METHOD8_(, , ct, m, __VA_ARGS__)
11733 #define MOCK_METHOD9_WITH_CALLTYPE(ct, m, ...) \
11734 GMOCK_METHOD9_(, , ct, m, __VA_ARGS__)
11735 #define MOCK_METHOD10_WITH_CALLTYPE(ct, m, ...) \
11736 GMOCK_METHOD10_(, , ct, m, __VA_ARGS__)
11738 #define MOCK_CONST_METHOD0_WITH_CALLTYPE(ct, m, ...) \
11739 GMOCK_METHOD0_(, const, ct, m, __VA_ARGS__)
11740 #define MOCK_CONST_METHOD1_WITH_CALLTYPE(ct, m, ...) \
11741 GMOCK_METHOD1_(, const, ct, m, __VA_ARGS__)
11742 #define MOCK_CONST_METHOD2_WITH_CALLTYPE(ct, m, ...) \
11743 GMOCK_METHOD2_(, const, ct, m, __VA_ARGS__)
11744 #define MOCK_CONST_METHOD3_WITH_CALLTYPE(ct, m, ...) \
11745 GMOCK_METHOD3_(, const, ct, m, __VA_ARGS__)
11746 #define MOCK_CONST_METHOD4_WITH_CALLTYPE(ct, m, ...) \
11747 GMOCK_METHOD4_(, const, ct, m, __VA_ARGS__)
11748 #define MOCK_CONST_METHOD5_WITH_CALLTYPE(ct, m, ...) \
11749 GMOCK_METHOD5_(, const, ct, m, __VA_ARGS__)
11750 #define MOCK_CONST_METHOD6_WITH_CALLTYPE(ct, m, ...) \
11751 GMOCK_METHOD6_(, const, ct, m, __VA_ARGS__)
11752 #define MOCK_CONST_METHOD7_WITH_CALLTYPE(ct, m, ...) \
11753 GMOCK_METHOD7_(, const, ct, m, __VA_ARGS__)
11754 #define MOCK_CONST_METHOD8_WITH_CALLTYPE(ct, m, ...) \
11755 GMOCK_METHOD8_(, const, ct, m, __VA_ARGS__)
11756 #define MOCK_CONST_METHOD9_WITH_CALLTYPE(ct, m, ...) \
11757 GMOCK_METHOD9_(, const, ct, m, __VA_ARGS__)
11758 #define MOCK_CONST_METHOD10_WITH_CALLTYPE(ct, m, ...) \
11759 GMOCK_METHOD10_(, const, ct, m, __VA_ARGS__)
11761 #define MOCK_METHOD0_T_WITH_CALLTYPE(ct, m, ...) \
11762 GMOCK_METHOD0_(typename, , ct, m, __VA_ARGS__)
11763 #define MOCK_METHOD1_T_WITH_CALLTYPE(ct, m, ...) \
11764 GMOCK_METHOD1_(typename, , ct, m, __VA_ARGS__)
11765 #define MOCK_METHOD2_T_WITH_CALLTYPE(ct, m, ...) \
11766 GMOCK_METHOD2_(typename, , ct, m, __VA_ARGS__)
11767 #define MOCK_METHOD3_T_WITH_CALLTYPE(ct, m, ...) \
11768 GMOCK_METHOD3_(typename, , ct, m, __VA_ARGS__)
11769 #define MOCK_METHOD4_T_WITH_CALLTYPE(ct, m, ...) \
11770 GMOCK_METHOD4_(typename, , ct, m, __VA_ARGS__)
11771 #define MOCK_METHOD5_T_WITH_CALLTYPE(ct, m, ...) \
11772 GMOCK_METHOD5_(typename, , ct, m, __VA_ARGS__)
11773 #define MOCK_METHOD6_T_WITH_CALLTYPE(ct, m, ...) \
11774 GMOCK_METHOD6_(typename, , ct, m, __VA_ARGS__)
11775 #define MOCK_METHOD7_T_WITH_CALLTYPE(ct, m, ...) \
11776 GMOCK_METHOD7_(typename, , ct, m, __VA_ARGS__)
11777 #define MOCK_METHOD8_T_WITH_CALLTYPE(ct, m, ...) \
11778 GMOCK_METHOD8_(typename, , ct, m, __VA_ARGS__)
11779 #define MOCK_METHOD9_T_WITH_CALLTYPE(ct, m, ...) \
11780 GMOCK_METHOD9_(typename, , ct, m, __VA_ARGS__)
11781 #define MOCK_METHOD10_T_WITH_CALLTYPE(ct, m, ...) \
11782 GMOCK_METHOD10_(typename, , ct, m, __VA_ARGS__)
11784 #define MOCK_CONST_METHOD0_T_WITH_CALLTYPE(ct, m, ...) \
11785 GMOCK_METHOD0_(typename, const, ct, m, __VA_ARGS__)
11786 #define MOCK_CONST_METHOD1_T_WITH_CALLTYPE(ct, m, ...) \
11787 GMOCK_METHOD1_(typename, const, ct, m, __VA_ARGS__)
11788 #define MOCK_CONST_METHOD2_T_WITH_CALLTYPE(ct, m, ...) \
11789 GMOCK_METHOD2_(typename, const, ct, m, __VA_ARGS__)
11790 #define MOCK_CONST_METHOD3_T_WITH_CALLTYPE(ct, m, ...) \
11791 GMOCK_METHOD3_(typename, const, ct, m, __VA_ARGS__)
11792 #define MOCK_CONST_METHOD4_T_WITH_CALLTYPE(ct, m, ...) \
11793 GMOCK_METHOD4_(typename, const, ct, m, __VA_ARGS__)
11794 #define MOCK_CONST_METHOD5_T_WITH_CALLTYPE(ct, m, ...) \
11795 GMOCK_METHOD5_(typename, const, ct, m, __VA_ARGS__)
11796 #define MOCK_CONST_METHOD6_T_WITH_CALLTYPE(ct, m, ...) \
11797 GMOCK_METHOD6_(typename, const, ct, m, __VA_ARGS__)
11798 #define MOCK_CONST_METHOD7_T_WITH_CALLTYPE(ct, m, ...) \
11799 GMOCK_METHOD7_(typename, const, ct, m, __VA_ARGS__)
11800 #define MOCK_CONST_METHOD8_T_WITH_CALLTYPE(ct, m, ...) \
11801 GMOCK_METHOD8_(typename, const, ct, m, __VA_ARGS__)
11802 #define MOCK_CONST_METHOD9_T_WITH_CALLTYPE(ct, m, ...) \
11803 GMOCK_METHOD9_(typename, const, ct, m, __VA_ARGS__)
11804 #define MOCK_CONST_METHOD10_T_WITH_CALLTYPE(ct, m, ...) \
11805 GMOCK_METHOD10_(typename, const, ct, m, __VA_ARGS__)
11807 // A MockFunction<F> class has one mock method whose type is F. It is
11808 // useful when you just want your test code to emit some messages and
11809 // have Google Mock verify the right messages are sent (and perhaps at
11810 // the right times). For example, if you are exercising code:
11816 // and want to verify that Foo(1) and Foo(3) both invoke
11817 // mock.Bar("a"), but Foo(2) doesn't invoke anything, you can write:
11819 // TEST(FooTest, InvokesBarCorrectly) {
11821 // MockFunction<void(string check_point_name)> check;
11825 // EXPECT_CALL(mock, Bar("a"));
11826 // EXPECT_CALL(check, Call("1"));
11827 // EXPECT_CALL(check, Call("2"));
11828 // EXPECT_CALL(mock, Bar("a"));
11831 // check.Call("1");
11833 // check.Call("2");
11837 // The expectation spec says that the first Bar("a") must happen
11838 // before check point "1", the second Bar("a") must happen after check
11839 // point "2", and nothing should happen between the two check
11840 // points. The explicit check points make it easy to tell which
11841 // Bar("a") is called by which call to Foo().
11843 // MockFunction<F> can also be used to exercise code that accepts
11844 // std::function<F> callbacks. To do so, use AsStdFunction() method
11845 // to create std::function proxy forwarding to original object's Call.
11848 // TEST(FooTest, RunsCallbackWithBarArgument) {
11849 // MockFunction<int(string)> callback;
11850 // EXPECT_CALL(callback, Call("bar")).WillOnce(Return(1));
11851 // Foo(callback.AsStdFunction());
11853 template <typename F>
11854 class MockFunction;
11856 template <typename R>
11857 class MockFunction<R()> {
11861 MOCK_METHOD0_T(Call, R());
11863 #if GTEST_HAS_STD_FUNCTION_
11864 std::function<R()> AsStdFunction() {
11865 return [this]() -> R {
11866 return this->Call();
11869 #endif // GTEST_HAS_STD_FUNCTION_
11872 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11875 template <typename R, typename A0>
11876 class MockFunction<R(A0)> {
11880 MOCK_METHOD1_T(Call, R(A0));
11882 #if GTEST_HAS_STD_FUNCTION_
11883 std::function<R(A0)> AsStdFunction() {
11884 return [this](A0 a0) -> R {
11885 return this->Call(a0);
11888 #endif // GTEST_HAS_STD_FUNCTION_
11891 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11894 template <typename R, typename A0, typename A1>
11895 class MockFunction<R(A0, A1)> {
11899 MOCK_METHOD2_T(Call, R(A0, A1));
11901 #if GTEST_HAS_STD_FUNCTION_
11902 std::function<R(A0, A1)> AsStdFunction() {
11903 return [this](A0 a0, A1 a1) -> R {
11904 return this->Call(a0, a1);
11907 #endif // GTEST_HAS_STD_FUNCTION_
11910 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11913 template <typename R, typename A0, typename A1, typename A2>
11914 class MockFunction<R(A0, A1, A2)> {
11918 MOCK_METHOD3_T(Call, R(A0, A1, A2));
11920 #if GTEST_HAS_STD_FUNCTION_
11921 std::function<R(A0, A1, A2)> AsStdFunction() {
11922 return [this](A0 a0, A1 a1, A2 a2) -> R {
11923 return this->Call(a0, a1, a2);
11926 #endif // GTEST_HAS_STD_FUNCTION_
11929 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11932 template <typename R, typename A0, typename A1, typename A2, typename A3>
11933 class MockFunction<R(A0, A1, A2, A3)> {
11937 MOCK_METHOD4_T(Call, R(A0, A1, A2, A3));
11939 #if GTEST_HAS_STD_FUNCTION_
11940 std::function<R(A0, A1, A2, A3)> AsStdFunction() {
11941 return [this](A0 a0, A1 a1, A2 a2, A3 a3) -> R {
11942 return this->Call(a0, a1, a2, a3);
11945 #endif // GTEST_HAS_STD_FUNCTION_
11948 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11951 template <typename R, typename A0, typename A1, typename A2, typename A3,
11953 class MockFunction<R(A0, A1, A2, A3, A4)> {
11957 MOCK_METHOD5_T(Call, R(A0, A1, A2, A3, A4));
11959 #if GTEST_HAS_STD_FUNCTION_
11960 std::function<R(A0, A1, A2, A3, A4)> AsStdFunction() {
11961 return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) -> R {
11962 return this->Call(a0, a1, a2, a3, a4);
11965 #endif // GTEST_HAS_STD_FUNCTION_
11968 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11971 template <typename R, typename A0, typename A1, typename A2, typename A3,
11972 typename A4, typename A5>
11973 class MockFunction<R(A0, A1, A2, A3, A4, A5)> {
11977 MOCK_METHOD6_T(Call, R(A0, A1, A2, A3, A4, A5));
11979 #if GTEST_HAS_STD_FUNCTION_
11980 std::function<R(A0, A1, A2, A3, A4, A5)> AsStdFunction() {
11981 return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) -> R {
11982 return this->Call(a0, a1, a2, a3, a4, a5);
11985 #endif // GTEST_HAS_STD_FUNCTION_
11988 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11991 template <typename R, typename A0, typename A1, typename A2, typename A3,
11992 typename A4, typename A5, typename A6>
11993 class MockFunction<R(A0, A1, A2, A3, A4, A5, A6)> {
11997 MOCK_METHOD7_T(Call, R(A0, A1, A2, A3, A4, A5, A6));
11999 #if GTEST_HAS_STD_FUNCTION_
12000 std::function<R(A0, A1, A2, A3, A4, A5, A6)> AsStdFunction() {
12001 return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) -> R {
12002 return this->Call(a0, a1, a2, a3, a4, a5, a6);
12005 #endif // GTEST_HAS_STD_FUNCTION_
12008 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
12011 template <typename R, typename A0, typename A1, typename A2, typename A3,
12012 typename A4, typename A5, typename A6, typename A7>
12013 class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7)> {
12017 MOCK_METHOD8_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7));
12019 #if GTEST_HAS_STD_FUNCTION_
12020 std::function<R(A0, A1, A2, A3, A4, A5, A6, A7)> AsStdFunction() {
12021 return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) -> R {
12022 return this->Call(a0, a1, a2, a3, a4, a5, a6, a7);
12025 #endif // GTEST_HAS_STD_FUNCTION_
12028 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
12031 template <typename R, typename A0, typename A1, typename A2, typename A3,
12032 typename A4, typename A5, typename A6, typename A7, typename A8>
12033 class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7, A8)> {
12037 MOCK_METHOD9_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7, A8));
12039 #if GTEST_HAS_STD_FUNCTION_
12040 std::function<R(A0, A1, A2, A3, A4, A5, A6, A7, A8)> AsStdFunction() {
12041 return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7,
12043 return this->Call(a0, a1, a2, a3, a4, a5, a6, a7, a8);
12046 #endif // GTEST_HAS_STD_FUNCTION_
12049 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
12052 template <typename R, typename A0, typename A1, typename A2, typename A3,
12053 typename A4, typename A5, typename A6, typename A7, typename A8,
12055 class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9)> {
12059 MOCK_METHOD10_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9));
12061 #if GTEST_HAS_STD_FUNCTION_
12062 std::function<R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9)> AsStdFunction() {
12063 return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7,
12064 A8 a8, A9 a9) -> R {
12065 return this->Call(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9);
12068 #endif // GTEST_HAS_STD_FUNCTION_
12071 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
12074 } // namespace testing
12076 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
12077 // This file was GENERATED by command:
12078 // pump.py gmock-generated-nice-strict.h.pump
12079 // DO NOT EDIT BY HAND!!!
12081 // Copyright 2008, Google Inc.
12082 // All rights reserved.
12084 // Redistribution and use in source and binary forms, with or without
12085 // modification, are permitted provided that the following conditions are
12088 // * Redistributions of source code must retain the above copyright
12089 // notice, this list of conditions and the following disclaimer.
12090 // * Redistributions in binary form must reproduce the above
12091 // copyright notice, this list of conditions and the following disclaimer
12092 // in the documentation and/or other materials provided with the
12094 // * Neither the name of Google Inc. nor the names of its
12095 // contributors may be used to endorse or promote products derived from
12096 // this software without specific prior written permission.
12098 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
12099 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
12100 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
12101 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
12102 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
12103 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
12104 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12105 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12106 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12107 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
12108 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12110 // Author: wan@google.com (Zhanyong Wan)
12112 // Implements class templates NiceMock, NaggyMock, and StrictMock.
12114 // Given a mock class MockFoo that is created using Google Mock,
12115 // NiceMock<MockFoo> is a subclass of MockFoo that allows
12116 // uninteresting calls (i.e. calls to mock methods that have no
12117 // EXPECT_CALL specs), NaggyMock<MockFoo> is a subclass of MockFoo
12118 // that prints a warning when an uninteresting call occurs, and
12119 // StrictMock<MockFoo> is a subclass of MockFoo that treats all
12120 // uninteresting calls as errors.
12122 // Currently a mock is naggy by default, so MockFoo and
12123 // NaggyMock<MockFoo> behave like the same. However, we will soon
12124 // switch the default behavior of mocks to be nice, as that in general
12125 // leads to more maintainable tests. When that happens, MockFoo will
12126 // stop behaving like NaggyMock<MockFoo> and start behaving like
12127 // NiceMock<MockFoo>.
12129 // NiceMock, NaggyMock, and StrictMock "inherit" the constructors of
12130 // their respective base class, with up-to 10 arguments. Therefore
12131 // you can write NiceMock<MockFoo>(5, "a") to construct a nice mock
12132 // where MockFoo has a constructor that accepts (int, const char*),
12135 // A known limitation is that NiceMock<MockFoo>, NaggyMock<MockFoo>,
12136 // and StrictMock<MockFoo> only works for mock methods defined using
12137 // the MOCK_METHOD* family of macros DIRECTLY in the MockFoo class.
12138 // If a mock method is defined in a base class of MockFoo, the "nice"
12139 // or "strict" modifier may not affect it, depending on the compiler.
12140 // In particular, nesting NiceMock, NaggyMock, and StrictMock is NOT
12143 // Another known limitation is that the constructors of the base mock
12144 // cannot have arguments passed by non-const reference, which are
12145 // banned by the Google C++ style guide anyway.
12147 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
12148 #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
12151 namespace testing {
12153 template <class MockClass>
12154 class NiceMock : public MockClass {
12156 // We don't factor out the constructor body to a common method, as
12157 // we have to avoid a possible clash with members of MockClass.
12159 ::testing::Mock::AllowUninterestingCalls(
12160 internal::ImplicitCast_<MockClass*>(this));
12163 // C++ doesn't (yet) allow inheritance of constructors, so we have
12164 // to define it for each arity.
12165 template <typename A1>
12166 explicit NiceMock(const A1& a1) : MockClass(a1) {
12167 ::testing::Mock::AllowUninterestingCalls(
12168 internal::ImplicitCast_<MockClass*>(this));
12170 template <typename A1, typename A2>
12171 NiceMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {
12172 ::testing::Mock::AllowUninterestingCalls(
12173 internal::ImplicitCast_<MockClass*>(this));
12176 template <typename A1, typename A2, typename A3>
12177 NiceMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {
12178 ::testing::Mock::AllowUninterestingCalls(
12179 internal::ImplicitCast_<MockClass*>(this));
12182 template <typename A1, typename A2, typename A3, typename A4>
12183 NiceMock(const A1& a1, const A2& a2, const A3& a3,
12184 const A4& a4) : MockClass(a1, a2, a3, a4) {
12185 ::testing::Mock::AllowUninterestingCalls(
12186 internal::ImplicitCast_<MockClass*>(this));
12189 template <typename A1, typename A2, typename A3, typename A4, typename A5>
12190 NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
12191 const A5& a5) : MockClass(a1, a2, a3, a4, a5) {
12192 ::testing::Mock::AllowUninterestingCalls(
12193 internal::ImplicitCast_<MockClass*>(this));
12196 template <typename A1, typename A2, typename A3, typename A4, typename A5,
12198 NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
12199 const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {
12200 ::testing::Mock::AllowUninterestingCalls(
12201 internal::ImplicitCast_<MockClass*>(this));
12204 template <typename A1, typename A2, typename A3, typename A4, typename A5,
12205 typename A6, typename A7>
12206 NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
12207 const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5,
12209 ::testing::Mock::AllowUninterestingCalls(
12210 internal::ImplicitCast_<MockClass*>(this));
12213 template <typename A1, typename A2, typename A3, typename A4, typename A5,
12214 typename A6, typename A7, typename A8>
12215 NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
12216 const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1,
12217 a2, a3, a4, a5, a6, a7, a8) {
12218 ::testing::Mock::AllowUninterestingCalls(
12219 internal::ImplicitCast_<MockClass*>(this));
12222 template <typename A1, typename A2, typename A3, typename A4, typename A5,
12223 typename A6, typename A7, typename A8, typename A9>
12224 NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
12225 const A5& a5, const A6& a6, const A7& a7, const A8& a8,
12226 const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
12227 ::testing::Mock::AllowUninterestingCalls(
12228 internal::ImplicitCast_<MockClass*>(this));
12231 template <typename A1, typename A2, typename A3, typename A4, typename A5,
12232 typename A6, typename A7, typename A8, typename A9, typename A10>
12233 NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
12234 const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9,
12235 const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {
12236 ::testing::Mock::AllowUninterestingCalls(
12237 internal::ImplicitCast_<MockClass*>(this));
12240 virtual ~NiceMock() {
12241 ::testing::Mock::UnregisterCallReaction(
12242 internal::ImplicitCast_<MockClass*>(this));
12246 GTEST_DISALLOW_COPY_AND_ASSIGN_(NiceMock);
12249 template <class MockClass>
12250 class NaggyMock : public MockClass {
12252 // We don't factor out the constructor body to a common method, as
12253 // we have to avoid a possible clash with members of MockClass.
12255 ::testing::Mock::WarnUninterestingCalls(
12256 internal::ImplicitCast_<MockClass*>(this));
12259 // C++ doesn't (yet) allow inheritance of constructors, so we have
12260 // to define it for each arity.
12261 template <typename A1>
12262 explicit NaggyMock(const A1& a1) : MockClass(a1) {
12263 ::testing::Mock::WarnUninterestingCalls(
12264 internal::ImplicitCast_<MockClass*>(this));
12266 template <typename A1, typename A2>
12267 NaggyMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {
12268 ::testing::Mock::WarnUninterestingCalls(
12269 internal::ImplicitCast_<MockClass*>(this));
12272 template <typename A1, typename A2, typename A3>
12273 NaggyMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {
12274 ::testing::Mock::WarnUninterestingCalls(
12275 internal::ImplicitCast_<MockClass*>(this));
12278 template <typename A1, typename A2, typename A3, typename A4>
12279 NaggyMock(const A1& a1, const A2& a2, const A3& a3,
12280 const A4& a4) : MockClass(a1, a2, a3, a4) {
12281 ::testing::Mock::WarnUninterestingCalls(
12282 internal::ImplicitCast_<MockClass*>(this));
12285 template <typename A1, typename A2, typename A3, typename A4, typename A5>
12286 NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
12287 const A5& a5) : MockClass(a1, a2, a3, a4, a5) {
12288 ::testing::Mock::WarnUninterestingCalls(
12289 internal::ImplicitCast_<MockClass*>(this));
12292 template <typename A1, typename A2, typename A3, typename A4, typename A5,
12294 NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
12295 const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {
12296 ::testing::Mock::WarnUninterestingCalls(
12297 internal::ImplicitCast_<MockClass*>(this));
12300 template <typename A1, typename A2, typename A3, typename A4, typename A5,
12301 typename A6, typename A7>
12302 NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
12303 const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5,
12305 ::testing::Mock::WarnUninterestingCalls(
12306 internal::ImplicitCast_<MockClass*>(this));
12309 template <typename A1, typename A2, typename A3, typename A4, typename A5,
12310 typename A6, typename A7, typename A8>
12311 NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
12312 const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1,
12313 a2, a3, a4, a5, a6, a7, a8) {
12314 ::testing::Mock::WarnUninterestingCalls(
12315 internal::ImplicitCast_<MockClass*>(this));
12318 template <typename A1, typename A2, typename A3, typename A4, typename A5,
12319 typename A6, typename A7, typename A8, typename A9>
12320 NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
12321 const A5& a5, const A6& a6, const A7& a7, const A8& a8,
12322 const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
12323 ::testing::Mock::WarnUninterestingCalls(
12324 internal::ImplicitCast_<MockClass*>(this));
12327 template <typename A1, typename A2, typename A3, typename A4, typename A5,
12328 typename A6, typename A7, typename A8, typename A9, typename A10>
12329 NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
12330 const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9,
12331 const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {
12332 ::testing::Mock::WarnUninterestingCalls(
12333 internal::ImplicitCast_<MockClass*>(this));
12336 virtual ~NaggyMock() {
12337 ::testing::Mock::UnregisterCallReaction(
12338 internal::ImplicitCast_<MockClass*>(this));
12342 GTEST_DISALLOW_COPY_AND_ASSIGN_(NaggyMock);
12345 template <class MockClass>
12346 class StrictMock : public MockClass {
12348 // We don't factor out the constructor body to a common method, as
12349 // we have to avoid a possible clash with members of MockClass.
12351 ::testing::Mock::FailUninterestingCalls(
12352 internal::ImplicitCast_<MockClass*>(this));
12355 // C++ doesn't (yet) allow inheritance of constructors, so we have
12356 // to define it for each arity.
12357 template <typename A1>
12358 explicit StrictMock(const A1& a1) : MockClass(a1) {
12359 ::testing::Mock::FailUninterestingCalls(
12360 internal::ImplicitCast_<MockClass*>(this));
12362 template <typename A1, typename A2>
12363 StrictMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {
12364 ::testing::Mock::FailUninterestingCalls(
12365 internal::ImplicitCast_<MockClass*>(this));
12368 template <typename A1, typename A2, typename A3>
12369 StrictMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {
12370 ::testing::Mock::FailUninterestingCalls(
12371 internal::ImplicitCast_<MockClass*>(this));
12374 template <typename A1, typename A2, typename A3, typename A4>
12375 StrictMock(const A1& a1, const A2& a2, const A3& a3,
12376 const A4& a4) : MockClass(a1, a2, a3, a4) {
12377 ::testing::Mock::FailUninterestingCalls(
12378 internal::ImplicitCast_<MockClass*>(this));
12381 template <typename A1, typename A2, typename A3, typename A4, typename A5>
12382 StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
12383 const A5& a5) : MockClass(a1, a2, a3, a4, a5) {
12384 ::testing::Mock::FailUninterestingCalls(
12385 internal::ImplicitCast_<MockClass*>(this));
12388 template <typename A1, typename A2, typename A3, typename A4, typename A5,
12390 StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
12391 const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {
12392 ::testing::Mock::FailUninterestingCalls(
12393 internal::ImplicitCast_<MockClass*>(this));
12396 template <typename A1, typename A2, typename A3, typename A4, typename A5,
12397 typename A6, typename A7>
12398 StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
12399 const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5,
12401 ::testing::Mock::FailUninterestingCalls(
12402 internal::ImplicitCast_<MockClass*>(this));
12405 template <typename A1, typename A2, typename A3, typename A4, typename A5,
12406 typename A6, typename A7, typename A8>
12407 StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
12408 const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1,
12409 a2, a3, a4, a5, a6, a7, a8) {
12410 ::testing::Mock::FailUninterestingCalls(
12411 internal::ImplicitCast_<MockClass*>(this));
12414 template <typename A1, typename A2, typename A3, typename A4, typename A5,
12415 typename A6, typename A7, typename A8, typename A9>
12416 StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
12417 const A5& a5, const A6& a6, const A7& a7, const A8& a8,
12418 const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
12419 ::testing::Mock::FailUninterestingCalls(
12420 internal::ImplicitCast_<MockClass*>(this));
12423 template <typename A1, typename A2, typename A3, typename A4, typename A5,
12424 typename A6, typename A7, typename A8, typename A9, typename A10>
12425 StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
12426 const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9,
12427 const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {
12428 ::testing::Mock::FailUninterestingCalls(
12429 internal::ImplicitCast_<MockClass*>(this));
12432 virtual ~StrictMock() {
12433 ::testing::Mock::UnregisterCallReaction(
12434 internal::ImplicitCast_<MockClass*>(this));
12438 GTEST_DISALLOW_COPY_AND_ASSIGN_(StrictMock);
12441 // The following specializations catch some (relatively more common)
12442 // user errors of nesting nice and strict mocks. They do NOT catch
12443 // all possible errors.
12445 // These specializations are declared but not defined, as NiceMock,
12446 // NaggyMock, and StrictMock cannot be nested.
12448 template <typename MockClass>
12449 class NiceMock<NiceMock<MockClass> >;
12450 template <typename MockClass>
12451 class NiceMock<NaggyMock<MockClass> >;
12452 template <typename MockClass>
12453 class NiceMock<StrictMock<MockClass> >;
12455 template <typename MockClass>
12456 class NaggyMock<NiceMock<MockClass> >;
12457 template <typename MockClass>
12458 class NaggyMock<NaggyMock<MockClass> >;
12459 template <typename MockClass>
12460 class NaggyMock<StrictMock<MockClass> >;
12462 template <typename MockClass>
12463 class StrictMock<NiceMock<MockClass> >;
12464 template <typename MockClass>
12465 class StrictMock<NaggyMock<MockClass> >;
12466 template <typename MockClass>
12467 class StrictMock<StrictMock<MockClass> >;
12469 } // namespace testing
12471 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
12472 // This file was GENERATED by command:
12473 // pump.py gmock-generated-matchers.h.pump
12474 // DO NOT EDIT BY HAND!!!
12476 // Copyright 2008, Google Inc.
12477 // All rights reserved.
12479 // Redistribution and use in source and binary forms, with or without
12480 // modification, are permitted provided that the following conditions are
12483 // * Redistributions of source code must retain the above copyright
12484 // notice, this list of conditions and the following disclaimer.
12485 // * Redistributions in binary form must reproduce the above
12486 // copyright notice, this list of conditions and the following disclaimer
12487 // in the documentation and/or other materials provided with the
12489 // * Neither the name of Google Inc. nor the names of its
12490 // contributors may be used to endorse or promote products derived from
12491 // this software without specific prior written permission.
12493 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
12494 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
12495 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
12496 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
12497 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
12498 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
12499 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12500 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12501 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12502 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
12503 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12505 // Google Mock - a framework for writing C++ mock classes.
12507 // This file implements some commonly used variadic matchers.
12509 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
12510 #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
12512 #include <iterator>
12517 namespace testing {
12518 namespace internal {
12520 // The type of the i-th (0-based) field of Tuple.
12521 #define GMOCK_FIELD_TYPE_(Tuple, i) \
12522 typename ::testing::tuple_element<i, Tuple>::type
12524 // TupleFields<Tuple, k0, ..., kn> is for selecting fields from a
12525 // tuple of type Tuple. It has two members:
12527 // type: a tuple type whose i-th field is the ki-th field of Tuple.
12528 // GetSelectedFields(t): returns fields k0, ..., and kn of t as a tuple.
12530 // For example, in class TupleFields<tuple<bool, char, int>, 2, 0>, we have:
12532 // type is tuple<int, bool>, and
12533 // GetSelectedFields(make_tuple(true, 'a', 42)) is (42, true).
12535 template <class Tuple, int k0 = -1, int k1 = -1, int k2 = -1, int k3 = -1,
12536 int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1, int k8 = -1,
12540 // This generic version is used when there are 10 selectors.
12541 template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6,
12542 int k7, int k8, int k9>
12543 class TupleFields {
12545 typedef ::testing::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
12546 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
12547 GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4),
12548 GMOCK_FIELD_TYPE_(Tuple, k5), GMOCK_FIELD_TYPE_(Tuple, k6),
12549 GMOCK_FIELD_TYPE_(Tuple, k7), GMOCK_FIELD_TYPE_(Tuple, k8),
12550 GMOCK_FIELD_TYPE_(Tuple, k9)> type;
12551 static type GetSelectedFields(const Tuple& t) {
12552 return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t),
12553 get<k5>(t), get<k6>(t), get<k7>(t), get<k8>(t), get<k9>(t));
12557 // The following specialization is used for 0 ~ 9 selectors.
12559 template <class Tuple>
12560 class TupleFields<Tuple, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1> {
12562 typedef ::testing::tuple<> type;
12563 static type GetSelectedFields(const Tuple& /* t */) {
12568 template <class Tuple, int k0>
12569 class TupleFields<Tuple, k0, -1, -1, -1, -1, -1, -1, -1, -1, -1> {
12571 typedef ::testing::tuple<GMOCK_FIELD_TYPE_(Tuple, k0)> type;
12572 static type GetSelectedFields(const Tuple& t) {
12573 return type(get<k0>(t));
12577 template <class Tuple, int k0, int k1>
12578 class TupleFields<Tuple, k0, k1, -1, -1, -1, -1, -1, -1, -1, -1> {
12580 typedef ::testing::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
12581 GMOCK_FIELD_TYPE_(Tuple, k1)> type;
12582 static type GetSelectedFields(const Tuple& t) {
12583 return type(get<k0>(t), get<k1>(t));
12587 template <class Tuple, int k0, int k1, int k2>
12588 class TupleFields<Tuple, k0, k1, k2, -1, -1, -1, -1, -1, -1, -1> {
12590 typedef ::testing::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
12591 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2)> type;
12592 static type GetSelectedFields(const Tuple& t) {
12593 return type(get<k0>(t), get<k1>(t), get<k2>(t));
12597 template <class Tuple, int k0, int k1, int k2, int k3>
12598 class TupleFields<Tuple, k0, k1, k2, k3, -1, -1, -1, -1, -1, -1> {
12600 typedef ::testing::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
12601 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
12602 GMOCK_FIELD_TYPE_(Tuple, k3)> type;
12603 static type GetSelectedFields(const Tuple& t) {
12604 return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t));
12608 template <class Tuple, int k0, int k1, int k2, int k3, int k4>
12609 class TupleFields<Tuple, k0, k1, k2, k3, k4, -1, -1, -1, -1, -1> {
12611 typedef ::testing::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
12612 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
12613 GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4)> type;
12614 static type GetSelectedFields(const Tuple& t) {
12615 return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t));
12619 template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5>
12620 class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, -1, -1, -1, -1> {
12622 typedef ::testing::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
12623 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
12624 GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4),
12625 GMOCK_FIELD_TYPE_(Tuple, k5)> type;
12626 static type GetSelectedFields(const Tuple& t) {
12627 return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t),
12632 template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6>
12633 class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, k6, -1, -1, -1> {
12635 typedef ::testing::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
12636 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
12637 GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4),
12638 GMOCK_FIELD_TYPE_(Tuple, k5), GMOCK_FIELD_TYPE_(Tuple, k6)> type;
12639 static type GetSelectedFields(const Tuple& t) {
12640 return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t),
12641 get<k5>(t), get<k6>(t));
12645 template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6,
12647 class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, k6, k7, -1, -1> {
12649 typedef ::testing::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
12650 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
12651 GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4),
12652 GMOCK_FIELD_TYPE_(Tuple, k5), GMOCK_FIELD_TYPE_(Tuple, k6),
12653 GMOCK_FIELD_TYPE_(Tuple, k7)> type;
12654 static type GetSelectedFields(const Tuple& t) {
12655 return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t),
12656 get<k5>(t), get<k6>(t), get<k7>(t));
12660 template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6,
12662 class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, k6, k7, k8, -1> {
12664 typedef ::testing::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
12665 GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
12666 GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4),
12667 GMOCK_FIELD_TYPE_(Tuple, k5), GMOCK_FIELD_TYPE_(Tuple, k6),
12668 GMOCK_FIELD_TYPE_(Tuple, k7), GMOCK_FIELD_TYPE_(Tuple, k8)> type;
12669 static type GetSelectedFields(const Tuple& t) {
12670 return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t),
12671 get<k5>(t), get<k6>(t), get<k7>(t), get<k8>(t));
12675 #undef GMOCK_FIELD_TYPE_
12677 // Implements the Args() matcher.
12678 template <class ArgsTuple, int k0 = -1, int k1 = -1, int k2 = -1, int k3 = -1,
12679 int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1, int k8 = -1,
12681 class ArgsMatcherImpl : public MatcherInterface<ArgsTuple> {
12683 // ArgsTuple may have top-level const or reference modifiers.
12684 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(ArgsTuple) RawArgsTuple;
12685 typedef typename internal::TupleFields<RawArgsTuple, k0, k1, k2, k3, k4, k5,
12686 k6, k7, k8, k9>::type SelectedArgs;
12687 typedef Matcher<const SelectedArgs&> MonomorphicInnerMatcher;
12689 template <typename InnerMatcher>
12690 explicit ArgsMatcherImpl(const InnerMatcher& inner_matcher)
12691 : inner_matcher_(SafeMatcherCast<const SelectedArgs&>(inner_matcher)) {}
12693 virtual bool MatchAndExplain(ArgsTuple args,
12694 MatchResultListener* listener) const {
12695 const SelectedArgs& selected_args = GetSelectedArgs(args);
12696 if (!listener->IsInterested())
12697 return inner_matcher_.Matches(selected_args);
12699 PrintIndices(listener->stream());
12700 *listener << "are " << PrintToString(selected_args);
12702 StringMatchResultListener inner_listener;
12703 const bool match = inner_matcher_.MatchAndExplain(selected_args,
12705 PrintIfNotEmpty(inner_listener.str(), listener->stream());
12709 virtual void DescribeTo(::std::ostream* os) const {
12710 *os << "are a tuple ";
12712 inner_matcher_.DescribeTo(os);
12715 virtual void DescribeNegationTo(::std::ostream* os) const {
12716 *os << "are a tuple ";
12718 inner_matcher_.DescribeNegationTo(os);
12722 static SelectedArgs GetSelectedArgs(ArgsTuple args) {
12723 return TupleFields<RawArgsTuple, k0, k1, k2, k3, k4, k5, k6, k7, k8,
12724 k9>::GetSelectedFields(args);
12727 // Prints the indices of the selected fields.
12728 static void PrintIndices(::std::ostream* os) {
12729 *os << "whose fields (";
12730 const int indices[10] = { k0, k1, k2, k3, k4, k5, k6, k7, k8, k9 };
12731 for (int i = 0; i < 10; i++) {
12732 if (indices[i] < 0)
12738 *os << "#" << indices[i];
12743 const MonomorphicInnerMatcher inner_matcher_;
12745 GTEST_DISALLOW_ASSIGN_(ArgsMatcherImpl);
12748 template <class InnerMatcher, int k0 = -1, int k1 = -1, int k2 = -1,
12749 int k3 = -1, int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1,
12750 int k8 = -1, int k9 = -1>
12751 class ArgsMatcher {
12753 explicit ArgsMatcher(const InnerMatcher& inner_matcher)
12754 : inner_matcher_(inner_matcher) {}
12756 template <typename ArgsTuple>
12757 operator Matcher<ArgsTuple>() const {
12758 return MakeMatcher(new ArgsMatcherImpl<ArgsTuple, k0, k1, k2, k3, k4, k5,
12759 k6, k7, k8, k9>(inner_matcher_));
12763 const InnerMatcher inner_matcher_;
12765 GTEST_DISALLOW_ASSIGN_(ArgsMatcher);
12768 // A set of metafunctions for computing the result type of AllOf.
12769 // AllOf(m1, ..., mN) returns
12770 // AllOfResultN<decltype(m1), ..., decltype(mN)>::type.
12772 // Although AllOf isn't defined for one argument, AllOfResult1 is defined
12773 // to simplify the implementation.
12774 template <typename M1>
12775 struct AllOfResult1 {
12779 template <typename M1, typename M2>
12780 struct AllOfResult2 {
12781 typedef BothOfMatcher<
12782 typename AllOfResult1<M1>::type,
12783 typename AllOfResult1<M2>::type
12787 template <typename M1, typename M2, typename M3>
12788 struct AllOfResult3 {
12789 typedef BothOfMatcher<
12790 typename AllOfResult1<M1>::type,
12791 typename AllOfResult2<M2, M3>::type
12795 template <typename M1, typename M2, typename M3, typename M4>
12796 struct AllOfResult4 {
12797 typedef BothOfMatcher<
12798 typename AllOfResult2<M1, M2>::type,
12799 typename AllOfResult2<M3, M4>::type
12803 template <typename M1, typename M2, typename M3, typename M4, typename M5>
12804 struct AllOfResult5 {
12805 typedef BothOfMatcher<
12806 typename AllOfResult2<M1, M2>::type,
12807 typename AllOfResult3<M3, M4, M5>::type
12811 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12813 struct AllOfResult6 {
12814 typedef BothOfMatcher<
12815 typename AllOfResult3<M1, M2, M3>::type,
12816 typename AllOfResult3<M4, M5, M6>::type
12820 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12821 typename M6, typename M7>
12822 struct AllOfResult7 {
12823 typedef BothOfMatcher<
12824 typename AllOfResult3<M1, M2, M3>::type,
12825 typename AllOfResult4<M4, M5, M6, M7>::type
12829 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12830 typename M6, typename M7, typename M8>
12831 struct AllOfResult8 {
12832 typedef BothOfMatcher<
12833 typename AllOfResult4<M1, M2, M3, M4>::type,
12834 typename AllOfResult4<M5, M6, M7, M8>::type
12838 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12839 typename M6, typename M7, typename M8, typename M9>
12840 struct AllOfResult9 {
12841 typedef BothOfMatcher<
12842 typename AllOfResult4<M1, M2, M3, M4>::type,
12843 typename AllOfResult5<M5, M6, M7, M8, M9>::type
12847 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12848 typename M6, typename M7, typename M8, typename M9, typename M10>
12849 struct AllOfResult10 {
12850 typedef BothOfMatcher<
12851 typename AllOfResult5<M1, M2, M3, M4, M5>::type,
12852 typename AllOfResult5<M6, M7, M8, M9, M10>::type
12856 // A set of metafunctions for computing the result type of AnyOf.
12857 // AnyOf(m1, ..., mN) returns
12858 // AnyOfResultN<decltype(m1), ..., decltype(mN)>::type.
12860 // Although AnyOf isn't defined for one argument, AnyOfResult1 is defined
12861 // to simplify the implementation.
12862 template <typename M1>
12863 struct AnyOfResult1 {
12867 template <typename M1, typename M2>
12868 struct AnyOfResult2 {
12869 typedef EitherOfMatcher<
12870 typename AnyOfResult1<M1>::type,
12871 typename AnyOfResult1<M2>::type
12875 template <typename M1, typename M2, typename M3>
12876 struct AnyOfResult3 {
12877 typedef EitherOfMatcher<
12878 typename AnyOfResult1<M1>::type,
12879 typename AnyOfResult2<M2, M3>::type
12883 template <typename M1, typename M2, typename M3, typename M4>
12884 struct AnyOfResult4 {
12885 typedef EitherOfMatcher<
12886 typename AnyOfResult2<M1, M2>::type,
12887 typename AnyOfResult2<M3, M4>::type
12891 template <typename M1, typename M2, typename M3, typename M4, typename M5>
12892 struct AnyOfResult5 {
12893 typedef EitherOfMatcher<
12894 typename AnyOfResult2<M1, M2>::type,
12895 typename AnyOfResult3<M3, M4, M5>::type
12899 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12901 struct AnyOfResult6 {
12902 typedef EitherOfMatcher<
12903 typename AnyOfResult3<M1, M2, M3>::type,
12904 typename AnyOfResult3<M4, M5, M6>::type
12908 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12909 typename M6, typename M7>
12910 struct AnyOfResult7 {
12911 typedef EitherOfMatcher<
12912 typename AnyOfResult3<M1, M2, M3>::type,
12913 typename AnyOfResult4<M4, M5, M6, M7>::type
12917 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12918 typename M6, typename M7, typename M8>
12919 struct AnyOfResult8 {
12920 typedef EitherOfMatcher<
12921 typename AnyOfResult4<M1, M2, M3, M4>::type,
12922 typename AnyOfResult4<M5, M6, M7, M8>::type
12926 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12927 typename M6, typename M7, typename M8, typename M9>
12928 struct AnyOfResult9 {
12929 typedef EitherOfMatcher<
12930 typename AnyOfResult4<M1, M2, M3, M4>::type,
12931 typename AnyOfResult5<M5, M6, M7, M8, M9>::type
12935 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12936 typename M6, typename M7, typename M8, typename M9, typename M10>
12937 struct AnyOfResult10 {
12938 typedef EitherOfMatcher<
12939 typename AnyOfResult5<M1, M2, M3, M4, M5>::type,
12940 typename AnyOfResult5<M6, M7, M8, M9, M10>::type
12944 } // namespace internal
12946 // Args<N1, N2, ..., Nk>(a_matcher) matches a tuple if the selected
12947 // fields of it matches a_matcher. C++ doesn't support default
12948 // arguments for function templates, so we have to overload it.
12949 template <typename InnerMatcher>
12950 inline internal::ArgsMatcher<InnerMatcher>
12951 Args(const InnerMatcher& matcher) {
12952 return internal::ArgsMatcher<InnerMatcher>(matcher);
12955 template <int k1, typename InnerMatcher>
12956 inline internal::ArgsMatcher<InnerMatcher, k1>
12957 Args(const InnerMatcher& matcher) {
12958 return internal::ArgsMatcher<InnerMatcher, k1>(matcher);
12961 template <int k1, int k2, typename InnerMatcher>
12962 inline internal::ArgsMatcher<InnerMatcher, k1, k2>
12963 Args(const InnerMatcher& matcher) {
12964 return internal::ArgsMatcher<InnerMatcher, k1, k2>(matcher);
12967 template <int k1, int k2, int k3, typename InnerMatcher>
12968 inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3>
12969 Args(const InnerMatcher& matcher) {
12970 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3>(matcher);
12973 template <int k1, int k2, int k3, int k4, typename InnerMatcher>
12974 inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4>
12975 Args(const InnerMatcher& matcher) {
12976 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4>(matcher);
12979 template <int k1, int k2, int k3, int k4, int k5, typename InnerMatcher>
12980 inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5>
12981 Args(const InnerMatcher& matcher) {
12982 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5>(matcher);
12985 template <int k1, int k2, int k3, int k4, int k5, int k6, typename InnerMatcher>
12986 inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6>
12987 Args(const InnerMatcher& matcher) {
12988 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6>(matcher);
12991 template <int k1, int k2, int k3, int k4, int k5, int k6, int k7,
12992 typename InnerMatcher>
12993 inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7>
12994 Args(const InnerMatcher& matcher) {
12995 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6,
12999 template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
13000 typename InnerMatcher>
13001 inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8>
13002 Args(const InnerMatcher& matcher) {
13003 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7,
13007 template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
13008 int k9, typename InnerMatcher>
13009 inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8, k9>
13010 Args(const InnerMatcher& matcher) {
13011 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8,
13015 template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
13016 int k9, int k10, typename InnerMatcher>
13017 inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8, k9,
13019 Args(const InnerMatcher& matcher) {
13020 return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8,
13024 // ElementsAre(e_1, e_2, ... e_n) matches an STL-style container with
13025 // n elements, where the i-th element in the container must
13026 // match the i-th argument in the list. Each argument of
13027 // ElementsAre() can be either a value or a matcher. We support up to
13030 // The use of DecayArray in the implementation allows ElementsAre()
13031 // to accept string literals, whose type is const char[N], but we
13032 // want to treat them as const char*.
13034 // NOTE: Since ElementsAre() cares about the order of the elements, it
13035 // must not be used with containers whose elements's order is
13036 // undefined (e.g. hash_map).
13038 inline internal::ElementsAreMatcher<
13039 ::testing::tuple<> >
13041 typedef ::testing::tuple<> Args;
13042 return internal::ElementsAreMatcher<Args>(Args());
13045 template <typename T1>
13046 inline internal::ElementsAreMatcher<
13048 typename internal::DecayArray<T1>::type> >
13049 ElementsAre(const T1& e1) {
13050 typedef ::testing::tuple<
13051 typename internal::DecayArray<T1>::type> Args;
13052 return internal::ElementsAreMatcher<Args>(Args(e1));
13055 template <typename T1, typename T2>
13056 inline internal::ElementsAreMatcher<
13058 typename internal::DecayArray<T1>::type,
13059 typename internal::DecayArray<T2>::type> >
13060 ElementsAre(const T1& e1, const T2& e2) {
13061 typedef ::testing::tuple<
13062 typename internal::DecayArray<T1>::type,
13063 typename internal::DecayArray<T2>::type> Args;
13064 return internal::ElementsAreMatcher<Args>(Args(e1, e2));
13067 template <typename T1, typename T2, typename T3>
13068 inline internal::ElementsAreMatcher<
13070 typename internal::DecayArray<T1>::type,
13071 typename internal::DecayArray<T2>::type,
13072 typename internal::DecayArray<T3>::type> >
13073 ElementsAre(const T1& e1, const T2& e2, const T3& e3) {
13074 typedef ::testing::tuple<
13075 typename internal::DecayArray<T1>::type,
13076 typename internal::DecayArray<T2>::type,
13077 typename internal::DecayArray<T3>::type> Args;
13078 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3));
13081 template <typename T1, typename T2, typename T3, typename T4>
13082 inline internal::ElementsAreMatcher<
13084 typename internal::DecayArray<T1>::type,
13085 typename internal::DecayArray<T2>::type,
13086 typename internal::DecayArray<T3>::type,
13087 typename internal::DecayArray<T4>::type> >
13088 ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4) {
13089 typedef ::testing::tuple<
13090 typename internal::DecayArray<T1>::type,
13091 typename internal::DecayArray<T2>::type,
13092 typename internal::DecayArray<T3>::type,
13093 typename internal::DecayArray<T4>::type> Args;
13094 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4));
13097 template <typename T1, typename T2, typename T3, typename T4, typename T5>
13098 inline internal::ElementsAreMatcher<
13100 typename internal::DecayArray<T1>::type,
13101 typename internal::DecayArray<T2>::type,
13102 typename internal::DecayArray<T3>::type,
13103 typename internal::DecayArray<T4>::type,
13104 typename internal::DecayArray<T5>::type> >
13105 ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
13107 typedef ::testing::tuple<
13108 typename internal::DecayArray<T1>::type,
13109 typename internal::DecayArray<T2>::type,
13110 typename internal::DecayArray<T3>::type,
13111 typename internal::DecayArray<T4>::type,
13112 typename internal::DecayArray<T5>::type> Args;
13113 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5));
13116 template <typename T1, typename T2, typename T3, typename T4, typename T5,
13118 inline internal::ElementsAreMatcher<
13120 typename internal::DecayArray<T1>::type,
13121 typename internal::DecayArray<T2>::type,
13122 typename internal::DecayArray<T3>::type,
13123 typename internal::DecayArray<T4>::type,
13124 typename internal::DecayArray<T5>::type,
13125 typename internal::DecayArray<T6>::type> >
13126 ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
13127 const T5& e5, const T6& e6) {
13128 typedef ::testing::tuple<
13129 typename internal::DecayArray<T1>::type,
13130 typename internal::DecayArray<T2>::type,
13131 typename internal::DecayArray<T3>::type,
13132 typename internal::DecayArray<T4>::type,
13133 typename internal::DecayArray<T5>::type,
13134 typename internal::DecayArray<T6>::type> Args;
13135 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, e6));
13138 template <typename T1, typename T2, typename T3, typename T4, typename T5,
13139 typename T6, typename T7>
13140 inline internal::ElementsAreMatcher<
13142 typename internal::DecayArray<T1>::type,
13143 typename internal::DecayArray<T2>::type,
13144 typename internal::DecayArray<T3>::type,
13145 typename internal::DecayArray<T4>::type,
13146 typename internal::DecayArray<T5>::type,
13147 typename internal::DecayArray<T6>::type,
13148 typename internal::DecayArray<T7>::type> >
13149 ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
13150 const T5& e5, const T6& e6, const T7& e7) {
13151 typedef ::testing::tuple<
13152 typename internal::DecayArray<T1>::type,
13153 typename internal::DecayArray<T2>::type,
13154 typename internal::DecayArray<T3>::type,
13155 typename internal::DecayArray<T4>::type,
13156 typename internal::DecayArray<T5>::type,
13157 typename internal::DecayArray<T6>::type,
13158 typename internal::DecayArray<T7>::type> Args;
13159 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, e6, e7));
13162 template <typename T1, typename T2, typename T3, typename T4, typename T5,
13163 typename T6, typename T7, typename T8>
13164 inline internal::ElementsAreMatcher<
13166 typename internal::DecayArray<T1>::type,
13167 typename internal::DecayArray<T2>::type,
13168 typename internal::DecayArray<T3>::type,
13169 typename internal::DecayArray<T4>::type,
13170 typename internal::DecayArray<T5>::type,
13171 typename internal::DecayArray<T6>::type,
13172 typename internal::DecayArray<T7>::type,
13173 typename internal::DecayArray<T8>::type> >
13174 ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
13175 const T5& e5, const T6& e6, const T7& e7, const T8& e8) {
13176 typedef ::testing::tuple<
13177 typename internal::DecayArray<T1>::type,
13178 typename internal::DecayArray<T2>::type,
13179 typename internal::DecayArray<T3>::type,
13180 typename internal::DecayArray<T4>::type,
13181 typename internal::DecayArray<T5>::type,
13182 typename internal::DecayArray<T6>::type,
13183 typename internal::DecayArray<T7>::type,
13184 typename internal::DecayArray<T8>::type> Args;
13185 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, e6, e7,
13189 template <typename T1, typename T2, typename T3, typename T4, typename T5,
13190 typename T6, typename T7, typename T8, typename T9>
13191 inline internal::ElementsAreMatcher<
13193 typename internal::DecayArray<T1>::type,
13194 typename internal::DecayArray<T2>::type,
13195 typename internal::DecayArray<T3>::type,
13196 typename internal::DecayArray<T4>::type,
13197 typename internal::DecayArray<T5>::type,
13198 typename internal::DecayArray<T6>::type,
13199 typename internal::DecayArray<T7>::type,
13200 typename internal::DecayArray<T8>::type,
13201 typename internal::DecayArray<T9>::type> >
13202 ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
13203 const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9) {
13204 typedef ::testing::tuple<
13205 typename internal::DecayArray<T1>::type,
13206 typename internal::DecayArray<T2>::type,
13207 typename internal::DecayArray<T3>::type,
13208 typename internal::DecayArray<T4>::type,
13209 typename internal::DecayArray<T5>::type,
13210 typename internal::DecayArray<T6>::type,
13211 typename internal::DecayArray<T7>::type,
13212 typename internal::DecayArray<T8>::type,
13213 typename internal::DecayArray<T9>::type> Args;
13214 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, e6, e7,
13218 template <typename T1, typename T2, typename T3, typename T4, typename T5,
13219 typename T6, typename T7, typename T8, typename T9, typename T10>
13220 inline internal::ElementsAreMatcher<
13222 typename internal::DecayArray<T1>::type,
13223 typename internal::DecayArray<T2>::type,
13224 typename internal::DecayArray<T3>::type,
13225 typename internal::DecayArray<T4>::type,
13226 typename internal::DecayArray<T5>::type,
13227 typename internal::DecayArray<T6>::type,
13228 typename internal::DecayArray<T7>::type,
13229 typename internal::DecayArray<T8>::type,
13230 typename internal::DecayArray<T9>::type,
13231 typename internal::DecayArray<T10>::type> >
13232 ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
13233 const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9,
13235 typedef ::testing::tuple<
13236 typename internal::DecayArray<T1>::type,
13237 typename internal::DecayArray<T2>::type,
13238 typename internal::DecayArray<T3>::type,
13239 typename internal::DecayArray<T4>::type,
13240 typename internal::DecayArray<T5>::type,
13241 typename internal::DecayArray<T6>::type,
13242 typename internal::DecayArray<T7>::type,
13243 typename internal::DecayArray<T8>::type,
13244 typename internal::DecayArray<T9>::type,
13245 typename internal::DecayArray<T10>::type> Args;
13246 return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, e6, e7,
13250 // UnorderedElementsAre(e_1, e_2, ..., e_n) is an ElementsAre extension
13251 // that matches n elements in any order. We support up to n=10 arguments.
13253 inline internal::UnorderedElementsAreMatcher<
13254 ::testing::tuple<> >
13255 UnorderedElementsAre() {
13256 typedef ::testing::tuple<> Args;
13257 return internal::UnorderedElementsAreMatcher<Args>(Args());
13260 template <typename T1>
13261 inline internal::UnorderedElementsAreMatcher<
13263 typename internal::DecayArray<T1>::type> >
13264 UnorderedElementsAre(const T1& e1) {
13265 typedef ::testing::tuple<
13266 typename internal::DecayArray<T1>::type> Args;
13267 return internal::UnorderedElementsAreMatcher<Args>(Args(e1));
13270 template <typename T1, typename T2>
13271 inline internal::UnorderedElementsAreMatcher<
13273 typename internal::DecayArray<T1>::type,
13274 typename internal::DecayArray<T2>::type> >
13275 UnorderedElementsAre(const T1& e1, const T2& e2) {
13276 typedef ::testing::tuple<
13277 typename internal::DecayArray<T1>::type,
13278 typename internal::DecayArray<T2>::type> Args;
13279 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2));
13282 template <typename T1, typename T2, typename T3>
13283 inline internal::UnorderedElementsAreMatcher<
13285 typename internal::DecayArray<T1>::type,
13286 typename internal::DecayArray<T2>::type,
13287 typename internal::DecayArray<T3>::type> >
13288 UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3) {
13289 typedef ::testing::tuple<
13290 typename internal::DecayArray<T1>::type,
13291 typename internal::DecayArray<T2>::type,
13292 typename internal::DecayArray<T3>::type> Args;
13293 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3));
13296 template <typename T1, typename T2, typename T3, typename T4>
13297 inline internal::UnorderedElementsAreMatcher<
13299 typename internal::DecayArray<T1>::type,
13300 typename internal::DecayArray<T2>::type,
13301 typename internal::DecayArray<T3>::type,
13302 typename internal::DecayArray<T4>::type> >
13303 UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4) {
13304 typedef ::testing::tuple<
13305 typename internal::DecayArray<T1>::type,
13306 typename internal::DecayArray<T2>::type,
13307 typename internal::DecayArray<T3>::type,
13308 typename internal::DecayArray<T4>::type> Args;
13309 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4));
13312 template <typename T1, typename T2, typename T3, typename T4, typename T5>
13313 inline internal::UnorderedElementsAreMatcher<
13315 typename internal::DecayArray<T1>::type,
13316 typename internal::DecayArray<T2>::type,
13317 typename internal::DecayArray<T3>::type,
13318 typename internal::DecayArray<T4>::type,
13319 typename internal::DecayArray<T5>::type> >
13320 UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
13322 typedef ::testing::tuple<
13323 typename internal::DecayArray<T1>::type,
13324 typename internal::DecayArray<T2>::type,
13325 typename internal::DecayArray<T3>::type,
13326 typename internal::DecayArray<T4>::type,
13327 typename internal::DecayArray<T5>::type> Args;
13328 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5));
13331 template <typename T1, typename T2, typename T3, typename T4, typename T5,
13333 inline internal::UnorderedElementsAreMatcher<
13335 typename internal::DecayArray<T1>::type,
13336 typename internal::DecayArray<T2>::type,
13337 typename internal::DecayArray<T3>::type,
13338 typename internal::DecayArray<T4>::type,
13339 typename internal::DecayArray<T5>::type,
13340 typename internal::DecayArray<T6>::type> >
13341 UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
13342 const T5& e5, const T6& e6) {
13343 typedef ::testing::tuple<
13344 typename internal::DecayArray<T1>::type,
13345 typename internal::DecayArray<T2>::type,
13346 typename internal::DecayArray<T3>::type,
13347 typename internal::DecayArray<T4>::type,
13348 typename internal::DecayArray<T5>::type,
13349 typename internal::DecayArray<T6>::type> Args;
13350 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5,
13354 template <typename T1, typename T2, typename T3, typename T4, typename T5,
13355 typename T6, typename T7>
13356 inline internal::UnorderedElementsAreMatcher<
13358 typename internal::DecayArray<T1>::type,
13359 typename internal::DecayArray<T2>::type,
13360 typename internal::DecayArray<T3>::type,
13361 typename internal::DecayArray<T4>::type,
13362 typename internal::DecayArray<T5>::type,
13363 typename internal::DecayArray<T6>::type,
13364 typename internal::DecayArray<T7>::type> >
13365 UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
13366 const T5& e5, const T6& e6, const T7& e7) {
13367 typedef ::testing::tuple<
13368 typename internal::DecayArray<T1>::type,
13369 typename internal::DecayArray<T2>::type,
13370 typename internal::DecayArray<T3>::type,
13371 typename internal::DecayArray<T4>::type,
13372 typename internal::DecayArray<T5>::type,
13373 typename internal::DecayArray<T6>::type,
13374 typename internal::DecayArray<T7>::type> Args;
13375 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5,
13379 template <typename T1, typename T2, typename T3, typename T4, typename T5,
13380 typename T6, typename T7, typename T8>
13381 inline internal::UnorderedElementsAreMatcher<
13383 typename internal::DecayArray<T1>::type,
13384 typename internal::DecayArray<T2>::type,
13385 typename internal::DecayArray<T3>::type,
13386 typename internal::DecayArray<T4>::type,
13387 typename internal::DecayArray<T5>::type,
13388 typename internal::DecayArray<T6>::type,
13389 typename internal::DecayArray<T7>::type,
13390 typename internal::DecayArray<T8>::type> >
13391 UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
13392 const T5& e5, const T6& e6, const T7& e7, const T8& e8) {
13393 typedef ::testing::tuple<
13394 typename internal::DecayArray<T1>::type,
13395 typename internal::DecayArray<T2>::type,
13396 typename internal::DecayArray<T3>::type,
13397 typename internal::DecayArray<T4>::type,
13398 typename internal::DecayArray<T5>::type,
13399 typename internal::DecayArray<T6>::type,
13400 typename internal::DecayArray<T7>::type,
13401 typename internal::DecayArray<T8>::type> Args;
13402 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5,
13406 template <typename T1, typename T2, typename T3, typename T4, typename T5,
13407 typename T6, typename T7, typename T8, typename T9>
13408 inline internal::UnorderedElementsAreMatcher<
13410 typename internal::DecayArray<T1>::type,
13411 typename internal::DecayArray<T2>::type,
13412 typename internal::DecayArray<T3>::type,
13413 typename internal::DecayArray<T4>::type,
13414 typename internal::DecayArray<T5>::type,
13415 typename internal::DecayArray<T6>::type,
13416 typename internal::DecayArray<T7>::type,
13417 typename internal::DecayArray<T8>::type,
13418 typename internal::DecayArray<T9>::type> >
13419 UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
13420 const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9) {
13421 typedef ::testing::tuple<
13422 typename internal::DecayArray<T1>::type,
13423 typename internal::DecayArray<T2>::type,
13424 typename internal::DecayArray<T3>::type,
13425 typename internal::DecayArray<T4>::type,
13426 typename internal::DecayArray<T5>::type,
13427 typename internal::DecayArray<T6>::type,
13428 typename internal::DecayArray<T7>::type,
13429 typename internal::DecayArray<T8>::type,
13430 typename internal::DecayArray<T9>::type> Args;
13431 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5,
13435 template <typename T1, typename T2, typename T3, typename T4, typename T5,
13436 typename T6, typename T7, typename T8, typename T9, typename T10>
13437 inline internal::UnorderedElementsAreMatcher<
13439 typename internal::DecayArray<T1>::type,
13440 typename internal::DecayArray<T2>::type,
13441 typename internal::DecayArray<T3>::type,
13442 typename internal::DecayArray<T4>::type,
13443 typename internal::DecayArray<T5>::type,
13444 typename internal::DecayArray<T6>::type,
13445 typename internal::DecayArray<T7>::type,
13446 typename internal::DecayArray<T8>::type,
13447 typename internal::DecayArray<T9>::type,
13448 typename internal::DecayArray<T10>::type> >
13449 UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
13450 const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9,
13452 typedef ::testing::tuple<
13453 typename internal::DecayArray<T1>::type,
13454 typename internal::DecayArray<T2>::type,
13455 typename internal::DecayArray<T3>::type,
13456 typename internal::DecayArray<T4>::type,
13457 typename internal::DecayArray<T5>::type,
13458 typename internal::DecayArray<T6>::type,
13459 typename internal::DecayArray<T7>::type,
13460 typename internal::DecayArray<T8>::type,
13461 typename internal::DecayArray<T9>::type,
13462 typename internal::DecayArray<T10>::type> Args;
13463 return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5,
13464 e6, e7, e8, e9, e10));
13467 // AllOf(m1, m2, ..., mk) matches any value that matches all of the given
13468 // sub-matchers. AllOf is called fully qualified to prevent ADL from firing.
13470 template <typename M1, typename M2>
13471 inline typename internal::AllOfResult2<M1, M2>::type
13472 AllOf(M1 m1, M2 m2) {
13473 return typename internal::AllOfResult2<M1, M2>::type(
13478 template <typename M1, typename M2, typename M3>
13479 inline typename internal::AllOfResult3<M1, M2, M3>::type
13480 AllOf(M1 m1, M2 m2, M3 m3) {
13481 return typename internal::AllOfResult3<M1, M2, M3>::type(
13483 ::testing::AllOf(m2, m3));
13486 template <typename M1, typename M2, typename M3, typename M4>
13487 inline typename internal::AllOfResult4<M1, M2, M3, M4>::type
13488 AllOf(M1 m1, M2 m2, M3 m3, M4 m4) {
13489 return typename internal::AllOfResult4<M1, M2, M3, M4>::type(
13490 ::testing::AllOf(m1, m2),
13491 ::testing::AllOf(m3, m4));
13494 template <typename M1, typename M2, typename M3, typename M4, typename M5>
13495 inline typename internal::AllOfResult5<M1, M2, M3, M4, M5>::type
13496 AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5) {
13497 return typename internal::AllOfResult5<M1, M2, M3, M4, M5>::type(
13498 ::testing::AllOf(m1, m2),
13499 ::testing::AllOf(m3, m4, m5));
13502 template <typename M1, typename M2, typename M3, typename M4, typename M5,
13504 inline typename internal::AllOfResult6<M1, M2, M3, M4, M5, M6>::type
13505 AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6) {
13506 return typename internal::AllOfResult6<M1, M2, M3, M4, M5, M6>::type(
13507 ::testing::AllOf(m1, m2, m3),
13508 ::testing::AllOf(m4, m5, m6));
13511 template <typename M1, typename M2, typename M3, typename M4, typename M5,
13512 typename M6, typename M7>
13513 inline typename internal::AllOfResult7<M1, M2, M3, M4, M5, M6, M7>::type
13514 AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7) {
13515 return typename internal::AllOfResult7<M1, M2, M3, M4, M5, M6, M7>::type(
13516 ::testing::AllOf(m1, m2, m3),
13517 ::testing::AllOf(m4, m5, m6, m7));
13520 template <typename M1, typename M2, typename M3, typename M4, typename M5,
13521 typename M6, typename M7, typename M8>
13522 inline typename internal::AllOfResult8<M1, M2, M3, M4, M5, M6, M7, M8>::type
13523 AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8) {
13524 return typename internal::AllOfResult8<M1, M2, M3, M4, M5, M6, M7, M8>::type(
13525 ::testing::AllOf(m1, m2, m3, m4),
13526 ::testing::AllOf(m5, m6, m7, m8));
13529 template <typename M1, typename M2, typename M3, typename M4, typename M5,
13530 typename M6, typename M7, typename M8, typename M9>
13531 inline typename internal::AllOfResult9<M1, M2, M3, M4, M5, M6, M7, M8, M9>::type
13532 AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9) {
13533 return typename internal::AllOfResult9<M1, M2, M3, M4, M5, M6, M7, M8,
13535 ::testing::AllOf(m1, m2, m3, m4),
13536 ::testing::AllOf(m5, m6, m7, m8, m9));
13539 template <typename M1, typename M2, typename M3, typename M4, typename M5,
13540 typename M6, typename M7, typename M8, typename M9, typename M10>
13541 inline typename internal::AllOfResult10<M1, M2, M3, M4, M5, M6, M7, M8, M9,
13543 AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
13544 return typename internal::AllOfResult10<M1, M2, M3, M4, M5, M6, M7, M8, M9,
13546 ::testing::AllOf(m1, m2, m3, m4, m5),
13547 ::testing::AllOf(m6, m7, m8, m9, m10));
13550 // AnyOf(m1, m2, ..., mk) matches any value that matches any of the given
13551 // sub-matchers. AnyOf is called fully qualified to prevent ADL from firing.
13553 template <typename M1, typename M2>
13554 inline typename internal::AnyOfResult2<M1, M2>::type
13555 AnyOf(M1 m1, M2 m2) {
13556 return typename internal::AnyOfResult2<M1, M2>::type(
13561 template <typename M1, typename M2, typename M3>
13562 inline typename internal::AnyOfResult3<M1, M2, M3>::type
13563 AnyOf(M1 m1, M2 m2, M3 m3) {
13564 return typename internal::AnyOfResult3<M1, M2, M3>::type(
13566 ::testing::AnyOf(m2, m3));
13569 template <typename M1, typename M2, typename M3, typename M4>
13570 inline typename internal::AnyOfResult4<M1, M2, M3, M4>::type
13571 AnyOf(M1 m1, M2 m2, M3 m3, M4 m4) {
13572 return typename internal::AnyOfResult4<M1, M2, M3, M4>::type(
13573 ::testing::AnyOf(m1, m2),
13574 ::testing::AnyOf(m3, m4));
13577 template <typename M1, typename M2, typename M3, typename M4, typename M5>
13578 inline typename internal::AnyOfResult5<M1, M2, M3, M4, M5>::type
13579 AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5) {
13580 return typename internal::AnyOfResult5<M1, M2, M3, M4, M5>::type(
13581 ::testing::AnyOf(m1, m2),
13582 ::testing::AnyOf(m3, m4, m5));
13585 template <typename M1, typename M2, typename M3, typename M4, typename M5,
13587 inline typename internal::AnyOfResult6<M1, M2, M3, M4, M5, M6>::type
13588 AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6) {
13589 return typename internal::AnyOfResult6<M1, M2, M3, M4, M5, M6>::type(
13590 ::testing::AnyOf(m1, m2, m3),
13591 ::testing::AnyOf(m4, m5, m6));
13594 template <typename M1, typename M2, typename M3, typename M4, typename M5,
13595 typename M6, typename M7>
13596 inline typename internal::AnyOfResult7<M1, M2, M3, M4, M5, M6, M7>::type
13597 AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7) {
13598 return typename internal::AnyOfResult7<M1, M2, M3, M4, M5, M6, M7>::type(
13599 ::testing::AnyOf(m1, m2, m3),
13600 ::testing::AnyOf(m4, m5, m6, m7));
13603 template <typename M1, typename M2, typename M3, typename M4, typename M5,
13604 typename M6, typename M7, typename M8>
13605 inline typename internal::AnyOfResult8<M1, M2, M3, M4, M5, M6, M7, M8>::type
13606 AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8) {
13607 return typename internal::AnyOfResult8<M1, M2, M3, M4, M5, M6, M7, M8>::type(
13608 ::testing::AnyOf(m1, m2, m3, m4),
13609 ::testing::AnyOf(m5, m6, m7, m8));
13612 template <typename M1, typename M2, typename M3, typename M4, typename M5,
13613 typename M6, typename M7, typename M8, typename M9>
13614 inline typename internal::AnyOfResult9<M1, M2, M3, M4, M5, M6, M7, M8, M9>::type
13615 AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9) {
13616 return typename internal::AnyOfResult9<M1, M2, M3, M4, M5, M6, M7, M8,
13618 ::testing::AnyOf(m1, m2, m3, m4),
13619 ::testing::AnyOf(m5, m6, m7, m8, m9));
13622 template <typename M1, typename M2, typename M3, typename M4, typename M5,
13623 typename M6, typename M7, typename M8, typename M9, typename M10>
13624 inline typename internal::AnyOfResult10<M1, M2, M3, M4, M5, M6, M7, M8, M9,
13626 AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
13627 return typename internal::AnyOfResult10<M1, M2, M3, M4, M5, M6, M7, M8, M9,
13629 ::testing::AnyOf(m1, m2, m3, m4, m5),
13630 ::testing::AnyOf(m6, m7, m8, m9, m10));
13633 } // namespace testing
13636 // The MATCHER* family of macros can be used in a namespace scope to
13637 // define custom matchers easily.
13644 // MATCHER(name, description_string) { statements; }
13646 // defines a matcher with the given name that executes the statements,
13647 // which must return a bool to indicate if the match succeeds. Inside
13648 // the statements, you can refer to the value being matched by 'arg',
13649 // and refer to its type by 'arg_type'.
13651 // The description string documents what the matcher does, and is used
13652 // to generate the failure message when the match fails. Since a
13653 // MATCHER() is usually defined in a header file shared by multiple
13654 // C++ source files, we require the description to be a C-string
13655 // literal to avoid possible side effects. It can be empty, in which
13656 // case we'll use the sequence of words in the matcher name as the
13661 // MATCHER(IsEven, "") { return (arg % 2) == 0; }
13663 // allows you to write
13665 // // Expects mock_foo.Bar(n) to be called where n is even.
13666 // EXPECT_CALL(mock_foo, Bar(IsEven()));
13670 // // Verifies that the value of some_expression is even.
13671 // EXPECT_THAT(some_expression, IsEven());
13673 // If the above assertion fails, it will print something like:
13675 // Value of: some_expression
13676 // Expected: is even
13679 // where the description "is even" is automatically calculated from the
13680 // matcher name IsEven.
13685 // Note that the type of the value being matched (arg_type) is
13686 // determined by the context in which you use the matcher and is
13687 // supplied to you by the compiler, so you don't need to worry about
13688 // declaring it (nor can you). This allows the matcher to be
13689 // polymorphic. For example, IsEven() can be used to match any type
13690 // where the value of "(arg % 2) == 0" can be implicitly converted to
13691 // a bool. In the "Bar(IsEven())" example above, if method Bar()
13692 // takes an int, 'arg_type' will be int; if it takes an unsigned long,
13693 // 'arg_type' will be unsigned long; and so on.
13695 // Parameterizing Matchers
13696 // =======================
13698 // Sometimes you'll want to parameterize the matcher. For that you
13699 // can use another macro:
13701 // MATCHER_P(name, param_name, description_string) { statements; }
13705 // MATCHER_P(HasAbsoluteValue, value, "") { return abs(arg) == value; }
13707 // will allow you to write:
13709 // EXPECT_THAT(Blah("a"), HasAbsoluteValue(n));
13711 // which may lead to this message (assuming n is 10):
13713 // Value of: Blah("a")
13714 // Expected: has absolute value 10
13717 // Note that both the matcher description and its parameter are
13718 // printed, making the message human-friendly.
13720 // In the matcher definition body, you can write 'foo_type' to
13721 // reference the type of a parameter named 'foo'. For example, in the
13722 // body of MATCHER_P(HasAbsoluteValue, value) above, you can write
13723 // 'value_type' to refer to the type of 'value'.
13725 // We also provide MATCHER_P2, MATCHER_P3, ..., up to MATCHER_P10 to
13726 // support multi-parameter matchers.
13728 // Describing Parameterized Matchers
13729 // =================================
13731 // The last argument to MATCHER*() is a string-typed expression. The
13732 // expression can reference all of the matcher's parameters and a
13733 // special bool-typed variable named 'negation'. When 'negation' is
13734 // false, the expression should evaluate to the matcher's description;
13735 // otherwise it should evaluate to the description of the negation of
13736 // the matcher. For example,
13738 // using testing::PrintToString;
13740 // MATCHER_P2(InClosedRange, low, hi,
13741 // string(negation ? "is not" : "is") + " in range [" +
13742 // PrintToString(low) + ", " + PrintToString(hi) + "]") {
13743 // return low <= arg && arg <= hi;
13746 // EXPECT_THAT(3, InClosedRange(4, 6));
13747 // EXPECT_THAT(3, Not(InClosedRange(2, 4)));
13749 // would generate two failures that contain the text:
13751 // Expected: is in range [4, 6]
13753 // Expected: is not in range [2, 4]
13755 // If you specify "" as the description, the failure message will
13756 // contain the sequence of words in the matcher name followed by the
13757 // parameter values printed as a tuple. For example,
13759 // MATCHER_P2(InClosedRange, low, hi, "") { ... }
13761 // EXPECT_THAT(3, InClosedRange(4, 6));
13762 // EXPECT_THAT(3, Not(InClosedRange(2, 4)));
13764 // would generate two failures that contain the text:
13766 // Expected: in closed range (4, 6)
13768 // Expected: not (in closed range (2, 4))
13770 // Types of Matcher Parameters
13771 // ===========================
13773 // For the purpose of typing, you can view
13775 // MATCHER_Pk(Foo, p1, ..., pk, description_string) { ... }
13777 // as shorthand for
13779 // template <typename p1_type, ..., typename pk_type>
13780 // FooMatcherPk<p1_type, ..., pk_type>
13781 // Foo(p1_type p1, ..., pk_type pk) { ... }
13783 // When you write Foo(v1, ..., vk), the compiler infers the types of
13784 // the parameters v1, ..., and vk for you. If you are not happy with
13785 // the result of the type inference, you can specify the types by
13786 // explicitly instantiating the template, as in Foo<long, bool>(5,
13787 // false). As said earlier, you don't get to (or need to) specify
13788 // 'arg_type' as that's determined by the context in which the matcher
13789 // is used. You can assign the result of expression Foo(p1, ..., pk)
13790 // to a variable of type FooMatcherPk<p1_type, ..., pk_type>. This
13791 // can be useful when composing matchers.
13793 // While you can instantiate a matcher template with reference types,
13794 // passing the parameters by pointer usually makes your code more
13795 // readable. If, however, you still want to pass a parameter by
13796 // reference, be aware that in the failure message generated by the
13797 // matcher you will see the value of the referenced object but not its
13800 // Explaining Match Results
13801 // ========================
13803 // Sometimes the matcher description alone isn't enough to explain why
13804 // the match has failed or succeeded. For example, when expecting a
13805 // long string, it can be very helpful to also print the diff between
13806 // the expected string and the actual one. To achieve that, you can
13807 // optionally stream additional information to a special variable
13808 // named result_listener, whose type is a pointer to class
13809 // MatchResultListener:
13811 // MATCHER_P(EqualsLongString, str, "") {
13812 // if (arg == str) return true;
13814 // *result_listener << "the difference: "
13815 /// << DiffStrings(str, arg);
13819 // Overloading Matchers
13820 // ====================
13822 // You can overload matchers with different numbers of parameters:
13824 // MATCHER_P(Blah, a, description_string1) { ... }
13825 // MATCHER_P2(Blah, a, b, description_string2) { ... }
13830 // When defining a new matcher, you should also consider implementing
13831 // MatcherInterface or using MakePolymorphicMatcher(). These
13832 // approaches require more work than the MATCHER* macros, but also
13833 // give you more control on the types of the value being matched and
13834 // the matcher parameters, which may leads to better compiler error
13835 // messages when the matcher is used wrong. They also allow
13836 // overloading matchers based on parameter types (as opposed to just
13837 // based on the number of parameters).
13839 // MATCHER*() can only be used in a namespace scope. The reason is
13840 // that C++ doesn't yet allow function-local types to be used to
13841 // instantiate templates. The up-coming C++0x standard will fix this.
13842 // Once that's done, we'll consider supporting using MATCHER*() inside
13845 // More Information
13846 // ================
13848 // To learn more about using these macros, please search for 'MATCHER'
13849 // on http://code.google.com/p/googlemock/wiki/CookBook.
13851 #define MATCHER(name, description)\
13852 class name##Matcher {\
13854 template <typename arg_type>\
13855 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13859 virtual bool MatchAndExplain(\
13860 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13861 virtual void DescribeTo(::std::ostream* gmock_os) const {\
13862 *gmock_os << FormatDescription(false);\
13864 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13865 *gmock_os << FormatDescription(true);\
13868 ::testing::internal::string FormatDescription(bool negation) const {\
13869 const ::testing::internal::string gmock_description = (description);\
13870 if (!gmock_description.empty())\
13871 return gmock_description;\
13872 return ::testing::internal::FormatMatcherDescription(\
13874 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13875 ::testing::tuple<>()));\
13877 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13879 template <typename arg_type>\
13880 operator ::testing::Matcher<arg_type>() const {\
13881 return ::testing::Matcher<arg_type>(\
13882 new gmock_Impl<arg_type>());\
13887 GTEST_DISALLOW_ASSIGN_(name##Matcher);\
13889 inline name##Matcher name() {\
13890 return name##Matcher();\
13892 template <typename arg_type>\
13893 bool name##Matcher::gmock_Impl<arg_type>::MatchAndExplain(\
13895 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13898 #define MATCHER_P(name, p0, description)\
13899 template <typename p0##_type>\
13900 class name##MatcherP {\
13902 template <typename arg_type>\
13903 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13905 explicit gmock_Impl(p0##_type gmock_p0)\
13907 virtual bool MatchAndExplain(\
13908 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13909 virtual void DescribeTo(::std::ostream* gmock_os) const {\
13910 *gmock_os << FormatDescription(false);\
13912 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13913 *gmock_os << FormatDescription(true);\
13917 ::testing::internal::string FormatDescription(bool negation) const {\
13918 const ::testing::internal::string gmock_description = (description);\
13919 if (!gmock_description.empty())\
13920 return gmock_description;\
13921 return ::testing::internal::FormatMatcherDescription(\
13923 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13924 ::testing::tuple<p0##_type>(p0)));\
13926 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13928 template <typename arg_type>\
13929 operator ::testing::Matcher<arg_type>() const {\
13930 return ::testing::Matcher<arg_type>(\
13931 new gmock_Impl<arg_type>(p0));\
13933 explicit name##MatcherP(p0##_type gmock_p0) : p0(gmock_p0) {\
13937 GTEST_DISALLOW_ASSIGN_(name##MatcherP);\
13939 template <typename p0##_type>\
13940 inline name##MatcherP<p0##_type> name(p0##_type p0) {\
13941 return name##MatcherP<p0##_type>(p0);\
13943 template <typename p0##_type>\
13944 template <typename arg_type>\
13945 bool name##MatcherP<p0##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
13947 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13950 #define MATCHER_P2(name, p0, p1, description)\
13951 template <typename p0##_type, typename p1##_type>\
13952 class name##MatcherP2 {\
13954 template <typename arg_type>\
13955 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13957 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1)\
13958 : p0(gmock_p0), p1(gmock_p1) {}\
13959 virtual bool MatchAndExplain(\
13960 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13961 virtual void DescribeTo(::std::ostream* gmock_os) const {\
13962 *gmock_os << FormatDescription(false);\
13964 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13965 *gmock_os << FormatDescription(true);\
13970 ::testing::internal::string FormatDescription(bool negation) const {\
13971 const ::testing::internal::string gmock_description = (description);\
13972 if (!gmock_description.empty())\
13973 return gmock_description;\
13974 return ::testing::internal::FormatMatcherDescription(\
13976 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13977 ::testing::tuple<p0##_type, p1##_type>(p0, p1)));\
13979 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13981 template <typename arg_type>\
13982 operator ::testing::Matcher<arg_type>() const {\
13983 return ::testing::Matcher<arg_type>(\
13984 new gmock_Impl<arg_type>(p0, p1));\
13986 name##MatcherP2(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \
13992 GTEST_DISALLOW_ASSIGN_(name##MatcherP2);\
13994 template <typename p0##_type, typename p1##_type>\
13995 inline name##MatcherP2<p0##_type, p1##_type> name(p0##_type p0, \
13997 return name##MatcherP2<p0##_type, p1##_type>(p0, p1);\
13999 template <typename p0##_type, typename p1##_type>\
14000 template <typename arg_type>\
14001 bool name##MatcherP2<p0##_type, \
14002 p1##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
14004 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
14007 #define MATCHER_P3(name, p0, p1, p2, description)\
14008 template <typename p0##_type, typename p1##_type, typename p2##_type>\
14009 class name##MatcherP3 {\
14011 template <typename arg_type>\
14012 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
14014 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2)\
14015 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\
14016 virtual bool MatchAndExplain(\
14017 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
14018 virtual void DescribeTo(::std::ostream* gmock_os) const {\
14019 *gmock_os << FormatDescription(false);\
14021 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
14022 *gmock_os << FormatDescription(true);\
14028 ::testing::internal::string FormatDescription(bool negation) const {\
14029 const ::testing::internal::string gmock_description = (description);\
14030 if (!gmock_description.empty())\
14031 return gmock_description;\
14032 return ::testing::internal::FormatMatcherDescription(\
14034 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
14035 ::testing::tuple<p0##_type, p1##_type, p2##_type>(p0, p1, \
14038 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
14040 template <typename arg_type>\
14041 operator ::testing::Matcher<arg_type>() const {\
14042 return ::testing::Matcher<arg_type>(\
14043 new gmock_Impl<arg_type>(p0, p1, p2));\
14045 name##MatcherP3(p0##_type gmock_p0, p1##_type gmock_p1, \
14046 p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {\
14052 GTEST_DISALLOW_ASSIGN_(name##MatcherP3);\
14054 template <typename p0##_type, typename p1##_type, typename p2##_type>\
14055 inline name##MatcherP3<p0##_type, p1##_type, p2##_type> name(p0##_type p0, \
14056 p1##_type p1, p2##_type p2) {\
14057 return name##MatcherP3<p0##_type, p1##_type, p2##_type>(p0, p1, p2);\
14059 template <typename p0##_type, typename p1##_type, typename p2##_type>\
14060 template <typename arg_type>\
14061 bool name##MatcherP3<p0##_type, p1##_type, \
14062 p2##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
14064 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
14067 #define MATCHER_P4(name, p0, p1, p2, p3, description)\
14068 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14069 typename p3##_type>\
14070 class name##MatcherP4 {\
14072 template <typename arg_type>\
14073 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
14075 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
14076 p3##_type gmock_p3)\
14077 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3) {}\
14078 virtual bool MatchAndExplain(\
14079 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
14080 virtual void DescribeTo(::std::ostream* gmock_os) const {\
14081 *gmock_os << FormatDescription(false);\
14083 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
14084 *gmock_os << FormatDescription(true);\
14091 ::testing::internal::string FormatDescription(bool negation) const {\
14092 const ::testing::internal::string gmock_description = (description);\
14093 if (!gmock_description.empty())\
14094 return gmock_description;\
14095 return ::testing::internal::FormatMatcherDescription(\
14097 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
14098 ::testing::tuple<p0##_type, p1##_type, p2##_type, \
14099 p3##_type>(p0, p1, p2, p3)));\
14101 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
14103 template <typename arg_type>\
14104 operator ::testing::Matcher<arg_type>() const {\
14105 return ::testing::Matcher<arg_type>(\
14106 new gmock_Impl<arg_type>(p0, p1, p2, p3));\
14108 name##MatcherP4(p0##_type gmock_p0, p1##_type gmock_p1, \
14109 p2##_type gmock_p2, p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), \
14110 p2(gmock_p2), p3(gmock_p3) {\
14117 GTEST_DISALLOW_ASSIGN_(name##MatcherP4);\
14119 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14120 typename p3##_type>\
14121 inline name##MatcherP4<p0##_type, p1##_type, p2##_type, \
14122 p3##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
14124 return name##MatcherP4<p0##_type, p1##_type, p2##_type, p3##_type>(p0, \
14127 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14128 typename p3##_type>\
14129 template <typename arg_type>\
14130 bool name##MatcherP4<p0##_type, p1##_type, p2##_type, \
14131 p3##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
14133 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
14136 #define MATCHER_P5(name, p0, p1, p2, p3, p4, description)\
14137 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14138 typename p3##_type, typename p4##_type>\
14139 class name##MatcherP5 {\
14141 template <typename arg_type>\
14142 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
14144 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
14145 p3##_type gmock_p3, p4##_type gmock_p4)\
14146 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
14148 virtual bool MatchAndExplain(\
14149 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
14150 virtual void DescribeTo(::std::ostream* gmock_os) const {\
14151 *gmock_os << FormatDescription(false);\
14153 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
14154 *gmock_os << FormatDescription(true);\
14162 ::testing::internal::string FormatDescription(bool negation) const {\
14163 const ::testing::internal::string gmock_description = (description);\
14164 if (!gmock_description.empty())\
14165 return gmock_description;\
14166 return ::testing::internal::FormatMatcherDescription(\
14168 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
14169 ::testing::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
14170 p4##_type>(p0, p1, p2, p3, p4)));\
14172 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
14174 template <typename arg_type>\
14175 operator ::testing::Matcher<arg_type>() const {\
14176 return ::testing::Matcher<arg_type>(\
14177 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4));\
14179 name##MatcherP5(p0##_type gmock_p0, p1##_type gmock_p1, \
14180 p2##_type gmock_p2, p3##_type gmock_p3, \
14181 p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
14182 p3(gmock_p3), p4(gmock_p4) {\
14190 GTEST_DISALLOW_ASSIGN_(name##MatcherP5);\
14192 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14193 typename p3##_type, typename p4##_type>\
14194 inline name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \
14195 p4##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
14197 return name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \
14198 p4##_type>(p0, p1, p2, p3, p4);\
14200 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14201 typename p3##_type, typename p4##_type>\
14202 template <typename arg_type>\
14203 bool name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \
14204 p4##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
14206 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
14209 #define MATCHER_P6(name, p0, p1, p2, p3, p4, p5, description)\
14210 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14211 typename p3##_type, typename p4##_type, typename p5##_type>\
14212 class name##MatcherP6 {\
14214 template <typename arg_type>\
14215 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
14217 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
14218 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5)\
14219 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
14220 p4(gmock_p4), p5(gmock_p5) {}\
14221 virtual bool MatchAndExplain(\
14222 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
14223 virtual void DescribeTo(::std::ostream* gmock_os) const {\
14224 *gmock_os << FormatDescription(false);\
14226 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
14227 *gmock_os << FormatDescription(true);\
14236 ::testing::internal::string FormatDescription(bool negation) const {\
14237 const ::testing::internal::string gmock_description = (description);\
14238 if (!gmock_description.empty())\
14239 return gmock_description;\
14240 return ::testing::internal::FormatMatcherDescription(\
14242 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
14243 ::testing::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
14244 p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5)));\
14246 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
14248 template <typename arg_type>\
14249 operator ::testing::Matcher<arg_type>() const {\
14250 return ::testing::Matcher<arg_type>(\
14251 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5));\
14253 name##MatcherP6(p0##_type gmock_p0, p1##_type gmock_p1, \
14254 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
14255 p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
14256 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {\
14265 GTEST_DISALLOW_ASSIGN_(name##MatcherP6);\
14267 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14268 typename p3##_type, typename p4##_type, typename p5##_type>\
14269 inline name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, \
14270 p4##_type, p5##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
14271 p3##_type p3, p4##_type p4, p5##_type p5) {\
14272 return name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, \
14273 p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5);\
14275 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14276 typename p3##_type, typename p4##_type, typename p5##_type>\
14277 template <typename arg_type>\
14278 bool name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
14279 p5##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
14281 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
14284 #define MATCHER_P7(name, p0, p1, p2, p3, p4, p5, p6, description)\
14285 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14286 typename p3##_type, typename p4##_type, typename p5##_type, \
14287 typename p6##_type>\
14288 class name##MatcherP7 {\
14290 template <typename arg_type>\
14291 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
14293 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
14294 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
14295 p6##_type gmock_p6)\
14296 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
14297 p4(gmock_p4), p5(gmock_p5), p6(gmock_p6) {}\
14298 virtual bool MatchAndExplain(\
14299 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
14300 virtual void DescribeTo(::std::ostream* gmock_os) const {\
14301 *gmock_os << FormatDescription(false);\
14303 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
14304 *gmock_os << FormatDescription(true);\
14314 ::testing::internal::string FormatDescription(bool negation) const {\
14315 const ::testing::internal::string gmock_description = (description);\
14316 if (!gmock_description.empty())\
14317 return gmock_description;\
14318 return ::testing::internal::FormatMatcherDescription(\
14320 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
14321 ::testing::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
14322 p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, \
14325 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
14327 template <typename arg_type>\
14328 operator ::testing::Matcher<arg_type>() const {\
14329 return ::testing::Matcher<arg_type>(\
14330 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6));\
14332 name##MatcherP7(p0##_type gmock_p0, p1##_type gmock_p1, \
14333 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
14334 p5##_type gmock_p5, p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), \
14335 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), \
14346 GTEST_DISALLOW_ASSIGN_(name##MatcherP7);\
14348 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14349 typename p3##_type, typename p4##_type, typename p5##_type, \
14350 typename p6##_type>\
14351 inline name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, \
14352 p4##_type, p5##_type, p6##_type> name(p0##_type p0, p1##_type p1, \
14353 p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
14355 return name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, \
14356 p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, p6);\
14358 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14359 typename p3##_type, typename p4##_type, typename p5##_type, \
14360 typename p6##_type>\
14361 template <typename arg_type>\
14362 bool name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
14363 p5##_type, p6##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
14365 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
14368 #define MATCHER_P8(name, p0, p1, p2, p3, p4, p5, p6, p7, description)\
14369 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14370 typename p3##_type, typename p4##_type, typename p5##_type, \
14371 typename p6##_type, typename p7##_type>\
14372 class name##MatcherP8 {\
14374 template <typename arg_type>\
14375 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
14377 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
14378 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
14379 p6##_type gmock_p6, p7##_type gmock_p7)\
14380 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
14381 p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7) {}\
14382 virtual bool MatchAndExplain(\
14383 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
14384 virtual void DescribeTo(::std::ostream* gmock_os) const {\
14385 *gmock_os << FormatDescription(false);\
14387 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
14388 *gmock_os << FormatDescription(true);\
14399 ::testing::internal::string FormatDescription(bool negation) const {\
14400 const ::testing::internal::string gmock_description = (description);\
14401 if (!gmock_description.empty())\
14402 return gmock_description;\
14403 return ::testing::internal::FormatMatcherDescription(\
14405 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
14406 ::testing::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
14407 p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, \
14408 p3, p4, p5, p6, p7)));\
14410 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
14412 template <typename arg_type>\
14413 operator ::testing::Matcher<arg_type>() const {\
14414 return ::testing::Matcher<arg_type>(\
14415 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7));\
14417 name##MatcherP8(p0##_type gmock_p0, p1##_type gmock_p1, \
14418 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
14419 p5##_type gmock_p5, p6##_type gmock_p6, \
14420 p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
14421 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
14433 GTEST_DISALLOW_ASSIGN_(name##MatcherP8);\
14435 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14436 typename p3##_type, typename p4##_type, typename p5##_type, \
14437 typename p6##_type, typename p7##_type>\
14438 inline name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, \
14439 p4##_type, p5##_type, p6##_type, p7##_type> name(p0##_type p0, \
14440 p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
14441 p6##_type p6, p7##_type p7) {\
14442 return name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, \
14443 p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, p3, p4, p5, \
14446 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14447 typename p3##_type, typename p4##_type, typename p5##_type, \
14448 typename p6##_type, typename p7##_type>\
14449 template <typename arg_type>\
14450 bool name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
14451 p5##_type, p6##_type, \
14452 p7##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
14454 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
14457 #define MATCHER_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, description)\
14458 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14459 typename p3##_type, typename p4##_type, typename p5##_type, \
14460 typename p6##_type, typename p7##_type, typename p8##_type>\
14461 class name##MatcherP9 {\
14463 template <typename arg_type>\
14464 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
14466 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
14467 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
14468 p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8)\
14469 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
14470 p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
14472 virtual bool MatchAndExplain(\
14473 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
14474 virtual void DescribeTo(::std::ostream* gmock_os) const {\
14475 *gmock_os << FormatDescription(false);\
14477 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
14478 *gmock_os << FormatDescription(true);\
14490 ::testing::internal::string FormatDescription(bool negation) const {\
14491 const ::testing::internal::string gmock_description = (description);\
14492 if (!gmock_description.empty())\
14493 return gmock_description;\
14494 return ::testing::internal::FormatMatcherDescription(\
14496 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
14497 ::testing::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
14498 p4##_type, p5##_type, p6##_type, p7##_type, \
14499 p8##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8)));\
14501 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
14503 template <typename arg_type>\
14504 operator ::testing::Matcher<arg_type>() const {\
14505 return ::testing::Matcher<arg_type>(\
14506 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8));\
14508 name##MatcherP9(p0##_type gmock_p0, p1##_type gmock_p1, \
14509 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
14510 p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
14511 p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
14512 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
14525 GTEST_DISALLOW_ASSIGN_(name##MatcherP9);\
14527 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14528 typename p3##_type, typename p4##_type, typename p5##_type, \
14529 typename p6##_type, typename p7##_type, typename p8##_type>\
14530 inline name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, \
14531 p4##_type, p5##_type, p6##_type, p7##_type, \
14532 p8##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
14533 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, \
14535 return name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, \
14536 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type>(p0, p1, p2, \
14537 p3, p4, p5, p6, p7, p8);\
14539 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14540 typename p3##_type, typename p4##_type, typename p5##_type, \
14541 typename p6##_type, typename p7##_type, typename p8##_type>\
14542 template <typename arg_type>\
14543 bool name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
14544 p5##_type, p6##_type, p7##_type, \
14545 p8##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
14547 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
14550 #define MATCHER_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, description)\
14551 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14552 typename p3##_type, typename p4##_type, typename p5##_type, \
14553 typename p6##_type, typename p7##_type, typename p8##_type, \
14554 typename p9##_type>\
14555 class name##MatcherP10 {\
14557 template <typename arg_type>\
14558 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
14560 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
14561 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
14562 p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
14563 p9##_type gmock_p9)\
14564 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
14565 p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
14566 p8(gmock_p8), p9(gmock_p9) {}\
14567 virtual bool MatchAndExplain(\
14568 arg_type arg, ::testing::MatchResultListener* result_listener) const;\
14569 virtual void DescribeTo(::std::ostream* gmock_os) const {\
14570 *gmock_os << FormatDescription(false);\
14572 virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
14573 *gmock_os << FormatDescription(true);\
14586 ::testing::internal::string FormatDescription(bool negation) const {\
14587 const ::testing::internal::string gmock_description = (description);\
14588 if (!gmock_description.empty())\
14589 return gmock_description;\
14590 return ::testing::internal::FormatMatcherDescription(\
14592 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
14593 ::testing::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
14594 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
14595 p9##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)));\
14597 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
14599 template <typename arg_type>\
14600 operator ::testing::Matcher<arg_type>() const {\
14601 return ::testing::Matcher<arg_type>(\
14602 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9));\
14604 name##MatcherP10(p0##_type gmock_p0, p1##_type gmock_p1, \
14605 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
14606 p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
14607 p8##_type gmock_p8, p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), \
14608 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
14609 p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {\
14622 GTEST_DISALLOW_ASSIGN_(name##MatcherP10);\
14624 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14625 typename p3##_type, typename p4##_type, typename p5##_type, \
14626 typename p6##_type, typename p7##_type, typename p8##_type, \
14627 typename p9##_type>\
14628 inline name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \
14629 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
14630 p9##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
14631 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \
14633 return name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \
14634 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, p9##_type>(p0, \
14635 p1, p2, p3, p4, p5, p6, p7, p8, p9);\
14637 template <typename p0##_type, typename p1##_type, typename p2##_type, \
14638 typename p3##_type, typename p4##_type, typename p5##_type, \
14639 typename p6##_type, typename p7##_type, typename p8##_type, \
14640 typename p9##_type>\
14641 template <typename arg_type>\
14642 bool name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \
14643 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
14644 p9##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
14646 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
14649 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
14650 // Copyright 2007, Google Inc.
14651 // All rights reserved.
14653 // Redistribution and use in source and binary forms, with or without
14654 // modification, are permitted provided that the following conditions are
14657 // * Redistributions of source code must retain the above copyright
14658 // notice, this list of conditions and the following disclaimer.
14659 // * Redistributions in binary form must reproduce the above
14660 // copyright notice, this list of conditions and the following disclaimer
14661 // in the documentation and/or other materials provided with the
14663 // * Neither the name of Google Inc. nor the names of its
14664 // contributors may be used to endorse or promote products derived from
14665 // this software without specific prior written permission.
14667 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14668 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14669 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
14670 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
14671 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
14672 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
14673 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
14674 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
14675 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14676 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14677 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14679 // Author: wan@google.com (Zhanyong Wan)
14681 // Google Mock - a framework for writing C++ mock classes.
14683 // This file implements some actions that depend on gmock-generated-actions.h.
14685 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
14686 #define GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
14688 #include <algorithm>
14691 namespace testing {
14692 namespace internal {
14694 // Implements the Invoke(f) action. The template argument
14695 // FunctionImpl is the implementation type of f, which can be either a
14696 // function pointer or a functor. Invoke(f) can be used as an
14697 // Action<F> as long as f's type is compatible with F (i.e. f can be
14698 // assigned to a tr1::function<F>).
14699 template <typename FunctionImpl>
14700 class InvokeAction {
14702 // The c'tor makes a copy of function_impl (either a function
14703 // pointer or a functor).
14704 explicit InvokeAction(FunctionImpl function_impl)
14705 : function_impl_(function_impl) {}
14707 template <typename Result, typename ArgumentTuple>
14708 Result Perform(const ArgumentTuple& args) {
14709 return InvokeHelper<Result, ArgumentTuple>::Invoke(function_impl_, args);
14713 FunctionImpl function_impl_;
14715 GTEST_DISALLOW_ASSIGN_(InvokeAction);
14718 // Implements the Invoke(object_ptr, &Class::Method) action.
14719 template <class Class, typename MethodPtr>
14720 class InvokeMethodAction {
14722 InvokeMethodAction(Class* obj_ptr, MethodPtr method_ptr)
14723 : method_ptr_(method_ptr), obj_ptr_(obj_ptr) {}
14725 template <typename Result, typename ArgumentTuple>
14726 Result Perform(const ArgumentTuple& args) const {
14727 return InvokeHelper<Result, ArgumentTuple>::InvokeMethod(
14728 obj_ptr_, method_ptr_, args);
14732 // The order of these members matters. Reversing the order can trigger
14733 // warning C4121 in MSVC (see
14734 // http://computer-programming-forum.com/7-vc.net/6fbc30265f860ad1.htm ).
14735 const MethodPtr method_ptr_;
14736 Class* const obj_ptr_;
14738 GTEST_DISALLOW_ASSIGN_(InvokeMethodAction);
14741 // An internal replacement for std::copy which mimics its behavior. This is
14742 // necessary because Visual Studio deprecates ::std::copy, issuing warning 4996.
14743 // However Visual Studio 2010 and later do not honor #pragmas which disable that
14745 template<typename InputIterator, typename OutputIterator>
14746 inline OutputIterator CopyElements(InputIterator first,
14747 InputIterator last,
14748 OutputIterator output) {
14749 for (; first != last; ++first, ++output) {
14755 } // namespace internal
14757 // Various overloads for Invoke().
14759 // Creates an action that invokes 'function_impl' with the mock
14760 // function's arguments.
14761 template <typename FunctionImpl>
14762 PolymorphicAction<internal::InvokeAction<FunctionImpl> > Invoke(
14763 FunctionImpl function_impl) {
14764 return MakePolymorphicAction(
14765 internal::InvokeAction<FunctionImpl>(function_impl));
14768 // Creates an action that invokes the given method on the given object
14769 // with the mock function's arguments.
14770 template <class Class, typename MethodPtr>
14771 PolymorphicAction<internal::InvokeMethodAction<Class, MethodPtr> > Invoke(
14772 Class* obj_ptr, MethodPtr method_ptr) {
14773 return MakePolymorphicAction(
14774 internal::InvokeMethodAction<Class, MethodPtr>(obj_ptr, method_ptr));
14777 // WithoutArgs(inner_action) can be used in a mock function with a
14778 // non-empty argument list to perform inner_action, which takes no
14779 // argument. In other words, it adapts an action accepting no
14780 // argument to one that accepts (and ignores) arguments.
14781 template <typename InnerAction>
14782 inline internal::WithArgsAction<InnerAction>
14783 WithoutArgs(const InnerAction& action) {
14784 return internal::WithArgsAction<InnerAction>(action);
14787 // WithArg<k>(an_action) creates an action that passes the k-th
14788 // (0-based) argument of the mock function to an_action and performs
14789 // it. It adapts an action accepting one argument to one that accepts
14790 // multiple arguments. For convenience, we also provide
14791 // WithArgs<k>(an_action) (defined below) as a synonym.
14792 template <int k, typename InnerAction>
14793 inline internal::WithArgsAction<InnerAction, k>
14794 WithArg(const InnerAction& action) {
14795 return internal::WithArgsAction<InnerAction, k>(action);
14798 // The ACTION*() macros trigger warning C4100 (unreferenced formal
14799 // parameter) in MSVC with -W4. Unfortunately they cannot be fixed in
14800 // the macro definition, as the warnings are generated when the macro
14801 // is expanded and macro expansion cannot contain #pragma. Therefore
14802 // we suppress them here.
14804 # pragma warning(push)
14805 # pragma warning(disable:4100)
14808 // Action ReturnArg<k>() returns the k-th argument of the mock function.
14809 ACTION_TEMPLATE(ReturnArg,
14810 HAS_1_TEMPLATE_PARAMS(int, k),
14811 AND_0_VALUE_PARAMS()) {
14812 return ::testing::get<k>(args);
14815 // Action SaveArg<k>(pointer) saves the k-th (0-based) argument of the
14816 // mock function to *pointer.
14817 ACTION_TEMPLATE(SaveArg,
14818 HAS_1_TEMPLATE_PARAMS(int, k),
14819 AND_1_VALUE_PARAMS(pointer)) {
14820 *pointer = ::testing::get<k>(args);
14823 // Action SaveArgPointee<k>(pointer) saves the value pointed to
14824 // by the k-th (0-based) argument of the mock function to *pointer.
14825 ACTION_TEMPLATE(SaveArgPointee,
14826 HAS_1_TEMPLATE_PARAMS(int, k),
14827 AND_1_VALUE_PARAMS(pointer)) {
14828 *pointer = *::testing::get<k>(args);
14831 // Action SetArgReferee<k>(value) assigns 'value' to the variable
14832 // referenced by the k-th (0-based) argument of the mock function.
14833 ACTION_TEMPLATE(SetArgReferee,
14834 HAS_1_TEMPLATE_PARAMS(int, k),
14835 AND_1_VALUE_PARAMS(value)) {
14836 typedef typename ::testing::tuple_element<k, args_type>::type argk_type;
14837 // Ensures that argument #k is a reference. If you get a compiler
14838 // error on the next line, you are using SetArgReferee<k>(value) in
14839 // a mock function whose k-th (0-based) argument is not a reference.
14840 GTEST_COMPILE_ASSERT_(internal::is_reference<argk_type>::value,
14841 SetArgReferee_must_be_used_with_a_reference_argument);
14842 ::testing::get<k>(args) = value;
14845 // Action SetArrayArgument<k>(first, last) copies the elements in
14846 // source range [first, last) to the array pointed to by the k-th
14847 // (0-based) argument, which can be either a pointer or an
14848 // iterator. The action does not take ownership of the elements in the
14850 ACTION_TEMPLATE(SetArrayArgument,
14851 HAS_1_TEMPLATE_PARAMS(int, k),
14852 AND_2_VALUE_PARAMS(first, last)) {
14853 // Visual Studio deprecates ::std::copy, so we use our own copy in that case.
14855 internal::CopyElements(first, last, ::testing::get<k>(args));
14857 ::std::copy(first, last, ::testing::get<k>(args));
14861 // Action DeleteArg<k>() deletes the k-th (0-based) argument of the mock
14863 ACTION_TEMPLATE(DeleteArg,
14864 HAS_1_TEMPLATE_PARAMS(int, k),
14865 AND_0_VALUE_PARAMS()) {
14866 delete ::testing::get<k>(args);
14869 // This action returns the value pointed to by 'pointer'.
14870 ACTION_P(ReturnPointee, pointer) { return *pointer; }
14872 // Action Throw(exception) can be used in a mock function of any type
14873 // to throw the given exception. Any copyable value can be thrown.
14874 #if GTEST_HAS_EXCEPTIONS
14876 // Suppresses the 'unreachable code' warning that VC generates in opt modes.
14878 # pragma warning(push) // Saves the current warning state.
14879 # pragma warning(disable:4702) // Temporarily disables warning 4702.
14881 ACTION_P(Throw, exception) { throw exception; }
14883 # pragma warning(pop) // Restores the warning state.
14886 #endif // GTEST_HAS_EXCEPTIONS
14889 # pragma warning(pop)
14892 } // namespace testing
14894 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
14895 // Copyright 2013, Google Inc.
14896 // All rights reserved.
14898 // Redistribution and use in source and binary forms, with or without
14899 // modification, are permitted provided that the following conditions are
14902 // * Redistributions of source code must retain the above copyright
14903 // notice, this list of conditions and the following disclaimer.
14904 // * Redistributions in binary form must reproduce the above
14905 // copyright notice, this list of conditions and the following disclaimer
14906 // in the documentation and/or other materials provided with the
14908 // * Neither the name of Google Inc. nor the names of its
14909 // contributors may be used to endorse or promote products derived from
14910 // this software without specific prior written permission.
14912 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14913 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14914 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
14915 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
14916 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
14917 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
14918 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
14919 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
14920 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14921 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14922 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14924 // Author: marcus.boerger@google.com (Marcus Boerger)
14926 // Google Mock - a framework for writing C++ mock classes.
14928 // This file implements some matchers that depend on gmock-generated-matchers.h.
14930 // Note that tests are implemented in gmock-matchers_test.cc rather than
14931 // gmock-more-matchers-test.cc.
14933 #ifndef GMOCK_GMOCK_MORE_MATCHERS_H_
14934 #define GMOCK_GMOCK_MORE_MATCHERS_H_
14937 namespace testing {
14939 // Defines a matcher that matches an empty container. The container must
14940 // support both size() and empty(), which all STL-like containers provide.
14941 MATCHER(IsEmpty, negation ? "isn't empty" : "is empty") {
14945 *result_listener << "whose size is " << arg.size();
14949 } // namespace testing
14951 #endif // GMOCK_GMOCK_MORE_MATCHERS_H_
14953 namespace testing {
14955 // Declares Google Mock flags that we want a user to use programmatically.
14956 GMOCK_DECLARE_bool_(catch_leaked_mocks);
14957 GMOCK_DECLARE_string_(verbose);
14959 // Initializes Google Mock. This must be called before running the
14960 // tests. In particular, it parses the command line for the flags
14961 // that Google Mock recognizes. Whenever a Google Mock flag is seen,
14962 // it is removed from argv, and *argc is decremented.
14964 // No value is returned. Instead, the Google Mock flag variables are
14967 // Since Google Test is needed for Google Mock to work, this function
14968 // also initializes Google Test and parses its flags, if that hasn't
14970 GTEST_API_ void InitGoogleMock(int* argc, char** argv);
14972 // This overloaded version can be used in Windows programs compiled in
14974 GTEST_API_ void InitGoogleMock(int* argc, wchar_t** argv);
14976 } // namespace testing
14978 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_H_